blob: 0967a01de633652d8dcbf4143d1db7d548073498 [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
Alexandre Rames67555f72014-11-18 10:55:16 +000083 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
Alexandre Rames67555f72014-11-18 10:55:16 +000099 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +0000100 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
Alexandre Rames67555f72014-11-18 10:55:16 +0000115 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100116 __ 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:
Alexandre Rames67555f72014-11-18 10:55:16 +0000127 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100128 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000129
Alexandre Rames67555f72014-11-18 10:55:16 +0000130 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
Alexandre Rames67555f72014-11-18 10:55:16 +0000169 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100170 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100171 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000172 // We're moving two locations to locations that could overlap, so we need a parallel
173 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100174 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000175 codegen->EmitParallelMoves(
176 index_location_,
177 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
178 length_location_,
179 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100180 arm_codegen->InvokeRuntime(
181 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100182 }
183
184 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100185 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100186 const Location index_location_;
187 const Location length_location_;
188
189 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
190};
191
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000192class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100193 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000194 LoadClassSlowPathARM(HLoadClass* cls,
195 HInstruction* at,
196 uint32_t dex_pc,
197 bool do_clinit)
198 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
199 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
200 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100201
Alexandre Rames67555f72014-11-18 10:55:16 +0000202 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000203 LocationSummary* locations = at_->GetLocations();
204
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100205 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
206 __ Bind(GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000207 codegen->SaveLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100208
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100209 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000210 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100211 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000212 int32_t entry_point_offset = do_clinit_
213 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
214 : QUICK_ENTRY_POINT(pInitializeType);
215 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_);
216
217 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000218 Location out = locations->Out();
219 if (out.IsValid()) {
220 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000221 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
222 }
223 codegen->RestoreLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100224 __ b(GetExitLabel());
225 }
226
227 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000228 // The class this slow path will load.
229 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100230
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000231 // The instruction where this slow path is happening.
232 // (Might be the load class or an initialization check).
233 HInstruction* const at_;
234
235 // The dex PC of `at_`.
236 const uint32_t dex_pc_;
237
238 // Whether to initialize the class.
239 const bool do_clinit_;
240
241 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100242};
243
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000244class LoadStringSlowPathARM : public SlowPathCodeARM {
245 public:
246 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
247
Alexandre Rames67555f72014-11-18 10:55:16 +0000248 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000249 LocationSummary* locations = instruction_->GetLocations();
250 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
251
252 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
253 __ Bind(GetEntryLabel());
254 codegen->SaveLiveRegisters(locations);
255
256 InvokeRuntimeCallingConvention calling_convention;
257 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0));
258 __ LoadImmediate(calling_convention.GetRegisterAt(1), instruction_->GetStringIndex());
259 arm_codegen->InvokeRuntime(
260 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
261 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
262
263 codegen->RestoreLiveRegisters(locations);
264 __ b(GetExitLabel());
265 }
266
267 private:
268 HLoadString* const instruction_;
269
270 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
271};
272
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000273class TypeCheckSlowPathARM : public SlowPathCodeARM {
274 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000275 TypeCheckSlowPathARM(HInstruction* instruction,
276 Location class_to_check,
277 Location object_class,
278 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000279 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000280 class_to_check_(class_to_check),
281 object_class_(object_class),
282 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000283
Alexandre Rames67555f72014-11-18 10:55:16 +0000284 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000285 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000286 DCHECK(instruction_->IsCheckCast()
287 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000288
289 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
290 __ Bind(GetEntryLabel());
291 codegen->SaveLiveRegisters(locations);
292
293 // We're moving two locations to locations that could overlap, so we need a parallel
294 // move resolver.
295 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000296 codegen->EmitParallelMoves(
297 class_to_check_,
298 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
299 object_class_,
300 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000301
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000302 if (instruction_->IsInstanceOf()) {
303 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_);
304 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
305 } else {
306 DCHECK(instruction_->IsCheckCast());
307 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_);
308 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000309
310 codegen->RestoreLiveRegisters(locations);
311 __ b(GetExitLabel());
312 }
313
314 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000315 HInstruction* const instruction_;
316 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000317 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000318 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000319
320 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
321};
322
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000323#undef __
324
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100325#undef __
326#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700327
328inline Condition ARMCondition(IfCondition cond) {
329 switch (cond) {
330 case kCondEQ: return EQ;
331 case kCondNE: return NE;
332 case kCondLT: return LT;
333 case kCondLE: return LE;
334 case kCondGT: return GT;
335 case kCondGE: return GE;
336 default:
337 LOG(FATAL) << "Unknown if condition";
338 }
339 return EQ; // Unreachable.
340}
341
342inline Condition ARMOppositeCondition(IfCondition cond) {
343 switch (cond) {
344 case kCondEQ: return NE;
345 case kCondNE: return EQ;
346 case kCondLT: return GE;
347 case kCondLE: return GT;
348 case kCondGT: return LE;
349 case kCondGE: return LT;
350 default:
351 LOG(FATAL) << "Unknown if condition";
352 }
353 return EQ; // Unreachable.
354}
355
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100356void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
357 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
358}
359
360void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000361 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100362}
363
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100364size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
365 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
366 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100367}
368
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100369size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
370 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
371 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100372}
373
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100374CodeGeneratorARM::CodeGeneratorARM(HGraph* graph)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000375 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100376 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100377 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100378 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100379 move_resolver_(graph->GetArena(), this),
380 assembler_(true) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100381
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100382size_t CodeGeneratorARM::FrameEntrySpillSize() const {
383 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
384}
385
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100386Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100387 switch (type) {
388 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100389 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100390 ArmManagedRegister pair =
391 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100392 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
393 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
394
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100395 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
396 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100397 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100398 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100399 }
400
401 case Primitive::kPrimByte:
402 case Primitive::kPrimBoolean:
403 case Primitive::kPrimChar:
404 case Primitive::kPrimShort:
405 case Primitive::kPrimInt:
406 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100407 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100408 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100409 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
410 ArmManagedRegister current =
411 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
412 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100413 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100414 }
415 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100416 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100417 }
418
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000419 case Primitive::kPrimFloat: {
420 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100421 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100422 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100423
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000424 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000425 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
426 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000427 return Location::FpuRegisterPairLocation(reg, reg + 1);
428 }
429
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100430 case Primitive::kPrimVoid:
431 LOG(FATAL) << "Unreachable type " << type;
432 }
433
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100434 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100435}
436
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100437void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100438 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100439 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100440
441 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100442 blocked_core_registers_[SP] = true;
443 blocked_core_registers_[LR] = true;
444 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100445
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100446 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100447 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100448
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100449 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100450 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100451
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100452 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100453 // We always save and restore R6 and R7 to make sure we can use three
454 // register pairs for long operations.
Nicolas Geoffray44b819e2014-11-06 12:00:54 +0000455 blocked_core_registers_[R4] = true;
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100456 blocked_core_registers_[R5] = true;
457 blocked_core_registers_[R8] = true;
458 blocked_core_registers_[R10] = true;
459 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100460
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000461 blocked_fpu_registers_[S16] = true;
462 blocked_fpu_registers_[S17] = true;
463 blocked_fpu_registers_[S18] = true;
464 blocked_fpu_registers_[S19] = true;
465 blocked_fpu_registers_[S20] = true;
466 blocked_fpu_registers_[S21] = true;
467 blocked_fpu_registers_[S22] = true;
468 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000469 blocked_fpu_registers_[S24] = true;
470 blocked_fpu_registers_[S25] = true;
471 blocked_fpu_registers_[S26] = true;
472 blocked_fpu_registers_[S27] = true;
473 blocked_fpu_registers_[S28] = true;
474 blocked_fpu_registers_[S29] = true;
475 blocked_fpu_registers_[S30] = true;
476 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100477
478 UpdateBlockedPairRegisters();
479}
480
481void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
482 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
483 ArmManagedRegister current =
484 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
485 if (blocked_core_registers_[current.AsRegisterPairLow()]
486 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
487 blocked_register_pairs_[i] = true;
488 }
489 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100490}
491
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100492InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
493 : HGraphVisitor(graph),
494 assembler_(codegen->GetAssembler()),
495 codegen_(codegen) {}
496
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000497void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000498 bool skip_overflow_check =
499 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100500 if (!skip_overflow_check) {
501 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100502 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100503 AddSlowPath(slow_path);
504
505 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
506 __ cmp(SP, ShifterOperand(IP));
507 __ b(slow_path->GetEntryLabel(), CC);
508 } else {
509 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100510 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100511 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100512 }
513 }
514
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100515 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
516 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000517
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100518 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100519 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100520 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000521}
522
523void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100524 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100525 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000526}
527
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100528void CodeGeneratorARM::Bind(HBasicBlock* block) {
529 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000530}
531
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100532Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
533 switch (load->GetType()) {
534 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100535 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100536 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
537 break;
538
539 case Primitive::kPrimInt:
540 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100541 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100542 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100543
544 case Primitive::kPrimBoolean:
545 case Primitive::kPrimByte:
546 case Primitive::kPrimChar:
547 case Primitive::kPrimShort:
548 case Primitive::kPrimVoid:
549 LOG(FATAL) << "Unexpected type " << load->GetType();
550 }
551
552 LOG(FATAL) << "Unreachable";
553 return Location();
554}
555
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100556Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
557 switch (type) {
558 case Primitive::kPrimBoolean:
559 case Primitive::kPrimByte:
560 case Primitive::kPrimChar:
561 case Primitive::kPrimShort:
562 case Primitive::kPrimInt:
563 case Primitive::kPrimNot: {
564 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000565 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100566 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100567 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100568 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000569 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100570 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100571 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100572
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000573 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100574 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000575 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100576 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000577 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100578 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100579 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
580 calling_convention.GetRegisterPairAt(index));
581 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100582 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000583 return Location::QuickParameter(index, stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100584 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000585 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
586 }
587 }
588
589 case Primitive::kPrimFloat: {
590 uint32_t stack_index = stack_index_++;
591 if (float_index_ % 2 == 0) {
592 float_index_ = std::max(double_index_, float_index_);
593 }
594 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
595 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
596 } else {
597 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
598 }
599 }
600
601 case Primitive::kPrimDouble: {
602 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
603 uint32_t stack_index = stack_index_;
604 stack_index_ += 2;
605 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
606 uint32_t index = double_index_;
607 double_index_ += 2;
608 return Location::FpuRegisterPairLocation(
609 calling_convention.GetFpuRegisterAt(index),
610 calling_convention.GetFpuRegisterAt(index + 1));
611 } else {
612 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100613 }
614 }
615
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100616 case Primitive::kPrimVoid:
617 LOG(FATAL) << "Unexpected parameter type " << type;
618 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100619 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100620 return Location();
621}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100622
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000623Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
624 switch (type) {
625 case Primitive::kPrimBoolean:
626 case Primitive::kPrimByte:
627 case Primitive::kPrimChar:
628 case Primitive::kPrimShort:
629 case Primitive::kPrimInt:
630 case Primitive::kPrimNot: {
631 return Location::RegisterLocation(R0);
632 }
633
634 case Primitive::kPrimFloat: {
635 return Location::FpuRegisterLocation(S0);
636 }
637
638 case Primitive::kPrimLong: {
639 return Location::RegisterPairLocation(R0, R1);
640 }
641
642 case Primitive::kPrimDouble: {
643 return Location::FpuRegisterPairLocation(S0, S1);
644 }
645
646 case Primitive::kPrimVoid:
647 return Location();
648 }
649 UNREACHABLE();
650 return Location();
651}
652
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100653void CodeGeneratorARM::Move32(Location destination, Location source) {
654 if (source.Equals(destination)) {
655 return;
656 }
657 if (destination.IsRegister()) {
658 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000659 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100660 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000661 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100662 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000663 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100664 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100665 } else if (destination.IsFpuRegister()) {
666 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000667 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100668 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000669 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100670 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000671 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100672 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100673 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000674 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100675 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000676 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100677 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000678 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100679 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000680 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100681 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
682 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100683 }
684 }
685}
686
687void CodeGeneratorARM::Move64(Location destination, Location source) {
688 if (source.Equals(destination)) {
689 return;
690 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100691 if (destination.IsRegisterPair()) {
692 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000693 EmitParallelMoves(
694 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
695 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
696 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
697 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100698 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000699 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100700 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000701 uint16_t register_index = source.GetQuickParameterRegisterIndex();
702 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100703 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000704 EmitParallelMoves(
705 Location::RegisterLocation(calling_convention.GetRegisterAt(register_index)),
706 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
707 Location::StackSlot(
708 calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize()),
709 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100710 } else {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000711 // No conflict possible, so just do the moves.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100712 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100713 if (destination.AsRegisterPairLow<Register>() == R1) {
714 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100715 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
716 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100717 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100718 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100719 SP, source.GetStackIndex());
720 }
721 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000722 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100723 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000724 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
725 SP,
726 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100727 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000728 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100729 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100730 } else if (destination.IsQuickParameter()) {
731 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000732 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
733 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100734 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000735 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100736 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000737 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100738 } else {
739 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000740 EmitParallelMoves(
741 Location::StackSlot(source.GetStackIndex()),
742 Location::RegisterLocation(calling_convention.GetRegisterAt(register_index)),
743 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
744 Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index + 1)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100745 }
746 } else {
747 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100748 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000749 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100750 if (source.AsRegisterPairLow<Register>() == R1) {
751 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100752 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
753 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100754 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100755 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100756 SP, destination.GetStackIndex());
757 }
758 } else if (source.IsQuickParameter()) {
759 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000760 uint16_t register_index = source.GetQuickParameterRegisterIndex();
761 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000762 // Just move the low part. The only time a source is a quick parameter is
763 // when moving the parameter to its stack locations. And the (Java) caller
764 // of this method has already done that.
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000765 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000766 SP, destination.GetStackIndex());
767 DCHECK_EQ(calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize(),
768 static_cast<size_t>(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000769 } else if (source.IsFpuRegisterPair()) {
770 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
771 SP,
772 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100773 } else {
774 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000775 EmitParallelMoves(
776 Location::StackSlot(source.GetStackIndex()),
777 Location::StackSlot(destination.GetStackIndex()),
778 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
779 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100780 }
781 }
782}
783
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100784void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100785 LocationSummary* locations = instruction->GetLocations();
786 if (locations != nullptr && locations->Out().Equals(location)) {
787 return;
788 }
789
Calin Juravlea21f5982014-11-13 15:53:04 +0000790 if (locations != nullptr && locations->Out().IsConstant()) {
791 HConstant* const_to_move = locations->Out().GetConstant();
792 if (const_to_move->IsIntConstant()) {
793 int32_t value = const_to_move->AsIntConstant()->GetValue();
794 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000795 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000796 } else {
797 DCHECK(location.IsStackSlot());
798 __ LoadImmediate(IP, value);
799 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
800 }
801 } else if (const_to_move->IsLongConstant()) {
802 int64_t value = const_to_move->AsLongConstant()->GetValue();
803 if (location.IsRegisterPair()) {
804 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
805 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
806 } else {
807 DCHECK(location.IsDoubleStackSlot());
808 __ LoadImmediate(IP, Low32Bits(value));
809 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
810 __ LoadImmediate(IP, High32Bits(value));
811 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
812 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100813 }
Roland Levillain476df552014-10-09 17:51:36 +0100814 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100815 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
816 switch (instruction->GetType()) {
817 case Primitive::kPrimBoolean:
818 case Primitive::kPrimByte:
819 case Primitive::kPrimChar:
820 case Primitive::kPrimShort:
821 case Primitive::kPrimInt:
822 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100823 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100824 Move32(location, Location::StackSlot(stack_slot));
825 break;
826
827 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100828 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100829 Move64(location, Location::DoubleStackSlot(stack_slot));
830 break;
831
832 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100833 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100834 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000835 } else if (instruction->IsTemporary()) {
836 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000837 if (temp_location.IsStackSlot()) {
838 Move32(location, temp_location);
839 } else {
840 DCHECK(temp_location.IsDoubleStackSlot());
841 Move64(location, temp_location);
842 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000843 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100844 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100845 switch (instruction->GetType()) {
846 case Primitive::kPrimBoolean:
847 case Primitive::kPrimByte:
848 case Primitive::kPrimChar:
849 case Primitive::kPrimShort:
850 case Primitive::kPrimNot:
851 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100852 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100853 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100854 break;
855
856 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100857 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100858 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100859 break;
860
861 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100862 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100863 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000864 }
865}
866
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100867void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
868 HInstruction* instruction,
869 uint32_t dex_pc) {
870 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
871 __ blx(LR);
872 RecordPcInfo(instruction, dex_pc);
873 DCHECK(instruction->IsSuspendCheck()
874 || instruction->IsBoundsCheck()
875 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000876 || instruction->IsDivZeroCheck()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100877 || !IsLeafMethod());
878}
879
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000880void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000881 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000882}
883
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000884void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000885 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100886 DCHECK(!successor->IsExitBlock());
887
888 HBasicBlock* block = got->GetBlock();
889 HInstruction* previous = got->GetPrevious();
890
891 HLoopInformation* info = block->GetLoopInformation();
892 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
893 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
894 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
895 return;
896 }
897
898 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
899 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
900 }
901 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000902 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000903 }
904}
905
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000906void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000907 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000908}
909
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000910void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700911 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000912 if (kIsDebugBuild) {
913 __ Comment("Unreachable");
914 __ bkpt(0);
915 }
916}
917
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000918void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100919 LocationSummary* locations =
920 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100921 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100922 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100923 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100924 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000925}
926
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000927void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700928 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100929 if (cond->IsIntConstant()) {
930 // Constant condition, statically compared against 1.
931 int32_t cond_value = cond->AsIntConstant()->GetValue();
932 if (cond_value == 1) {
933 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
934 if_instr->IfTrueSuccessor())) {
935 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100936 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100937 return;
938 } else {
939 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100940 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100941 } else {
942 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
943 // Condition has been materialized, compare the output to 0
944 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000945 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100946 ShifterOperand(0));
947 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
948 } else {
949 // Condition has not been materialized, use its inputs as the
950 // comparison and its condition as the branch condition.
951 LocationSummary* locations = cond->GetLocations();
952 if (locations->InAt(1).IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000953 __ cmp(locations->InAt(0).AsRegister<Register>(),
954 ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100955 } else {
956 DCHECK(locations->InAt(1).IsConstant());
957 int32_t value =
958 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
959 ShifterOperand operand;
960 if (ShifterOperand::CanHoldArm(value, &operand)) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000961 __ cmp(locations->InAt(0).AsRegister<Register>(), ShifterOperand(value));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100962 } else {
963 Register temp = IP;
964 __ LoadImmediate(temp, value);
Roland Levillain271ab9c2014-11-27 15:23:57 +0000965 __ cmp(locations->InAt(0).AsRegister<Register>(), ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100966 }
967 }
968 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
969 ARMCondition(cond->AsCondition()->GetCondition()));
970 }
Dave Allison20dfc792014-06-16 20:44:29 -0700971 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100972 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
973 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700974 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000975 }
976}
977
Dave Allison20dfc792014-06-16 20:44:29 -0700978
979void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100980 LocationSummary* locations =
981 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100982 locations->SetInAt(0, Location::RequiresRegister());
983 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100984 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100985 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100986 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000987}
988
Dave Allison20dfc792014-06-16 20:44:29 -0700989void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100990 if (!comp->NeedsMaterialization()) return;
991
992 LocationSummary* locations = comp->GetLocations();
993 if (locations->InAt(1).IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000994 __ cmp(locations->InAt(0).AsRegister<Register>(),
995 ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100996 } else {
997 DCHECK(locations->InAt(1).IsConstant());
998 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
999 ShifterOperand operand;
1000 if (ShifterOperand::CanHoldArm(value, &operand)) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001001 __ cmp(locations->InAt(0).AsRegister<Register>(), ShifterOperand(value));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001002 } else {
1003 Register temp = IP;
1004 __ LoadImmediate(temp, value);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001005 __ cmp(locations->InAt(0).AsRegister<Register>(), ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001006 }
Dave Allison20dfc792014-06-16 20:44:29 -07001007 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001008 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001009 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001010 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001011 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001012 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001013}
1014
1015void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1016 VisitCondition(comp);
1017}
1018
1019void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1020 VisitCondition(comp);
1021}
1022
1023void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1024 VisitCondition(comp);
1025}
1026
1027void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1028 VisitCondition(comp);
1029}
1030
1031void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1032 VisitCondition(comp);
1033}
1034
1035void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1036 VisitCondition(comp);
1037}
1038
1039void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1040 VisitCondition(comp);
1041}
1042
1043void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1044 VisitCondition(comp);
1045}
1046
1047void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1048 VisitCondition(comp);
1049}
1050
1051void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1052 VisitCondition(comp);
1053}
1054
1055void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1056 VisitCondition(comp);
1057}
1058
1059void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1060 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001061}
1062
1063void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001064 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001065}
1066
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001067void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1068 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001069}
1070
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001071void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001072 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001073}
1074
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001075void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001076 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001077 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001078}
1079
1080void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001081 LocationSummary* locations =
1082 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001083 switch (store->InputAt(1)->GetType()) {
1084 case Primitive::kPrimBoolean:
1085 case Primitive::kPrimByte:
1086 case Primitive::kPrimChar:
1087 case Primitive::kPrimShort:
1088 case Primitive::kPrimInt:
1089 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001090 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001091 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1092 break;
1093
1094 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001095 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001096 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1097 break;
1098
1099 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001100 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001101 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001102}
1103
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001104void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001105 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001106}
1107
1108void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001109 LocationSummary* locations =
1110 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001111 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001112}
1113
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001114void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001115 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001116 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001117}
1118
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001119void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001120 LocationSummary* locations =
1121 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001122 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001123}
1124
1125void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1126 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001127 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001128}
1129
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001130void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1131 LocationSummary* locations =
1132 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1133 locations->SetOut(Location::ConstantLocation(constant));
1134}
1135
1136void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1137 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001138 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001139}
1140
1141void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1142 LocationSummary* locations =
1143 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1144 locations->SetOut(Location::ConstantLocation(constant));
1145}
1146
1147void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1148 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001149 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001150}
1151
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001152void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001153 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001154}
1155
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001156void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001157 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001158 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001159}
1160
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001161void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001162 LocationSummary* locations =
1163 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001164 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001165}
1166
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001167void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001168 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001169 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001170}
1171
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001172void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001173 HandleInvoke(invoke);
1174}
1175
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001176void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001177 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001178}
1179
1180void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001181 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001182
1183 // TODO: Implement all kinds of calls:
1184 // 1) boot -> boot
1185 // 2) app -> boot
1186 // 3) app -> app
1187 //
1188 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1189
1190 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001191 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001192 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001193 __ LoadFromOffset(
1194 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001195 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001196 __ LoadFromOffset(
1197 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001198 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001199 __ LoadFromOffset(kLoadWord, LR, temp,
Mathieu Chartier2d721012014-11-10 11:08:06 -08001200 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001201 kArmWordSize).Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001202 // LR()
1203 __ blx(LR);
1204
1205 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1206 DCHECK(!codegen_->IsLeafMethod());
1207}
1208
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001209void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001210 LocationSummary* locations =
1211 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001212 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001213
1214 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001215 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001216 HInstruction* input = invoke->InputAt(i);
1217 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1218 }
1219
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001220 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001221}
1222
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001223void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1224 HandleInvoke(invoke);
1225}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001226
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001227void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001228 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001229 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1230 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1231 LocationSummary* locations = invoke->GetLocations();
1232 Location receiver = locations->InAt(0);
1233 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1234 // temp = object->GetClass();
1235 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001236 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1237 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001238 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001239 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001240 }
1241 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001242 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001243 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001244 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001245 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001246 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001247 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001248 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001249 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001250 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001251}
1252
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001253void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1254 HandleInvoke(invoke);
1255 // Add the hidden argument.
1256 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1257}
1258
1259void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1260 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001261 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001262 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1263 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1264 LocationSummary* locations = invoke->GetLocations();
1265 Location receiver = locations->InAt(0);
1266 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1267
1268 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001269 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1270 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001271
1272 // temp = object->GetClass();
1273 if (receiver.IsStackSlot()) {
1274 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1275 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1276 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001277 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001278 }
1279 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001280 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001281 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001282 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1283 // LR = temp->GetEntryPoint();
1284 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1285 // LR();
1286 __ blx(LR);
1287 DCHECK(!codegen_->IsLeafMethod());
1288 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1289}
1290
Roland Levillain88cb1752014-10-20 16:36:47 +01001291void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1292 LocationSummary* locations =
1293 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1294 switch (neg->GetResultType()) {
1295 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001296 case Primitive::kPrimLong: {
1297 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001298 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001299 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001300 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001301 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001302
Roland Levillain88cb1752014-10-20 16:36:47 +01001303 case Primitive::kPrimFloat:
1304 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001305 locations->SetInAt(0, Location::RequiresFpuRegister());
1306 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001307 break;
1308
1309 default:
1310 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1311 }
1312}
1313
1314void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1315 LocationSummary* locations = neg->GetLocations();
1316 Location out = locations->Out();
1317 Location in = locations->InAt(0);
1318 switch (neg->GetResultType()) {
1319 case Primitive::kPrimInt:
1320 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001321 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001322 break;
1323
1324 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001325 DCHECK(in.IsRegisterPair());
1326 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1327 __ rsbs(out.AsRegisterPairLow<Register>(),
1328 in.AsRegisterPairLow<Register>(),
1329 ShifterOperand(0));
1330 // We cannot emit an RSC (Reverse Subtract with Carry)
1331 // instruction here, as it does not exist in the Thumb-2
1332 // instruction set. We use the following approach
1333 // using SBC and SUB instead.
1334 //
1335 // out.hi = -C
1336 __ sbc(out.AsRegisterPairHigh<Register>(),
1337 out.AsRegisterPairHigh<Register>(),
1338 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1339 // out.hi = out.hi - in.hi
1340 __ sub(out.AsRegisterPairHigh<Register>(),
1341 out.AsRegisterPairHigh<Register>(),
1342 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1343 break;
1344
Roland Levillain88cb1752014-10-20 16:36:47 +01001345 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001346 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001347 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001348 break;
1349
Roland Levillain88cb1752014-10-20 16:36:47 +01001350 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001351 DCHECK(in.IsFpuRegisterPair());
1352 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1353 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001354 break;
1355
1356 default:
1357 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1358 }
1359}
1360
Roland Levillaindff1f282014-11-05 14:15:05 +00001361void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
1362 LocationSummary* locations =
1363 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
1364 Primitive::Type result_type = conversion->GetResultType();
1365 Primitive::Type input_type = conversion->GetInputType();
1366 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001367 case Primitive::kPrimByte:
1368 switch (input_type) {
1369 case Primitive::kPrimShort:
1370 case Primitive::kPrimInt:
1371 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001372 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001373 locations->SetInAt(0, Location::RequiresRegister());
1374 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1375 break;
1376
1377 default:
1378 LOG(FATAL) << "Unexpected type conversion from " << input_type
1379 << " to " << result_type;
1380 }
1381 break;
1382
Roland Levillain01a8d712014-11-14 16:27:39 +00001383 case Primitive::kPrimShort:
1384 switch (input_type) {
1385 case Primitive::kPrimByte:
1386 case Primitive::kPrimInt:
1387 case Primitive::kPrimChar:
1388 // Processing a Dex `int-to-short' instruction.
1389 locations->SetInAt(0, Location::RequiresRegister());
1390 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1391 break;
1392
1393 default:
1394 LOG(FATAL) << "Unexpected type conversion from " << input_type
1395 << " to " << result_type;
1396 }
1397 break;
1398
Roland Levillain946e1432014-11-11 17:35:19 +00001399 case Primitive::kPrimInt:
1400 switch (input_type) {
1401 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001402 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001403 locations->SetInAt(0, Location::Any());
1404 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1405 break;
1406
1407 case Primitive::kPrimFloat:
1408 case Primitive::kPrimDouble:
1409 LOG(FATAL) << "Type conversion from " << input_type
1410 << " to " << result_type << " not yet implemented";
1411 break;
1412
1413 default:
1414 LOG(FATAL) << "Unexpected type conversion from " << input_type
1415 << " to " << result_type;
1416 }
1417 break;
1418
Roland Levillaindff1f282014-11-05 14:15:05 +00001419 case Primitive::kPrimLong:
1420 switch (input_type) {
1421 case Primitive::kPrimByte:
1422 case Primitive::kPrimShort:
1423 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001424 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001425 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001426 locations->SetInAt(0, Location::RequiresRegister());
1427 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1428 break;
1429
1430 case Primitive::kPrimFloat:
1431 case Primitive::kPrimDouble:
1432 LOG(FATAL) << "Type conversion from " << input_type << " to "
1433 << result_type << " not yet implemented";
1434 break;
1435
1436 default:
1437 LOG(FATAL) << "Unexpected type conversion from " << input_type
1438 << " to " << result_type;
1439 }
1440 break;
1441
Roland Levillain981e4542014-11-14 11:47:14 +00001442 case Primitive::kPrimChar:
1443 switch (input_type) {
1444 case Primitive::kPrimByte:
1445 case Primitive::kPrimShort:
1446 case Primitive::kPrimInt:
1447 case Primitive::kPrimChar:
1448 // Processing a Dex `int-to-char' instruction.
1449 locations->SetInAt(0, Location::RequiresRegister());
1450 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1451 break;
1452
1453 default:
1454 LOG(FATAL) << "Unexpected type conversion from " << input_type
1455 << " to " << result_type;
1456 }
1457 break;
1458
Roland Levillaindff1f282014-11-05 14:15:05 +00001459 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001460 switch (input_type) {
1461 case Primitive::kPrimByte:
1462 case Primitive::kPrimShort:
1463 case Primitive::kPrimInt:
1464 case Primitive::kPrimChar:
1465 // Processing a Dex `int-to-float' instruction.
1466 locations->SetInAt(0, Location::RequiresRegister());
1467 locations->SetOut(Location::RequiresFpuRegister());
1468 break;
1469
1470 case Primitive::kPrimLong:
1471 case Primitive::kPrimDouble:
1472 LOG(FATAL) << "Type conversion from " << input_type
1473 << " to " << result_type << " not yet implemented";
1474 break;
1475
1476 default:
1477 LOG(FATAL) << "Unexpected type conversion from " << input_type
1478 << " to " << result_type;
1479 };
1480 break;
1481
Roland Levillaindff1f282014-11-05 14:15:05 +00001482 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001483 switch (input_type) {
1484 case Primitive::kPrimByte:
1485 case Primitive::kPrimShort:
1486 case Primitive::kPrimInt:
1487 case Primitive::kPrimChar:
1488 // Processing a Dex `int-to-double' instruction.
1489 locations->SetInAt(0, Location::RequiresRegister());
1490 locations->SetOut(Location::RequiresFpuRegister());
1491 break;
1492
1493 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001494 // Processing a Dex `long-to-double' instruction.
1495 locations->SetInAt(0, Location::RequiresRegister());
1496 locations->SetOut(Location::RequiresFpuRegister());
1497 locations->AddTemp(Location::RequiresRegister());
1498 locations->AddTemp(Location::RequiresRegister());
1499 locations->AddTemp(Location::RequiresFpuRegister());
1500 break;
1501
Roland Levillaincff13742014-11-17 14:32:17 +00001502 case Primitive::kPrimFloat:
1503 LOG(FATAL) << "Type conversion from " << input_type
1504 << " to " << result_type << " not yet implemented";
1505 break;
1506
1507 default:
1508 LOG(FATAL) << "Unexpected type conversion from " << input_type
1509 << " to " << result_type;
1510 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001511 break;
1512
1513 default:
1514 LOG(FATAL) << "Unexpected type conversion from " << input_type
1515 << " to " << result_type;
1516 }
1517}
1518
1519void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1520 LocationSummary* locations = conversion->GetLocations();
1521 Location out = locations->Out();
1522 Location in = locations->InAt(0);
1523 Primitive::Type result_type = conversion->GetResultType();
1524 Primitive::Type input_type = conversion->GetInputType();
1525 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001526 case Primitive::kPrimByte:
1527 switch (input_type) {
1528 case Primitive::kPrimShort:
1529 case Primitive::kPrimInt:
1530 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001531 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001532 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001533 break;
1534
1535 default:
1536 LOG(FATAL) << "Unexpected type conversion from " << input_type
1537 << " to " << result_type;
1538 }
1539 break;
1540
Roland Levillain01a8d712014-11-14 16:27:39 +00001541 case Primitive::kPrimShort:
1542 switch (input_type) {
1543 case Primitive::kPrimByte:
1544 case Primitive::kPrimInt:
1545 case Primitive::kPrimChar:
1546 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001547 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001548 break;
1549
1550 default:
1551 LOG(FATAL) << "Unexpected type conversion from " << input_type
1552 << " to " << result_type;
1553 }
1554 break;
1555
Roland Levillain946e1432014-11-11 17:35:19 +00001556 case Primitive::kPrimInt:
1557 switch (input_type) {
1558 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001559 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001560 DCHECK(out.IsRegister());
1561 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001562 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001563 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001564 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001565 } else {
1566 DCHECK(in.IsConstant());
1567 DCHECK(in.GetConstant()->IsLongConstant());
1568 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001569 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001570 }
1571 break;
1572
1573 case Primitive::kPrimFloat:
1574 case Primitive::kPrimDouble:
1575 LOG(FATAL) << "Type conversion from " << input_type
1576 << " to " << result_type << " not yet implemented";
1577 break;
1578
1579 default:
1580 LOG(FATAL) << "Unexpected type conversion from " << input_type
1581 << " to " << result_type;
1582 }
1583 break;
1584
Roland Levillaindff1f282014-11-05 14:15:05 +00001585 case Primitive::kPrimLong:
1586 switch (input_type) {
1587 case Primitive::kPrimByte:
1588 case Primitive::kPrimShort:
1589 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001590 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001591 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001592 DCHECK(out.IsRegisterPair());
1593 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001594 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001595 // Sign extension.
1596 __ Asr(out.AsRegisterPairHigh<Register>(),
1597 out.AsRegisterPairLow<Register>(),
1598 31);
1599 break;
1600
1601 case Primitive::kPrimFloat:
1602 case Primitive::kPrimDouble:
1603 LOG(FATAL) << "Type conversion from " << input_type << " to "
1604 << result_type << " not yet implemented";
1605 break;
1606
1607 default:
1608 LOG(FATAL) << "Unexpected type conversion from " << input_type
1609 << " to " << result_type;
1610 }
1611 break;
1612
Roland Levillain981e4542014-11-14 11:47:14 +00001613 case Primitive::kPrimChar:
1614 switch (input_type) {
1615 case Primitive::kPrimByte:
1616 case Primitive::kPrimShort:
1617 case Primitive::kPrimInt:
1618 case Primitive::kPrimChar:
1619 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001620 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001621 break;
1622
1623 default:
1624 LOG(FATAL) << "Unexpected type conversion from " << input_type
1625 << " to " << result_type;
1626 }
1627 break;
1628
Roland Levillaindff1f282014-11-05 14:15:05 +00001629 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001630 switch (input_type) {
1631 case Primitive::kPrimByte:
1632 case Primitive::kPrimShort:
1633 case Primitive::kPrimInt:
1634 case Primitive::kPrimChar: {
1635 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001636 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1637 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001638 break;
1639 }
1640
1641 case Primitive::kPrimLong:
1642 case Primitive::kPrimDouble:
1643 LOG(FATAL) << "Type conversion from " << input_type
1644 << " to " << result_type << " not yet implemented";
1645 break;
1646
1647 default:
1648 LOG(FATAL) << "Unexpected type conversion from " << input_type
1649 << " to " << result_type;
1650 };
1651 break;
1652
Roland Levillaindff1f282014-11-05 14:15:05 +00001653 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001654 switch (input_type) {
1655 case Primitive::kPrimByte:
1656 case Primitive::kPrimShort:
1657 case Primitive::kPrimInt:
1658 case Primitive::kPrimChar: {
1659 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001660 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001661 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1662 out.AsFpuRegisterPairLow<SRegister>());
1663 break;
1664 }
1665
Roland Levillain647b9ed2014-11-27 12:06:00 +00001666 case Primitive::kPrimLong: {
1667 // Processing a Dex `long-to-double' instruction.
1668 Register low = in.AsRegisterPairLow<Register>();
1669 Register high = in.AsRegisterPairHigh<Register>();
1670 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1671 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001672 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1673 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001674 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1675 DRegister temp_d = FromLowSToD(temp_s);
1676
1677 // Binary encoding of 2^32 for type double.
1678 const uint64_t c = UINT64_C(0x41F0000000000000);
1679
1680 // out_d = int-to-double(high)
1681 __ vmovsr(out_s, high);
1682 __ vcvtdi(out_d, out_s);
1683 // Using vmovd to load the `c` constant as an immediate
1684 // value into `temp_d` does not work, as this instruction
1685 // only transfers 8 significant bits of its immediate
1686 // operand. Instead, use two 32-bit core registers to
1687 // load `c` into `temp_d`.
1688 __ LoadImmediate(constant_low, Low32Bits(c));
1689 __ LoadImmediate(constant_high, High32Bits(c));
1690 __ vmovdrr(temp_d, constant_low, constant_high);
1691 // out_d = out_d * 2^32
1692 __ vmuld(out_d, out_d, temp_d);
1693 // temp_d = unsigned-to-double(low)
1694 __ vmovsr(temp_s, low);
1695 __ vcvtdu(temp_d, temp_s);
1696 // out_d = out_d + temp_d
1697 __ vaddd(out_d, out_d, temp_d);
1698 break;
1699 }
1700
Roland Levillaincff13742014-11-17 14:32:17 +00001701 case Primitive::kPrimFloat:
1702 LOG(FATAL) << "Type conversion from " << input_type
1703 << " to " << result_type << " not yet implemented";
1704 break;
1705
1706 default:
1707 LOG(FATAL) << "Unexpected type conversion from " << input_type
1708 << " to " << result_type;
1709 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001710 break;
1711
1712 default:
1713 LOG(FATAL) << "Unexpected type conversion from " << input_type
1714 << " to " << result_type;
1715 }
1716}
1717
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001718void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001719 LocationSummary* locations =
1720 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001721 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001722 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001723 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001724 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1725 locations->SetInAt(0, Location::RequiresRegister());
1726 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1727 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001728 break;
1729 }
1730
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001731 case Primitive::kPrimFloat:
1732 case Primitive::kPrimDouble: {
1733 locations->SetInAt(0, Location::RequiresFpuRegister());
1734 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001735 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001736 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001737 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001738
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001739 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001740 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001741 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001742}
1743
1744void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1745 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001746 Location out = locations->Out();
1747 Location first = locations->InAt(0);
1748 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001749 switch (add->GetResultType()) {
1750 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001751 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001752 __ add(out.AsRegister<Register>(),
1753 first.AsRegister<Register>(),
1754 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001755 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001756 __ AddConstant(out.AsRegister<Register>(),
1757 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001758 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001759 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001760 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001761
1762 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001763 __ adds(out.AsRegisterPairLow<Register>(),
1764 first.AsRegisterPairLow<Register>(),
1765 ShifterOperand(second.AsRegisterPairLow<Register>()));
1766 __ adc(out.AsRegisterPairHigh<Register>(),
1767 first.AsRegisterPairHigh<Register>(),
1768 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001769 break;
1770
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001771 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001772 __ vadds(out.AsFpuRegister<SRegister>(),
1773 first.AsFpuRegister<SRegister>(),
1774 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001775 break;
1776
1777 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001778 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1779 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1780 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001781 break;
1782
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001783 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001784 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001785 }
1786}
1787
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001788void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001789 LocationSummary* locations =
1790 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001791 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001792 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001793 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001794 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1795 locations->SetInAt(0, Location::RequiresRegister());
1796 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1797 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001798 break;
1799 }
Calin Juravle11351682014-10-23 15:38:15 +01001800 case Primitive::kPrimFloat:
1801 case Primitive::kPrimDouble: {
1802 locations->SetInAt(0, Location::RequiresFpuRegister());
1803 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001804 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001805 break;
Calin Juravle11351682014-10-23 15:38:15 +01001806 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001807 default:
Calin Juravle11351682014-10-23 15:38:15 +01001808 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001809 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001810}
1811
1812void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1813 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001814 Location out = locations->Out();
1815 Location first = locations->InAt(0);
1816 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001817 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001818 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001819 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001820 __ sub(out.AsRegister<Register>(),
1821 first.AsRegister<Register>(),
1822 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001823 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001824 __ AddConstant(out.AsRegister<Register>(),
1825 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001826 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001827 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001828 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001829 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001830
Calin Juravle11351682014-10-23 15:38:15 +01001831 case Primitive::kPrimLong: {
1832 __ subs(out.AsRegisterPairLow<Register>(),
1833 first.AsRegisterPairLow<Register>(),
1834 ShifterOperand(second.AsRegisterPairLow<Register>()));
1835 __ sbc(out.AsRegisterPairHigh<Register>(),
1836 first.AsRegisterPairHigh<Register>(),
1837 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001838 break;
Calin Juravle11351682014-10-23 15:38:15 +01001839 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001840
Calin Juravle11351682014-10-23 15:38:15 +01001841 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001842 __ vsubs(out.AsFpuRegister<SRegister>(),
1843 first.AsFpuRegister<SRegister>(),
1844 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001845 break;
Calin Juravle11351682014-10-23 15:38:15 +01001846 }
1847
1848 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001849 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1850 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1851 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001852 break;
1853 }
1854
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001855
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001856 default:
Calin Juravle11351682014-10-23 15:38:15 +01001857 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001858 }
1859}
1860
Calin Juravle34bacdf2014-10-07 20:23:36 +01001861void LocationsBuilderARM::VisitMul(HMul* mul) {
1862 LocationSummary* locations =
1863 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1864 switch (mul->GetResultType()) {
1865 case Primitive::kPrimInt:
1866 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001867 locations->SetInAt(0, Location::RequiresRegister());
1868 locations->SetInAt(1, Location::RequiresRegister());
1869 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001870 break;
1871 }
1872
Calin Juravleb5bfa962014-10-21 18:02:24 +01001873 case Primitive::kPrimFloat:
1874 case Primitive::kPrimDouble: {
1875 locations->SetInAt(0, Location::RequiresFpuRegister());
1876 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001877 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001878 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001879 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001880
1881 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001882 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001883 }
1884}
1885
1886void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1887 LocationSummary* locations = mul->GetLocations();
1888 Location out = locations->Out();
1889 Location first = locations->InAt(0);
1890 Location second = locations->InAt(1);
1891 switch (mul->GetResultType()) {
1892 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00001893 __ mul(out.AsRegister<Register>(),
1894 first.AsRegister<Register>(),
1895 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001896 break;
1897 }
1898 case Primitive::kPrimLong: {
1899 Register out_hi = out.AsRegisterPairHigh<Register>();
1900 Register out_lo = out.AsRegisterPairLow<Register>();
1901 Register in1_hi = first.AsRegisterPairHigh<Register>();
1902 Register in1_lo = first.AsRegisterPairLow<Register>();
1903 Register in2_hi = second.AsRegisterPairHigh<Register>();
1904 Register in2_lo = second.AsRegisterPairLow<Register>();
1905
1906 // Extra checks to protect caused by the existence of R1_R2.
1907 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1908 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1909 DCHECK_NE(out_hi, in1_lo);
1910 DCHECK_NE(out_hi, in2_lo);
1911
1912 // input: in1 - 64 bits, in2 - 64 bits
1913 // output: out
1914 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1915 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1916 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1917
1918 // IP <- in1.lo * in2.hi
1919 __ mul(IP, in1_lo, in2_hi);
1920 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1921 __ mla(out_hi, in1_hi, in2_lo, IP);
1922 // out.lo <- (in1.lo * in2.lo)[31:0];
1923 __ umull(out_lo, IP, in1_lo, in2_lo);
1924 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1925 __ add(out_hi, out_hi, ShifterOperand(IP));
1926 break;
1927 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001928
1929 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001930 __ vmuls(out.AsFpuRegister<SRegister>(),
1931 first.AsFpuRegister<SRegister>(),
1932 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001933 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001934 }
1935
1936 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001937 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1938 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1939 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01001940 break;
1941 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001942
1943 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001944 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001945 }
1946}
1947
Calin Juravle7c4954d2014-10-28 16:57:40 +00001948void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001949 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
1950 ? LocationSummary::kCall
1951 : LocationSummary::kNoCall;
1952 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
1953
Calin Juravle7c4954d2014-10-28 16:57:40 +00001954 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001955 case Primitive::kPrimInt: {
1956 locations->SetInAt(0, Location::RequiresRegister());
1957 locations->SetInAt(1, Location::RequiresRegister());
1958 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1959 break;
1960 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00001961 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001962 InvokeRuntimeCallingConvention calling_convention;
1963 locations->SetInAt(0, Location::RegisterPairLocation(
1964 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1965 locations->SetInAt(1, Location::RegisterPairLocation(
1966 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
1967 // The runtime helper puts the output in R0,R2.
1968 locations->SetOut(Location::RegisterPairLocation(R0, R2));
Calin Juravle7c4954d2014-10-28 16:57:40 +00001969 break;
1970 }
1971 case Primitive::kPrimFloat:
1972 case Primitive::kPrimDouble: {
1973 locations->SetInAt(0, Location::RequiresFpuRegister());
1974 locations->SetInAt(1, Location::RequiresFpuRegister());
1975 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1976 break;
1977 }
1978
1979 default:
1980 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1981 }
1982}
1983
1984void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
1985 LocationSummary* locations = div->GetLocations();
1986 Location out = locations->Out();
1987 Location first = locations->InAt(0);
1988 Location second = locations->InAt(1);
1989
1990 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00001991 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00001992 __ sdiv(out.AsRegister<Register>(),
1993 first.AsRegister<Register>(),
1994 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00001995 break;
1996 }
1997
Calin Juravle7c4954d2014-10-28 16:57:40 +00001998 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00001999 InvokeRuntimeCallingConvention calling_convention;
2000 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2001 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2002 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2003 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2004 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2005 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2006
2007 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002008 break;
2009 }
2010
2011 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002012 __ vdivs(out.AsFpuRegister<SRegister>(),
2013 first.AsFpuRegister<SRegister>(),
2014 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002015 break;
2016 }
2017
2018 case Primitive::kPrimDouble: {
2019 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2020 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2021 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2022 break;
2023 }
2024
2025 default:
2026 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2027 }
2028}
2029
Calin Juravlebacfec32014-11-14 15:54:36 +00002030void LocationsBuilderARM::VisitRem(HRem* rem) {
2031 LocationSummary::CallKind call_kind = rem->GetResultType() == Primitive::kPrimLong
2032 ? LocationSummary::kCall
2033 : LocationSummary::kNoCall;
2034 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2035
2036 switch (rem->GetResultType()) {
2037 case Primitive::kPrimInt: {
2038 locations->SetInAt(0, Location::RequiresRegister());
2039 locations->SetInAt(1, Location::RequiresRegister());
2040 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2041 locations->AddTemp(Location::RequiresRegister());
2042 break;
2043 }
2044 case Primitive::kPrimLong: {
2045 InvokeRuntimeCallingConvention calling_convention;
2046 locations->SetInAt(0, Location::RegisterPairLocation(
2047 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2048 locations->SetInAt(1, Location::RegisterPairLocation(
2049 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2050 // The runtime helper puts the output in R2,R3.
2051 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2052 break;
2053 }
2054 case Primitive::kPrimFloat:
2055 case Primitive::kPrimDouble: {
2056 LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType();
2057 break;
2058 }
2059
2060 default:
2061 LOG(FATAL) << "Unexpected rem type " << rem->GetResultType();
2062 }
2063}
2064
2065void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2066 LocationSummary* locations = rem->GetLocations();
2067 Location out = locations->Out();
2068 Location first = locations->InAt(0);
2069 Location second = locations->InAt(1);
2070
2071 switch (rem->GetResultType()) {
2072 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002073 Register reg1 = first.AsRegister<Register>();
2074 Register reg2 = second.AsRegister<Register>();
2075 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002076
2077 // temp = reg1 / reg2 (integer division)
2078 // temp = temp * reg2
2079 // dest = reg1 - temp
2080 __ sdiv(temp, reg1, reg2);
2081 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002082 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002083 break;
2084 }
2085
2086 case Primitive::kPrimLong: {
2087 InvokeRuntimeCallingConvention calling_convention;
2088 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2089 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2090 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2091 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2092 DCHECK_EQ(R2, out.AsRegisterPairLow<Register>());
2093 DCHECK_EQ(R3, out.AsRegisterPairHigh<Register>());
2094
2095 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2096 break;
2097 }
2098
2099 case Primitive::kPrimFloat:
2100 case Primitive::kPrimDouble: {
2101 LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType();
2102 break;
2103 }
2104
2105 default:
2106 LOG(FATAL) << "Unexpected rem type " << rem->GetResultType();
2107 }
2108}
2109
Calin Juravled0d48522014-11-04 16:40:20 +00002110void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2111 LocationSummary* locations =
2112 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002113 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002114 if (instruction->HasUses()) {
2115 locations->SetOut(Location::SameAsFirstInput());
2116 }
2117}
2118
2119void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2120 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2121 codegen_->AddSlowPath(slow_path);
2122
2123 LocationSummary* locations = instruction->GetLocations();
2124 Location value = locations->InAt(0);
2125
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002126 switch (instruction->GetType()) {
2127 case Primitive::kPrimInt: {
2128 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002129 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002130 __ b(slow_path->GetEntryLabel(), EQ);
2131 } else {
2132 DCHECK(value.IsConstant()) << value;
2133 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2134 __ b(slow_path->GetEntryLabel());
2135 }
2136 }
2137 break;
2138 }
2139 case Primitive::kPrimLong: {
2140 if (value.IsRegisterPair()) {
2141 __ orrs(IP,
2142 value.AsRegisterPairLow<Register>(),
2143 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2144 __ b(slow_path->GetEntryLabel(), EQ);
2145 } else {
2146 DCHECK(value.IsConstant()) << value;
2147 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2148 __ b(slow_path->GetEntryLabel());
2149 }
2150 }
2151 break;
2152 default:
2153 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2154 }
2155 }
Calin Juravled0d48522014-11-04 16:40:20 +00002156}
2157
Calin Juravle9aec02f2014-11-18 23:06:35 +00002158void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2159 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2160
2161 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2162 ? LocationSummary::kCall
2163 : LocationSummary::kNoCall;
2164 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2165
2166 switch (op->GetResultType()) {
2167 case Primitive::kPrimInt: {
2168 locations->SetInAt(0, Location::RequiresRegister());
2169 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
2170 locations->SetOut(Location::RequiresRegister());
2171 break;
2172 }
2173 case Primitive::kPrimLong: {
2174 InvokeRuntimeCallingConvention calling_convention;
2175 locations->SetInAt(0, Location::RegisterPairLocation(
2176 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2177 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2178 // The runtime helper puts the output in R0,R2.
2179 locations->SetOut(Location::RegisterPairLocation(R0, R2));
2180 break;
2181 }
2182 default:
2183 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2184 }
2185}
2186
2187void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2188 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2189
2190 LocationSummary* locations = op->GetLocations();
2191 Location out = locations->Out();
2192 Location first = locations->InAt(0);
2193 Location second = locations->InAt(1);
2194
2195 Primitive::Type type = op->GetResultType();
2196 switch (type) {
2197 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002198 Register out_reg = out.AsRegister<Register>();
2199 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002200 // Arm doesn't mask the shift count so we need to do it ourselves.
2201 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002202 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002203 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2204 if (op->IsShl()) {
2205 __ Lsl(out_reg, first_reg, second_reg);
2206 } else if (op->IsShr()) {
2207 __ Asr(out_reg, first_reg, second_reg);
2208 } else {
2209 __ Lsr(out_reg, first_reg, second_reg);
2210 }
2211 } else {
2212 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2213 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2214 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2215 __ Mov(out_reg, first_reg);
2216 } else if (op->IsShl()) {
2217 __ Lsl(out_reg, first_reg, shift_value);
2218 } else if (op->IsShr()) {
2219 __ Asr(out_reg, first_reg, shift_value);
2220 } else {
2221 __ Lsr(out_reg, first_reg, shift_value);
2222 }
2223 }
2224 break;
2225 }
2226 case Primitive::kPrimLong: {
2227 // TODO: Inline the assembly instead of calling the runtime.
2228 InvokeRuntimeCallingConvention calling_convention;
2229 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2230 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002231 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002232 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2233 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2234
2235 int32_t entry_point_offset;
2236 if (op->IsShl()) {
2237 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2238 } else if (op->IsShr()) {
2239 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2240 } else {
2241 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2242 }
2243 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2244 __ blx(LR);
2245 break;
2246 }
2247 default:
2248 LOG(FATAL) << "Unexpected operation type " << type;
2249 }
2250}
2251
2252void LocationsBuilderARM::VisitShl(HShl* shl) {
2253 HandleShift(shl);
2254}
2255
2256void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2257 HandleShift(shl);
2258}
2259
2260void LocationsBuilderARM::VisitShr(HShr* shr) {
2261 HandleShift(shr);
2262}
2263
2264void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2265 HandleShift(shr);
2266}
2267
2268void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2269 HandleShift(ushr);
2270}
2271
2272void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2273 HandleShift(ushr);
2274}
2275
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002276void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002277 LocationSummary* locations =
2278 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002279 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002280 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2281 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2282 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002283}
2284
2285void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2286 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002287 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002288 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002289 codegen_->InvokeRuntime(
2290 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002291}
2292
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002293void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2294 LocationSummary* locations =
2295 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2296 InvokeRuntimeCallingConvention calling_convention;
2297 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2298 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2299 locations->SetOut(Location::RegisterLocation(R0));
2300 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2301}
2302
2303void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2304 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002305 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002306 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002307 codegen_->InvokeRuntime(
2308 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002309}
2310
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002311void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002312 LocationSummary* locations =
2313 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002314 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2315 if (location.IsStackSlot()) {
2316 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2317 } else if (location.IsDoubleStackSlot()) {
2318 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002319 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002320 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002321}
2322
2323void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002324 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002325 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002326}
2327
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002328void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002329 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002330 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002331 locations->SetInAt(0, Location::RequiresRegister());
2332 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002333}
2334
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002335void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2336 LocationSummary* locations = not_->GetLocations();
2337 Location out = locations->Out();
2338 Location in = locations->InAt(0);
2339 switch (not_->InputAt(0)->GetType()) {
2340 case Primitive::kPrimBoolean:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002341 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002342 break;
2343
2344 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002345 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002346 break;
2347
2348 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002349 __ mvn(out.AsRegisterPairLow<Register>(),
2350 ShifterOperand(in.AsRegisterPairLow<Register>()));
2351 __ mvn(out.AsRegisterPairHigh<Register>(),
2352 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002353 break;
2354
2355 default:
2356 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2357 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002358}
2359
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002360void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002361 LocationSummary* locations =
2362 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002363 switch (compare->InputAt(0)->GetType()) {
2364 case Primitive::kPrimLong: {
2365 locations->SetInAt(0, Location::RequiresRegister());
2366 locations->SetInAt(1, Location::RequiresRegister());
2367 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2368 break;
2369 }
2370 case Primitive::kPrimFloat:
2371 case Primitive::kPrimDouble: {
2372 locations->SetInAt(0, Location::RequiresFpuRegister());
2373 locations->SetInAt(1, Location::RequiresFpuRegister());
2374 locations->SetOut(Location::RequiresRegister());
2375 break;
2376 }
2377 default:
2378 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2379 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002380}
2381
2382void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002383 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002384 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002385 Location left = locations->InAt(0);
2386 Location right = locations->InAt(1);
2387
2388 Label less, greater, done;
2389 Primitive::Type type = compare->InputAt(0)->GetType();
2390 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002391 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002392 __ cmp(left.AsRegisterPairHigh<Register>(),
2393 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002394 __ b(&less, LT);
2395 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002396 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2397 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002398 __ cmp(left.AsRegisterPairLow<Register>(),
2399 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002400 break;
2401 }
2402 case Primitive::kPrimFloat:
2403 case Primitive::kPrimDouble: {
2404 __ LoadImmediate(out, 0);
2405 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002406 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002407 } else {
2408 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2409 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2410 }
2411 __ vmstat(); // transfer FP status register to ARM APSR.
2412 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002413 break;
2414 }
2415 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002416 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002417 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002418 __ b(&done, EQ);
2419 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2420
2421 __ Bind(&greater);
2422 __ LoadImmediate(out, 1);
2423 __ b(&done);
2424
2425 __ Bind(&less);
2426 __ LoadImmediate(out, -1);
2427
2428 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002429}
2430
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002431void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002432 LocationSummary* locations =
2433 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002434 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2435 locations->SetInAt(i, Location::Any());
2436 }
2437 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002438}
2439
2440void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002441 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002442 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002443}
2444
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002445void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002446 LocationSummary* locations =
2447 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002448 bool needs_write_barrier =
2449 CodeGenerator::StoreNeedsWriteBarrier(instruction->GetFieldType(), instruction->GetValue());
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002450 locations->SetInAt(0, Location::RequiresRegister());
2451 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002452 // Temporary registers for the write barrier.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002453 if (needs_write_barrier) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002454 locations->AddTemp(Location::RequiresRegister());
2455 locations->AddTemp(Location::RequiresRegister());
2456 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002457}
2458
2459void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2460 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002461 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002462 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01002463 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002464
2465 switch (field_type) {
2466 case Primitive::kPrimBoolean:
2467 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002468 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002469 __ StoreToOffset(kStoreByte, value, obj, offset);
2470 break;
2471 }
2472
2473 case Primitive::kPrimShort:
2474 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002475 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002476 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2477 break;
2478 }
2479
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002480 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002481 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002482 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002483 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002484 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002485 Register temp = locations->GetTemp(0).AsRegister<Register>();
2486 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002487 codegen_->MarkGCCard(temp, card, obj, value);
2488 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002489 break;
2490 }
2491
2492 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002493 Location value = locations->InAt(1);
2494 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002495 break;
2496 }
2497
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002498 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002499 SRegister value = locations->InAt(1).AsFpuRegister<SRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002500 __ StoreSToOffset(value, obj, offset);
2501 break;
2502 }
2503
2504 case Primitive::kPrimDouble: {
2505 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
2506 __ StoreDToOffset(value, obj, offset);
2507 break;
2508 }
2509
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002510 case Primitive::kPrimVoid:
2511 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002512 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002513 }
2514}
2515
2516void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002517 LocationSummary* locations =
2518 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002519 locations->SetInAt(0, Location::RequiresRegister());
2520 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002521}
2522
2523void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2524 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002525 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002526 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2527
2528 switch (instruction->GetType()) {
2529 case Primitive::kPrimBoolean: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002530 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002531 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2532 break;
2533 }
2534
2535 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002536 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002537 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2538 break;
2539 }
2540
2541 case Primitive::kPrimShort: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002542 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002543 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2544 break;
2545 }
2546
2547 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002548 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002549 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2550 break;
2551 }
2552
2553 case Primitive::kPrimInt:
2554 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002555 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002556 __ LoadFromOffset(kLoadWord, out, obj, offset);
2557 break;
2558 }
2559
2560 case Primitive::kPrimLong: {
2561 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002562 Location out = locations->Out();
2563 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002564 break;
2565 }
2566
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002567 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002568 SRegister out = locations->Out().AsFpuRegister<SRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002569 __ LoadSFromOffset(out, obj, offset);
2570 break;
2571 }
2572
2573 case Primitive::kPrimDouble: {
2574 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2575 __ LoadDFromOffset(out, obj, offset);
2576 break;
2577 }
2578
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002579 case Primitive::kPrimVoid:
2580 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002581 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002582 }
2583}
2584
2585void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002586 LocationSummary* locations =
2587 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002588 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002589 if (instruction->HasUses()) {
2590 locations->SetOut(Location::SameAsFirstInput());
2591 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002592}
2593
2594void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002595 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002596 codegen_->AddSlowPath(slow_path);
2597
2598 LocationSummary* locations = instruction->GetLocations();
2599 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002600
2601 if (obj.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002602 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002603 __ b(slow_path->GetEntryLabel(), EQ);
2604 } else {
2605 DCHECK(obj.IsConstant()) << obj;
2606 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2607 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002608 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002609}
2610
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002611void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002612 LocationSummary* locations =
2613 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002614 locations->SetInAt(0, Location::RequiresRegister());
2615 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2616 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002617}
2618
2619void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2620 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002621 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002622 Location index = locations->InAt(1);
2623
2624 switch (instruction->GetType()) {
2625 case Primitive::kPrimBoolean: {
2626 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002627 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002628 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002629 size_t offset =
2630 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002631 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2632 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002633 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002634 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2635 }
2636 break;
2637 }
2638
2639 case Primitive::kPrimByte: {
2640 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002641 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002642 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002643 size_t offset =
2644 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002645 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2646 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002647 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002648 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2649 }
2650 break;
2651 }
2652
2653 case Primitive::kPrimShort: {
2654 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002655 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002656 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002657 size_t offset =
2658 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002659 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2660 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002661 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002662 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2663 }
2664 break;
2665 }
2666
2667 case Primitive::kPrimChar: {
2668 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002669 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002670 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002671 size_t offset =
2672 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002673 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2674 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002675 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002676 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2677 }
2678 break;
2679 }
2680
2681 case Primitive::kPrimInt:
2682 case Primitive::kPrimNot: {
2683 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2684 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002685 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002686 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002687 size_t offset =
2688 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002689 __ LoadFromOffset(kLoadWord, out, obj, offset);
2690 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002691 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002692 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2693 }
2694 break;
2695 }
2696
2697 case Primitive::kPrimLong: {
2698 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002699 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002700 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002701 size_t offset =
2702 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002703 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002704 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002705 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002706 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002707 }
2708 break;
2709 }
2710
2711 case Primitive::kPrimFloat:
2712 case Primitive::kPrimDouble:
2713 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002714 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002715 case Primitive::kPrimVoid:
2716 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002717 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002718 }
2719}
2720
2721void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002722 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002723
2724 bool needs_write_barrier =
2725 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
2726 bool needs_runtime_call = instruction->NeedsTypeCheck();
2727
Nicolas Geoffray39468442014-09-02 15:17:15 +01002728 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002729 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
2730 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002731 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002732 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2733 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2734 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002735 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002736 locations->SetInAt(0, Location::RequiresRegister());
2737 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2738 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002739
2740 if (needs_write_barrier) {
2741 // Temporary registers for the write barrier.
2742 locations->AddTemp(Location::RequiresRegister());
2743 locations->AddTemp(Location::RequiresRegister());
2744 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002745 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002746}
2747
2748void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
2749 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002750 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002751 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002752 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002753 bool needs_runtime_call = locations->WillCall();
2754 bool needs_write_barrier =
2755 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002756
2757 switch (value_type) {
2758 case Primitive::kPrimBoolean:
2759 case Primitive::kPrimByte: {
2760 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002761 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002762 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002763 size_t offset =
2764 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002765 __ StoreToOffset(kStoreByte, value, obj, offset);
2766 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002767 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002768 __ StoreToOffset(kStoreByte, value, IP, data_offset);
2769 }
2770 break;
2771 }
2772
2773 case Primitive::kPrimShort:
2774 case Primitive::kPrimChar: {
2775 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002776 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002777 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002778 size_t offset =
2779 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002780 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2781 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002782 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002783 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
2784 }
2785 break;
2786 }
2787
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002788 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002789 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002790 if (!needs_runtime_call) {
2791 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002792 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002793 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002794 size_t offset =
2795 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002796 __ StoreToOffset(kStoreWord, value, obj, offset);
2797 } else {
2798 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00002799 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002800 __ StoreToOffset(kStoreWord, value, IP, data_offset);
2801 }
2802 if (needs_write_barrier) {
2803 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002804 Register temp = locations->GetTemp(0).AsRegister<Register>();
2805 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002806 codegen_->MarkGCCard(temp, card, obj, value);
2807 }
2808 } else {
2809 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00002810 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
2811 instruction,
2812 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002813 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002814 break;
2815 }
2816
2817 case Primitive::kPrimLong: {
2818 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002819 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002820 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002821 size_t offset =
2822 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002823 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002824 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002825 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002826 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002827 }
2828 break;
2829 }
2830
2831 case Primitive::kPrimFloat:
2832 case Primitive::kPrimDouble:
2833 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002834 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002835 case Primitive::kPrimVoid:
2836 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002837 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002838 }
2839}
2840
2841void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002842 LocationSummary* locations =
2843 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002844 locations->SetInAt(0, Location::RequiresRegister());
2845 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002846}
2847
2848void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
2849 LocationSummary* locations = instruction->GetLocations();
2850 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002851 Register obj = locations->InAt(0).AsRegister<Register>();
2852 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002853 __ LoadFromOffset(kLoadWord, out, obj, offset);
2854}
2855
2856void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002857 LocationSummary* locations =
2858 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002859 locations->SetInAt(0, Location::RequiresRegister());
2860 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002861 if (instruction->HasUses()) {
2862 locations->SetOut(Location::SameAsFirstInput());
2863 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002864}
2865
2866void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
2867 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002868 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002869 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002870 codegen_->AddSlowPath(slow_path);
2871
Roland Levillain271ab9c2014-11-27 15:23:57 +00002872 Register index = locations->InAt(0).AsRegister<Register>();
2873 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002874
2875 __ cmp(index, ShifterOperand(length));
2876 __ b(slow_path->GetEntryLabel(), CS);
2877}
2878
2879void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
2880 Label is_null;
2881 __ CompareAndBranchIfZero(value, &is_null);
2882 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
2883 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
2884 __ strb(card, Address(card, temp));
2885 __ Bind(&is_null);
2886}
2887
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002888void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
2889 temp->SetLocations(nullptr);
2890}
2891
2892void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
2893 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002894 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002895}
2896
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002897void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002898 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002899 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002900}
2901
2902void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002903 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2904}
2905
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002906void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2907 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2908}
2909
2910void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002911 HBasicBlock* block = instruction->GetBlock();
2912 if (block->GetLoopInformation() != nullptr) {
2913 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2914 // The back edge will generate the suspend check.
2915 return;
2916 }
2917 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2918 // The goto will generate the suspend check.
2919 return;
2920 }
2921 GenerateSuspendCheck(instruction, nullptr);
2922}
2923
2924void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
2925 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002926 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002927 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002928 codegen_->AddSlowPath(slow_path);
2929
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002930 __ LoadFromOffset(
2931 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
2932 __ cmp(IP, ShifterOperand(0));
2933 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002934 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002935 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002936 __ Bind(slow_path->GetReturnLabel());
2937 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00002938 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002939 __ b(slow_path->GetEntryLabel());
2940 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002941}
2942
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002943ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
2944 return codegen_->GetAssembler();
2945}
2946
2947void ParallelMoveResolverARM::EmitMove(size_t index) {
2948 MoveOperands* move = moves_.Get(index);
2949 Location source = move->GetSource();
2950 Location destination = move->GetDestination();
2951
2952 if (source.IsRegister()) {
2953 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002954 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002955 } else {
2956 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002957 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002958 SP, destination.GetStackIndex());
2959 }
2960 } else if (source.IsStackSlot()) {
2961 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002962 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002963 SP, source.GetStackIndex());
2964 } else {
2965 DCHECK(destination.IsStackSlot());
2966 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
2967 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
2968 }
2969 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002970 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01002971 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002972 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
2973 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002974 __ LoadImmediate(destination.AsRegister<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002975 } else {
2976 DCHECK(destination.IsStackSlot());
2977 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01002978 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002979 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002980 }
2981}
2982
2983void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
2984 __ Mov(IP, reg);
2985 __ LoadFromOffset(kLoadWord, reg, SP, mem);
2986 __ StoreToOffset(kStoreWord, IP, SP, mem);
2987}
2988
2989void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
2990 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
2991 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
2992 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
2993 SP, mem1 + stack_offset);
2994 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
2995 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
2996 SP, mem2 + stack_offset);
2997 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
2998}
2999
3000void ParallelMoveResolverARM::EmitSwap(size_t index) {
3001 MoveOperands* move = moves_.Get(index);
3002 Location source = move->GetSource();
3003 Location destination = move->GetDestination();
3004
3005 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003006 DCHECK_NE(source.AsRegister<Register>(), IP);
3007 DCHECK_NE(destination.AsRegister<Register>(), IP);
3008 __ Mov(IP, source.AsRegister<Register>());
3009 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3010 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003011 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003012 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003013 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003014 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003015 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3016 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3017 } else {
3018 LOG(FATAL) << "Unimplemented";
3019 }
3020}
3021
3022void ParallelMoveResolverARM::SpillScratch(int reg) {
3023 __ Push(static_cast<Register>(reg));
3024}
3025
3026void ParallelMoveResolverARM::RestoreScratch(int reg) {
3027 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003028}
3029
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003030void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003031 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3032 ? LocationSummary::kCallOnSlowPath
3033 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003034 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003035 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003036 locations->SetOut(Location::RequiresRegister());
3037}
3038
3039void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003040 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003041 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003042 DCHECK(!cls->CanCallRuntime());
3043 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003044 codegen_->LoadCurrentMethod(out);
3045 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3046 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003047 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003048 codegen_->LoadCurrentMethod(out);
3049 __ LoadFromOffset(
3050 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3051 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003052
3053 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3054 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3055 codegen_->AddSlowPath(slow_path);
3056 __ cmp(out, ShifterOperand(0));
3057 __ b(slow_path->GetEntryLabel(), EQ);
3058 if (cls->MustGenerateClinitCheck()) {
3059 GenerateClassInitializationCheck(slow_path, out);
3060 } else {
3061 __ Bind(slow_path->GetExitLabel());
3062 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003063 }
3064}
3065
3066void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3067 LocationSummary* locations =
3068 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3069 locations->SetInAt(0, Location::RequiresRegister());
3070 if (check->HasUses()) {
3071 locations->SetOut(Location::SameAsFirstInput());
3072 }
3073}
3074
3075void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003076 // We assume the class is not null.
3077 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3078 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003079 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003080 GenerateClassInitializationCheck(slow_path,
3081 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003082}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003083
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003084void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3085 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003086 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3087 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3088 __ b(slow_path->GetEntryLabel(), LT);
3089 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3090 // properly. Therefore, we do a memory fence.
3091 __ dmb(ISH);
3092 __ Bind(slow_path->GetExitLabel());
3093}
3094
3095void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3096 LocationSummary* locations =
3097 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3098 locations->SetInAt(0, Location::RequiresRegister());
3099 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3100}
3101
3102void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3103 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003104 Register cls = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003105 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
3106
3107 switch (instruction->GetType()) {
3108 case Primitive::kPrimBoolean: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003109 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003110 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
3111 break;
3112 }
3113
3114 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003115 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003116 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
3117 break;
3118 }
3119
3120 case Primitive::kPrimShort: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003121 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003122 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
3123 break;
3124 }
3125
3126 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003127 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003128 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
3129 break;
3130 }
3131
3132 case Primitive::kPrimInt:
3133 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003134 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003135 __ LoadFromOffset(kLoadWord, out, cls, offset);
3136 break;
3137 }
3138
3139 case Primitive::kPrimLong: {
3140 // TODO: support volatile.
3141 Location out = locations->Out();
3142 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
3143 break;
3144 }
3145
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003146 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003147 SRegister out = locations->Out().AsFpuRegister<SRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003148 __ LoadSFromOffset(out, cls, offset);
3149 break;
3150 }
3151
3152 case Primitive::kPrimDouble: {
3153 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
3154 __ LoadDFromOffset(out, cls, offset);
3155 break;
3156 }
3157
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003158 case Primitive::kPrimVoid:
3159 LOG(FATAL) << "Unreachable type " << instruction->GetType();
3160 UNREACHABLE();
3161 }
3162}
3163
3164void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3165 LocationSummary* locations =
3166 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003167 bool needs_write_barrier =
3168 CodeGenerator::StoreNeedsWriteBarrier(instruction->GetFieldType(), instruction->GetValue());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003169 locations->SetInAt(0, Location::RequiresRegister());
3170 locations->SetInAt(1, Location::RequiresRegister());
3171 // Temporary registers for the write barrier.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003172 if (needs_write_barrier) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003173 locations->AddTemp(Location::RequiresRegister());
3174 locations->AddTemp(Location::RequiresRegister());
3175 }
3176}
3177
3178void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3179 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003180 Register cls = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003181 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
3182 Primitive::Type field_type = instruction->GetFieldType();
3183
3184 switch (field_type) {
3185 case Primitive::kPrimBoolean:
3186 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003187 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003188 __ StoreToOffset(kStoreByte, value, cls, offset);
3189 break;
3190 }
3191
3192 case Primitive::kPrimShort:
3193 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003194 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003195 __ StoreToOffset(kStoreHalfword, value, cls, offset);
3196 break;
3197 }
3198
3199 case Primitive::kPrimInt:
3200 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003201 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003202 __ StoreToOffset(kStoreWord, value, cls, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003203 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003204 Register temp = locations->GetTemp(0).AsRegister<Register>();
3205 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003206 codegen_->MarkGCCard(temp, card, cls, value);
3207 }
3208 break;
3209 }
3210
3211 case Primitive::kPrimLong: {
3212 Location value = locations->InAt(1);
3213 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
3214 break;
3215 }
3216
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003217 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003218 SRegister value = locations->InAt(1).AsFpuRegister<SRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003219 __ StoreSToOffset(value, cls, offset);
3220 break;
3221 }
3222
3223 case Primitive::kPrimDouble: {
3224 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
3225 __ StoreDToOffset(value, cls, offset);
3226 break;
3227 }
3228
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003229 case Primitive::kPrimVoid:
3230 LOG(FATAL) << "Unreachable type " << field_type;
3231 UNREACHABLE();
3232 }
3233}
3234
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003235void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3236 LocationSummary* locations =
3237 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3238 locations->SetOut(Location::RequiresRegister());
3239}
3240
3241void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3242 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3243 codegen_->AddSlowPath(slow_path);
3244
Roland Levillain271ab9c2014-11-27 15:23:57 +00003245 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003246 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003247 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3248 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003249 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3250 __ cmp(out, ShifterOperand(0));
3251 __ b(slow_path->GetEntryLabel(), EQ);
3252 __ Bind(slow_path->GetExitLabel());
3253}
3254
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003255void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3256 LocationSummary* locations =
3257 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3258 locations->SetOut(Location::RequiresRegister());
3259}
3260
3261void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003262 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003263 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3264 __ LoadFromOffset(kLoadWord, out, TR, offset);
3265 __ LoadImmediate(IP, 0);
3266 __ StoreToOffset(kStoreWord, IP, TR, offset);
3267}
3268
3269void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3270 LocationSummary* locations =
3271 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3272 InvokeRuntimeCallingConvention calling_convention;
3273 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3274}
3275
3276void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3277 codegen_->InvokeRuntime(
3278 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3279}
3280
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003281void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003282 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3283 ? LocationSummary::kNoCall
3284 : LocationSummary::kCallOnSlowPath;
3285 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3286 locations->SetInAt(0, Location::RequiresRegister());
3287 locations->SetInAt(1, Location::RequiresRegister());
3288 locations->SetOut(Location::RequiresRegister());
3289}
3290
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003291void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003292 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003293 Register obj = locations->InAt(0).AsRegister<Register>();
3294 Register cls = locations->InAt(1).AsRegister<Register>();
3295 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003296 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3297 Label done, zero;
3298 SlowPathCodeARM* slow_path = nullptr;
3299
3300 // Return 0 if `obj` is null.
3301 // TODO: avoid this check if we know obj is not null.
3302 __ cmp(obj, ShifterOperand(0));
3303 __ b(&zero, EQ);
3304 // Compare the class of `obj` with `cls`.
3305 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3306 __ cmp(out, ShifterOperand(cls));
3307 if (instruction->IsClassFinal()) {
3308 // Classes must be equal for the instanceof to succeed.
3309 __ b(&zero, NE);
3310 __ LoadImmediate(out, 1);
3311 __ b(&done);
3312 } else {
3313 // If the classes are not equal, we go into a slow path.
3314 DCHECK(locations->OnlyCallsOnSlowPath());
3315 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003316 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003317 codegen_->AddSlowPath(slow_path);
3318 __ b(slow_path->GetEntryLabel(), NE);
3319 __ LoadImmediate(out, 1);
3320 __ b(&done);
3321 }
3322 __ Bind(&zero);
3323 __ LoadImmediate(out, 0);
3324 if (slow_path != nullptr) {
3325 __ Bind(slow_path->GetExitLabel());
3326 }
3327 __ Bind(&done);
3328}
3329
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003330void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3331 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3332 instruction, LocationSummary::kCallOnSlowPath);
3333 locations->SetInAt(0, Location::RequiresRegister());
3334 locations->SetInAt(1, Location::RequiresRegister());
3335 locations->AddTemp(Location::RequiresRegister());
3336}
3337
3338void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3339 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003340 Register obj = locations->InAt(0).AsRegister<Register>();
3341 Register cls = locations->InAt(1).AsRegister<Register>();
3342 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003343 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3344
3345 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3346 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3347 codegen_->AddSlowPath(slow_path);
3348
3349 // TODO: avoid this check if we know obj is not null.
3350 __ cmp(obj, ShifterOperand(0));
3351 __ b(slow_path->GetExitLabel(), EQ);
3352 // Compare the class of `obj` with `cls`.
3353 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3354 __ cmp(temp, ShifterOperand(cls));
3355 __ b(slow_path->GetEntryLabel(), NE);
3356 __ Bind(slow_path->GetExitLabel());
3357}
3358
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003359void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3360 LocationSummary* locations =
3361 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3362 InvokeRuntimeCallingConvention calling_convention;
3363 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3364}
3365
3366void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3367 codegen_->InvokeRuntime(instruction->IsEnter()
3368 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3369 instruction,
3370 instruction->GetDexPc());
3371}
3372
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003373void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3374void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3375void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3376
3377void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3378 LocationSummary* locations =
3379 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3380 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3381 || instruction->GetResultType() == Primitive::kPrimLong);
3382 locations->SetInAt(0, Location::RequiresRegister());
3383 locations->SetInAt(1, Location::RequiresRegister());
3384 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
3385 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3386}
3387
3388void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3389 HandleBitwiseOperation(instruction);
3390}
3391
3392void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3393 HandleBitwiseOperation(instruction);
3394}
3395
3396void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3397 HandleBitwiseOperation(instruction);
3398}
3399
3400void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3401 LocationSummary* locations = instruction->GetLocations();
3402
3403 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003404 Register first = locations->InAt(0).AsRegister<Register>();
3405 Register second = locations->InAt(1).AsRegister<Register>();
3406 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003407 if (instruction->IsAnd()) {
3408 __ and_(out, first, ShifterOperand(second));
3409 } else if (instruction->IsOr()) {
3410 __ orr(out, first, ShifterOperand(second));
3411 } else {
3412 DCHECK(instruction->IsXor());
3413 __ eor(out, first, ShifterOperand(second));
3414 }
3415 } else {
3416 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3417 Location first = locations->InAt(0);
3418 Location second = locations->InAt(1);
3419 Location out = locations->Out();
3420 if (instruction->IsAnd()) {
3421 __ and_(out.AsRegisterPairLow<Register>(),
3422 first.AsRegisterPairLow<Register>(),
3423 ShifterOperand(second.AsRegisterPairLow<Register>()));
3424 __ and_(out.AsRegisterPairHigh<Register>(),
3425 first.AsRegisterPairHigh<Register>(),
3426 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3427 } else if (instruction->IsOr()) {
3428 __ orr(out.AsRegisterPairLow<Register>(),
3429 first.AsRegisterPairLow<Register>(),
3430 ShifterOperand(second.AsRegisterPairLow<Register>()));
3431 __ orr(out.AsRegisterPairHigh<Register>(),
3432 first.AsRegisterPairHigh<Register>(),
3433 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3434 } else {
3435 DCHECK(instruction->IsXor());
3436 __ eor(out.AsRegisterPairLow<Register>(),
3437 first.AsRegisterPairLow<Register>(),
3438 ShifterOperand(second.AsRegisterPairLow<Register>()));
3439 __ eor(out.AsRegisterPairHigh<Register>(),
3440 first.AsRegisterPairHigh<Register>(),
3441 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3442 }
3443 }
3444}
3445
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003446} // namespace arm
3447} // namespace art