blob: 746d4afeec4a57e49ac66a5388c5abc1e0337d3b [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/arm/assembler_arm.h"
26#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000027#include "utils/assembler.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
Calin Juravled6fb6cf2014-11-11 19:07:44 +000044static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2, R3 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010045static 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());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000172 // We're moving two locations to locations that could overlap, so we need a parallel
173 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100174 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000175 codegen->EmitParallelMoves(
176 index_location_,
177 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
178 length_location_,
179 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100180 arm_codegen->InvokeRuntime(
181 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100182 }
183
184 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100185 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100186 const Location index_location_;
187 const Location length_location_;
188
189 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
190};
191
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000192class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100193 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000194 LoadClassSlowPathARM(HLoadClass* cls,
195 HInstruction* at,
196 uint32_t dex_pc,
197 bool do_clinit)
198 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
199 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
200 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100201
202 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000203 LocationSummary* locations = at_->GetLocations();
204
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100205 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
206 __ Bind(GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000207 codegen->SaveLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100208
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100209 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000210 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100211 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000212 int32_t entry_point_offset = do_clinit_
213 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
214 : QUICK_ENTRY_POINT(pInitializeType);
215 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_);
216
217 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000218 Location out = locations->Out();
219 if (out.IsValid()) {
220 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000221 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
222 }
223 codegen->RestoreLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100224 __ b(GetExitLabel());
225 }
226
227 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000228 // The class this slow path will load.
229 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100230
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000231 // The instruction where this slow path is happening.
232 // (Might be the load class or an initialization check).
233 HInstruction* const at_;
234
235 // The dex PC of `at_`.
236 const uint32_t dex_pc_;
237
238 // Whether to initialize the class.
239 const bool do_clinit_;
240
241 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100242};
243
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000244class LoadStringSlowPathARM : public SlowPathCodeARM {
245 public:
246 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
247
248 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
249 LocationSummary* locations = instruction_->GetLocations();
250 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
251
252 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
253 __ Bind(GetEntryLabel());
254 codegen->SaveLiveRegisters(locations);
255
256 InvokeRuntimeCallingConvention calling_convention;
257 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0));
258 __ LoadImmediate(calling_convention.GetRegisterAt(1), instruction_->GetStringIndex());
259 arm_codegen->InvokeRuntime(
260 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
261 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
262
263 codegen->RestoreLiveRegisters(locations);
264 __ b(GetExitLabel());
265 }
266
267 private:
268 HLoadString* const instruction_;
269
270 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
271};
272
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000273class TypeCheckSlowPathARM : public SlowPathCodeARM {
274 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000275 TypeCheckSlowPathARM(HInstruction* instruction,
276 Location class_to_check,
277 Location object_class,
278 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000279 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000280 class_to_check_(class_to_check),
281 object_class_(object_class),
282 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000283
284 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
285 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000286 DCHECK(instruction_->IsCheckCast()
287 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000288
289 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
290 __ Bind(GetEntryLabel());
291 codegen->SaveLiveRegisters(locations);
292
293 // We're moving two locations to locations that could overlap, so we need a parallel
294 // move resolver.
295 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000296 codegen->EmitParallelMoves(
297 class_to_check_,
298 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
299 object_class_,
300 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000301
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000302 if (instruction_->IsInstanceOf()) {
303 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_);
304 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
305 } else {
306 DCHECK(instruction_->IsCheckCast());
307 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_);
308 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000309
310 codegen->RestoreLiveRegisters(locations);
311 __ b(GetExitLabel());
312 }
313
314 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000315 HInstruction* const instruction_;
316 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000317 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000318 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000319
320 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
321};
322
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000323#undef __
324
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100325#undef __
326#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700327
328inline Condition ARMCondition(IfCondition cond) {
329 switch (cond) {
330 case kCondEQ: return EQ;
331 case kCondNE: return NE;
332 case kCondLT: return LT;
333 case kCondLE: return LE;
334 case kCondGT: return GT;
335 case kCondGE: return GE;
336 default:
337 LOG(FATAL) << "Unknown if condition";
338 }
339 return EQ; // Unreachable.
340}
341
342inline Condition ARMOppositeCondition(IfCondition cond) {
343 switch (cond) {
344 case kCondEQ: return NE;
345 case kCondNE: return EQ;
346 case kCondLT: return GE;
347 case kCondLE: return GT;
348 case kCondGT: return LE;
349 case kCondGE: return LT;
350 default:
351 LOG(FATAL) << "Unknown if condition";
352 }
353 return EQ; // Unreachable.
354}
355
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100356void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
357 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
358}
359
360void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000361 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100362}
363
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100364size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
365 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
366 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100367}
368
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100369size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
370 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
371 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100372}
373
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100374CodeGeneratorARM::CodeGeneratorARM(HGraph* graph)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000375 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100376 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100377 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100378 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100379 move_resolver_(graph->GetArena(), this),
380 assembler_(true) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100381
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100382size_t CodeGeneratorARM::FrameEntrySpillSize() const {
383 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
384}
385
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100386Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100387 switch (type) {
388 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100389 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100390 ArmManagedRegister pair =
391 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100392 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
393 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
394
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100395 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
396 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100397 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100398 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100399 }
400
401 case Primitive::kPrimByte:
402 case Primitive::kPrimBoolean:
403 case Primitive::kPrimChar:
404 case Primitive::kPrimShort:
405 case Primitive::kPrimInt:
406 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100407 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100408 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100409 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
410 ArmManagedRegister current =
411 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
412 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100413 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100414 }
415 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100416 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100417 }
418
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000419 case Primitive::kPrimFloat: {
420 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100421 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100422 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100423
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000424 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000425 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
426 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000427 return Location::FpuRegisterPairLocation(reg, reg + 1);
428 }
429
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100430 case Primitive::kPrimVoid:
431 LOG(FATAL) << "Unreachable type " << type;
432 }
433
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100434 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100435}
436
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100437void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100438 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100439 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100440
441 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100442 blocked_core_registers_[SP] = true;
443 blocked_core_registers_[LR] = true;
444 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100445
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100446 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100447 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100448
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100449 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100450 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100451
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100452 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100453 // We always save and restore R6 and R7 to make sure we can use three
454 // register pairs for long operations.
Nicolas Geoffray44b819e2014-11-06 12:00:54 +0000455 blocked_core_registers_[R4] = true;
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100456 blocked_core_registers_[R5] = true;
457 blocked_core_registers_[R8] = true;
458 blocked_core_registers_[R10] = true;
459 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100460
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000461 blocked_fpu_registers_[S16] = true;
462 blocked_fpu_registers_[S17] = true;
463 blocked_fpu_registers_[S18] = true;
464 blocked_fpu_registers_[S19] = true;
465 blocked_fpu_registers_[S20] = true;
466 blocked_fpu_registers_[S21] = true;
467 blocked_fpu_registers_[S22] = true;
468 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000469 blocked_fpu_registers_[S24] = true;
470 blocked_fpu_registers_[S25] = true;
471 blocked_fpu_registers_[S26] = true;
472 blocked_fpu_registers_[S27] = true;
473 blocked_fpu_registers_[S28] = true;
474 blocked_fpu_registers_[S29] = true;
475 blocked_fpu_registers_[S30] = true;
476 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100477
478 UpdateBlockedPairRegisters();
479}
480
481void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
482 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
483 ArmManagedRegister current =
484 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
485 if (blocked_core_registers_[current.AsRegisterPairLow()]
486 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
487 blocked_register_pairs_[i] = true;
488 }
489 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100490}
491
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100492InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
493 : HGraphVisitor(graph),
494 assembler_(codegen->GetAssembler()),
495 codegen_(codegen) {}
496
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000497void CodeGeneratorARM::GenerateFrameEntry() {
Dave Allison648d7112014-07-25 16:15:27 -0700498 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100499 if (!skip_overflow_check) {
500 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100501 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100502 AddSlowPath(slow_path);
503
504 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
505 __ cmp(SP, ShifterOperand(IP));
506 __ b(slow_path->GetEntryLabel(), CC);
507 } else {
508 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100509 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100510 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100511 }
512 }
513
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100514 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
515 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000516
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100517 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100518 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100519 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000520}
521
522void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100523 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100524 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000525}
526
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100527void CodeGeneratorARM::Bind(HBasicBlock* block) {
528 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000529}
530
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100531Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
532 switch (load->GetType()) {
533 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100534 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100535 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
536 break;
537
538 case Primitive::kPrimInt:
539 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100540 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100541 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100542
543 case Primitive::kPrimBoolean:
544 case Primitive::kPrimByte:
545 case Primitive::kPrimChar:
546 case Primitive::kPrimShort:
547 case Primitive::kPrimVoid:
548 LOG(FATAL) << "Unexpected type " << load->GetType();
549 }
550
551 LOG(FATAL) << "Unreachable";
552 return Location();
553}
554
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100555Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
556 switch (type) {
557 case Primitive::kPrimBoolean:
558 case Primitive::kPrimByte:
559 case Primitive::kPrimChar:
560 case Primitive::kPrimShort:
561 case Primitive::kPrimInt:
562 case Primitive::kPrimNot: {
563 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 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100566 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100567 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000568 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100569 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100570 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100571
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000572 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100573 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000574 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100575 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000576 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100577 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100578 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
579 calling_convention.GetRegisterPairAt(index));
580 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100581 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000582 return Location::QuickParameter(index, stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100583 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000584 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
585 }
586 }
587
588 case Primitive::kPrimFloat: {
589 uint32_t stack_index = stack_index_++;
590 if (float_index_ % 2 == 0) {
591 float_index_ = std::max(double_index_, float_index_);
592 }
593 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
594 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
595 } else {
596 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
597 }
598 }
599
600 case Primitive::kPrimDouble: {
601 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
602 uint32_t stack_index = stack_index_;
603 stack_index_ += 2;
604 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
605 uint32_t index = double_index_;
606 double_index_ += 2;
607 return Location::FpuRegisterPairLocation(
608 calling_convention.GetFpuRegisterAt(index),
609 calling_convention.GetFpuRegisterAt(index + 1));
610 } else {
611 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100612 }
613 }
614
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100615 case Primitive::kPrimVoid:
616 LOG(FATAL) << "Unexpected parameter type " << type;
617 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100618 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100619 return Location();
620}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100621
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000622Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
623 switch (type) {
624 case Primitive::kPrimBoolean:
625 case Primitive::kPrimByte:
626 case Primitive::kPrimChar:
627 case Primitive::kPrimShort:
628 case Primitive::kPrimInt:
629 case Primitive::kPrimNot: {
630 return Location::RegisterLocation(R0);
631 }
632
633 case Primitive::kPrimFloat: {
634 return Location::FpuRegisterLocation(S0);
635 }
636
637 case Primitive::kPrimLong: {
638 return Location::RegisterPairLocation(R0, R1);
639 }
640
641 case Primitive::kPrimDouble: {
642 return Location::FpuRegisterPairLocation(S0, S1);
643 }
644
645 case Primitive::kPrimVoid:
646 return Location();
647 }
648 UNREACHABLE();
649 return Location();
650}
651
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100652void CodeGeneratorARM::Move32(Location destination, Location source) {
653 if (source.Equals(destination)) {
654 return;
655 }
656 if (destination.IsRegister()) {
657 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100658 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100659 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000660 __ vmovrs(destination.As<Register>(), source.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100661 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100662 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100663 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100664 } else if (destination.IsFpuRegister()) {
665 if (source.IsRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000666 __ vmovsr(destination.As<SRegister>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100667 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000668 __ vmovs(destination.As<SRegister>(), source.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100669 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000670 __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100671 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100672 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000673 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100674 if (source.IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100675 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100676 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000677 __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100678 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000679 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100680 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
681 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100682 }
683 }
684}
685
686void CodeGeneratorARM::Move64(Location destination, Location source) {
687 if (source.Equals(destination)) {
688 return;
689 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100690 if (destination.IsRegisterPair()) {
691 if (source.IsRegisterPair()) {
692 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
693 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100694 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000695 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100696 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000697 uint16_t register_index = source.GetQuickParameterRegisterIndex();
698 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100699 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100700 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000701 calling_convention.GetRegisterAt(register_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100702 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000703 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100704 } else {
705 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100706 if (destination.AsRegisterPairLow<Register>() == R1) {
707 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100708 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
709 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100710 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100711 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100712 SP, source.GetStackIndex());
713 }
714 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000715 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100716 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000717 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
718 SP,
719 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100720 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000721 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100722 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100723 } else if (destination.IsQuickParameter()) {
724 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000725 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
726 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100727 if (source.IsRegisterPair()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000728 __ Mov(calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100729 source.AsRegisterPairLow<Register>());
730 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000731 SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100732 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000733 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100734 } else {
735 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000736 __ LoadFromOffset(
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000737 kLoadWord, calling_convention.GetRegisterAt(register_index), SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100738 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000739 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100740 }
741 } else {
742 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100743 if (source.IsRegisterPair()) {
744 if (source.AsRegisterPairLow<Register>() == R1) {
745 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100746 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
747 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100748 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100749 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100750 SP, destination.GetStackIndex());
751 }
752 } else if (source.IsQuickParameter()) {
753 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000754 uint16_t register_index = source.GetQuickParameterRegisterIndex();
755 uint16_t stack_index = source.GetQuickParameterStackIndex();
756 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100757 SP, destination.GetStackIndex());
758 __ LoadFromOffset(kLoadWord, R0,
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000759 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100760 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000761 } else if (source.IsFpuRegisterPair()) {
762 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
763 SP,
764 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100765 } else {
766 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100767 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
768 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
769 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
770 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100771 }
772 }
773}
774
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100775void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100776 LocationSummary* locations = instruction->GetLocations();
777 if (locations != nullptr && locations->Out().Equals(location)) {
778 return;
779 }
780
Calin Juravlea21f5982014-11-13 15:53:04 +0000781 if (locations != nullptr && locations->Out().IsConstant()) {
782 HConstant* const_to_move = locations->Out().GetConstant();
783 if (const_to_move->IsIntConstant()) {
784 int32_t value = const_to_move->AsIntConstant()->GetValue();
785 if (location.IsRegister()) {
786 __ LoadImmediate(location.As<Register>(), value);
787 } else {
788 DCHECK(location.IsStackSlot());
789 __ LoadImmediate(IP, value);
790 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
791 }
792 } else if (const_to_move->IsLongConstant()) {
793 int64_t value = const_to_move->AsLongConstant()->GetValue();
794 if (location.IsRegisterPair()) {
795 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
796 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
797 } else {
798 DCHECK(location.IsDoubleStackSlot());
799 __ LoadImmediate(IP, Low32Bits(value));
800 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
801 __ LoadImmediate(IP, High32Bits(value));
802 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
803 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100804 }
Roland Levillain476df552014-10-09 17:51:36 +0100805 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100806 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
807 switch (instruction->GetType()) {
808 case Primitive::kPrimBoolean:
809 case Primitive::kPrimByte:
810 case Primitive::kPrimChar:
811 case Primitive::kPrimShort:
812 case Primitive::kPrimInt:
813 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100814 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100815 Move32(location, Location::StackSlot(stack_slot));
816 break;
817
818 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100819 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100820 Move64(location, Location::DoubleStackSlot(stack_slot));
821 break;
822
823 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100824 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100825 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000826 } else if (instruction->IsTemporary()) {
827 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000828 if (temp_location.IsStackSlot()) {
829 Move32(location, temp_location);
830 } else {
831 DCHECK(temp_location.IsDoubleStackSlot());
832 Move64(location, temp_location);
833 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000834 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100835 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100836 switch (instruction->GetType()) {
837 case Primitive::kPrimBoolean:
838 case Primitive::kPrimByte:
839 case Primitive::kPrimChar:
840 case Primitive::kPrimShort:
841 case Primitive::kPrimNot:
842 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100843 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100844 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100845 break;
846
847 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100848 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100849 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100850 break;
851
852 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100853 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100854 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000855 }
856}
857
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100858void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
859 HInstruction* instruction,
860 uint32_t dex_pc) {
861 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
862 __ blx(LR);
863 RecordPcInfo(instruction, dex_pc);
864 DCHECK(instruction->IsSuspendCheck()
865 || instruction->IsBoundsCheck()
866 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000867 || instruction->IsDivZeroCheck()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100868 || !IsLeafMethod());
869}
870
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000871void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000872 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000873}
874
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000875void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000876 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100877 DCHECK(!successor->IsExitBlock());
878
879 HBasicBlock* block = got->GetBlock();
880 HInstruction* previous = got->GetPrevious();
881
882 HLoopInformation* info = block->GetLoopInformation();
883 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
884 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
885 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
886 return;
887 }
888
889 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
890 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
891 }
892 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000893 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000894 }
895}
896
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000897void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000898 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000899}
900
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000901void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700902 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000903 if (kIsDebugBuild) {
904 __ Comment("Unreachable");
905 __ bkpt(0);
906 }
907}
908
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000909void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100910 LocationSummary* locations =
911 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100912 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100913 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100914 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100915 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000916}
917
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000918void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700919 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100920 if (cond->IsIntConstant()) {
921 // Constant condition, statically compared against 1.
922 int32_t cond_value = cond->AsIntConstant()->GetValue();
923 if (cond_value == 1) {
924 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
925 if_instr->IfTrueSuccessor())) {
926 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100927 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100928 return;
929 } else {
930 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100931 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100932 } else {
933 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
934 // Condition has been materialized, compare the output to 0
935 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
936 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
937 ShifterOperand(0));
938 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
939 } else {
940 // Condition has not been materialized, use its inputs as the
941 // comparison and its condition as the branch condition.
942 LocationSummary* locations = cond->GetLocations();
943 if (locations->InAt(1).IsRegister()) {
944 __ cmp(locations->InAt(0).As<Register>(),
945 ShifterOperand(locations->InAt(1).As<Register>()));
946 } else {
947 DCHECK(locations->InAt(1).IsConstant());
948 int32_t value =
949 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
950 ShifterOperand operand;
951 if (ShifterOperand::CanHoldArm(value, &operand)) {
952 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
953 } else {
954 Register temp = IP;
955 __ LoadImmediate(temp, value);
956 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
957 }
958 }
959 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
960 ARMCondition(cond->AsCondition()->GetCondition()));
961 }
Dave Allison20dfc792014-06-16 20:44:29 -0700962 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100963 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
964 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700965 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000966 }
967}
968
Dave Allison20dfc792014-06-16 20:44:29 -0700969
970void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100971 LocationSummary* locations =
972 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100973 locations->SetInAt(0, Location::RequiresRegister());
974 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100975 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100976 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100977 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000978}
979
Dave Allison20dfc792014-06-16 20:44:29 -0700980void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100981 if (!comp->NeedsMaterialization()) return;
982
983 LocationSummary* locations = comp->GetLocations();
984 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100985 __ cmp(locations->InAt(0).As<Register>(),
986 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100987 } else {
988 DCHECK(locations->InAt(1).IsConstant());
989 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
990 ShifterOperand operand;
991 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100992 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100993 } else {
994 Register temp = IP;
995 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100996 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100997 }
Dave Allison20dfc792014-06-16 20:44:29 -0700998 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100999 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001000 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001001 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001002 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001003 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001004}
1005
1006void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1007 VisitCondition(comp);
1008}
1009
1010void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1011 VisitCondition(comp);
1012}
1013
1014void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1015 VisitCondition(comp);
1016}
1017
1018void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1019 VisitCondition(comp);
1020}
1021
1022void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1023 VisitCondition(comp);
1024}
1025
1026void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1027 VisitCondition(comp);
1028}
1029
1030void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1031 VisitCondition(comp);
1032}
1033
1034void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1035 VisitCondition(comp);
1036}
1037
1038void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1039 VisitCondition(comp);
1040}
1041
1042void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1043 VisitCondition(comp);
1044}
1045
1046void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1047 VisitCondition(comp);
1048}
1049
1050void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1051 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001052}
1053
1054void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001055 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001056}
1057
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001058void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1059 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001060}
1061
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001062void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001063 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001064}
1065
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001066void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001067 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001068 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001069}
1070
1071void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001072 LocationSummary* locations =
1073 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001074 switch (store->InputAt(1)->GetType()) {
1075 case Primitive::kPrimBoolean:
1076 case Primitive::kPrimByte:
1077 case Primitive::kPrimChar:
1078 case Primitive::kPrimShort:
1079 case Primitive::kPrimInt:
1080 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001081 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001082 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1083 break;
1084
1085 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001086 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001087 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1088 break;
1089
1090 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001091 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001092 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001093}
1094
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001095void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001096 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001097}
1098
1099void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001100 LocationSummary* locations =
1101 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001102 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001103}
1104
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001105void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001106 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001107 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001108}
1109
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001110void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001111 LocationSummary* locations =
1112 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001113 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001114}
1115
1116void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1117 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001118 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001119}
1120
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001121void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1122 LocationSummary* locations =
1123 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1124 locations->SetOut(Location::ConstantLocation(constant));
1125}
1126
1127void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1128 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001129 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001130}
1131
1132void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1133 LocationSummary* locations =
1134 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1135 locations->SetOut(Location::ConstantLocation(constant));
1136}
1137
1138void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1139 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001140 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001141}
1142
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001143void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001144 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001145}
1146
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001147void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001148 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001149 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001150}
1151
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001152void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001153 LocationSummary* locations =
1154 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001155 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001156}
1157
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001158void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001159 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001160 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001161}
1162
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001163void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001164 HandleInvoke(invoke);
1165}
1166
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001167void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001168 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001169}
1170
1171void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001172 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001173
1174 // TODO: Implement all kinds of calls:
1175 // 1) boot -> boot
1176 // 2) app -> boot
1177 // 3) app -> app
1178 //
1179 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1180
1181 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001182 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001183 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001184 __ LoadFromOffset(
1185 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001186 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001187 __ LoadFromOffset(
1188 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001189 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001190 __ LoadFromOffset(kLoadWord, LR, temp,
1191 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001192 // LR()
1193 __ blx(LR);
1194
1195 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1196 DCHECK(!codegen_->IsLeafMethod());
1197}
1198
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001199void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001200 LocationSummary* locations =
1201 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001202 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001203
1204 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001205 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001206 HInstruction* input = invoke->InputAt(i);
1207 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1208 }
1209
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001210 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001211}
1212
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001213void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1214 HandleInvoke(invoke);
1215}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001216
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001217void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001218 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001219 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1220 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1221 LocationSummary* locations = invoke->GetLocations();
1222 Location receiver = locations->InAt(0);
1223 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1224 // temp = object->GetClass();
1225 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001226 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1227 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001228 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001229 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001230 }
1231 // temp = temp->GetMethodAt(method_offset);
1232 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001233 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001234 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001235 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001236 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001237 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001238 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001239 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001240}
1241
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001242void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1243 HandleInvoke(invoke);
1244 // Add the hidden argument.
1245 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1246}
1247
1248void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1249 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1250 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
1251 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1252 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1253 LocationSummary* locations = invoke->GetLocations();
1254 Location receiver = locations->InAt(0);
1255 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1256
1257 // Set the hidden argument.
1258 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).As<Register>(), invoke->GetDexMethodIndex());
1259
1260 // temp = object->GetClass();
1261 if (receiver.IsStackSlot()) {
1262 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1263 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1264 } else {
1265 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
1266 }
1267 // temp = temp->GetImtEntryAt(method_offset);
1268 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
1269 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1270 // LR = temp->GetEntryPoint();
1271 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1272 // LR();
1273 __ blx(LR);
1274 DCHECK(!codegen_->IsLeafMethod());
1275 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1276}
1277
Roland Levillain88cb1752014-10-20 16:36:47 +01001278void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1279 LocationSummary* locations =
1280 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1281 switch (neg->GetResultType()) {
1282 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001283 case Primitive::kPrimLong: {
1284 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001285 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001286 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001287 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001288 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001289
Roland Levillain88cb1752014-10-20 16:36:47 +01001290 case Primitive::kPrimFloat:
1291 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001292 locations->SetInAt(0, Location::RequiresFpuRegister());
1293 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001294 break;
1295
1296 default:
1297 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1298 }
1299}
1300
1301void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1302 LocationSummary* locations = neg->GetLocations();
1303 Location out = locations->Out();
1304 Location in = locations->InAt(0);
1305 switch (neg->GetResultType()) {
1306 case Primitive::kPrimInt:
1307 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001308 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001309 break;
1310
1311 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001312 DCHECK(in.IsRegisterPair());
1313 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1314 __ rsbs(out.AsRegisterPairLow<Register>(),
1315 in.AsRegisterPairLow<Register>(),
1316 ShifterOperand(0));
1317 // We cannot emit an RSC (Reverse Subtract with Carry)
1318 // instruction here, as it does not exist in the Thumb-2
1319 // instruction set. We use the following approach
1320 // using SBC and SUB instead.
1321 //
1322 // out.hi = -C
1323 __ sbc(out.AsRegisterPairHigh<Register>(),
1324 out.AsRegisterPairHigh<Register>(),
1325 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1326 // out.hi = out.hi - in.hi
1327 __ sub(out.AsRegisterPairHigh<Register>(),
1328 out.AsRegisterPairHigh<Register>(),
1329 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1330 break;
1331
Roland Levillain88cb1752014-10-20 16:36:47 +01001332 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001333 DCHECK(in.IsFpuRegister());
1334 __ vnegs(out.As<SRegister>(), in.As<SRegister>());
1335 break;
1336
Roland Levillain88cb1752014-10-20 16:36:47 +01001337 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001338 DCHECK(in.IsFpuRegisterPair());
1339 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1340 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001341 break;
1342
1343 default:
1344 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1345 }
1346}
1347
Roland Levillaindff1f282014-11-05 14:15:05 +00001348void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
1349 LocationSummary* locations =
1350 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
1351 Primitive::Type result_type = conversion->GetResultType();
1352 Primitive::Type input_type = conversion->GetInputType();
1353 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001354 case Primitive::kPrimByte:
1355 switch (input_type) {
1356 case Primitive::kPrimShort:
1357 case Primitive::kPrimInt:
1358 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001359 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001360 locations->SetInAt(0, Location::RequiresRegister());
1361 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1362 break;
1363
1364 default:
1365 LOG(FATAL) << "Unexpected type conversion from " << input_type
1366 << " to " << result_type;
1367 }
1368 break;
1369
Roland Levillain01a8d712014-11-14 16:27:39 +00001370 case Primitive::kPrimShort:
1371 switch (input_type) {
1372 case Primitive::kPrimByte:
1373 case Primitive::kPrimInt:
1374 case Primitive::kPrimChar:
1375 // Processing a Dex `int-to-short' instruction.
1376 locations->SetInAt(0, Location::RequiresRegister());
1377 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1378 break;
1379
1380 default:
1381 LOG(FATAL) << "Unexpected type conversion from " << input_type
1382 << " to " << result_type;
1383 }
1384 break;
1385
Roland Levillain946e1432014-11-11 17:35:19 +00001386 case Primitive::kPrimInt:
1387 switch (input_type) {
1388 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001389 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001390 locations->SetInAt(0, Location::Any());
1391 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1392 break;
1393
1394 case Primitive::kPrimFloat:
1395 case Primitive::kPrimDouble:
1396 LOG(FATAL) << "Type conversion from " << input_type
1397 << " to " << result_type << " not yet implemented";
1398 break;
1399
1400 default:
1401 LOG(FATAL) << "Unexpected type conversion from " << input_type
1402 << " to " << result_type;
1403 }
1404 break;
1405
Roland Levillaindff1f282014-11-05 14:15:05 +00001406 case Primitive::kPrimLong:
1407 switch (input_type) {
1408 case Primitive::kPrimByte:
1409 case Primitive::kPrimShort:
1410 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001411 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001412 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001413 locations->SetInAt(0, Location::RequiresRegister());
1414 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1415 break;
1416
1417 case Primitive::kPrimFloat:
1418 case Primitive::kPrimDouble:
1419 LOG(FATAL) << "Type conversion from " << input_type << " to "
1420 << result_type << " not yet implemented";
1421 break;
1422
1423 default:
1424 LOG(FATAL) << "Unexpected type conversion from " << input_type
1425 << " to " << result_type;
1426 }
1427 break;
1428
Roland Levillain981e4542014-11-14 11:47:14 +00001429 case Primitive::kPrimChar:
1430 switch (input_type) {
1431 case Primitive::kPrimByte:
1432 case Primitive::kPrimShort:
1433 case Primitive::kPrimInt:
1434 case Primitive::kPrimChar:
1435 // Processing a Dex `int-to-char' instruction.
1436 locations->SetInAt(0, Location::RequiresRegister());
1437 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1438 break;
1439
1440 default:
1441 LOG(FATAL) << "Unexpected type conversion from " << input_type
1442 << " to " << result_type;
1443 }
1444 break;
1445
Roland Levillaindff1f282014-11-05 14:15:05 +00001446 case Primitive::kPrimFloat:
1447 case Primitive::kPrimDouble:
1448 LOG(FATAL) << "Type conversion from " << input_type
1449 << " to " << result_type << " not yet implemented";
1450 break;
1451
1452 default:
1453 LOG(FATAL) << "Unexpected type conversion from " << input_type
1454 << " to " << result_type;
1455 }
1456}
1457
1458void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1459 LocationSummary* locations = conversion->GetLocations();
1460 Location out = locations->Out();
1461 Location in = locations->InAt(0);
1462 Primitive::Type result_type = conversion->GetResultType();
1463 Primitive::Type input_type = conversion->GetInputType();
1464 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001465 case Primitive::kPrimByte:
1466 switch (input_type) {
1467 case Primitive::kPrimShort:
1468 case Primitive::kPrimInt:
1469 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001470 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001471 __ sbfx(out.As<Register>(), in.As<Register>(), 0, 8);
1472 break;
1473
1474 default:
1475 LOG(FATAL) << "Unexpected type conversion from " << input_type
1476 << " to " << result_type;
1477 }
1478 break;
1479
Roland Levillain01a8d712014-11-14 16:27:39 +00001480 case Primitive::kPrimShort:
1481 switch (input_type) {
1482 case Primitive::kPrimByte:
1483 case Primitive::kPrimInt:
1484 case Primitive::kPrimChar:
1485 // Processing a Dex `int-to-short' instruction.
1486 __ sbfx(out.As<Register>(), in.As<Register>(), 0, 16);
1487 break;
1488
1489 default:
1490 LOG(FATAL) << "Unexpected type conversion from " << input_type
1491 << " to " << result_type;
1492 }
1493 break;
1494
Roland Levillain946e1432014-11-11 17:35:19 +00001495 case Primitive::kPrimInt:
1496 switch (input_type) {
1497 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001498 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001499 DCHECK(out.IsRegister());
1500 if (in.IsRegisterPair()) {
1501 __ Mov(out.As<Register>(), in.AsRegisterPairLow<Register>());
1502 } else if (in.IsDoubleStackSlot()) {
1503 __ LoadFromOffset(kLoadWord, out.As<Register>(), SP, in.GetStackIndex());
1504 } else {
1505 DCHECK(in.IsConstant());
1506 DCHECK(in.GetConstant()->IsLongConstant());
1507 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
1508 __ LoadImmediate(out.As<Register>(), static_cast<int32_t>(value));
1509 }
1510 break;
1511
1512 case Primitive::kPrimFloat:
1513 case Primitive::kPrimDouble:
1514 LOG(FATAL) << "Type conversion from " << input_type
1515 << " to " << result_type << " not yet implemented";
1516 break;
1517
1518 default:
1519 LOG(FATAL) << "Unexpected type conversion from " << input_type
1520 << " to " << result_type;
1521 }
1522 break;
1523
Roland Levillaindff1f282014-11-05 14:15:05 +00001524 case Primitive::kPrimLong:
1525 switch (input_type) {
1526 case Primitive::kPrimByte:
1527 case Primitive::kPrimShort:
1528 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001529 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001530 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001531 DCHECK(out.IsRegisterPair());
1532 DCHECK(in.IsRegister());
1533 __ Mov(out.AsRegisterPairLow<Register>(), in.As<Register>());
1534 // Sign extension.
1535 __ Asr(out.AsRegisterPairHigh<Register>(),
1536 out.AsRegisterPairLow<Register>(),
1537 31);
1538 break;
1539
1540 case Primitive::kPrimFloat:
1541 case Primitive::kPrimDouble:
1542 LOG(FATAL) << "Type conversion from " << input_type << " to "
1543 << result_type << " not yet implemented";
1544 break;
1545
1546 default:
1547 LOG(FATAL) << "Unexpected type conversion from " << input_type
1548 << " to " << result_type;
1549 }
1550 break;
1551
Roland Levillain981e4542014-11-14 11:47:14 +00001552 case Primitive::kPrimChar:
1553 switch (input_type) {
1554 case Primitive::kPrimByte:
1555 case Primitive::kPrimShort:
1556 case Primitive::kPrimInt:
1557 case Primitive::kPrimChar:
1558 // Processing a Dex `int-to-char' instruction.
1559 __ ubfx(out.As<Register>(), in.As<Register>(), 0, 16);
1560 break;
1561
1562 default:
1563 LOG(FATAL) << "Unexpected type conversion from " << input_type
1564 << " to " << result_type;
1565 }
1566 break;
1567
Roland Levillaindff1f282014-11-05 14:15:05 +00001568 case Primitive::kPrimFloat:
1569 case Primitive::kPrimDouble:
1570 LOG(FATAL) << "Type conversion from " << input_type
1571 << " to " << result_type << " not yet implemented";
1572 break;
1573
1574 default:
1575 LOG(FATAL) << "Unexpected type conversion from " << input_type
1576 << " to " << result_type;
1577 }
1578}
1579
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001580void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001581 LocationSummary* locations =
1582 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001583 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001584 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001585 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001586 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1587 locations->SetInAt(0, Location::RequiresRegister());
1588 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1589 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001590 break;
1591 }
1592
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001593 case Primitive::kPrimFloat:
1594 case Primitive::kPrimDouble: {
1595 locations->SetInAt(0, Location::RequiresFpuRegister());
1596 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001597 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001598 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001599 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001600
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001601 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001602 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001603 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001604}
1605
1606void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1607 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001608 Location out = locations->Out();
1609 Location first = locations->InAt(0);
1610 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001611 switch (add->GetResultType()) {
1612 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001613 if (second.IsRegister()) {
1614 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001615 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001616 __ AddConstant(out.As<Register>(),
1617 first.As<Register>(),
1618 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001619 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001620 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001621
1622 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001623 __ adds(out.AsRegisterPairLow<Register>(),
1624 first.AsRegisterPairLow<Register>(),
1625 ShifterOperand(second.AsRegisterPairLow<Register>()));
1626 __ adc(out.AsRegisterPairHigh<Register>(),
1627 first.AsRegisterPairHigh<Register>(),
1628 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001629 break;
1630
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001631 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001632 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001633 break;
1634
1635 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001636 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1637 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1638 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001639 break;
1640
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001641 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001642 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001643 }
1644}
1645
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001646void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001647 LocationSummary* locations =
1648 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001649 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001650 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001651 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001652 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1653 locations->SetInAt(0, Location::RequiresRegister());
1654 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1655 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001656 break;
1657 }
Calin Juravle11351682014-10-23 15:38:15 +01001658 case Primitive::kPrimFloat:
1659 case Primitive::kPrimDouble: {
1660 locations->SetInAt(0, Location::RequiresFpuRegister());
1661 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001662 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001663 break;
Calin Juravle11351682014-10-23 15:38:15 +01001664 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001665 default:
Calin Juravle11351682014-10-23 15:38:15 +01001666 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001667 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001668}
1669
1670void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1671 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001672 Location out = locations->Out();
1673 Location first = locations->InAt(0);
1674 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001675 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001676 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001677 if (second.IsRegister()) {
1678 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001679 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001680 __ AddConstant(out.As<Register>(),
1681 first.As<Register>(),
1682 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001683 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001684 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001685 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001686
Calin Juravle11351682014-10-23 15:38:15 +01001687 case Primitive::kPrimLong: {
1688 __ subs(out.AsRegisterPairLow<Register>(),
1689 first.AsRegisterPairLow<Register>(),
1690 ShifterOperand(second.AsRegisterPairLow<Register>()));
1691 __ sbc(out.AsRegisterPairHigh<Register>(),
1692 first.AsRegisterPairHigh<Register>(),
1693 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001694 break;
Calin Juravle11351682014-10-23 15:38:15 +01001695 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001696
Calin Juravle11351682014-10-23 15:38:15 +01001697 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001698 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001699 break;
Calin Juravle11351682014-10-23 15:38:15 +01001700 }
1701
1702 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001703 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1704 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1705 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001706 break;
1707 }
1708
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001709
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001710 default:
Calin Juravle11351682014-10-23 15:38:15 +01001711 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001712 }
1713}
1714
Calin Juravle34bacdf2014-10-07 20:23:36 +01001715void LocationsBuilderARM::VisitMul(HMul* mul) {
1716 LocationSummary* locations =
1717 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1718 switch (mul->GetResultType()) {
1719 case Primitive::kPrimInt:
1720 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001721 locations->SetInAt(0, Location::RequiresRegister());
1722 locations->SetInAt(1, Location::RequiresRegister());
1723 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001724 break;
1725 }
1726
Calin Juravleb5bfa962014-10-21 18:02:24 +01001727 case Primitive::kPrimFloat:
1728 case Primitive::kPrimDouble: {
1729 locations->SetInAt(0, Location::RequiresFpuRegister());
1730 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001731 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001732 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001733 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001734
1735 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001736 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001737 }
1738}
1739
1740void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1741 LocationSummary* locations = mul->GetLocations();
1742 Location out = locations->Out();
1743 Location first = locations->InAt(0);
1744 Location second = locations->InAt(1);
1745 switch (mul->GetResultType()) {
1746 case Primitive::kPrimInt: {
1747 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1748 break;
1749 }
1750 case Primitive::kPrimLong: {
1751 Register out_hi = out.AsRegisterPairHigh<Register>();
1752 Register out_lo = out.AsRegisterPairLow<Register>();
1753 Register in1_hi = first.AsRegisterPairHigh<Register>();
1754 Register in1_lo = first.AsRegisterPairLow<Register>();
1755 Register in2_hi = second.AsRegisterPairHigh<Register>();
1756 Register in2_lo = second.AsRegisterPairLow<Register>();
1757
1758 // Extra checks to protect caused by the existence of R1_R2.
1759 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1760 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1761 DCHECK_NE(out_hi, in1_lo);
1762 DCHECK_NE(out_hi, in2_lo);
1763
1764 // input: in1 - 64 bits, in2 - 64 bits
1765 // output: out
1766 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1767 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1768 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1769
1770 // IP <- in1.lo * in2.hi
1771 __ mul(IP, in1_lo, in2_hi);
1772 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1773 __ mla(out_hi, in1_hi, in2_lo, IP);
1774 // out.lo <- (in1.lo * in2.lo)[31:0];
1775 __ umull(out_lo, IP, in1_lo, in2_lo);
1776 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1777 __ add(out_hi, out_hi, ShifterOperand(IP));
1778 break;
1779 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001780
1781 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001782 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001783 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001784 }
1785
1786 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001787 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1788 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1789 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001790 break;
1791 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001792
1793 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001794 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001795 }
1796}
1797
Calin Juravle7c4954d2014-10-28 16:57:40 +00001798void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001799 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
1800 ? LocationSummary::kCall
1801 : LocationSummary::kNoCall;
1802 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
1803
Calin Juravle7c4954d2014-10-28 16:57:40 +00001804 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001805 case Primitive::kPrimInt: {
1806 locations->SetInAt(0, Location::RequiresRegister());
1807 locations->SetInAt(1, Location::RequiresRegister());
1808 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1809 break;
1810 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00001811 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001812 InvokeRuntimeCallingConvention calling_convention;
1813 locations->SetInAt(0, Location::RegisterPairLocation(
1814 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1815 locations->SetInAt(1, Location::RegisterPairLocation(
1816 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
1817 // The runtime helper puts the output in R0,R2.
1818 locations->SetOut(Location::RegisterPairLocation(R0, R2));
Calin Juravle7c4954d2014-10-28 16:57:40 +00001819 break;
1820 }
1821 case Primitive::kPrimFloat:
1822 case Primitive::kPrimDouble: {
1823 locations->SetInAt(0, Location::RequiresFpuRegister());
1824 locations->SetInAt(1, Location::RequiresFpuRegister());
1825 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1826 break;
1827 }
1828
1829 default:
1830 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1831 }
1832}
1833
1834void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1835 LocationSummary* locations = div->GetLocations();
1836 Location out = locations->Out();
1837 Location first = locations->InAt(0);
1838 Location second = locations->InAt(1);
1839
1840 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001841 case Primitive::kPrimInt: {
1842 __ sdiv(out.As<Register>(), first.As<Register>(), second.As<Register>());
1843 break;
1844 }
1845
Calin Juravle7c4954d2014-10-28 16:57:40 +00001846 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001847 InvokeRuntimeCallingConvention calling_convention;
1848 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
1849 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
1850 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
1851 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
1852 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
1853 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
1854
1855 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001856 break;
1857 }
1858
1859 case Primitive::kPrimFloat: {
1860 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1861 break;
1862 }
1863
1864 case Primitive::kPrimDouble: {
1865 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1866 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1867 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1868 break;
1869 }
1870
1871 default:
1872 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1873 }
1874}
1875
Calin Juravlebacfec32014-11-14 15:54:36 +00001876void LocationsBuilderARM::VisitRem(HRem* rem) {
1877 LocationSummary::CallKind call_kind = rem->GetResultType() == Primitive::kPrimLong
1878 ? LocationSummary::kCall
1879 : LocationSummary::kNoCall;
1880 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
1881
1882 switch (rem->GetResultType()) {
1883 case Primitive::kPrimInt: {
1884 locations->SetInAt(0, Location::RequiresRegister());
1885 locations->SetInAt(1, Location::RequiresRegister());
1886 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1887 locations->AddTemp(Location::RequiresRegister());
1888 break;
1889 }
1890 case Primitive::kPrimLong: {
1891 InvokeRuntimeCallingConvention calling_convention;
1892 locations->SetInAt(0, Location::RegisterPairLocation(
1893 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1894 locations->SetInAt(1, Location::RegisterPairLocation(
1895 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
1896 // The runtime helper puts the output in R2,R3.
1897 locations->SetOut(Location::RegisterPairLocation(R2, R3));
1898 break;
1899 }
1900 case Primitive::kPrimFloat:
1901 case Primitive::kPrimDouble: {
1902 LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType();
1903 break;
1904 }
1905
1906 default:
1907 LOG(FATAL) << "Unexpected rem type " << rem->GetResultType();
1908 }
1909}
1910
1911void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
1912 LocationSummary* locations = rem->GetLocations();
1913 Location out = locations->Out();
1914 Location first = locations->InAt(0);
1915 Location second = locations->InAt(1);
1916
1917 switch (rem->GetResultType()) {
1918 case Primitive::kPrimInt: {
1919 Register reg1 = first.As<Register>();
1920 Register reg2 = second.As<Register>();
1921 Register temp = locations->GetTemp(0).As<Register>();
1922
1923 // temp = reg1 / reg2 (integer division)
1924 // temp = temp * reg2
1925 // dest = reg1 - temp
1926 __ sdiv(temp, reg1, reg2);
1927 __ mul(temp, temp, reg2);
1928 __ sub(out.As<Register>(), reg1, ShifterOperand(temp));
1929 break;
1930 }
1931
1932 case Primitive::kPrimLong: {
1933 InvokeRuntimeCallingConvention calling_convention;
1934 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
1935 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
1936 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
1937 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
1938 DCHECK_EQ(R2, out.AsRegisterPairLow<Register>());
1939 DCHECK_EQ(R3, out.AsRegisterPairHigh<Register>());
1940
1941 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
1942 break;
1943 }
1944
1945 case Primitive::kPrimFloat:
1946 case Primitive::kPrimDouble: {
1947 LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType();
1948 break;
1949 }
1950
1951 default:
1952 LOG(FATAL) << "Unexpected rem type " << rem->GetResultType();
1953 }
1954}
1955
Calin Juravled0d48522014-11-04 16:40:20 +00001956void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1957 LocationSummary* locations =
1958 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001959 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00001960 if (instruction->HasUses()) {
1961 locations->SetOut(Location::SameAsFirstInput());
1962 }
1963}
1964
1965void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1966 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
1967 codegen_->AddSlowPath(slow_path);
1968
1969 LocationSummary* locations = instruction->GetLocations();
1970 Location value = locations->InAt(0);
1971
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001972 switch (instruction->GetType()) {
1973 case Primitive::kPrimInt: {
1974 if (value.IsRegister()) {
1975 __ cmp(value.As<Register>(), ShifterOperand(0));
1976 __ b(slow_path->GetEntryLabel(), EQ);
1977 } else {
1978 DCHECK(value.IsConstant()) << value;
1979 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
1980 __ b(slow_path->GetEntryLabel());
1981 }
1982 }
1983 break;
1984 }
1985 case Primitive::kPrimLong: {
1986 if (value.IsRegisterPair()) {
1987 __ orrs(IP,
1988 value.AsRegisterPairLow<Register>(),
1989 ShifterOperand(value.AsRegisterPairHigh<Register>()));
1990 __ b(slow_path->GetEntryLabel(), EQ);
1991 } else {
1992 DCHECK(value.IsConstant()) << value;
1993 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
1994 __ b(slow_path->GetEntryLabel());
1995 }
1996 }
1997 break;
1998 default:
1999 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2000 }
2001 }
Calin Juravled0d48522014-11-04 16:40:20 +00002002}
2003
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002004void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002005 LocationSummary* locations =
2006 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002007 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002008 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2009 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2010 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002011}
2012
2013void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2014 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002015 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002016 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002017 codegen_->InvokeRuntime(
2018 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002019}
2020
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002021void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2022 LocationSummary* locations =
2023 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2024 InvokeRuntimeCallingConvention calling_convention;
2025 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2026 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2027 locations->SetOut(Location::RegisterLocation(R0));
2028 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2029}
2030
2031void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2032 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002033 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002034 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002035 codegen_->InvokeRuntime(
2036 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002037}
2038
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002039void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002040 LocationSummary* locations =
2041 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002042 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2043 if (location.IsStackSlot()) {
2044 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2045 } else if (location.IsDoubleStackSlot()) {
2046 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002047 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002048 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002049}
2050
2051void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002052 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002053 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002054}
2055
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002056void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002057 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002058 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002059 locations->SetInAt(0, Location::RequiresRegister());
2060 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002061}
2062
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002063void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2064 LocationSummary* locations = not_->GetLocations();
2065 Location out = locations->Out();
2066 Location in = locations->InAt(0);
2067 switch (not_->InputAt(0)->GetType()) {
2068 case Primitive::kPrimBoolean:
2069 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
2070 break;
2071
2072 case Primitive::kPrimInt:
2073 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
2074 break;
2075
2076 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002077 __ mvn(out.AsRegisterPairLow<Register>(),
2078 ShifterOperand(in.AsRegisterPairLow<Register>()));
2079 __ mvn(out.AsRegisterPairHigh<Register>(),
2080 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002081 break;
2082
2083 default:
2084 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2085 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002086}
2087
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002088void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002089 LocationSummary* locations =
2090 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002091 locations->SetInAt(0, Location::RequiresRegister());
2092 locations->SetInAt(1, Location::RequiresRegister());
2093 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002094}
2095
2096void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002097 LocationSummary* locations = compare->GetLocations();
2098 switch (compare->InputAt(0)->GetType()) {
2099 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002100 Register output = locations->Out().As<Register>();
2101 Location left = locations->InAt(0);
2102 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002103 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002104 __ cmp(left.AsRegisterPairHigh<Register>(),
2105 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002106 __ b(&less, LT);
2107 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01002108 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
2109 // the status flags.
2110 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002111 __ cmp(left.AsRegisterPairLow<Register>(),
2112 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002113 __ b(&done, EQ);
2114 __ b(&less, CC);
2115
2116 __ Bind(&greater);
2117 __ LoadImmediate(output, 1);
2118 __ b(&done);
2119
2120 __ Bind(&less);
2121 __ LoadImmediate(output, -1);
2122
2123 __ Bind(&done);
2124 break;
2125 }
2126 default:
2127 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
2128 }
2129}
2130
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002131void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002132 LocationSummary* locations =
2133 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002134 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2135 locations->SetInAt(i, Location::Any());
2136 }
2137 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002138}
2139
2140void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002141 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002142 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002143}
2144
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002145void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002146 LocationSummary* locations =
2147 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002148 bool needs_write_barrier =
2149 CodeGenerator::StoreNeedsWriteBarrier(instruction->GetFieldType(), instruction->GetValue());
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002150 locations->SetInAt(0, Location::RequiresRegister());
2151 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002152 // Temporary registers for the write barrier.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002153 if (needs_write_barrier) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002154 locations->AddTemp(Location::RequiresRegister());
2155 locations->AddTemp(Location::RequiresRegister());
2156 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002157}
2158
2159void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2160 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002161 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002162 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01002163 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002164
2165 switch (field_type) {
2166 case Primitive::kPrimBoolean:
2167 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002168 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002169 __ StoreToOffset(kStoreByte, value, obj, offset);
2170 break;
2171 }
2172
2173 case Primitive::kPrimShort:
2174 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002175 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002176 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2177 break;
2178 }
2179
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002180 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002181 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002182 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002183 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002184 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002185 Register temp = locations->GetTemp(0).As<Register>();
2186 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002187 codegen_->MarkGCCard(temp, card, obj, value);
2188 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002189 break;
2190 }
2191
2192 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002193 Location value = locations->InAt(1);
2194 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002195 break;
2196 }
2197
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002198 case Primitive::kPrimFloat: {
2199 SRegister value = locations->InAt(1).As<SRegister>();
2200 __ StoreSToOffset(value, obj, offset);
2201 break;
2202 }
2203
2204 case Primitive::kPrimDouble: {
2205 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
2206 __ StoreDToOffset(value, obj, offset);
2207 break;
2208 }
2209
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002210 case Primitive::kPrimVoid:
2211 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002212 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002213 }
2214}
2215
2216void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002217 LocationSummary* locations =
2218 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002219 locations->SetInAt(0, Location::RequiresRegister());
2220 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002221}
2222
2223void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2224 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002225 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002226 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2227
2228 switch (instruction->GetType()) {
2229 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002230 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002231 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2232 break;
2233 }
2234
2235 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002236 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002237 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2238 break;
2239 }
2240
2241 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002242 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002243 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2244 break;
2245 }
2246
2247 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002248 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002249 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2250 break;
2251 }
2252
2253 case Primitive::kPrimInt:
2254 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002255 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002256 __ LoadFromOffset(kLoadWord, out, obj, offset);
2257 break;
2258 }
2259
2260 case Primitive::kPrimLong: {
2261 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002262 Location out = locations->Out();
2263 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002264 break;
2265 }
2266
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002267 case Primitive::kPrimFloat: {
2268 SRegister out = locations->Out().As<SRegister>();
2269 __ LoadSFromOffset(out, obj, offset);
2270 break;
2271 }
2272
2273 case Primitive::kPrimDouble: {
2274 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2275 __ LoadDFromOffset(out, obj, offset);
2276 break;
2277 }
2278
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002279 case Primitive::kPrimVoid:
2280 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002281 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002282 }
2283}
2284
2285void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002286 LocationSummary* locations =
2287 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002288 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002289 if (instruction->HasUses()) {
2290 locations->SetOut(Location::SameAsFirstInput());
2291 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002292}
2293
2294void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002295 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002296 codegen_->AddSlowPath(slow_path);
2297
2298 LocationSummary* locations = instruction->GetLocations();
2299 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002300
2301 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002302 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002303 __ b(slow_path->GetEntryLabel(), EQ);
2304 } else {
2305 DCHECK(obj.IsConstant()) << obj;
2306 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2307 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002308 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002309}
2310
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002311void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002312 LocationSummary* locations =
2313 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002314 locations->SetInAt(0, Location::RequiresRegister());
2315 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2316 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002317}
2318
2319void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2320 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002321 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002322 Location index = locations->InAt(1);
2323
2324 switch (instruction->GetType()) {
2325 case Primitive::kPrimBoolean: {
2326 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002327 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002328 if (index.IsConstant()) {
2329 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2330 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2331 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002332 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002333 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2334 }
2335 break;
2336 }
2337
2338 case Primitive::kPrimByte: {
2339 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002340 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002341 if (index.IsConstant()) {
2342 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2343 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2344 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002345 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002346 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2347 }
2348 break;
2349 }
2350
2351 case Primitive::kPrimShort: {
2352 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002353 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002354 if (index.IsConstant()) {
2355 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2356 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2357 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002358 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002359 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2360 }
2361 break;
2362 }
2363
2364 case Primitive::kPrimChar: {
2365 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002366 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002367 if (index.IsConstant()) {
2368 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2369 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2370 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002371 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002372 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2373 }
2374 break;
2375 }
2376
2377 case Primitive::kPrimInt:
2378 case Primitive::kPrimNot: {
2379 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2380 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002381 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002382 if (index.IsConstant()) {
2383 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2384 __ LoadFromOffset(kLoadWord, out, obj, offset);
2385 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002386 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002387 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2388 }
2389 break;
2390 }
2391
2392 case Primitive::kPrimLong: {
2393 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002394 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002395 if (index.IsConstant()) {
2396 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002397 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002398 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002399 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2400 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002401 }
2402 break;
2403 }
2404
2405 case Primitive::kPrimFloat:
2406 case Primitive::kPrimDouble:
2407 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002408 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002409 case Primitive::kPrimVoid:
2410 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002411 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002412 }
2413}
2414
2415void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002416 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002417
2418 bool needs_write_barrier =
2419 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
2420 bool needs_runtime_call = instruction->NeedsTypeCheck();
2421
Nicolas Geoffray39468442014-09-02 15:17:15 +01002422 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002423 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
2424 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002425 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002426 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2427 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2428 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002429 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002430 locations->SetInAt(0, Location::RequiresRegister());
2431 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2432 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002433
2434 if (needs_write_barrier) {
2435 // Temporary registers for the write barrier.
2436 locations->AddTemp(Location::RequiresRegister());
2437 locations->AddTemp(Location::RequiresRegister());
2438 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002439 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002440}
2441
2442void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
2443 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002444 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002445 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002446 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002447 bool needs_runtime_call = locations->WillCall();
2448 bool needs_write_barrier =
2449 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002450
2451 switch (value_type) {
2452 case Primitive::kPrimBoolean:
2453 case Primitive::kPrimByte: {
2454 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002455 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002456 if (index.IsConstant()) {
2457 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2458 __ StoreToOffset(kStoreByte, value, obj, offset);
2459 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002460 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002461 __ StoreToOffset(kStoreByte, value, IP, data_offset);
2462 }
2463 break;
2464 }
2465
2466 case Primitive::kPrimShort:
2467 case Primitive::kPrimChar: {
2468 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002469 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002470 if (index.IsConstant()) {
2471 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2472 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2473 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002474 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002475 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
2476 }
2477 break;
2478 }
2479
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002480 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002481 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002482 if (!needs_runtime_call) {
2483 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2484 Register value = locations->InAt(2).As<Register>();
2485 if (index.IsConstant()) {
2486 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2487 __ StoreToOffset(kStoreWord, value, obj, offset);
2488 } else {
2489 DCHECK(index.IsRegister()) << index;
2490 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
2491 __ StoreToOffset(kStoreWord, value, IP, data_offset);
2492 }
2493 if (needs_write_barrier) {
2494 DCHECK_EQ(value_type, Primitive::kPrimNot);
2495 Register temp = locations->GetTemp(0).As<Register>();
2496 Register card = locations->GetTemp(1).As<Register>();
2497 codegen_->MarkGCCard(temp, card, obj, value);
2498 }
2499 } else {
2500 DCHECK_EQ(value_type, Primitive::kPrimNot);
2501 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
2502 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002503 break;
2504 }
2505
2506 case Primitive::kPrimLong: {
2507 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002508 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002509 if (index.IsConstant()) {
2510 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002511 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002512 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002513 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2514 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002515 }
2516 break;
2517 }
2518
2519 case Primitive::kPrimFloat:
2520 case Primitive::kPrimDouble:
2521 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002522 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002523 case Primitive::kPrimVoid:
2524 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002525 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002526 }
2527}
2528
2529void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002530 LocationSummary* locations =
2531 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002532 locations->SetInAt(0, Location::RequiresRegister());
2533 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002534}
2535
2536void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
2537 LocationSummary* locations = instruction->GetLocations();
2538 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002539 Register obj = locations->InAt(0).As<Register>();
2540 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002541 __ LoadFromOffset(kLoadWord, out, obj, offset);
2542}
2543
2544void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002545 LocationSummary* locations =
2546 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002547 locations->SetInAt(0, Location::RequiresRegister());
2548 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002549 if (instruction->HasUses()) {
2550 locations->SetOut(Location::SameAsFirstInput());
2551 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002552}
2553
2554void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
2555 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002556 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002557 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002558 codegen_->AddSlowPath(slow_path);
2559
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002560 Register index = locations->InAt(0).As<Register>();
2561 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002562
2563 __ cmp(index, ShifterOperand(length));
2564 __ b(slow_path->GetEntryLabel(), CS);
2565}
2566
2567void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
2568 Label is_null;
2569 __ CompareAndBranchIfZero(value, &is_null);
2570 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
2571 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
2572 __ strb(card, Address(card, temp));
2573 __ Bind(&is_null);
2574}
2575
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002576void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
2577 temp->SetLocations(nullptr);
2578}
2579
2580void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
2581 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002582 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002583}
2584
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002585void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002586 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002587 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002588}
2589
2590void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002591 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2592}
2593
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002594void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2595 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2596}
2597
2598void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002599 HBasicBlock* block = instruction->GetBlock();
2600 if (block->GetLoopInformation() != nullptr) {
2601 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2602 // The back edge will generate the suspend check.
2603 return;
2604 }
2605 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2606 // The goto will generate the suspend check.
2607 return;
2608 }
2609 GenerateSuspendCheck(instruction, nullptr);
2610}
2611
2612void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
2613 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002614 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002615 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002616 codegen_->AddSlowPath(slow_path);
2617
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002618 __ LoadFromOffset(
2619 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
2620 __ cmp(IP, ShifterOperand(0));
2621 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002622 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002623 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002624 __ Bind(slow_path->GetReturnLabel());
2625 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002626 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002627 __ b(slow_path->GetEntryLabel());
2628 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002629}
2630
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002631ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2632 return codegen_->GetAssembler();
2633}
2634
2635void ParallelMoveResolverARM::EmitMove(size_t index) {
2636 MoveOperands* move = moves_.Get(index);
2637 Location source = move->GetSource();
2638 Location destination = move->GetDestination();
2639
2640 if (source.IsRegister()) {
2641 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002642 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002643 } else {
2644 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002645 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002646 SP, destination.GetStackIndex());
2647 }
2648 } else if (source.IsStackSlot()) {
2649 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002650 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002651 SP, source.GetStackIndex());
2652 } else {
2653 DCHECK(destination.IsStackSlot());
2654 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2655 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2656 }
2657 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002658 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002659 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002660 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2661 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002662 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002663 } else {
2664 DCHECK(destination.IsStackSlot());
2665 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002666 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002667 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002668 }
2669}
2670
2671void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2672 __ Mov(IP, reg);
2673 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2674 __ StoreToOffset(kStoreWord, IP, SP, mem);
2675}
2676
2677void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2678 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2679 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2680 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2681 SP, mem1 + stack_offset);
2682 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2683 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2684 SP, mem2 + stack_offset);
2685 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2686}
2687
2688void ParallelMoveResolverARM::EmitSwap(size_t index) {
2689 MoveOperands* move = moves_.Get(index);
2690 Location source = move->GetSource();
2691 Location destination = move->GetDestination();
2692
2693 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002694 DCHECK_NE(source.As<Register>(), IP);
2695 DCHECK_NE(destination.As<Register>(), IP);
2696 __ Mov(IP, source.As<Register>());
2697 __ Mov(source.As<Register>(), destination.As<Register>());
2698 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002699 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002700 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002701 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002702 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002703 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2704 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2705 } else {
2706 LOG(FATAL) << "Unimplemented";
2707 }
2708}
2709
2710void ParallelMoveResolverARM::SpillScratch(int reg) {
2711 __ Push(static_cast<Register>(reg));
2712}
2713
2714void ParallelMoveResolverARM::RestoreScratch(int reg) {
2715 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002716}
2717
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002718void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002719 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
2720 ? LocationSummary::kCallOnSlowPath
2721 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002722 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002723 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002724 locations->SetOut(Location::RequiresRegister());
2725}
2726
2727void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2728 Register out = cls->GetLocations()->Out().As<Register>();
2729 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002730 DCHECK(!cls->CanCallRuntime());
2731 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002732 codegen_->LoadCurrentMethod(out);
2733 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2734 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002735 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002736 codegen_->LoadCurrentMethod(out);
2737 __ LoadFromOffset(
2738 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2739 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002740
2741 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2742 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2743 codegen_->AddSlowPath(slow_path);
2744 __ cmp(out, ShifterOperand(0));
2745 __ b(slow_path->GetEntryLabel(), EQ);
2746 if (cls->MustGenerateClinitCheck()) {
2747 GenerateClassInitializationCheck(slow_path, out);
2748 } else {
2749 __ Bind(slow_path->GetExitLabel());
2750 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002751 }
2752}
2753
2754void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2755 LocationSummary* locations =
2756 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2757 locations->SetInAt(0, Location::RequiresRegister());
2758 if (check->HasUses()) {
2759 locations->SetOut(Location::SameAsFirstInput());
2760 }
2761}
2762
2763void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002764 // We assume the class is not null.
2765 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2766 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002767 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002768 GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>());
2769}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002770
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002771void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
2772 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002773 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2774 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2775 __ b(slow_path->GetEntryLabel(), LT);
2776 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2777 // properly. Therefore, we do a memory fence.
2778 __ dmb(ISH);
2779 __ Bind(slow_path->GetExitLabel());
2780}
2781
2782void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2783 LocationSummary* locations =
2784 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2785 locations->SetInAt(0, Location::RequiresRegister());
2786 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2787}
2788
2789void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2790 LocationSummary* locations = instruction->GetLocations();
2791 Register cls = locations->InAt(0).As<Register>();
2792 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2793
2794 switch (instruction->GetType()) {
2795 case Primitive::kPrimBoolean: {
2796 Register out = locations->Out().As<Register>();
2797 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2798 break;
2799 }
2800
2801 case Primitive::kPrimByte: {
2802 Register out = locations->Out().As<Register>();
2803 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2804 break;
2805 }
2806
2807 case Primitive::kPrimShort: {
2808 Register out = locations->Out().As<Register>();
2809 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2810 break;
2811 }
2812
2813 case Primitive::kPrimChar: {
2814 Register out = locations->Out().As<Register>();
2815 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2816 break;
2817 }
2818
2819 case Primitive::kPrimInt:
2820 case Primitive::kPrimNot: {
2821 Register out = locations->Out().As<Register>();
2822 __ LoadFromOffset(kLoadWord, out, cls, offset);
2823 break;
2824 }
2825
2826 case Primitive::kPrimLong: {
2827 // TODO: support volatile.
2828 Location out = locations->Out();
2829 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2830 break;
2831 }
2832
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002833 case Primitive::kPrimFloat: {
2834 SRegister out = locations->Out().As<SRegister>();
2835 __ LoadSFromOffset(out, cls, offset);
2836 break;
2837 }
2838
2839 case Primitive::kPrimDouble: {
2840 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2841 __ LoadDFromOffset(out, cls, offset);
2842 break;
2843 }
2844
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002845 case Primitive::kPrimVoid:
2846 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2847 UNREACHABLE();
2848 }
2849}
2850
2851void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2852 LocationSummary* locations =
2853 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002854 bool needs_write_barrier =
2855 CodeGenerator::StoreNeedsWriteBarrier(instruction->GetFieldType(), instruction->GetValue());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002856 locations->SetInAt(0, Location::RequiresRegister());
2857 locations->SetInAt(1, Location::RequiresRegister());
2858 // Temporary registers for the write barrier.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002859 if (needs_write_barrier) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002860 locations->AddTemp(Location::RequiresRegister());
2861 locations->AddTemp(Location::RequiresRegister());
2862 }
2863}
2864
2865void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2866 LocationSummary* locations = instruction->GetLocations();
2867 Register cls = locations->InAt(0).As<Register>();
2868 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2869 Primitive::Type field_type = instruction->GetFieldType();
2870
2871 switch (field_type) {
2872 case Primitive::kPrimBoolean:
2873 case Primitive::kPrimByte: {
2874 Register value = locations->InAt(1).As<Register>();
2875 __ StoreToOffset(kStoreByte, value, cls, offset);
2876 break;
2877 }
2878
2879 case Primitive::kPrimShort:
2880 case Primitive::kPrimChar: {
2881 Register value = locations->InAt(1).As<Register>();
2882 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2883 break;
2884 }
2885
2886 case Primitive::kPrimInt:
2887 case Primitive::kPrimNot: {
2888 Register value = locations->InAt(1).As<Register>();
2889 __ StoreToOffset(kStoreWord, value, cls, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002890 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002891 Register temp = locations->GetTemp(0).As<Register>();
2892 Register card = locations->GetTemp(1).As<Register>();
2893 codegen_->MarkGCCard(temp, card, cls, value);
2894 }
2895 break;
2896 }
2897
2898 case Primitive::kPrimLong: {
2899 Location value = locations->InAt(1);
2900 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2901 break;
2902 }
2903
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002904 case Primitive::kPrimFloat: {
2905 SRegister value = locations->InAt(1).As<SRegister>();
2906 __ StoreSToOffset(value, cls, offset);
2907 break;
2908 }
2909
2910 case Primitive::kPrimDouble: {
2911 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
2912 __ StoreDToOffset(value, cls, offset);
2913 break;
2914 }
2915
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002916 case Primitive::kPrimVoid:
2917 LOG(FATAL) << "Unreachable type " << field_type;
2918 UNREACHABLE();
2919 }
2920}
2921
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002922void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
2923 LocationSummary* locations =
2924 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2925 locations->SetOut(Location::RequiresRegister());
2926}
2927
2928void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
2929 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
2930 codegen_->AddSlowPath(slow_path);
2931
2932 Register out = load->GetLocations()->Out().As<Register>();
2933 codegen_->LoadCurrentMethod(out);
2934 __ LoadFromOffset(
2935 kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value());
2936 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2937 __ cmp(out, ShifterOperand(0));
2938 __ b(slow_path->GetEntryLabel(), EQ);
2939 __ Bind(slow_path->GetExitLabel());
2940}
2941
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002942void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
2943 LocationSummary* locations =
2944 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2945 locations->SetOut(Location::RequiresRegister());
2946}
2947
2948void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
2949 Register out = load->GetLocations()->Out().As<Register>();
2950 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
2951 __ LoadFromOffset(kLoadWord, out, TR, offset);
2952 __ LoadImmediate(IP, 0);
2953 __ StoreToOffset(kStoreWord, IP, TR, offset);
2954}
2955
2956void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
2957 LocationSummary* locations =
2958 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2959 InvokeRuntimeCallingConvention calling_convention;
2960 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2961}
2962
2963void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
2964 codegen_->InvokeRuntime(
2965 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
2966}
2967
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002968void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002969 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
2970 ? LocationSummary::kNoCall
2971 : LocationSummary::kCallOnSlowPath;
2972 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2973 locations->SetInAt(0, Location::RequiresRegister());
2974 locations->SetInAt(1, Location::RequiresRegister());
2975 locations->SetOut(Location::RequiresRegister());
2976}
2977
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002978void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002979 LocationSummary* locations = instruction->GetLocations();
2980 Register obj = locations->InAt(0).As<Register>();
2981 Register cls = locations->InAt(1).As<Register>();
2982 Register out = locations->Out().As<Register>();
2983 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2984 Label done, zero;
2985 SlowPathCodeARM* slow_path = nullptr;
2986
2987 // Return 0 if `obj` is null.
2988 // TODO: avoid this check if we know obj is not null.
2989 __ cmp(obj, ShifterOperand(0));
2990 __ b(&zero, EQ);
2991 // Compare the class of `obj` with `cls`.
2992 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
2993 __ cmp(out, ShifterOperand(cls));
2994 if (instruction->IsClassFinal()) {
2995 // Classes must be equal for the instanceof to succeed.
2996 __ b(&zero, NE);
2997 __ LoadImmediate(out, 1);
2998 __ b(&done);
2999 } else {
3000 // If the classes are not equal, we go into a slow path.
3001 DCHECK(locations->OnlyCallsOnSlowPath());
3002 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003003 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003004 codegen_->AddSlowPath(slow_path);
3005 __ b(slow_path->GetEntryLabel(), NE);
3006 __ LoadImmediate(out, 1);
3007 __ b(&done);
3008 }
3009 __ Bind(&zero);
3010 __ LoadImmediate(out, 0);
3011 if (slow_path != nullptr) {
3012 __ Bind(slow_path->GetExitLabel());
3013 }
3014 __ Bind(&done);
3015}
3016
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003017void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3018 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3019 instruction, LocationSummary::kCallOnSlowPath);
3020 locations->SetInAt(0, Location::RequiresRegister());
3021 locations->SetInAt(1, Location::RequiresRegister());
3022 locations->AddTemp(Location::RequiresRegister());
3023}
3024
3025void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3026 LocationSummary* locations = instruction->GetLocations();
3027 Register obj = locations->InAt(0).As<Register>();
3028 Register cls = locations->InAt(1).As<Register>();
3029 Register temp = locations->GetTemp(0).As<Register>();
3030 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3031
3032 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3033 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3034 codegen_->AddSlowPath(slow_path);
3035
3036 // TODO: avoid this check if we know obj is not null.
3037 __ cmp(obj, ShifterOperand(0));
3038 __ b(slow_path->GetExitLabel(), EQ);
3039 // Compare the class of `obj` with `cls`.
3040 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3041 __ cmp(temp, ShifterOperand(cls));
3042 __ b(slow_path->GetEntryLabel(), NE);
3043 __ Bind(slow_path->GetExitLabel());
3044}
3045
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003046void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3047 LocationSummary* locations =
3048 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3049 InvokeRuntimeCallingConvention calling_convention;
3050 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3051}
3052
3053void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3054 codegen_->InvokeRuntime(instruction->IsEnter()
3055 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3056 instruction,
3057 instruction->GetDexPc());
3058}
3059
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003060void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3061void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3062void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3063
3064void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3065 LocationSummary* locations =
3066 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3067 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3068 || instruction->GetResultType() == Primitive::kPrimLong);
3069 locations->SetInAt(0, Location::RequiresRegister());
3070 locations->SetInAt(1, Location::RequiresRegister());
3071 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
3072 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3073}
3074
3075void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3076 HandleBitwiseOperation(instruction);
3077}
3078
3079void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3080 HandleBitwiseOperation(instruction);
3081}
3082
3083void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3084 HandleBitwiseOperation(instruction);
3085}
3086
3087void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3088 LocationSummary* locations = instruction->GetLocations();
3089
3090 if (instruction->GetResultType() == Primitive::kPrimInt) {
3091 Register first = locations->InAt(0).As<Register>();
3092 Register second = locations->InAt(1).As<Register>();
3093 Register out = locations->Out().As<Register>();
3094 if (instruction->IsAnd()) {
3095 __ and_(out, first, ShifterOperand(second));
3096 } else if (instruction->IsOr()) {
3097 __ orr(out, first, ShifterOperand(second));
3098 } else {
3099 DCHECK(instruction->IsXor());
3100 __ eor(out, first, ShifterOperand(second));
3101 }
3102 } else {
3103 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3104 Location first = locations->InAt(0);
3105 Location second = locations->InAt(1);
3106 Location out = locations->Out();
3107 if (instruction->IsAnd()) {
3108 __ and_(out.AsRegisterPairLow<Register>(),
3109 first.AsRegisterPairLow<Register>(),
3110 ShifterOperand(second.AsRegisterPairLow<Register>()));
3111 __ and_(out.AsRegisterPairHigh<Register>(),
3112 first.AsRegisterPairHigh<Register>(),
3113 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3114 } else if (instruction->IsOr()) {
3115 __ orr(out.AsRegisterPairLow<Register>(),
3116 first.AsRegisterPairLow<Register>(),
3117 ShifterOperand(second.AsRegisterPairLow<Register>()));
3118 __ orr(out.AsRegisterPairHigh<Register>(),
3119 first.AsRegisterPairHigh<Register>(),
3120 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3121 } else {
3122 DCHECK(instruction->IsXor());
3123 __ eor(out.AsRegisterPairLow<Register>(),
3124 first.AsRegisterPairLow<Register>(),
3125 ShifterOperand(second.AsRegisterPairLow<Register>()));
3126 __ eor(out.AsRegisterPairHigh<Register>(),
3127 first.AsRegisterPairHigh<Register>(),
3128 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3129 }
3130 }
3131}
3132
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003133} // namespace arm
3134} // namespace art