blob: 0f79d189befa6665ec7a1fa23656f8b55d994251 [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
Calin Juravle34166012014-12-19 17:22:29 +000019#include "arch/arm/instruction_set_features_arm.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070020#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010021#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080022#include "intrinsics.h"
23#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070024#include "mirror/array-inl.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000025#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010026#include "mirror/class.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070027#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010028#include "utils/arm/assembler_arm.h"
29#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000030#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010031#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000032
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000033namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010034
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000035namespace arm {
36
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000037static bool ExpectedPairLayout(Location location) {
38 // We expected this for both core and fpu register pairs.
39 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
40}
41
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010042static constexpr int kCurrentMethodStackOffset = 0;
43
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000044// We unconditionally allocate R5 to ensure we can do long operations
45// with baseline.
46static constexpr Register kCoreSavedRegisterForBaseline = R5;
47static constexpr Register kCoreCalleeSaves[] =
48 { R5, R6, R7, R8, R10, R11, PC };
49static constexpr SRegister kFpuCalleeSaves[] =
50 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010051
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000052// D31 cannot be split into two S registers, and the register allocator only works on
53// S registers. Therefore there is no need to block it.
54static constexpr DRegister DTMP = D31;
55
Nicolas Geoffraye5038322014-07-04 09:41:32 +010056#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010057#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010058
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010059class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010060 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010061 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010062
Alexandre Rames67555f72014-11-18 10:55:16 +000063 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010064 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010065 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010066 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000067 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010068 }
69
70 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010071 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010072 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
73};
74
Calin Juravled0d48522014-11-04 16:40:20 +000075class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
76 public:
77 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
78
Alexandre Rames67555f72014-11-18 10:55:16 +000079 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000080 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
81 __ Bind(GetEntryLabel());
82 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000083 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Calin Juravled0d48522014-11-04 16:40:20 +000084 }
85
86 private:
87 HDivZeroCheck* const instruction_;
88 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
89};
90
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010091class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000092 public:
Alexandre Rames67555f72014-11-18 10:55:16 +000093 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +010094 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000095
Alexandre Rames67555f72014-11-18 10:55:16 +000096 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010097 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000098 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +000099 SaveLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100100 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000101 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000102 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100103 if (successor_ == nullptr) {
104 __ b(GetReturnLabel());
105 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100106 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100107 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000108 }
109
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100110 Label* GetReturnLabel() {
111 DCHECK(successor_ == nullptr);
112 return &return_label_;
113 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000114
115 private:
116 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100117 // If not null, the block to branch to after the suspend check.
118 HBasicBlock* const successor_;
119
120 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000121 Label return_label_;
122
123 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
124};
125
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100126class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100127 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100128 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
129 Location index_location,
130 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100131 : instruction_(instruction),
132 index_location_(index_location),
133 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100134
Alexandre Rames67555f72014-11-18 10:55:16 +0000135 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100136 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100137 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000138 // We're moving two locations to locations that could overlap, so we need a parallel
139 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100140 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000141 codegen->EmitParallelMoves(
142 index_location_,
143 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
144 length_location_,
145 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100146 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000147 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100148 }
149
150 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100151 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152 const Location index_location_;
153 const Location length_location_;
154
155 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
156};
157
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000158class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100159 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000160 LoadClassSlowPathARM(HLoadClass* cls,
161 HInstruction* at,
162 uint32_t dex_pc,
163 bool do_clinit)
164 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
165 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
166 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100167
Alexandre Rames67555f72014-11-18 10:55:16 +0000168 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000169 LocationSummary* locations = at_->GetLocations();
170
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100171 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
172 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000173 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100174
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100175 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000176 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100177 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000178 int32_t entry_point_offset = do_clinit_
179 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
180 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000181 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000182
183 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000184 Location out = locations->Out();
185 if (out.IsValid()) {
186 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000187 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
188 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000189 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100190 __ b(GetExitLabel());
191 }
192
193 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000194 // The class this slow path will load.
195 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100196
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000197 // The instruction where this slow path is happening.
198 // (Might be the load class or an initialization check).
199 HInstruction* const at_;
200
201 // The dex PC of `at_`.
202 const uint32_t dex_pc_;
203
204 // Whether to initialize the class.
205 const bool do_clinit_;
206
207 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100208};
209
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000210class LoadStringSlowPathARM : public SlowPathCodeARM {
211 public:
212 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
213
Alexandre Rames67555f72014-11-18 10:55:16 +0000214 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000215 LocationSummary* locations = instruction_->GetLocations();
216 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
217
218 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
219 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000220 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000221
222 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800223 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
224 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000225 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000226 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000227 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
228
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000229 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000230 __ b(GetExitLabel());
231 }
232
233 private:
234 HLoadString* const instruction_;
235
236 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
237};
238
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000239class TypeCheckSlowPathARM : public SlowPathCodeARM {
240 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000241 TypeCheckSlowPathARM(HInstruction* instruction,
242 Location class_to_check,
243 Location object_class,
244 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000245 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000246 class_to_check_(class_to_check),
247 object_class_(object_class),
248 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000249
Alexandre Rames67555f72014-11-18 10:55:16 +0000250 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000251 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000252 DCHECK(instruction_->IsCheckCast()
253 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000254
255 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
256 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000257 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000258
259 // We're moving two locations to locations that could overlap, so we need a parallel
260 // move resolver.
261 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000262 codegen->EmitParallelMoves(
263 class_to_check_,
264 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
265 object_class_,
266 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000267
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000268 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000269 arm_codegen->InvokeRuntime(
270 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000271 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
272 } else {
273 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000274 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000275 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000276
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000277 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000278 __ b(GetExitLabel());
279 }
280
281 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000282 HInstruction* const instruction_;
283 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000284 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000285 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000286
287 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
288};
289
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000290#undef __
291
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100292#undef __
293#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700294
295inline Condition ARMCondition(IfCondition cond) {
296 switch (cond) {
297 case kCondEQ: return EQ;
298 case kCondNE: return NE;
299 case kCondLT: return LT;
300 case kCondLE: return LE;
301 case kCondGT: return GT;
302 case kCondGE: return GE;
303 default:
304 LOG(FATAL) << "Unknown if condition";
305 }
306 return EQ; // Unreachable.
307}
308
309inline Condition ARMOppositeCondition(IfCondition cond) {
310 switch (cond) {
311 case kCondEQ: return NE;
312 case kCondNE: return EQ;
313 case kCondLT: return GE;
314 case kCondLE: return GT;
315 case kCondGT: return LE;
316 case kCondGE: return LT;
317 default:
318 LOG(FATAL) << "Unknown if condition";
319 }
320 return EQ; // Unreachable.
321}
322
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100323void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
324 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
325}
326
327void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000328 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100329}
330
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100331size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
332 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
333 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100334}
335
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100336size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
337 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
338 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100339}
340
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000341size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
342 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
343 return kArmWordSize;
344}
345
346size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
347 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
348 return kArmWordSize;
349}
350
Calin Juravle34166012014-12-19 17:22:29 +0000351CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000352 const ArmInstructionSetFeatures& isa_features,
353 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000354 : CodeGenerator(graph,
355 kNumberOfCoreRegisters,
356 kNumberOfSRegisters,
357 kNumberOfRegisterPairs,
358 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
359 arraysize(kCoreCalleeSaves)),
360 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
361 arraysize(kFpuCalleeSaves)),
362 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100363 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100364 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100365 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100366 move_resolver_(graph->GetArena(), this),
Calin Juravle34166012014-12-19 17:22:29 +0000367 assembler_(true),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000368 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000369 // Save the PC register to mimic Quick.
370 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100371}
372
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100373Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100374 switch (type) {
375 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100376 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100377 ArmManagedRegister pair =
378 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100379 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
380 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
381
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100382 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
383 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100384 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100385 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100386 }
387
388 case Primitive::kPrimByte:
389 case Primitive::kPrimBoolean:
390 case Primitive::kPrimChar:
391 case Primitive::kPrimShort:
392 case Primitive::kPrimInt:
393 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100394 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100395 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100396 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
397 ArmManagedRegister current =
398 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
399 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100400 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100401 }
402 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100403 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100404 }
405
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000406 case Primitive::kPrimFloat: {
407 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100408 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100409 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100410
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000411 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000412 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
413 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000414 return Location::FpuRegisterPairLocation(reg, reg + 1);
415 }
416
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100417 case Primitive::kPrimVoid:
418 LOG(FATAL) << "Unreachable type " << type;
419 }
420
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100421 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100422}
423
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000424void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100425 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100426 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100427
428 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100429 blocked_core_registers_[SP] = true;
430 blocked_core_registers_[LR] = true;
431 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100432
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100433 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100434 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100435
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100436 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100437 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100438
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000439 if (is_baseline) {
440 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
441 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
442 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000443
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000444 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
445
446 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
447 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
448 }
449 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100450
451 UpdateBlockedPairRegisters();
452}
453
454void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
455 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
456 ArmManagedRegister current =
457 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
458 if (blocked_core_registers_[current.AsRegisterPairLow()]
459 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
460 blocked_register_pairs_[i] = true;
461 }
462 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100463}
464
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100465InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
466 : HGraphVisitor(graph),
467 assembler_(codegen->GetAssembler()),
468 codegen_(codegen) {}
469
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000470static uint32_t LeastSignificantBit(uint32_t mask) {
471 // ffs starts at 1.
472 return ffs(mask) - 1;
473}
474
475void CodeGeneratorARM::ComputeSpillMask() {
476 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000477 // Save one extra register for baseline. Note that on thumb2, there is no easy
478 // instruction to restore just the PC, so this actually helps both baseline
479 // and non-baseline to save and restore at least two registers at entry and exit.
480 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000481 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
482 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
483 // We use vpush and vpop for saving and restoring floating point registers, which take
484 // a SRegister and the number of registers to save/restore after that SRegister. We
485 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
486 // but in the range.
487 if (fpu_spill_mask_ != 0) {
488 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
489 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
490 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
491 fpu_spill_mask_ |= (1 << i);
492 }
493 }
494}
495
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000496void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000497 bool skip_overflow_check =
498 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000499 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000500 __ Bind(&frame_entry_label_);
501
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000502 if (HasEmptyFrame()) {
503 return;
504 }
505
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100506 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000507 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
508 __ LoadFromOffset(kLoadWord, IP, IP, 0);
509 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100510 }
511
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000512 // PC is in the list of callee-save to mimic Quick, but we need to push
513 // LR at entry instead.
514 __ PushList((core_spill_mask_ & (~(1 << PC))) | 1 << LR);
515 if (fpu_spill_mask_ != 0) {
516 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
517 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
518 }
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000519 __ AddConstant(SP, -(GetFrameSize() - FrameEntrySpillSize()));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100520 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000521}
522
523void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000524 if (HasEmptyFrame()) {
525 __ bx(LR);
526 return;
527 }
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000528 __ AddConstant(SP, GetFrameSize() - FrameEntrySpillSize());
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000529 if (fpu_spill_mask_ != 0) {
530 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
531 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
532 }
533 __ PopList(core_spill_mask_);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000534}
535
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100536void CodeGeneratorARM::Bind(HBasicBlock* block) {
537 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000538}
539
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100540Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
541 switch (load->GetType()) {
542 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100543 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100544 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
545 break;
546
547 case Primitive::kPrimInt:
548 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100549 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100550 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100551
552 case Primitive::kPrimBoolean:
553 case Primitive::kPrimByte:
554 case Primitive::kPrimChar:
555 case Primitive::kPrimShort:
556 case Primitive::kPrimVoid:
557 LOG(FATAL) << "Unexpected type " << load->GetType();
558 }
559
560 LOG(FATAL) << "Unreachable";
561 return Location();
562}
563
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100564Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
565 switch (type) {
566 case Primitive::kPrimBoolean:
567 case Primitive::kPrimByte:
568 case Primitive::kPrimChar:
569 case Primitive::kPrimShort:
570 case Primitive::kPrimInt:
571 case Primitive::kPrimNot: {
572 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000573 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100574 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100575 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100576 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000577 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100578 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100579 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100580
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000581 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100582 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000583 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100584 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000585 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100586 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000587 if (calling_convention.GetRegisterAt(index) == R1) {
588 // Skip R1, and use R2_R3 instead.
589 gp_index_++;
590 index++;
591 }
592 }
593 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
594 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000595 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000596 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000597 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100598 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000599 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
600 }
601 }
602
603 case Primitive::kPrimFloat: {
604 uint32_t stack_index = stack_index_++;
605 if (float_index_ % 2 == 0) {
606 float_index_ = std::max(double_index_, float_index_);
607 }
608 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
609 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
610 } else {
611 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
612 }
613 }
614
615 case Primitive::kPrimDouble: {
616 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
617 uint32_t stack_index = stack_index_;
618 stack_index_ += 2;
619 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
620 uint32_t index = double_index_;
621 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000622 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000623 calling_convention.GetFpuRegisterAt(index),
624 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000625 DCHECK(ExpectedPairLayout(result));
626 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000627 } else {
628 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100629 }
630 }
631
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100632 case Primitive::kPrimVoid:
633 LOG(FATAL) << "Unexpected parameter type " << type;
634 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100635 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100636 return Location();
637}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100638
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000639Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
640 switch (type) {
641 case Primitive::kPrimBoolean:
642 case Primitive::kPrimByte:
643 case Primitive::kPrimChar:
644 case Primitive::kPrimShort:
645 case Primitive::kPrimInt:
646 case Primitive::kPrimNot: {
647 return Location::RegisterLocation(R0);
648 }
649
650 case Primitive::kPrimFloat: {
651 return Location::FpuRegisterLocation(S0);
652 }
653
654 case Primitive::kPrimLong: {
655 return Location::RegisterPairLocation(R0, R1);
656 }
657
658 case Primitive::kPrimDouble: {
659 return Location::FpuRegisterPairLocation(S0, S1);
660 }
661
662 case Primitive::kPrimVoid:
663 return Location();
664 }
665 UNREACHABLE();
666 return Location();
667}
668
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100669void CodeGeneratorARM::Move32(Location destination, Location source) {
670 if (source.Equals(destination)) {
671 return;
672 }
673 if (destination.IsRegister()) {
674 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000675 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100676 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000677 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100678 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000679 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100680 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100681 } else if (destination.IsFpuRegister()) {
682 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000683 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100684 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000685 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100686 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000687 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100688 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100689 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000690 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100691 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000692 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100693 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000694 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100695 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000696 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100697 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
698 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100699 }
700 }
701}
702
703void CodeGeneratorARM::Move64(Location destination, Location source) {
704 if (source.Equals(destination)) {
705 return;
706 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100707 if (destination.IsRegisterPair()) {
708 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000709 EmitParallelMoves(
710 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
711 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
712 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
713 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100714 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000715 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100716 } else {
717 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000718 DCHECK(ExpectedPairLayout(destination));
719 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
720 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100721 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000722 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100723 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000724 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
725 SP,
726 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100727 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000728 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100729 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100730 } else {
731 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100732 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000733 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100734 if (source.AsRegisterPairLow<Register>() == R1) {
735 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100736 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
737 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100738 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100739 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100740 SP, destination.GetStackIndex());
741 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000742 } else if (source.IsFpuRegisterPair()) {
743 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
744 SP,
745 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100746 } else {
747 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000748 EmitParallelMoves(
749 Location::StackSlot(source.GetStackIndex()),
750 Location::StackSlot(destination.GetStackIndex()),
751 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
752 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100753 }
754 }
755}
756
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100757void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100758 LocationSummary* locations = instruction->GetLocations();
759 if (locations != nullptr && locations->Out().Equals(location)) {
760 return;
761 }
762
Calin Juravlea21f5982014-11-13 15:53:04 +0000763 if (locations != nullptr && locations->Out().IsConstant()) {
764 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000765 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
766 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000767 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000768 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000769 } else {
770 DCHECK(location.IsStackSlot());
771 __ LoadImmediate(IP, value);
772 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
773 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000774 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000775 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000776 int64_t value = const_to_move->AsLongConstant()->GetValue();
777 if (location.IsRegisterPair()) {
778 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
779 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
780 } else {
781 DCHECK(location.IsDoubleStackSlot());
782 __ LoadImmediate(IP, Low32Bits(value));
783 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
784 __ LoadImmediate(IP, High32Bits(value));
785 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
786 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100787 }
Roland Levillain476df552014-10-09 17:51:36 +0100788 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100789 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
790 switch (instruction->GetType()) {
791 case Primitive::kPrimBoolean:
792 case Primitive::kPrimByte:
793 case Primitive::kPrimChar:
794 case Primitive::kPrimShort:
795 case Primitive::kPrimInt:
796 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100797 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100798 Move32(location, Location::StackSlot(stack_slot));
799 break;
800
801 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100802 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100803 Move64(location, Location::DoubleStackSlot(stack_slot));
804 break;
805
806 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100807 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100808 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000809 } else if (instruction->IsTemporary()) {
810 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000811 if (temp_location.IsStackSlot()) {
812 Move32(location, temp_location);
813 } else {
814 DCHECK(temp_location.IsDoubleStackSlot());
815 Move64(location, temp_location);
816 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000817 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100818 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100819 switch (instruction->GetType()) {
820 case Primitive::kPrimBoolean:
821 case Primitive::kPrimByte:
822 case Primitive::kPrimChar:
823 case Primitive::kPrimShort:
824 case Primitive::kPrimNot:
825 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100826 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100827 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100828 break;
829
830 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100831 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100832 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100833 break;
834
835 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100836 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100837 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000838 }
839}
840
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100841void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
842 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000843 uint32_t dex_pc,
844 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100845 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
846 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000847 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100848 DCHECK(instruction->IsSuspendCheck()
849 || instruction->IsBoundsCheck()
850 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000851 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000852 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100853 || !IsLeafMethod());
854}
855
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000856void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000857 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000858}
859
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000860void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000861 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100862 DCHECK(!successor->IsExitBlock());
863
864 HBasicBlock* block = got->GetBlock();
865 HInstruction* previous = got->GetPrevious();
866
867 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000868 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100869 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
870 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
871 return;
872 }
873
874 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
875 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
876 }
877 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000878 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000879 }
880}
881
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000882void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000883 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000884}
885
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000886void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700887 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000888}
889
Andreas Gampe0ba62732015-03-24 02:39:46 +0000890void LocationsBuilderARM::VisitIf(HIf* if_instr) {
891 LocationSummary* locations =
892 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
893 HInstruction* cond = if_instr->InputAt(0);
894 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
895 locations->SetInAt(0, Location::RequiresRegister());
896 }
897}
898
899void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
900 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100901 if (cond->IsIntConstant()) {
902 // Constant condition, statically compared against 1.
903 int32_t cond_value = cond->AsIntConstant()->GetValue();
904 if (cond_value == 1) {
Andreas Gampe0ba62732015-03-24 02:39:46 +0000905 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
906 if_instr->IfTrueSuccessor())) {
907 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100908 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100909 return;
910 } else {
911 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100912 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100913 } else {
914 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
915 // Condition has been materialized, compare the output to 0
Andreas Gampe0ba62732015-03-24 02:39:46 +0000916 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
917 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100918 ShifterOperand(0));
Andreas Gampe0ba62732015-03-24 02:39:46 +0000919 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100920 } else {
921 // Condition has not been materialized, use its inputs as the
922 // comparison and its condition as the branch condition.
923 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000924 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000925 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100926 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000927 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100928 } else {
929 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000930 HConstant* constant = locations->InAt(1).GetConstant();
931 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100932 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000933 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
934 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100935 } else {
936 Register temp = IP;
937 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000938 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100939 }
940 }
Andreas Gampe0ba62732015-03-24 02:39:46 +0000941 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
942 ARMCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100943 }
Dave Allison20dfc792014-06-16 20:44:29 -0700944 }
Andreas Gampe0ba62732015-03-24 02:39:46 +0000945 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
946 if_instr->IfFalseSuccessor())) {
947 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000948 }
949}
950
Dave Allison20dfc792014-06-16 20:44:29 -0700951
952void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100953 LocationSummary* locations =
954 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100955 locations->SetInAt(0, Location::RequiresRegister());
956 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100957 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100958 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100959 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000960}
961
Dave Allison20dfc792014-06-16 20:44:29 -0700962void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100963 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100964 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000965 Register left = locations->InAt(0).AsRegister<Register>();
966
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100967 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000968 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100969 } else {
970 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -0800971 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100972 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000973 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
974 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100975 } else {
976 Register temp = IP;
977 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000978 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100979 }
Dave Allison20dfc792014-06-16 20:44:29 -0700980 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100981 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +0000982 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100983 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +0000984 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100985 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700986}
987
988void LocationsBuilderARM::VisitEqual(HEqual* comp) {
989 VisitCondition(comp);
990}
991
992void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
993 VisitCondition(comp);
994}
995
996void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
997 VisitCondition(comp);
998}
999
1000void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1001 VisitCondition(comp);
1002}
1003
1004void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1005 VisitCondition(comp);
1006}
1007
1008void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1009 VisitCondition(comp);
1010}
1011
1012void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1013 VisitCondition(comp);
1014}
1015
1016void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1017 VisitCondition(comp);
1018}
1019
1020void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1021 VisitCondition(comp);
1022}
1023
1024void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1025 VisitCondition(comp);
1026}
1027
1028void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1029 VisitCondition(comp);
1030}
1031
1032void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1033 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001034}
1035
1036void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001037 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001038}
1039
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001040void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1041 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001042}
1043
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001044void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001045 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001046}
1047
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001048void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001049 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001050 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001051}
1052
1053void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001054 LocationSummary* locations =
1055 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001056 switch (store->InputAt(1)->GetType()) {
1057 case Primitive::kPrimBoolean:
1058 case Primitive::kPrimByte:
1059 case Primitive::kPrimChar:
1060 case Primitive::kPrimShort:
1061 case Primitive::kPrimInt:
1062 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001063 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001064 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1065 break;
1066
1067 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001068 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001069 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1070 break;
1071
1072 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001073 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001074 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001075}
1076
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001077void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001078 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001079}
1080
1081void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001082 LocationSummary* locations =
1083 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001084 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001085}
1086
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001087void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001088 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001089 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001090}
1091
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001092void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1093 LocationSummary* locations =
1094 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1095 locations->SetOut(Location::ConstantLocation(constant));
1096}
1097
1098void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1099 // Will be generated at use site.
1100 UNUSED(constant);
1101}
1102
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001103void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001104 LocationSummary* locations =
1105 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001106 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001107}
1108
1109void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1110 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001111 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001112}
1113
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001114void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1115 LocationSummary* locations =
1116 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1117 locations->SetOut(Location::ConstantLocation(constant));
1118}
1119
1120void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1121 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001122 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001123}
1124
1125void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1126 LocationSummary* locations =
1127 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1128 locations->SetOut(Location::ConstantLocation(constant));
1129}
1130
1131void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1132 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001133 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001134}
1135
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001136void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001137 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001138}
1139
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001140void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001141 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001142 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001143}
1144
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001145void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001146 LocationSummary* locations =
1147 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001148 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001149}
1150
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001151void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001152 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001153 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001154}
1155
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001156void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001157 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1158 codegen_->GetInstructionSetFeatures());
1159 if (intrinsic.TryDispatch(invoke)) {
1160 return;
1161 }
1162
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001163 HandleInvoke(invoke);
1164}
1165
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001166void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001167 DCHECK(RequiresCurrentMethod());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001168 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001169}
1170
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001171static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1172 if (invoke->GetLocations()->Intrinsified()) {
1173 IntrinsicCodeGeneratorARM intrinsic(codegen);
1174 intrinsic.Dispatch(invoke);
1175 return true;
1176 }
1177 return false;
1178}
1179
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001180void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001181 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1182 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001183 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001184
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001185 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
1186
1187 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001188 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001189}
1190
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001191void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001192 LocationSummary* locations =
1193 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001194 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001195
1196 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001197 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001198 HInstruction* input = invoke->InputAt(i);
1199 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1200 }
1201
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001202 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001203}
1204
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001205void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001206 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1207 codegen_->GetInstructionSetFeatures());
1208 if (intrinsic.TryDispatch(invoke)) {
1209 return;
1210 }
1211
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001212 HandleInvoke(invoke);
1213}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001214
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001215void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001216 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1217 return;
1218 }
1219
Roland Levillain271ab9c2014-11-27 15:23:57 +00001220 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001221 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1222 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1223 LocationSummary* locations = invoke->GetLocations();
1224 Location receiver = locations->InAt(0);
1225 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1226 // temp = object->GetClass();
1227 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001228 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1229 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001230 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001231 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001232 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001233 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001234 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001235 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001236 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001237 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001238 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001239 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001240 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001241 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001242 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001243 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001244}
1245
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001246void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1247 HandleInvoke(invoke);
1248 // Add the hidden argument.
1249 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1250}
1251
1252void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1253 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001254 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001255 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1256 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1257 LocationSummary* locations = invoke->GetLocations();
1258 Location receiver = locations->InAt(0);
1259 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1260
1261 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001262 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1263 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001264
1265 // temp = object->GetClass();
1266 if (receiver.IsStackSlot()) {
1267 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1268 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1269 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001270 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001271 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001272 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001273 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001274 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001275 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001276 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1277 // LR = temp->GetEntryPoint();
1278 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1279 // LR();
1280 __ blx(LR);
1281 DCHECK(!codegen_->IsLeafMethod());
1282 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1283}
1284
Roland Levillain88cb1752014-10-20 16:36:47 +01001285void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1286 LocationSummary* locations =
1287 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1288 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001289 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001290 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001291 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1292 break;
1293 }
1294 case Primitive::kPrimLong: {
1295 locations->SetInAt(0, Location::RequiresRegister());
1296 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
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
David Brazdilb2bd1c52015-03-25 11:17:37 +00001373 // The Java language does not allow treating boolean as an integral type but
1374 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001375
Roland Levillaindff1f282014-11-05 14:15:05 +00001376 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001377 case Primitive::kPrimByte:
1378 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001379 case Primitive::kPrimBoolean:
1380 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001381 case Primitive::kPrimShort:
1382 case Primitive::kPrimInt:
1383 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001384 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001385 locations->SetInAt(0, Location::RequiresRegister());
1386 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1387 break;
1388
1389 default:
1390 LOG(FATAL) << "Unexpected type conversion from " << input_type
1391 << " to " << result_type;
1392 }
1393 break;
1394
Roland Levillain01a8d712014-11-14 16:27:39 +00001395 case Primitive::kPrimShort:
1396 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001397 case Primitive::kPrimBoolean:
1398 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001399 case Primitive::kPrimByte:
1400 case Primitive::kPrimInt:
1401 case Primitive::kPrimChar:
1402 // Processing a Dex `int-to-short' instruction.
1403 locations->SetInAt(0, Location::RequiresRegister());
1404 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1405 break;
1406
1407 default:
1408 LOG(FATAL) << "Unexpected type conversion from " << input_type
1409 << " to " << result_type;
1410 }
1411 break;
1412
Roland Levillain946e1432014-11-11 17:35:19 +00001413 case Primitive::kPrimInt:
1414 switch (input_type) {
1415 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001416 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001417 locations->SetInAt(0, Location::Any());
1418 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1419 break;
1420
1421 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001422 // Processing a Dex `float-to-int' instruction.
1423 locations->SetInAt(0, Location::RequiresFpuRegister());
1424 locations->SetOut(Location::RequiresRegister());
1425 locations->AddTemp(Location::RequiresFpuRegister());
1426 break;
1427
Roland Levillain946e1432014-11-11 17:35:19 +00001428 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001429 // Processing a Dex `double-to-int' instruction.
1430 locations->SetInAt(0, Location::RequiresFpuRegister());
1431 locations->SetOut(Location::RequiresRegister());
1432 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001433 break;
1434
1435 default:
1436 LOG(FATAL) << "Unexpected type conversion from " << input_type
1437 << " to " << result_type;
1438 }
1439 break;
1440
Roland Levillaindff1f282014-11-05 14:15:05 +00001441 case Primitive::kPrimLong:
1442 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001443 case Primitive::kPrimBoolean:
1444 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001445 case Primitive::kPrimByte:
1446 case Primitive::kPrimShort:
1447 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001448 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001449 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001450 locations->SetInAt(0, Location::RequiresRegister());
1451 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1452 break;
1453
Roland Levillain624279f2014-12-04 11:54:28 +00001454 case Primitive::kPrimFloat: {
1455 // Processing a Dex `float-to-long' instruction.
1456 InvokeRuntimeCallingConvention calling_convention;
1457 locations->SetInAt(0, Location::FpuRegisterLocation(
1458 calling_convention.GetFpuRegisterAt(0)));
1459 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1460 break;
1461 }
1462
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001463 case Primitive::kPrimDouble: {
1464 // Processing a Dex `double-to-long' instruction.
1465 InvokeRuntimeCallingConvention calling_convention;
1466 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1467 calling_convention.GetFpuRegisterAt(0),
1468 calling_convention.GetFpuRegisterAt(1)));
1469 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001470 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001471 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001472
1473 default:
1474 LOG(FATAL) << "Unexpected type conversion from " << input_type
1475 << " to " << result_type;
1476 }
1477 break;
1478
Roland Levillain981e4542014-11-14 11:47:14 +00001479 case Primitive::kPrimChar:
1480 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001481 case Primitive::kPrimBoolean:
1482 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001483 case Primitive::kPrimByte:
1484 case Primitive::kPrimShort:
1485 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001486 // Processing a Dex `int-to-char' instruction.
1487 locations->SetInAt(0, Location::RequiresRegister());
1488 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1489 break;
1490
1491 default:
1492 LOG(FATAL) << "Unexpected type conversion from " << input_type
1493 << " to " << result_type;
1494 }
1495 break;
1496
Roland Levillaindff1f282014-11-05 14:15:05 +00001497 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001498 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001499 case Primitive::kPrimBoolean:
1500 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001501 case Primitive::kPrimByte:
1502 case Primitive::kPrimShort:
1503 case Primitive::kPrimInt:
1504 case Primitive::kPrimChar:
1505 // Processing a Dex `int-to-float' instruction.
1506 locations->SetInAt(0, Location::RequiresRegister());
1507 locations->SetOut(Location::RequiresFpuRegister());
1508 break;
1509
1510 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001511 // Processing a Dex `long-to-float' instruction.
1512 locations->SetInAt(0, Location::RequiresRegister());
1513 locations->SetOut(Location::RequiresFpuRegister());
1514 locations->AddTemp(Location::RequiresRegister());
1515 locations->AddTemp(Location::RequiresRegister());
1516 locations->AddTemp(Location::RequiresFpuRegister());
1517 locations->AddTemp(Location::RequiresFpuRegister());
1518 break;
1519
Roland Levillaincff13742014-11-17 14:32:17 +00001520 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001521 // Processing a Dex `double-to-float' instruction.
1522 locations->SetInAt(0, Location::RequiresFpuRegister());
1523 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001524 break;
1525
1526 default:
1527 LOG(FATAL) << "Unexpected type conversion from " << input_type
1528 << " to " << result_type;
1529 };
1530 break;
1531
Roland Levillaindff1f282014-11-05 14:15:05 +00001532 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001533 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001534 case Primitive::kPrimBoolean:
1535 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001536 case Primitive::kPrimByte:
1537 case Primitive::kPrimShort:
1538 case Primitive::kPrimInt:
1539 case Primitive::kPrimChar:
1540 // Processing a Dex `int-to-double' instruction.
1541 locations->SetInAt(0, Location::RequiresRegister());
1542 locations->SetOut(Location::RequiresFpuRegister());
1543 break;
1544
1545 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001546 // Processing a Dex `long-to-double' instruction.
1547 locations->SetInAt(0, Location::RequiresRegister());
1548 locations->SetOut(Location::RequiresFpuRegister());
1549 locations->AddTemp(Location::RequiresRegister());
1550 locations->AddTemp(Location::RequiresRegister());
1551 locations->AddTemp(Location::RequiresFpuRegister());
1552 break;
1553
Roland Levillaincff13742014-11-17 14:32:17 +00001554 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001555 // Processing a Dex `float-to-double' instruction.
1556 locations->SetInAt(0, Location::RequiresFpuRegister());
1557 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001558 break;
1559
1560 default:
1561 LOG(FATAL) << "Unexpected type conversion from " << input_type
1562 << " to " << result_type;
1563 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001564 break;
1565
1566 default:
1567 LOG(FATAL) << "Unexpected type conversion from " << input_type
1568 << " to " << result_type;
1569 }
1570}
1571
1572void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1573 LocationSummary* locations = conversion->GetLocations();
1574 Location out = locations->Out();
1575 Location in = locations->InAt(0);
1576 Primitive::Type result_type = conversion->GetResultType();
1577 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001578 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001579 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001580 case Primitive::kPrimByte:
1581 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001582 case Primitive::kPrimBoolean:
1583 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001584 case Primitive::kPrimShort:
1585 case Primitive::kPrimInt:
1586 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001587 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001588 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001589 break;
1590
1591 default:
1592 LOG(FATAL) << "Unexpected type conversion from " << input_type
1593 << " to " << result_type;
1594 }
1595 break;
1596
Roland Levillain01a8d712014-11-14 16:27:39 +00001597 case Primitive::kPrimShort:
1598 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001599 case Primitive::kPrimBoolean:
1600 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001601 case Primitive::kPrimByte:
1602 case Primitive::kPrimInt:
1603 case Primitive::kPrimChar:
1604 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001605 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001606 break;
1607
1608 default:
1609 LOG(FATAL) << "Unexpected type conversion from " << input_type
1610 << " to " << result_type;
1611 }
1612 break;
1613
Roland Levillain946e1432014-11-11 17:35:19 +00001614 case Primitive::kPrimInt:
1615 switch (input_type) {
1616 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001617 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001618 DCHECK(out.IsRegister());
1619 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001620 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001621 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001622 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001623 } else {
1624 DCHECK(in.IsConstant());
1625 DCHECK(in.GetConstant()->IsLongConstant());
1626 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001627 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001628 }
1629 break;
1630
Roland Levillain3f8f9362014-12-02 17:45:01 +00001631 case Primitive::kPrimFloat: {
1632 // Processing a Dex `float-to-int' instruction.
1633 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1634 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1635 __ vcvtis(temp, temp);
1636 __ vmovrs(out.AsRegister<Register>(), temp);
1637 break;
1638 }
1639
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001640 case Primitive::kPrimDouble: {
1641 // Processing a Dex `double-to-int' instruction.
1642 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1643 DRegister temp_d = FromLowSToD(temp_s);
1644 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1645 __ vcvtid(temp_s, temp_d);
1646 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001647 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001648 }
Roland Levillain946e1432014-11-11 17:35:19 +00001649
1650 default:
1651 LOG(FATAL) << "Unexpected type conversion from " << input_type
1652 << " to " << result_type;
1653 }
1654 break;
1655
Roland Levillaindff1f282014-11-05 14:15:05 +00001656 case Primitive::kPrimLong:
1657 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001658 case Primitive::kPrimBoolean:
1659 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001660 case Primitive::kPrimByte:
1661 case Primitive::kPrimShort:
1662 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001663 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001664 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001665 DCHECK(out.IsRegisterPair());
1666 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001667 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001668 // Sign extension.
1669 __ Asr(out.AsRegisterPairHigh<Register>(),
1670 out.AsRegisterPairLow<Register>(),
1671 31);
1672 break;
1673
1674 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001675 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001676 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1677 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001678 conversion->GetDexPc(),
1679 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001680 break;
1681
Roland Levillaindff1f282014-11-05 14:15:05 +00001682 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001683 // Processing a Dex `double-to-long' instruction.
1684 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1685 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001686 conversion->GetDexPc(),
1687 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001688 break;
1689
1690 default:
1691 LOG(FATAL) << "Unexpected type conversion from " << input_type
1692 << " to " << result_type;
1693 }
1694 break;
1695
Roland Levillain981e4542014-11-14 11:47:14 +00001696 case Primitive::kPrimChar:
1697 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001698 case Primitive::kPrimBoolean:
1699 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001700 case Primitive::kPrimByte:
1701 case Primitive::kPrimShort:
1702 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001703 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001704 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001705 break;
1706
1707 default:
1708 LOG(FATAL) << "Unexpected type conversion from " << input_type
1709 << " to " << result_type;
1710 }
1711 break;
1712
Roland Levillaindff1f282014-11-05 14:15:05 +00001713 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001714 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001715 case Primitive::kPrimBoolean:
1716 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001717 case Primitive::kPrimByte:
1718 case Primitive::kPrimShort:
1719 case Primitive::kPrimInt:
1720 case Primitive::kPrimChar: {
1721 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001722 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1723 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001724 break;
1725 }
1726
Roland Levillain6d0e4832014-11-27 18:31:21 +00001727 case Primitive::kPrimLong: {
1728 // Processing a Dex `long-to-float' instruction.
1729 Register low = in.AsRegisterPairLow<Register>();
1730 Register high = in.AsRegisterPairHigh<Register>();
1731 SRegister output = out.AsFpuRegister<SRegister>();
1732 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1733 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1734 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1735 DRegister temp1_d = FromLowSToD(temp1_s);
1736 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1737 DRegister temp2_d = FromLowSToD(temp2_s);
1738
1739 // Operations use doubles for precision reasons (each 32-bit
1740 // half of a long fits in the 53-bit mantissa of a double,
1741 // but not in the 24-bit mantissa of a float). This is
1742 // especially important for the low bits. The result is
1743 // eventually converted to float.
1744
1745 // temp1_d = int-to-double(high)
1746 __ vmovsr(temp1_s, high);
1747 __ vcvtdi(temp1_d, temp1_s);
1748 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1749 // as an immediate value into `temp2_d` does not work, as
1750 // this instruction only transfers 8 significant bits of its
1751 // immediate operand. Instead, use two 32-bit core
1752 // registers to load `k2Pow32EncodingForDouble` into
1753 // `temp2_d`.
1754 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1755 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1756 __ vmovdrr(temp2_d, constant_low, constant_high);
1757 // temp1_d = temp1_d * 2^32
1758 __ vmuld(temp1_d, temp1_d, temp2_d);
1759 // temp2_d = unsigned-to-double(low)
1760 __ vmovsr(temp2_s, low);
1761 __ vcvtdu(temp2_d, temp2_s);
1762 // temp1_d = temp1_d + temp2_d
1763 __ vaddd(temp1_d, temp1_d, temp2_d);
1764 // output = double-to-float(temp1_d);
1765 __ vcvtsd(output, temp1_d);
1766 break;
1767 }
1768
Roland Levillaincff13742014-11-17 14:32:17 +00001769 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001770 // Processing a Dex `double-to-float' instruction.
1771 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1772 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001773 break;
1774
1775 default:
1776 LOG(FATAL) << "Unexpected type conversion from " << input_type
1777 << " to " << result_type;
1778 };
1779 break;
1780
Roland Levillaindff1f282014-11-05 14:15:05 +00001781 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001782 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001783 case Primitive::kPrimBoolean:
1784 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001785 case Primitive::kPrimByte:
1786 case Primitive::kPrimShort:
1787 case Primitive::kPrimInt:
1788 case Primitive::kPrimChar: {
1789 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001790 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001791 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1792 out.AsFpuRegisterPairLow<SRegister>());
1793 break;
1794 }
1795
Roland Levillain647b9ed2014-11-27 12:06:00 +00001796 case Primitive::kPrimLong: {
1797 // Processing a Dex `long-to-double' instruction.
1798 Register low = in.AsRegisterPairLow<Register>();
1799 Register high = in.AsRegisterPairHigh<Register>();
1800 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1801 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001802 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1803 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001804 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1805 DRegister temp_d = FromLowSToD(temp_s);
1806
Roland Levillain647b9ed2014-11-27 12:06:00 +00001807 // out_d = int-to-double(high)
1808 __ vmovsr(out_s, high);
1809 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001810 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1811 // as an immediate value into `temp_d` does not work, as
1812 // this instruction only transfers 8 significant bits of its
1813 // immediate operand. Instead, use two 32-bit core
1814 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1815 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1816 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001817 __ vmovdrr(temp_d, constant_low, constant_high);
1818 // out_d = out_d * 2^32
1819 __ vmuld(out_d, out_d, temp_d);
1820 // temp_d = unsigned-to-double(low)
1821 __ vmovsr(temp_s, low);
1822 __ vcvtdu(temp_d, temp_s);
1823 // out_d = out_d + temp_d
1824 __ vaddd(out_d, out_d, temp_d);
1825 break;
1826 }
1827
Roland Levillaincff13742014-11-17 14:32:17 +00001828 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001829 // Processing a Dex `float-to-double' instruction.
1830 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1831 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001832 break;
1833
1834 default:
1835 LOG(FATAL) << "Unexpected type conversion from " << input_type
1836 << " to " << result_type;
1837 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001838 break;
1839
1840 default:
1841 LOG(FATAL) << "Unexpected type conversion from " << input_type
1842 << " to " << result_type;
1843 }
1844}
1845
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001846void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001847 LocationSummary* locations =
1848 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001849 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001850 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001851 locations->SetInAt(0, Location::RequiresRegister());
1852 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001853 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1854 break;
1855 }
1856
1857 case Primitive::kPrimLong: {
1858 locations->SetInAt(0, Location::RequiresRegister());
1859 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001860 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001861 break;
1862 }
1863
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001864 case Primitive::kPrimFloat:
1865 case Primitive::kPrimDouble: {
1866 locations->SetInAt(0, Location::RequiresFpuRegister());
1867 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001868 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001869 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001870 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001871
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001872 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001873 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001874 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001875}
1876
1877void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1878 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001879 Location out = locations->Out();
1880 Location first = locations->InAt(0);
1881 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001882 switch (add->GetResultType()) {
1883 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001884 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001885 __ add(out.AsRegister<Register>(),
1886 first.AsRegister<Register>(),
1887 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001888 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001889 __ AddConstant(out.AsRegister<Register>(),
1890 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001891 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001892 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001893 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001894
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001895 case Primitive::kPrimLong: {
1896 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001897 __ adds(out.AsRegisterPairLow<Register>(),
1898 first.AsRegisterPairLow<Register>(),
1899 ShifterOperand(second.AsRegisterPairLow<Register>()));
1900 __ adc(out.AsRegisterPairHigh<Register>(),
1901 first.AsRegisterPairHigh<Register>(),
1902 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001903 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001904 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001905
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001906 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001907 __ vadds(out.AsFpuRegister<SRegister>(),
1908 first.AsFpuRegister<SRegister>(),
1909 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001910 break;
1911
1912 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001913 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1914 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1915 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001916 break;
1917
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001918 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001919 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001920 }
1921}
1922
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001923void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001924 LocationSummary* locations =
1925 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001926 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001927 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001928 locations->SetInAt(0, Location::RequiresRegister());
1929 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001930 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1931 break;
1932 }
1933
1934 case Primitive::kPrimLong: {
1935 locations->SetInAt(0, Location::RequiresRegister());
1936 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001937 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001938 break;
1939 }
Calin Juravle11351682014-10-23 15:38:15 +01001940 case Primitive::kPrimFloat:
1941 case Primitive::kPrimDouble: {
1942 locations->SetInAt(0, Location::RequiresFpuRegister());
1943 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001944 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001945 break;
Calin Juravle11351682014-10-23 15:38:15 +01001946 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001947 default:
Calin Juravle11351682014-10-23 15:38:15 +01001948 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001949 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001950}
1951
1952void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1953 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001954 Location out = locations->Out();
1955 Location first = locations->InAt(0);
1956 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001957 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001958 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001959 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001960 __ sub(out.AsRegister<Register>(),
1961 first.AsRegister<Register>(),
1962 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001963 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001964 __ AddConstant(out.AsRegister<Register>(),
1965 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001966 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001967 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001968 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001969 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001970
Calin Juravle11351682014-10-23 15:38:15 +01001971 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001972 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01001973 __ subs(out.AsRegisterPairLow<Register>(),
1974 first.AsRegisterPairLow<Register>(),
1975 ShifterOperand(second.AsRegisterPairLow<Register>()));
1976 __ sbc(out.AsRegisterPairHigh<Register>(),
1977 first.AsRegisterPairHigh<Register>(),
1978 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001979 break;
Calin Juravle11351682014-10-23 15:38:15 +01001980 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001981
Calin Juravle11351682014-10-23 15:38:15 +01001982 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001983 __ vsubs(out.AsFpuRegister<SRegister>(),
1984 first.AsFpuRegister<SRegister>(),
1985 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001986 break;
Calin Juravle11351682014-10-23 15:38:15 +01001987 }
1988
1989 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001990 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1991 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1992 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001993 break;
1994 }
1995
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001996
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001997 default:
Calin Juravle11351682014-10-23 15:38:15 +01001998 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001999 }
2000}
2001
Calin Juravle34bacdf2014-10-07 20:23:36 +01002002void LocationsBuilderARM::VisitMul(HMul* mul) {
2003 LocationSummary* locations =
2004 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2005 switch (mul->GetResultType()) {
2006 case Primitive::kPrimInt:
2007 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002008 locations->SetInAt(0, Location::RequiresRegister());
2009 locations->SetInAt(1, Location::RequiresRegister());
2010 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002011 break;
2012 }
2013
Calin Juravleb5bfa962014-10-21 18:02:24 +01002014 case Primitive::kPrimFloat:
2015 case Primitive::kPrimDouble: {
2016 locations->SetInAt(0, Location::RequiresFpuRegister());
2017 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002018 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002019 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002020 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002021
2022 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002023 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002024 }
2025}
2026
2027void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2028 LocationSummary* locations = mul->GetLocations();
2029 Location out = locations->Out();
2030 Location first = locations->InAt(0);
2031 Location second = locations->InAt(1);
2032 switch (mul->GetResultType()) {
2033 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002034 __ mul(out.AsRegister<Register>(),
2035 first.AsRegister<Register>(),
2036 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002037 break;
2038 }
2039 case Primitive::kPrimLong: {
2040 Register out_hi = out.AsRegisterPairHigh<Register>();
2041 Register out_lo = out.AsRegisterPairLow<Register>();
2042 Register in1_hi = first.AsRegisterPairHigh<Register>();
2043 Register in1_lo = first.AsRegisterPairLow<Register>();
2044 Register in2_hi = second.AsRegisterPairHigh<Register>();
2045 Register in2_lo = second.AsRegisterPairLow<Register>();
2046
2047 // Extra checks to protect caused by the existence of R1_R2.
2048 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2049 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2050 DCHECK_NE(out_hi, in1_lo);
2051 DCHECK_NE(out_hi, in2_lo);
2052
2053 // input: in1 - 64 bits, in2 - 64 bits
2054 // output: out
2055 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2056 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2057 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2058
2059 // IP <- in1.lo * in2.hi
2060 __ mul(IP, in1_lo, in2_hi);
2061 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2062 __ mla(out_hi, in1_hi, in2_lo, IP);
2063 // out.lo <- (in1.lo * in2.lo)[31:0];
2064 __ umull(out_lo, IP, in1_lo, in2_lo);
2065 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2066 __ add(out_hi, out_hi, ShifterOperand(IP));
2067 break;
2068 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002069
2070 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002071 __ vmuls(out.AsFpuRegister<SRegister>(),
2072 first.AsFpuRegister<SRegister>(),
2073 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002074 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002075 }
2076
2077 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002078 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2079 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2080 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002081 break;
2082 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002083
2084 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002085 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002086 }
2087}
2088
Calin Juravle7c4954d2014-10-28 16:57:40 +00002089void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002090 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2091 ? LocationSummary::kCall
2092 : LocationSummary::kNoCall;
2093 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2094
Calin Juravle7c4954d2014-10-28 16:57:40 +00002095 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002096 case Primitive::kPrimInt: {
2097 locations->SetInAt(0, Location::RequiresRegister());
2098 locations->SetInAt(1, Location::RequiresRegister());
2099 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2100 break;
2101 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002102 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002103 InvokeRuntimeCallingConvention calling_convention;
2104 locations->SetInAt(0, Location::RegisterPairLocation(
2105 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2106 locations->SetInAt(1, Location::RegisterPairLocation(
2107 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002108 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002109 break;
2110 }
2111 case Primitive::kPrimFloat:
2112 case Primitive::kPrimDouble: {
2113 locations->SetInAt(0, Location::RequiresFpuRegister());
2114 locations->SetInAt(1, Location::RequiresFpuRegister());
2115 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2116 break;
2117 }
2118
2119 default:
2120 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2121 }
2122}
2123
2124void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2125 LocationSummary* locations = div->GetLocations();
2126 Location out = locations->Out();
2127 Location first = locations->InAt(0);
2128 Location second = locations->InAt(1);
2129
2130 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002131 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002132 __ sdiv(out.AsRegister<Register>(),
2133 first.AsRegister<Register>(),
2134 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002135 break;
2136 }
2137
Calin Juravle7c4954d2014-10-28 16:57:40 +00002138 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002139 InvokeRuntimeCallingConvention calling_convention;
2140 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2141 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2142 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2143 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2144 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002145 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002146
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002147 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002148 break;
2149 }
2150
2151 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002152 __ vdivs(out.AsFpuRegister<SRegister>(),
2153 first.AsFpuRegister<SRegister>(),
2154 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002155 break;
2156 }
2157
2158 case Primitive::kPrimDouble: {
2159 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2160 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2161 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2162 break;
2163 }
2164
2165 default:
2166 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2167 }
2168}
2169
Calin Juravlebacfec32014-11-14 15:54:36 +00002170void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002171 Primitive::Type type = rem->GetResultType();
2172 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2173 ? LocationSummary::kNoCall
2174 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002175 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2176
Calin Juravled2ec87d2014-12-08 14:24:46 +00002177 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002178 case Primitive::kPrimInt: {
2179 locations->SetInAt(0, Location::RequiresRegister());
2180 locations->SetInAt(1, Location::RequiresRegister());
2181 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2182 locations->AddTemp(Location::RequiresRegister());
2183 break;
2184 }
2185 case Primitive::kPrimLong: {
2186 InvokeRuntimeCallingConvention calling_convention;
2187 locations->SetInAt(0, Location::RegisterPairLocation(
2188 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2189 locations->SetInAt(1, Location::RegisterPairLocation(
2190 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2191 // The runtime helper puts the output in R2,R3.
2192 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2193 break;
2194 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002195 case Primitive::kPrimFloat: {
2196 InvokeRuntimeCallingConvention calling_convention;
2197 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2198 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2199 locations->SetOut(Location::FpuRegisterLocation(S0));
2200 break;
2201 }
2202
Calin Juravlebacfec32014-11-14 15:54:36 +00002203 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002204 InvokeRuntimeCallingConvention calling_convention;
2205 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2206 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2207 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2208 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2209 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002210 break;
2211 }
2212
2213 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002214 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002215 }
2216}
2217
2218void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2219 LocationSummary* locations = rem->GetLocations();
2220 Location out = locations->Out();
2221 Location first = locations->InAt(0);
2222 Location second = locations->InAt(1);
2223
Calin Juravled2ec87d2014-12-08 14:24:46 +00002224 Primitive::Type type = rem->GetResultType();
2225 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002226 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002227 Register reg1 = first.AsRegister<Register>();
2228 Register reg2 = second.AsRegister<Register>();
2229 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002230
2231 // temp = reg1 / reg2 (integer division)
2232 // temp = temp * reg2
2233 // dest = reg1 - temp
2234 __ sdiv(temp, reg1, reg2);
2235 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002236 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002237 break;
2238 }
2239
2240 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002241 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002242 break;
2243 }
2244
Calin Juravled2ec87d2014-12-08 14:24:46 +00002245 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002246 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002247 break;
2248 }
2249
Calin Juravlebacfec32014-11-14 15:54:36 +00002250 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002251 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002252 break;
2253 }
2254
2255 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002256 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002257 }
2258}
2259
Calin Juravled0d48522014-11-04 16:40:20 +00002260void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2261 LocationSummary* locations =
2262 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002263 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002264 if (instruction->HasUses()) {
2265 locations->SetOut(Location::SameAsFirstInput());
2266 }
2267}
2268
2269void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2270 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2271 codegen_->AddSlowPath(slow_path);
2272
2273 LocationSummary* locations = instruction->GetLocations();
2274 Location value = locations->InAt(0);
2275
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002276 switch (instruction->GetType()) {
2277 case Primitive::kPrimInt: {
2278 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002279 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002280 __ b(slow_path->GetEntryLabel(), EQ);
2281 } else {
2282 DCHECK(value.IsConstant()) << value;
2283 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2284 __ b(slow_path->GetEntryLabel());
2285 }
2286 }
2287 break;
2288 }
2289 case Primitive::kPrimLong: {
2290 if (value.IsRegisterPair()) {
2291 __ orrs(IP,
2292 value.AsRegisterPairLow<Register>(),
2293 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2294 __ b(slow_path->GetEntryLabel(), EQ);
2295 } else {
2296 DCHECK(value.IsConstant()) << value;
2297 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2298 __ b(slow_path->GetEntryLabel());
2299 }
2300 }
2301 break;
2302 default:
2303 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2304 }
2305 }
Calin Juravled0d48522014-11-04 16:40:20 +00002306}
2307
Calin Juravle9aec02f2014-11-18 23:06:35 +00002308void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2309 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2310
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002311 LocationSummary* locations =
2312 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002313
2314 switch (op->GetResultType()) {
2315 case Primitive::kPrimInt: {
2316 locations->SetInAt(0, Location::RequiresRegister());
2317 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002318 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002319 break;
2320 }
2321 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002322 locations->SetInAt(0, Location::RequiresRegister());
2323 locations->SetInAt(1, Location::RequiresRegister());
2324 locations->AddTemp(Location::RequiresRegister());
2325 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002326 break;
2327 }
2328 default:
2329 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2330 }
2331}
2332
2333void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2334 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2335
2336 LocationSummary* locations = op->GetLocations();
2337 Location out = locations->Out();
2338 Location first = locations->InAt(0);
2339 Location second = locations->InAt(1);
2340
2341 Primitive::Type type = op->GetResultType();
2342 switch (type) {
2343 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002344 Register out_reg = out.AsRegister<Register>();
2345 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002346 // Arm doesn't mask the shift count so we need to do it ourselves.
2347 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002348 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002349 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2350 if (op->IsShl()) {
2351 __ Lsl(out_reg, first_reg, second_reg);
2352 } else if (op->IsShr()) {
2353 __ Asr(out_reg, first_reg, second_reg);
2354 } else {
2355 __ Lsr(out_reg, first_reg, second_reg);
2356 }
2357 } else {
2358 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2359 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2360 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2361 __ Mov(out_reg, first_reg);
2362 } else if (op->IsShl()) {
2363 __ Lsl(out_reg, first_reg, shift_value);
2364 } else if (op->IsShr()) {
2365 __ Asr(out_reg, first_reg, shift_value);
2366 } else {
2367 __ Lsr(out_reg, first_reg, shift_value);
2368 }
2369 }
2370 break;
2371 }
2372 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002373 Register o_h = out.AsRegisterPairHigh<Register>();
2374 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002375
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002376 Register temp = locations->GetTemp(0).AsRegister<Register>();
2377
2378 Register high = first.AsRegisterPairHigh<Register>();
2379 Register low = first.AsRegisterPairLow<Register>();
2380
2381 Register second_reg = second.AsRegister<Register>();
2382
Calin Juravle9aec02f2014-11-18 23:06:35 +00002383 if (op->IsShl()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002384 // Shift the high part
2385 __ and_(second_reg, second_reg, ShifterOperand(63));
2386 __ Lsl(o_h, high, second_reg);
2387 // Shift the low part and `or` what overflew on the high part
2388 __ rsb(temp, second_reg, ShifterOperand(32));
2389 __ Lsr(temp, low, temp);
2390 __ orr(o_h, o_h, ShifterOperand(temp));
2391 // If the shift is > 32 bits, override the high part
2392 __ subs(temp, second_reg, ShifterOperand(32));
2393 __ it(PL);
2394 __ Lsl(o_h, low, temp, false, PL);
2395 // Shift the low part
2396 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002397 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002398 // Shift the low part
2399 __ and_(second_reg, second_reg, ShifterOperand(63));
2400 __ Lsr(o_l, low, second_reg);
2401 // Shift the high part and `or` what underflew on the low part
2402 __ rsb(temp, second_reg, ShifterOperand(32));
2403 __ Lsl(temp, high, temp);
2404 __ orr(o_l, o_l, ShifterOperand(temp));
2405 // If the shift is > 32 bits, override the low part
2406 __ subs(temp, second_reg, ShifterOperand(32));
2407 __ it(PL);
2408 __ Asr(o_l, high, temp, false, PL);
2409 // Shift the high part
2410 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002411 } else {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002412 // same as Shr except we use `Lsr`s and not `Asr`s
2413 __ and_(second_reg, second_reg, ShifterOperand(63));
2414 __ Lsr(o_l, low, second_reg);
2415 __ rsb(temp, second_reg, ShifterOperand(32));
2416 __ Lsl(temp, high, temp);
2417 __ orr(o_l, o_l, ShifterOperand(temp));
2418 __ subs(temp, second_reg, ShifterOperand(32));
2419 __ it(PL);
2420 __ Lsr(o_l, high, temp, false, PL);
2421 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002422 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002423 break;
2424 }
2425 default:
2426 LOG(FATAL) << "Unexpected operation type " << type;
2427 }
2428}
2429
2430void LocationsBuilderARM::VisitShl(HShl* shl) {
2431 HandleShift(shl);
2432}
2433
2434void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2435 HandleShift(shl);
2436}
2437
2438void LocationsBuilderARM::VisitShr(HShr* shr) {
2439 HandleShift(shr);
2440}
2441
2442void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2443 HandleShift(shr);
2444}
2445
2446void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2447 HandleShift(ushr);
2448}
2449
2450void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2451 HandleShift(ushr);
2452}
2453
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002454void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002455 LocationSummary* locations =
2456 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002457 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002458 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2459 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2460 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002461}
2462
2463void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2464 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002465 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002466 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002467 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2468 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002469 instruction->GetDexPc(),
2470 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002471}
2472
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002473void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2474 LocationSummary* locations =
2475 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2476 InvokeRuntimeCallingConvention calling_convention;
2477 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002478 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002479 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002480 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002481}
2482
2483void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2484 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002485 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002486 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002487 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2488 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002489 instruction->GetDexPc(),
2490 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002491}
2492
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002493void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002494 LocationSummary* locations =
2495 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002496 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2497 if (location.IsStackSlot()) {
2498 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2499 } else if (location.IsDoubleStackSlot()) {
2500 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002501 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002502 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002503}
2504
2505void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002506 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002507 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002508}
2509
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002510void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002511 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002512 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002513 locations->SetInAt(0, Location::RequiresRegister());
2514 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002515}
2516
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002517void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2518 LocationSummary* locations = not_->GetLocations();
2519 Location out = locations->Out();
2520 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002521 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002522 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002523 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002524 break;
2525
2526 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002527 __ mvn(out.AsRegisterPairLow<Register>(),
2528 ShifterOperand(in.AsRegisterPairLow<Register>()));
2529 __ mvn(out.AsRegisterPairHigh<Register>(),
2530 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002531 break;
2532
2533 default:
2534 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2535 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002536}
2537
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002538void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002539 LocationSummary* locations =
2540 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002541 switch (compare->InputAt(0)->GetType()) {
2542 case Primitive::kPrimLong: {
2543 locations->SetInAt(0, Location::RequiresRegister());
2544 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002545 // Output overlaps because it is written before doing the low comparison.
2546 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002547 break;
2548 }
2549 case Primitive::kPrimFloat:
2550 case Primitive::kPrimDouble: {
2551 locations->SetInAt(0, Location::RequiresFpuRegister());
2552 locations->SetInAt(1, Location::RequiresFpuRegister());
2553 locations->SetOut(Location::RequiresRegister());
2554 break;
2555 }
2556 default:
2557 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2558 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002559}
2560
2561void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002562 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002563 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002564 Location left = locations->InAt(0);
2565 Location right = locations->InAt(1);
2566
2567 Label less, greater, done;
2568 Primitive::Type type = compare->InputAt(0)->GetType();
2569 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002570 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002571 __ cmp(left.AsRegisterPairHigh<Register>(),
2572 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002573 __ b(&less, LT);
2574 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002575 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2576 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002577 __ cmp(left.AsRegisterPairLow<Register>(),
2578 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002579 break;
2580 }
2581 case Primitive::kPrimFloat:
2582 case Primitive::kPrimDouble: {
2583 __ LoadImmediate(out, 0);
2584 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002585 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002586 } else {
2587 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2588 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2589 }
2590 __ vmstat(); // transfer FP status register to ARM APSR.
2591 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002592 break;
2593 }
2594 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002595 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002596 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002597 __ b(&done, EQ);
2598 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2599
2600 __ Bind(&greater);
2601 __ LoadImmediate(out, 1);
2602 __ b(&done);
2603
2604 __ Bind(&less);
2605 __ LoadImmediate(out, -1);
2606
2607 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002608}
2609
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002610void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002611 LocationSummary* locations =
2612 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002613 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2614 locations->SetInAt(i, Location::Any());
2615 }
2616 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002617}
2618
2619void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002620 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002621 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002622}
2623
Calin Juravle52c48962014-12-16 17:02:57 +00002624void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2625 // TODO (ported from quick): revisit Arm barrier kinds
2626 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2627 switch (kind) {
2628 case MemBarrierKind::kAnyStore:
2629 case MemBarrierKind::kLoadAny:
2630 case MemBarrierKind::kAnyAny: {
2631 flavour = DmbOptions::ISH;
2632 break;
2633 }
2634 case MemBarrierKind::kStoreStore: {
2635 flavour = DmbOptions::ISHST;
2636 break;
2637 }
2638 default:
2639 LOG(FATAL) << "Unexpected memory barrier " << kind;
2640 }
2641 __ dmb(flavour);
2642}
2643
2644void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2645 uint32_t offset,
2646 Register out_lo,
2647 Register out_hi) {
2648 if (offset != 0) {
2649 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002650 __ add(IP, addr, ShifterOperand(out_lo));
2651 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002652 }
2653 __ ldrexd(out_lo, out_hi, addr);
2654}
2655
2656void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2657 uint32_t offset,
2658 Register value_lo,
2659 Register value_hi,
2660 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002661 Register temp2,
2662 HInstruction* instruction) {
Calin Juravle52c48962014-12-16 17:02:57 +00002663 Label fail;
2664 if (offset != 0) {
2665 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002666 __ add(IP, addr, ShifterOperand(temp1));
2667 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002668 }
2669 __ Bind(&fail);
2670 // We need a load followed by store. (The address used in a STREX instruction must
2671 // be the same as the address in the most recently executed LDREX instruction.)
2672 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002673 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002674 __ strexd(temp1, value_lo, value_hi, addr);
2675 __ cmp(temp1, ShifterOperand(0));
2676 __ b(&fail, NE);
2677}
2678
2679void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2680 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2681
Nicolas Geoffray39468442014-09-02 15:17:15 +01002682 LocationSummary* locations =
2683 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002684 locations->SetInAt(0, Location::RequiresRegister());
2685 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002686
Calin Juravle34166012014-12-19 17:22:29 +00002687
Calin Juravle52c48962014-12-16 17:02:57 +00002688 Primitive::Type field_type = field_info.GetFieldType();
2689 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002690 bool generate_volatile = field_info.IsVolatile()
2691 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002692 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002693 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002694 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2695 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002696 locations->AddTemp(Location::RequiresRegister());
2697 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002698 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002699 // Arm encoding have some additional constraints for ldrexd/strexd:
2700 // - registers need to be consecutive
2701 // - the first register should be even but not R14.
2702 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2703 // enable Arm encoding.
2704 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2705
2706 locations->AddTemp(Location::RequiresRegister());
2707 locations->AddTemp(Location::RequiresRegister());
2708 if (field_type == Primitive::kPrimDouble) {
2709 // For doubles we need two more registers to copy the value.
2710 locations->AddTemp(Location::RegisterLocation(R2));
2711 locations->AddTemp(Location::RegisterLocation(R3));
2712 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002713 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002714}
2715
Calin Juravle52c48962014-12-16 17:02:57 +00002716void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2717 const FieldInfo& field_info) {
2718 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2719
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002720 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002721 Register base = locations->InAt(0).AsRegister<Register>();
2722 Location value = locations->InAt(1);
2723
2724 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002725 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002726 Primitive::Type field_type = field_info.GetFieldType();
2727 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2728
2729 if (is_volatile) {
2730 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2731 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002732
2733 switch (field_type) {
2734 case Primitive::kPrimBoolean:
2735 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002736 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002737 break;
2738 }
2739
2740 case Primitive::kPrimShort:
2741 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002742 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002743 break;
2744 }
2745
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002746 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002747 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00002748 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002749 break;
2750 }
2751
2752 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002753 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002754 GenerateWideAtomicStore(base, offset,
2755 value.AsRegisterPairLow<Register>(),
2756 value.AsRegisterPairHigh<Register>(),
2757 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002758 locations->GetTemp(1).AsRegister<Register>(),
2759 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002760 } else {
2761 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002762 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002763 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002764 break;
2765 }
2766
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002767 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002768 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002769 break;
2770 }
2771
2772 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002773 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002774 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002775 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2776 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2777
2778 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2779
2780 GenerateWideAtomicStore(base, offset,
2781 value_reg_lo,
2782 value_reg_hi,
2783 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002784 locations->GetTemp(3).AsRegister<Register>(),
2785 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002786 } else {
2787 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002788 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002789 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002790 break;
2791 }
2792
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002793 case Primitive::kPrimVoid:
2794 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002795 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002796 }
Calin Juravle52c48962014-12-16 17:02:57 +00002797
Calin Juravle77520bc2015-01-12 18:45:46 +00002798 // Longs and doubles are handled in the switch.
2799 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
2800 codegen_->MaybeRecordImplicitNullCheck(instruction);
2801 }
2802
2803 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
2804 Register temp = locations->GetTemp(0).AsRegister<Register>();
2805 Register card = locations->GetTemp(1).AsRegister<Register>();
2806 codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>());
2807 }
2808
Calin Juravle52c48962014-12-16 17:02:57 +00002809 if (is_volatile) {
2810 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2811 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002812}
2813
Calin Juravle52c48962014-12-16 17:02:57 +00002814void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2815 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002816 LocationSummary* locations =
2817 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002818 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002819
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002820 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00002821 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002822 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002823 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
2824 locations->SetOut(Location::RequiresRegister(),
2825 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
2826 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00002827 // Arm encoding have some additional constraints for ldrexd/strexd:
2828 // - registers need to be consecutive
2829 // - the first register should be even but not R14.
2830 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2831 // enable Arm encoding.
2832 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2833 locations->AddTemp(Location::RequiresRegister());
2834 locations->AddTemp(Location::RequiresRegister());
2835 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002836}
2837
Calin Juravle52c48962014-12-16 17:02:57 +00002838void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2839 const FieldInfo& field_info) {
2840 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002841
Calin Juravle52c48962014-12-16 17:02:57 +00002842 LocationSummary* locations = instruction->GetLocations();
2843 Register base = locations->InAt(0).AsRegister<Register>();
2844 Location out = locations->Out();
2845 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002846 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002847 Primitive::Type field_type = field_info.GetFieldType();
2848 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2849
2850 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002851 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002852 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002853 break;
2854 }
2855
2856 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002857 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002858 break;
2859 }
2860
2861 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002862 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002863 break;
2864 }
2865
2866 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002867 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002868 break;
2869 }
2870
2871 case Primitive::kPrimInt:
2872 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002873 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002874 break;
2875 }
2876
2877 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002878 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002879 GenerateWideAtomicLoad(base, offset,
2880 out.AsRegisterPairLow<Register>(),
2881 out.AsRegisterPairHigh<Register>());
2882 } else {
2883 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2884 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002885 break;
2886 }
2887
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002888 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002889 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002890 break;
2891 }
2892
2893 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002894 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002895 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002896 Register lo = locations->GetTemp(0).AsRegister<Register>();
2897 Register hi = locations->GetTemp(1).AsRegister<Register>();
2898 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00002899 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002900 __ vmovdrr(out_reg, lo, hi);
2901 } else {
2902 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002903 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002904 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002905 break;
2906 }
2907
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002908 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002909 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002910 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002911 }
Calin Juravle52c48962014-12-16 17:02:57 +00002912
Calin Juravle77520bc2015-01-12 18:45:46 +00002913 // Doubles are handled in the switch.
2914 if (field_type != Primitive::kPrimDouble) {
2915 codegen_->MaybeRecordImplicitNullCheck(instruction);
2916 }
2917
Calin Juravle52c48962014-12-16 17:02:57 +00002918 if (is_volatile) {
2919 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2920 }
2921}
2922
2923void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2924 HandleFieldSet(instruction, instruction->GetFieldInfo());
2925}
2926
2927void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2928 HandleFieldSet(instruction, instruction->GetFieldInfo());
2929}
2930
2931void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2932 HandleFieldGet(instruction, instruction->GetFieldInfo());
2933}
2934
2935void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2936 HandleFieldGet(instruction, instruction->GetFieldInfo());
2937}
2938
2939void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2940 HandleFieldGet(instruction, instruction->GetFieldInfo());
2941}
2942
2943void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2944 HandleFieldGet(instruction, instruction->GetFieldInfo());
2945}
2946
2947void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2948 HandleFieldSet(instruction, instruction->GetFieldInfo());
2949}
2950
2951void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2952 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002953}
2954
2955void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002956 LocationSummary* locations =
2957 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00002958 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002959 if (instruction->HasUses()) {
2960 locations->SetOut(Location::SameAsFirstInput());
2961 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002962}
2963
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002964void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002965 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2966 return;
2967 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002968 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002969
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002970 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
2971 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2972}
2973
2974void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002975 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002976 codegen_->AddSlowPath(slow_path);
2977
2978 LocationSummary* locations = instruction->GetLocations();
2979 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002980
Calin Juravle77520bc2015-01-12 18:45:46 +00002981 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
2982 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002983}
2984
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002985void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
2986 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2987 GenerateImplicitNullCheck(instruction);
2988 } else {
2989 GenerateExplicitNullCheck(instruction);
2990 }
2991}
2992
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002993void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002994 LocationSummary* locations =
2995 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002996 locations->SetInAt(0, Location::RequiresRegister());
2997 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2998 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002999}
3000
3001void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3002 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003003 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003004 Location index = locations->InAt(1);
3005
3006 switch (instruction->GetType()) {
3007 case Primitive::kPrimBoolean: {
3008 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003009 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003010 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003011 size_t offset =
3012 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003013 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3014 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003015 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003016 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3017 }
3018 break;
3019 }
3020
3021 case Primitive::kPrimByte: {
3022 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003023 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003024 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003025 size_t offset =
3026 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003027 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3028 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003029 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003030 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3031 }
3032 break;
3033 }
3034
3035 case Primitive::kPrimShort: {
3036 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003037 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003038 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003039 size_t offset =
3040 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003041 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3042 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003043 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003044 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3045 }
3046 break;
3047 }
3048
3049 case Primitive::kPrimChar: {
3050 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003051 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003052 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003053 size_t offset =
3054 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003055 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3056 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003057 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003058 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3059 }
3060 break;
3061 }
3062
3063 case Primitive::kPrimInt:
3064 case Primitive::kPrimNot: {
3065 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3066 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003067 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003068 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003069 size_t offset =
3070 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003071 __ LoadFromOffset(kLoadWord, out, obj, offset);
3072 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003073 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003074 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3075 }
3076 break;
3077 }
3078
3079 case Primitive::kPrimLong: {
3080 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003081 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003082 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003083 size_t offset =
3084 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003085 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003086 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003087 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003088 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003089 }
3090 break;
3091 }
3092
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003093 case Primitive::kPrimFloat: {
3094 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3095 Location out = locations->Out();
3096 DCHECK(out.IsFpuRegister());
3097 if (index.IsConstant()) {
3098 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3099 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3100 } else {
3101 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3102 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3103 }
3104 break;
3105 }
3106
3107 case Primitive::kPrimDouble: {
3108 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3109 Location out = locations->Out();
3110 DCHECK(out.IsFpuRegisterPair());
3111 if (index.IsConstant()) {
3112 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3113 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3114 } else {
3115 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3116 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3117 }
3118 break;
3119 }
3120
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003121 case Primitive::kPrimVoid:
3122 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003123 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003124 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003125 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003126}
3127
3128void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003129 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003130
3131 bool needs_write_barrier =
3132 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3133 bool needs_runtime_call = instruction->NeedsTypeCheck();
3134
Nicolas Geoffray39468442014-09-02 15:17:15 +01003135 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003136 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3137 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003138 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003139 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3140 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3141 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003142 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003143 locations->SetInAt(0, Location::RequiresRegister());
3144 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3145 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003146
3147 if (needs_write_barrier) {
3148 // Temporary registers for the write barrier.
3149 locations->AddTemp(Location::RequiresRegister());
3150 locations->AddTemp(Location::RequiresRegister());
3151 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003152 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003153}
3154
3155void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3156 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003157 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003158 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003159 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003160 bool needs_runtime_call = locations->WillCall();
3161 bool needs_write_barrier =
3162 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003163
3164 switch (value_type) {
3165 case Primitive::kPrimBoolean:
3166 case Primitive::kPrimByte: {
3167 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003168 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003169 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003170 size_t offset =
3171 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003172 __ StoreToOffset(kStoreByte, value, obj, offset);
3173 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003174 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003175 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3176 }
3177 break;
3178 }
3179
3180 case Primitive::kPrimShort:
3181 case Primitive::kPrimChar: {
3182 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003183 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003184 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003185 size_t offset =
3186 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003187 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3188 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003189 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003190 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3191 }
3192 break;
3193 }
3194
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003195 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003196 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003197 if (!needs_runtime_call) {
3198 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003199 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003200 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003201 size_t offset =
3202 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003203 __ StoreToOffset(kStoreWord, value, obj, offset);
3204 } else {
3205 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003206 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003207 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3208 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003209 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003210 if (needs_write_barrier) {
3211 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003212 Register temp = locations->GetTemp(0).AsRegister<Register>();
3213 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003214 codegen_->MarkGCCard(temp, card, obj, value);
3215 }
3216 } else {
3217 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003218 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3219 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003220 instruction->GetDexPc(),
3221 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003222 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003223 break;
3224 }
3225
3226 case Primitive::kPrimLong: {
3227 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003228 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003229 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003230 size_t offset =
3231 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003232 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003233 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003234 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003235 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003236 }
3237 break;
3238 }
3239
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003240 case Primitive::kPrimFloat: {
3241 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3242 Location value = locations->InAt(2);
3243 DCHECK(value.IsFpuRegister());
3244 if (index.IsConstant()) {
3245 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3246 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3247 } else {
3248 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3249 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3250 }
3251 break;
3252 }
3253
3254 case Primitive::kPrimDouble: {
3255 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3256 Location value = locations->InAt(2);
3257 DCHECK(value.IsFpuRegisterPair());
3258 if (index.IsConstant()) {
3259 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3260 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3261 } else {
3262 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3263 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3264 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003265
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003266 break;
3267 }
3268
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003269 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003270 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003271 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003272 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003273
3274 // Ints and objects are handled in the switch.
3275 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3276 codegen_->MaybeRecordImplicitNullCheck(instruction);
3277 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003278}
3279
3280void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003281 LocationSummary* locations =
3282 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003283 locations->SetInAt(0, Location::RequiresRegister());
3284 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003285}
3286
3287void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3288 LocationSummary* locations = instruction->GetLocations();
3289 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003290 Register obj = locations->InAt(0).AsRegister<Register>();
3291 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003292 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003293 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003294}
3295
3296void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003297 LocationSummary* locations =
3298 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003299 locations->SetInAt(0, Location::RequiresRegister());
3300 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003301 if (instruction->HasUses()) {
3302 locations->SetOut(Location::SameAsFirstInput());
3303 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003304}
3305
3306void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3307 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003308 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003309 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003310 codegen_->AddSlowPath(slow_path);
3311
Roland Levillain271ab9c2014-11-27 15:23:57 +00003312 Register index = locations->InAt(0).AsRegister<Register>();
3313 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003314
3315 __ cmp(index, ShifterOperand(length));
3316 __ b(slow_path->GetEntryLabel(), CS);
3317}
3318
3319void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3320 Label is_null;
3321 __ CompareAndBranchIfZero(value, &is_null);
3322 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3323 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3324 __ strb(card, Address(card, temp));
3325 __ Bind(&is_null);
3326}
3327
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003328void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3329 temp->SetLocations(nullptr);
3330}
3331
3332void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3333 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003334 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003335}
3336
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003337void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003338 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003339 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003340}
3341
3342void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003343 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3344}
3345
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003346void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3347 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3348}
3349
3350void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003351 HBasicBlock* block = instruction->GetBlock();
3352 if (block->GetLoopInformation() != nullptr) {
3353 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3354 // The back edge will generate the suspend check.
3355 return;
3356 }
3357 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3358 // The goto will generate the suspend check.
3359 return;
3360 }
3361 GenerateSuspendCheck(instruction, nullptr);
3362}
3363
3364void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3365 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003366 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003367 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003368 codegen_->AddSlowPath(slow_path);
3369
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003370 __ LoadFromOffset(
3371 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3372 __ cmp(IP, ShifterOperand(0));
3373 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003374 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003375 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003376 __ Bind(slow_path->GetReturnLabel());
3377 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003378 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003379 __ b(slow_path->GetEntryLabel());
3380 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003381}
3382
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003383ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3384 return codegen_->GetAssembler();
3385}
3386
3387void ParallelMoveResolverARM::EmitMove(size_t index) {
3388 MoveOperands* move = moves_.Get(index);
3389 Location source = move->GetSource();
3390 Location destination = move->GetDestination();
3391
3392 if (source.IsRegister()) {
3393 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003394 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003395 } else {
3396 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003397 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003398 SP, destination.GetStackIndex());
3399 }
3400 } else if (source.IsStackSlot()) {
3401 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003402 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003403 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003404 } else if (destination.IsFpuRegister()) {
3405 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003406 } else {
3407 DCHECK(destination.IsStackSlot());
3408 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3409 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3410 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003411 } else if (source.IsFpuRegister()) {
3412 if (destination.IsFpuRegister()) {
3413 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003414 } else {
3415 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003416 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3417 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003418 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003419 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003420 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3421 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003422 } else if (destination.IsRegisterPair()) {
3423 DCHECK(ExpectedPairLayout(destination));
3424 __ LoadFromOffset(
3425 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3426 } else {
3427 DCHECK(destination.IsFpuRegisterPair()) << destination;
3428 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3429 SP,
3430 source.GetStackIndex());
3431 }
3432 } else if (source.IsRegisterPair()) {
3433 if (destination.IsRegisterPair()) {
3434 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3435 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3436 } else {
3437 DCHECK(destination.IsDoubleStackSlot()) << destination;
3438 DCHECK(ExpectedPairLayout(source));
3439 __ StoreToOffset(
3440 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3441 }
3442 } else if (source.IsFpuRegisterPair()) {
3443 if (destination.IsFpuRegisterPair()) {
3444 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3445 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3446 } else {
3447 DCHECK(destination.IsDoubleStackSlot()) << destination;
3448 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3449 SP,
3450 destination.GetStackIndex());
3451 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003452 } else {
3453 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003454 HConstant* constant = source.GetConstant();
3455 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3456 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003457 if (destination.IsRegister()) {
3458 __ LoadImmediate(destination.AsRegister<Register>(), value);
3459 } else {
3460 DCHECK(destination.IsStackSlot());
3461 __ LoadImmediate(IP, value);
3462 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3463 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003464 } else if (constant->IsLongConstant()) {
3465 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003466 if (destination.IsRegisterPair()) {
3467 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3468 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003469 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003470 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003471 __ LoadImmediate(IP, Low32Bits(value));
3472 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3473 __ LoadImmediate(IP, High32Bits(value));
3474 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3475 }
3476 } else if (constant->IsDoubleConstant()) {
3477 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003478 if (destination.IsFpuRegisterPair()) {
3479 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003480 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003481 DCHECK(destination.IsDoubleStackSlot()) << destination;
3482 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003483 __ LoadImmediate(IP, Low32Bits(int_value));
3484 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3485 __ LoadImmediate(IP, High32Bits(int_value));
3486 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3487 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003488 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003489 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003490 float value = constant->AsFloatConstant()->GetValue();
3491 if (destination.IsFpuRegister()) {
3492 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3493 } else {
3494 DCHECK(destination.IsStackSlot());
3495 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3496 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3497 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003498 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003499 }
3500}
3501
3502void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3503 __ Mov(IP, reg);
3504 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3505 __ StoreToOffset(kStoreWord, IP, SP, mem);
3506}
3507
3508void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3509 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3510 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3511 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3512 SP, mem1 + stack_offset);
3513 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3514 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3515 SP, mem2 + stack_offset);
3516 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3517}
3518
3519void ParallelMoveResolverARM::EmitSwap(size_t index) {
3520 MoveOperands* move = moves_.Get(index);
3521 Location source = move->GetSource();
3522 Location destination = move->GetDestination();
3523
3524 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003525 DCHECK_NE(source.AsRegister<Register>(), IP);
3526 DCHECK_NE(destination.AsRegister<Register>(), IP);
3527 __ Mov(IP, source.AsRegister<Register>());
3528 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3529 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003530 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003531 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003532 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003533 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003534 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3535 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003536 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003537 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003538 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003539 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003540 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003541 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003542 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003543 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003544 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3545 destination.AsRegisterPairHigh<Register>(),
3546 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003547 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003548 Register low_reg = source.IsRegisterPair()
3549 ? source.AsRegisterPairLow<Register>()
3550 : destination.AsRegisterPairLow<Register>();
3551 int mem = source.IsRegisterPair()
3552 ? destination.GetStackIndex()
3553 : source.GetStackIndex();
3554 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003555 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003556 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003557 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003558 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003559 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3560 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003561 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003562 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003563 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003564 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3565 DRegister reg = source.IsFpuRegisterPair()
3566 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3567 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3568 int mem = source.IsFpuRegisterPair()
3569 ? destination.GetStackIndex()
3570 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003571 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003572 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003573 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003574 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3575 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3576 : destination.AsFpuRegister<SRegister>();
3577 int mem = source.IsFpuRegister()
3578 ? destination.GetStackIndex()
3579 : source.GetStackIndex();
3580
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003581 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003582 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003583 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003584 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003585 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3586 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003587 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003588 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003589 }
3590}
3591
3592void ParallelMoveResolverARM::SpillScratch(int reg) {
3593 __ Push(static_cast<Register>(reg));
3594}
3595
3596void ParallelMoveResolverARM::RestoreScratch(int reg) {
3597 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003598}
3599
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003600void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003601 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3602 ? LocationSummary::kCallOnSlowPath
3603 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003604 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003605 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003606 locations->SetOut(Location::RequiresRegister());
3607}
3608
3609void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003610 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003611 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003612 DCHECK(!cls->CanCallRuntime());
3613 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003614 codegen_->LoadCurrentMethod(out);
3615 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3616 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003617 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003618 codegen_->LoadCurrentMethod(out);
3619 __ LoadFromOffset(
3620 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3621 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003622
3623 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3624 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3625 codegen_->AddSlowPath(slow_path);
3626 __ cmp(out, ShifterOperand(0));
3627 __ b(slow_path->GetEntryLabel(), EQ);
3628 if (cls->MustGenerateClinitCheck()) {
3629 GenerateClassInitializationCheck(slow_path, out);
3630 } else {
3631 __ Bind(slow_path->GetExitLabel());
3632 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003633 }
3634}
3635
3636void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3637 LocationSummary* locations =
3638 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3639 locations->SetInAt(0, Location::RequiresRegister());
3640 if (check->HasUses()) {
3641 locations->SetOut(Location::SameAsFirstInput());
3642 }
3643}
3644
3645void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003646 // We assume the class is not null.
3647 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3648 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003649 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003650 GenerateClassInitializationCheck(slow_path,
3651 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003652}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003653
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003654void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3655 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003656 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3657 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3658 __ b(slow_path->GetEntryLabel(), LT);
3659 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3660 // properly. Therefore, we do a memory fence.
3661 __ dmb(ISH);
3662 __ Bind(slow_path->GetExitLabel());
3663}
3664
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003665void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3666 LocationSummary* locations =
3667 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3668 locations->SetOut(Location::RequiresRegister());
3669}
3670
3671void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3672 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3673 codegen_->AddSlowPath(slow_path);
3674
Roland Levillain271ab9c2014-11-27 15:23:57 +00003675 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003676 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003677 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3678 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003679 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3680 __ cmp(out, ShifterOperand(0));
3681 __ b(slow_path->GetEntryLabel(), EQ);
3682 __ Bind(slow_path->GetExitLabel());
3683}
3684
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003685void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3686 LocationSummary* locations =
3687 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3688 locations->SetOut(Location::RequiresRegister());
3689}
3690
3691void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003692 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003693 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3694 __ LoadFromOffset(kLoadWord, out, TR, offset);
3695 __ LoadImmediate(IP, 0);
3696 __ StoreToOffset(kStoreWord, IP, TR, offset);
3697}
3698
3699void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3700 LocationSummary* locations =
3701 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3702 InvokeRuntimeCallingConvention calling_convention;
3703 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3704}
3705
3706void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3707 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003708 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003709}
3710
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003711void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003712 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3713 ? LocationSummary::kNoCall
3714 : LocationSummary::kCallOnSlowPath;
3715 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3716 locations->SetInAt(0, Location::RequiresRegister());
3717 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003718 // The out register is used as a temporary, so it overlaps with the inputs.
3719 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003720}
3721
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003722void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003723 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003724 Register obj = locations->InAt(0).AsRegister<Register>();
3725 Register cls = locations->InAt(1).AsRegister<Register>();
3726 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003727 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3728 Label done, zero;
3729 SlowPathCodeARM* slow_path = nullptr;
3730
3731 // Return 0 if `obj` is null.
3732 // TODO: avoid this check if we know obj is not null.
3733 __ cmp(obj, ShifterOperand(0));
3734 __ b(&zero, EQ);
3735 // Compare the class of `obj` with `cls`.
3736 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3737 __ cmp(out, ShifterOperand(cls));
3738 if (instruction->IsClassFinal()) {
3739 // Classes must be equal for the instanceof to succeed.
3740 __ b(&zero, NE);
3741 __ LoadImmediate(out, 1);
3742 __ b(&done);
3743 } else {
3744 // If the classes are not equal, we go into a slow path.
3745 DCHECK(locations->OnlyCallsOnSlowPath());
3746 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003747 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003748 codegen_->AddSlowPath(slow_path);
3749 __ b(slow_path->GetEntryLabel(), NE);
3750 __ LoadImmediate(out, 1);
3751 __ b(&done);
3752 }
3753 __ Bind(&zero);
3754 __ LoadImmediate(out, 0);
3755 if (slow_path != nullptr) {
3756 __ Bind(slow_path->GetExitLabel());
3757 }
3758 __ Bind(&done);
3759}
3760
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003761void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3762 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3763 instruction, LocationSummary::kCallOnSlowPath);
3764 locations->SetInAt(0, Location::RequiresRegister());
3765 locations->SetInAt(1, Location::RequiresRegister());
3766 locations->AddTemp(Location::RequiresRegister());
3767}
3768
3769void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3770 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003771 Register obj = locations->InAt(0).AsRegister<Register>();
3772 Register cls = locations->InAt(1).AsRegister<Register>();
3773 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003774 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3775
3776 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3777 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3778 codegen_->AddSlowPath(slow_path);
3779
3780 // TODO: avoid this check if we know obj is not null.
3781 __ cmp(obj, ShifterOperand(0));
3782 __ b(slow_path->GetExitLabel(), EQ);
3783 // Compare the class of `obj` with `cls`.
3784 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3785 __ cmp(temp, ShifterOperand(cls));
3786 __ b(slow_path->GetEntryLabel(), NE);
3787 __ Bind(slow_path->GetExitLabel());
3788}
3789
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003790void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3791 LocationSummary* locations =
3792 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3793 InvokeRuntimeCallingConvention calling_convention;
3794 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3795}
3796
3797void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3798 codegen_->InvokeRuntime(instruction->IsEnter()
3799 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3800 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003801 instruction->GetDexPc(),
3802 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003803}
3804
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003805void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3806void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3807void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3808
3809void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3810 LocationSummary* locations =
3811 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3812 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3813 || instruction->GetResultType() == Primitive::kPrimLong);
3814 locations->SetInAt(0, Location::RequiresRegister());
3815 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003816 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003817}
3818
3819void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3820 HandleBitwiseOperation(instruction);
3821}
3822
3823void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3824 HandleBitwiseOperation(instruction);
3825}
3826
3827void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3828 HandleBitwiseOperation(instruction);
3829}
3830
3831void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3832 LocationSummary* locations = instruction->GetLocations();
3833
3834 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003835 Register first = locations->InAt(0).AsRegister<Register>();
3836 Register second = locations->InAt(1).AsRegister<Register>();
3837 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003838 if (instruction->IsAnd()) {
3839 __ and_(out, first, ShifterOperand(second));
3840 } else if (instruction->IsOr()) {
3841 __ orr(out, first, ShifterOperand(second));
3842 } else {
3843 DCHECK(instruction->IsXor());
3844 __ eor(out, first, ShifterOperand(second));
3845 }
3846 } else {
3847 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3848 Location first = locations->InAt(0);
3849 Location second = locations->InAt(1);
3850 Location out = locations->Out();
3851 if (instruction->IsAnd()) {
3852 __ and_(out.AsRegisterPairLow<Register>(),
3853 first.AsRegisterPairLow<Register>(),
3854 ShifterOperand(second.AsRegisterPairLow<Register>()));
3855 __ and_(out.AsRegisterPairHigh<Register>(),
3856 first.AsRegisterPairHigh<Register>(),
3857 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3858 } else if (instruction->IsOr()) {
3859 __ orr(out.AsRegisterPairLow<Register>(),
3860 first.AsRegisterPairLow<Register>(),
3861 ShifterOperand(second.AsRegisterPairLow<Register>()));
3862 __ orr(out.AsRegisterPairHigh<Register>(),
3863 first.AsRegisterPairHigh<Register>(),
3864 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3865 } else {
3866 DCHECK(instruction->IsXor());
3867 __ eor(out.AsRegisterPairLow<Register>(),
3868 first.AsRegisterPairLow<Register>(),
3869 ShifterOperand(second.AsRegisterPairLow<Register>()));
3870 __ eor(out.AsRegisterPairHigh<Register>(),
3871 first.AsRegisterPairHigh<Register>(),
3872 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3873 }
3874 }
3875}
3876
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08003877void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
3878 DCHECK_EQ(temp, kArtMethodRegister);
3879
3880 // TODO: Implement all kinds of calls:
3881 // 1) boot -> boot
3882 // 2) app -> boot
3883 // 3) app -> app
3884 //
3885 // Currently we implement the app -> app logic, which looks up in the resolve cache.
3886
3887 // temp = method;
3888 LoadCurrentMethod(temp);
3889 if (!invoke->IsRecursive()) {
3890 // temp = temp->dex_cache_resolved_methods_;
3891 __ LoadFromOffset(
3892 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
3893 // temp = temp[index_in_cache]
3894 __ LoadFromOffset(
3895 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
3896 // LR = temp[offset_of_quick_compiled_code]
3897 __ LoadFromOffset(kLoadWord, LR, temp,
3898 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
3899 kArmWordSize).Int32Value());
3900 // LR()
3901 __ blx(LR);
3902 } else {
3903 __ bl(GetFrameEntryLabel());
3904 }
3905
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08003906 DCHECK(!IsLeafMethod());
3907}
3908
Calin Juravleb1498f62015-02-16 13:13:29 +00003909void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
3910 // Nothing to do, this should be removed during prepare for register allocator.
3911 UNUSED(instruction);
3912 LOG(FATAL) << "Unreachable";
3913}
3914
3915void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
3916 // Nothing to do, this should be removed during prepare for register allocator.
3917 UNUSED(instruction);
3918 LOG(FATAL) << "Unreachable";
3919}
3920
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003921} // namespace arm
3922} // namespace art