blob: 1f95041a92f8d57ac5d96be07427e13d51a7bfc5 [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) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002090 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2091 if (div->GetResultType() == Primitive::kPrimLong) {
2092 // pLdiv runtime call.
2093 call_kind = LocationSummary::kCall;
2094 } else if (div->GetResultType() == Primitive::kPrimInt &&
2095 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2096 // pIdivmod runtime call.
2097 call_kind = LocationSummary::kCall;
2098 }
2099
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002100 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2101
Calin Juravle7c4954d2014-10-28 16:57:40 +00002102 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002103 case Primitive::kPrimInt: {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002104 if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2105 locations->SetInAt(0, Location::RequiresRegister());
2106 locations->SetInAt(1, Location::RequiresRegister());
2107 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2108 } else {
2109 InvokeRuntimeCallingConvention calling_convention;
2110 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2111 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2112 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2113 // we only need the former.
2114 locations->SetOut(Location::RegisterLocation(R0));
2115 }
Calin Juravled0d48522014-11-04 16:40:20 +00002116 break;
2117 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002118 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002119 InvokeRuntimeCallingConvention calling_convention;
2120 locations->SetInAt(0, Location::RegisterPairLocation(
2121 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2122 locations->SetInAt(1, Location::RegisterPairLocation(
2123 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002124 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002125 break;
2126 }
2127 case Primitive::kPrimFloat:
2128 case Primitive::kPrimDouble: {
2129 locations->SetInAt(0, Location::RequiresFpuRegister());
2130 locations->SetInAt(1, Location::RequiresFpuRegister());
2131 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2132 break;
2133 }
2134
2135 default:
2136 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2137 }
2138}
2139
2140void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2141 LocationSummary* locations = div->GetLocations();
2142 Location out = locations->Out();
2143 Location first = locations->InAt(0);
2144 Location second = locations->InAt(1);
2145
2146 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002147 case Primitive::kPrimInt: {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002148 if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2149 __ sdiv(out.AsRegister<Register>(),
2150 first.AsRegister<Register>(),
2151 second.AsRegister<Register>());
2152 } else {
2153 InvokeRuntimeCallingConvention calling_convention;
2154 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2155 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2156 DCHECK_EQ(R0, out.AsRegister<Register>());
2157
2158 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2159 }
Calin Juravled0d48522014-11-04 16:40:20 +00002160 break;
2161 }
2162
Calin Juravle7c4954d2014-10-28 16:57:40 +00002163 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002164 InvokeRuntimeCallingConvention calling_convention;
2165 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2166 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2167 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2168 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2169 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002170 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002171
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002172 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002173 break;
2174 }
2175
2176 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002177 __ vdivs(out.AsFpuRegister<SRegister>(),
2178 first.AsFpuRegister<SRegister>(),
2179 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002180 break;
2181 }
2182
2183 case Primitive::kPrimDouble: {
2184 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2185 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2186 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2187 break;
2188 }
2189
2190 default:
2191 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2192 }
2193}
2194
Calin Juravlebacfec32014-11-14 15:54:36 +00002195void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002196 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002197
2198 // Most remainders are implemented in the runtime.
2199 LocationSummary::CallKind call_kind = LocationSummary::kCall;
2200 if (rem->GetResultType() == Primitive::kPrimInt &&
2201 codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2202 // Have hardware divide instruction for int, do it with three instructions.
2203 call_kind = LocationSummary::kNoCall;
2204 }
2205
Calin Juravlebacfec32014-11-14 15:54:36 +00002206 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2207
Calin Juravled2ec87d2014-12-08 14:24:46 +00002208 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002209 case Primitive::kPrimInt: {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002210 if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2211 locations->SetInAt(0, Location::RequiresRegister());
2212 locations->SetInAt(1, Location::RequiresRegister());
2213 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2214 locations->AddTemp(Location::RequiresRegister());
2215 } else {
2216 InvokeRuntimeCallingConvention calling_convention;
2217 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2218 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2219 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2220 // we only need the latter.
2221 locations->SetOut(Location::RegisterLocation(R1));
2222 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002223 break;
2224 }
2225 case Primitive::kPrimLong: {
2226 InvokeRuntimeCallingConvention calling_convention;
2227 locations->SetInAt(0, Location::RegisterPairLocation(
2228 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2229 locations->SetInAt(1, Location::RegisterPairLocation(
2230 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2231 // The runtime helper puts the output in R2,R3.
2232 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2233 break;
2234 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002235 case Primitive::kPrimFloat: {
2236 InvokeRuntimeCallingConvention calling_convention;
2237 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2238 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2239 locations->SetOut(Location::FpuRegisterLocation(S0));
2240 break;
2241 }
2242
Calin Juravlebacfec32014-11-14 15:54:36 +00002243 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002244 InvokeRuntimeCallingConvention calling_convention;
2245 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2246 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2247 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2248 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2249 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002250 break;
2251 }
2252
2253 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002254 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002255 }
2256}
2257
2258void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2259 LocationSummary* locations = rem->GetLocations();
2260 Location out = locations->Out();
2261 Location first = locations->InAt(0);
2262 Location second = locations->InAt(1);
2263
Calin Juravled2ec87d2014-12-08 14:24:46 +00002264 Primitive::Type type = rem->GetResultType();
2265 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002266 case Primitive::kPrimInt: {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002267 if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2268 Register reg1 = first.AsRegister<Register>();
2269 Register reg2 = second.AsRegister<Register>();
2270 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002271
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002272 // temp = reg1 / reg2 (integer division)
2273 // temp = temp * reg2
2274 // dest = reg1 - temp
2275 __ sdiv(temp, reg1, reg2);
2276 __ mul(temp, temp, reg2);
2277 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2278 } else {
2279 InvokeRuntimeCallingConvention calling_convention;
2280 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2281 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2282 DCHECK_EQ(R1, out.AsRegister<Register>());
2283
2284 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2285 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002286 break;
2287 }
2288
2289 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002290 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002291 break;
2292 }
2293
Calin Juravled2ec87d2014-12-08 14:24:46 +00002294 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002295 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002296 break;
2297 }
2298
Calin Juravlebacfec32014-11-14 15:54:36 +00002299 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002300 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002301 break;
2302 }
2303
2304 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002305 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002306 }
2307}
2308
Calin Juravled0d48522014-11-04 16:40:20 +00002309void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2310 LocationSummary* locations =
2311 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002312 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002313 if (instruction->HasUses()) {
2314 locations->SetOut(Location::SameAsFirstInput());
2315 }
2316}
2317
2318void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2319 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2320 codegen_->AddSlowPath(slow_path);
2321
2322 LocationSummary* locations = instruction->GetLocations();
2323 Location value = locations->InAt(0);
2324
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002325 switch (instruction->GetType()) {
2326 case Primitive::kPrimInt: {
2327 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002328 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002329 __ b(slow_path->GetEntryLabel(), EQ);
2330 } else {
2331 DCHECK(value.IsConstant()) << value;
2332 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2333 __ b(slow_path->GetEntryLabel());
2334 }
2335 }
2336 break;
2337 }
2338 case Primitive::kPrimLong: {
2339 if (value.IsRegisterPair()) {
2340 __ orrs(IP,
2341 value.AsRegisterPairLow<Register>(),
2342 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2343 __ b(slow_path->GetEntryLabel(), EQ);
2344 } else {
2345 DCHECK(value.IsConstant()) << value;
2346 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2347 __ b(slow_path->GetEntryLabel());
2348 }
2349 }
2350 break;
2351 default:
2352 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2353 }
2354 }
Calin Juravled0d48522014-11-04 16:40:20 +00002355}
2356
Calin Juravle9aec02f2014-11-18 23:06:35 +00002357void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2358 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2359
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002360 LocationSummary* locations =
2361 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002362
2363 switch (op->GetResultType()) {
2364 case Primitive::kPrimInt: {
2365 locations->SetInAt(0, Location::RequiresRegister());
2366 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002367 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002368 break;
2369 }
2370 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002371 locations->SetInAt(0, Location::RequiresRegister());
2372 locations->SetInAt(1, Location::RequiresRegister());
2373 locations->AddTemp(Location::RequiresRegister());
2374 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002375 break;
2376 }
2377 default:
2378 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2379 }
2380}
2381
2382void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2383 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2384
2385 LocationSummary* locations = op->GetLocations();
2386 Location out = locations->Out();
2387 Location first = locations->InAt(0);
2388 Location second = locations->InAt(1);
2389
2390 Primitive::Type type = op->GetResultType();
2391 switch (type) {
2392 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002393 Register out_reg = out.AsRegister<Register>();
2394 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002395 // Arm doesn't mask the shift count so we need to do it ourselves.
2396 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002397 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002398 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2399 if (op->IsShl()) {
2400 __ Lsl(out_reg, first_reg, second_reg);
2401 } else if (op->IsShr()) {
2402 __ Asr(out_reg, first_reg, second_reg);
2403 } else {
2404 __ Lsr(out_reg, first_reg, second_reg);
2405 }
2406 } else {
2407 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2408 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2409 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2410 __ Mov(out_reg, first_reg);
2411 } else if (op->IsShl()) {
2412 __ Lsl(out_reg, first_reg, shift_value);
2413 } else if (op->IsShr()) {
2414 __ Asr(out_reg, first_reg, shift_value);
2415 } else {
2416 __ Lsr(out_reg, first_reg, shift_value);
2417 }
2418 }
2419 break;
2420 }
2421 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002422 Register o_h = out.AsRegisterPairHigh<Register>();
2423 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002424
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002425 Register temp = locations->GetTemp(0).AsRegister<Register>();
2426
2427 Register high = first.AsRegisterPairHigh<Register>();
2428 Register low = first.AsRegisterPairLow<Register>();
2429
2430 Register second_reg = second.AsRegister<Register>();
2431
Calin Juravle9aec02f2014-11-18 23:06:35 +00002432 if (op->IsShl()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002433 // Shift the high part
2434 __ and_(second_reg, second_reg, ShifterOperand(63));
2435 __ Lsl(o_h, high, second_reg);
2436 // Shift the low part and `or` what overflew on the high part
2437 __ rsb(temp, second_reg, ShifterOperand(32));
2438 __ Lsr(temp, low, temp);
2439 __ orr(o_h, o_h, ShifterOperand(temp));
2440 // If the shift is > 32 bits, override the high part
2441 __ subs(temp, second_reg, ShifterOperand(32));
2442 __ it(PL);
2443 __ Lsl(o_h, low, temp, false, PL);
2444 // Shift the low part
2445 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002446 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002447 // Shift the low part
2448 __ and_(second_reg, second_reg, ShifterOperand(63));
2449 __ Lsr(o_l, low, second_reg);
2450 // Shift the high part and `or` what underflew on the low part
2451 __ rsb(temp, second_reg, ShifterOperand(32));
2452 __ Lsl(temp, high, temp);
2453 __ orr(o_l, o_l, ShifterOperand(temp));
2454 // If the shift is > 32 bits, override the low part
2455 __ subs(temp, second_reg, ShifterOperand(32));
2456 __ it(PL);
2457 __ Asr(o_l, high, temp, false, PL);
2458 // Shift the high part
2459 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002460 } else {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002461 // same as Shr except we use `Lsr`s and not `Asr`s
2462 __ and_(second_reg, second_reg, ShifterOperand(63));
2463 __ Lsr(o_l, low, second_reg);
2464 __ rsb(temp, second_reg, ShifterOperand(32));
2465 __ Lsl(temp, high, temp);
2466 __ orr(o_l, o_l, ShifterOperand(temp));
2467 __ subs(temp, second_reg, ShifterOperand(32));
2468 __ it(PL);
2469 __ Lsr(o_l, high, temp, false, PL);
2470 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002471 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002472 break;
2473 }
2474 default:
2475 LOG(FATAL) << "Unexpected operation type " << type;
2476 }
2477}
2478
2479void LocationsBuilderARM::VisitShl(HShl* shl) {
2480 HandleShift(shl);
2481}
2482
2483void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2484 HandleShift(shl);
2485}
2486
2487void LocationsBuilderARM::VisitShr(HShr* shr) {
2488 HandleShift(shr);
2489}
2490
2491void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2492 HandleShift(shr);
2493}
2494
2495void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2496 HandleShift(ushr);
2497}
2498
2499void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2500 HandleShift(ushr);
2501}
2502
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002503void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002504 LocationSummary* locations =
2505 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002506 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002507 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2508 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2509 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002510}
2511
2512void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2513 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002514 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002515 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002516 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2517 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002518 instruction->GetDexPc(),
2519 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002520}
2521
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002522void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2523 LocationSummary* locations =
2524 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2525 InvokeRuntimeCallingConvention calling_convention;
2526 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002527 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002528 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002529 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002530}
2531
2532void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2533 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002534 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002535 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002536 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2537 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002538 instruction->GetDexPc(),
2539 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002540}
2541
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002542void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002543 LocationSummary* locations =
2544 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002545 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2546 if (location.IsStackSlot()) {
2547 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2548 } else if (location.IsDoubleStackSlot()) {
2549 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002550 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002551 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002552}
2553
2554void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002555 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002556 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002557}
2558
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002559void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002560 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002561 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002562 locations->SetInAt(0, Location::RequiresRegister());
2563 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002564}
2565
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002566void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2567 LocationSummary* locations = not_->GetLocations();
2568 Location out = locations->Out();
2569 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002570 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002571 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002572 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002573 break;
2574
2575 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002576 __ mvn(out.AsRegisterPairLow<Register>(),
2577 ShifterOperand(in.AsRegisterPairLow<Register>()));
2578 __ mvn(out.AsRegisterPairHigh<Register>(),
2579 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002580 break;
2581
2582 default:
2583 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2584 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002585}
2586
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002587void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002588 LocationSummary* locations =
2589 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002590 switch (compare->InputAt(0)->GetType()) {
2591 case Primitive::kPrimLong: {
2592 locations->SetInAt(0, Location::RequiresRegister());
2593 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002594 // Output overlaps because it is written before doing the low comparison.
2595 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002596 break;
2597 }
2598 case Primitive::kPrimFloat:
2599 case Primitive::kPrimDouble: {
2600 locations->SetInAt(0, Location::RequiresFpuRegister());
2601 locations->SetInAt(1, Location::RequiresFpuRegister());
2602 locations->SetOut(Location::RequiresRegister());
2603 break;
2604 }
2605 default:
2606 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2607 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002608}
2609
2610void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002611 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002612 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002613 Location left = locations->InAt(0);
2614 Location right = locations->InAt(1);
2615
2616 Label less, greater, done;
2617 Primitive::Type type = compare->InputAt(0)->GetType();
2618 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002619 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002620 __ cmp(left.AsRegisterPairHigh<Register>(),
2621 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002622 __ b(&less, LT);
2623 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002624 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2625 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002626 __ cmp(left.AsRegisterPairLow<Register>(),
2627 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002628 break;
2629 }
2630 case Primitive::kPrimFloat:
2631 case Primitive::kPrimDouble: {
2632 __ LoadImmediate(out, 0);
2633 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002634 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002635 } else {
2636 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2637 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2638 }
2639 __ vmstat(); // transfer FP status register to ARM APSR.
2640 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002641 break;
2642 }
2643 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002644 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002645 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002646 __ b(&done, EQ);
2647 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2648
2649 __ Bind(&greater);
2650 __ LoadImmediate(out, 1);
2651 __ b(&done);
2652
2653 __ Bind(&less);
2654 __ LoadImmediate(out, -1);
2655
2656 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002657}
2658
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002659void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002660 LocationSummary* locations =
2661 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002662 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2663 locations->SetInAt(i, Location::Any());
2664 }
2665 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002666}
2667
2668void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002669 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002670 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002671}
2672
Calin Juravle52c48962014-12-16 17:02:57 +00002673void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2674 // TODO (ported from quick): revisit Arm barrier kinds
2675 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2676 switch (kind) {
2677 case MemBarrierKind::kAnyStore:
2678 case MemBarrierKind::kLoadAny:
2679 case MemBarrierKind::kAnyAny: {
2680 flavour = DmbOptions::ISH;
2681 break;
2682 }
2683 case MemBarrierKind::kStoreStore: {
2684 flavour = DmbOptions::ISHST;
2685 break;
2686 }
2687 default:
2688 LOG(FATAL) << "Unexpected memory barrier " << kind;
2689 }
2690 __ dmb(flavour);
2691}
2692
2693void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2694 uint32_t offset,
2695 Register out_lo,
2696 Register out_hi) {
2697 if (offset != 0) {
2698 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002699 __ add(IP, addr, ShifterOperand(out_lo));
2700 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002701 }
2702 __ ldrexd(out_lo, out_hi, addr);
2703}
2704
2705void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2706 uint32_t offset,
2707 Register value_lo,
2708 Register value_hi,
2709 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002710 Register temp2,
2711 HInstruction* instruction) {
Calin Juravle52c48962014-12-16 17:02:57 +00002712 Label fail;
2713 if (offset != 0) {
2714 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002715 __ add(IP, addr, ShifterOperand(temp1));
2716 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002717 }
2718 __ Bind(&fail);
2719 // We need a load followed by store. (The address used in a STREX instruction must
2720 // be the same as the address in the most recently executed LDREX instruction.)
2721 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002722 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002723 __ strexd(temp1, value_lo, value_hi, addr);
2724 __ cmp(temp1, ShifterOperand(0));
2725 __ b(&fail, NE);
2726}
2727
2728void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2729 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2730
Nicolas Geoffray39468442014-09-02 15:17:15 +01002731 LocationSummary* locations =
2732 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002733 locations->SetInAt(0, Location::RequiresRegister());
2734 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002735
Calin Juravle34166012014-12-19 17:22:29 +00002736
Calin Juravle52c48962014-12-16 17:02:57 +00002737 Primitive::Type field_type = field_info.GetFieldType();
2738 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002739 bool generate_volatile = field_info.IsVolatile()
2740 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002741 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002742 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002743 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2744 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002745 locations->AddTemp(Location::RequiresRegister());
2746 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002747 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002748 // Arm encoding have some additional constraints for ldrexd/strexd:
2749 // - registers need to be consecutive
2750 // - the first register should be even but not R14.
2751 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2752 // enable Arm encoding.
2753 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2754
2755 locations->AddTemp(Location::RequiresRegister());
2756 locations->AddTemp(Location::RequiresRegister());
2757 if (field_type == Primitive::kPrimDouble) {
2758 // For doubles we need two more registers to copy the value.
2759 locations->AddTemp(Location::RegisterLocation(R2));
2760 locations->AddTemp(Location::RegisterLocation(R3));
2761 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002762 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002763}
2764
Calin Juravle52c48962014-12-16 17:02:57 +00002765void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2766 const FieldInfo& field_info) {
2767 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2768
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002769 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002770 Register base = locations->InAt(0).AsRegister<Register>();
2771 Location value = locations->InAt(1);
2772
2773 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002774 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002775 Primitive::Type field_type = field_info.GetFieldType();
2776 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2777
2778 if (is_volatile) {
2779 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2780 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002781
2782 switch (field_type) {
2783 case Primitive::kPrimBoolean:
2784 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002785 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002786 break;
2787 }
2788
2789 case Primitive::kPrimShort:
2790 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002791 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002792 break;
2793 }
2794
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002795 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002796 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00002797 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002798 break;
2799 }
2800
2801 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002802 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002803 GenerateWideAtomicStore(base, offset,
2804 value.AsRegisterPairLow<Register>(),
2805 value.AsRegisterPairHigh<Register>(),
2806 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002807 locations->GetTemp(1).AsRegister<Register>(),
2808 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002809 } else {
2810 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002811 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002812 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002813 break;
2814 }
2815
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002816 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002817 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002818 break;
2819 }
2820
2821 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002822 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002823 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002824 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2825 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2826
2827 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2828
2829 GenerateWideAtomicStore(base, offset,
2830 value_reg_lo,
2831 value_reg_hi,
2832 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002833 locations->GetTemp(3).AsRegister<Register>(),
2834 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002835 } else {
2836 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002837 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002838 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002839 break;
2840 }
2841
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002842 case Primitive::kPrimVoid:
2843 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002844 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002845 }
Calin Juravle52c48962014-12-16 17:02:57 +00002846
Calin Juravle77520bc2015-01-12 18:45:46 +00002847 // Longs and doubles are handled in the switch.
2848 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
2849 codegen_->MaybeRecordImplicitNullCheck(instruction);
2850 }
2851
2852 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
2853 Register temp = locations->GetTemp(0).AsRegister<Register>();
2854 Register card = locations->GetTemp(1).AsRegister<Register>();
2855 codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>());
2856 }
2857
Calin Juravle52c48962014-12-16 17:02:57 +00002858 if (is_volatile) {
2859 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2860 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002861}
2862
Calin Juravle52c48962014-12-16 17:02:57 +00002863void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2864 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002865 LocationSummary* locations =
2866 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002867 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002868
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002869 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00002870 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002871 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002872 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
2873 locations->SetOut(Location::RequiresRegister(),
2874 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
2875 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00002876 // Arm encoding have some additional constraints for ldrexd/strexd:
2877 // - registers need to be consecutive
2878 // - the first register should be even but not R14.
2879 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2880 // enable Arm encoding.
2881 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2882 locations->AddTemp(Location::RequiresRegister());
2883 locations->AddTemp(Location::RequiresRegister());
2884 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002885}
2886
Calin Juravle52c48962014-12-16 17:02:57 +00002887void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2888 const FieldInfo& field_info) {
2889 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002890
Calin Juravle52c48962014-12-16 17:02:57 +00002891 LocationSummary* locations = instruction->GetLocations();
2892 Register base = locations->InAt(0).AsRegister<Register>();
2893 Location out = locations->Out();
2894 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002895 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002896 Primitive::Type field_type = field_info.GetFieldType();
2897 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2898
2899 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002900 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002901 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002902 break;
2903 }
2904
2905 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002906 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002907 break;
2908 }
2909
2910 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002911 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002912 break;
2913 }
2914
2915 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002916 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002917 break;
2918 }
2919
2920 case Primitive::kPrimInt:
2921 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002922 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002923 break;
2924 }
2925
2926 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002927 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002928 GenerateWideAtomicLoad(base, offset,
2929 out.AsRegisterPairLow<Register>(),
2930 out.AsRegisterPairHigh<Register>());
2931 } else {
2932 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2933 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002934 break;
2935 }
2936
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002937 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002938 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002939 break;
2940 }
2941
2942 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002943 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002944 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002945 Register lo = locations->GetTemp(0).AsRegister<Register>();
2946 Register hi = locations->GetTemp(1).AsRegister<Register>();
2947 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00002948 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002949 __ vmovdrr(out_reg, lo, hi);
2950 } else {
2951 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002952 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002953 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002954 break;
2955 }
2956
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002957 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002958 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002959 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002960 }
Calin Juravle52c48962014-12-16 17:02:57 +00002961
Calin Juravle77520bc2015-01-12 18:45:46 +00002962 // Doubles are handled in the switch.
2963 if (field_type != Primitive::kPrimDouble) {
2964 codegen_->MaybeRecordImplicitNullCheck(instruction);
2965 }
2966
Calin Juravle52c48962014-12-16 17:02:57 +00002967 if (is_volatile) {
2968 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2969 }
2970}
2971
2972void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2973 HandleFieldSet(instruction, instruction->GetFieldInfo());
2974}
2975
2976void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2977 HandleFieldSet(instruction, instruction->GetFieldInfo());
2978}
2979
2980void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2981 HandleFieldGet(instruction, instruction->GetFieldInfo());
2982}
2983
2984void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2985 HandleFieldGet(instruction, instruction->GetFieldInfo());
2986}
2987
2988void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2989 HandleFieldGet(instruction, instruction->GetFieldInfo());
2990}
2991
2992void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2993 HandleFieldGet(instruction, instruction->GetFieldInfo());
2994}
2995
2996void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2997 HandleFieldSet(instruction, instruction->GetFieldInfo());
2998}
2999
3000void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3001 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003002}
3003
3004void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003005 LocationSummary* locations =
3006 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003007 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003008 if (instruction->HasUses()) {
3009 locations->SetOut(Location::SameAsFirstInput());
3010 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003011}
3012
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003013void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003014 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3015 return;
3016 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003017 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003018
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003019 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3020 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3021}
3022
3023void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003024 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003025 codegen_->AddSlowPath(slow_path);
3026
3027 LocationSummary* locations = instruction->GetLocations();
3028 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003029
Calin Juravle77520bc2015-01-12 18:45:46 +00003030 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
3031 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003032}
3033
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003034void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3035 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3036 GenerateImplicitNullCheck(instruction);
3037 } else {
3038 GenerateExplicitNullCheck(instruction);
3039 }
3040}
3041
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003042void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003043 LocationSummary* locations =
3044 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003045 locations->SetInAt(0, Location::RequiresRegister());
3046 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3047 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003048}
3049
3050void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3051 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003052 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003053 Location index = locations->InAt(1);
3054
3055 switch (instruction->GetType()) {
3056 case Primitive::kPrimBoolean: {
3057 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003058 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003059 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003060 size_t offset =
3061 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003062 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3063 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003064 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003065 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3066 }
3067 break;
3068 }
3069
3070 case Primitive::kPrimByte: {
3071 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003072 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003073 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003074 size_t offset =
3075 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003076 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3077 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003078 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003079 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3080 }
3081 break;
3082 }
3083
3084 case Primitive::kPrimShort: {
3085 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003086 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003087 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003088 size_t offset =
3089 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003090 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3091 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003092 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003093 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3094 }
3095 break;
3096 }
3097
3098 case Primitive::kPrimChar: {
3099 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003100 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003101 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003102 size_t offset =
3103 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003104 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3105 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003106 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003107 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3108 }
3109 break;
3110 }
3111
3112 case Primitive::kPrimInt:
3113 case Primitive::kPrimNot: {
3114 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3115 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003116 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003117 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003118 size_t offset =
3119 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003120 __ LoadFromOffset(kLoadWord, out, obj, offset);
3121 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003122 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003123 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3124 }
3125 break;
3126 }
3127
3128 case Primitive::kPrimLong: {
3129 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003130 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003131 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003132 size_t offset =
3133 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003134 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003135 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003136 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003137 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003138 }
3139 break;
3140 }
3141
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003142 case Primitive::kPrimFloat: {
3143 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3144 Location out = locations->Out();
3145 DCHECK(out.IsFpuRegister());
3146 if (index.IsConstant()) {
3147 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3148 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3149 } else {
3150 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3151 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3152 }
3153 break;
3154 }
3155
3156 case Primitive::kPrimDouble: {
3157 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3158 Location out = locations->Out();
3159 DCHECK(out.IsFpuRegisterPair());
3160 if (index.IsConstant()) {
3161 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3162 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3163 } else {
3164 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3165 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3166 }
3167 break;
3168 }
3169
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003170 case Primitive::kPrimVoid:
3171 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003172 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003173 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003174 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003175}
3176
3177void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003178 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003179
3180 bool needs_write_barrier =
3181 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3182 bool needs_runtime_call = instruction->NeedsTypeCheck();
3183
Nicolas Geoffray39468442014-09-02 15:17:15 +01003184 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003185 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3186 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003187 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003188 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3189 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3190 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003191 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003192 locations->SetInAt(0, Location::RequiresRegister());
3193 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3194 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003195
3196 if (needs_write_barrier) {
3197 // Temporary registers for the write barrier.
3198 locations->AddTemp(Location::RequiresRegister());
3199 locations->AddTemp(Location::RequiresRegister());
3200 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003201 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003202}
3203
3204void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3205 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003206 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003207 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003208 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003209 bool needs_runtime_call = locations->WillCall();
3210 bool needs_write_barrier =
3211 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003212
3213 switch (value_type) {
3214 case Primitive::kPrimBoolean:
3215 case Primitive::kPrimByte: {
3216 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003217 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003218 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003219 size_t offset =
3220 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003221 __ StoreToOffset(kStoreByte, value, obj, offset);
3222 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003223 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003224 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3225 }
3226 break;
3227 }
3228
3229 case Primitive::kPrimShort:
3230 case Primitive::kPrimChar: {
3231 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003232 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003233 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003234 size_t offset =
3235 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003236 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3237 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003238 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003239 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3240 }
3241 break;
3242 }
3243
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003244 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003245 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003246 if (!needs_runtime_call) {
3247 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003248 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003249 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003250 size_t offset =
3251 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003252 __ StoreToOffset(kStoreWord, value, obj, offset);
3253 } else {
3254 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003255 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003256 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3257 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003258 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003259 if (needs_write_barrier) {
3260 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003261 Register temp = locations->GetTemp(0).AsRegister<Register>();
3262 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003263 codegen_->MarkGCCard(temp, card, obj, value);
3264 }
3265 } else {
3266 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003267 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3268 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003269 instruction->GetDexPc(),
3270 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003271 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003272 break;
3273 }
3274
3275 case Primitive::kPrimLong: {
3276 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003277 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003278 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003279 size_t offset =
3280 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003281 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003282 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003283 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003284 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003285 }
3286 break;
3287 }
3288
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003289 case Primitive::kPrimFloat: {
3290 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3291 Location value = locations->InAt(2);
3292 DCHECK(value.IsFpuRegister());
3293 if (index.IsConstant()) {
3294 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3295 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3296 } else {
3297 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3298 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3299 }
3300 break;
3301 }
3302
3303 case Primitive::kPrimDouble: {
3304 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3305 Location value = locations->InAt(2);
3306 DCHECK(value.IsFpuRegisterPair());
3307 if (index.IsConstant()) {
3308 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3309 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3310 } else {
3311 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3312 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3313 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003314
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003315 break;
3316 }
3317
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003318 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003319 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003320 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003321 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003322
3323 // Ints and objects are handled in the switch.
3324 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3325 codegen_->MaybeRecordImplicitNullCheck(instruction);
3326 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003327}
3328
3329void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003330 LocationSummary* locations =
3331 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003332 locations->SetInAt(0, Location::RequiresRegister());
3333 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003334}
3335
3336void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3337 LocationSummary* locations = instruction->GetLocations();
3338 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003339 Register obj = locations->InAt(0).AsRegister<Register>();
3340 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003341 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003342 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003343}
3344
3345void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003346 LocationSummary* locations =
3347 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003348 locations->SetInAt(0, Location::RequiresRegister());
3349 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003350 if (instruction->HasUses()) {
3351 locations->SetOut(Location::SameAsFirstInput());
3352 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003353}
3354
3355void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3356 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003357 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003358 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003359 codegen_->AddSlowPath(slow_path);
3360
Roland Levillain271ab9c2014-11-27 15:23:57 +00003361 Register index = locations->InAt(0).AsRegister<Register>();
3362 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003363
3364 __ cmp(index, ShifterOperand(length));
3365 __ b(slow_path->GetEntryLabel(), CS);
3366}
3367
3368void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3369 Label is_null;
3370 __ CompareAndBranchIfZero(value, &is_null);
3371 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3372 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3373 __ strb(card, Address(card, temp));
3374 __ Bind(&is_null);
3375}
3376
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003377void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3378 temp->SetLocations(nullptr);
3379}
3380
3381void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3382 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003383 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003384}
3385
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003386void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003387 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003388 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003389}
3390
3391void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003392 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3393}
3394
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003395void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3396 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3397}
3398
3399void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003400 HBasicBlock* block = instruction->GetBlock();
3401 if (block->GetLoopInformation() != nullptr) {
3402 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3403 // The back edge will generate the suspend check.
3404 return;
3405 }
3406 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3407 // The goto will generate the suspend check.
3408 return;
3409 }
3410 GenerateSuspendCheck(instruction, nullptr);
3411}
3412
3413void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3414 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003415 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003416 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003417 codegen_->AddSlowPath(slow_path);
3418
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003419 __ LoadFromOffset(
3420 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3421 __ cmp(IP, ShifterOperand(0));
3422 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003423 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003424 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003425 __ Bind(slow_path->GetReturnLabel());
3426 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003427 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003428 __ b(slow_path->GetEntryLabel());
3429 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003430}
3431
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003432ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3433 return codegen_->GetAssembler();
3434}
3435
3436void ParallelMoveResolverARM::EmitMove(size_t index) {
3437 MoveOperands* move = moves_.Get(index);
3438 Location source = move->GetSource();
3439 Location destination = move->GetDestination();
3440
3441 if (source.IsRegister()) {
3442 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003443 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003444 } else {
3445 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003446 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003447 SP, destination.GetStackIndex());
3448 }
3449 } else if (source.IsStackSlot()) {
3450 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003451 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003452 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003453 } else if (destination.IsFpuRegister()) {
3454 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003455 } else {
3456 DCHECK(destination.IsStackSlot());
3457 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3458 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3459 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003460 } else if (source.IsFpuRegister()) {
3461 if (destination.IsFpuRegister()) {
3462 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003463 } else {
3464 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003465 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3466 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003467 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003468 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003469 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3470 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003471 } else if (destination.IsRegisterPair()) {
3472 DCHECK(ExpectedPairLayout(destination));
3473 __ LoadFromOffset(
3474 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3475 } else {
3476 DCHECK(destination.IsFpuRegisterPair()) << destination;
3477 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3478 SP,
3479 source.GetStackIndex());
3480 }
3481 } else if (source.IsRegisterPair()) {
3482 if (destination.IsRegisterPair()) {
3483 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3484 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3485 } else {
3486 DCHECK(destination.IsDoubleStackSlot()) << destination;
3487 DCHECK(ExpectedPairLayout(source));
3488 __ StoreToOffset(
3489 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3490 }
3491 } else if (source.IsFpuRegisterPair()) {
3492 if (destination.IsFpuRegisterPair()) {
3493 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3494 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3495 } else {
3496 DCHECK(destination.IsDoubleStackSlot()) << destination;
3497 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3498 SP,
3499 destination.GetStackIndex());
3500 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003501 } else {
3502 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003503 HConstant* constant = source.GetConstant();
3504 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3505 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003506 if (destination.IsRegister()) {
3507 __ LoadImmediate(destination.AsRegister<Register>(), value);
3508 } else {
3509 DCHECK(destination.IsStackSlot());
3510 __ LoadImmediate(IP, value);
3511 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3512 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003513 } else if (constant->IsLongConstant()) {
3514 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003515 if (destination.IsRegisterPair()) {
3516 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3517 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003518 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003519 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003520 __ LoadImmediate(IP, Low32Bits(value));
3521 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3522 __ LoadImmediate(IP, High32Bits(value));
3523 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3524 }
3525 } else if (constant->IsDoubleConstant()) {
3526 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003527 if (destination.IsFpuRegisterPair()) {
3528 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003529 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003530 DCHECK(destination.IsDoubleStackSlot()) << destination;
3531 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003532 __ LoadImmediate(IP, Low32Bits(int_value));
3533 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3534 __ LoadImmediate(IP, High32Bits(int_value));
3535 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3536 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003537 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003538 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003539 float value = constant->AsFloatConstant()->GetValue();
3540 if (destination.IsFpuRegister()) {
3541 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3542 } else {
3543 DCHECK(destination.IsStackSlot());
3544 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3545 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3546 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003547 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003548 }
3549}
3550
3551void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3552 __ Mov(IP, reg);
3553 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3554 __ StoreToOffset(kStoreWord, IP, SP, mem);
3555}
3556
3557void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3558 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3559 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3560 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3561 SP, mem1 + stack_offset);
3562 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3563 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3564 SP, mem2 + stack_offset);
3565 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3566}
3567
3568void ParallelMoveResolverARM::EmitSwap(size_t index) {
3569 MoveOperands* move = moves_.Get(index);
3570 Location source = move->GetSource();
3571 Location destination = move->GetDestination();
3572
3573 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003574 DCHECK_NE(source.AsRegister<Register>(), IP);
3575 DCHECK_NE(destination.AsRegister<Register>(), IP);
3576 __ Mov(IP, source.AsRegister<Register>());
3577 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3578 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003579 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003580 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003581 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003582 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003583 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3584 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003585 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003586 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003587 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003588 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003589 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003590 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003591 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003592 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003593 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3594 destination.AsRegisterPairHigh<Register>(),
3595 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003596 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003597 Register low_reg = source.IsRegisterPair()
3598 ? source.AsRegisterPairLow<Register>()
3599 : destination.AsRegisterPairLow<Register>();
3600 int mem = source.IsRegisterPair()
3601 ? destination.GetStackIndex()
3602 : source.GetStackIndex();
3603 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003604 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003605 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003606 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003607 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003608 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3609 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003610 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003611 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003612 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003613 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3614 DRegister reg = source.IsFpuRegisterPair()
3615 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3616 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3617 int mem = source.IsFpuRegisterPair()
3618 ? destination.GetStackIndex()
3619 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003620 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003621 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003622 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003623 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3624 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3625 : destination.AsFpuRegister<SRegister>();
3626 int mem = source.IsFpuRegister()
3627 ? destination.GetStackIndex()
3628 : source.GetStackIndex();
3629
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003630 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003631 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003632 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003633 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003634 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3635 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003636 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003637 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003638 }
3639}
3640
3641void ParallelMoveResolverARM::SpillScratch(int reg) {
3642 __ Push(static_cast<Register>(reg));
3643}
3644
3645void ParallelMoveResolverARM::RestoreScratch(int reg) {
3646 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003647}
3648
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003649void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003650 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3651 ? LocationSummary::kCallOnSlowPath
3652 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003653 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003654 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003655 locations->SetOut(Location::RequiresRegister());
3656}
3657
3658void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003659 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003660 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003661 DCHECK(!cls->CanCallRuntime());
3662 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003663 codegen_->LoadCurrentMethod(out);
3664 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3665 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003666 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003667 codegen_->LoadCurrentMethod(out);
3668 __ LoadFromOffset(
3669 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3670 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003671
3672 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3673 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3674 codegen_->AddSlowPath(slow_path);
3675 __ cmp(out, ShifterOperand(0));
3676 __ b(slow_path->GetEntryLabel(), EQ);
3677 if (cls->MustGenerateClinitCheck()) {
3678 GenerateClassInitializationCheck(slow_path, out);
3679 } else {
3680 __ Bind(slow_path->GetExitLabel());
3681 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003682 }
3683}
3684
3685void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3686 LocationSummary* locations =
3687 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3688 locations->SetInAt(0, Location::RequiresRegister());
3689 if (check->HasUses()) {
3690 locations->SetOut(Location::SameAsFirstInput());
3691 }
3692}
3693
3694void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003695 // We assume the class is not null.
3696 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3697 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003698 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003699 GenerateClassInitializationCheck(slow_path,
3700 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003701}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003702
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003703void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3704 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003705 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3706 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3707 __ b(slow_path->GetEntryLabel(), LT);
3708 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3709 // properly. Therefore, we do a memory fence.
3710 __ dmb(ISH);
3711 __ Bind(slow_path->GetExitLabel());
3712}
3713
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003714void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3715 LocationSummary* locations =
3716 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3717 locations->SetOut(Location::RequiresRegister());
3718}
3719
3720void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3721 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3722 codegen_->AddSlowPath(slow_path);
3723
Roland Levillain271ab9c2014-11-27 15:23:57 +00003724 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003725 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003726 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3727 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003728 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3729 __ cmp(out, ShifterOperand(0));
3730 __ b(slow_path->GetEntryLabel(), EQ);
3731 __ Bind(slow_path->GetExitLabel());
3732}
3733
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003734void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3735 LocationSummary* locations =
3736 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3737 locations->SetOut(Location::RequiresRegister());
3738}
3739
3740void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003741 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003742 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3743 __ LoadFromOffset(kLoadWord, out, TR, offset);
3744 __ LoadImmediate(IP, 0);
3745 __ StoreToOffset(kStoreWord, IP, TR, offset);
3746}
3747
3748void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3749 LocationSummary* locations =
3750 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3751 InvokeRuntimeCallingConvention calling_convention;
3752 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3753}
3754
3755void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3756 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003757 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003758}
3759
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003760void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003761 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3762 ? LocationSummary::kNoCall
3763 : LocationSummary::kCallOnSlowPath;
3764 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3765 locations->SetInAt(0, Location::RequiresRegister());
3766 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003767 // The out register is used as a temporary, so it overlaps with the inputs.
3768 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003769}
3770
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003771void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003772 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003773 Register obj = locations->InAt(0).AsRegister<Register>();
3774 Register cls = locations->InAt(1).AsRegister<Register>();
3775 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003776 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3777 Label done, zero;
3778 SlowPathCodeARM* slow_path = nullptr;
3779
3780 // Return 0 if `obj` is null.
3781 // TODO: avoid this check if we know obj is not null.
3782 __ cmp(obj, ShifterOperand(0));
3783 __ b(&zero, EQ);
3784 // Compare the class of `obj` with `cls`.
3785 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3786 __ cmp(out, ShifterOperand(cls));
3787 if (instruction->IsClassFinal()) {
3788 // Classes must be equal for the instanceof to succeed.
3789 __ b(&zero, NE);
3790 __ LoadImmediate(out, 1);
3791 __ b(&done);
3792 } else {
3793 // If the classes are not equal, we go into a slow path.
3794 DCHECK(locations->OnlyCallsOnSlowPath());
3795 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003796 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003797 codegen_->AddSlowPath(slow_path);
3798 __ b(slow_path->GetEntryLabel(), NE);
3799 __ LoadImmediate(out, 1);
3800 __ b(&done);
3801 }
3802 __ Bind(&zero);
3803 __ LoadImmediate(out, 0);
3804 if (slow_path != nullptr) {
3805 __ Bind(slow_path->GetExitLabel());
3806 }
3807 __ Bind(&done);
3808}
3809
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003810void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3811 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3812 instruction, LocationSummary::kCallOnSlowPath);
3813 locations->SetInAt(0, Location::RequiresRegister());
3814 locations->SetInAt(1, Location::RequiresRegister());
3815 locations->AddTemp(Location::RequiresRegister());
3816}
3817
3818void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3819 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003820 Register obj = locations->InAt(0).AsRegister<Register>();
3821 Register cls = locations->InAt(1).AsRegister<Register>();
3822 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003823 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3824
3825 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3826 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3827 codegen_->AddSlowPath(slow_path);
3828
3829 // TODO: avoid this check if we know obj is not null.
3830 __ cmp(obj, ShifterOperand(0));
3831 __ b(slow_path->GetExitLabel(), EQ);
3832 // Compare the class of `obj` with `cls`.
3833 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3834 __ cmp(temp, ShifterOperand(cls));
3835 __ b(slow_path->GetEntryLabel(), NE);
3836 __ Bind(slow_path->GetExitLabel());
3837}
3838
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003839void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3840 LocationSummary* locations =
3841 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3842 InvokeRuntimeCallingConvention calling_convention;
3843 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3844}
3845
3846void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3847 codegen_->InvokeRuntime(instruction->IsEnter()
3848 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3849 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003850 instruction->GetDexPc(),
3851 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003852}
3853
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003854void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3855void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3856void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3857
3858void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3859 LocationSummary* locations =
3860 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3861 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3862 || instruction->GetResultType() == Primitive::kPrimLong);
3863 locations->SetInAt(0, Location::RequiresRegister());
3864 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003865 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003866}
3867
3868void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3869 HandleBitwiseOperation(instruction);
3870}
3871
3872void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3873 HandleBitwiseOperation(instruction);
3874}
3875
3876void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3877 HandleBitwiseOperation(instruction);
3878}
3879
3880void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3881 LocationSummary* locations = instruction->GetLocations();
3882
3883 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003884 Register first = locations->InAt(0).AsRegister<Register>();
3885 Register second = locations->InAt(1).AsRegister<Register>();
3886 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003887 if (instruction->IsAnd()) {
3888 __ and_(out, first, ShifterOperand(second));
3889 } else if (instruction->IsOr()) {
3890 __ orr(out, first, ShifterOperand(second));
3891 } else {
3892 DCHECK(instruction->IsXor());
3893 __ eor(out, first, ShifterOperand(second));
3894 }
3895 } else {
3896 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3897 Location first = locations->InAt(0);
3898 Location second = locations->InAt(1);
3899 Location out = locations->Out();
3900 if (instruction->IsAnd()) {
3901 __ and_(out.AsRegisterPairLow<Register>(),
3902 first.AsRegisterPairLow<Register>(),
3903 ShifterOperand(second.AsRegisterPairLow<Register>()));
3904 __ and_(out.AsRegisterPairHigh<Register>(),
3905 first.AsRegisterPairHigh<Register>(),
3906 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3907 } else if (instruction->IsOr()) {
3908 __ orr(out.AsRegisterPairLow<Register>(),
3909 first.AsRegisterPairLow<Register>(),
3910 ShifterOperand(second.AsRegisterPairLow<Register>()));
3911 __ orr(out.AsRegisterPairHigh<Register>(),
3912 first.AsRegisterPairHigh<Register>(),
3913 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3914 } else {
3915 DCHECK(instruction->IsXor());
3916 __ eor(out.AsRegisterPairLow<Register>(),
3917 first.AsRegisterPairLow<Register>(),
3918 ShifterOperand(second.AsRegisterPairLow<Register>()));
3919 __ eor(out.AsRegisterPairHigh<Register>(),
3920 first.AsRegisterPairHigh<Register>(),
3921 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3922 }
3923 }
3924}
3925
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08003926void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
3927 DCHECK_EQ(temp, kArtMethodRegister);
3928
3929 // TODO: Implement all kinds of calls:
3930 // 1) boot -> boot
3931 // 2) app -> boot
3932 // 3) app -> app
3933 //
3934 // Currently we implement the app -> app logic, which looks up in the resolve cache.
3935
3936 // temp = method;
3937 LoadCurrentMethod(temp);
3938 if (!invoke->IsRecursive()) {
3939 // temp = temp->dex_cache_resolved_methods_;
3940 __ LoadFromOffset(
3941 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
3942 // temp = temp[index_in_cache]
3943 __ LoadFromOffset(
3944 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
3945 // LR = temp[offset_of_quick_compiled_code]
3946 __ LoadFromOffset(kLoadWord, LR, temp,
3947 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
3948 kArmWordSize).Int32Value());
3949 // LR()
3950 __ blx(LR);
3951 } else {
3952 __ bl(GetFrameEntryLabel());
3953 }
3954
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08003955 DCHECK(!IsLeafMethod());
3956}
3957
Calin Juravleb1498f62015-02-16 13:13:29 +00003958void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
3959 // Nothing to do, this should be removed during prepare for register allocator.
3960 UNUSED(instruction);
3961 LOG(FATAL) << "Unreachable";
3962}
3963
3964void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
3965 // Nothing to do, this should be removed during prepare for register allocator.
3966 UNUSED(instruction);
3967 LOG(FATAL) << "Unreachable";
3968}
3969
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003970} // namespace arm
3971} // namespace art