blob: 6218fc973addacb6f8e68986733f82d49a5762bb [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_generator_arm.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000018
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070019#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010020#include "gc/accounting/card_table.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070021#include "mirror/array-inl.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000022#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010023#include "mirror/class.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070024#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010025#include "utils/assembler.h"
26#include "utils/arm/assembler_arm.h"
27#include "utils/arm/managed_register_arm.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010028#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000029
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000030namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010031
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000032namespace arm {
33
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000034static DRegister FromLowSToD(SRegister reg) {
35 DCHECK_EQ(reg % 2, 0);
36 return static_cast<DRegister>(reg / 2);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010037}
38
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010039static constexpr bool kExplicitStackOverflowCheck = false;
40
41static constexpr int kNumberOfPushedRegistersAtEntry = 1 + 2; // LR, R6, R7
42static constexpr int kCurrentMethodStackOffset = 0;
43
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010044static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2 };
45static constexpr size_t kRuntimeParameterCoreRegistersLength =
46 arraysize(kRuntimeParameterCoreRegisters);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000047static constexpr SRegister kRuntimeParameterFpuRegisters[] = { };
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010048static constexpr size_t kRuntimeParameterFpuRegistersLength = 0;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010049
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000050class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010051 public:
52 InvokeRuntimeCallingConvention()
53 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010054 kRuntimeParameterCoreRegistersLength,
55 kRuntimeParameterFpuRegisters,
56 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010057
58 private:
59 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
60};
61
Nicolas Geoffraye5038322014-07-04 09:41:32 +010062#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010063#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010064
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010065class SlowPathCodeARM : public SlowPathCode {
66 public:
67 SlowPathCodeARM() : entry_label_(), exit_label_() {}
68
69 Label* GetEntryLabel() { return &entry_label_; }
70 Label* GetExitLabel() { return &exit_label_; }
71
72 private:
73 Label entry_label_;
74 Label exit_label_;
75
76 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM);
77};
78
79class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010080 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010081 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010082
83 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010084 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010085 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010086 arm_codegen->InvokeRuntime(
87 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010088 }
89
90 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010091 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010092 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
93};
94
Calin Juravled0d48522014-11-04 16:40:20 +000095class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
96 public:
97 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
98
99 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
100 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
101 __ Bind(GetEntryLabel());
102 arm_codegen->InvokeRuntime(
103 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc());
104 }
105
106 private:
107 HDivZeroCheck* const instruction_;
108 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
109};
110
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100111class StackOverflowCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100112 public:
113 StackOverflowCheckSlowPathARM() {}
114
115 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
116 __ Bind(GetEntryLabel());
117 __ LoadFromOffset(kLoadWord, PC, TR,
118 QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value());
119 }
120
121 private:
122 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM);
123};
124
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100125class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000126 public:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100127 explicit SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
128 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000129
130 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100131 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000132 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100133 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100134 arm_codegen->InvokeRuntime(
135 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100136 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100137 if (successor_ == nullptr) {
138 __ b(GetReturnLabel());
139 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100140 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100141 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000142 }
143
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100144 Label* GetReturnLabel() {
145 DCHECK(successor_ == nullptr);
146 return &return_label_;
147 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000148
149 private:
150 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100151 // If not null, the block to branch to after the suspend check.
152 HBasicBlock* const successor_;
153
154 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000155 Label return_label_;
156
157 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
158};
159
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100160class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100161 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100162 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
163 Location index_location,
164 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100165 : instruction_(instruction),
166 index_location_(index_location),
167 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100168
169 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100170 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100171 __ Bind(GetEntryLabel());
172 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100173 arm_codegen->Move32(
174 Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_);
175 arm_codegen->Move32(
176 Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_);
177 arm_codegen->InvokeRuntime(
178 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100179 }
180
181 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100182 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100183 const Location index_location_;
184 const Location length_location_;
185
186 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
187};
188
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000189class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100190 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000191 LoadClassSlowPathARM(HLoadClass* cls,
192 HInstruction* at,
193 uint32_t dex_pc,
194 bool do_clinit)
195 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
196 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
197 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100198
199 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000200 LocationSummary* locations = at_->GetLocations();
201
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100202 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
203 __ Bind(GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000204 codegen->SaveLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100205
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100206 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000207 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100208 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000209 int32_t entry_point_offset = do_clinit_
210 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
211 : QUICK_ENTRY_POINT(pInitializeType);
212 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_);
213
214 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000215 Location out = locations->Out();
216 if (out.IsValid()) {
217 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000218 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
219 }
220 codegen->RestoreLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100221 __ b(GetExitLabel());
222 }
223
224 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000225 // The class this slow path will load.
226 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100227
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000228 // The instruction where this slow path is happening.
229 // (Might be the load class or an initialization check).
230 HInstruction* const at_;
231
232 // The dex PC of `at_`.
233 const uint32_t dex_pc_;
234
235 // Whether to initialize the class.
236 const bool do_clinit_;
237
238 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100239};
240
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000241class LoadStringSlowPathARM : public SlowPathCodeARM {
242 public:
243 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
244
245 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
246 LocationSummary* locations = instruction_->GetLocations();
247 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
248
249 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
250 __ Bind(GetEntryLabel());
251 codegen->SaveLiveRegisters(locations);
252
253 InvokeRuntimeCallingConvention calling_convention;
254 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0));
255 __ LoadImmediate(calling_convention.GetRegisterAt(1), instruction_->GetStringIndex());
256 arm_codegen->InvokeRuntime(
257 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
258 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
259
260 codegen->RestoreLiveRegisters(locations);
261 __ b(GetExitLabel());
262 }
263
264 private:
265 HLoadString* const instruction_;
266
267 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
268};
269
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000270class TypeCheckSlowPathARM : public SlowPathCodeARM {
271 public:
272 explicit TypeCheckSlowPathARM(HTypeCheck* instruction, Location object_class)
273 : instruction_(instruction),
274 object_class_(object_class) {}
275
276 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
277 LocationSummary* locations = instruction_->GetLocations();
278 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
279
280 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
281 __ Bind(GetEntryLabel());
282 codegen->SaveLiveRegisters(locations);
283
284 // We're moving two locations to locations that could overlap, so we need a parallel
285 // move resolver.
286 InvokeRuntimeCallingConvention calling_convention;
287 MoveOperands move1(locations->InAt(1),
288 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
289 nullptr);
290 MoveOperands move2(object_class_,
291 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
292 nullptr);
293 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
294 parallel_move.AddMove(&move1);
295 parallel_move.AddMove(&move2);
296 arm_codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
297
298 arm_codegen->InvokeRuntime(
299 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, instruction_->GetDexPc());
300 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
301
302 codegen->RestoreLiveRegisters(locations);
303 __ b(GetExitLabel());
304 }
305
306 private:
307 HTypeCheck* const instruction_;
308 const Location object_class_;
309
310 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
311};
312
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000313#undef __
314
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100315#undef __
316#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700317
318inline Condition ARMCondition(IfCondition cond) {
319 switch (cond) {
320 case kCondEQ: return EQ;
321 case kCondNE: return NE;
322 case kCondLT: return LT;
323 case kCondLE: return LE;
324 case kCondGT: return GT;
325 case kCondGE: return GE;
326 default:
327 LOG(FATAL) << "Unknown if condition";
328 }
329 return EQ; // Unreachable.
330}
331
332inline Condition ARMOppositeCondition(IfCondition cond) {
333 switch (cond) {
334 case kCondEQ: return NE;
335 case kCondNE: return EQ;
336 case kCondLT: return GE;
337 case kCondLE: return GT;
338 case kCondGT: return LE;
339 case kCondGE: return LT;
340 default:
341 LOG(FATAL) << "Unknown if condition";
342 }
343 return EQ; // Unreachable.
344}
345
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100346void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
347 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
348}
349
350void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000351 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100352}
353
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100354size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
355 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
356 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100357}
358
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100359size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
360 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
361 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100362}
363
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100364CodeGeneratorARM::CodeGeneratorARM(HGraph* graph)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000365 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100366 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100367 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100368 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100369 move_resolver_(graph->GetArena(), this),
370 assembler_(true) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100371
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100372size_t CodeGeneratorARM::FrameEntrySpillSize() const {
373 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
374}
375
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100376Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100377 switch (type) {
378 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100379 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100380 ArmManagedRegister pair =
381 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100382 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
383 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
384
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100385 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
386 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100387 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100388 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100389 }
390
391 case Primitive::kPrimByte:
392 case Primitive::kPrimBoolean:
393 case Primitive::kPrimChar:
394 case Primitive::kPrimShort:
395 case Primitive::kPrimInt:
396 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100397 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100398 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100399 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
400 ArmManagedRegister current =
401 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
402 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100403 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100404 }
405 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100406 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100407 }
408
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000409 case Primitive::kPrimFloat: {
410 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100411 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100412 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100413
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000414 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000415 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
416 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000417 return Location::FpuRegisterPairLocation(reg, reg + 1);
418 }
419
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100420 case Primitive::kPrimVoid:
421 LOG(FATAL) << "Unreachable type " << type;
422 }
423
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100424 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100425}
426
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100427void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100428 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100429 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100430
431 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100432 blocked_core_registers_[SP] = true;
433 blocked_core_registers_[LR] = true;
434 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100435
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100436 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100437 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100438
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100439 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100440 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100441
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100442 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100443 // We always save and restore R6 and R7 to make sure we can use three
444 // register pairs for long operations.
Nicolas Geoffray44b819e2014-11-06 12:00:54 +0000445 blocked_core_registers_[R4] = true;
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100446 blocked_core_registers_[R5] = true;
447 blocked_core_registers_[R8] = true;
448 blocked_core_registers_[R10] = true;
449 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100450
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000451 blocked_fpu_registers_[S16] = true;
452 blocked_fpu_registers_[S17] = true;
453 blocked_fpu_registers_[S18] = true;
454 blocked_fpu_registers_[S19] = true;
455 blocked_fpu_registers_[S20] = true;
456 blocked_fpu_registers_[S21] = true;
457 blocked_fpu_registers_[S22] = true;
458 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000459 blocked_fpu_registers_[S24] = true;
460 blocked_fpu_registers_[S25] = true;
461 blocked_fpu_registers_[S26] = true;
462 blocked_fpu_registers_[S27] = true;
463 blocked_fpu_registers_[S28] = true;
464 blocked_fpu_registers_[S29] = true;
465 blocked_fpu_registers_[S30] = true;
466 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100467
468 UpdateBlockedPairRegisters();
469}
470
471void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
472 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
473 ArmManagedRegister current =
474 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
475 if (blocked_core_registers_[current.AsRegisterPairLow()]
476 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
477 blocked_register_pairs_[i] = true;
478 }
479 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100480}
481
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100482InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
483 : HGraphVisitor(graph),
484 assembler_(codegen->GetAssembler()),
485 codegen_(codegen) {}
486
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000487void CodeGeneratorARM::GenerateFrameEntry() {
Dave Allison648d7112014-07-25 16:15:27 -0700488 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100489 if (!skip_overflow_check) {
490 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100491 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100492 AddSlowPath(slow_path);
493
494 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
495 __ cmp(SP, ShifterOperand(IP));
496 __ b(slow_path->GetEntryLabel(), CC);
497 } else {
498 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100499 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100500 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100501 }
502 }
503
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100504 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
505 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000506
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100507 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100508 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100509 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000510}
511
512void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100513 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100514 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000515}
516
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100517void CodeGeneratorARM::Bind(HBasicBlock* block) {
518 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000519}
520
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100521Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
522 switch (load->GetType()) {
523 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100524 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100525 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
526 break;
527
528 case Primitive::kPrimInt:
529 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100530 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100531 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100532
533 case Primitive::kPrimBoolean:
534 case Primitive::kPrimByte:
535 case Primitive::kPrimChar:
536 case Primitive::kPrimShort:
537 case Primitive::kPrimVoid:
538 LOG(FATAL) << "Unexpected type " << load->GetType();
539 }
540
541 LOG(FATAL) << "Unreachable";
542 return Location();
543}
544
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100545Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
546 switch (type) {
547 case Primitive::kPrimBoolean:
548 case Primitive::kPrimByte:
549 case Primitive::kPrimChar:
550 case Primitive::kPrimShort:
551 case Primitive::kPrimInt:
552 case Primitive::kPrimNot: {
553 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000554 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100555 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100556 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100557 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000558 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100559 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100560 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100561
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000562 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100563 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000564 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100565 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000566 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100567 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100568 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
569 calling_convention.GetRegisterPairAt(index));
570 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100571 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000572 return Location::QuickParameter(index, stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100573 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000574 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
575 }
576 }
577
578 case Primitive::kPrimFloat: {
579 uint32_t stack_index = stack_index_++;
580 if (float_index_ % 2 == 0) {
581 float_index_ = std::max(double_index_, float_index_);
582 }
583 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
584 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
585 } else {
586 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
587 }
588 }
589
590 case Primitive::kPrimDouble: {
591 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
592 uint32_t stack_index = stack_index_;
593 stack_index_ += 2;
594 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
595 uint32_t index = double_index_;
596 double_index_ += 2;
597 return Location::FpuRegisterPairLocation(
598 calling_convention.GetFpuRegisterAt(index),
599 calling_convention.GetFpuRegisterAt(index + 1));
600 } else {
601 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100602 }
603 }
604
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100605 case Primitive::kPrimVoid:
606 LOG(FATAL) << "Unexpected parameter type " << type;
607 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100608 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100609 return Location();
610}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100611
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000612Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
613 switch (type) {
614 case Primitive::kPrimBoolean:
615 case Primitive::kPrimByte:
616 case Primitive::kPrimChar:
617 case Primitive::kPrimShort:
618 case Primitive::kPrimInt:
619 case Primitive::kPrimNot: {
620 return Location::RegisterLocation(R0);
621 }
622
623 case Primitive::kPrimFloat: {
624 return Location::FpuRegisterLocation(S0);
625 }
626
627 case Primitive::kPrimLong: {
628 return Location::RegisterPairLocation(R0, R1);
629 }
630
631 case Primitive::kPrimDouble: {
632 return Location::FpuRegisterPairLocation(S0, S1);
633 }
634
635 case Primitive::kPrimVoid:
636 return Location();
637 }
638 UNREACHABLE();
639 return Location();
640}
641
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100642void CodeGeneratorARM::Move32(Location destination, Location source) {
643 if (source.Equals(destination)) {
644 return;
645 }
646 if (destination.IsRegister()) {
647 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100648 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100649 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000650 __ vmovrs(destination.As<Register>(), source.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100651 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100652 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100653 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100654 } else if (destination.IsFpuRegister()) {
655 if (source.IsRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000656 __ vmovsr(destination.As<SRegister>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100657 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000658 __ vmovs(destination.As<SRegister>(), source.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100659 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000660 __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100661 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100662 } else {
663 DCHECK(destination.IsStackSlot());
664 if (source.IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100665 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100666 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000667 __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100668 } else {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100669 DCHECK(source.IsStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100670 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
671 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100672 }
673 }
674}
675
676void CodeGeneratorARM::Move64(Location destination, Location source) {
677 if (source.Equals(destination)) {
678 return;
679 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100680 if (destination.IsRegisterPair()) {
681 if (source.IsRegisterPair()) {
682 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
683 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100684 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000685 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100686 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000687 uint16_t register_index = source.GetQuickParameterRegisterIndex();
688 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100689 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100690 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000691 calling_convention.GetRegisterAt(register_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100692 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000693 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100694 } else {
695 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100696 if (destination.AsRegisterPairLow<Register>() == R1) {
697 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100698 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
699 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100700 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100701 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100702 SP, source.GetStackIndex());
703 }
704 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000705 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100706 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000707 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
708 SP,
709 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100710 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000711 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100712 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100713 } else if (destination.IsQuickParameter()) {
714 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000715 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
716 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100717 if (source.IsRegisterPair()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000718 __ Mov(calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100719 source.AsRegisterPairLow<Register>());
720 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000721 SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100722 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000723 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100724 } else {
725 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000726 __ LoadFromOffset(
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000727 kLoadWord, calling_convention.GetRegisterAt(register_index), SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100728 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000729 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100730 }
731 } else {
732 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100733 if (source.IsRegisterPair()) {
734 if (source.AsRegisterPairLow<Register>() == R1) {
735 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100736 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
737 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100738 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100739 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100740 SP, destination.GetStackIndex());
741 }
742 } else if (source.IsQuickParameter()) {
743 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000744 uint16_t register_index = source.GetQuickParameterRegisterIndex();
745 uint16_t stack_index = source.GetQuickParameterStackIndex();
746 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100747 SP, destination.GetStackIndex());
748 __ LoadFromOffset(kLoadWord, R0,
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000749 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100750 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000751 } else if (source.IsFpuRegisterPair()) {
752 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
753 SP,
754 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100755 } else {
756 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100757 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
758 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
759 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
760 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100761 }
762 }
763}
764
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100765void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100766 LocationSummary* locations = instruction->GetLocations();
767 if (locations != nullptr && locations->Out().Equals(location)) {
768 return;
769 }
770
Roland Levillain476df552014-10-09 17:51:36 +0100771 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100772 int32_t value = instruction->AsIntConstant()->GetValue();
773 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100774 __ LoadImmediate(location.As<Register>(), value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100775 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100776 DCHECK(location.IsStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100777 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100778 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100779 }
Roland Levillain476df552014-10-09 17:51:36 +0100780 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100781 int64_t value = instruction->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100782 if (location.IsRegisterPair()) {
783 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
784 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100785 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100786 DCHECK(location.IsDoubleStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100787 __ LoadImmediate(IP, Low32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100788 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100789 __ LoadImmediate(IP, High32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100790 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100791 }
Roland Levillain476df552014-10-09 17:51:36 +0100792 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100793 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
794 switch (instruction->GetType()) {
795 case Primitive::kPrimBoolean:
796 case Primitive::kPrimByte:
797 case Primitive::kPrimChar:
798 case Primitive::kPrimShort:
799 case Primitive::kPrimInt:
800 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100801 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100802 Move32(location, Location::StackSlot(stack_slot));
803 break;
804
805 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100806 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100807 Move64(location, Location::DoubleStackSlot(stack_slot));
808 break;
809
810 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100811 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100812 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000813 } else if (instruction->IsTemporary()) {
814 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
815 Move32(location, temp_location);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000816 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100817 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100818 switch (instruction->GetType()) {
819 case Primitive::kPrimBoolean:
820 case Primitive::kPrimByte:
821 case Primitive::kPrimChar:
822 case Primitive::kPrimShort:
823 case Primitive::kPrimNot:
824 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100825 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100826 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100827 break;
828
829 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100830 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100831 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100832 break;
833
834 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100835 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100836 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000837 }
838}
839
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100840void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
841 HInstruction* instruction,
842 uint32_t dex_pc) {
843 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
844 __ blx(LR);
845 RecordPcInfo(instruction, dex_pc);
846 DCHECK(instruction->IsSuspendCheck()
847 || instruction->IsBoundsCheck()
848 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000849 || instruction->IsDivZeroCheck()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100850 || !IsLeafMethod());
851}
852
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000853void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000854 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000855}
856
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000857void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000858 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100859 DCHECK(!successor->IsExitBlock());
860
861 HBasicBlock* block = got->GetBlock();
862 HInstruction* previous = got->GetPrevious();
863
864 HLoopInformation* info = block->GetLoopInformation();
865 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
866 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
867 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
868 return;
869 }
870
871 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
872 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
873 }
874 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000875 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000876 }
877}
878
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000879void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000880 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000881}
882
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000883void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700884 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000885 if (kIsDebugBuild) {
886 __ Comment("Unreachable");
887 __ bkpt(0);
888 }
889}
890
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000891void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100892 LocationSummary* locations =
893 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100894 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100895 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100896 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100897 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000898}
899
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000900void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700901 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100902 if (cond->IsIntConstant()) {
903 // Constant condition, statically compared against 1.
904 int32_t cond_value = cond->AsIntConstant()->GetValue();
905 if (cond_value == 1) {
906 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
907 if_instr->IfTrueSuccessor())) {
908 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100909 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100910 return;
911 } else {
912 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100913 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100914 } else {
915 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
916 // Condition has been materialized, compare the output to 0
917 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
918 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
919 ShifterOperand(0));
920 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
921 } else {
922 // Condition has not been materialized, use its inputs as the
923 // comparison and its condition as the branch condition.
924 LocationSummary* locations = cond->GetLocations();
925 if (locations->InAt(1).IsRegister()) {
926 __ cmp(locations->InAt(0).As<Register>(),
927 ShifterOperand(locations->InAt(1).As<Register>()));
928 } else {
929 DCHECK(locations->InAt(1).IsConstant());
930 int32_t value =
931 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
932 ShifterOperand operand;
933 if (ShifterOperand::CanHoldArm(value, &operand)) {
934 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
935 } else {
936 Register temp = IP;
937 __ LoadImmediate(temp, value);
938 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
939 }
940 }
941 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
942 ARMCondition(cond->AsCondition()->GetCondition()));
943 }
Dave Allison20dfc792014-06-16 20:44:29 -0700944 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100945 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
946 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700947 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000948 }
949}
950
Dave Allison20dfc792014-06-16 20:44:29 -0700951
952void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100953 LocationSummary* locations =
954 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100955 locations->SetInAt(0, Location::RequiresRegister());
956 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100957 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100958 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100959 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000960}
961
Dave Allison20dfc792014-06-16 20:44:29 -0700962void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100963 if (!comp->NeedsMaterialization()) return;
964
965 LocationSummary* locations = comp->GetLocations();
966 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100967 __ cmp(locations->InAt(0).As<Register>(),
968 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100969 } else {
970 DCHECK(locations->InAt(1).IsConstant());
971 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
972 ShifterOperand operand;
973 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100974 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100975 } else {
976 Register temp = IP;
977 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100978 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100979 }
Dave Allison20dfc792014-06-16 20:44:29 -0700980 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100981 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100982 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100983 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100984 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100985 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700986}
987
988void LocationsBuilderARM::VisitEqual(HEqual* comp) {
989 VisitCondition(comp);
990}
991
992void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
993 VisitCondition(comp);
994}
995
996void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
997 VisitCondition(comp);
998}
999
1000void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1001 VisitCondition(comp);
1002}
1003
1004void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1005 VisitCondition(comp);
1006}
1007
1008void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1009 VisitCondition(comp);
1010}
1011
1012void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1013 VisitCondition(comp);
1014}
1015
1016void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1017 VisitCondition(comp);
1018}
1019
1020void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1021 VisitCondition(comp);
1022}
1023
1024void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1025 VisitCondition(comp);
1026}
1027
1028void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1029 VisitCondition(comp);
1030}
1031
1032void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1033 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001034}
1035
1036void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001037 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001038}
1039
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001040void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1041 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001042}
1043
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001044void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001045 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001046}
1047
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001048void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001049 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001050 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001051}
1052
1053void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001054 LocationSummary* locations =
1055 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001056 switch (store->InputAt(1)->GetType()) {
1057 case Primitive::kPrimBoolean:
1058 case Primitive::kPrimByte:
1059 case Primitive::kPrimChar:
1060 case Primitive::kPrimShort:
1061 case Primitive::kPrimInt:
1062 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001063 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001064 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1065 break;
1066
1067 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001068 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001069 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1070 break;
1071
1072 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001073 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001074 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001075}
1076
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001077void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001078 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001079}
1080
1081void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001082 LocationSummary* locations =
1083 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001084 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001085}
1086
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001087void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001088 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001089 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001090}
1091
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001092void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001093 LocationSummary* locations =
1094 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001095 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001096}
1097
1098void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1099 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001100 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001101}
1102
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001103void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1104 LocationSummary* locations =
1105 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1106 locations->SetOut(Location::ConstantLocation(constant));
1107}
1108
1109void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1110 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001111 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001112}
1113
1114void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1115 LocationSummary* locations =
1116 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1117 locations->SetOut(Location::ConstantLocation(constant));
1118}
1119
1120void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1121 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001122 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001123}
1124
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001125void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001126 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001127}
1128
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001129void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001130 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001131 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001132}
1133
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001134void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001135 LocationSummary* locations =
1136 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001137 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001138}
1139
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001140void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001141 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001142 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001143}
1144
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001145void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001146 HandleInvoke(invoke);
1147}
1148
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001149void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001150 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001151}
1152
1153void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001154 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001155
1156 // TODO: Implement all kinds of calls:
1157 // 1) boot -> boot
1158 // 2) app -> boot
1159 // 3) app -> app
1160 //
1161 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1162
1163 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001164 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001165 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001166 __ LoadFromOffset(
1167 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001168 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001169 __ LoadFromOffset(
1170 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001171 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001172 __ LoadFromOffset(kLoadWord, LR, temp,
1173 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001174 // LR()
1175 __ blx(LR);
1176
1177 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1178 DCHECK(!codegen_->IsLeafMethod());
1179}
1180
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001181void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001182 LocationSummary* locations =
1183 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001184 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001185
1186 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001187 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001188 HInstruction* input = invoke->InputAt(i);
1189 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1190 }
1191
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001192 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001193}
1194
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001195void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1196 HandleInvoke(invoke);
1197}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001198
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001199void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001200 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001201 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1202 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1203 LocationSummary* locations = invoke->GetLocations();
1204 Location receiver = locations->InAt(0);
1205 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1206 // temp = object->GetClass();
1207 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001208 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1209 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001210 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001211 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001212 }
1213 // temp = temp->GetMethodAt(method_offset);
1214 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001215 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001216 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001217 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001218 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001219 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001220 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001221 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001222}
1223
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001224void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1225 HandleInvoke(invoke);
1226 // Add the hidden argument.
1227 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1228}
1229
1230void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1231 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1232 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
1233 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1234 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1235 LocationSummary* locations = invoke->GetLocations();
1236 Location receiver = locations->InAt(0);
1237 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1238
1239 // Set the hidden argument.
1240 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).As<Register>(), invoke->GetDexMethodIndex());
1241
1242 // temp = object->GetClass();
1243 if (receiver.IsStackSlot()) {
1244 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1245 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1246 } else {
1247 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
1248 }
1249 // temp = temp->GetImtEntryAt(method_offset);
1250 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
1251 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1252 // LR = temp->GetEntryPoint();
1253 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1254 // LR();
1255 __ blx(LR);
1256 DCHECK(!codegen_->IsLeafMethod());
1257 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1258}
1259
Roland Levillain88cb1752014-10-20 16:36:47 +01001260void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1261 LocationSummary* locations =
1262 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1263 switch (neg->GetResultType()) {
1264 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001265 case Primitive::kPrimLong: {
1266 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001267 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001268 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001269 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001270 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001271
Roland Levillain88cb1752014-10-20 16:36:47 +01001272 case Primitive::kPrimFloat:
1273 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001274 locations->SetInAt(0, Location::RequiresFpuRegister());
1275 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001276 break;
1277
1278 default:
1279 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1280 }
1281}
1282
1283void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1284 LocationSummary* locations = neg->GetLocations();
1285 Location out = locations->Out();
1286 Location in = locations->InAt(0);
1287 switch (neg->GetResultType()) {
1288 case Primitive::kPrimInt:
1289 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001290 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001291 break;
1292
1293 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001294 DCHECK(in.IsRegisterPair());
1295 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1296 __ rsbs(out.AsRegisterPairLow<Register>(),
1297 in.AsRegisterPairLow<Register>(),
1298 ShifterOperand(0));
1299 // We cannot emit an RSC (Reverse Subtract with Carry)
1300 // instruction here, as it does not exist in the Thumb-2
1301 // instruction set. We use the following approach
1302 // using SBC and SUB instead.
1303 //
1304 // out.hi = -C
1305 __ sbc(out.AsRegisterPairHigh<Register>(),
1306 out.AsRegisterPairHigh<Register>(),
1307 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1308 // out.hi = out.hi - in.hi
1309 __ sub(out.AsRegisterPairHigh<Register>(),
1310 out.AsRegisterPairHigh<Register>(),
1311 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1312 break;
1313
Roland Levillain88cb1752014-10-20 16:36:47 +01001314 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001315 DCHECK(in.IsFpuRegister());
1316 __ vnegs(out.As<SRegister>(), in.As<SRegister>());
1317 break;
1318
Roland Levillain88cb1752014-10-20 16:36:47 +01001319 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001320 DCHECK(in.IsFpuRegisterPair());
1321 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1322 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001323 break;
1324
1325 default:
1326 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1327 }
1328}
1329
Roland Levillaindff1f282014-11-05 14:15:05 +00001330void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
1331 LocationSummary* locations =
1332 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
1333 Primitive::Type result_type = conversion->GetResultType();
1334 Primitive::Type input_type = conversion->GetInputType();
1335 switch (result_type) {
1336 case Primitive::kPrimLong:
1337 switch (input_type) {
1338 case Primitive::kPrimByte:
1339 case Primitive::kPrimShort:
1340 case Primitive::kPrimInt:
1341 // int-to-long conversion.
1342 locations->SetInAt(0, Location::RequiresRegister());
1343 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1344 break;
1345
1346 case Primitive::kPrimFloat:
1347 case Primitive::kPrimDouble:
1348 LOG(FATAL) << "Type conversion from " << input_type << " to "
1349 << result_type << " not yet implemented";
1350 break;
1351
1352 default:
1353 LOG(FATAL) << "Unexpected type conversion from " << input_type
1354 << " to " << result_type;
1355 }
1356 break;
1357
1358 case Primitive::kPrimInt:
1359 case Primitive::kPrimFloat:
1360 case Primitive::kPrimDouble:
1361 LOG(FATAL) << "Type conversion from " << input_type
1362 << " to " << result_type << " not yet implemented";
1363 break;
1364
1365 default:
1366 LOG(FATAL) << "Unexpected type conversion from " << input_type
1367 << " to " << result_type;
1368 }
1369}
1370
1371void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1372 LocationSummary* locations = conversion->GetLocations();
1373 Location out = locations->Out();
1374 Location in = locations->InAt(0);
1375 Primitive::Type result_type = conversion->GetResultType();
1376 Primitive::Type input_type = conversion->GetInputType();
1377 switch (result_type) {
1378 case Primitive::kPrimLong:
1379 switch (input_type) {
1380 case Primitive::kPrimByte:
1381 case Primitive::kPrimShort:
1382 case Primitive::kPrimInt:
1383 // int-to-long conversion.
1384 DCHECK(out.IsRegisterPair());
1385 DCHECK(in.IsRegister());
1386 __ Mov(out.AsRegisterPairLow<Register>(), in.As<Register>());
1387 // Sign extension.
1388 __ Asr(out.AsRegisterPairHigh<Register>(),
1389 out.AsRegisterPairLow<Register>(),
1390 31);
1391 break;
1392
1393 case Primitive::kPrimFloat:
1394 case Primitive::kPrimDouble:
1395 LOG(FATAL) << "Type conversion from " << input_type << " to "
1396 << result_type << " not yet implemented";
1397 break;
1398
1399 default:
1400 LOG(FATAL) << "Unexpected type conversion from " << input_type
1401 << " to " << result_type;
1402 }
1403 break;
1404
1405 case Primitive::kPrimInt:
1406 case Primitive::kPrimFloat:
1407 case Primitive::kPrimDouble:
1408 LOG(FATAL) << "Type conversion from " << input_type
1409 << " to " << result_type << " not yet implemented";
1410 break;
1411
1412 default:
1413 LOG(FATAL) << "Unexpected type conversion from " << input_type
1414 << " to " << result_type;
1415 }
1416}
1417
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001418void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001419 LocationSummary* locations =
1420 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001421 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001422 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001423 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001424 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1425 locations->SetInAt(0, Location::RequiresRegister());
1426 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1427 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001428 break;
1429 }
1430
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001431 case Primitive::kPrimFloat:
1432 case Primitive::kPrimDouble: {
1433 locations->SetInAt(0, Location::RequiresFpuRegister());
1434 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001435 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001436 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001437 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001438
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001439 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001440 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001441 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001442}
1443
1444void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1445 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001446 Location out = locations->Out();
1447 Location first = locations->InAt(0);
1448 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001449 switch (add->GetResultType()) {
1450 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001451 if (second.IsRegister()) {
1452 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001453 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001454 __ AddConstant(out.As<Register>(),
1455 first.As<Register>(),
1456 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001457 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001458 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001459
1460 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001461 __ adds(out.AsRegisterPairLow<Register>(),
1462 first.AsRegisterPairLow<Register>(),
1463 ShifterOperand(second.AsRegisterPairLow<Register>()));
1464 __ adc(out.AsRegisterPairHigh<Register>(),
1465 first.AsRegisterPairHigh<Register>(),
1466 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001467 break;
1468
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001469 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001470 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001471 break;
1472
1473 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001474 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1475 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1476 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001477 break;
1478
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001479 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001480 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001481 }
1482}
1483
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001484void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001485 LocationSummary* locations =
1486 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001487 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001488 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001489 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001490 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1491 locations->SetInAt(0, Location::RequiresRegister());
1492 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1493 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001494 break;
1495 }
Calin Juravle11351682014-10-23 15:38:15 +01001496 case Primitive::kPrimFloat:
1497 case Primitive::kPrimDouble: {
1498 locations->SetInAt(0, Location::RequiresFpuRegister());
1499 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001500 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001501 break;
Calin Juravle11351682014-10-23 15:38:15 +01001502 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001503 default:
Calin Juravle11351682014-10-23 15:38:15 +01001504 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001505 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001506}
1507
1508void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1509 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001510 Location out = locations->Out();
1511 Location first = locations->InAt(0);
1512 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001513 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001514 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001515 if (second.IsRegister()) {
1516 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001517 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001518 __ AddConstant(out.As<Register>(),
1519 first.As<Register>(),
1520 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001521 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001522 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001523 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001524
Calin Juravle11351682014-10-23 15:38:15 +01001525 case Primitive::kPrimLong: {
1526 __ subs(out.AsRegisterPairLow<Register>(),
1527 first.AsRegisterPairLow<Register>(),
1528 ShifterOperand(second.AsRegisterPairLow<Register>()));
1529 __ sbc(out.AsRegisterPairHigh<Register>(),
1530 first.AsRegisterPairHigh<Register>(),
1531 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001532 break;
Calin Juravle11351682014-10-23 15:38:15 +01001533 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001534
Calin Juravle11351682014-10-23 15:38:15 +01001535 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001536 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001537 break;
Calin Juravle11351682014-10-23 15:38:15 +01001538 }
1539
1540 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001541 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1542 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1543 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001544 break;
1545 }
1546
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001547
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001548 default:
Calin Juravle11351682014-10-23 15:38:15 +01001549 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001550 }
1551}
1552
Calin Juravle34bacdf2014-10-07 20:23:36 +01001553void LocationsBuilderARM::VisitMul(HMul* mul) {
1554 LocationSummary* locations =
1555 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1556 switch (mul->GetResultType()) {
1557 case Primitive::kPrimInt:
1558 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001559 locations->SetInAt(0, Location::RequiresRegister());
1560 locations->SetInAt(1, Location::RequiresRegister());
1561 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001562 break;
1563 }
1564
Calin Juravleb5bfa962014-10-21 18:02:24 +01001565 case Primitive::kPrimFloat:
1566 case Primitive::kPrimDouble: {
1567 locations->SetInAt(0, Location::RequiresFpuRegister());
1568 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001569 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001570 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001571 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001572
1573 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001574 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001575 }
1576}
1577
1578void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1579 LocationSummary* locations = mul->GetLocations();
1580 Location out = locations->Out();
1581 Location first = locations->InAt(0);
1582 Location second = locations->InAt(1);
1583 switch (mul->GetResultType()) {
1584 case Primitive::kPrimInt: {
1585 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1586 break;
1587 }
1588 case Primitive::kPrimLong: {
1589 Register out_hi = out.AsRegisterPairHigh<Register>();
1590 Register out_lo = out.AsRegisterPairLow<Register>();
1591 Register in1_hi = first.AsRegisterPairHigh<Register>();
1592 Register in1_lo = first.AsRegisterPairLow<Register>();
1593 Register in2_hi = second.AsRegisterPairHigh<Register>();
1594 Register in2_lo = second.AsRegisterPairLow<Register>();
1595
1596 // Extra checks to protect caused by the existence of R1_R2.
1597 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1598 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1599 DCHECK_NE(out_hi, in1_lo);
1600 DCHECK_NE(out_hi, in2_lo);
1601
1602 // input: in1 - 64 bits, in2 - 64 bits
1603 // output: out
1604 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1605 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1606 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1607
1608 // IP <- in1.lo * in2.hi
1609 __ mul(IP, in1_lo, in2_hi);
1610 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1611 __ mla(out_hi, in1_hi, in2_lo, IP);
1612 // out.lo <- (in1.lo * in2.lo)[31:0];
1613 __ umull(out_lo, IP, in1_lo, in2_lo);
1614 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1615 __ add(out_hi, out_hi, ShifterOperand(IP));
1616 break;
1617 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001618
1619 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001620 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001621 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001622 }
1623
1624 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001625 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1626 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1627 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001628 break;
1629 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001630
1631 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001632 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001633 }
1634}
1635
Calin Juravle7c4954d2014-10-28 16:57:40 +00001636void LocationsBuilderARM::VisitDiv(HDiv* div) {
1637 LocationSummary* locations =
1638 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1639 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001640 case Primitive::kPrimInt: {
1641 locations->SetInAt(0, Location::RequiresRegister());
1642 locations->SetInAt(1, Location::RequiresRegister());
1643 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1644 break;
1645 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00001646 case Primitive::kPrimLong: {
1647 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1648 break;
1649 }
1650 case Primitive::kPrimFloat:
1651 case Primitive::kPrimDouble: {
1652 locations->SetInAt(0, Location::RequiresFpuRegister());
1653 locations->SetInAt(1, Location::RequiresFpuRegister());
1654 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1655 break;
1656 }
1657
1658 default:
1659 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1660 }
1661}
1662
1663void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1664 LocationSummary* locations = div->GetLocations();
1665 Location out = locations->Out();
1666 Location first = locations->InAt(0);
1667 Location second = locations->InAt(1);
1668
1669 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001670 case Primitive::kPrimInt: {
1671 __ sdiv(out.As<Register>(), first.As<Register>(), second.As<Register>());
1672 break;
1673 }
1674
Calin Juravle7c4954d2014-10-28 16:57:40 +00001675 case Primitive::kPrimLong: {
1676 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1677 break;
1678 }
1679
1680 case Primitive::kPrimFloat: {
1681 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1682 break;
1683 }
1684
1685 case Primitive::kPrimDouble: {
1686 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1687 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1688 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1689 break;
1690 }
1691
1692 default:
1693 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1694 }
1695}
1696
Calin Juravled0d48522014-11-04 16:40:20 +00001697void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1698 LocationSummary* locations =
1699 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1700 locations->SetInAt(0, Location::RequiresRegister());
1701 if (instruction->HasUses()) {
1702 locations->SetOut(Location::SameAsFirstInput());
1703 }
1704}
1705
1706void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1707 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
1708 codegen_->AddSlowPath(slow_path);
1709
1710 LocationSummary* locations = instruction->GetLocations();
1711 Location value = locations->InAt(0);
1712
1713 DCHECK(value.IsRegister()) << value;
1714 __ cmp(value.As<Register>(), ShifterOperand(0));
1715 __ b(slow_path->GetEntryLabel(), EQ);
1716}
1717
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001718void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001719 LocationSummary* locations =
1720 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001721 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001722 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1723 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1724 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001725}
1726
1727void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1728 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001729 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001730 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001731 codegen_->InvokeRuntime(
1732 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001733}
1734
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001735void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1736 LocationSummary* locations =
1737 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1738 InvokeRuntimeCallingConvention calling_convention;
1739 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1740 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1741 locations->SetOut(Location::RegisterLocation(R0));
1742 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1743}
1744
1745void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1746 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001747 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001748 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001749 codegen_->InvokeRuntime(
1750 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001751}
1752
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001753void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001754 LocationSummary* locations =
1755 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001756 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1757 if (location.IsStackSlot()) {
1758 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1759 } else if (location.IsDoubleStackSlot()) {
1760 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001761 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001762 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001763}
1764
1765void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001766 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001767 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001768}
1769
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001770void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001771 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001772 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001773 locations->SetInAt(0, Location::RequiresRegister());
1774 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001775}
1776
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001777void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1778 LocationSummary* locations = not_->GetLocations();
1779 Location out = locations->Out();
1780 Location in = locations->InAt(0);
1781 switch (not_->InputAt(0)->GetType()) {
1782 case Primitive::kPrimBoolean:
1783 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1784 break;
1785
1786 case Primitive::kPrimInt:
1787 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1788 break;
1789
1790 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001791 __ mvn(out.AsRegisterPairLow<Register>(),
1792 ShifterOperand(in.AsRegisterPairLow<Register>()));
1793 __ mvn(out.AsRegisterPairHigh<Register>(),
1794 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001795 break;
1796
1797 default:
1798 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1799 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001800}
1801
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001802void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001803 LocationSummary* locations =
1804 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001805 locations->SetInAt(0, Location::RequiresRegister());
1806 locations->SetInAt(1, Location::RequiresRegister());
1807 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001808}
1809
1810void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001811 LocationSummary* locations = compare->GetLocations();
1812 switch (compare->InputAt(0)->GetType()) {
1813 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001814 Register output = locations->Out().As<Register>();
1815 Location left = locations->InAt(0);
1816 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001817 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001818 __ cmp(left.AsRegisterPairHigh<Register>(),
1819 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001820 __ b(&less, LT);
1821 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001822 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1823 // the status flags.
1824 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001825 __ cmp(left.AsRegisterPairLow<Register>(),
1826 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001827 __ b(&done, EQ);
1828 __ b(&less, CC);
1829
1830 __ Bind(&greater);
1831 __ LoadImmediate(output, 1);
1832 __ b(&done);
1833
1834 __ Bind(&less);
1835 __ LoadImmediate(output, -1);
1836
1837 __ Bind(&done);
1838 break;
1839 }
1840 default:
1841 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1842 }
1843}
1844
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001845void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001846 LocationSummary* locations =
1847 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001848 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1849 locations->SetInAt(i, Location::Any());
1850 }
1851 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001852}
1853
1854void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001855 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001856 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001857}
1858
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001859void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001860 LocationSummary* locations =
1861 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001862 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001863 locations->SetInAt(0, Location::RequiresRegister());
1864 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001865 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001866 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001867 locations->AddTemp(Location::RequiresRegister());
1868 locations->AddTemp(Location::RequiresRegister());
1869 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001870}
1871
1872void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1873 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001874 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001875 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001876 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001877
1878 switch (field_type) {
1879 case Primitive::kPrimBoolean:
1880 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001881 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001882 __ StoreToOffset(kStoreByte, value, obj, offset);
1883 break;
1884 }
1885
1886 case Primitive::kPrimShort:
1887 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001888 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001889 __ StoreToOffset(kStoreHalfword, value, obj, offset);
1890 break;
1891 }
1892
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001893 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001894 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001895 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001896 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001897 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001898 Register temp = locations->GetTemp(0).As<Register>();
1899 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001900 codegen_->MarkGCCard(temp, card, obj, value);
1901 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001902 break;
1903 }
1904
1905 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001906 Location value = locations->InAt(1);
1907 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001908 break;
1909 }
1910
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00001911 case Primitive::kPrimFloat: {
1912 SRegister value = locations->InAt(1).As<SRegister>();
1913 __ StoreSToOffset(value, obj, offset);
1914 break;
1915 }
1916
1917 case Primitive::kPrimDouble: {
1918 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
1919 __ StoreDToOffset(value, obj, offset);
1920 break;
1921 }
1922
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001923 case Primitive::kPrimVoid:
1924 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001925 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001926 }
1927}
1928
1929void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001930 LocationSummary* locations =
1931 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001932 locations->SetInAt(0, Location::RequiresRegister());
1933 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001934}
1935
1936void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1937 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001938 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001939 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1940
1941 switch (instruction->GetType()) {
1942 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001943 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001944 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
1945 break;
1946 }
1947
1948 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001949 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001950 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
1951 break;
1952 }
1953
1954 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001955 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001956 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
1957 break;
1958 }
1959
1960 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001961 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001962 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
1963 break;
1964 }
1965
1966 case Primitive::kPrimInt:
1967 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001968 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001969 __ LoadFromOffset(kLoadWord, out, obj, offset);
1970 break;
1971 }
1972
1973 case Primitive::kPrimLong: {
1974 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001975 Location out = locations->Out();
1976 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001977 break;
1978 }
1979
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00001980 case Primitive::kPrimFloat: {
1981 SRegister out = locations->Out().As<SRegister>();
1982 __ LoadSFromOffset(out, obj, offset);
1983 break;
1984 }
1985
1986 case Primitive::kPrimDouble: {
1987 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
1988 __ LoadDFromOffset(out, obj, offset);
1989 break;
1990 }
1991
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001992 case Primitive::kPrimVoid:
1993 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001994 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001995 }
1996}
1997
1998void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001999 LocationSummary* locations =
2000 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002001 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002002 if (instruction->HasUses()) {
2003 locations->SetOut(Location::SameAsFirstInput());
2004 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002005}
2006
2007void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002008 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002009 codegen_->AddSlowPath(slow_path);
2010
2011 LocationSummary* locations = instruction->GetLocations();
2012 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002013
2014 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002015 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002016 __ b(slow_path->GetEntryLabel(), EQ);
2017 } else {
2018 DCHECK(obj.IsConstant()) << obj;
2019 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2020 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002021 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002022}
2023
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002024void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002025 LocationSummary* locations =
2026 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002027 locations->SetInAt(0, Location::RequiresRegister());
2028 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2029 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002030}
2031
2032void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2033 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002034 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002035 Location index = locations->InAt(1);
2036
2037 switch (instruction->GetType()) {
2038 case Primitive::kPrimBoolean: {
2039 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002040 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002041 if (index.IsConstant()) {
2042 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2043 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2044 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002045 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002046 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2047 }
2048 break;
2049 }
2050
2051 case Primitive::kPrimByte: {
2052 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002053 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002054 if (index.IsConstant()) {
2055 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2056 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2057 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002058 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002059 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2060 }
2061 break;
2062 }
2063
2064 case Primitive::kPrimShort: {
2065 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002066 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002067 if (index.IsConstant()) {
2068 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2069 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2070 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002071 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002072 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2073 }
2074 break;
2075 }
2076
2077 case Primitive::kPrimChar: {
2078 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002079 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002080 if (index.IsConstant()) {
2081 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2082 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2083 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002084 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002085 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2086 }
2087 break;
2088 }
2089
2090 case Primitive::kPrimInt:
2091 case Primitive::kPrimNot: {
2092 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2093 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002094 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002095 if (index.IsConstant()) {
2096 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2097 __ LoadFromOffset(kLoadWord, out, obj, offset);
2098 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002099 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002100 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2101 }
2102 break;
2103 }
2104
2105 case Primitive::kPrimLong: {
2106 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002107 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002108 if (index.IsConstant()) {
2109 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002110 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002111 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002112 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2113 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002114 }
2115 break;
2116 }
2117
2118 case Primitive::kPrimFloat:
2119 case Primitive::kPrimDouble:
2120 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002121 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002122 case Primitive::kPrimVoid:
2123 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002124 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002125 }
2126}
2127
2128void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002129 Primitive::Type value_type = instruction->GetComponentType();
2130 bool is_object = value_type == Primitive::kPrimNot;
2131 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2132 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
2133 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002134 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002135 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2136 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2137 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002138 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002139 locations->SetInAt(0, Location::RequiresRegister());
2140 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2141 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002142 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002143}
2144
2145void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
2146 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002147 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002148 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002149 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002150
2151 switch (value_type) {
2152 case Primitive::kPrimBoolean:
2153 case Primitive::kPrimByte: {
2154 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002155 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002156 if (index.IsConstant()) {
2157 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2158 __ StoreToOffset(kStoreByte, value, obj, offset);
2159 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002160 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002161 __ StoreToOffset(kStoreByte, value, IP, data_offset);
2162 }
2163 break;
2164 }
2165
2166 case Primitive::kPrimShort:
2167 case Primitive::kPrimChar: {
2168 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002169 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002170 if (index.IsConstant()) {
2171 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2172 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2173 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002174 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002175 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
2176 }
2177 break;
2178 }
2179
2180 case Primitive::kPrimInt: {
2181 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002182 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002183 if (index.IsConstant()) {
2184 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2185 __ StoreToOffset(kStoreWord, value, obj, offset);
2186 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002187 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002188 __ StoreToOffset(kStoreWord, value, IP, data_offset);
2189 }
2190 break;
2191 }
2192
2193 case Primitive::kPrimNot: {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002194 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002195 break;
2196 }
2197
2198 case Primitive::kPrimLong: {
2199 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002200 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002201 if (index.IsConstant()) {
2202 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002203 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002204 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002205 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2206 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002207 }
2208 break;
2209 }
2210
2211 case Primitive::kPrimFloat:
2212 case Primitive::kPrimDouble:
2213 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002214 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002215 case Primitive::kPrimVoid:
2216 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002217 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002218 }
2219}
2220
2221void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002222 LocationSummary* locations =
2223 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002224 locations->SetInAt(0, Location::RequiresRegister());
2225 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002226}
2227
2228void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
2229 LocationSummary* locations = instruction->GetLocations();
2230 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002231 Register obj = locations->InAt(0).As<Register>();
2232 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002233 __ LoadFromOffset(kLoadWord, out, obj, offset);
2234}
2235
2236void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002237 LocationSummary* locations =
2238 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002239 locations->SetInAt(0, Location::RequiresRegister());
2240 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002241 if (instruction->HasUses()) {
2242 locations->SetOut(Location::SameAsFirstInput());
2243 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002244}
2245
2246void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
2247 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002248 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002249 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002250 codegen_->AddSlowPath(slow_path);
2251
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002252 Register index = locations->InAt(0).As<Register>();
2253 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002254
2255 __ cmp(index, ShifterOperand(length));
2256 __ b(slow_path->GetEntryLabel(), CS);
2257}
2258
2259void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
2260 Label is_null;
2261 __ CompareAndBranchIfZero(value, &is_null);
2262 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
2263 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
2264 __ strb(card, Address(card, temp));
2265 __ Bind(&is_null);
2266}
2267
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002268void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
2269 temp->SetLocations(nullptr);
2270}
2271
2272void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
2273 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002274 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002275}
2276
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002277void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002278 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002279 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002280}
2281
2282void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002283 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2284}
2285
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002286void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2287 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2288}
2289
2290void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002291 HBasicBlock* block = instruction->GetBlock();
2292 if (block->GetLoopInformation() != nullptr) {
2293 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2294 // The back edge will generate the suspend check.
2295 return;
2296 }
2297 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2298 // The goto will generate the suspend check.
2299 return;
2300 }
2301 GenerateSuspendCheck(instruction, nullptr);
2302}
2303
2304void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
2305 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002306 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002307 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002308 codegen_->AddSlowPath(slow_path);
2309
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002310 __ LoadFromOffset(
2311 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
2312 __ cmp(IP, ShifterOperand(0));
2313 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002314 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002315 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002316 __ Bind(slow_path->GetReturnLabel());
2317 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002318 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002319 __ b(slow_path->GetEntryLabel());
2320 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002321}
2322
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002323ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2324 return codegen_->GetAssembler();
2325}
2326
2327void ParallelMoveResolverARM::EmitMove(size_t index) {
2328 MoveOperands* move = moves_.Get(index);
2329 Location source = move->GetSource();
2330 Location destination = move->GetDestination();
2331
2332 if (source.IsRegister()) {
2333 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002334 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002335 } else {
2336 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002337 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002338 SP, destination.GetStackIndex());
2339 }
2340 } else if (source.IsStackSlot()) {
2341 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002342 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002343 SP, source.GetStackIndex());
2344 } else {
2345 DCHECK(destination.IsStackSlot());
2346 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2347 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2348 }
2349 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002350 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002351 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002352 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2353 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002354 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002355 } else {
2356 DCHECK(destination.IsStackSlot());
2357 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002358 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002359 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002360 }
2361}
2362
2363void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2364 __ Mov(IP, reg);
2365 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2366 __ StoreToOffset(kStoreWord, IP, SP, mem);
2367}
2368
2369void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2370 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2371 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2372 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2373 SP, mem1 + stack_offset);
2374 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2375 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2376 SP, mem2 + stack_offset);
2377 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2378}
2379
2380void ParallelMoveResolverARM::EmitSwap(size_t index) {
2381 MoveOperands* move = moves_.Get(index);
2382 Location source = move->GetSource();
2383 Location destination = move->GetDestination();
2384
2385 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002386 DCHECK_NE(source.As<Register>(), IP);
2387 DCHECK_NE(destination.As<Register>(), IP);
2388 __ Mov(IP, source.As<Register>());
2389 __ Mov(source.As<Register>(), destination.As<Register>());
2390 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002391 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002392 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002393 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002394 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002395 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2396 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2397 } else {
2398 LOG(FATAL) << "Unimplemented";
2399 }
2400}
2401
2402void ParallelMoveResolverARM::SpillScratch(int reg) {
2403 __ Push(static_cast<Register>(reg));
2404}
2405
2406void ParallelMoveResolverARM::RestoreScratch(int reg) {
2407 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002408}
2409
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002410void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002411 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
2412 ? LocationSummary::kCallOnSlowPath
2413 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002414 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002415 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002416 locations->SetOut(Location::RequiresRegister());
2417}
2418
2419void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2420 Register out = cls->GetLocations()->Out().As<Register>();
2421 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002422 DCHECK(!cls->CanCallRuntime());
2423 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002424 codegen_->LoadCurrentMethod(out);
2425 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2426 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002427 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002428 codegen_->LoadCurrentMethod(out);
2429 __ LoadFromOffset(
2430 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2431 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002432
2433 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2434 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2435 codegen_->AddSlowPath(slow_path);
2436 __ cmp(out, ShifterOperand(0));
2437 __ b(slow_path->GetEntryLabel(), EQ);
2438 if (cls->MustGenerateClinitCheck()) {
2439 GenerateClassInitializationCheck(slow_path, out);
2440 } else {
2441 __ Bind(slow_path->GetExitLabel());
2442 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002443 }
2444}
2445
2446void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2447 LocationSummary* locations =
2448 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2449 locations->SetInAt(0, Location::RequiresRegister());
2450 if (check->HasUses()) {
2451 locations->SetOut(Location::SameAsFirstInput());
2452 }
2453}
2454
2455void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002456 // We assume the class is not null.
2457 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2458 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002459 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002460 GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>());
2461}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002462
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002463void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
2464 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002465 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2466 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2467 __ b(slow_path->GetEntryLabel(), LT);
2468 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2469 // properly. Therefore, we do a memory fence.
2470 __ dmb(ISH);
2471 __ Bind(slow_path->GetExitLabel());
2472}
2473
2474void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2475 LocationSummary* locations =
2476 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2477 locations->SetInAt(0, Location::RequiresRegister());
2478 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2479}
2480
2481void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2482 LocationSummary* locations = instruction->GetLocations();
2483 Register cls = locations->InAt(0).As<Register>();
2484 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2485
2486 switch (instruction->GetType()) {
2487 case Primitive::kPrimBoolean: {
2488 Register out = locations->Out().As<Register>();
2489 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2490 break;
2491 }
2492
2493 case Primitive::kPrimByte: {
2494 Register out = locations->Out().As<Register>();
2495 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2496 break;
2497 }
2498
2499 case Primitive::kPrimShort: {
2500 Register out = locations->Out().As<Register>();
2501 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2502 break;
2503 }
2504
2505 case Primitive::kPrimChar: {
2506 Register out = locations->Out().As<Register>();
2507 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2508 break;
2509 }
2510
2511 case Primitive::kPrimInt:
2512 case Primitive::kPrimNot: {
2513 Register out = locations->Out().As<Register>();
2514 __ LoadFromOffset(kLoadWord, out, cls, offset);
2515 break;
2516 }
2517
2518 case Primitive::kPrimLong: {
2519 // TODO: support volatile.
2520 Location out = locations->Out();
2521 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2522 break;
2523 }
2524
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002525 case Primitive::kPrimFloat: {
2526 SRegister out = locations->Out().As<SRegister>();
2527 __ LoadSFromOffset(out, cls, offset);
2528 break;
2529 }
2530
2531 case Primitive::kPrimDouble: {
2532 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2533 __ LoadDFromOffset(out, cls, offset);
2534 break;
2535 }
2536
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002537 case Primitive::kPrimVoid:
2538 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2539 UNREACHABLE();
2540 }
2541}
2542
2543void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2544 LocationSummary* locations =
2545 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2546 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
2547 locations->SetInAt(0, Location::RequiresRegister());
2548 locations->SetInAt(1, Location::RequiresRegister());
2549 // Temporary registers for the write barrier.
2550 if (is_object_type) {
2551 locations->AddTemp(Location::RequiresRegister());
2552 locations->AddTemp(Location::RequiresRegister());
2553 }
2554}
2555
2556void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2557 LocationSummary* locations = instruction->GetLocations();
2558 Register cls = locations->InAt(0).As<Register>();
2559 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2560 Primitive::Type field_type = instruction->GetFieldType();
2561
2562 switch (field_type) {
2563 case Primitive::kPrimBoolean:
2564 case Primitive::kPrimByte: {
2565 Register value = locations->InAt(1).As<Register>();
2566 __ StoreToOffset(kStoreByte, value, cls, offset);
2567 break;
2568 }
2569
2570 case Primitive::kPrimShort:
2571 case Primitive::kPrimChar: {
2572 Register value = locations->InAt(1).As<Register>();
2573 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2574 break;
2575 }
2576
2577 case Primitive::kPrimInt:
2578 case Primitive::kPrimNot: {
2579 Register value = locations->InAt(1).As<Register>();
2580 __ StoreToOffset(kStoreWord, value, cls, offset);
2581 if (field_type == Primitive::kPrimNot) {
2582 Register temp = locations->GetTemp(0).As<Register>();
2583 Register card = locations->GetTemp(1).As<Register>();
2584 codegen_->MarkGCCard(temp, card, cls, value);
2585 }
2586 break;
2587 }
2588
2589 case Primitive::kPrimLong: {
2590 Location value = locations->InAt(1);
2591 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2592 break;
2593 }
2594
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002595 case Primitive::kPrimFloat: {
2596 SRegister value = locations->InAt(1).As<SRegister>();
2597 __ StoreSToOffset(value, cls, offset);
2598 break;
2599 }
2600
2601 case Primitive::kPrimDouble: {
2602 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
2603 __ StoreDToOffset(value, cls, offset);
2604 break;
2605 }
2606
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002607 case Primitive::kPrimVoid:
2608 LOG(FATAL) << "Unreachable type " << field_type;
2609 UNREACHABLE();
2610 }
2611}
2612
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002613void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
2614 LocationSummary* locations =
2615 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2616 locations->SetOut(Location::RequiresRegister());
2617}
2618
2619void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
2620 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
2621 codegen_->AddSlowPath(slow_path);
2622
2623 Register out = load->GetLocations()->Out().As<Register>();
2624 codegen_->LoadCurrentMethod(out);
2625 __ LoadFromOffset(
2626 kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value());
2627 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2628 __ cmp(out, ShifterOperand(0));
2629 __ b(slow_path->GetEntryLabel(), EQ);
2630 __ Bind(slow_path->GetExitLabel());
2631}
2632
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002633void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
2634 LocationSummary* locations =
2635 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2636 locations->SetOut(Location::RequiresRegister());
2637}
2638
2639void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
2640 Register out = load->GetLocations()->Out().As<Register>();
2641 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
2642 __ LoadFromOffset(kLoadWord, out, TR, offset);
2643 __ LoadImmediate(IP, 0);
2644 __ StoreToOffset(kStoreWord, IP, TR, offset);
2645}
2646
2647void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
2648 LocationSummary* locations =
2649 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2650 InvokeRuntimeCallingConvention calling_convention;
2651 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2652}
2653
2654void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
2655 codegen_->InvokeRuntime(
2656 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
2657}
2658
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002659void LocationsBuilderARM::VisitTypeCheck(HTypeCheck* instruction) {
2660 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
2661 ? LocationSummary::kNoCall
2662 : LocationSummary::kCallOnSlowPath;
2663 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2664 locations->SetInAt(0, Location::RequiresRegister());
2665 locations->SetInAt(1, Location::RequiresRegister());
2666 locations->SetOut(Location::RequiresRegister());
2667}
2668
2669void InstructionCodeGeneratorARM::VisitTypeCheck(HTypeCheck* instruction) {
2670 LocationSummary* locations = instruction->GetLocations();
2671 Register obj = locations->InAt(0).As<Register>();
2672 Register cls = locations->InAt(1).As<Register>();
2673 Register out = locations->Out().As<Register>();
2674 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2675 Label done, zero;
2676 SlowPathCodeARM* slow_path = nullptr;
2677
2678 // Return 0 if `obj` is null.
2679 // TODO: avoid this check if we know obj is not null.
2680 __ cmp(obj, ShifterOperand(0));
2681 __ b(&zero, EQ);
2682 // Compare the class of `obj` with `cls`.
2683 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
2684 __ cmp(out, ShifterOperand(cls));
2685 if (instruction->IsClassFinal()) {
2686 // Classes must be equal for the instanceof to succeed.
2687 __ b(&zero, NE);
2688 __ LoadImmediate(out, 1);
2689 __ b(&done);
2690 } else {
2691 // If the classes are not equal, we go into a slow path.
2692 DCHECK(locations->OnlyCallsOnSlowPath());
2693 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
2694 instruction, Location::RegisterLocation(out));
2695 codegen_->AddSlowPath(slow_path);
2696 __ b(slow_path->GetEntryLabel(), NE);
2697 __ LoadImmediate(out, 1);
2698 __ b(&done);
2699 }
2700 __ Bind(&zero);
2701 __ LoadImmediate(out, 0);
2702 if (slow_path != nullptr) {
2703 __ Bind(slow_path->GetExitLabel());
2704 }
2705 __ Bind(&done);
2706}
2707
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002708} // namespace arm
2709} // namespace art