blob: f43449d511f144121c9587b51004d5d28dfccd14 [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
Nicolas Geoffray60047962014-12-15 00:01:18 +000041static constexpr int kNumberOfPushedRegistersAtEntry = 1; // LR.
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010042static 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);
Calin Juravled2ec87d2014-12-08 14:24:46 +000047static constexpr SRegister kRuntimeParameterFpuRegisters[] = { S0, S1, S2, S3 };
Roland Levillain624279f2014-12-04 11:54:28 +000048static 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 Geoffray60047962014-12-15 00:01:18 +0000447 // Reserve frame pointer register.
448 blocked_core_registers_[FP] = true;
449
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100450 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100451 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100452
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100453 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100454 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100455
Nicolas Geoffray60047962014-12-15 00:01:18 +0000456 // Reserve hard-float's callee saved registers.
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000457 blocked_fpu_registers_[S16] = true;
458 blocked_fpu_registers_[S17] = true;
459 blocked_fpu_registers_[S18] = true;
460 blocked_fpu_registers_[S19] = true;
461 blocked_fpu_registers_[S20] = true;
462 blocked_fpu_registers_[S21] = true;
463 blocked_fpu_registers_[S22] = true;
464 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000465 blocked_fpu_registers_[S24] = true;
466 blocked_fpu_registers_[S25] = true;
467 blocked_fpu_registers_[S26] = true;
468 blocked_fpu_registers_[S27] = true;
469 blocked_fpu_registers_[S28] = true;
470 blocked_fpu_registers_[S29] = true;
471 blocked_fpu_registers_[S30] = true;
472 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100473
474 UpdateBlockedPairRegisters();
475}
476
477void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
478 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
479 ArmManagedRegister current =
480 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
481 if (blocked_core_registers_[current.AsRegisterPairLow()]
482 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
483 blocked_register_pairs_[i] = true;
484 }
485 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100486}
487
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100488InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
489 : HGraphVisitor(graph),
490 assembler_(codegen->GetAssembler()),
491 codegen_(codegen) {}
492
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000493void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000494 bool skip_overflow_check =
495 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100496 if (!skip_overflow_check) {
497 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100498 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100499 AddSlowPath(slow_path);
500
501 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
502 __ cmp(SP, ShifterOperand(IP));
503 __ b(slow_path->GetEntryLabel(), CC);
504 } else {
505 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100506 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100507 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100508 }
509 }
510
Nicolas Geoffray60047962014-12-15 00:01:18 +0000511 core_spill_mask_ |= (1 << LR);
512 __ Push(LR);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000513
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100514 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100515 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100516 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000517}
518
519void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100520 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffray60047962014-12-15 00:01:18 +0000521 __ Pop(PC);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000522}
523
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100524void CodeGeneratorARM::Bind(HBasicBlock* block) {
525 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000526}
527
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100528Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
529 switch (load->GetType()) {
530 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100531 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100532 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
533 break;
534
535 case Primitive::kPrimInt:
536 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100537 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100538 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100539
540 case Primitive::kPrimBoolean:
541 case Primitive::kPrimByte:
542 case Primitive::kPrimChar:
543 case Primitive::kPrimShort:
544 case Primitive::kPrimVoid:
545 LOG(FATAL) << "Unexpected type " << load->GetType();
546 }
547
548 LOG(FATAL) << "Unreachable";
549 return Location();
550}
551
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100552Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
553 switch (type) {
554 case Primitive::kPrimBoolean:
555 case Primitive::kPrimByte:
556 case Primitive::kPrimChar:
557 case Primitive::kPrimShort:
558 case Primitive::kPrimInt:
559 case Primitive::kPrimNot: {
560 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000561 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100562 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100563 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100564 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000565 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100566 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100567 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100568
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000569 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100570 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000571 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100572 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000573 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100574 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100575 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
576 calling_convention.GetRegisterPairAt(index));
577 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100578 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000579 return Location::QuickParameter(index, stack_index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100580 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000581 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
582 }
583 }
584
585 case Primitive::kPrimFloat: {
586 uint32_t stack_index = stack_index_++;
587 if (float_index_ % 2 == 0) {
588 float_index_ = std::max(double_index_, float_index_);
589 }
590 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
591 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
592 } else {
593 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
594 }
595 }
596
597 case Primitive::kPrimDouble: {
598 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
599 uint32_t stack_index = stack_index_;
600 stack_index_ += 2;
601 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
602 uint32_t index = double_index_;
603 double_index_ += 2;
604 return Location::FpuRegisterPairLocation(
605 calling_convention.GetFpuRegisterAt(index),
606 calling_convention.GetFpuRegisterAt(index + 1));
607 } else {
608 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100609 }
610 }
611
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100612 case Primitive::kPrimVoid:
613 LOG(FATAL) << "Unexpected parameter type " << type;
614 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100615 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100616 return Location();
617}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100618
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000619Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
620 switch (type) {
621 case Primitive::kPrimBoolean:
622 case Primitive::kPrimByte:
623 case Primitive::kPrimChar:
624 case Primitive::kPrimShort:
625 case Primitive::kPrimInt:
626 case Primitive::kPrimNot: {
627 return Location::RegisterLocation(R0);
628 }
629
630 case Primitive::kPrimFloat: {
631 return Location::FpuRegisterLocation(S0);
632 }
633
634 case Primitive::kPrimLong: {
635 return Location::RegisterPairLocation(R0, R1);
636 }
637
638 case Primitive::kPrimDouble: {
639 return Location::FpuRegisterPairLocation(S0, S1);
640 }
641
642 case Primitive::kPrimVoid:
643 return Location();
644 }
645 UNREACHABLE();
646 return Location();
647}
648
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100649void CodeGeneratorARM::Move32(Location destination, Location source) {
650 if (source.Equals(destination)) {
651 return;
652 }
653 if (destination.IsRegister()) {
654 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000655 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100656 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000657 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100658 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000659 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100660 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100661 } else if (destination.IsFpuRegister()) {
662 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000663 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100664 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000665 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100666 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000667 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100668 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100669 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000670 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100671 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000672 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100673 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000674 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100675 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000676 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100677 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
678 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100679 }
680 }
681}
682
683void CodeGeneratorARM::Move64(Location destination, Location source) {
684 if (source.Equals(destination)) {
685 return;
686 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100687 if (destination.IsRegisterPair()) {
688 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000689 EmitParallelMoves(
690 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
691 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
692 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
693 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100694 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000695 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100696 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000697 uint16_t register_index = source.GetQuickParameterRegisterIndex();
698 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100699 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000700 EmitParallelMoves(
701 Location::RegisterLocation(calling_convention.GetRegisterAt(register_index)),
702 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
703 Location::StackSlot(
704 calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize()),
705 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100706 } else {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000707 // No conflict possible, so just do the moves.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100708 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100709 if (destination.AsRegisterPairLow<Register>() == R1) {
710 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100711 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
712 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100713 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100714 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100715 SP, source.GetStackIndex());
716 }
717 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000718 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100719 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000720 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
721 SP,
722 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100723 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000724 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100725 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100726 } else if (destination.IsQuickParameter()) {
727 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000728 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
729 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100730 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000731 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100732 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000733 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100734 } else {
735 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000736 EmitParallelMoves(
737 Location::StackSlot(source.GetStackIndex()),
738 Location::RegisterLocation(calling_convention.GetRegisterAt(register_index)),
739 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
740 Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index + 1)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100741 }
742 } else {
743 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100744 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000745 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100746 if (source.AsRegisterPairLow<Register>() == R1) {
747 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100748 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
749 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100750 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100751 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100752 SP, destination.GetStackIndex());
753 }
754 } else if (source.IsQuickParameter()) {
755 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000756 uint16_t register_index = source.GetQuickParameterRegisterIndex();
757 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000758 // Just move the low part. The only time a source is a quick parameter is
759 // when moving the parameter to its stack locations. And the (Java) caller
760 // of this method has already done that.
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000761 __ StoreToOffset(kStoreWord, calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000762 SP, destination.GetStackIndex());
763 DCHECK_EQ(calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize(),
764 static_cast<size_t>(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000765 } else if (source.IsFpuRegisterPair()) {
766 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
767 SP,
768 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100769 } else {
770 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000771 EmitParallelMoves(
772 Location::StackSlot(source.GetStackIndex()),
773 Location::StackSlot(destination.GetStackIndex()),
774 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
775 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100776 }
777 }
778}
779
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100780void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100781 LocationSummary* locations = instruction->GetLocations();
782 if (locations != nullptr && locations->Out().Equals(location)) {
783 return;
784 }
785
Calin Juravlea21f5982014-11-13 15:53:04 +0000786 if (locations != nullptr && locations->Out().IsConstant()) {
787 HConstant* const_to_move = locations->Out().GetConstant();
788 if (const_to_move->IsIntConstant()) {
789 int32_t value = const_to_move->AsIntConstant()->GetValue();
790 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000791 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000792 } else {
793 DCHECK(location.IsStackSlot());
794 __ LoadImmediate(IP, value);
795 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
796 }
797 } else if (const_to_move->IsLongConstant()) {
798 int64_t value = const_to_move->AsLongConstant()->GetValue();
799 if (location.IsRegisterPair()) {
800 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
801 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
802 } else {
803 DCHECK(location.IsDoubleStackSlot());
804 __ LoadImmediate(IP, Low32Bits(value));
805 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
806 __ LoadImmediate(IP, High32Bits(value));
807 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
808 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100809 }
Roland Levillain476df552014-10-09 17:51:36 +0100810 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100811 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
812 switch (instruction->GetType()) {
813 case Primitive::kPrimBoolean:
814 case Primitive::kPrimByte:
815 case Primitive::kPrimChar:
816 case Primitive::kPrimShort:
817 case Primitive::kPrimInt:
818 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100819 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100820 Move32(location, Location::StackSlot(stack_slot));
821 break;
822
823 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100824 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100825 Move64(location, Location::DoubleStackSlot(stack_slot));
826 break;
827
828 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100829 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100830 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000831 } else if (instruction->IsTemporary()) {
832 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000833 if (temp_location.IsStackSlot()) {
834 Move32(location, temp_location);
835 } else {
836 DCHECK(temp_location.IsDoubleStackSlot());
837 Move64(location, temp_location);
838 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000839 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100840 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100841 switch (instruction->GetType()) {
842 case Primitive::kPrimBoolean:
843 case Primitive::kPrimByte:
844 case Primitive::kPrimChar:
845 case Primitive::kPrimShort:
846 case Primitive::kPrimNot:
847 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100848 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100849 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100850 break;
851
852 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100853 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100854 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100855 break;
856
857 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100858 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100859 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000860 }
861}
862
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100863void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
864 HInstruction* instruction,
865 uint32_t dex_pc) {
866 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
867 __ blx(LR);
868 RecordPcInfo(instruction, dex_pc);
869 DCHECK(instruction->IsSuspendCheck()
870 || instruction->IsBoundsCheck()
871 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000872 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000873 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100874 || !IsLeafMethod());
875}
876
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000877void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000878 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000879}
880
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000881void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000882 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100883 DCHECK(!successor->IsExitBlock());
884
885 HBasicBlock* block = got->GetBlock();
886 HInstruction* previous = got->GetPrevious();
887
888 HLoopInformation* info = block->GetLoopInformation();
889 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
890 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
891 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
892 return;
893 }
894
895 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
896 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
897 }
898 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000899 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000900 }
901}
902
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000903void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000904 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000905}
906
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000907void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700908 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000909 if (kIsDebugBuild) {
910 __ Comment("Unreachable");
911 __ bkpt(0);
912 }
913}
914
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000915void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100916 LocationSummary* locations =
917 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100918 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100919 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100920 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100921 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000922}
923
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000924void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700925 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100926 if (cond->IsIntConstant()) {
927 // Constant condition, statically compared against 1.
928 int32_t cond_value = cond->AsIntConstant()->GetValue();
929 if (cond_value == 1) {
930 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
931 if_instr->IfTrueSuccessor())) {
932 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100933 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100934 return;
935 } else {
936 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100937 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100938 } else {
939 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
940 // Condition has been materialized, compare the output to 0
941 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000942 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100943 ShifterOperand(0));
944 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
945 } else {
946 // Condition has not been materialized, use its inputs as the
947 // comparison and its condition as the branch condition.
948 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000949 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100950 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000951 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100952 } else {
953 DCHECK(locations->InAt(1).IsConstant());
954 int32_t value =
955 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
956 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000957 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
958 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100959 } else {
960 Register temp = IP;
961 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000962 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100963 }
964 }
965 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
966 ARMCondition(cond->AsCondition()->GetCondition()));
967 }
Dave Allison20dfc792014-06-16 20:44:29 -0700968 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100969 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
970 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700971 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000972 }
973}
974
Dave Allison20dfc792014-06-16 20:44:29 -0700975
976void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100977 LocationSummary* locations =
978 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100979 locations->SetInAt(0, Location::RequiresRegister());
980 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100981 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100982 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100983 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000984}
985
Dave Allison20dfc792014-06-16 20:44:29 -0700986void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100987 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100988 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000989 Register left = locations->InAt(0).AsRegister<Register>();
990
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100991 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000992 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100993 } else {
994 DCHECK(locations->InAt(1).IsConstant());
995 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
996 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000997 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
998 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100999 } else {
1000 Register temp = IP;
1001 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001002 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001003 }
Dave Allison20dfc792014-06-16 20:44:29 -07001004 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001005 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001006 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001007 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001008 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001009 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001010}
1011
1012void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1013 VisitCondition(comp);
1014}
1015
1016void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1017 VisitCondition(comp);
1018}
1019
1020void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1021 VisitCondition(comp);
1022}
1023
1024void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1025 VisitCondition(comp);
1026}
1027
1028void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1029 VisitCondition(comp);
1030}
1031
1032void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1033 VisitCondition(comp);
1034}
1035
1036void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1037 VisitCondition(comp);
1038}
1039
1040void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1041 VisitCondition(comp);
1042}
1043
1044void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1045 VisitCondition(comp);
1046}
1047
1048void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1049 VisitCondition(comp);
1050}
1051
1052void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1053 VisitCondition(comp);
1054}
1055
1056void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1057 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001058}
1059
1060void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001061 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001062}
1063
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001064void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1065 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001066}
1067
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001068void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001069 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001070}
1071
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001072void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001073 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001074 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001075}
1076
1077void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001078 LocationSummary* locations =
1079 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001080 switch (store->InputAt(1)->GetType()) {
1081 case Primitive::kPrimBoolean:
1082 case Primitive::kPrimByte:
1083 case Primitive::kPrimChar:
1084 case Primitive::kPrimShort:
1085 case Primitive::kPrimInt:
1086 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001087 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001088 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1089 break;
1090
1091 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001092 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001093 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1094 break;
1095
1096 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001097 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001098 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001099}
1100
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001101void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001102 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001103}
1104
1105void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001106 LocationSummary* locations =
1107 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001108 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001109}
1110
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001111void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001112 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001113 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001114}
1115
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001116void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001117 LocationSummary* locations =
1118 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001119 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001120}
1121
1122void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1123 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001124 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001125}
1126
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001127void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1128 LocationSummary* locations =
1129 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1130 locations->SetOut(Location::ConstantLocation(constant));
1131}
1132
1133void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1134 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001135 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001136}
1137
1138void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1139 LocationSummary* locations =
1140 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1141 locations->SetOut(Location::ConstantLocation(constant));
1142}
1143
1144void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1145 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001146 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001147}
1148
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001149void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001150 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001151}
1152
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001153void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001154 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001155 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001156}
1157
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001158void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001159 LocationSummary* locations =
1160 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001161 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001162}
1163
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001164void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001165 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001166 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001167}
1168
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001169void LocationsBuilderARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001170 HandleInvoke(invoke);
1171}
1172
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001173void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001174 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001175}
1176
1177void InstructionCodeGeneratorARM::VisitInvokeStatic(HInvokeStatic* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001178 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001179
1180 // TODO: Implement all kinds of calls:
1181 // 1) boot -> boot
1182 // 2) app -> boot
1183 // 3) app -> app
1184 //
1185 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1186
1187 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001188 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001189 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001190 __ LoadFromOffset(
1191 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001192 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001193 __ LoadFromOffset(
1194 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001195 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001196 __ LoadFromOffset(kLoadWord, LR, temp,
Mathieu Chartier2d721012014-11-10 11:08:06 -08001197 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001198 kArmWordSize).Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001199 // LR()
1200 __ blx(LR);
1201
1202 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1203 DCHECK(!codegen_->IsLeafMethod());
1204}
1205
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001206void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001207 LocationSummary* locations =
1208 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001209 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001210
1211 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001212 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001213 HInstruction* input = invoke->InputAt(i);
1214 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1215 }
1216
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001217 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001218}
1219
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001220void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1221 HandleInvoke(invoke);
1222}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001223
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001224void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001225 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001226 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1227 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1228 LocationSummary* locations = invoke->GetLocations();
1229 Location receiver = locations->InAt(0);
1230 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1231 // temp = object->GetClass();
1232 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001233 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1234 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001235 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001236 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001237 }
1238 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001239 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001240 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001241 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001242 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001243 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001244 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001245 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001246 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001247 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001248}
1249
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001250void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1251 HandleInvoke(invoke);
1252 // Add the hidden argument.
1253 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1254}
1255
1256void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1257 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001258 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001259 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1260 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1261 LocationSummary* locations = invoke->GetLocations();
1262 Location receiver = locations->InAt(0);
1263 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1264
1265 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001266 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1267 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001268
1269 // temp = object->GetClass();
1270 if (receiver.IsStackSlot()) {
1271 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1272 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1273 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001274 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001275 }
1276 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001277 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001278 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001279 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1280 // LR = temp->GetEntryPoint();
1281 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1282 // LR();
1283 __ blx(LR);
1284 DCHECK(!codegen_->IsLeafMethod());
1285 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1286}
1287
Roland Levillain88cb1752014-10-20 16:36:47 +01001288void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1289 LocationSummary* locations =
1290 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1291 switch (neg->GetResultType()) {
1292 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001293 case Primitive::kPrimLong: {
1294 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001295 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001296 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001297 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001298 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001299
Roland Levillain88cb1752014-10-20 16:36:47 +01001300 case Primitive::kPrimFloat:
1301 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001302 locations->SetInAt(0, Location::RequiresFpuRegister());
1303 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001304 break;
1305
1306 default:
1307 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1308 }
1309}
1310
1311void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1312 LocationSummary* locations = neg->GetLocations();
1313 Location out = locations->Out();
1314 Location in = locations->InAt(0);
1315 switch (neg->GetResultType()) {
1316 case Primitive::kPrimInt:
1317 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001318 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001319 break;
1320
1321 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001322 DCHECK(in.IsRegisterPair());
1323 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1324 __ rsbs(out.AsRegisterPairLow<Register>(),
1325 in.AsRegisterPairLow<Register>(),
1326 ShifterOperand(0));
1327 // We cannot emit an RSC (Reverse Subtract with Carry)
1328 // instruction here, as it does not exist in the Thumb-2
1329 // instruction set. We use the following approach
1330 // using SBC and SUB instead.
1331 //
1332 // out.hi = -C
1333 __ sbc(out.AsRegisterPairHigh<Register>(),
1334 out.AsRegisterPairHigh<Register>(),
1335 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1336 // out.hi = out.hi - in.hi
1337 __ sub(out.AsRegisterPairHigh<Register>(),
1338 out.AsRegisterPairHigh<Register>(),
1339 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1340 break;
1341
Roland Levillain88cb1752014-10-20 16:36:47 +01001342 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001343 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001344 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001345 break;
1346
Roland Levillain88cb1752014-10-20 16:36:47 +01001347 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001348 DCHECK(in.IsFpuRegisterPair());
1349 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1350 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001351 break;
1352
1353 default:
1354 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1355 }
1356}
1357
Roland Levillaindff1f282014-11-05 14:15:05 +00001358void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001359 Primitive::Type result_type = conversion->GetResultType();
1360 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001361 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001362
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001363 // The float-to-long and double-to-long type conversions rely on a
1364 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001365 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001366 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1367 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001368 ? LocationSummary::kCall
1369 : LocationSummary::kNoCall;
1370 LocationSummary* locations =
1371 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1372
Roland Levillaindff1f282014-11-05 14:15:05 +00001373 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001374 case Primitive::kPrimByte:
1375 switch (input_type) {
1376 case Primitive::kPrimShort:
1377 case Primitive::kPrimInt:
1378 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001379 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001380 locations->SetInAt(0, Location::RequiresRegister());
1381 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1382 break;
1383
1384 default:
1385 LOG(FATAL) << "Unexpected type conversion from " << input_type
1386 << " to " << result_type;
1387 }
1388 break;
1389
Roland Levillain01a8d712014-11-14 16:27:39 +00001390 case Primitive::kPrimShort:
1391 switch (input_type) {
1392 case Primitive::kPrimByte:
1393 case Primitive::kPrimInt:
1394 case Primitive::kPrimChar:
1395 // Processing a Dex `int-to-short' instruction.
1396 locations->SetInAt(0, Location::RequiresRegister());
1397 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1398 break;
1399
1400 default:
1401 LOG(FATAL) << "Unexpected type conversion from " << input_type
1402 << " to " << result_type;
1403 }
1404 break;
1405
Roland Levillain946e1432014-11-11 17:35:19 +00001406 case Primitive::kPrimInt:
1407 switch (input_type) {
1408 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001409 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001410 locations->SetInAt(0, Location::Any());
1411 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1412 break;
1413
1414 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001415 // Processing a Dex `float-to-int' instruction.
1416 locations->SetInAt(0, Location::RequiresFpuRegister());
1417 locations->SetOut(Location::RequiresRegister());
1418 locations->AddTemp(Location::RequiresFpuRegister());
1419 break;
1420
Roland Levillain946e1432014-11-11 17:35:19 +00001421 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001422 // Processing a Dex `double-to-int' instruction.
1423 locations->SetInAt(0, Location::RequiresFpuRegister());
1424 locations->SetOut(Location::RequiresRegister());
1425 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001426 break;
1427
1428 default:
1429 LOG(FATAL) << "Unexpected type conversion from " << input_type
1430 << " to " << result_type;
1431 }
1432 break;
1433
Roland Levillaindff1f282014-11-05 14:15:05 +00001434 case Primitive::kPrimLong:
1435 switch (input_type) {
1436 case Primitive::kPrimByte:
1437 case Primitive::kPrimShort:
1438 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001439 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001440 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001441 locations->SetInAt(0, Location::RequiresRegister());
1442 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1443 break;
1444
Roland Levillain624279f2014-12-04 11:54:28 +00001445 case Primitive::kPrimFloat: {
1446 // Processing a Dex `float-to-long' instruction.
1447 InvokeRuntimeCallingConvention calling_convention;
1448 locations->SetInAt(0, Location::FpuRegisterLocation(
1449 calling_convention.GetFpuRegisterAt(0)));
1450 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1451 break;
1452 }
1453
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001454 case Primitive::kPrimDouble: {
1455 // Processing a Dex `double-to-long' instruction.
1456 InvokeRuntimeCallingConvention calling_convention;
1457 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1458 calling_convention.GetFpuRegisterAt(0),
1459 calling_convention.GetFpuRegisterAt(1)));
1460 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001461 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001462 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001463
1464 default:
1465 LOG(FATAL) << "Unexpected type conversion from " << input_type
1466 << " to " << result_type;
1467 }
1468 break;
1469
Roland Levillain981e4542014-11-14 11:47:14 +00001470 case Primitive::kPrimChar:
1471 switch (input_type) {
1472 case Primitive::kPrimByte:
1473 case Primitive::kPrimShort:
1474 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001475 // Processing a Dex `int-to-char' instruction.
1476 locations->SetInAt(0, Location::RequiresRegister());
1477 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1478 break;
1479
1480 default:
1481 LOG(FATAL) << "Unexpected type conversion from " << input_type
1482 << " to " << result_type;
1483 }
1484 break;
1485
Roland Levillaindff1f282014-11-05 14:15:05 +00001486 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001487 switch (input_type) {
1488 case Primitive::kPrimByte:
1489 case Primitive::kPrimShort:
1490 case Primitive::kPrimInt:
1491 case Primitive::kPrimChar:
1492 // Processing a Dex `int-to-float' instruction.
1493 locations->SetInAt(0, Location::RequiresRegister());
1494 locations->SetOut(Location::RequiresFpuRegister());
1495 break;
1496
1497 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001498 // Processing a Dex `long-to-float' instruction.
1499 locations->SetInAt(0, Location::RequiresRegister());
1500 locations->SetOut(Location::RequiresFpuRegister());
1501 locations->AddTemp(Location::RequiresRegister());
1502 locations->AddTemp(Location::RequiresRegister());
1503 locations->AddTemp(Location::RequiresFpuRegister());
1504 locations->AddTemp(Location::RequiresFpuRegister());
1505 break;
1506
Roland Levillaincff13742014-11-17 14:32:17 +00001507 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001508 // Processing a Dex `double-to-float' instruction.
1509 locations->SetInAt(0, Location::RequiresFpuRegister());
1510 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001511 break;
1512
1513 default:
1514 LOG(FATAL) << "Unexpected type conversion from " << input_type
1515 << " to " << result_type;
1516 };
1517 break;
1518
Roland Levillaindff1f282014-11-05 14:15:05 +00001519 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001520 switch (input_type) {
1521 case Primitive::kPrimByte:
1522 case Primitive::kPrimShort:
1523 case Primitive::kPrimInt:
1524 case Primitive::kPrimChar:
1525 // Processing a Dex `int-to-double' instruction.
1526 locations->SetInAt(0, Location::RequiresRegister());
1527 locations->SetOut(Location::RequiresFpuRegister());
1528 break;
1529
1530 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001531 // Processing a Dex `long-to-double' instruction.
1532 locations->SetInAt(0, Location::RequiresRegister());
1533 locations->SetOut(Location::RequiresFpuRegister());
1534 locations->AddTemp(Location::RequiresRegister());
1535 locations->AddTemp(Location::RequiresRegister());
1536 locations->AddTemp(Location::RequiresFpuRegister());
1537 break;
1538
Roland Levillaincff13742014-11-17 14:32:17 +00001539 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001540 // Processing a Dex `float-to-double' instruction.
1541 locations->SetInAt(0, Location::RequiresFpuRegister());
1542 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001543 break;
1544
1545 default:
1546 LOG(FATAL) << "Unexpected type conversion from " << input_type
1547 << " to " << result_type;
1548 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001549 break;
1550
1551 default:
1552 LOG(FATAL) << "Unexpected type conversion from " << input_type
1553 << " to " << result_type;
1554 }
1555}
1556
1557void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1558 LocationSummary* locations = conversion->GetLocations();
1559 Location out = locations->Out();
1560 Location in = locations->InAt(0);
1561 Primitive::Type result_type = conversion->GetResultType();
1562 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001563 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001564 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001565 case Primitive::kPrimByte:
1566 switch (input_type) {
1567 case Primitive::kPrimShort:
1568 case Primitive::kPrimInt:
1569 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001570 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001571 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001572 break;
1573
1574 default:
1575 LOG(FATAL) << "Unexpected type conversion from " << input_type
1576 << " to " << result_type;
1577 }
1578 break;
1579
Roland Levillain01a8d712014-11-14 16:27:39 +00001580 case Primitive::kPrimShort:
1581 switch (input_type) {
1582 case Primitive::kPrimByte:
1583 case Primitive::kPrimInt:
1584 case Primitive::kPrimChar:
1585 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001586 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001587 break;
1588
1589 default:
1590 LOG(FATAL) << "Unexpected type conversion from " << input_type
1591 << " to " << result_type;
1592 }
1593 break;
1594
Roland Levillain946e1432014-11-11 17:35:19 +00001595 case Primitive::kPrimInt:
1596 switch (input_type) {
1597 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001598 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001599 DCHECK(out.IsRegister());
1600 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001601 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001602 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001603 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001604 } else {
1605 DCHECK(in.IsConstant());
1606 DCHECK(in.GetConstant()->IsLongConstant());
1607 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001608 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001609 }
1610 break;
1611
Roland Levillain3f8f9362014-12-02 17:45:01 +00001612 case Primitive::kPrimFloat: {
1613 // Processing a Dex `float-to-int' instruction.
1614 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1615 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1616 __ vcvtis(temp, temp);
1617 __ vmovrs(out.AsRegister<Register>(), temp);
1618 break;
1619 }
1620
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001621 case Primitive::kPrimDouble: {
1622 // Processing a Dex `double-to-int' instruction.
1623 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1624 DRegister temp_d = FromLowSToD(temp_s);
1625 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1626 __ vcvtid(temp_s, temp_d);
1627 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001628 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001629 }
Roland Levillain946e1432014-11-11 17:35:19 +00001630
1631 default:
1632 LOG(FATAL) << "Unexpected type conversion from " << input_type
1633 << " to " << result_type;
1634 }
1635 break;
1636
Roland Levillaindff1f282014-11-05 14:15:05 +00001637 case Primitive::kPrimLong:
1638 switch (input_type) {
1639 case Primitive::kPrimByte:
1640 case Primitive::kPrimShort:
1641 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001642 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001643 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001644 DCHECK(out.IsRegisterPair());
1645 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001646 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001647 // Sign extension.
1648 __ Asr(out.AsRegisterPairHigh<Register>(),
1649 out.AsRegisterPairLow<Register>(),
1650 31);
1651 break;
1652
1653 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001654 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001655 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1656 conversion,
1657 conversion->GetDexPc());
1658 break;
1659
Roland Levillaindff1f282014-11-05 14:15:05 +00001660 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001661 // Processing a Dex `double-to-long' instruction.
1662 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1663 conversion,
1664 conversion->GetDexPc());
Roland Levillaindff1f282014-11-05 14:15:05 +00001665 break;
1666
1667 default:
1668 LOG(FATAL) << "Unexpected type conversion from " << input_type
1669 << " to " << result_type;
1670 }
1671 break;
1672
Roland Levillain981e4542014-11-14 11:47:14 +00001673 case Primitive::kPrimChar:
1674 switch (input_type) {
1675 case Primitive::kPrimByte:
1676 case Primitive::kPrimShort:
1677 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001678 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001679 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001680 break;
1681
1682 default:
1683 LOG(FATAL) << "Unexpected type conversion from " << input_type
1684 << " to " << result_type;
1685 }
1686 break;
1687
Roland Levillaindff1f282014-11-05 14:15:05 +00001688 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001689 switch (input_type) {
1690 case Primitive::kPrimByte:
1691 case Primitive::kPrimShort:
1692 case Primitive::kPrimInt:
1693 case Primitive::kPrimChar: {
1694 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001695 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1696 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001697 break;
1698 }
1699
Roland Levillain6d0e4832014-11-27 18:31:21 +00001700 case Primitive::kPrimLong: {
1701 // Processing a Dex `long-to-float' instruction.
1702 Register low = in.AsRegisterPairLow<Register>();
1703 Register high = in.AsRegisterPairHigh<Register>();
1704 SRegister output = out.AsFpuRegister<SRegister>();
1705 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1706 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1707 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1708 DRegister temp1_d = FromLowSToD(temp1_s);
1709 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1710 DRegister temp2_d = FromLowSToD(temp2_s);
1711
1712 // Operations use doubles for precision reasons (each 32-bit
1713 // half of a long fits in the 53-bit mantissa of a double,
1714 // but not in the 24-bit mantissa of a float). This is
1715 // especially important for the low bits. The result is
1716 // eventually converted to float.
1717
1718 // temp1_d = int-to-double(high)
1719 __ vmovsr(temp1_s, high);
1720 __ vcvtdi(temp1_d, temp1_s);
1721 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1722 // as an immediate value into `temp2_d` does not work, as
1723 // this instruction only transfers 8 significant bits of its
1724 // immediate operand. Instead, use two 32-bit core
1725 // registers to load `k2Pow32EncodingForDouble` into
1726 // `temp2_d`.
1727 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1728 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1729 __ vmovdrr(temp2_d, constant_low, constant_high);
1730 // temp1_d = temp1_d * 2^32
1731 __ vmuld(temp1_d, temp1_d, temp2_d);
1732 // temp2_d = unsigned-to-double(low)
1733 __ vmovsr(temp2_s, low);
1734 __ vcvtdu(temp2_d, temp2_s);
1735 // temp1_d = temp1_d + temp2_d
1736 __ vaddd(temp1_d, temp1_d, temp2_d);
1737 // output = double-to-float(temp1_d);
1738 __ vcvtsd(output, temp1_d);
1739 break;
1740 }
1741
Roland Levillaincff13742014-11-17 14:32:17 +00001742 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001743 // Processing a Dex `double-to-float' instruction.
1744 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1745 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001746 break;
1747
1748 default:
1749 LOG(FATAL) << "Unexpected type conversion from " << input_type
1750 << " to " << result_type;
1751 };
1752 break;
1753
Roland Levillaindff1f282014-11-05 14:15:05 +00001754 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001755 switch (input_type) {
1756 case Primitive::kPrimByte:
1757 case Primitive::kPrimShort:
1758 case Primitive::kPrimInt:
1759 case Primitive::kPrimChar: {
1760 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001761 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001762 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1763 out.AsFpuRegisterPairLow<SRegister>());
1764 break;
1765 }
1766
Roland Levillain647b9ed2014-11-27 12:06:00 +00001767 case Primitive::kPrimLong: {
1768 // Processing a Dex `long-to-double' instruction.
1769 Register low = in.AsRegisterPairLow<Register>();
1770 Register high = in.AsRegisterPairHigh<Register>();
1771 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1772 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001773 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1774 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001775 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1776 DRegister temp_d = FromLowSToD(temp_s);
1777
Roland Levillain647b9ed2014-11-27 12:06:00 +00001778 // out_d = int-to-double(high)
1779 __ vmovsr(out_s, high);
1780 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001781 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1782 // as an immediate value into `temp_d` does not work, as
1783 // this instruction only transfers 8 significant bits of its
1784 // immediate operand. Instead, use two 32-bit core
1785 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1786 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1787 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001788 __ vmovdrr(temp_d, constant_low, constant_high);
1789 // out_d = out_d * 2^32
1790 __ vmuld(out_d, out_d, temp_d);
1791 // temp_d = unsigned-to-double(low)
1792 __ vmovsr(temp_s, low);
1793 __ vcvtdu(temp_d, temp_s);
1794 // out_d = out_d + temp_d
1795 __ vaddd(out_d, out_d, temp_d);
1796 break;
1797 }
1798
Roland Levillaincff13742014-11-17 14:32:17 +00001799 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001800 // Processing a Dex `float-to-double' instruction.
1801 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1802 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001803 break;
1804
1805 default:
1806 LOG(FATAL) << "Unexpected type conversion from " << input_type
1807 << " to " << result_type;
1808 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001809 break;
1810
1811 default:
1812 LOG(FATAL) << "Unexpected type conversion from " << input_type
1813 << " to " << result_type;
1814 }
1815}
1816
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001817void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001818 LocationSummary* locations =
1819 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001820 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001821 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001822 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001823 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1824 locations->SetInAt(0, Location::RequiresRegister());
1825 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1826 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001827 break;
1828 }
1829
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001830 case Primitive::kPrimFloat:
1831 case Primitive::kPrimDouble: {
1832 locations->SetInAt(0, Location::RequiresFpuRegister());
1833 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001834 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001835 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001836 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001837
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001838 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001839 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001840 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001841}
1842
1843void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1844 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001845 Location out = locations->Out();
1846 Location first = locations->InAt(0);
1847 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001848 switch (add->GetResultType()) {
1849 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001850 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001851 __ add(out.AsRegister<Register>(),
1852 first.AsRegister<Register>(),
1853 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001854 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001855 __ AddConstant(out.AsRegister<Register>(),
1856 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001857 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001858 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001859 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001860
1861 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001862 __ adds(out.AsRegisterPairLow<Register>(),
1863 first.AsRegisterPairLow<Register>(),
1864 ShifterOperand(second.AsRegisterPairLow<Register>()));
1865 __ adc(out.AsRegisterPairHigh<Register>(),
1866 first.AsRegisterPairHigh<Register>(),
1867 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001868 break;
1869
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001870 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001871 __ vadds(out.AsFpuRegister<SRegister>(),
1872 first.AsFpuRegister<SRegister>(),
1873 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001874 break;
1875
1876 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001877 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1878 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1879 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001880 break;
1881
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001882 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001883 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001884 }
1885}
1886
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001887void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001888 LocationSummary* locations =
1889 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001890 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001891 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001892 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001893 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1894 locations->SetInAt(0, Location::RequiresRegister());
1895 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1896 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001897 break;
1898 }
Calin Juravle11351682014-10-23 15:38:15 +01001899 case Primitive::kPrimFloat:
1900 case Primitive::kPrimDouble: {
1901 locations->SetInAt(0, Location::RequiresFpuRegister());
1902 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001903 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001904 break;
Calin Juravle11351682014-10-23 15:38:15 +01001905 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001906 default:
Calin Juravle11351682014-10-23 15:38:15 +01001907 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001908 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001909}
1910
1911void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1912 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001913 Location out = locations->Out();
1914 Location first = locations->InAt(0);
1915 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001916 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001917 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001918 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001919 __ sub(out.AsRegister<Register>(),
1920 first.AsRegister<Register>(),
1921 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001922 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001923 __ AddConstant(out.AsRegister<Register>(),
1924 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001925 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001926 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001927 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001928 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001929
Calin Juravle11351682014-10-23 15:38:15 +01001930 case Primitive::kPrimLong: {
1931 __ subs(out.AsRegisterPairLow<Register>(),
1932 first.AsRegisterPairLow<Register>(),
1933 ShifterOperand(second.AsRegisterPairLow<Register>()));
1934 __ sbc(out.AsRegisterPairHigh<Register>(),
1935 first.AsRegisterPairHigh<Register>(),
1936 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001937 break;
Calin Juravle11351682014-10-23 15:38:15 +01001938 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001939
Calin Juravle11351682014-10-23 15:38:15 +01001940 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001941 __ vsubs(out.AsFpuRegister<SRegister>(),
1942 first.AsFpuRegister<SRegister>(),
1943 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001944 break;
Calin Juravle11351682014-10-23 15:38:15 +01001945 }
1946
1947 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001948 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1949 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1950 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001951 break;
1952 }
1953
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001954
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001955 default:
Calin Juravle11351682014-10-23 15:38:15 +01001956 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001957 }
1958}
1959
Calin Juravle34bacdf2014-10-07 20:23:36 +01001960void LocationsBuilderARM::VisitMul(HMul* mul) {
1961 LocationSummary* locations =
1962 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1963 switch (mul->GetResultType()) {
1964 case Primitive::kPrimInt:
1965 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001966 locations->SetInAt(0, Location::RequiresRegister());
1967 locations->SetInAt(1, Location::RequiresRegister());
1968 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001969 break;
1970 }
1971
Calin Juravleb5bfa962014-10-21 18:02:24 +01001972 case Primitive::kPrimFloat:
1973 case Primitive::kPrimDouble: {
1974 locations->SetInAt(0, Location::RequiresFpuRegister());
1975 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001976 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001977 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001978 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001979
1980 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001981 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001982 }
1983}
1984
1985void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1986 LocationSummary* locations = mul->GetLocations();
1987 Location out = locations->Out();
1988 Location first = locations->InAt(0);
1989 Location second = locations->InAt(1);
1990 switch (mul->GetResultType()) {
1991 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00001992 __ mul(out.AsRegister<Register>(),
1993 first.AsRegister<Register>(),
1994 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001995 break;
1996 }
1997 case Primitive::kPrimLong: {
1998 Register out_hi = out.AsRegisterPairHigh<Register>();
1999 Register out_lo = out.AsRegisterPairLow<Register>();
2000 Register in1_hi = first.AsRegisterPairHigh<Register>();
2001 Register in1_lo = first.AsRegisterPairLow<Register>();
2002 Register in2_hi = second.AsRegisterPairHigh<Register>();
2003 Register in2_lo = second.AsRegisterPairLow<Register>();
2004
2005 // Extra checks to protect caused by the existence of R1_R2.
2006 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2007 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2008 DCHECK_NE(out_hi, in1_lo);
2009 DCHECK_NE(out_hi, in2_lo);
2010
2011 // input: in1 - 64 bits, in2 - 64 bits
2012 // output: out
2013 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2014 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2015 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2016
2017 // IP <- in1.lo * in2.hi
2018 __ mul(IP, in1_lo, in2_hi);
2019 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2020 __ mla(out_hi, in1_hi, in2_lo, IP);
2021 // out.lo <- (in1.lo * in2.lo)[31:0];
2022 __ umull(out_lo, IP, in1_lo, in2_lo);
2023 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2024 __ add(out_hi, out_hi, ShifterOperand(IP));
2025 break;
2026 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002027
2028 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002029 __ vmuls(out.AsFpuRegister<SRegister>(),
2030 first.AsFpuRegister<SRegister>(),
2031 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002032 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002033 }
2034
2035 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002036 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2037 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2038 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002039 break;
2040 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002041
2042 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002043 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002044 }
2045}
2046
Calin Juravle7c4954d2014-10-28 16:57:40 +00002047void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002048 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2049 ? LocationSummary::kCall
2050 : LocationSummary::kNoCall;
2051 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2052
Calin Juravle7c4954d2014-10-28 16:57:40 +00002053 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002054 case Primitive::kPrimInt: {
2055 locations->SetInAt(0, Location::RequiresRegister());
2056 locations->SetInAt(1, Location::RequiresRegister());
2057 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2058 break;
2059 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002060 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002061 InvokeRuntimeCallingConvention calling_convention;
2062 locations->SetInAt(0, Location::RegisterPairLocation(
2063 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2064 locations->SetInAt(1, Location::RegisterPairLocation(
2065 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2066 // The runtime helper puts the output in R0,R2.
2067 locations->SetOut(Location::RegisterPairLocation(R0, R2));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002068 break;
2069 }
2070 case Primitive::kPrimFloat:
2071 case Primitive::kPrimDouble: {
2072 locations->SetInAt(0, Location::RequiresFpuRegister());
2073 locations->SetInAt(1, Location::RequiresFpuRegister());
2074 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2075 break;
2076 }
2077
2078 default:
2079 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2080 }
2081}
2082
2083void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2084 LocationSummary* locations = div->GetLocations();
2085 Location out = locations->Out();
2086 Location first = locations->InAt(0);
2087 Location second = locations->InAt(1);
2088
2089 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002090 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002091 __ sdiv(out.AsRegister<Register>(),
2092 first.AsRegister<Register>(),
2093 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002094 break;
2095 }
2096
Calin Juravle7c4954d2014-10-28 16:57:40 +00002097 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002098 InvokeRuntimeCallingConvention calling_convention;
2099 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2100 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2101 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2102 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2103 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2104 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2105
2106 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002107 break;
2108 }
2109
2110 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002111 __ vdivs(out.AsFpuRegister<SRegister>(),
2112 first.AsFpuRegister<SRegister>(),
2113 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002114 break;
2115 }
2116
2117 case Primitive::kPrimDouble: {
2118 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2119 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2120 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2121 break;
2122 }
2123
2124 default:
2125 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2126 }
2127}
2128
Calin Juravlebacfec32014-11-14 15:54:36 +00002129void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002130 Primitive::Type type = rem->GetResultType();
2131 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2132 ? LocationSummary::kNoCall
2133 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002134 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2135
Calin Juravled2ec87d2014-12-08 14:24:46 +00002136 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002137 case Primitive::kPrimInt: {
2138 locations->SetInAt(0, Location::RequiresRegister());
2139 locations->SetInAt(1, Location::RequiresRegister());
2140 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2141 locations->AddTemp(Location::RequiresRegister());
2142 break;
2143 }
2144 case Primitive::kPrimLong: {
2145 InvokeRuntimeCallingConvention calling_convention;
2146 locations->SetInAt(0, Location::RegisterPairLocation(
2147 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2148 locations->SetInAt(1, Location::RegisterPairLocation(
2149 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2150 // The runtime helper puts the output in R2,R3.
2151 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2152 break;
2153 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002154 case Primitive::kPrimFloat: {
2155 InvokeRuntimeCallingConvention calling_convention;
2156 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2157 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2158 locations->SetOut(Location::FpuRegisterLocation(S0));
2159 break;
2160 }
2161
Calin Juravlebacfec32014-11-14 15:54:36 +00002162 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002163 InvokeRuntimeCallingConvention calling_convention;
2164 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2165 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2166 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2167 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2168 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002169 break;
2170 }
2171
2172 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002173 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002174 }
2175}
2176
2177void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2178 LocationSummary* locations = rem->GetLocations();
2179 Location out = locations->Out();
2180 Location first = locations->InAt(0);
2181 Location second = locations->InAt(1);
2182
Calin Juravled2ec87d2014-12-08 14:24:46 +00002183 Primitive::Type type = rem->GetResultType();
2184 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002185 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002186 Register reg1 = first.AsRegister<Register>();
2187 Register reg2 = second.AsRegister<Register>();
2188 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002189
2190 // temp = reg1 / reg2 (integer division)
2191 // temp = temp * reg2
2192 // dest = reg1 - temp
2193 __ sdiv(temp, reg1, reg2);
2194 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002195 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002196 break;
2197 }
2198
2199 case Primitive::kPrimLong: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002200 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2201 break;
2202 }
2203
Calin Juravled2ec87d2014-12-08 14:24:46 +00002204 case Primitive::kPrimFloat: {
2205 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc());
2206 break;
2207 }
2208
Calin Juravlebacfec32014-11-14 15:54:36 +00002209 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002210 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc());
Calin Juravlebacfec32014-11-14 15:54:36 +00002211 break;
2212 }
2213
2214 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002215 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002216 }
2217}
2218
Calin Juravled0d48522014-11-04 16:40:20 +00002219void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2220 LocationSummary* locations =
2221 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002222 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002223 if (instruction->HasUses()) {
2224 locations->SetOut(Location::SameAsFirstInput());
2225 }
2226}
2227
2228void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2229 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2230 codegen_->AddSlowPath(slow_path);
2231
2232 LocationSummary* locations = instruction->GetLocations();
2233 Location value = locations->InAt(0);
2234
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002235 switch (instruction->GetType()) {
2236 case Primitive::kPrimInt: {
2237 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002238 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002239 __ b(slow_path->GetEntryLabel(), EQ);
2240 } else {
2241 DCHECK(value.IsConstant()) << value;
2242 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2243 __ b(slow_path->GetEntryLabel());
2244 }
2245 }
2246 break;
2247 }
2248 case Primitive::kPrimLong: {
2249 if (value.IsRegisterPair()) {
2250 __ orrs(IP,
2251 value.AsRegisterPairLow<Register>(),
2252 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2253 __ b(slow_path->GetEntryLabel(), EQ);
2254 } else {
2255 DCHECK(value.IsConstant()) << value;
2256 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2257 __ b(slow_path->GetEntryLabel());
2258 }
2259 }
2260 break;
2261 default:
2262 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2263 }
2264 }
Calin Juravled0d48522014-11-04 16:40:20 +00002265}
2266
Calin Juravle9aec02f2014-11-18 23:06:35 +00002267void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2268 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2269
2270 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2271 ? LocationSummary::kCall
2272 : LocationSummary::kNoCall;
2273 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2274
2275 switch (op->GetResultType()) {
2276 case Primitive::kPrimInt: {
2277 locations->SetInAt(0, Location::RequiresRegister());
2278 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
2279 locations->SetOut(Location::RequiresRegister());
2280 break;
2281 }
2282 case Primitive::kPrimLong: {
2283 InvokeRuntimeCallingConvention calling_convention;
2284 locations->SetInAt(0, Location::RegisterPairLocation(
2285 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2286 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2287 // The runtime helper puts the output in R0,R2.
2288 locations->SetOut(Location::RegisterPairLocation(R0, R2));
2289 break;
2290 }
2291 default:
2292 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2293 }
2294}
2295
2296void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2297 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2298
2299 LocationSummary* locations = op->GetLocations();
2300 Location out = locations->Out();
2301 Location first = locations->InAt(0);
2302 Location second = locations->InAt(1);
2303
2304 Primitive::Type type = op->GetResultType();
2305 switch (type) {
2306 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002307 Register out_reg = out.AsRegister<Register>();
2308 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002309 // Arm doesn't mask the shift count so we need to do it ourselves.
2310 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002311 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002312 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2313 if (op->IsShl()) {
2314 __ Lsl(out_reg, first_reg, second_reg);
2315 } else if (op->IsShr()) {
2316 __ Asr(out_reg, first_reg, second_reg);
2317 } else {
2318 __ Lsr(out_reg, first_reg, second_reg);
2319 }
2320 } else {
2321 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2322 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2323 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2324 __ Mov(out_reg, first_reg);
2325 } else if (op->IsShl()) {
2326 __ Lsl(out_reg, first_reg, shift_value);
2327 } else if (op->IsShr()) {
2328 __ Asr(out_reg, first_reg, shift_value);
2329 } else {
2330 __ Lsr(out_reg, first_reg, shift_value);
2331 }
2332 }
2333 break;
2334 }
2335 case Primitive::kPrimLong: {
2336 // TODO: Inline the assembly instead of calling the runtime.
2337 InvokeRuntimeCallingConvention calling_convention;
2338 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2339 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002340 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002341 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2342 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2343
2344 int32_t entry_point_offset;
2345 if (op->IsShl()) {
2346 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2347 } else if (op->IsShr()) {
2348 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2349 } else {
2350 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2351 }
2352 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2353 __ blx(LR);
2354 break;
2355 }
2356 default:
2357 LOG(FATAL) << "Unexpected operation type " << type;
2358 }
2359}
2360
2361void LocationsBuilderARM::VisitShl(HShl* shl) {
2362 HandleShift(shl);
2363}
2364
2365void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2366 HandleShift(shl);
2367}
2368
2369void LocationsBuilderARM::VisitShr(HShr* shr) {
2370 HandleShift(shr);
2371}
2372
2373void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2374 HandleShift(shr);
2375}
2376
2377void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2378 HandleShift(ushr);
2379}
2380
2381void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2382 HandleShift(ushr);
2383}
2384
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002385void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002386 LocationSummary* locations =
2387 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002388 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002389 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2390 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2391 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002392}
2393
2394void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2395 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002396 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002397 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002398 codegen_->InvokeRuntime(
2399 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002400}
2401
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002402void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2403 LocationSummary* locations =
2404 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2405 InvokeRuntimeCallingConvention calling_convention;
2406 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2407 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2408 locations->SetOut(Location::RegisterLocation(R0));
2409 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2410}
2411
2412void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2413 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002414 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002415 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002416 codegen_->InvokeRuntime(
2417 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002418}
2419
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002420void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002421 LocationSummary* locations =
2422 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002423 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2424 if (location.IsStackSlot()) {
2425 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2426 } else if (location.IsDoubleStackSlot()) {
2427 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002428 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002429 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002430}
2431
2432void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002433 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002434 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002435}
2436
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002437void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002438 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002439 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002440 locations->SetInAt(0, Location::RequiresRegister());
2441 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002442}
2443
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002444void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2445 LocationSummary* locations = not_->GetLocations();
2446 Location out = locations->Out();
2447 Location in = locations->InAt(0);
2448 switch (not_->InputAt(0)->GetType()) {
2449 case Primitive::kPrimBoolean:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002450 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002451 break;
2452
2453 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002454 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002455 break;
2456
2457 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002458 __ mvn(out.AsRegisterPairLow<Register>(),
2459 ShifterOperand(in.AsRegisterPairLow<Register>()));
2460 __ mvn(out.AsRegisterPairHigh<Register>(),
2461 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002462 break;
2463
2464 default:
2465 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2466 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002467}
2468
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002469void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002470 LocationSummary* locations =
2471 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002472 switch (compare->InputAt(0)->GetType()) {
2473 case Primitive::kPrimLong: {
2474 locations->SetInAt(0, Location::RequiresRegister());
2475 locations->SetInAt(1, Location::RequiresRegister());
2476 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2477 break;
2478 }
2479 case Primitive::kPrimFloat:
2480 case Primitive::kPrimDouble: {
2481 locations->SetInAt(0, Location::RequiresFpuRegister());
2482 locations->SetInAt(1, Location::RequiresFpuRegister());
2483 locations->SetOut(Location::RequiresRegister());
2484 break;
2485 }
2486 default:
2487 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2488 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002489}
2490
2491void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002492 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002493 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002494 Location left = locations->InAt(0);
2495 Location right = locations->InAt(1);
2496
2497 Label less, greater, done;
2498 Primitive::Type type = compare->InputAt(0)->GetType();
2499 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002500 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002501 __ cmp(left.AsRegisterPairHigh<Register>(),
2502 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002503 __ b(&less, LT);
2504 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002505 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2506 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002507 __ cmp(left.AsRegisterPairLow<Register>(),
2508 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002509 break;
2510 }
2511 case Primitive::kPrimFloat:
2512 case Primitive::kPrimDouble: {
2513 __ LoadImmediate(out, 0);
2514 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002515 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002516 } else {
2517 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2518 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2519 }
2520 __ vmstat(); // transfer FP status register to ARM APSR.
2521 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002522 break;
2523 }
2524 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002525 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002526 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002527 __ b(&done, EQ);
2528 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2529
2530 __ Bind(&greater);
2531 __ LoadImmediate(out, 1);
2532 __ b(&done);
2533
2534 __ Bind(&less);
2535 __ LoadImmediate(out, -1);
2536
2537 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002538}
2539
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002540void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002541 LocationSummary* locations =
2542 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002543 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2544 locations->SetInAt(i, Location::Any());
2545 }
2546 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002547}
2548
2549void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002550 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002551 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002552}
2553
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002554void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002555 LocationSummary* locations =
2556 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002557 bool needs_write_barrier =
2558 CodeGenerator::StoreNeedsWriteBarrier(instruction->GetFieldType(), instruction->GetValue());
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002559 locations->SetInAt(0, Location::RequiresRegister());
2560 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002561 // Temporary registers for the write barrier.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002562 if (needs_write_barrier) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002563 locations->AddTemp(Location::RequiresRegister());
2564 locations->AddTemp(Location::RequiresRegister());
2565 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002566}
2567
2568void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2569 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002570 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002571 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01002572 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002573
2574 switch (field_type) {
2575 case Primitive::kPrimBoolean:
2576 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002577 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002578 __ StoreToOffset(kStoreByte, value, obj, offset);
2579 break;
2580 }
2581
2582 case Primitive::kPrimShort:
2583 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002584 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002585 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2586 break;
2587 }
2588
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002589 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002590 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002591 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002592 __ StoreToOffset(kStoreWord, value, obj, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002593 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002594 Register temp = locations->GetTemp(0).AsRegister<Register>();
2595 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002596 codegen_->MarkGCCard(temp, card, obj, value);
2597 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002598 break;
2599 }
2600
2601 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002602 Location value = locations->InAt(1);
2603 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002604 break;
2605 }
2606
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002607 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002608 SRegister value = locations->InAt(1).AsFpuRegister<SRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002609 __ StoreSToOffset(value, obj, offset);
2610 break;
2611 }
2612
2613 case Primitive::kPrimDouble: {
2614 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
2615 __ StoreDToOffset(value, obj, offset);
2616 break;
2617 }
2618
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002619 case Primitive::kPrimVoid:
2620 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002621 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002622 }
2623}
2624
2625void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002626 LocationSummary* locations =
2627 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002628 locations->SetInAt(0, Location::RequiresRegister());
2629 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002630}
2631
2632void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2633 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002634 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002635 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2636
2637 switch (instruction->GetType()) {
2638 case Primitive::kPrimBoolean: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002639 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002640 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2641 break;
2642 }
2643
2644 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002645 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002646 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2647 break;
2648 }
2649
2650 case Primitive::kPrimShort: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002651 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002652 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2653 break;
2654 }
2655
2656 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002657 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002658 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2659 break;
2660 }
2661
2662 case Primitive::kPrimInt:
2663 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002664 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002665 __ LoadFromOffset(kLoadWord, out, obj, offset);
2666 break;
2667 }
2668
2669 case Primitive::kPrimLong: {
2670 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002671 Location out = locations->Out();
2672 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002673 break;
2674 }
2675
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002676 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002677 SRegister out = locations->Out().AsFpuRegister<SRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002678 __ LoadSFromOffset(out, obj, offset);
2679 break;
2680 }
2681
2682 case Primitive::kPrimDouble: {
2683 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
2684 __ LoadDFromOffset(out, obj, offset);
2685 break;
2686 }
2687
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002688 case Primitive::kPrimVoid:
2689 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002690 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002691 }
2692}
2693
2694void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002695 LocationSummary* locations =
2696 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002697 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002698 if (instruction->HasUses()) {
2699 locations->SetOut(Location::SameAsFirstInput());
2700 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002701}
2702
2703void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002704 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002705 codegen_->AddSlowPath(slow_path);
2706
2707 LocationSummary* locations = instruction->GetLocations();
2708 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002709
2710 if (obj.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002711 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002712 __ b(slow_path->GetEntryLabel(), EQ);
2713 } else {
2714 DCHECK(obj.IsConstant()) << obj;
2715 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2716 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002717 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002718}
2719
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002720void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002721 LocationSummary* locations =
2722 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002723 locations->SetInAt(0, Location::RequiresRegister());
2724 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2725 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002726}
2727
2728void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2729 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002730 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002731 Location index = locations->InAt(1);
2732
2733 switch (instruction->GetType()) {
2734 case Primitive::kPrimBoolean: {
2735 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002736 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002737 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002738 size_t offset =
2739 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002740 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2741 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002742 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002743 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2744 }
2745 break;
2746 }
2747
2748 case Primitive::kPrimByte: {
2749 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002750 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002751 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002752 size_t offset =
2753 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002754 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2755 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002756 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002757 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2758 }
2759 break;
2760 }
2761
2762 case Primitive::kPrimShort: {
2763 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002764 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002765 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002766 size_t offset =
2767 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002768 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2769 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002770 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002771 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2772 }
2773 break;
2774 }
2775
2776 case Primitive::kPrimChar: {
2777 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002778 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002779 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002780 size_t offset =
2781 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002782 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2783 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002784 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002785 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2786 }
2787 break;
2788 }
2789
2790 case Primitive::kPrimInt:
2791 case Primitive::kPrimNot: {
2792 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2793 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002794 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002795 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002796 size_t offset =
2797 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002798 __ LoadFromOffset(kLoadWord, out, obj, offset);
2799 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002800 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002801 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2802 }
2803 break;
2804 }
2805
2806 case Primitive::kPrimLong: {
2807 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002808 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002809 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002810 size_t offset =
2811 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002812 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002813 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002814 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002815 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002816 }
2817 break;
2818 }
2819
2820 case Primitive::kPrimFloat:
2821 case Primitive::kPrimDouble:
2822 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002823 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002824 case Primitive::kPrimVoid:
2825 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002826 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002827 }
2828}
2829
2830void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002831 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002832
2833 bool needs_write_barrier =
2834 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
2835 bool needs_runtime_call = instruction->NeedsTypeCheck();
2836
Nicolas Geoffray39468442014-09-02 15:17:15 +01002837 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002838 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
2839 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002840 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002841 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2842 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2843 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002844 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002845 locations->SetInAt(0, Location::RequiresRegister());
2846 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2847 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002848
2849 if (needs_write_barrier) {
2850 // Temporary registers for the write barrier.
2851 locations->AddTemp(Location::RequiresRegister());
2852 locations->AddTemp(Location::RequiresRegister());
2853 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002854 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002855}
2856
2857void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
2858 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002859 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002860 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002861 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002862 bool needs_runtime_call = locations->WillCall();
2863 bool needs_write_barrier =
2864 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002865
2866 switch (value_type) {
2867 case Primitive::kPrimBoolean:
2868 case Primitive::kPrimByte: {
2869 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002870 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002871 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002872 size_t offset =
2873 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002874 __ StoreToOffset(kStoreByte, value, obj, offset);
2875 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002876 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002877 __ StoreToOffset(kStoreByte, value, IP, data_offset);
2878 }
2879 break;
2880 }
2881
2882 case Primitive::kPrimShort:
2883 case Primitive::kPrimChar: {
2884 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002885 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002886 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002887 size_t offset =
2888 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002889 __ StoreToOffset(kStoreHalfword, value, obj, offset);
2890 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002891 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002892 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
2893 }
2894 break;
2895 }
2896
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002897 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002898 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002899 if (!needs_runtime_call) {
2900 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002901 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002902 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002903 size_t offset =
2904 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002905 __ StoreToOffset(kStoreWord, value, obj, offset);
2906 } else {
2907 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00002908 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002909 __ StoreToOffset(kStoreWord, value, IP, data_offset);
2910 }
2911 if (needs_write_barrier) {
2912 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002913 Register temp = locations->GetTemp(0).AsRegister<Register>();
2914 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002915 codegen_->MarkGCCard(temp, card, obj, value);
2916 }
2917 } else {
2918 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00002919 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
2920 instruction,
2921 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002922 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002923 break;
2924 }
2925
2926 case Primitive::kPrimLong: {
2927 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002928 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002929 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002930 size_t offset =
2931 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002932 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002933 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002934 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002935 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002936 }
2937 break;
2938 }
2939
2940 case Primitive::kPrimFloat:
2941 case Primitive::kPrimDouble:
2942 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002943 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002944 case Primitive::kPrimVoid:
2945 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002946 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002947 }
2948}
2949
2950void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002951 LocationSummary* locations =
2952 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002953 locations->SetInAt(0, Location::RequiresRegister());
2954 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002955}
2956
2957void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
2958 LocationSummary* locations = instruction->GetLocations();
2959 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002960 Register obj = locations->InAt(0).AsRegister<Register>();
2961 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002962 __ LoadFromOffset(kLoadWord, out, obj, offset);
2963}
2964
2965void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002966 LocationSummary* locations =
2967 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002968 locations->SetInAt(0, Location::RequiresRegister());
2969 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002970 if (instruction->HasUses()) {
2971 locations->SetOut(Location::SameAsFirstInput());
2972 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002973}
2974
2975void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
2976 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002977 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002978 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002979 codegen_->AddSlowPath(slow_path);
2980
Roland Levillain271ab9c2014-11-27 15:23:57 +00002981 Register index = locations->InAt(0).AsRegister<Register>();
2982 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002983
2984 __ cmp(index, ShifterOperand(length));
2985 __ b(slow_path->GetEntryLabel(), CS);
2986}
2987
2988void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
2989 Label is_null;
2990 __ CompareAndBranchIfZero(value, &is_null);
2991 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
2992 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
2993 __ strb(card, Address(card, temp));
2994 __ Bind(&is_null);
2995}
2996
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002997void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
2998 temp->SetLocations(nullptr);
2999}
3000
3001void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3002 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003003 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003004}
3005
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003006void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003007 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003008 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003009}
3010
3011void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003012 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3013}
3014
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003015void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3016 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3017}
3018
3019void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003020 HBasicBlock* block = instruction->GetBlock();
3021 if (block->GetLoopInformation() != nullptr) {
3022 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3023 // The back edge will generate the suspend check.
3024 return;
3025 }
3026 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3027 // The goto will generate the suspend check.
3028 return;
3029 }
3030 GenerateSuspendCheck(instruction, nullptr);
3031}
3032
3033void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3034 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003035 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003036 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003037 codegen_->AddSlowPath(slow_path);
3038
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003039 __ LoadFromOffset(
3040 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3041 __ cmp(IP, ShifterOperand(0));
3042 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003043 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003044 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003045 __ Bind(slow_path->GetReturnLabel());
3046 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003047 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003048 __ b(slow_path->GetEntryLabel());
3049 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003050}
3051
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003052ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3053 return codegen_->GetAssembler();
3054}
3055
3056void ParallelMoveResolverARM::EmitMove(size_t index) {
3057 MoveOperands* move = moves_.Get(index);
3058 Location source = move->GetSource();
3059 Location destination = move->GetDestination();
3060
3061 if (source.IsRegister()) {
3062 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003063 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003064 } else {
3065 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003066 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003067 SP, destination.GetStackIndex());
3068 }
3069 } else if (source.IsStackSlot()) {
3070 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003071 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003072 SP, source.GetStackIndex());
3073 } else {
3074 DCHECK(destination.IsStackSlot());
3075 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3076 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3077 }
3078 } else {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003079 DCHECK(source.IsConstant());
Roland Levillain476df552014-10-09 17:51:36 +01003080 DCHECK(source.GetConstant()->IsIntConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003081 int32_t value = source.GetConstant()->AsIntConstant()->GetValue();
3082 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003083 __ LoadImmediate(destination.AsRegister<Register>(), value);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003084 } else {
3085 DCHECK(destination.IsStackSlot());
3086 __ LoadImmediate(IP, value);
Nicolas Geoffray360231a2014-10-08 21:07:48 +01003087 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003088 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003089 }
3090}
3091
3092void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3093 __ Mov(IP, reg);
3094 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3095 __ StoreToOffset(kStoreWord, IP, SP, mem);
3096}
3097
3098void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3099 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3100 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3101 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3102 SP, mem1 + stack_offset);
3103 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3104 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3105 SP, mem2 + stack_offset);
3106 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3107}
3108
3109void ParallelMoveResolverARM::EmitSwap(size_t index) {
3110 MoveOperands* move = moves_.Get(index);
3111 Location source = move->GetSource();
3112 Location destination = move->GetDestination();
3113
3114 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003115 DCHECK_NE(source.AsRegister<Register>(), IP);
3116 DCHECK_NE(destination.AsRegister<Register>(), IP);
3117 __ Mov(IP, source.AsRegister<Register>());
3118 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3119 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003120 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003121 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003122 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003123 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003124 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3125 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3126 } else {
3127 LOG(FATAL) << "Unimplemented";
3128 }
3129}
3130
3131void ParallelMoveResolverARM::SpillScratch(int reg) {
3132 __ Push(static_cast<Register>(reg));
3133}
3134
3135void ParallelMoveResolverARM::RestoreScratch(int reg) {
3136 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003137}
3138
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003139void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003140 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3141 ? LocationSummary::kCallOnSlowPath
3142 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003143 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003144 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003145 locations->SetOut(Location::RequiresRegister());
3146}
3147
3148void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003149 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003150 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003151 DCHECK(!cls->CanCallRuntime());
3152 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003153 codegen_->LoadCurrentMethod(out);
3154 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3155 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003156 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003157 codegen_->LoadCurrentMethod(out);
3158 __ LoadFromOffset(
3159 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3160 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003161
3162 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3163 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3164 codegen_->AddSlowPath(slow_path);
3165 __ cmp(out, ShifterOperand(0));
3166 __ b(slow_path->GetEntryLabel(), EQ);
3167 if (cls->MustGenerateClinitCheck()) {
3168 GenerateClassInitializationCheck(slow_path, out);
3169 } else {
3170 __ Bind(slow_path->GetExitLabel());
3171 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003172 }
3173}
3174
3175void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3176 LocationSummary* locations =
3177 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3178 locations->SetInAt(0, Location::RequiresRegister());
3179 if (check->HasUses()) {
3180 locations->SetOut(Location::SameAsFirstInput());
3181 }
3182}
3183
3184void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003185 // We assume the class is not null.
3186 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3187 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003188 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003189 GenerateClassInitializationCheck(slow_path,
3190 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003191}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003192
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003193void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3194 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003195 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3196 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3197 __ b(slow_path->GetEntryLabel(), LT);
3198 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3199 // properly. Therefore, we do a memory fence.
3200 __ dmb(ISH);
3201 __ Bind(slow_path->GetExitLabel());
3202}
3203
3204void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3205 LocationSummary* locations =
3206 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3207 locations->SetInAt(0, Location::RequiresRegister());
3208 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3209}
3210
3211void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3212 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003213 Register cls = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003214 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
3215
3216 switch (instruction->GetType()) {
3217 case Primitive::kPrimBoolean: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003218 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003219 __ LoadFromOffset(kLoadUnsignedByte, out, cls, offset);
3220 break;
3221 }
3222
3223 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003224 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003225 __ LoadFromOffset(kLoadSignedByte, out, cls, offset);
3226 break;
3227 }
3228
3229 case Primitive::kPrimShort: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003230 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003231 __ LoadFromOffset(kLoadSignedHalfword, out, cls, offset);
3232 break;
3233 }
3234
3235 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003236 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003237 __ LoadFromOffset(kLoadUnsignedHalfword, out, cls, offset);
3238 break;
3239 }
3240
3241 case Primitive::kPrimInt:
3242 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003243 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003244 __ LoadFromOffset(kLoadWord, out, cls, offset);
3245 break;
3246 }
3247
3248 case Primitive::kPrimLong: {
3249 // TODO: support volatile.
3250 Location out = locations->Out();
3251 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), cls, offset);
3252 break;
3253 }
3254
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003255 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003256 SRegister out = locations->Out().AsFpuRegister<SRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003257 __ LoadSFromOffset(out, cls, offset);
3258 break;
3259 }
3260
3261 case Primitive::kPrimDouble: {
3262 DRegister out = FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>());
3263 __ LoadDFromOffset(out, cls, offset);
3264 break;
3265 }
3266
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003267 case Primitive::kPrimVoid:
3268 LOG(FATAL) << "Unreachable type " << instruction->GetType();
3269 UNREACHABLE();
3270 }
3271}
3272
3273void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3274 LocationSummary* locations =
3275 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003276 bool needs_write_barrier =
3277 CodeGenerator::StoreNeedsWriteBarrier(instruction->GetFieldType(), instruction->GetValue());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003278 locations->SetInAt(0, Location::RequiresRegister());
3279 locations->SetInAt(1, Location::RequiresRegister());
3280 // Temporary registers for the write barrier.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003281 if (needs_write_barrier) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003282 locations->AddTemp(Location::RequiresRegister());
3283 locations->AddTemp(Location::RequiresRegister());
3284 }
3285}
3286
3287void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3288 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003289 Register cls = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003290 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
3291 Primitive::Type field_type = instruction->GetFieldType();
3292
3293 switch (field_type) {
3294 case Primitive::kPrimBoolean:
3295 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003296 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003297 __ StoreToOffset(kStoreByte, value, cls, offset);
3298 break;
3299 }
3300
3301 case Primitive::kPrimShort:
3302 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003303 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003304 __ StoreToOffset(kStoreHalfword, value, cls, offset);
3305 break;
3306 }
3307
3308 case Primitive::kPrimInt:
3309 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003310 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003311 __ StoreToOffset(kStoreWord, value, cls, offset);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003312 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->GetValue())) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003313 Register temp = locations->GetTemp(0).AsRegister<Register>();
3314 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003315 codegen_->MarkGCCard(temp, card, cls, value);
3316 }
3317 break;
3318 }
3319
3320 case Primitive::kPrimLong: {
3321 Location value = locations->InAt(1);
3322 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), cls, offset);
3323 break;
3324 }
3325
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003326 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003327 SRegister value = locations->InAt(1).AsFpuRegister<SRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003328 __ StoreSToOffset(value, cls, offset);
3329 break;
3330 }
3331
3332 case Primitive::kPrimDouble: {
3333 DRegister value = FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>());
3334 __ StoreDToOffset(value, cls, offset);
3335 break;
3336 }
3337
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003338 case Primitive::kPrimVoid:
3339 LOG(FATAL) << "Unreachable type " << field_type;
3340 UNREACHABLE();
3341 }
3342}
3343
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003344void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3345 LocationSummary* locations =
3346 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3347 locations->SetOut(Location::RequiresRegister());
3348}
3349
3350void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3351 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3352 codegen_->AddSlowPath(slow_path);
3353
Roland Levillain271ab9c2014-11-27 15:23:57 +00003354 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003355 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003356 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3357 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003358 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3359 __ cmp(out, ShifterOperand(0));
3360 __ b(slow_path->GetEntryLabel(), EQ);
3361 __ Bind(slow_path->GetExitLabel());
3362}
3363
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003364void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3365 LocationSummary* locations =
3366 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3367 locations->SetOut(Location::RequiresRegister());
3368}
3369
3370void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003371 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003372 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3373 __ LoadFromOffset(kLoadWord, out, TR, offset);
3374 __ LoadImmediate(IP, 0);
3375 __ StoreToOffset(kStoreWord, IP, TR, offset);
3376}
3377
3378void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3379 LocationSummary* locations =
3380 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3381 InvokeRuntimeCallingConvention calling_convention;
3382 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3383}
3384
3385void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3386 codegen_->InvokeRuntime(
3387 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3388}
3389
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003390void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003391 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3392 ? LocationSummary::kNoCall
3393 : LocationSummary::kCallOnSlowPath;
3394 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3395 locations->SetInAt(0, Location::RequiresRegister());
3396 locations->SetInAt(1, Location::RequiresRegister());
3397 locations->SetOut(Location::RequiresRegister());
3398}
3399
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003400void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003401 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003402 Register obj = locations->InAt(0).AsRegister<Register>();
3403 Register cls = locations->InAt(1).AsRegister<Register>();
3404 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003405 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3406 Label done, zero;
3407 SlowPathCodeARM* slow_path = nullptr;
3408
3409 // Return 0 if `obj` is null.
3410 // TODO: avoid this check if we know obj is not null.
3411 __ cmp(obj, ShifterOperand(0));
3412 __ b(&zero, EQ);
3413 // Compare the class of `obj` with `cls`.
3414 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3415 __ cmp(out, ShifterOperand(cls));
3416 if (instruction->IsClassFinal()) {
3417 // Classes must be equal for the instanceof to succeed.
3418 __ b(&zero, NE);
3419 __ LoadImmediate(out, 1);
3420 __ b(&done);
3421 } else {
3422 // If the classes are not equal, we go into a slow path.
3423 DCHECK(locations->OnlyCallsOnSlowPath());
3424 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003425 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003426 codegen_->AddSlowPath(slow_path);
3427 __ b(slow_path->GetEntryLabel(), NE);
3428 __ LoadImmediate(out, 1);
3429 __ b(&done);
3430 }
3431 __ Bind(&zero);
3432 __ LoadImmediate(out, 0);
3433 if (slow_path != nullptr) {
3434 __ Bind(slow_path->GetExitLabel());
3435 }
3436 __ Bind(&done);
3437}
3438
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003439void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3440 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3441 instruction, LocationSummary::kCallOnSlowPath);
3442 locations->SetInAt(0, Location::RequiresRegister());
3443 locations->SetInAt(1, Location::RequiresRegister());
3444 locations->AddTemp(Location::RequiresRegister());
3445}
3446
3447void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3448 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003449 Register obj = locations->InAt(0).AsRegister<Register>();
3450 Register cls = locations->InAt(1).AsRegister<Register>();
3451 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003452 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3453
3454 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3455 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3456 codegen_->AddSlowPath(slow_path);
3457
3458 // TODO: avoid this check if we know obj is not null.
3459 __ cmp(obj, ShifterOperand(0));
3460 __ b(slow_path->GetExitLabel(), EQ);
3461 // Compare the class of `obj` with `cls`.
3462 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3463 __ cmp(temp, ShifterOperand(cls));
3464 __ b(slow_path->GetEntryLabel(), NE);
3465 __ Bind(slow_path->GetExitLabel());
3466}
3467
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003468void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3469 LocationSummary* locations =
3470 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3471 InvokeRuntimeCallingConvention calling_convention;
3472 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3473}
3474
3475void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3476 codegen_->InvokeRuntime(instruction->IsEnter()
3477 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3478 instruction,
3479 instruction->GetDexPc());
3480}
3481
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003482void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3483void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3484void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3485
3486void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3487 LocationSummary* locations =
3488 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3489 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3490 || instruction->GetResultType() == Primitive::kPrimLong);
3491 locations->SetInAt(0, Location::RequiresRegister());
3492 locations->SetInAt(1, Location::RequiresRegister());
3493 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
3494 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3495}
3496
3497void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3498 HandleBitwiseOperation(instruction);
3499}
3500
3501void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3502 HandleBitwiseOperation(instruction);
3503}
3504
3505void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3506 HandleBitwiseOperation(instruction);
3507}
3508
3509void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3510 LocationSummary* locations = instruction->GetLocations();
3511
3512 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003513 Register first = locations->InAt(0).AsRegister<Register>();
3514 Register second = locations->InAt(1).AsRegister<Register>();
3515 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003516 if (instruction->IsAnd()) {
3517 __ and_(out, first, ShifterOperand(second));
3518 } else if (instruction->IsOr()) {
3519 __ orr(out, first, ShifterOperand(second));
3520 } else {
3521 DCHECK(instruction->IsXor());
3522 __ eor(out, first, ShifterOperand(second));
3523 }
3524 } else {
3525 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3526 Location first = locations->InAt(0);
3527 Location second = locations->InAt(1);
3528 Location out = locations->Out();
3529 if (instruction->IsAnd()) {
3530 __ and_(out.AsRegisterPairLow<Register>(),
3531 first.AsRegisterPairLow<Register>(),
3532 ShifterOperand(second.AsRegisterPairLow<Register>()));
3533 __ and_(out.AsRegisterPairHigh<Register>(),
3534 first.AsRegisterPairHigh<Register>(),
3535 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3536 } else if (instruction->IsOr()) {
3537 __ orr(out.AsRegisterPairLow<Register>(),
3538 first.AsRegisterPairLow<Register>(),
3539 ShifterOperand(second.AsRegisterPairLow<Register>()));
3540 __ orr(out.AsRegisterPairHigh<Register>(),
3541 first.AsRegisterPairHigh<Register>(),
3542 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3543 } else {
3544 DCHECK(instruction->IsXor());
3545 __ eor(out.AsRegisterPairLow<Register>(),
3546 first.AsRegisterPairLow<Register>(),
3547 ShifterOperand(second.AsRegisterPairLow<Register>()));
3548 __ eor(out.AsRegisterPairHigh<Register>(),
3549 first.AsRegisterPairHigh<Register>(),
3550 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3551 }
3552 }
3553}
3554
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003555} // namespace arm
3556} // namespace art