blob: 4d86732cc76e12291aedaf49221ae63fc8e93f17 [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());
172 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100173 arm_codegen->Move32(
174 Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_);
175 arm_codegen->Move32(
176 Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_);
177 arm_codegen->InvokeRuntime(
178 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100179 }
180
181 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100182 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100183 const Location index_location_;
184 const Location length_location_;
185
186 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
187};
188
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000189class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100190 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000191 LoadClassSlowPathARM(HLoadClass* cls,
192 HInstruction* at,
193 uint32_t dex_pc,
194 bool do_clinit)
195 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
196 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
197 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100198
199 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000200 LocationSummary* locations = at_->GetLocations();
201
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100202 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
203 __ Bind(GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000204 codegen->SaveLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100205
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100206 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000207 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100208 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000209 int32_t entry_point_offset = do_clinit_
210 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
211 : QUICK_ENTRY_POINT(pInitializeType);
212 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_);
213
214 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000215 Location out = locations->Out();
216 if (out.IsValid()) {
217 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000218 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
219 }
220 codegen->RestoreLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100221 __ b(GetExitLabel());
222 }
223
224 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000225 // The class this slow path will load.
226 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100227
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000228 // The instruction where this slow path is happening.
229 // (Might be the load class or an initialization check).
230 HInstruction* const at_;
231
232 // The dex PC of `at_`.
233 const uint32_t dex_pc_;
234
235 // Whether to initialize the class.
236 const bool do_clinit_;
237
238 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100239};
240
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000241class LoadStringSlowPathARM : public SlowPathCodeARM {
242 public:
243 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
244
245 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
246 LocationSummary* locations = instruction_->GetLocations();
247 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
248
249 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
250 __ Bind(GetEntryLabel());
251 codegen->SaveLiveRegisters(locations);
252
253 InvokeRuntimeCallingConvention calling_convention;
254 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0));
255 __ LoadImmediate(calling_convention.GetRegisterAt(1), instruction_->GetStringIndex());
256 arm_codegen->InvokeRuntime(
257 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
258 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
259
260 codegen->RestoreLiveRegisters(locations);
261 __ b(GetExitLabel());
262 }
263
264 private:
265 HLoadString* const instruction_;
266
267 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
268};
269
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000270class TypeCheckSlowPathARM : public SlowPathCodeARM {
271 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000272 TypeCheckSlowPathARM(HInstruction* instruction,
273 Location class_to_check,
274 Location object_class,
275 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000276 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000277 class_to_check_(class_to_check),
278 object_class_(object_class),
279 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000280
281 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
282 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000283 DCHECK(instruction_->IsCheckCast()
284 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000285
286 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
287 __ Bind(GetEntryLabel());
288 codegen->SaveLiveRegisters(locations);
289
290 // We're moving two locations to locations that could overlap, so we need a parallel
291 // move resolver.
292 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000293 MoveOperands move1(class_to_check_,
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000294 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
295 nullptr);
296 MoveOperands move2(object_class_,
297 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
298 nullptr);
299 HParallelMove parallel_move(codegen->GetGraph()->GetArena());
300 parallel_move.AddMove(&move1);
301 parallel_move.AddMove(&move2);
302 arm_codegen->GetMoveResolver()->EmitNativeCode(&parallel_move);
303
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000304 if (instruction_->IsInstanceOf()) {
305 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_);
306 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
307 } else {
308 DCHECK(instruction_->IsCheckCast());
309 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_);
310 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000311
312 codegen->RestoreLiveRegisters(locations);
313 __ b(GetExitLabel());
314 }
315
316 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000317 HInstruction* const instruction_;
318 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000319 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000320 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000321
322 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
323};
324
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000325#undef __
326
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100327#undef __
328#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700329
330inline Condition ARMCondition(IfCondition cond) {
331 switch (cond) {
332 case kCondEQ: return EQ;
333 case kCondNE: return NE;
334 case kCondLT: return LT;
335 case kCondLE: return LE;
336 case kCondGT: return GT;
337 case kCondGE: return GE;
338 default:
339 LOG(FATAL) << "Unknown if condition";
340 }
341 return EQ; // Unreachable.
342}
343
344inline Condition ARMOppositeCondition(IfCondition cond) {
345 switch (cond) {
346 case kCondEQ: return NE;
347 case kCondNE: return EQ;
348 case kCondLT: return GE;
349 case kCondLE: return GT;
350 case kCondGT: return LE;
351 case kCondGE: return LT;
352 default:
353 LOG(FATAL) << "Unknown if condition";
354 }
355 return EQ; // Unreachable.
356}
357
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100358void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
359 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
360}
361
362void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000363 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100364}
365
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100366size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
367 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
368 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100369}
370
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100371size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
372 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
373 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100374}
375
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100376CodeGeneratorARM::CodeGeneratorARM(HGraph* graph)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000377 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100378 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100379 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100380 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100381 move_resolver_(graph->GetArena(), this),
382 assembler_(true) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100383
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100384size_t CodeGeneratorARM::FrameEntrySpillSize() const {
385 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
386}
387
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100388Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100389 switch (type) {
390 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100391 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100392 ArmManagedRegister pair =
393 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100394 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
395 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
396
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100397 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
398 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100399 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100400 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100401 }
402
403 case Primitive::kPrimByte:
404 case Primitive::kPrimBoolean:
405 case Primitive::kPrimChar:
406 case Primitive::kPrimShort:
407 case Primitive::kPrimInt:
408 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100409 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100410 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100411 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
412 ArmManagedRegister current =
413 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
414 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100415 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100416 }
417 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100418 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100419 }
420
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000421 case Primitive::kPrimFloat: {
422 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100423 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100424 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100425
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000426 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000427 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
428 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000429 return Location::FpuRegisterPairLocation(reg, reg + 1);
430 }
431
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100432 case Primitive::kPrimVoid:
433 LOG(FATAL) << "Unreachable type " << type;
434 }
435
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100436 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100437}
438
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100439void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100440 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100441 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100442
443 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100444 blocked_core_registers_[SP] = true;
445 blocked_core_registers_[LR] = true;
446 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100447
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100448 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100449 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100450
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100451 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100452 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100453
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100454 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100455 // We always save and restore R6 and R7 to make sure we can use three
456 // register pairs for long operations.
Nicolas Geoffray44b819e2014-11-06 12:00:54 +0000457 blocked_core_registers_[R4] = true;
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100458 blocked_core_registers_[R5] = true;
459 blocked_core_registers_[R8] = true;
460 blocked_core_registers_[R10] = true;
461 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100462
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000463 blocked_fpu_registers_[S16] = true;
464 blocked_fpu_registers_[S17] = true;
465 blocked_fpu_registers_[S18] = true;
466 blocked_fpu_registers_[S19] = true;
467 blocked_fpu_registers_[S20] = true;
468 blocked_fpu_registers_[S21] = true;
469 blocked_fpu_registers_[S22] = true;
470 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000471 blocked_fpu_registers_[S24] = true;
472 blocked_fpu_registers_[S25] = true;
473 blocked_fpu_registers_[S26] = true;
474 blocked_fpu_registers_[S27] = true;
475 blocked_fpu_registers_[S28] = true;
476 blocked_fpu_registers_[S29] = true;
477 blocked_fpu_registers_[S30] = true;
478 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100479
480 UpdateBlockedPairRegisters();
481}
482
483void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
484 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
485 ArmManagedRegister current =
486 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
487 if (blocked_core_registers_[current.AsRegisterPairLow()]
488 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
489 blocked_register_pairs_[i] = true;
490 }
491 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100492}
493
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100494InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
495 : HGraphVisitor(graph),
496 assembler_(codegen->GetAssembler()),
497 codegen_(codegen) {}
498
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000499void CodeGeneratorARM::GenerateFrameEntry() {
Dave Allison648d7112014-07-25 16:15:27 -0700500 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100501 if (!skip_overflow_check) {
502 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100503 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100504 AddSlowPath(slow_path);
505
506 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
507 __ cmp(SP, ShifterOperand(IP));
508 __ b(slow_path->GetEntryLabel(), CC);
509 } else {
510 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100511 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100512 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100513 }
514 }
515
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100516 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
517 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000518
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100519 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100520 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100521 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000522}
523
524void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100525 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100526 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000527}
528
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100529void CodeGeneratorARM::Bind(HBasicBlock* block) {
530 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000531}
532
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100533Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
534 switch (load->GetType()) {
535 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100536 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100537 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
538 break;
539
540 case Primitive::kPrimInt:
541 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100542 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100543 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100544
545 case Primitive::kPrimBoolean:
546 case Primitive::kPrimByte:
547 case Primitive::kPrimChar:
548 case Primitive::kPrimShort:
549 case Primitive::kPrimVoid:
550 LOG(FATAL) << "Unexpected type " << load->GetType();
551 }
552
553 LOG(FATAL) << "Unreachable";
554 return Location();
555}
556
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100557Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
558 switch (type) {
559 case Primitive::kPrimBoolean:
560 case Primitive::kPrimByte:
561 case Primitive::kPrimChar:
562 case Primitive::kPrimShort:
563 case Primitive::kPrimInt:
564 case Primitive::kPrimNot: {
565 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000566 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100567 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100568 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100569 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000570 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100571 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100572 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100573
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000574 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100575 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000576 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100577 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000578 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100579 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100580 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
581 calling_convention.GetRegisterPairAt(index));
582 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100583 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000584 return Location::QuickParameter(index, stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100585 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000586 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
587 }
588 }
589
590 case Primitive::kPrimFloat: {
591 uint32_t stack_index = stack_index_++;
592 if (float_index_ % 2 == 0) {
593 float_index_ = std::max(double_index_, float_index_);
594 }
595 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
596 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
597 } else {
598 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
599 }
600 }
601
602 case Primitive::kPrimDouble: {
603 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
604 uint32_t stack_index = stack_index_;
605 stack_index_ += 2;
606 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
607 uint32_t index = double_index_;
608 double_index_ += 2;
609 return Location::FpuRegisterPairLocation(
610 calling_convention.GetFpuRegisterAt(index),
611 calling_convention.GetFpuRegisterAt(index + 1));
612 } else {
613 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100614 }
615 }
616
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100617 case Primitive::kPrimVoid:
618 LOG(FATAL) << "Unexpected parameter type " << type;
619 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100620 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100621 return Location();
622}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100623
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000624Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
625 switch (type) {
626 case Primitive::kPrimBoolean:
627 case Primitive::kPrimByte:
628 case Primitive::kPrimChar:
629 case Primitive::kPrimShort:
630 case Primitive::kPrimInt:
631 case Primitive::kPrimNot: {
632 return Location::RegisterLocation(R0);
633 }
634
635 case Primitive::kPrimFloat: {
636 return Location::FpuRegisterLocation(S0);
637 }
638
639 case Primitive::kPrimLong: {
640 return Location::RegisterPairLocation(R0, R1);
641 }
642
643 case Primitive::kPrimDouble: {
644 return Location::FpuRegisterPairLocation(S0, S1);
645 }
646
647 case Primitive::kPrimVoid:
648 return Location();
649 }
650 UNREACHABLE();
651 return Location();
652}
653
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100654void CodeGeneratorARM::Move32(Location destination, Location source) {
655 if (source.Equals(destination)) {
656 return;
657 }
658 if (destination.IsRegister()) {
659 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100660 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100661 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000662 __ vmovrs(destination.As<Register>(), source.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100663 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100664 __ LoadFromOffset(kLoadWord, destination.As<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100665 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100666 } else if (destination.IsFpuRegister()) {
667 if (source.IsRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000668 __ vmovsr(destination.As<SRegister>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100669 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000670 __ vmovs(destination.As<SRegister>(), source.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100671 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000672 __ LoadSFromOffset(destination.As<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100673 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100674 } else {
675 DCHECK(destination.IsStackSlot());
676 if (source.IsRegister()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100677 __ StoreToOffset(kStoreWord, source.As<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100678 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000679 __ StoreSToOffset(source.As<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100680 } else {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100681 DCHECK(source.IsStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100682 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
683 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100684 }
685 }
686}
687
688void CodeGeneratorARM::Move64(Location destination, Location source) {
689 if (source.Equals(destination)) {
690 return;
691 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100692 if (destination.IsRegisterPair()) {
693 if (source.IsRegisterPair()) {
694 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
695 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100696 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000697 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100698 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000699 uint16_t register_index = source.GetQuickParameterRegisterIndex();
700 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100701 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100702 __ Mov(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000703 calling_convention.GetRegisterAt(register_index));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100704 __ LoadFromOffset(kLoadWord, destination.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000705 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100706 } else {
707 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100708 if (destination.AsRegisterPairLow<Register>() == R1) {
709 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100710 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
711 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100712 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100713 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100714 SP, source.GetStackIndex());
715 }
716 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000717 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100718 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000719 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
720 SP,
721 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100722 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000723 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100724 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100725 } else if (destination.IsQuickParameter()) {
726 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000727 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
728 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100729 if (source.IsRegisterPair()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000730 __ Mov(calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100731 source.AsRegisterPairLow<Register>());
732 __ StoreToOffset(kStoreWord, source.AsRegisterPairHigh<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000733 SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100734 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000735 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100736 } else {
737 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000738 __ LoadFromOffset(
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000739 kLoadWord, calling_convention.GetRegisterAt(register_index), SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100740 __ LoadFromOffset(kLoadWord, R0, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000741 __ StoreToOffset(kStoreWord, R0, SP, calling_convention.GetStackOffsetOf(stack_index + 1));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100742 }
743 } else {
744 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100745 if (source.IsRegisterPair()) {
746 if (source.AsRegisterPairLow<Register>() == R1) {
747 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100748 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
749 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100750 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100751 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100752 SP, destination.GetStackIndex());
753 }
754 } else if (source.IsQuickParameter()) {
755 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000756 uint16_t register_index = source.GetQuickParameterRegisterIndex();
757 uint16_t stack_index = source.GetQuickParameterStackIndex();
758 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100759 SP, destination.GetStackIndex());
760 __ LoadFromOffset(kLoadWord, R0,
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000761 SP, calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100762 __ StoreToOffset(kStoreWord, R0, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000763 } else if (source.IsFpuRegisterPair()) {
764 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
765 SP,
766 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100767 } else {
768 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100769 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
770 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
771 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
772 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100773 }
774 }
775}
776
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100777void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100778 LocationSummary* locations = instruction->GetLocations();
779 if (locations != nullptr && locations->Out().Equals(location)) {
780 return;
781 }
782
Roland Levillain476df552014-10-09 17:51:36 +0100783 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100784 int32_t value = instruction->AsIntConstant()->GetValue();
785 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100786 __ LoadImmediate(location.As<Register>(), value);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100787 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100788 DCHECK(location.IsStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100789 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100790 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100791 }
Roland Levillain476df552014-10-09 17:51:36 +0100792 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100793 int64_t value = instruction->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100794 if (location.IsRegisterPair()) {
795 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
796 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100797 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100798 DCHECK(location.IsDoubleStackSlot());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100799 __ LoadImmediate(IP, Low32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100800 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100801 __ LoadImmediate(IP, High32Bits(value));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100802 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100803 }
Roland Levillain476df552014-10-09 17:51:36 +0100804 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100805 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
806 switch (instruction->GetType()) {
807 case Primitive::kPrimBoolean:
808 case Primitive::kPrimByte:
809 case Primitive::kPrimChar:
810 case Primitive::kPrimShort:
811 case Primitive::kPrimInt:
812 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100813 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100814 Move32(location, Location::StackSlot(stack_slot));
815 break;
816
817 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100818 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100819 Move64(location, Location::DoubleStackSlot(stack_slot));
820 break;
821
822 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100823 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100824 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000825 } else if (instruction->IsTemporary()) {
826 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000827 if (temp_location.IsStackSlot()) {
828 Move32(location, temp_location);
829 } else {
830 DCHECK(temp_location.IsDoubleStackSlot());
831 Move64(location, temp_location);
832 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000833 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100834 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100835 switch (instruction->GetType()) {
836 case Primitive::kPrimBoolean:
837 case Primitive::kPrimByte:
838 case Primitive::kPrimChar:
839 case Primitive::kPrimShort:
840 case Primitive::kPrimNot:
841 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100842 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100843 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100844 break;
845
846 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100847 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100848 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100849 break;
850
851 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100852 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100853 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000854 }
855}
856
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100857void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
858 HInstruction* instruction,
859 uint32_t dex_pc) {
860 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
861 __ blx(LR);
862 RecordPcInfo(instruction, dex_pc);
863 DCHECK(instruction->IsSuspendCheck()
864 || instruction->IsBoundsCheck()
865 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000866 || instruction->IsDivZeroCheck()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100867 || !IsLeafMethod());
868}
869
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000870void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000871 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000872}
873
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000874void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000875 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100876 DCHECK(!successor->IsExitBlock());
877
878 HBasicBlock* block = got->GetBlock();
879 HInstruction* previous = got->GetPrevious();
880
881 HLoopInformation* info = block->GetLoopInformation();
882 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
883 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
884 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
885 return;
886 }
887
888 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
889 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
890 }
891 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000892 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000893 }
894}
895
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000896void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000897 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000898}
899
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000900void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700901 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000902 if (kIsDebugBuild) {
903 __ Comment("Unreachable");
904 __ bkpt(0);
905 }
906}
907
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000908void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100909 LocationSummary* locations =
910 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100911 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100912 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100913 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100914 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000915}
916
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000917void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700918 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100919 if (cond->IsIntConstant()) {
920 // Constant condition, statically compared against 1.
921 int32_t cond_value = cond->AsIntConstant()->GetValue();
922 if (cond_value == 1) {
923 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
924 if_instr->IfTrueSuccessor())) {
925 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100926 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100927 return;
928 } else {
929 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100930 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100931 } else {
932 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
933 // Condition has been materialized, compare the output to 0
934 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
935 __ cmp(if_instr->GetLocations()->InAt(0).As<Register>(),
936 ShifterOperand(0));
937 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
938 } else {
939 // Condition has not been materialized, use its inputs as the
940 // comparison and its condition as the branch condition.
941 LocationSummary* locations = cond->GetLocations();
942 if (locations->InAt(1).IsRegister()) {
943 __ cmp(locations->InAt(0).As<Register>(),
944 ShifterOperand(locations->InAt(1).As<Register>()));
945 } else {
946 DCHECK(locations->InAt(1).IsConstant());
947 int32_t value =
948 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
949 ShifterOperand operand;
950 if (ShifterOperand::CanHoldArm(value, &operand)) {
951 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
952 } else {
953 Register temp = IP;
954 __ LoadImmediate(temp, value);
955 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
956 }
957 }
958 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
959 ARMCondition(cond->AsCondition()->GetCondition()));
960 }
Dave Allison20dfc792014-06-16 20:44:29 -0700961 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100962 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
963 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700964 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000965 }
966}
967
Dave Allison20dfc792014-06-16 20:44:29 -0700968
969void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100970 LocationSummary* locations =
971 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100972 locations->SetInAt(0, Location::RequiresRegister());
973 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100974 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100975 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100976 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000977}
978
Dave Allison20dfc792014-06-16 20:44:29 -0700979void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100980 if (!comp->NeedsMaterialization()) return;
981
982 LocationSummary* locations = comp->GetLocations();
983 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100984 __ cmp(locations->InAt(0).As<Register>(),
985 ShifterOperand(locations->InAt(1).As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100986 } else {
987 DCHECK(locations->InAt(1).IsConstant());
988 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
989 ShifterOperand operand;
990 if (ShifterOperand::CanHoldArm(value, &operand)) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100991 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100992 } else {
993 Register temp = IP;
994 __ LoadImmediate(temp, value);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100995 __ cmp(locations->InAt(0).As<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100996 }
Dave Allison20dfc792014-06-16 20:44:29 -0700997 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100998 __ it(ARMCondition(comp->GetCondition()), kItElse);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100999 __ mov(locations->Out().As<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001000 ARMCondition(comp->GetCondition()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001001 __ mov(locations->Out().As<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001002 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001003}
1004
1005void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1006 VisitCondition(comp);
1007}
1008
1009void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1010 VisitCondition(comp);
1011}
1012
1013void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1014 VisitCondition(comp);
1015}
1016
1017void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1018 VisitCondition(comp);
1019}
1020
1021void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1022 VisitCondition(comp);
1023}
1024
1025void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1026 VisitCondition(comp);
1027}
1028
1029void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1030 VisitCondition(comp);
1031}
1032
1033void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1034 VisitCondition(comp);
1035}
1036
1037void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1038 VisitCondition(comp);
1039}
1040
1041void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1042 VisitCondition(comp);
1043}
1044
1045void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1046 VisitCondition(comp);
1047}
1048
1049void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1050 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001051}
1052
1053void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001054 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001055}
1056
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001057void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1058 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001059}
1060
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001061void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001062 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001063}
1064
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001065void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001066 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001067 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001068}
1069
1070void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001071 LocationSummary* locations =
1072 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001073 switch (store->InputAt(1)->GetType()) {
1074 case Primitive::kPrimBoolean:
1075 case Primitive::kPrimByte:
1076 case Primitive::kPrimChar:
1077 case Primitive::kPrimShort:
1078 case Primitive::kPrimInt:
1079 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001080 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001081 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1082 break;
1083
1084 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001085 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001086 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1087 break;
1088
1089 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001090 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001091 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001092}
1093
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001094void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001095 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001096}
1097
1098void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001099 LocationSummary* locations =
1100 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001101 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001102}
1103
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001104void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001105 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001106 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001107}
1108
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001109void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001110 LocationSummary* locations =
1111 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001112 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001113}
1114
1115void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1116 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001117 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001118}
1119
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001120void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1121 LocationSummary* locations =
1122 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1123 locations->SetOut(Location::ConstantLocation(constant));
1124}
1125
1126void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1127 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001128 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001129}
1130
1131void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1132 LocationSummary* locations =
1133 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1134 locations->SetOut(Location::ConstantLocation(constant));
1135}
1136
1137void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1138 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001139 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001140}
1141
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001142void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001143 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001144}
1145
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001146void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001147 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001148 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001149}
1150
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001151void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001152 LocationSummary* locations =
1153 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001154 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001155}
1156
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001157void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001158 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001159 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001160}
1161
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001162void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001163 HandleInvoke(invoke);
1164}
1165
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001166void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001167 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001168}
1169
1170void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001171 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001172
1173 // TODO: Implement all kinds of calls:
1174 // 1) boot -> boot
1175 // 2) app -> boot
1176 // 3) app -> app
1177 //
1178 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1179
1180 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001181 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001182 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001183 __ LoadFromOffset(
1184 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001185 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001186 __ LoadFromOffset(
1187 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001188 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001189 __ LoadFromOffset(kLoadWord, LR, temp,
1190 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001191 // LR()
1192 __ blx(LR);
1193
1194 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1195 DCHECK(!codegen_->IsLeafMethod());
1196}
1197
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001198void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001199 LocationSummary* locations =
1200 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001201 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001202
1203 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001204 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001205 HInstruction* input = invoke->InputAt(i);
1206 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1207 }
1208
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001209 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001210}
1211
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001212void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1213 HandleInvoke(invoke);
1214}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001215
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001216void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001217 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001218 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1219 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1220 LocationSummary* locations = invoke->GetLocations();
1221 Location receiver = locations->InAt(0);
1222 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1223 // temp = object->GetClass();
1224 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001225 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1226 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001227 } else {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001228 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001229 }
1230 // temp = temp->GetMethodAt(method_offset);
1231 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001232 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001233 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001234 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001235 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001236 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001237 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001238 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001239}
1240
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001241void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1242 HandleInvoke(invoke);
1243 // Add the hidden argument.
1244 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1245}
1246
1247void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1248 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1249 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
1250 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1251 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1252 LocationSummary* locations = invoke->GetLocations();
1253 Location receiver = locations->InAt(0);
1254 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1255
1256 // Set the hidden argument.
1257 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).As<Register>(), invoke->GetDexMethodIndex());
1258
1259 // temp = object->GetClass();
1260 if (receiver.IsStackSlot()) {
1261 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1262 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1263 } else {
1264 __ LoadFromOffset(kLoadWord, temp, receiver.As<Register>(), class_offset);
1265 }
1266 // temp = temp->GetImtEntryAt(method_offset);
1267 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value();
1268 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1269 // LR = temp->GetEntryPoint();
1270 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1271 // LR();
1272 __ blx(LR);
1273 DCHECK(!codegen_->IsLeafMethod());
1274 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1275}
1276
Roland Levillain88cb1752014-10-20 16:36:47 +01001277void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1278 LocationSummary* locations =
1279 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1280 switch (neg->GetResultType()) {
1281 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001282 case Primitive::kPrimLong: {
1283 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001284 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001285 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001286 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001287 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001288
Roland Levillain88cb1752014-10-20 16:36:47 +01001289 case Primitive::kPrimFloat:
1290 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001291 locations->SetInAt(0, Location::RequiresFpuRegister());
1292 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001293 break;
1294
1295 default:
1296 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1297 }
1298}
1299
1300void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1301 LocationSummary* locations = neg->GetLocations();
1302 Location out = locations->Out();
1303 Location in = locations->InAt(0);
1304 switch (neg->GetResultType()) {
1305 case Primitive::kPrimInt:
1306 DCHECK(in.IsRegister());
Roland Levillainb762d2e2014-10-22 10:11:06 +01001307 __ rsb(out.As<Register>(), in.As<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001308 break;
1309
1310 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001311 DCHECK(in.IsRegisterPair());
1312 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1313 __ rsbs(out.AsRegisterPairLow<Register>(),
1314 in.AsRegisterPairLow<Register>(),
1315 ShifterOperand(0));
1316 // We cannot emit an RSC (Reverse Subtract with Carry)
1317 // instruction here, as it does not exist in the Thumb-2
1318 // instruction set. We use the following approach
1319 // using SBC and SUB instead.
1320 //
1321 // out.hi = -C
1322 __ sbc(out.AsRegisterPairHigh<Register>(),
1323 out.AsRegisterPairHigh<Register>(),
1324 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1325 // out.hi = out.hi - in.hi
1326 __ sub(out.AsRegisterPairHigh<Register>(),
1327 out.AsRegisterPairHigh<Register>(),
1328 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1329 break;
1330
Roland Levillain88cb1752014-10-20 16:36:47 +01001331 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001332 DCHECK(in.IsFpuRegister());
1333 __ vnegs(out.As<SRegister>(), in.As<SRegister>());
1334 break;
1335
Roland Levillain88cb1752014-10-20 16:36:47 +01001336 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001337 DCHECK(in.IsFpuRegisterPair());
1338 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1339 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001340 break;
1341
1342 default:
1343 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1344 }
1345}
1346
Roland Levillaindff1f282014-11-05 14:15:05 +00001347void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
1348 LocationSummary* locations =
1349 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
1350 Primitive::Type result_type = conversion->GetResultType();
1351 Primitive::Type input_type = conversion->GetInputType();
1352 switch (result_type) {
Roland Levillain946e1432014-11-11 17:35:19 +00001353 case Primitive::kPrimInt:
1354 switch (input_type) {
1355 case Primitive::kPrimLong:
1356 // long-to-int conversion.
1357 locations->SetInAt(0, Location::Any());
1358 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1359 break;
1360
1361 case Primitive::kPrimFloat:
1362 case Primitive::kPrimDouble:
1363 LOG(FATAL) << "Type conversion from " << input_type
1364 << " to " << result_type << " not yet implemented";
1365 break;
1366
1367 default:
1368 LOG(FATAL) << "Unexpected type conversion from " << input_type
1369 << " to " << result_type;
1370 }
1371 break;
1372
Roland Levillaindff1f282014-11-05 14:15:05 +00001373 case Primitive::kPrimLong:
1374 switch (input_type) {
1375 case Primitive::kPrimByte:
1376 case Primitive::kPrimShort:
1377 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001378 case Primitive::kPrimChar:
Roland Levillaindff1f282014-11-05 14:15:05 +00001379 // int-to-long conversion.
1380 locations->SetInAt(0, Location::RequiresRegister());
1381 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1382 break;
1383
1384 case Primitive::kPrimFloat:
1385 case Primitive::kPrimDouble:
1386 LOG(FATAL) << "Type conversion from " << input_type << " to "
1387 << result_type << " not yet implemented";
1388 break;
1389
1390 default:
1391 LOG(FATAL) << "Unexpected type conversion from " << input_type
1392 << " to " << result_type;
1393 }
1394 break;
1395
Roland Levillaindff1f282014-11-05 14:15:05 +00001396 case Primitive::kPrimFloat:
1397 case Primitive::kPrimDouble:
1398 LOG(FATAL) << "Type conversion from " << input_type
1399 << " to " << result_type << " not yet implemented";
1400 break;
1401
1402 default:
1403 LOG(FATAL) << "Unexpected type conversion from " << input_type
1404 << " to " << result_type;
1405 }
1406}
1407
1408void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1409 LocationSummary* locations = conversion->GetLocations();
1410 Location out = locations->Out();
1411 Location in = locations->InAt(0);
1412 Primitive::Type result_type = conversion->GetResultType();
1413 Primitive::Type input_type = conversion->GetInputType();
1414 switch (result_type) {
Roland Levillain946e1432014-11-11 17:35:19 +00001415 case Primitive::kPrimInt:
1416 switch (input_type) {
1417 case Primitive::kPrimLong:
1418 // long-to-int conversion.
1419 DCHECK(out.IsRegister());
1420 if (in.IsRegisterPair()) {
1421 __ Mov(out.As<Register>(), in.AsRegisterPairLow<Register>());
1422 } else if (in.IsDoubleStackSlot()) {
1423 __ LoadFromOffset(kLoadWord, out.As<Register>(), SP, in.GetStackIndex());
1424 } else {
1425 DCHECK(in.IsConstant());
1426 DCHECK(in.GetConstant()->IsLongConstant());
1427 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
1428 __ LoadImmediate(out.As<Register>(), static_cast<int32_t>(value));
1429 }
1430 break;
1431
1432 case Primitive::kPrimFloat:
1433 case Primitive::kPrimDouble:
1434 LOG(FATAL) << "Type conversion from " << input_type
1435 << " to " << result_type << " not yet implemented";
1436 break;
1437
1438 default:
1439 LOG(FATAL) << "Unexpected type conversion from " << input_type
1440 << " to " << result_type;
1441 }
1442 break;
1443
Roland Levillaindff1f282014-11-05 14:15:05 +00001444 case Primitive::kPrimLong:
1445 switch (input_type) {
1446 case Primitive::kPrimByte:
1447 case Primitive::kPrimShort:
1448 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001449 case Primitive::kPrimChar:
Roland Levillaindff1f282014-11-05 14:15:05 +00001450 // int-to-long conversion.
1451 DCHECK(out.IsRegisterPair());
1452 DCHECK(in.IsRegister());
1453 __ Mov(out.AsRegisterPairLow<Register>(), in.As<Register>());
1454 // Sign extension.
1455 __ Asr(out.AsRegisterPairHigh<Register>(),
1456 out.AsRegisterPairLow<Register>(),
1457 31);
1458 break;
1459
1460 case Primitive::kPrimFloat:
1461 case Primitive::kPrimDouble:
1462 LOG(FATAL) << "Type conversion from " << input_type << " to "
1463 << result_type << " not yet implemented";
1464 break;
1465
1466 default:
1467 LOG(FATAL) << "Unexpected type conversion from " << input_type
1468 << " to " << result_type;
1469 }
1470 break;
1471
Roland Levillaindff1f282014-11-05 14:15:05 +00001472 case Primitive::kPrimFloat:
1473 case Primitive::kPrimDouble:
1474 LOG(FATAL) << "Type conversion from " << input_type
1475 << " to " << result_type << " not yet implemented";
1476 break;
1477
1478 default:
1479 LOG(FATAL) << "Unexpected type conversion from " << input_type
1480 << " to " << result_type;
1481 }
1482}
1483
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001484void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001485 LocationSummary* locations =
1486 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001487 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001488 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001489 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001490 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1491 locations->SetInAt(0, Location::RequiresRegister());
1492 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1493 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001494 break;
1495 }
1496
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001497 case Primitive::kPrimFloat:
1498 case Primitive::kPrimDouble: {
1499 locations->SetInAt(0, Location::RequiresFpuRegister());
1500 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001501 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001502 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001503 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001504
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001505 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001506 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001507 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001508}
1509
1510void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1511 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001512 Location out = locations->Out();
1513 Location first = locations->InAt(0);
1514 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001515 switch (add->GetResultType()) {
1516 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001517 if (second.IsRegister()) {
1518 __ add(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001519 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001520 __ AddConstant(out.As<Register>(),
1521 first.As<Register>(),
1522 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001523 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001524 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001525
1526 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001527 __ adds(out.AsRegisterPairLow<Register>(),
1528 first.AsRegisterPairLow<Register>(),
1529 ShifterOperand(second.AsRegisterPairLow<Register>()));
1530 __ adc(out.AsRegisterPairHigh<Register>(),
1531 first.AsRegisterPairHigh<Register>(),
1532 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001533 break;
1534
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001535 case Primitive::kPrimFloat:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001536 __ vadds(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001537 break;
1538
1539 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001540 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1541 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1542 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001543 break;
1544
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001545 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001546 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001547 }
1548}
1549
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001550void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001551 LocationSummary* locations =
1552 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001553 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001554 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001555 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001556 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1557 locations->SetInAt(0, Location::RequiresRegister());
1558 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1559 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001560 break;
1561 }
Calin Juravle11351682014-10-23 15:38:15 +01001562 case Primitive::kPrimFloat:
1563 case Primitive::kPrimDouble: {
1564 locations->SetInAt(0, Location::RequiresFpuRegister());
1565 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001566 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001567 break;
Calin Juravle11351682014-10-23 15:38:15 +01001568 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001569 default:
Calin Juravle11351682014-10-23 15:38:15 +01001570 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001571 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001572}
1573
1574void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1575 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001576 Location out = locations->Out();
1577 Location first = locations->InAt(0);
1578 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001579 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001580 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001581 if (second.IsRegister()) {
1582 __ sub(out.As<Register>(), first.As<Register>(), ShifterOperand(second.As<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001583 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001584 __ AddConstant(out.As<Register>(),
1585 first.As<Register>(),
1586 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001587 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001588 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001589 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001590
Calin Juravle11351682014-10-23 15:38:15 +01001591 case Primitive::kPrimLong: {
1592 __ subs(out.AsRegisterPairLow<Register>(),
1593 first.AsRegisterPairLow<Register>(),
1594 ShifterOperand(second.AsRegisterPairLow<Register>()));
1595 __ sbc(out.AsRegisterPairHigh<Register>(),
1596 first.AsRegisterPairHigh<Register>(),
1597 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001598 break;
Calin Juravle11351682014-10-23 15:38:15 +01001599 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001600
Calin Juravle11351682014-10-23 15:38:15 +01001601 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001602 __ vsubs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001603 break;
Calin Juravle11351682014-10-23 15:38:15 +01001604 }
1605
1606 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001607 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1608 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1609 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001610 break;
1611 }
1612
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001613
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001614 default:
Calin Juravle11351682014-10-23 15:38:15 +01001615 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001616 }
1617}
1618
Calin Juravle34bacdf2014-10-07 20:23:36 +01001619void LocationsBuilderARM::VisitMul(HMul* mul) {
1620 LocationSummary* locations =
1621 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1622 switch (mul->GetResultType()) {
1623 case Primitive::kPrimInt:
1624 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001625 locations->SetInAt(0, Location::RequiresRegister());
1626 locations->SetInAt(1, Location::RequiresRegister());
1627 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001628 break;
1629 }
1630
Calin Juravleb5bfa962014-10-21 18:02:24 +01001631 case Primitive::kPrimFloat:
1632 case Primitive::kPrimDouble: {
1633 locations->SetInAt(0, Location::RequiresFpuRegister());
1634 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001635 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001636 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001637 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001638
1639 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001640 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001641 }
1642}
1643
1644void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1645 LocationSummary* locations = mul->GetLocations();
1646 Location out = locations->Out();
1647 Location first = locations->InAt(0);
1648 Location second = locations->InAt(1);
1649 switch (mul->GetResultType()) {
1650 case Primitive::kPrimInt: {
1651 __ mul(out.As<Register>(), first.As<Register>(), second.As<Register>());
1652 break;
1653 }
1654 case Primitive::kPrimLong: {
1655 Register out_hi = out.AsRegisterPairHigh<Register>();
1656 Register out_lo = out.AsRegisterPairLow<Register>();
1657 Register in1_hi = first.AsRegisterPairHigh<Register>();
1658 Register in1_lo = first.AsRegisterPairLow<Register>();
1659 Register in2_hi = second.AsRegisterPairHigh<Register>();
1660 Register in2_lo = second.AsRegisterPairLow<Register>();
1661
1662 // Extra checks to protect caused by the existence of R1_R2.
1663 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1664 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1665 DCHECK_NE(out_hi, in1_lo);
1666 DCHECK_NE(out_hi, in2_lo);
1667
1668 // input: in1 - 64 bits, in2 - 64 bits
1669 // output: out
1670 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1671 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1672 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1673
1674 // IP <- in1.lo * in2.hi
1675 __ mul(IP, in1_lo, in2_hi);
1676 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1677 __ mla(out_hi, in1_hi, in2_lo, IP);
1678 // out.lo <- (in1.lo * in2.lo)[31:0];
1679 __ umull(out_lo, IP, in1_lo, in2_lo);
1680 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1681 __ add(out_hi, out_hi, ShifterOperand(IP));
1682 break;
1683 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001684
1685 case Primitive::kPrimFloat: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001686 __ vmuls(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001687 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001688 }
1689
1690 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001691 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1692 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1693 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001694 break;
1695 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001696
1697 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001698 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001699 }
1700}
1701
Calin Juravle7c4954d2014-10-28 16:57:40 +00001702void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001703 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
1704 ? LocationSummary::kCall
1705 : LocationSummary::kNoCall;
1706 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
1707
Calin Juravle7c4954d2014-10-28 16:57:40 +00001708 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001709 case Primitive::kPrimInt: {
1710 locations->SetInAt(0, Location::RequiresRegister());
1711 locations->SetInAt(1, Location::RequiresRegister());
1712 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1713 break;
1714 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00001715 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001716 InvokeRuntimeCallingConvention calling_convention;
1717 locations->SetInAt(0, Location::RegisterPairLocation(
1718 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1719 locations->SetInAt(1, Location::RegisterPairLocation(
1720 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
1721 // The runtime helper puts the output in R0,R2.
1722 locations->SetOut(Location::RegisterPairLocation(R0, R2));
Calin Juravle7c4954d2014-10-28 16:57:40 +00001723 break;
1724 }
1725 case Primitive::kPrimFloat:
1726 case Primitive::kPrimDouble: {
1727 locations->SetInAt(0, Location::RequiresFpuRegister());
1728 locations->SetInAt(1, Location::RequiresFpuRegister());
1729 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1730 break;
1731 }
1732
1733 default:
1734 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1735 }
1736}
1737
1738void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1739 LocationSummary* locations = div->GetLocations();
1740 Location out = locations->Out();
1741 Location first = locations->InAt(0);
1742 Location second = locations->InAt(1);
1743
1744 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001745 case Primitive::kPrimInt: {
1746 __ sdiv(out.As<Register>(), first.As<Register>(), second.As<Register>());
1747 break;
1748 }
1749
Calin Juravle7c4954d2014-10-28 16:57:40 +00001750 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001751 InvokeRuntimeCallingConvention calling_convention;
1752 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
1753 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
1754 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
1755 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
1756 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
1757 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
1758
1759 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001760 break;
1761 }
1762
1763 case Primitive::kPrimFloat: {
1764 __ vdivs(out.As<SRegister>(), first.As<SRegister>(), second.As<SRegister>());
1765 break;
1766 }
1767
1768 case Primitive::kPrimDouble: {
1769 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1770 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1771 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
1772 break;
1773 }
1774
1775 default:
1776 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1777 }
1778}
1779
Calin Juravled0d48522014-11-04 16:40:20 +00001780void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1781 LocationSummary* locations =
1782 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001783 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00001784 if (instruction->HasUses()) {
1785 locations->SetOut(Location::SameAsFirstInput());
1786 }
1787}
1788
1789void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1790 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
1791 codegen_->AddSlowPath(slow_path);
1792
1793 LocationSummary* locations = instruction->GetLocations();
1794 Location value = locations->InAt(0);
1795
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001796 switch (instruction->GetType()) {
1797 case Primitive::kPrimInt: {
1798 if (value.IsRegister()) {
1799 __ cmp(value.As<Register>(), ShifterOperand(0));
1800 __ b(slow_path->GetEntryLabel(), EQ);
1801 } else {
1802 DCHECK(value.IsConstant()) << value;
1803 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
1804 __ b(slow_path->GetEntryLabel());
1805 }
1806 }
1807 break;
1808 }
1809 case Primitive::kPrimLong: {
1810 if (value.IsRegisterPair()) {
1811 __ orrs(IP,
1812 value.AsRegisterPairLow<Register>(),
1813 ShifterOperand(value.AsRegisterPairHigh<Register>()));
1814 __ b(slow_path->GetEntryLabel(), EQ);
1815 } else {
1816 DCHECK(value.IsConstant()) << value;
1817 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
1818 __ b(slow_path->GetEntryLabel());
1819 }
1820 }
1821 break;
1822 default:
1823 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
1824 }
1825 }
Calin Juravled0d48522014-11-04 16:40:20 +00001826}
1827
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001828void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001829 LocationSummary* locations =
1830 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001831 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001832 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1833 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1834 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001835}
1836
1837void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
1838 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001839 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001840 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001841 codegen_->InvokeRuntime(
1842 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001843}
1844
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001845void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
1846 LocationSummary* locations =
1847 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1848 InvokeRuntimeCallingConvention calling_convention;
1849 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1850 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1851 locations->SetOut(Location::RegisterLocation(R0));
1852 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1853}
1854
1855void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
1856 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001857 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001858 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001859 codegen_->InvokeRuntime(
1860 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001861}
1862
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001863void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001864 LocationSummary* locations =
1865 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001866 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1867 if (location.IsStackSlot()) {
1868 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1869 } else if (location.IsDoubleStackSlot()) {
1870 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001871 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001872 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001873}
1874
1875void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001876 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001877 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001878}
1879
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001880void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001881 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001882 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001883 locations->SetInAt(0, Location::RequiresRegister());
1884 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001885}
1886
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001887void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
1888 LocationSummary* locations = not_->GetLocations();
1889 Location out = locations->Out();
1890 Location in = locations->InAt(0);
1891 switch (not_->InputAt(0)->GetType()) {
1892 case Primitive::kPrimBoolean:
1893 __ eor(out.As<Register>(), in.As<Register>(), ShifterOperand(1));
1894 break;
1895
1896 case Primitive::kPrimInt:
1897 __ mvn(out.As<Register>(), ShifterOperand(in.As<Register>()));
1898 break;
1899
1900 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001901 __ mvn(out.AsRegisterPairLow<Register>(),
1902 ShifterOperand(in.AsRegisterPairLow<Register>()));
1903 __ mvn(out.AsRegisterPairHigh<Register>(),
1904 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001905 break;
1906
1907 default:
1908 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1909 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001910}
1911
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001912void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001913 LocationSummary* locations =
1914 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001915 locations->SetInAt(0, Location::RequiresRegister());
1916 locations->SetInAt(1, Location::RequiresRegister());
1917 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001918}
1919
1920void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001921 LocationSummary* locations = compare->GetLocations();
1922 switch (compare->InputAt(0)->GetType()) {
1923 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001924 Register output = locations->Out().As<Register>();
1925 Location left = locations->InAt(0);
1926 Location right = locations->InAt(1);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001927 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001928 __ cmp(left.AsRegisterPairHigh<Register>(),
1929 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001930 __ b(&less, LT);
1931 __ b(&greater, GT);
Nicolas Geoffray8d486732014-07-16 16:23:40 +01001932 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect
1933 // the status flags.
1934 __ LoadImmediate(output, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001935 __ cmp(left.AsRegisterPairLow<Register>(),
1936 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001937 __ b(&done, EQ);
1938 __ b(&less, CC);
1939
1940 __ Bind(&greater);
1941 __ LoadImmediate(output, 1);
1942 __ b(&done);
1943
1944 __ Bind(&less);
1945 __ LoadImmediate(output, -1);
1946
1947 __ Bind(&done);
1948 break;
1949 }
1950 default:
1951 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1952 }
1953}
1954
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001955void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001956 LocationSummary* locations =
1957 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001958 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1959 locations->SetInAt(i, Location::Any());
1960 }
1961 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001962}
1963
1964void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001965 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01001966 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001967}
1968
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001969void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001970 LocationSummary* locations =
1971 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001972 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001973 locations->SetInAt(0, Location::RequiresRegister());
1974 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001975 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001976 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001977 locations->AddTemp(Location::RequiresRegister());
1978 locations->AddTemp(Location::RequiresRegister());
1979 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001980}
1981
1982void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1983 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001984 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001985 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001986 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001987
1988 switch (field_type) {
1989 case Primitive::kPrimBoolean:
1990 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001991 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001992 __ StoreToOffset(kStoreByte, value, obj, offset);
1993 break;
1994 }
1995
1996 case Primitive::kPrimShort:
1997 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001998 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001999 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2000 break;
2001 }
2002
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002003 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002004 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002005 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002006 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002007 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002008 Register temp = locations->GetTemp(0).As<Register>();
2009 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002010 codegen_->MarkGCCard(temp, card, obj, value);
2011 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002012 break;
2013 }
2014
2015 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002016 Location value = locations->InAt(1);
2017 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002018 break;
2019 }
2020
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002021 case Primitive::kPrimFloat: {
2022 SRegister value = locations->InAt(1).As<SRegister>();
2023 __ StoreSToOffset(value, obj, offset);
2024 break;
2025 }
2026
2027 case Primitive::kPrimDouble: {
2028 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
2029 __ StoreDToOffset(value, obj, offset);
2030 break;
2031 }
2032
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002033 case Primitive::kPrimVoid:
2034 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002035 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002036 }
2037}
2038
2039void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002040 LocationSummary* locations =
2041 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002042 locations->SetInAt(0, Location::RequiresRegister());
2043 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002044}
2045
2046void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2047 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002048 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002049 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2050
2051 switch (instruction->GetType()) {
2052 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002053 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002054 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2055 break;
2056 }
2057
2058 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002059 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002060 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2061 break;
2062 }
2063
2064 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002065 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002066 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2067 break;
2068 }
2069
2070 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002071 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002072 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2073 break;
2074 }
2075
2076 case Primitive::kPrimInt:
2077 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002078 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002079 __ LoadFromOffset(kLoadWord, out, obj, offset);
2080 break;
2081 }
2082
2083 case Primitive::kPrimLong: {
2084 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002085 Location out = locations->Out();
2086 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002087 break;
2088 }
2089
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002090 case Primitive::kPrimFloat: {
2091 SRegister out = locations->Out().As<SRegister>();
2092 __ LoadSFromOffset(out, obj, offset);
2093 break;
2094 }
2095
2096 case Primitive::kPrimDouble: {
2097 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2098 __ LoadDFromOffset(out, obj, offset);
2099 break;
2100 }
2101
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002102 case Primitive::kPrimVoid:
2103 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002104 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002105 }
2106}
2107
2108void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002109 LocationSummary* locations =
2110 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002111 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002112 if (instruction->HasUses()) {
2113 locations->SetOut(Location::SameAsFirstInput());
2114 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002115}
2116
2117void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002118 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002119 codegen_->AddSlowPath(slow_path);
2120
2121 LocationSummary* locations = instruction->GetLocations();
2122 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002123
2124 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002125 __ cmp(obj.As<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002126 __ b(slow_path->GetEntryLabel(), EQ);
2127 } else {
2128 DCHECK(obj.IsConstant()) << obj;
2129 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2130 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002131 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002132}
2133
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002134void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002135 LocationSummary* locations =
2136 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002137 locations->SetInAt(0, Location::RequiresRegister());
2138 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2139 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002140}
2141
2142void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2143 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002144 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002145 Location index = locations->InAt(1);
2146
2147 switch (instruction->GetType()) {
2148 case Primitive::kPrimBoolean: {
2149 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002150 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002151 if (index.IsConstant()) {
2152 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2153 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2154 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002155 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002156 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2157 }
2158 break;
2159 }
2160
2161 case Primitive::kPrimByte: {
2162 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002163 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002164 if (index.IsConstant()) {
2165 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2166 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2167 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002168 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002169 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2170 }
2171 break;
2172 }
2173
2174 case Primitive::kPrimShort: {
2175 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002176 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002177 if (index.IsConstant()) {
2178 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2179 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2180 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002181 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002182 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2183 }
2184 break;
2185 }
2186
2187 case Primitive::kPrimChar: {
2188 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002189 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002190 if (index.IsConstant()) {
2191 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2192 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2193 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002194 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002195 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2196 }
2197 break;
2198 }
2199
2200 case Primitive::kPrimInt:
2201 case Primitive::kPrimNot: {
2202 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2203 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002204 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002205 if (index.IsConstant()) {
2206 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2207 __ LoadFromOffset(kLoadWord, out, obj, offset);
2208 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002209 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002210 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2211 }
2212 break;
2213 }
2214
2215 case Primitive::kPrimLong: {
2216 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002217 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002218 if (index.IsConstant()) {
2219 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002220 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002221 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002222 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2223 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002224 }
2225 break;
2226 }
2227
2228 case Primitive::kPrimFloat:
2229 case Primitive::kPrimDouble:
2230 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002231 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002232 case Primitive::kPrimVoid:
2233 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002234 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002235 }
2236}
2237
2238void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002239 Primitive::Type value_type = instruction->GetComponentType();
2240 bool is_object = value_type == Primitive::kPrimNot;
2241 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2242 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
2243 if (is_object) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002244 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002245 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2246 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2247 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002248 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002249 locations->SetInAt(0, Location::RequiresRegister());
2250 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2251 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002252 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002253}
2254
2255void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
2256 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002257 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002258 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002259 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002260
2261 switch (value_type) {
2262 case Primitive::kPrimBoolean:
2263 case Primitive::kPrimByte: {
2264 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002265 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002266 if (index.IsConstant()) {
2267 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
2268 __ StoreToOffset(kStoreByte, value, obj, offset);
2269 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002270 __ add(IP, obj, ShifterOperand(index.As<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002271 __ StoreToOffset(kStoreByte, value, IP, data_offset);
2272 }
2273 break;
2274 }
2275
2276 case Primitive::kPrimShort:
2277 case Primitive::kPrimChar: {
2278 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002279 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002280 if (index.IsConstant()) {
2281 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
2282 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2283 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002284 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002285 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
2286 }
2287 break;
2288 }
2289
2290 case Primitive::kPrimInt: {
2291 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002292 Register value = locations->InAt(2).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002293 if (index.IsConstant()) {
2294 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2295 __ StoreToOffset(kStoreWord, value, obj, offset);
2296 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002297 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002298 __ StoreToOffset(kStoreWord, value, IP, data_offset);
2299 }
2300 break;
2301 }
2302
2303 case Primitive::kPrimNot: {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002304 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002305 break;
2306 }
2307
2308 case Primitive::kPrimLong: {
2309 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002310 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002311 if (index.IsConstant()) {
2312 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002313 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002314 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002315 __ add(IP, obj, ShifterOperand(index.As<Register>(), LSL, TIMES_8));
2316 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002317 }
2318 break;
2319 }
2320
2321 case Primitive::kPrimFloat:
2322 case Primitive::kPrimDouble:
2323 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002324 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002325 case Primitive::kPrimVoid:
2326 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002327 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002328 }
2329}
2330
2331void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002332 LocationSummary* locations =
2333 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002334 locations->SetInAt(0, Location::RequiresRegister());
2335 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002336}
2337
2338void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
2339 LocationSummary* locations = instruction->GetLocations();
2340 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002341 Register obj = locations->InAt(0).As<Register>();
2342 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002343 __ LoadFromOffset(kLoadWord, out, obj, offset);
2344}
2345
2346void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002347 LocationSummary* locations =
2348 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002349 locations->SetInAt(0, Location::RequiresRegister());
2350 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002351 if (instruction->HasUses()) {
2352 locations->SetOut(Location::SameAsFirstInput());
2353 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002354}
2355
2356void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
2357 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002358 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002359 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002360 codegen_->AddSlowPath(slow_path);
2361
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002362 Register index = locations->InAt(0).As<Register>();
2363 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002364
2365 __ cmp(index, ShifterOperand(length));
2366 __ b(slow_path->GetEntryLabel(), CS);
2367}
2368
2369void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
2370 Label is_null;
2371 __ CompareAndBranchIfZero(value, &is_null);
2372 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
2373 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
2374 __ strb(card, Address(card, temp));
2375 __ Bind(&is_null);
2376}
2377
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002378void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
2379 temp->SetLocations(nullptr);
2380}
2381
2382void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
2383 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002384 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002385}
2386
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002387void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002388 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002389 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002390}
2391
2392void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002393 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2394}
2395
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002396void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2397 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2398}
2399
2400void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002401 HBasicBlock* block = instruction->GetBlock();
2402 if (block->GetLoopInformation() != nullptr) {
2403 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2404 // The back edge will generate the suspend check.
2405 return;
2406 }
2407 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2408 // The goto will generate the suspend check.
2409 return;
2410 }
2411 GenerateSuspendCheck(instruction, nullptr);
2412}
2413
2414void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
2415 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002416 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002417 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002418 codegen_->AddSlowPath(slow_path);
2419
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002420 __ LoadFromOffset(
2421 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
2422 __ cmp(IP, ShifterOperand(0));
2423 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002424 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002425 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002426 __ Bind(slow_path->GetReturnLabel());
2427 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002428 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002429 __ b(slow_path->GetEntryLabel());
2430 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002431}
2432
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002433ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2434 return codegen_->GetAssembler();
2435}
2436
2437void ParallelMoveResolverARM::EmitMove(size_t index) {
2438 MoveOperands* move = moves_.Get(index);
2439 Location source = move->GetSource();
2440 Location destination = move->GetDestination();
2441
2442 if (source.IsRegister()) {
2443 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002444 __ Mov(destination.As<Register>(), source.As<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002445 } else {
2446 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002447 __ StoreToOffset(kStoreWord, source.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002448 SP, destination.GetStackIndex());
2449 }
2450 } else if (source.IsStackSlot()) {
2451 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002452 __ LoadFromOffset(kLoadWord, destination.As<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002453 SP, source.GetStackIndex());
2454 } else {
2455 DCHECK(destination.IsStackSlot());
2456 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2457 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2458 }
2459 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002460 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002461 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002462 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2463 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002464 __ LoadImmediate(destination.As<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002465 } else {
2466 DCHECK(destination.IsStackSlot());
2467 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002468 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002469 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002470 }
2471}
2472
2473void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2474 __ Mov(IP, reg);
2475 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2476 __ StoreToOffset(kStoreWord, IP, SP, mem);
2477}
2478
2479void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2480 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2481 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2482 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2483 SP, mem1 + stack_offset);
2484 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2485 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2486 SP, mem2 + stack_offset);
2487 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2488}
2489
2490void ParallelMoveResolverARM::EmitSwap(size_t index) {
2491 MoveOperands* move = moves_.Get(index);
2492 Location source = move->GetSource();
2493 Location destination = move->GetDestination();
2494
2495 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002496 DCHECK_NE(source.As<Register>(), IP);
2497 DCHECK_NE(destination.As<Register>(), IP);
2498 __ Mov(IP, source.As<Register>());
2499 __ Mov(source.As<Register>(), destination.As<Register>());
2500 __ Mov(destination.As<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002501 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002502 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002503 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002504 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002505 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2506 Exchange(source.GetStackIndex(), destination.GetStackIndex());
2507 } else {
2508 LOG(FATAL) << "Unimplemented";
2509 }
2510}
2511
2512void ParallelMoveResolverARM::SpillScratch(int reg) {
2513 __ Push(static_cast<Register>(reg));
2514}
2515
2516void ParallelMoveResolverARM::RestoreScratch(int reg) {
2517 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002518}
2519
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002520void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002521 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
2522 ? LocationSummary::kCallOnSlowPath
2523 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002524 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002525 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002526 locations->SetOut(Location::RequiresRegister());
2527}
2528
2529void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
2530 Register out = cls->GetLocations()->Out().As<Register>();
2531 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002532 DCHECK(!cls->CanCallRuntime());
2533 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002534 codegen_->LoadCurrentMethod(out);
2535 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
2536 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002537 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002538 codegen_->LoadCurrentMethod(out);
2539 __ LoadFromOffset(
2540 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
2541 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002542
2543 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2544 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2545 codegen_->AddSlowPath(slow_path);
2546 __ cmp(out, ShifterOperand(0));
2547 __ b(slow_path->GetEntryLabel(), EQ);
2548 if (cls->MustGenerateClinitCheck()) {
2549 GenerateClassInitializationCheck(slow_path, out);
2550 } else {
2551 __ Bind(slow_path->GetExitLabel());
2552 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002553 }
2554}
2555
2556void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
2557 LocationSummary* locations =
2558 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2559 locations->SetInAt(0, Location::RequiresRegister());
2560 if (check->HasUses()) {
2561 locations->SetOut(Location::SameAsFirstInput());
2562 }
2563}
2564
2565void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002566 // We assume the class is not null.
2567 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
2568 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002569 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002570 GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>());
2571}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002572
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002573void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
2574 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002575 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
2576 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
2577 __ b(slow_path->GetEntryLabel(), LT);
2578 // Even if the initialized flag is set, we may be in a situation where caches are not synced
2579 // properly. Therefore, we do a memory fence.
2580 __ dmb(ISH);
2581 __ Bind(slow_path->GetExitLabel());
2582}
2583
2584void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2585 LocationSummary* locations =
2586 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2587 locations->SetInAt(0, Location::RequiresRegister());
2588 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2589}
2590
2591void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2592 LocationSummary* locations = instruction->GetLocations();
2593 Register cls = locations->InAt(0).As<Register>();
2594 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2595
2596 switch (instruction->GetType()) {
2597 case Primitive::kPrimBoolean: {
2598 Register out = locations->Out().As<Register>();
2599 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
2600 break;
2601 }
2602
2603 case Primitive::kPrimByte: {
2604 Register out = locations->Out().As<Register>();
2605 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
2606 break;
2607 }
2608
2609 case Primitive::kPrimShort: {
2610 Register out = locations->Out().As<Register>();
2611 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
2612 break;
2613 }
2614
2615 case Primitive::kPrimChar: {
2616 Register out = locations->Out().As<Register>();
2617 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
2618 break;
2619 }
2620
2621 case Primitive::kPrimInt:
2622 case Primitive::kPrimNot: {
2623 Register out = locations->Out().As<Register>();
2624 __ LoadFromOffset(kLoadWord, out, cls, offset);
2625 break;
2626 }
2627
2628 case Primitive::kPrimLong: {
2629 // TODO: support volatile.
2630 Location out = locations->Out();
2631 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
2632 break;
2633 }
2634
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002635 case Primitive::kPrimFloat: {
2636 SRegister out = locations->Out().As<SRegister>();
2637 __ LoadSFromOffset(out, cls, offset);
2638 break;
2639 }
2640
2641 case Primitive::kPrimDouble: {
2642 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2643 __ LoadDFromOffset(out, cls, offset);
2644 break;
2645 }
2646
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002647 case Primitive::kPrimVoid:
2648 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2649 UNREACHABLE();
2650 }
2651}
2652
2653void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2654 LocationSummary* locations =
2655 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2656 bool is_object_type = instruction->GetFieldType() == Primitive::kPrimNot;
2657 locations->SetInAt(0, Location::RequiresRegister());
2658 locations->SetInAt(1, Location::RequiresRegister());
2659 // Temporary registers for the write barrier.
2660 if (is_object_type) {
2661 locations->AddTemp(Location::RequiresRegister());
2662 locations->AddTemp(Location::RequiresRegister());
2663 }
2664}
2665
2666void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2667 LocationSummary* locations = instruction->GetLocations();
2668 Register cls = locations->InAt(0).As<Register>();
2669 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2670 Primitive::Type field_type = instruction->GetFieldType();
2671
2672 switch (field_type) {
2673 case Primitive::kPrimBoolean:
2674 case Primitive::kPrimByte: {
2675 Register value = locations->InAt(1).As<Register>();
2676 __ StoreToOffset(kStoreByte, value, cls, offset);
2677 break;
2678 }
2679
2680 case Primitive::kPrimShort:
2681 case Primitive::kPrimChar: {
2682 Register value = locations->InAt(1).As<Register>();
2683 __ StoreToOffset(kStoreHalfword, value, cls, offset);
2684 break;
2685 }
2686
2687 case Primitive::kPrimInt:
2688 case Primitive::kPrimNot: {
2689 Register value = locations->InAt(1).As<Register>();
2690 __ StoreToOffset(kStoreWord, value, cls, offset);
2691 if (field_type == Primitive::kPrimNot) {
2692 Register temp = locations->GetTemp(0).As<Register>();
2693 Register card = locations->GetTemp(1).As<Register>();
2694 codegen_->MarkGCCard(temp, card, cls, value);
2695 }
2696 break;
2697 }
2698
2699 case Primitive::kPrimLong: {
2700 Location value = locations->InAt(1);
2701 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
2702 break;
2703 }
2704
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002705 case Primitive::kPrimFloat: {
2706 SRegister value = locations->InAt(1).As<SRegister>();
2707 __ StoreSToOffset(value, cls, offset);
2708 break;
2709 }
2710
2711 case Primitive::kPrimDouble: {
2712 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
2713 __ StoreDToOffset(value, cls, offset);
2714 break;
2715 }
2716
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002717 case Primitive::kPrimVoid:
2718 LOG(FATAL) << "Unreachable type " << field_type;
2719 UNREACHABLE();
2720 }
2721}
2722
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002723void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
2724 LocationSummary* locations =
2725 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2726 locations->SetOut(Location::RequiresRegister());
2727}
2728
2729void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
2730 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
2731 codegen_->AddSlowPath(slow_path);
2732
2733 Register out = load->GetLocations()->Out().As<Register>();
2734 codegen_->LoadCurrentMethod(out);
2735 __ LoadFromOffset(
2736 kLoadWord, out, out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value());
2737 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
2738 __ cmp(out, ShifterOperand(0));
2739 __ b(slow_path->GetEntryLabel(), EQ);
2740 __ Bind(slow_path->GetExitLabel());
2741}
2742
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002743void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
2744 LocationSummary* locations =
2745 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2746 locations->SetOut(Location::RequiresRegister());
2747}
2748
2749void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
2750 Register out = load->GetLocations()->Out().As<Register>();
2751 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
2752 __ LoadFromOffset(kLoadWord, out, TR, offset);
2753 __ LoadImmediate(IP, 0);
2754 __ StoreToOffset(kStoreWord, IP, TR, offset);
2755}
2756
2757void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
2758 LocationSummary* locations =
2759 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2760 InvokeRuntimeCallingConvention calling_convention;
2761 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2762}
2763
2764void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
2765 codegen_->InvokeRuntime(
2766 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
2767}
2768
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002769void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002770 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
2771 ? LocationSummary::kNoCall
2772 : LocationSummary::kCallOnSlowPath;
2773 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
2774 locations->SetInAt(0, Location::RequiresRegister());
2775 locations->SetInAt(1, Location::RequiresRegister());
2776 locations->SetOut(Location::RequiresRegister());
2777}
2778
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002779void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002780 LocationSummary* locations = instruction->GetLocations();
2781 Register obj = locations->InAt(0).As<Register>();
2782 Register cls = locations->InAt(1).As<Register>();
2783 Register out = locations->Out().As<Register>();
2784 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2785 Label done, zero;
2786 SlowPathCodeARM* slow_path = nullptr;
2787
2788 // Return 0 if `obj` is null.
2789 // TODO: avoid this check if we know obj is not null.
2790 __ cmp(obj, ShifterOperand(0));
2791 __ b(&zero, EQ);
2792 // Compare the class of `obj` with `cls`.
2793 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
2794 __ cmp(out, ShifterOperand(cls));
2795 if (instruction->IsClassFinal()) {
2796 // Classes must be equal for the instanceof to succeed.
2797 __ b(&zero, NE);
2798 __ LoadImmediate(out, 1);
2799 __ b(&done);
2800 } else {
2801 // If the classes are not equal, we go into a slow path.
2802 DCHECK(locations->OnlyCallsOnSlowPath());
2803 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002804 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002805 codegen_->AddSlowPath(slow_path);
2806 __ b(slow_path->GetEntryLabel(), NE);
2807 __ LoadImmediate(out, 1);
2808 __ b(&done);
2809 }
2810 __ Bind(&zero);
2811 __ LoadImmediate(out, 0);
2812 if (slow_path != nullptr) {
2813 __ Bind(slow_path->GetExitLabel());
2814 }
2815 __ Bind(&done);
2816}
2817
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002818void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
2819 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2820 instruction, LocationSummary::kCallOnSlowPath);
2821 locations->SetInAt(0, Location::RequiresRegister());
2822 locations->SetInAt(1, Location::RequiresRegister());
2823 locations->AddTemp(Location::RequiresRegister());
2824}
2825
2826void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
2827 LocationSummary* locations = instruction->GetLocations();
2828 Register obj = locations->InAt(0).As<Register>();
2829 Register cls = locations->InAt(1).As<Register>();
2830 Register temp = locations->GetTemp(0).As<Register>();
2831 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2832
2833 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
2834 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
2835 codegen_->AddSlowPath(slow_path);
2836
2837 // TODO: avoid this check if we know obj is not null.
2838 __ cmp(obj, ShifterOperand(0));
2839 __ b(slow_path->GetExitLabel(), EQ);
2840 // Compare the class of `obj` with `cls`.
2841 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
2842 __ cmp(temp, ShifterOperand(cls));
2843 __ b(slow_path->GetEntryLabel(), NE);
2844 __ Bind(slow_path->GetExitLabel());
2845}
2846
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00002847void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
2848 LocationSummary* locations =
2849 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2850 InvokeRuntimeCallingConvention calling_convention;
2851 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2852}
2853
2854void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
2855 codegen_->InvokeRuntime(instruction->IsEnter()
2856 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2857 instruction,
2858 instruction->GetDexPc());
2859}
2860
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002861void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
2862void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
2863void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
2864
2865void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
2866 LocationSummary* locations =
2867 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2868 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
2869 || instruction->GetResultType() == Primitive::kPrimLong);
2870 locations->SetInAt(0, Location::RequiresRegister());
2871 locations->SetInAt(1, Location::RequiresRegister());
2872 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
2873 locations->SetOut(Location::RequiresRegister(), output_overlaps);
2874}
2875
2876void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
2877 HandleBitwiseOperation(instruction);
2878}
2879
2880void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
2881 HandleBitwiseOperation(instruction);
2882}
2883
2884void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
2885 HandleBitwiseOperation(instruction);
2886}
2887
2888void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
2889 LocationSummary* locations = instruction->GetLocations();
2890
2891 if (instruction->GetResultType() == Primitive::kPrimInt) {
2892 Register first = locations->InAt(0).As<Register>();
2893 Register second = locations->InAt(1).As<Register>();
2894 Register out = locations->Out().As<Register>();
2895 if (instruction->IsAnd()) {
2896 __ and_(out, first, ShifterOperand(second));
2897 } else if (instruction->IsOr()) {
2898 __ orr(out, first, ShifterOperand(second));
2899 } else {
2900 DCHECK(instruction->IsXor());
2901 __ eor(out, first, ShifterOperand(second));
2902 }
2903 } else {
2904 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
2905 Location first = locations->InAt(0);
2906 Location second = locations->InAt(1);
2907 Location out = locations->Out();
2908 if (instruction->IsAnd()) {
2909 __ and_(out.AsRegisterPairLow<Register>(),
2910 first.AsRegisterPairLow<Register>(),
2911 ShifterOperand(second.AsRegisterPairLow<Register>()));
2912 __ and_(out.AsRegisterPairHigh<Register>(),
2913 first.AsRegisterPairHigh<Register>(),
2914 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2915 } else if (instruction->IsOr()) {
2916 __ orr(out.AsRegisterPairLow<Register>(),
2917 first.AsRegisterPairLow<Register>(),
2918 ShifterOperand(second.AsRegisterPairLow<Register>()));
2919 __ orr(out.AsRegisterPairHigh<Register>(),
2920 first.AsRegisterPairHigh<Register>(),
2921 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2922 } else {
2923 DCHECK(instruction->IsXor());
2924 __ eor(out.AsRegisterPairLow<Register>(),
2925 first.AsRegisterPairLow<Register>(),
2926 ShifterOperand(second.AsRegisterPairLow<Register>()));
2927 __ eor(out.AsRegisterPairHigh<Register>(),
2928 first.AsRegisterPairHigh<Register>(),
2929 ShifterOperand(second.AsRegisterPairHigh<Register>()));
2930 }
2931 }
2932}
2933
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002934} // namespace arm
2935} // namespace art