blob: f0506051ca39a54c88333383fee4b7c249418b20 [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);
Roland Levillain624279f2014-12-04 11:54:28 +000047static constexpr SRegister kRuntimeParameterFpuRegisters[] = { S0 };
48static constexpr size_t kRuntimeParameterFpuRegistersLength =
49 arraysize(kRuntimeParameterFpuRegisters);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010050
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000051class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010052 public:
53 InvokeRuntimeCallingConvention()
54 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010055 kRuntimeParameterCoreRegistersLength,
56 kRuntimeParameterFpuRegisters,
57 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010058
59 private:
60 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
61};
62
Nicolas Geoffraye5038322014-07-04 09:41:32 +010063#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010064#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010065
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010066class SlowPathCodeARM : public SlowPathCode {
67 public:
68 SlowPathCodeARM() : entry_label_(), exit_label_() {}
69
70 Label* GetEntryLabel() { return &entry_label_; }
71 Label* GetExitLabel() { return &exit_label_; }
72
73 private:
74 Label entry_label_;
75 Label exit_label_;
76
77 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM);
78};
79
80class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010081 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010082 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010083
Alexandre Rames67555f72014-11-18 10:55:16 +000084 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010085 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010086 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010087 arm_codegen->InvokeRuntime(
88 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010089 }
90
91 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010092 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010093 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
94};
95
Calin Juravled0d48522014-11-04 16:40:20 +000096class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
97 public:
98 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
99
Alexandre Rames67555f72014-11-18 10:55:16 +0000100 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +0000101 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
102 __ Bind(GetEntryLabel());
103 arm_codegen->InvokeRuntime(
104 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc());
105 }
106
107 private:
108 HDivZeroCheck* const instruction_;
109 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
110};
111
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100112class StackOverflowCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100113 public:
114 StackOverflowCheckSlowPathARM() {}
115
Alexandre Rames67555f72014-11-18 10:55:16 +0000116 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100117 __ Bind(GetEntryLabel());
118 __ LoadFromOffset(kLoadWord, PC, TR,
119 QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value());
120 }
121
122 private:
123 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM);
124};
125
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100126class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000127 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000128 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100129 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000130
Alexandre Rames67555f72014-11-18 10:55:16 +0000131 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100132 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000133 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100134 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100135 arm_codegen->InvokeRuntime(
136 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100137 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100138 if (successor_ == nullptr) {
139 __ b(GetReturnLabel());
140 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100141 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100142 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000143 }
144
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100145 Label* GetReturnLabel() {
146 DCHECK(successor_ == nullptr);
147 return &return_label_;
148 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000149
150 private:
151 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100152 // If not null, the block to branch to after the suspend check.
153 HBasicBlock* const successor_;
154
155 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000156 Label return_label_;
157
158 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
159};
160
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100161class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100162 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100163 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
164 Location index_location,
165 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100166 : instruction_(instruction),
167 index_location_(index_location),
168 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100169
Alexandre Rames67555f72014-11-18 10:55:16 +0000170 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100171 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100172 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000173 // We're moving two locations to locations that could overlap, so we need a parallel
174 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100175 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000176 codegen->EmitParallelMoves(
177 index_location_,
178 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
179 length_location_,
180 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100181 arm_codegen->InvokeRuntime(
182 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100183 }
184
185 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100186 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100187 const Location index_location_;
188 const Location length_location_;
189
190 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
191};
192
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000193class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100194 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000195 LoadClassSlowPathARM(HLoadClass* cls,
196 HInstruction* at,
197 uint32_t dex_pc,
198 bool do_clinit)
199 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
200 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
201 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100202
Alexandre Rames67555f72014-11-18 10:55:16 +0000203 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000204 LocationSummary* locations = at_->GetLocations();
205
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100206 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
207 __ Bind(GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000208 codegen->SaveLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100209
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100210 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000211 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100212 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000213 int32_t entry_point_offset = do_clinit_
214 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
215 : QUICK_ENTRY_POINT(pInitializeType);
216 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_);
217
218 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000219 Location out = locations->Out();
220 if (out.IsValid()) {
221 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000222 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
223 }
224 codegen->RestoreLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100225 __ b(GetExitLabel());
226 }
227
228 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000229 // The class this slow path will load.
230 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100231
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000232 // The instruction where this slow path is happening.
233 // (Might be the load class or an initialization check).
234 HInstruction* const at_;
235
236 // The dex PC of `at_`.
237 const uint32_t dex_pc_;
238
239 // Whether to initialize the class.
240 const bool do_clinit_;
241
242 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100243};
244
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000245class LoadStringSlowPathARM : public SlowPathCodeARM {
246 public:
247 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
248
Alexandre Rames67555f72014-11-18 10:55:16 +0000249 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000250 LocationSummary* locations = instruction_->GetLocations();
251 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
252
253 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
254 __ Bind(GetEntryLabel());
255 codegen->SaveLiveRegisters(locations);
256
257 InvokeRuntimeCallingConvention calling_convention;
258 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0));
259 __ LoadImmediate(calling_convention.GetRegisterAt(1), instruction_->GetStringIndex());
260 arm_codegen->InvokeRuntime(
261 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
262 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
263
264 codegen->RestoreLiveRegisters(locations);
265 __ b(GetExitLabel());
266 }
267
268 private:
269 HLoadString* const instruction_;
270
271 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
272};
273
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000274class TypeCheckSlowPathARM : public SlowPathCodeARM {
275 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000276 TypeCheckSlowPathARM(HInstruction* instruction,
277 Location class_to_check,
278 Location object_class,
279 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000280 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000281 class_to_check_(class_to_check),
282 object_class_(object_class),
283 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000284
Alexandre Rames67555f72014-11-18 10:55:16 +0000285 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000286 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000287 DCHECK(instruction_->IsCheckCast()
288 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000289
290 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
291 __ Bind(GetEntryLabel());
292 codegen->SaveLiveRegisters(locations);
293
294 // We're moving two locations to locations that could overlap, so we need a parallel
295 // move resolver.
296 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000297 codegen->EmitParallelMoves(
298 class_to_check_,
299 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
300 object_class_,
301 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000302
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000303 if (instruction_->IsInstanceOf()) {
304 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_);
305 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
306 } else {
307 DCHECK(instruction_->IsCheckCast());
308 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_);
309 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000310
311 codegen->RestoreLiveRegisters(locations);
312 __ b(GetExitLabel());
313 }
314
315 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000316 HInstruction* const instruction_;
317 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000318 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000319 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000320
321 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
322};
323
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000324#undef __
325
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100326#undef __
327#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700328
329inline Condition ARMCondition(IfCondition cond) {
330 switch (cond) {
331 case kCondEQ: return EQ;
332 case kCondNE: return NE;
333 case kCondLT: return LT;
334 case kCondLE: return LE;
335 case kCondGT: return GT;
336 case kCondGE: return GE;
337 default:
338 LOG(FATAL) << "Unknown if condition";
339 }
340 return EQ; // Unreachable.
341}
342
343inline Condition ARMOppositeCondition(IfCondition cond) {
344 switch (cond) {
345 case kCondEQ: return NE;
346 case kCondNE: return EQ;
347 case kCondLT: return GE;
348 case kCondLE: return GT;
349 case kCondGT: return LE;
350 case kCondGE: return LT;
351 default:
352 LOG(FATAL) << "Unknown if condition";
353 }
354 return EQ; // Unreachable.
355}
356
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100357void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
358 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
359}
360
361void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000362 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100363}
364
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100365size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
366 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
367 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100368}
369
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100370size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
371 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
372 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100373}
374
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100375CodeGeneratorARM::CodeGeneratorARM(HGraph* graph)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000376 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100377 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100378 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100379 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100380 move_resolver_(graph->GetArena(), this),
381 assembler_(true) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100382
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100383size_t CodeGeneratorARM::FrameEntrySpillSize() const {
384 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
385}
386
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100387Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100388 switch (type) {
389 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100390 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100391 ArmManagedRegister pair =
392 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100393 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
394 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
395
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100396 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
397 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100398 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100399 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100400 }
401
402 case Primitive::kPrimByte:
403 case Primitive::kPrimBoolean:
404 case Primitive::kPrimChar:
405 case Primitive::kPrimShort:
406 case Primitive::kPrimInt:
407 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100408 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100409 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100410 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
411 ArmManagedRegister current =
412 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
413 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100414 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100415 }
416 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100417 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100418 }
419
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000420 case Primitive::kPrimFloat: {
421 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100422 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100423 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100424
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000425 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000426 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
427 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000428 return Location::FpuRegisterPairLocation(reg, reg + 1);
429 }
430
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100431 case Primitive::kPrimVoid:
432 LOG(FATAL) << "Unreachable type " << type;
433 }
434
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100435 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100436}
437
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100438void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100439 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100440 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100441
442 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100443 blocked_core_registers_[SP] = true;
444 blocked_core_registers_[LR] = true;
445 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100446
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100447 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100448 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100449
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100450 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100451 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100452
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100453 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100454 // We always save and restore R6 and R7 to make sure we can use three
455 // register pairs for long operations.
Nicolas Geoffray44b819e2014-11-06 12:00:54 +0000456 blocked_core_registers_[R4] = true;
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100457 blocked_core_registers_[R5] = true;
458 blocked_core_registers_[R8] = true;
459 blocked_core_registers_[R10] = true;
460 blocked_core_registers_[R11] = true;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100461
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000462 blocked_fpu_registers_[S16] = true;
463 blocked_fpu_registers_[S17] = true;
464 blocked_fpu_registers_[S18] = true;
465 blocked_fpu_registers_[S19] = true;
466 blocked_fpu_registers_[S20] = true;
467 blocked_fpu_registers_[S21] = true;
468 blocked_fpu_registers_[S22] = true;
469 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000470 blocked_fpu_registers_[S24] = true;
471 blocked_fpu_registers_[S25] = true;
472 blocked_fpu_registers_[S26] = true;
473 blocked_fpu_registers_[S27] = true;
474 blocked_fpu_registers_[S28] = true;
475 blocked_fpu_registers_[S29] = true;
476 blocked_fpu_registers_[S30] = true;
477 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100478
479 UpdateBlockedPairRegisters();
480}
481
482void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
483 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
484 ArmManagedRegister current =
485 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
486 if (blocked_core_registers_[current.AsRegisterPairLow()]
487 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
488 blocked_register_pairs_[i] = true;
489 }
490 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100491}
492
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100493InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
494 : HGraphVisitor(graph),
495 assembler_(codegen->GetAssembler()),
496 codegen_(codegen) {}
497
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000498void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000499 bool skip_overflow_check =
500 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100501 if (!skip_overflow_check) {
502 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100503 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100504 AddSlowPath(slow_path);
505
506 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
507 __ cmp(SP, ShifterOperand(IP));
508 __ b(slow_path->GetEntryLabel(), CC);
509 } else {
510 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100511 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100512 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100513 }
514 }
515
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100516 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
517 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000518
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100519 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100520 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100521 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000522}
523
524void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100525 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100526 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000527}
528
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100529void CodeGeneratorARM::Bind(HBasicBlock* block) {
530 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000531}
532
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100533Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
534 switch (load->GetType()) {
535 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100536 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100537 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
538 break;
539
540 case Primitive::kPrimInt:
541 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100542 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100543 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100544
545 case Primitive::kPrimBoolean:
546 case Primitive::kPrimByte:
547 case Primitive::kPrimChar:
548 case Primitive::kPrimShort:
549 case Primitive::kPrimVoid:
550 LOG(FATAL) << "Unexpected type " << load->GetType();
551 }
552
553 LOG(FATAL) << "Unreachable";
554 return Location();
555}
556
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100557Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
558 switch (type) {
559 case Primitive::kPrimBoolean:
560 case Primitive::kPrimByte:
561 case Primitive::kPrimChar:
562 case Primitive::kPrimShort:
563 case Primitive::kPrimInt:
564 case Primitive::kPrimNot: {
565 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000566 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100567 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100568 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100569 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000570 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100571 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100572 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100573
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000574 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100575 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000576 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100577 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000578 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100579 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100580 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
581 calling_convention.GetRegisterPairAt(index));
582 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100583 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000584 return Location::QuickParameter(index, stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100585 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000586 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
587 }
588 }
589
590 case Primitive::kPrimFloat: {
591 uint32_t stack_index = stack_index_++;
592 if (float_index_ % 2 == 0) {
593 float_index_ = std::max(double_index_, float_index_);
594 }
595 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
596 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
597 } else {
598 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
599 }
600 }
601
602 case Primitive::kPrimDouble: {
603 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
604 uint32_t stack_index = stack_index_;
605 stack_index_ += 2;
606 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
607 uint32_t index = double_index_;
608 double_index_ += 2;
609 return Location::FpuRegisterPairLocation(
610 calling_convention.GetFpuRegisterAt(index),
611 calling_convention.GetFpuRegisterAt(index + 1));
612 } else {
613 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100614 }
615 }
616
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100617 case Primitive::kPrimVoid:
618 LOG(FATAL) << "Unexpected parameter type " << type;
619 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100620 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100621 return Location();
622}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100623
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000624Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
625 switch (type) {
626 case Primitive::kPrimBoolean:
627 case Primitive::kPrimByte:
628 case Primitive::kPrimChar:
629 case Primitive::kPrimShort:
630 case Primitive::kPrimInt:
631 case Primitive::kPrimNot: {
632 return Location::RegisterLocation(R0);
633 }
634
635 case Primitive::kPrimFloat: {
636 return Location::FpuRegisterLocation(S0);
637 }
638
639 case Primitive::kPrimLong: {
640 return Location::RegisterPairLocation(R0, R1);
641 }
642
643 case Primitive::kPrimDouble: {
644 return Location::FpuRegisterPairLocation(S0, S1);
645 }
646
647 case Primitive::kPrimVoid:
648 return Location();
649 }
650 UNREACHABLE();
651 return Location();
652}
653
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100654void CodeGeneratorARM::Move32(Location destination, Location source) {
655 if (source.Equals(destination)) {
656 return;
657 }
658 if (destination.IsRegister()) {
659 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000660 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100661 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000662 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100663 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000664 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100665 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100666 } else if (destination.IsFpuRegister()) {
667 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000668 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100669 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000670 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100671 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000672 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100673 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100674 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000675 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100676 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000677 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100678 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000679 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100680 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000681 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100682 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
683 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100684 }
685 }
686}
687
688void CodeGeneratorARM::Move64(Location destination, Location source) {
689 if (source.Equals(destination)) {
690 return;
691 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100692 if (destination.IsRegisterPair()) {
693 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000694 EmitParallelMoves(
695 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
696 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
697 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
698 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100699 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000700 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100701 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000702 uint16_t register_index = source.GetQuickParameterRegisterIndex();
703 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100704 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000705 EmitParallelMoves(
706 Location::RegisterLocation(calling_convention.GetRegisterAt(register_index)),
707 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
708 Location::StackSlot(
709 calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize()),
710 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100711 } else {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000712 // No conflict possible, so just do the moves.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100713 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100714 if (destination.AsRegisterPairLow<Register>() == R1) {
715 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100716 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
717 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100718 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100719 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100720 SP, source.GetStackIndex());
721 }
722 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000723 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100724 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000725 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
726 SP,
727 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100728 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000729 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100730 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100731 } else if (destination.IsQuickParameter()) {
732 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000733 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
734 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100735 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000736 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100737 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000738 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100739 } else {
740 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000741 EmitParallelMoves(
742 Location::StackSlot(source.GetStackIndex()),
743 Location::RegisterLocation(calling_convention.GetRegisterAt(register_index)),
744 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
745 Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index + 1)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100746 }
747 } else {
748 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100749 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000750 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100751 if (source.AsRegisterPairLow<Register>() == R1) {
752 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100753 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
754 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100755 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100756 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100757 SP, destination.GetStackIndex());
758 }
759 } else if (source.IsQuickParameter()) {
760 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000761 uint16_t register_index = source.GetQuickParameterRegisterIndex();
762 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000763 // Just move the low part. The only time a source is a quick parameter is
764 // when moving the parameter to its stack locations. And the (Java) caller
765 // of this method has already done that.
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000766 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000767 SP, destination.GetStackIndex());
768 DCHECK_EQ(calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize(),
769 static_cast<size_t>(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000770 } else if (source.IsFpuRegisterPair()) {
771 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
772 SP,
773 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100774 } else {
775 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000776 EmitParallelMoves(
777 Location::StackSlot(source.GetStackIndex()),
778 Location::StackSlot(destination.GetStackIndex()),
779 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
780 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100781 }
782 }
783}
784
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100785void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100786 LocationSummary* locations = instruction->GetLocations();
787 if (locations != nullptr && locations->Out().Equals(location)) {
788 return;
789 }
790
Calin Juravlea21f5982014-11-13 15:53:04 +0000791 if (locations != nullptr && locations->Out().IsConstant()) {
792 HConstant* const_to_move = locations->Out().GetConstant();
793 if (const_to_move->IsIntConstant()) {
794 int32_t value = const_to_move->AsIntConstant()->GetValue();
795 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000796 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000797 } else {
798 DCHECK(location.IsStackSlot());
799 __ LoadImmediate(IP, value);
800 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
801 }
802 } else if (const_to_move->IsLongConstant()) {
803 int64_t value = const_to_move->AsLongConstant()->GetValue();
804 if (location.IsRegisterPair()) {
805 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
806 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
807 } else {
808 DCHECK(location.IsDoubleStackSlot());
809 __ LoadImmediate(IP, Low32Bits(value));
810 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
811 __ LoadImmediate(IP, High32Bits(value));
812 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
813 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100814 }
Roland Levillain476df552014-10-09 17:51:36 +0100815 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100816 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
817 switch (instruction->GetType()) {
818 case Primitive::kPrimBoolean:
819 case Primitive::kPrimByte:
820 case Primitive::kPrimChar:
821 case Primitive::kPrimShort:
822 case Primitive::kPrimInt:
823 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100824 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100825 Move32(location, Location::StackSlot(stack_slot));
826 break;
827
828 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100829 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100830 Move64(location, Location::DoubleStackSlot(stack_slot));
831 break;
832
833 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100834 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100835 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000836 } else if (instruction->IsTemporary()) {
837 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000838 if (temp_location.IsStackSlot()) {
839 Move32(location, temp_location);
840 } else {
841 DCHECK(temp_location.IsDoubleStackSlot());
842 Move64(location, temp_location);
843 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000844 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100845 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100846 switch (instruction->GetType()) {
847 case Primitive::kPrimBoolean:
848 case Primitive::kPrimByte:
849 case Primitive::kPrimChar:
850 case Primitive::kPrimShort:
851 case Primitive::kPrimNot:
852 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100853 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100854 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100855 break;
856
857 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100858 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100859 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100860 break;
861
862 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100863 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100864 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000865 }
866}
867
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100868void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
869 HInstruction* instruction,
870 uint32_t dex_pc) {
871 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
872 __ blx(LR);
873 RecordPcInfo(instruction, dex_pc);
874 DCHECK(instruction->IsSuspendCheck()
875 || instruction->IsBoundsCheck()
876 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000877 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000878 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100879 || !IsLeafMethod());
880}
881
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000882void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000883 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000884}
885
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000886void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000887 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100888 DCHECK(!successor->IsExitBlock());
889
890 HBasicBlock* block = got->GetBlock();
891 HInstruction* previous = got->GetPrevious();
892
893 HLoopInformation* info = block->GetLoopInformation();
894 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
895 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
896 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
897 return;
898 }
899
900 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
901 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
902 }
903 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000904 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000905 }
906}
907
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000908void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000909 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000910}
911
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000912void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700913 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000914 if (kIsDebugBuild) {
915 __ Comment("Unreachable");
916 __ bkpt(0);
917 }
918}
919
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000920void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100921 LocationSummary* locations =
922 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100923 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100924 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100925 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100926 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000927}
928
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000929void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700930 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100931 if (cond->IsIntConstant()) {
932 // Constant condition, statically compared against 1.
933 int32_t cond_value = cond->AsIntConstant()->GetValue();
934 if (cond_value == 1) {
935 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
936 if_instr->IfTrueSuccessor())) {
937 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100938 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100939 return;
940 } else {
941 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100942 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100943 } else {
944 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
945 // Condition has been materialized, compare the output to 0
946 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000947 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100948 ShifterOperand(0));
949 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
950 } else {
951 // Condition has not been materialized, use its inputs as the
952 // comparison and its condition as the branch condition.
953 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000954 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100955 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000956 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100957 } else {
958 DCHECK(locations->InAt(1).IsConstant());
959 int32_t value =
960 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
961 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000962 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
963 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100964 } else {
965 Register temp = IP;
966 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000967 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100968 }
969 }
970 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
971 ARMCondition(cond->AsCondition()->GetCondition()));
972 }
Dave Allison20dfc792014-06-16 20:44:29 -0700973 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100974 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
975 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700976 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000977 }
978}
979
Dave Allison20dfc792014-06-16 20:44:29 -0700980
981void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100982 LocationSummary* locations =
983 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100984 locations->SetInAt(0, Location::RequiresRegister());
985 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100986 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100987 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100988 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000989}
990
Dave Allison20dfc792014-06-16 20:44:29 -0700991void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100992 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100993 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000994 Register left = locations->InAt(0).AsRegister<Register>();
995
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100996 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000997 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100998 } else {
999 DCHECK(locations->InAt(1).IsConstant());
1000 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
1001 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001002 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1003 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001004 } else {
1005 Register temp = IP;
1006 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001007 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001008 }
Dave Allison20dfc792014-06-16 20:44:29 -07001009 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001010 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001011 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001012 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001013 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001014 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001015}
1016
1017void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1018 VisitCondition(comp);
1019}
1020
1021void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1022 VisitCondition(comp);
1023}
1024
1025void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1026 VisitCondition(comp);
1027}
1028
1029void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1030 VisitCondition(comp);
1031}
1032
1033void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1034 VisitCondition(comp);
1035}
1036
1037void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1038 VisitCondition(comp);
1039}
1040
1041void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1042 VisitCondition(comp);
1043}
1044
1045void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1046 VisitCondition(comp);
1047}
1048
1049void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1050 VisitCondition(comp);
1051}
1052
1053void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1054 VisitCondition(comp);
1055}
1056
1057void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1058 VisitCondition(comp);
1059}
1060
1061void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1062 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001063}
1064
1065void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001066 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001067}
1068
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001069void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1070 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001071}
1072
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001073void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001074 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001075}
1076
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001077void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001078 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001079 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001080}
1081
1082void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001083 LocationSummary* locations =
1084 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001085 switch (store->InputAt(1)->GetType()) {
1086 case Primitive::kPrimBoolean:
1087 case Primitive::kPrimByte:
1088 case Primitive::kPrimChar:
1089 case Primitive::kPrimShort:
1090 case Primitive::kPrimInt:
1091 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001092 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001093 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1094 break;
1095
1096 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001097 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001098 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1099 break;
1100
1101 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001102 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001103 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001104}
1105
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001106void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001107 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001108}
1109
1110void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001111 LocationSummary* locations =
1112 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001113 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001114}
1115
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001116void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001117 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001118 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001119}
1120
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001121void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001122 LocationSummary* locations =
1123 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001124 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001125}
1126
1127void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1128 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001129 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001130}
1131
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001132void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1133 LocationSummary* locations =
1134 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1135 locations->SetOut(Location::ConstantLocation(constant));
1136}
1137
1138void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1139 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001140 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001141}
1142
1143void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1144 LocationSummary* locations =
1145 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1146 locations->SetOut(Location::ConstantLocation(constant));
1147}
1148
1149void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1150 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001151 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001152}
1153
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001154void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001155 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001156}
1157
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001158void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001159 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001160 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001161}
1162
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001163void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001164 LocationSummary* locations =
1165 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001166 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001167}
1168
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001169void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001170 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001171 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001172}
1173
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001174void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001175 HandleInvoke(invoke);
1176}
1177
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001178void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001179 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001180}
1181
1182void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001183 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001184
1185 // TODO: Implement all kinds of calls:
1186 // 1) boot -> boot
1187 // 2) app -> boot
1188 // 3) app -> app
1189 //
1190 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1191
1192 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001193 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001194 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001195 __ LoadFromOffset(
1196 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001197 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001198 __ LoadFromOffset(
1199 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001200 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001201 __ LoadFromOffset(kLoadWord, LR, temp,
Mathieu Chartier2d721012014-11-10 11:08:06 -08001202 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001203 kArmWordSize).Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001204 // LR()
1205 __ blx(LR);
1206
1207 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1208 DCHECK(!codegen_->IsLeafMethod());
1209}
1210
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001211void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001212 LocationSummary* locations =
1213 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001214 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001215
1216 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001217 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001218 HInstruction* input = invoke->InputAt(i);
1219 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1220 }
1221
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001222 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001223}
1224
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001225void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1226 HandleInvoke(invoke);
1227}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001228
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001229void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001230 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001231 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1232 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1233 LocationSummary* locations = invoke->GetLocations();
1234 Location receiver = locations->InAt(0);
1235 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1236 // temp = object->GetClass();
1237 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001238 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1239 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001240 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001241 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001242 }
1243 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001244 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001245 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001246 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001247 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001248 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001249 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001250 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001251 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001252 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001253}
1254
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001255void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1256 HandleInvoke(invoke);
1257 // Add the hidden argument.
1258 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1259}
1260
1261void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1262 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001263 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001264 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1265 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1266 LocationSummary* locations = invoke->GetLocations();
1267 Location receiver = locations->InAt(0);
1268 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1269
1270 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001271 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1272 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001273
1274 // temp = object->GetClass();
1275 if (receiver.IsStackSlot()) {
1276 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1277 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1278 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001279 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001280 }
1281 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001282 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001283 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001284 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1285 // LR = temp->GetEntryPoint();
1286 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1287 // LR();
1288 __ blx(LR);
1289 DCHECK(!codegen_->IsLeafMethod());
1290 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1291}
1292
Roland Levillain88cb1752014-10-20 16:36:47 +01001293void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1294 LocationSummary* locations =
1295 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1296 switch (neg->GetResultType()) {
1297 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001298 case Primitive::kPrimLong: {
1299 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001300 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001301 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001302 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001303 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001304
Roland Levillain88cb1752014-10-20 16:36:47 +01001305 case Primitive::kPrimFloat:
1306 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001307 locations->SetInAt(0, Location::RequiresFpuRegister());
1308 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001309 break;
1310
1311 default:
1312 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1313 }
1314}
1315
1316void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1317 LocationSummary* locations = neg->GetLocations();
1318 Location out = locations->Out();
1319 Location in = locations->InAt(0);
1320 switch (neg->GetResultType()) {
1321 case Primitive::kPrimInt:
1322 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001323 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001324 break;
1325
1326 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001327 DCHECK(in.IsRegisterPair());
1328 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1329 __ rsbs(out.AsRegisterPairLow<Register>(),
1330 in.AsRegisterPairLow<Register>(),
1331 ShifterOperand(0));
1332 // We cannot emit an RSC (Reverse Subtract with Carry)
1333 // instruction here, as it does not exist in the Thumb-2
1334 // instruction set. We use the following approach
1335 // using SBC and SUB instead.
1336 //
1337 // out.hi = -C
1338 __ sbc(out.AsRegisterPairHigh<Register>(),
1339 out.AsRegisterPairHigh<Register>(),
1340 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1341 // out.hi = out.hi - in.hi
1342 __ sub(out.AsRegisterPairHigh<Register>(),
1343 out.AsRegisterPairHigh<Register>(),
1344 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1345 break;
1346
Roland Levillain88cb1752014-10-20 16:36:47 +01001347 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001348 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001349 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001350 break;
1351
Roland Levillain88cb1752014-10-20 16:36:47 +01001352 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001353 DCHECK(in.IsFpuRegisterPair());
1354 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1355 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001356 break;
1357
1358 default:
1359 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1360 }
1361}
1362
Roland Levillaindff1f282014-11-05 14:15:05 +00001363void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001364 Primitive::Type result_type = conversion->GetResultType();
1365 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001366 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001367
1368 // Float-to-long conversions invoke the runtime.
1369 LocationSummary::CallKind call_kind =
1370 (input_type == Primitive::kPrimFloat && result_type == Primitive::kPrimLong)
1371 ? LocationSummary::kCall
1372 : LocationSummary::kNoCall;
1373 LocationSummary* locations =
1374 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1375
Roland Levillaindff1f282014-11-05 14:15:05 +00001376 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001377 case Primitive::kPrimByte:
1378 switch (input_type) {
1379 case Primitive::kPrimShort:
1380 case Primitive::kPrimInt:
1381 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001382 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001383 locations->SetInAt(0, Location::RequiresRegister());
1384 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1385 break;
1386
1387 default:
1388 LOG(FATAL) << "Unexpected type conversion from " << input_type
1389 << " to " << result_type;
1390 }
1391 break;
1392
Roland Levillain01a8d712014-11-14 16:27:39 +00001393 case Primitive::kPrimShort:
1394 switch (input_type) {
1395 case Primitive::kPrimByte:
1396 case Primitive::kPrimInt:
1397 case Primitive::kPrimChar:
1398 // Processing a Dex `int-to-short' instruction.
1399 locations->SetInAt(0, Location::RequiresRegister());
1400 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1401 break;
1402
1403 default:
1404 LOG(FATAL) << "Unexpected type conversion from " << input_type
1405 << " to " << result_type;
1406 }
1407 break;
1408
Roland Levillain946e1432014-11-11 17:35:19 +00001409 case Primitive::kPrimInt:
1410 switch (input_type) {
1411 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001412 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001413 locations->SetInAt(0, Location::Any());
1414 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1415 break;
1416
1417 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001418 // Processing a Dex `float-to-int' instruction.
1419 locations->SetInAt(0, Location::RequiresFpuRegister());
1420 locations->SetOut(Location::RequiresRegister());
1421 locations->AddTemp(Location::RequiresFpuRegister());
1422 break;
1423
Roland Levillain946e1432014-11-11 17:35:19 +00001424 case Primitive::kPrimDouble:
1425 LOG(FATAL) << "Type conversion from " << input_type
1426 << " to " << result_type << " not yet implemented";
1427 break;
1428
1429 default:
1430 LOG(FATAL) << "Unexpected type conversion from " << input_type
1431 << " to " << result_type;
1432 }
1433 break;
1434
Roland Levillaindff1f282014-11-05 14:15:05 +00001435 case Primitive::kPrimLong:
1436 switch (input_type) {
1437 case Primitive::kPrimByte:
1438 case Primitive::kPrimShort:
1439 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001440 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001441 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001442 locations->SetInAt(0, Location::RequiresRegister());
1443 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1444 break;
1445
Roland Levillain624279f2014-12-04 11:54:28 +00001446 case Primitive::kPrimFloat: {
1447 // Processing a Dex `float-to-long' instruction.
1448 InvokeRuntimeCallingConvention calling_convention;
1449 locations->SetInAt(0, Location::FpuRegisterLocation(
1450 calling_convention.GetFpuRegisterAt(0)));
1451 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1452 break;
1453 }
1454
Roland Levillaindff1f282014-11-05 14:15:05 +00001455 case Primitive::kPrimDouble:
1456 LOG(FATAL) << "Type conversion from " << input_type << " to "
1457 << result_type << " not yet implemented";
1458 break;
1459
1460 default:
1461 LOG(FATAL) << "Unexpected type conversion from " << input_type
1462 << " to " << result_type;
1463 }
1464 break;
1465
Roland Levillain981e4542014-11-14 11:47:14 +00001466 case Primitive::kPrimChar:
1467 switch (input_type) {
1468 case Primitive::kPrimByte:
1469 case Primitive::kPrimShort:
1470 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001471 // Processing a Dex `int-to-char' instruction.
1472 locations->SetInAt(0, Location::RequiresRegister());
1473 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
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::kPrimFloat:
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-float' instruction.
1489 locations->SetInAt(0, Location::RequiresRegister());
1490 locations->SetOut(Location::RequiresFpuRegister());
1491 break;
1492
1493 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001494 // Processing a Dex `long-to-float' 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 locations->AddTemp(Location::RequiresFpuRegister());
1501 break;
1502
Roland Levillaincff13742014-11-17 14:32:17 +00001503 case Primitive::kPrimDouble:
1504 LOG(FATAL) << "Type conversion from " << input_type
1505 << " to " << result_type << " not yet implemented";
1506 break;
1507
1508 default:
1509 LOG(FATAL) << "Unexpected type conversion from " << input_type
1510 << " to " << result_type;
1511 };
1512 break;
1513
Roland Levillaindff1f282014-11-05 14:15:05 +00001514 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001515 switch (input_type) {
1516 case Primitive::kPrimByte:
1517 case Primitive::kPrimShort:
1518 case Primitive::kPrimInt:
1519 case Primitive::kPrimChar:
1520 // Processing a Dex `int-to-double' instruction.
1521 locations->SetInAt(0, Location::RequiresRegister());
1522 locations->SetOut(Location::RequiresFpuRegister());
1523 break;
1524
1525 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001526 // Processing a Dex `long-to-double' instruction.
1527 locations->SetInAt(0, Location::RequiresRegister());
1528 locations->SetOut(Location::RequiresFpuRegister());
1529 locations->AddTemp(Location::RequiresRegister());
1530 locations->AddTemp(Location::RequiresRegister());
1531 locations->AddTemp(Location::RequiresFpuRegister());
1532 break;
1533
Roland Levillaincff13742014-11-17 14:32:17 +00001534 case Primitive::kPrimFloat:
1535 LOG(FATAL) << "Type conversion from " << input_type
1536 << " to " << result_type << " not yet implemented";
1537 break;
1538
1539 default:
1540 LOG(FATAL) << "Unexpected type conversion from " << input_type
1541 << " to " << result_type;
1542 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001543 break;
1544
1545 default:
1546 LOG(FATAL) << "Unexpected type conversion from " << input_type
1547 << " to " << result_type;
1548 }
1549}
1550
1551void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1552 LocationSummary* locations = conversion->GetLocations();
1553 Location out = locations->Out();
1554 Location in = locations->InAt(0);
1555 Primitive::Type result_type = conversion->GetResultType();
1556 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001557 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001558 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001559 case Primitive::kPrimByte:
1560 switch (input_type) {
1561 case Primitive::kPrimShort:
1562 case Primitive::kPrimInt:
1563 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001564 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001565 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001566 break;
1567
1568 default:
1569 LOG(FATAL) << "Unexpected type conversion from " << input_type
1570 << " to " << result_type;
1571 }
1572 break;
1573
Roland Levillain01a8d712014-11-14 16:27:39 +00001574 case Primitive::kPrimShort:
1575 switch (input_type) {
1576 case Primitive::kPrimByte:
1577 case Primitive::kPrimInt:
1578 case Primitive::kPrimChar:
1579 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001580 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001581 break;
1582
1583 default:
1584 LOG(FATAL) << "Unexpected type conversion from " << input_type
1585 << " to " << result_type;
1586 }
1587 break;
1588
Roland Levillain946e1432014-11-11 17:35:19 +00001589 case Primitive::kPrimInt:
1590 switch (input_type) {
1591 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001592 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001593 DCHECK(out.IsRegister());
1594 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001595 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001596 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001597 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001598 } else {
1599 DCHECK(in.IsConstant());
1600 DCHECK(in.GetConstant()->IsLongConstant());
1601 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001602 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001603 }
1604 break;
1605
Roland Levillain3f8f9362014-12-02 17:45:01 +00001606 case Primitive::kPrimFloat: {
1607 // Processing a Dex `float-to-int' instruction.
1608 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1609 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1610 __ vcvtis(temp, temp);
1611 __ vmovrs(out.AsRegister<Register>(), temp);
1612 break;
1613 }
1614
Roland Levillain946e1432014-11-11 17:35:19 +00001615 case Primitive::kPrimDouble:
1616 LOG(FATAL) << "Type conversion from " << input_type
1617 << " to " << result_type << " not yet implemented";
1618 break;
1619
1620 default:
1621 LOG(FATAL) << "Unexpected type conversion from " << input_type
1622 << " to " << result_type;
1623 }
1624 break;
1625
Roland Levillaindff1f282014-11-05 14:15:05 +00001626 case Primitive::kPrimLong:
1627 switch (input_type) {
1628 case Primitive::kPrimByte:
1629 case Primitive::kPrimShort:
1630 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001631 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001632 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001633 DCHECK(out.IsRegisterPair());
1634 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001635 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001636 // Sign extension.
1637 __ Asr(out.AsRegisterPairHigh<Register>(),
1638 out.AsRegisterPairLow<Register>(),
1639 31);
1640 break;
1641
1642 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001643 // Processing a Dex `float-to-long' instruction.
1644 // This call does not actually record PC information.
1645 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1646 conversion,
1647 conversion->GetDexPc());
1648 break;
1649
Roland Levillaindff1f282014-11-05 14:15:05 +00001650 case Primitive::kPrimDouble:
1651 LOG(FATAL) << "Type conversion from " << input_type << " to "
1652 << result_type << " not yet implemented";
1653 break;
1654
1655 default:
1656 LOG(FATAL) << "Unexpected type conversion from " << input_type
1657 << " to " << result_type;
1658 }
1659 break;
1660
Roland Levillain981e4542014-11-14 11:47:14 +00001661 case Primitive::kPrimChar:
1662 switch (input_type) {
1663 case Primitive::kPrimByte:
1664 case Primitive::kPrimShort:
1665 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001666 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001667 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001668 break;
1669
1670 default:
1671 LOG(FATAL) << "Unexpected type conversion from " << input_type
1672 << " to " << result_type;
1673 }
1674 break;
1675
Roland Levillaindff1f282014-11-05 14:15:05 +00001676 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001677 switch (input_type) {
1678 case Primitive::kPrimByte:
1679 case Primitive::kPrimShort:
1680 case Primitive::kPrimInt:
1681 case Primitive::kPrimChar: {
1682 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001683 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1684 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001685 break;
1686 }
1687
Roland Levillain6d0e4832014-11-27 18:31:21 +00001688 case Primitive::kPrimLong: {
1689 // Processing a Dex `long-to-float' instruction.
1690 Register low = in.AsRegisterPairLow<Register>();
1691 Register high = in.AsRegisterPairHigh<Register>();
1692 SRegister output = out.AsFpuRegister<SRegister>();
1693 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1694 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1695 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1696 DRegister temp1_d = FromLowSToD(temp1_s);
1697 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1698 DRegister temp2_d = FromLowSToD(temp2_s);
1699
1700 // Operations use doubles for precision reasons (each 32-bit
1701 // half of a long fits in the 53-bit mantissa of a double,
1702 // but not in the 24-bit mantissa of a float). This is
1703 // especially important for the low bits. The result is
1704 // eventually converted to float.
1705
1706 // temp1_d = int-to-double(high)
1707 __ vmovsr(temp1_s, high);
1708 __ vcvtdi(temp1_d, temp1_s);
1709 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1710 // as an immediate value into `temp2_d` does not work, as
1711 // this instruction only transfers 8 significant bits of its
1712 // immediate operand. Instead, use two 32-bit core
1713 // registers to load `k2Pow32EncodingForDouble` into
1714 // `temp2_d`.
1715 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1716 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1717 __ vmovdrr(temp2_d, constant_low, constant_high);
1718 // temp1_d = temp1_d * 2^32
1719 __ vmuld(temp1_d, temp1_d, temp2_d);
1720 // temp2_d = unsigned-to-double(low)
1721 __ vmovsr(temp2_s, low);
1722 __ vcvtdu(temp2_d, temp2_s);
1723 // temp1_d = temp1_d + temp2_d
1724 __ vaddd(temp1_d, temp1_d, temp2_d);
1725 // output = double-to-float(temp1_d);
1726 __ vcvtsd(output, temp1_d);
1727 break;
1728 }
1729
Roland Levillaincff13742014-11-17 14:32:17 +00001730 case Primitive::kPrimDouble:
1731 LOG(FATAL) << "Type conversion from " << input_type
1732 << " to " << result_type << " not yet implemented";
1733 break;
1734
1735 default:
1736 LOG(FATAL) << "Unexpected type conversion from " << input_type
1737 << " to " << result_type;
1738 };
1739 break;
1740
Roland Levillaindff1f282014-11-05 14:15:05 +00001741 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001742 switch (input_type) {
1743 case Primitive::kPrimByte:
1744 case Primitive::kPrimShort:
1745 case Primitive::kPrimInt:
1746 case Primitive::kPrimChar: {
1747 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001748 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001749 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1750 out.AsFpuRegisterPairLow<SRegister>());
1751 break;
1752 }
1753
Roland Levillain647b9ed2014-11-27 12:06:00 +00001754 case Primitive::kPrimLong: {
1755 // Processing a Dex `long-to-double' instruction.
1756 Register low = in.AsRegisterPairLow<Register>();
1757 Register high = in.AsRegisterPairHigh<Register>();
1758 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1759 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001760 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1761 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001762 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1763 DRegister temp_d = FromLowSToD(temp_s);
1764
Roland Levillain647b9ed2014-11-27 12:06:00 +00001765 // out_d = int-to-double(high)
1766 __ vmovsr(out_s, high);
1767 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001768 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1769 // as an immediate value into `temp_d` does not work, as
1770 // this instruction only transfers 8 significant bits of its
1771 // immediate operand. Instead, use two 32-bit core
1772 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1773 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1774 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001775 __ vmovdrr(temp_d, constant_low, constant_high);
1776 // out_d = out_d * 2^32
1777 __ vmuld(out_d, out_d, temp_d);
1778 // temp_d = unsigned-to-double(low)
1779 __ vmovsr(temp_s, low);
1780 __ vcvtdu(temp_d, temp_s);
1781 // out_d = out_d + temp_d
1782 __ vaddd(out_d, out_d, temp_d);
1783 break;
1784 }
1785
Roland Levillaincff13742014-11-17 14:32:17 +00001786 case Primitive::kPrimFloat:
1787 LOG(FATAL) << "Type conversion from " << input_type
1788 << " to " << result_type << " not yet implemented";
1789 break;
1790
1791 default:
1792 LOG(FATAL) << "Unexpected type conversion from " << input_type
1793 << " to " << result_type;
1794 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001795 break;
1796
1797 default:
1798 LOG(FATAL) << "Unexpected type conversion from " << input_type
1799 << " to " << result_type;
1800 }
1801}
1802
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001803void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001804 LocationSummary* locations =
1805 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001806 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001807 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001808 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001809 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1810 locations->SetInAt(0, Location::RequiresRegister());
1811 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1812 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001813 break;
1814 }
1815
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001816 case Primitive::kPrimFloat:
1817 case Primitive::kPrimDouble: {
1818 locations->SetInAt(0, Location::RequiresFpuRegister());
1819 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001820 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001821 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001822 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001823
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001824 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001825 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001826 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001827}
1828
1829void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1830 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001831 Location out = locations->Out();
1832 Location first = locations->InAt(0);
1833 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001834 switch (add->GetResultType()) {
1835 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001836 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001837 __ add(out.AsRegister<Register>(),
1838 first.AsRegister<Register>(),
1839 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001840 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001841 __ AddConstant(out.AsRegister<Register>(),
1842 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001843 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001844 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001845 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001846
1847 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001848 __ adds(out.AsRegisterPairLow<Register>(),
1849 first.AsRegisterPairLow<Register>(),
1850 ShifterOperand(second.AsRegisterPairLow<Register>()));
1851 __ adc(out.AsRegisterPairHigh<Register>(),
1852 first.AsRegisterPairHigh<Register>(),
1853 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001854 break;
1855
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001856 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001857 __ vadds(out.AsFpuRegister<SRegister>(),
1858 first.AsFpuRegister<SRegister>(),
1859 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001860 break;
1861
1862 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001863 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1864 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1865 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001866 break;
1867
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001868 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001869 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001870 }
1871}
1872
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001873void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001874 LocationSummary* locations =
1875 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001876 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001877 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001878 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001879 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1880 locations->SetInAt(0, Location::RequiresRegister());
1881 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1882 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001883 break;
1884 }
Calin Juravle11351682014-10-23 15:38:15 +01001885 case Primitive::kPrimFloat:
1886 case Primitive::kPrimDouble: {
1887 locations->SetInAt(0, Location::RequiresFpuRegister());
1888 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001889 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001890 break;
Calin Juravle11351682014-10-23 15:38:15 +01001891 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001892 default:
Calin Juravle11351682014-10-23 15:38:15 +01001893 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001894 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001895}
1896
1897void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1898 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001899 Location out = locations->Out();
1900 Location first = locations->InAt(0);
1901 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001902 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001903 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001904 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001905 __ sub(out.AsRegister<Register>(),
1906 first.AsRegister<Register>(),
1907 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001908 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001909 __ AddConstant(out.AsRegister<Register>(),
1910 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001911 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001912 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001913 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001914 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001915
Calin Juravle11351682014-10-23 15:38:15 +01001916 case Primitive::kPrimLong: {
1917 __ subs(out.AsRegisterPairLow<Register>(),
1918 first.AsRegisterPairLow<Register>(),
1919 ShifterOperand(second.AsRegisterPairLow<Register>()));
1920 __ sbc(out.AsRegisterPairHigh<Register>(),
1921 first.AsRegisterPairHigh<Register>(),
1922 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001923 break;
Calin Juravle11351682014-10-23 15:38:15 +01001924 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001925
Calin Juravle11351682014-10-23 15:38:15 +01001926 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001927 __ vsubs(out.AsFpuRegister<SRegister>(),
1928 first.AsFpuRegister<SRegister>(),
1929 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001930 break;
Calin Juravle11351682014-10-23 15:38:15 +01001931 }
1932
1933 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001934 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1935 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1936 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001937 break;
1938 }
1939
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001940
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001941 default:
Calin Juravle11351682014-10-23 15:38:15 +01001942 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001943 }
1944}
1945
Calin Juravle34bacdf2014-10-07 20:23:36 +01001946void LocationsBuilderARM::VisitMul(HMul* mul) {
1947 LocationSummary* locations =
1948 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1949 switch (mul->GetResultType()) {
1950 case Primitive::kPrimInt:
1951 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001952 locations->SetInAt(0, Location::RequiresRegister());
1953 locations->SetInAt(1, Location::RequiresRegister());
1954 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001955 break;
1956 }
1957
Calin Juravleb5bfa962014-10-21 18:02:24 +01001958 case Primitive::kPrimFloat:
1959 case Primitive::kPrimDouble: {
1960 locations->SetInAt(0, Location::RequiresFpuRegister());
1961 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001962 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001963 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001964 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001965
1966 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001967 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001968 }
1969}
1970
1971void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1972 LocationSummary* locations = mul->GetLocations();
1973 Location out = locations->Out();
1974 Location first = locations->InAt(0);
1975 Location second = locations->InAt(1);
1976 switch (mul->GetResultType()) {
1977 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00001978 __ mul(out.AsRegister<Register>(),
1979 first.AsRegister<Register>(),
1980 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001981 break;
1982 }
1983 case Primitive::kPrimLong: {
1984 Register out_hi = out.AsRegisterPairHigh<Register>();
1985 Register out_lo = out.AsRegisterPairLow<Register>();
1986 Register in1_hi = first.AsRegisterPairHigh<Register>();
1987 Register in1_lo = first.AsRegisterPairLow<Register>();
1988 Register in2_hi = second.AsRegisterPairHigh<Register>();
1989 Register in2_lo = second.AsRegisterPairLow<Register>();
1990
1991 // Extra checks to protect caused by the existence of R1_R2.
1992 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1993 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1994 DCHECK_NE(out_hi, in1_lo);
1995 DCHECK_NE(out_hi, in2_lo);
1996
1997 // input: in1 - 64 bits, in2 - 64 bits
1998 // output: out
1999 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2000 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2001 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2002
2003 // IP <- in1.lo * in2.hi
2004 __ mul(IP, in1_lo, in2_hi);
2005 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2006 __ mla(out_hi, in1_hi, in2_lo, IP);
2007 // out.lo <- (in1.lo * in2.lo)[31:0];
2008 __ umull(out_lo, IP, in1_lo, in2_lo);
2009 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2010 __ add(out_hi, out_hi, ShifterOperand(IP));
2011 break;
2012 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002013
2014 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002015 __ vmuls(out.AsFpuRegister<SRegister>(),
2016 first.AsFpuRegister<SRegister>(),
2017 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002018 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002019 }
2020
2021 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002022 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2023 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2024 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002025 break;
2026 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002027
2028 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002029 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002030 }
2031}
2032
Calin Juravle7c4954d2014-10-28 16:57:40 +00002033void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002034 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2035 ? LocationSummary::kCall
2036 : LocationSummary::kNoCall;
2037 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2038
Calin Juravle7c4954d2014-10-28 16:57:40 +00002039 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002040 case Primitive::kPrimInt: {
2041 locations->SetInAt(0, Location::RequiresRegister());
2042 locations->SetInAt(1, Location::RequiresRegister());
2043 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2044 break;
2045 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002046 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002047 InvokeRuntimeCallingConvention calling_convention;
2048 locations->SetInAt(0, Location::RegisterPairLocation(
2049 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2050 locations->SetInAt(1, Location::RegisterPairLocation(
2051 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2052 // The runtime helper puts the output in R0,R2.
2053 locations->SetOut(Location::RegisterPairLocation(R0, R2));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002054 break;
2055 }
2056 case Primitive::kPrimFloat:
2057 case Primitive::kPrimDouble: {
2058 locations->SetInAt(0, Location::RequiresFpuRegister());
2059 locations->SetInAt(1, Location::RequiresFpuRegister());
2060 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2061 break;
2062 }
2063
2064 default:
2065 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2066 }
2067}
2068
2069void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2070 LocationSummary* locations = div->GetLocations();
2071 Location out = locations->Out();
2072 Location first = locations->InAt(0);
2073 Location second = locations->InAt(1);
2074
2075 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002076 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002077 __ sdiv(out.AsRegister<Register>(),
2078 first.AsRegister<Register>(),
2079 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002080 break;
2081 }
2082
Calin Juravle7c4954d2014-10-28 16:57:40 +00002083 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002084 InvokeRuntimeCallingConvention calling_convention;
2085 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2086 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2087 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2088 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2089 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2090 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2091
2092 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002093 break;
2094 }
2095
2096 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002097 __ vdivs(out.AsFpuRegister<SRegister>(),
2098 first.AsFpuRegister<SRegister>(),
2099 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002100 break;
2101 }
2102
2103 case Primitive::kPrimDouble: {
2104 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2105 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2106 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2107 break;
2108 }
2109
2110 default:
2111 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2112 }
2113}
2114
Calin Juravlebacfec32014-11-14 15:54:36 +00002115void LocationsBuilderARM::VisitRem(HRem* rem) {
2116 LocationSummary::CallKind call_kind = rem->GetResultType() == Primitive::kPrimLong
2117 ? LocationSummary::kCall
2118 : LocationSummary::kNoCall;
2119 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2120
2121 switch (rem->GetResultType()) {
2122 case Primitive::kPrimInt: {
2123 locations->SetInAt(0, Location::RequiresRegister());
2124 locations->SetInAt(1, Location::RequiresRegister());
2125 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2126 locations->AddTemp(Location::RequiresRegister());
2127 break;
2128 }
2129 case Primitive::kPrimLong: {
2130 InvokeRuntimeCallingConvention calling_convention;
2131 locations->SetInAt(0, Location::RegisterPairLocation(
2132 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2133 locations->SetInAt(1, Location::RegisterPairLocation(
2134 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2135 // The runtime helper puts the output in R2,R3.
2136 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2137 break;
2138 }
2139 case Primitive::kPrimFloat:
2140 case Primitive::kPrimDouble: {
2141 LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType();
2142 break;
2143 }
2144
2145 default:
2146 LOG(FATAL) << "Unexpected rem type " << rem->GetResultType();
2147 }
2148}
2149
2150void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2151 LocationSummary* locations = rem->GetLocations();
2152 Location out = locations->Out();
2153 Location first = locations->InAt(0);
2154 Location second = locations->InAt(1);
2155
2156 switch (rem->GetResultType()) {
2157 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002158 Register reg1 = first.AsRegister<Register>();
2159 Register reg2 = second.AsRegister<Register>();
2160 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002161
2162 // temp = reg1 / reg2 (integer division)
2163 // temp = temp * reg2
2164 // dest = reg1 - temp
2165 __ sdiv(temp, reg1, reg2);
2166 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002167 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002168 break;
2169 }
2170
2171 case Primitive::kPrimLong: {
2172 InvokeRuntimeCallingConvention calling_convention;
2173 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2174 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2175 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2176 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2177 DCHECK_EQ(R2, out.AsRegisterPairLow<Register>());
2178 DCHECK_EQ(R3, out.AsRegisterPairHigh<Register>());
2179
2180 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2181 break;
2182 }
2183
2184 case Primitive::kPrimFloat:
2185 case Primitive::kPrimDouble: {
2186 LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType();
2187 break;
2188 }
2189
2190 default:
2191 LOG(FATAL) << "Unexpected rem type " << rem->GetResultType();
2192 }
2193}
2194
Calin Juravled0d48522014-11-04 16:40:20 +00002195void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2196 LocationSummary* locations =
2197 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002198 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002199 if (instruction->HasUses()) {
2200 locations->SetOut(Location::SameAsFirstInput());
2201 }
2202}
2203
2204void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2205 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2206 codegen_->AddSlowPath(slow_path);
2207
2208 LocationSummary* locations = instruction->GetLocations();
2209 Location value = locations->InAt(0);
2210
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002211 switch (instruction->GetType()) {
2212 case Primitive::kPrimInt: {
2213 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002214 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002215 __ b(slow_path->GetEntryLabel(), EQ);
2216 } else {
2217 DCHECK(value.IsConstant()) << value;
2218 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2219 __ b(slow_path->GetEntryLabel());
2220 }
2221 }
2222 break;
2223 }
2224 case Primitive::kPrimLong: {
2225 if (value.IsRegisterPair()) {
2226 __ orrs(IP,
2227 value.AsRegisterPairLow<Register>(),
2228 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2229 __ b(slow_path->GetEntryLabel(), EQ);
2230 } else {
2231 DCHECK(value.IsConstant()) << value;
2232 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2233 __ b(slow_path->GetEntryLabel());
2234 }
2235 }
2236 break;
2237 default:
2238 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2239 }
2240 }
Calin Juravled0d48522014-11-04 16:40:20 +00002241}
2242
Calin Juravle9aec02f2014-11-18 23:06:35 +00002243void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2244 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2245
2246 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2247 ? LocationSummary::kCall
2248 : LocationSummary::kNoCall;
2249 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2250
2251 switch (op->GetResultType()) {
2252 case Primitive::kPrimInt: {
2253 locations->SetInAt(0, Location::RequiresRegister());
2254 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
2255 locations->SetOut(Location::RequiresRegister());
2256 break;
2257 }
2258 case Primitive::kPrimLong: {
2259 InvokeRuntimeCallingConvention calling_convention;
2260 locations->SetInAt(0, Location::RegisterPairLocation(
2261 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2262 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2263 // The runtime helper puts the output in R0,R2.
2264 locations->SetOut(Location::RegisterPairLocation(R0, R2));
2265 break;
2266 }
2267 default:
2268 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2269 }
2270}
2271
2272void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2273 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2274
2275 LocationSummary* locations = op->GetLocations();
2276 Location out = locations->Out();
2277 Location first = locations->InAt(0);
2278 Location second = locations->InAt(1);
2279
2280 Primitive::Type type = op->GetResultType();
2281 switch (type) {
2282 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002283 Register out_reg = out.AsRegister<Register>();
2284 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002285 // Arm doesn't mask the shift count so we need to do it ourselves.
2286 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002287 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002288 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2289 if (op->IsShl()) {
2290 __ Lsl(out_reg, first_reg, second_reg);
2291 } else if (op->IsShr()) {
2292 __ Asr(out_reg, first_reg, second_reg);
2293 } else {
2294 __ Lsr(out_reg, first_reg, second_reg);
2295 }
2296 } else {
2297 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2298 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2299 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2300 __ Mov(out_reg, first_reg);
2301 } else if (op->IsShl()) {
2302 __ Lsl(out_reg, first_reg, shift_value);
2303 } else if (op->IsShr()) {
2304 __ Asr(out_reg, first_reg, shift_value);
2305 } else {
2306 __ Lsr(out_reg, first_reg, shift_value);
2307 }
2308 }
2309 break;
2310 }
2311 case Primitive::kPrimLong: {
2312 // TODO: Inline the assembly instead of calling the runtime.
2313 InvokeRuntimeCallingConvention calling_convention;
2314 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2315 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002316 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002317 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2318 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2319
2320 int32_t entry_point_offset;
2321 if (op->IsShl()) {
2322 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2323 } else if (op->IsShr()) {
2324 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2325 } else {
2326 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2327 }
2328 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2329 __ blx(LR);
2330 break;
2331 }
2332 default:
2333 LOG(FATAL) << "Unexpected operation type " << type;
2334 }
2335}
2336
2337void LocationsBuilderARM::VisitShl(HShl* shl) {
2338 HandleShift(shl);
2339}
2340
2341void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2342 HandleShift(shl);
2343}
2344
2345void LocationsBuilderARM::VisitShr(HShr* shr) {
2346 HandleShift(shr);
2347}
2348
2349void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2350 HandleShift(shr);
2351}
2352
2353void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2354 HandleShift(ushr);
2355}
2356
2357void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2358 HandleShift(ushr);
2359}
2360
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002361void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002362 LocationSummary* locations =
2363 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002364 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002365 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2366 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2367 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002368}
2369
2370void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2371 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002372 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002373 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002374 codegen_->InvokeRuntime(
2375 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002376}
2377
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002378void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2379 LocationSummary* locations =
2380 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2381 InvokeRuntimeCallingConvention calling_convention;
2382 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2383 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2384 locations->SetOut(Location::RegisterLocation(R0));
2385 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2386}
2387
2388void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2389 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002390 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002391 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002392 codegen_->InvokeRuntime(
2393 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002394}
2395
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002396void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002397 LocationSummary* locations =
2398 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002399 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2400 if (location.IsStackSlot()) {
2401 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2402 } else if (location.IsDoubleStackSlot()) {
2403 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002404 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002405 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002406}
2407
2408void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002409 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002410 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002411}
2412
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002413void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002414 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002415 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002416 locations->SetInAt(0, Location::RequiresRegister());
2417 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002418}
2419
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002420void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2421 LocationSummary* locations = not_->GetLocations();
2422 Location out = locations->Out();
2423 Location in = locations->InAt(0);
2424 switch (not_->InputAt(0)->GetType()) {
2425 case Primitive::kPrimBoolean:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002426 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002427 break;
2428
2429 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002430 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002431 break;
2432
2433 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002434 __ mvn(out.AsRegisterPairLow<Register>(),
2435 ShifterOperand(in.AsRegisterPairLow<Register>()));
2436 __ mvn(out.AsRegisterPairHigh<Register>(),
2437 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002438 break;
2439
2440 default:
2441 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2442 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002443}
2444
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002445void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002446 LocationSummary* locations =
2447 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002448 switch (compare->InputAt(0)->GetType()) {
2449 case Primitive::kPrimLong: {
2450 locations->SetInAt(0, Location::RequiresRegister());
2451 locations->SetInAt(1, Location::RequiresRegister());
2452 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2453 break;
2454 }
2455 case Primitive::kPrimFloat:
2456 case Primitive::kPrimDouble: {
2457 locations->SetInAt(0, Location::RequiresFpuRegister());
2458 locations->SetInAt(1, Location::RequiresFpuRegister());
2459 locations->SetOut(Location::RequiresRegister());
2460 break;
2461 }
2462 default:
2463 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2464 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002465}
2466
2467void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002468 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002469 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002470 Location left = locations->InAt(0);
2471 Location right = locations->InAt(1);
2472
2473 Label less, greater, done;
2474 Primitive::Type type = compare->InputAt(0)->GetType();
2475 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002476 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002477 __ cmp(left.AsRegisterPairHigh<Register>(),
2478 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002479 __ b(&less, LT);
2480 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002481 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2482 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002483 __ cmp(left.AsRegisterPairLow<Register>(),
2484 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002485 break;
2486 }
2487 case Primitive::kPrimFloat:
2488 case Primitive::kPrimDouble: {
2489 __ LoadImmediate(out, 0);
2490 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002491 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002492 } else {
2493 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2494 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2495 }
2496 __ vmstat(); // transfer FP status register to ARM APSR.
2497 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002498 break;
2499 }
2500 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002501 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002502 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002503 __ b(&done, EQ);
2504 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2505
2506 __ Bind(&greater);
2507 __ LoadImmediate(out, 1);
2508 __ b(&done);
2509
2510 __ Bind(&less);
2511 __ LoadImmediate(out, -1);
2512
2513 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002514}
2515
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002516void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002517 LocationSummary* locations =
2518 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002519 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2520 locations->SetInAt(i, Location::Any());
2521 }
2522 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002523}
2524
2525void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002526 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002527 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002528}
2529
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002530void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002531 LocationSummary* locations =
2532 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002533 bool needs_write_barrier =
2534 CodeGenerator::StoreNeedsWriteBarrier(instruction->GetFieldType(), instruction->GetValue());
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002535 locations->SetInAt(0, Location::RequiresRegister());
2536 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002537 // Temporary registers for the write barrier.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002538 if (needs_write_barrier) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002539 locations->AddTemp(Location::RequiresRegister());
2540 locations->AddTemp(Location::RequiresRegister());
2541 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002542}
2543
2544void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2545 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002546 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002547 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01002548 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002549
2550 switch (field_type) {
2551 case Primitive::kPrimBoolean:
2552 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002553 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002554 __ StoreToOffset(kStoreByte, value, obj, offset);
2555 break;
2556 }
2557
2558 case Primitive::kPrimShort:
2559 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002560 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002561 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2562 break;
2563 }
2564
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002565 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002566 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002567 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002568 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002569 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002570 Register temp = locations->GetTemp(0).AsRegister<Register>();
2571 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002572 codegen_->MarkGCCard(temp, card, obj, value);
2573 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002574 break;
2575 }
2576
2577 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002578 Location value = locations->InAt(1);
2579 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002580 break;
2581 }
2582
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002583 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002584 SRegister value = locations->InAt(1).AsFpuRegister<SRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002585 __ StoreSToOffset(value, obj, offset);
2586 break;
2587 }
2588
2589 case Primitive::kPrimDouble: {
2590 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
2591 __ StoreDToOffset(value, obj, offset);
2592 break;
2593 }
2594
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002595 case Primitive::kPrimVoid:
2596 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002597 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002598 }
2599}
2600
2601void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002602 LocationSummary* locations =
2603 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002604 locations->SetInAt(0, Location::RequiresRegister());
2605 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002606}
2607
2608void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2609 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002610 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002611 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2612
2613 switch (instruction->GetType()) {
2614 case Primitive::kPrimBoolean: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002615 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002616 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2617 break;
2618 }
2619
2620 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002621 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002622 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2623 break;
2624 }
2625
2626 case Primitive::kPrimShort: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002627 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002628 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2629 break;
2630 }
2631
2632 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002633 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002634 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2635 break;
2636 }
2637
2638 case Primitive::kPrimInt:
2639 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002640 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002641 __ LoadFromOffset(kLoadWord, out, obj, offset);
2642 break;
2643 }
2644
2645 case Primitive::kPrimLong: {
2646 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002647 Location out = locations->Out();
2648 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002649 break;
2650 }
2651
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002652 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002653 SRegister out = locations->Out().AsFpuRegister<SRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002654 __ LoadSFromOffset(out, obj, offset);
2655 break;
2656 }
2657
2658 case Primitive::kPrimDouble: {
2659 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2660 __ LoadDFromOffset(out, obj, offset);
2661 break;
2662 }
2663
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002664 case Primitive::kPrimVoid:
2665 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002666 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002667 }
2668}
2669
2670void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002671 LocationSummary* locations =
2672 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002673 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002674 if (instruction->HasUses()) {
2675 locations->SetOut(Location::SameAsFirstInput());
2676 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002677}
2678
2679void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002680 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002681 codegen_->AddSlowPath(slow_path);
2682
2683 LocationSummary* locations = instruction->GetLocations();
2684 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002685
2686 if (obj.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002687 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002688 __ b(slow_path->GetEntryLabel(), EQ);
2689 } else {
2690 DCHECK(obj.IsConstant()) << obj;
2691 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2692 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002693 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002694}
2695
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002696void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002697 LocationSummary* locations =
2698 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002699 locations->SetInAt(0, Location::RequiresRegister());
2700 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2701 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002702}
2703
2704void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2705 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002706 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002707 Location index = locations->InAt(1);
2708
2709 switch (instruction->GetType()) {
2710 case Primitive::kPrimBoolean: {
2711 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002712 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002713 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002714 size_t offset =
2715 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002716 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2717 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002718 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002719 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2720 }
2721 break;
2722 }
2723
2724 case Primitive::kPrimByte: {
2725 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002726 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002727 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002728 size_t offset =
2729 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002730 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2731 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002732 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002733 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2734 }
2735 break;
2736 }
2737
2738 case Primitive::kPrimShort: {
2739 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002740 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002741 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002742 size_t offset =
2743 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002744 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2745 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002746 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002747 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2748 }
2749 break;
2750 }
2751
2752 case Primitive::kPrimChar: {
2753 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002754 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002755 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002756 size_t offset =
2757 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002758 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2759 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002760 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002761 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2762 }
2763 break;
2764 }
2765
2766 case Primitive::kPrimInt:
2767 case Primitive::kPrimNot: {
2768 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2769 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002770 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002771 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002772 size_t offset =
2773 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002774 __ LoadFromOffset(kLoadWord, out, obj, offset);
2775 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002776 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002777 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2778 }
2779 break;
2780 }
2781
2782 case Primitive::kPrimLong: {
2783 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002784 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002785 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002786 size_t offset =
2787 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002788 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002789 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002790 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002791 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002792 }
2793 break;
2794 }
2795
2796 case Primitive::kPrimFloat:
2797 case Primitive::kPrimDouble:
2798 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002799 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002800 case Primitive::kPrimVoid:
2801 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002802 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002803 }
2804}
2805
2806void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002807 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002808
2809 bool needs_write_barrier =
2810 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
2811 bool needs_runtime_call = instruction->NeedsTypeCheck();
2812
Nicolas Geoffray39468442014-09-02 15:17:15 +01002813 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002814 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
2815 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002816 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002817 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2818 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2819 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002820 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002821 locations->SetInAt(0, Location::RequiresRegister());
2822 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2823 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002824
2825 if (needs_write_barrier) {
2826 // Temporary registers for the write barrier.
2827 locations->AddTemp(Location::RequiresRegister());
2828 locations->AddTemp(Location::RequiresRegister());
2829 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002830 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002831}
2832
2833void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
2834 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002835 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002836 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002837 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002838 bool needs_runtime_call = locations->WillCall();
2839 bool needs_write_barrier =
2840 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002841
2842 switch (value_type) {
2843 case Primitive::kPrimBoolean:
2844 case Primitive::kPrimByte: {
2845 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002846 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002847 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002848 size_t offset =
2849 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002850 __ StoreToOffset(kStoreByte, value, obj, offset);
2851 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002852 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002853 __ StoreToOffset(kStoreByte, value, IP, data_offset);
2854 }
2855 break;
2856 }
2857
2858 case Primitive::kPrimShort:
2859 case Primitive::kPrimChar: {
2860 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002861 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002862 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002863 size_t offset =
2864 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002865 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2866 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002867 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002868 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
2869 }
2870 break;
2871 }
2872
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002873 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002874 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002875 if (!needs_runtime_call) {
2876 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002877 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002878 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002879 size_t offset =
2880 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002881 __ StoreToOffset(kStoreWord, value, obj, offset);
2882 } else {
2883 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00002884 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002885 __ StoreToOffset(kStoreWord, value, IP, data_offset);
2886 }
2887 if (needs_write_barrier) {
2888 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002889 Register temp = locations->GetTemp(0).AsRegister<Register>();
2890 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002891 codegen_->MarkGCCard(temp, card, obj, value);
2892 }
2893 } else {
2894 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00002895 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
2896 instruction,
2897 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002898 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002899 break;
2900 }
2901
2902 case Primitive::kPrimLong: {
2903 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002904 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002905 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002906 size_t offset =
2907 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002908 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002909 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002910 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002911 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002912 }
2913 break;
2914 }
2915
2916 case Primitive::kPrimFloat:
2917 case Primitive::kPrimDouble:
2918 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002919 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002920 case Primitive::kPrimVoid:
2921 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002922 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002923 }
2924}
2925
2926void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002927 LocationSummary* locations =
2928 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002929 locations->SetInAt(0, Location::RequiresRegister());
2930 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002931}
2932
2933void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
2934 LocationSummary* locations = instruction->GetLocations();
2935 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002936 Register obj = locations->InAt(0).AsRegister<Register>();
2937 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002938 __ LoadFromOffset(kLoadWord, out, obj, offset);
2939}
2940
2941void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002942 LocationSummary* locations =
2943 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002944 locations->SetInAt(0, Location::RequiresRegister());
2945 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002946 if (instruction->HasUses()) {
2947 locations->SetOut(Location::SameAsFirstInput());
2948 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002949}
2950
2951void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
2952 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002953 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002954 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002955 codegen_->AddSlowPath(slow_path);
2956
Roland Levillain271ab9c2014-11-27 15:23:57 +00002957 Register index = locations->InAt(0).AsRegister<Register>();
2958 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002959
2960 __ cmp(index, ShifterOperand(length));
2961 __ b(slow_path->GetEntryLabel(), CS);
2962}
2963
2964void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
2965 Label is_null;
2966 __ CompareAndBranchIfZero(value, &is_null);
2967 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
2968 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
2969 __ strb(card, Address(card, temp));
2970 __ Bind(&is_null);
2971}
2972
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002973void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
2974 temp->SetLocations(nullptr);
2975}
2976
2977void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
2978 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002979 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002980}
2981
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002982void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002983 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002984 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002985}
2986
2987void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002988 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2989}
2990
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002991void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
2992 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2993}
2994
2995void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002996 HBasicBlock* block = instruction->GetBlock();
2997 if (block->GetLoopInformation() != nullptr) {
2998 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2999 // The back edge will generate the suspend check.
3000 return;
3001 }
3002 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3003 // The goto will generate the suspend check.
3004 return;
3005 }
3006 GenerateSuspendCheck(instruction, nullptr);
3007}
3008
3009void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3010 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003011 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003012 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003013 codegen_->AddSlowPath(slow_path);
3014
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003015 __ LoadFromOffset(
3016 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3017 __ cmp(IP, ShifterOperand(0));
3018 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003019 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003020 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003021 __ Bind(slow_path->GetReturnLabel());
3022 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003023 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003024 __ b(slow_path->GetEntryLabel());
3025 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003026}
3027
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003028ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3029 return codegen_->GetAssembler();
3030}
3031
3032void ParallelMoveResolverARM::EmitMove(size_t index) {
3033 MoveOperands* move = moves_.Get(index);
3034 Location source = move->GetSource();
3035 Location destination = move->GetDestination();
3036
3037 if (source.IsRegister()) {
3038 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003039 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003040 } else {
3041 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003042 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003043 SP, destination.GetStackIndex());
3044 }
3045 } else if (source.IsStackSlot()) {
3046 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003047 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003048 SP, source.GetStackIndex());
3049 } else {
3050 DCHECK(destination.IsStackSlot());
3051 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3052 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3053 }
3054 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003055 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01003056 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003057 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
3058 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003059 __ LoadImmediate(destination.AsRegister<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003060 } else {
3061 DCHECK(destination.IsStackSlot());
3062 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01003063 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003064 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003065 }
3066}
3067
3068void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3069 __ Mov(IP, reg);
3070 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3071 __ StoreToOffset(kStoreWord, IP, SP, mem);
3072}
3073
3074void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3075 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3076 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3077 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3078 SP, mem1 + stack_offset);
3079 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3080 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3081 SP, mem2 + stack_offset);
3082 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3083}
3084
3085void ParallelMoveResolverARM::EmitSwap(size_t index) {
3086 MoveOperands* move = moves_.Get(index);
3087 Location source = move->GetSource();
3088 Location destination = move->GetDestination();
3089
3090 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003091 DCHECK_NE(source.AsRegister<Register>(), IP);
3092 DCHECK_NE(destination.AsRegister<Register>(), IP);
3093 __ Mov(IP, source.AsRegister<Register>());
3094 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3095 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003096 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003097 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003098 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003099 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003100 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3101 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3102 } else {
3103 LOG(FATAL) << "Unimplemented";
3104 }
3105}
3106
3107void ParallelMoveResolverARM::SpillScratch(int reg) {
3108 __ Push(static_cast<Register>(reg));
3109}
3110
3111void ParallelMoveResolverARM::RestoreScratch(int reg) {
3112 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003113}
3114
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003115void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003116 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3117 ? LocationSummary::kCallOnSlowPath
3118 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003119 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003120 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003121 locations->SetOut(Location::RequiresRegister());
3122}
3123
3124void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003125 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003126 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003127 DCHECK(!cls->CanCallRuntime());
3128 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003129 codegen_->LoadCurrentMethod(out);
3130 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3131 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003132 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003133 codegen_->LoadCurrentMethod(out);
3134 __ LoadFromOffset(
3135 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3136 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003137
3138 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3139 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3140 codegen_->AddSlowPath(slow_path);
3141 __ cmp(out, ShifterOperand(0));
3142 __ b(slow_path->GetEntryLabel(), EQ);
3143 if (cls->MustGenerateClinitCheck()) {
3144 GenerateClassInitializationCheck(slow_path, out);
3145 } else {
3146 __ Bind(slow_path->GetExitLabel());
3147 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003148 }
3149}
3150
3151void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3152 LocationSummary* locations =
3153 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3154 locations->SetInAt(0, Location::RequiresRegister());
3155 if (check->HasUses()) {
3156 locations->SetOut(Location::SameAsFirstInput());
3157 }
3158}
3159
3160void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003161 // We assume the class is not null.
3162 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3163 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003164 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003165 GenerateClassInitializationCheck(slow_path,
3166 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003167}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003168
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003169void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3170 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003171 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3172 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3173 __ b(slow_path->GetEntryLabel(), LT);
3174 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3175 // properly. Therefore, we do a memory fence.
3176 __ dmb(ISH);
3177 __ Bind(slow_path->GetExitLabel());
3178}
3179
3180void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3181 LocationSummary* locations =
3182 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3183 locations->SetInAt(0, Location::RequiresRegister());
3184 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3185}
3186
3187void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3188 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003189 Register cls = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003190 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
3191
3192 switch (instruction->GetType()) {
3193 case Primitive::kPrimBoolean: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003194 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003195 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
3196 break;
3197 }
3198
3199 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003200 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003201 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
3202 break;
3203 }
3204
3205 case Primitive::kPrimShort: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003206 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003207 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
3208 break;
3209 }
3210
3211 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003212 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003213 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
3214 break;
3215 }
3216
3217 case Primitive::kPrimInt:
3218 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003219 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003220 __ LoadFromOffset(kLoadWord, out, cls, offset);
3221 break;
3222 }
3223
3224 case Primitive::kPrimLong: {
3225 // TODO: support volatile.
3226 Location out = locations->Out();
3227 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
3228 break;
3229 }
3230
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003231 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003232 SRegister out = locations->Out().AsFpuRegister<SRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003233 __ LoadSFromOffset(out, cls, offset);
3234 break;
3235 }
3236
3237 case Primitive::kPrimDouble: {
3238 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
3239 __ LoadDFromOffset(out, cls, offset);
3240 break;
3241 }
3242
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003243 case Primitive::kPrimVoid:
3244 LOG(FATAL) << "Unreachable type " << instruction->GetType();
3245 UNREACHABLE();
3246 }
3247}
3248
3249void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3250 LocationSummary* locations =
3251 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003252 bool needs_write_barrier =
3253 CodeGenerator::StoreNeedsWriteBarrier(instruction->GetFieldType(), instruction->GetValue());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003254 locations->SetInAt(0, Location::RequiresRegister());
3255 locations->SetInAt(1, Location::RequiresRegister());
3256 // Temporary registers for the write barrier.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003257 if (needs_write_barrier) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003258 locations->AddTemp(Location::RequiresRegister());
3259 locations->AddTemp(Location::RequiresRegister());
3260 }
3261}
3262
3263void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3264 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003265 Register cls = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003266 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
3267 Primitive::Type field_type = instruction->GetFieldType();
3268
3269 switch (field_type) {
3270 case Primitive::kPrimBoolean:
3271 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003272 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003273 __ StoreToOffset(kStoreByte, value, cls, offset);
3274 break;
3275 }
3276
3277 case Primitive::kPrimShort:
3278 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003279 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003280 __ StoreToOffset(kStoreHalfword, value, cls, offset);
3281 break;
3282 }
3283
3284 case Primitive::kPrimInt:
3285 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003286 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003287 __ StoreToOffset(kStoreWord, value, cls, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003288 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003289 Register temp = locations->GetTemp(0).AsRegister<Register>();
3290 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003291 codegen_->MarkGCCard(temp, card, cls, value);
3292 }
3293 break;
3294 }
3295
3296 case Primitive::kPrimLong: {
3297 Location value = locations->InAt(1);
3298 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
3299 break;
3300 }
3301
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003302 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003303 SRegister value = locations->InAt(1).AsFpuRegister<SRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003304 __ StoreSToOffset(value, cls, offset);
3305 break;
3306 }
3307
3308 case Primitive::kPrimDouble: {
3309 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
3310 __ StoreDToOffset(value, cls, offset);
3311 break;
3312 }
3313
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003314 case Primitive::kPrimVoid:
3315 LOG(FATAL) << "Unreachable type " << field_type;
3316 UNREACHABLE();
3317 }
3318}
3319
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003320void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3321 LocationSummary* locations =
3322 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3323 locations->SetOut(Location::RequiresRegister());
3324}
3325
3326void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3327 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3328 codegen_->AddSlowPath(slow_path);
3329
Roland Levillain271ab9c2014-11-27 15:23:57 +00003330 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003331 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003332 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3333 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003334 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3335 __ cmp(out, ShifterOperand(0));
3336 __ b(slow_path->GetEntryLabel(), EQ);
3337 __ Bind(slow_path->GetExitLabel());
3338}
3339
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003340void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3341 LocationSummary* locations =
3342 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3343 locations->SetOut(Location::RequiresRegister());
3344}
3345
3346void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003347 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003348 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3349 __ LoadFromOffset(kLoadWord, out, TR, offset);
3350 __ LoadImmediate(IP, 0);
3351 __ StoreToOffset(kStoreWord, IP, TR, offset);
3352}
3353
3354void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3355 LocationSummary* locations =
3356 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3357 InvokeRuntimeCallingConvention calling_convention;
3358 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3359}
3360
3361void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3362 codegen_->InvokeRuntime(
3363 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3364}
3365
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003366void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003367 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3368 ? LocationSummary::kNoCall
3369 : LocationSummary::kCallOnSlowPath;
3370 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3371 locations->SetInAt(0, Location::RequiresRegister());
3372 locations->SetInAt(1, Location::RequiresRegister());
3373 locations->SetOut(Location::RequiresRegister());
3374}
3375
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003376void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003377 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003378 Register obj = locations->InAt(0).AsRegister<Register>();
3379 Register cls = locations->InAt(1).AsRegister<Register>();
3380 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003381 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3382 Label done, zero;
3383 SlowPathCodeARM* slow_path = nullptr;
3384
3385 // Return 0 if `obj` is null.
3386 // TODO: avoid this check if we know obj is not null.
3387 __ cmp(obj, ShifterOperand(0));
3388 __ b(&zero, EQ);
3389 // Compare the class of `obj` with `cls`.
3390 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3391 __ cmp(out, ShifterOperand(cls));
3392 if (instruction->IsClassFinal()) {
3393 // Classes must be equal for the instanceof to succeed.
3394 __ b(&zero, NE);
3395 __ LoadImmediate(out, 1);
3396 __ b(&done);
3397 } else {
3398 // If the classes are not equal, we go into a slow path.
3399 DCHECK(locations->OnlyCallsOnSlowPath());
3400 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003401 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003402 codegen_->AddSlowPath(slow_path);
3403 __ b(slow_path->GetEntryLabel(), NE);
3404 __ LoadImmediate(out, 1);
3405 __ b(&done);
3406 }
3407 __ Bind(&zero);
3408 __ LoadImmediate(out, 0);
3409 if (slow_path != nullptr) {
3410 __ Bind(slow_path->GetExitLabel());
3411 }
3412 __ Bind(&done);
3413}
3414
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003415void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3416 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3417 instruction, LocationSummary::kCallOnSlowPath);
3418 locations->SetInAt(0, Location::RequiresRegister());
3419 locations->SetInAt(1, Location::RequiresRegister());
3420 locations->AddTemp(Location::RequiresRegister());
3421}
3422
3423void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3424 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003425 Register obj = locations->InAt(0).AsRegister<Register>();
3426 Register cls = locations->InAt(1).AsRegister<Register>();
3427 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003428 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3429
3430 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3431 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3432 codegen_->AddSlowPath(slow_path);
3433
3434 // TODO: avoid this check if we know obj is not null.
3435 __ cmp(obj, ShifterOperand(0));
3436 __ b(slow_path->GetExitLabel(), EQ);
3437 // Compare the class of `obj` with `cls`.
3438 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3439 __ cmp(temp, ShifterOperand(cls));
3440 __ b(slow_path->GetEntryLabel(), NE);
3441 __ Bind(slow_path->GetExitLabel());
3442}
3443
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003444void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3445 LocationSummary* locations =
3446 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3447 InvokeRuntimeCallingConvention calling_convention;
3448 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3449}
3450
3451void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3452 codegen_->InvokeRuntime(instruction->IsEnter()
3453 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3454 instruction,
3455 instruction->GetDexPc());
3456}
3457
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003458void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3459void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3460void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3461
3462void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3463 LocationSummary* locations =
3464 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3465 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3466 || instruction->GetResultType() == Primitive::kPrimLong);
3467 locations->SetInAt(0, Location::RequiresRegister());
3468 locations->SetInAt(1, Location::RequiresRegister());
3469 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
3470 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3471}
3472
3473void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3474 HandleBitwiseOperation(instruction);
3475}
3476
3477void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3478 HandleBitwiseOperation(instruction);
3479}
3480
3481void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3482 HandleBitwiseOperation(instruction);
3483}
3484
3485void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3486 LocationSummary* locations = instruction->GetLocations();
3487
3488 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003489 Register first = locations->InAt(0).AsRegister<Register>();
3490 Register second = locations->InAt(1).AsRegister<Register>();
3491 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003492 if (instruction->IsAnd()) {
3493 __ and_(out, first, ShifterOperand(second));
3494 } else if (instruction->IsOr()) {
3495 __ orr(out, first, ShifterOperand(second));
3496 } else {
3497 DCHECK(instruction->IsXor());
3498 __ eor(out, first, ShifterOperand(second));
3499 }
3500 } else {
3501 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3502 Location first = locations->InAt(0);
3503 Location second = locations->InAt(1);
3504 Location out = locations->Out();
3505 if (instruction->IsAnd()) {
3506 __ and_(out.AsRegisterPairLow<Register>(),
3507 first.AsRegisterPairLow<Register>(),
3508 ShifterOperand(second.AsRegisterPairLow<Register>()));
3509 __ and_(out.AsRegisterPairHigh<Register>(),
3510 first.AsRegisterPairHigh<Register>(),
3511 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3512 } else if (instruction->IsOr()) {
3513 __ orr(out.AsRegisterPairLow<Register>(),
3514 first.AsRegisterPairLow<Register>(),
3515 ShifterOperand(second.AsRegisterPairLow<Register>()));
3516 __ orr(out.AsRegisterPairHigh<Register>(),
3517 first.AsRegisterPairHigh<Register>(),
3518 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3519 } else {
3520 DCHECK(instruction->IsXor());
3521 __ eor(out.AsRegisterPairLow<Register>(),
3522 first.AsRegisterPairLow<Register>(),
3523 ShifterOperand(second.AsRegisterPairLow<Register>()));
3524 __ eor(out.AsRegisterPairHigh<Register>(),
3525 first.AsRegisterPairHigh<Register>(),
3526 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3527 }
3528 }
3529}
3530
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003531} // namespace arm
3532} // namespace art