blob: e434e9e7efd8c2e183df297245872e4b48e3733c [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
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700290class DeoptimizationSlowPathARM : public SlowPathCodeARM {
291 public:
292 explicit DeoptimizationSlowPathARM(HInstruction* instruction)
293 : instruction_(instruction) {}
294
295 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
296 __ Bind(GetEntryLabel());
297 SaveLiveRegisters(codegen, instruction_->GetLocations());
298 DCHECK(instruction_->IsDeoptimize());
299 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
300 uint32_t dex_pc = deoptimize->GetDexPc();
301 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
302 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
303 }
304
305 private:
306 HInstruction* const instruction_;
307 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
308};
309
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000310#undef __
311
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100312#undef __
313#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700314
315inline Condition ARMCondition(IfCondition cond) {
316 switch (cond) {
317 case kCondEQ: return EQ;
318 case kCondNE: return NE;
319 case kCondLT: return LT;
320 case kCondLE: return LE;
321 case kCondGT: return GT;
322 case kCondGE: return GE;
323 default:
324 LOG(FATAL) << "Unknown if condition";
325 }
326 return EQ; // Unreachable.
327}
328
329inline Condition ARMOppositeCondition(IfCondition cond) {
330 switch (cond) {
331 case kCondEQ: return NE;
332 case kCondNE: return EQ;
333 case kCondLT: return GE;
334 case kCondLE: return GT;
335 case kCondGT: return LE;
336 case kCondGE: return LT;
337 default:
338 LOG(FATAL) << "Unknown if condition";
339 }
340 return EQ; // Unreachable.
341}
342
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100343void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
344 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
345}
346
347void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000348 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100349}
350
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100351size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
352 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
353 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100354}
355
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100356size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
357 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
358 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100359}
360
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000361size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
362 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
363 return kArmWordSize;
364}
365
366size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
367 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
368 return kArmWordSize;
369}
370
Calin Juravle34166012014-12-19 17:22:29 +0000371CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000372 const ArmInstructionSetFeatures& isa_features,
373 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000374 : CodeGenerator(graph,
375 kNumberOfCoreRegisters,
376 kNumberOfSRegisters,
377 kNumberOfRegisterPairs,
378 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
379 arraysize(kCoreCalleeSaves)),
380 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
381 arraysize(kFpuCalleeSaves)),
382 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100383 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100384 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100385 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100386 move_resolver_(graph->GetArena(), this),
Calin Juravle34166012014-12-19 17:22:29 +0000387 assembler_(true),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000388 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000389 // Save the PC register to mimic Quick.
390 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100391}
392
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100393Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100394 switch (type) {
395 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100396 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100397 ArmManagedRegister pair =
398 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100399 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
400 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
401
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100402 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
403 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100404 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100405 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100406 }
407
408 case Primitive::kPrimByte:
409 case Primitive::kPrimBoolean:
410 case Primitive::kPrimChar:
411 case Primitive::kPrimShort:
412 case Primitive::kPrimInt:
413 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100414 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100415 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100416 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
417 ArmManagedRegister current =
418 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
419 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100420 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100421 }
422 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100423 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100424 }
425
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000426 case Primitive::kPrimFloat: {
427 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100428 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100429 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100430
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000431 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000432 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
433 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000434 return Location::FpuRegisterPairLocation(reg, reg + 1);
435 }
436
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100437 case Primitive::kPrimVoid:
438 LOG(FATAL) << "Unreachable type " << type;
439 }
440
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100441 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100442}
443
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000444void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100445 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100446 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100447
448 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100449 blocked_core_registers_[SP] = true;
450 blocked_core_registers_[LR] = true;
451 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100452
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100453 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100454 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100455
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100456 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100457 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100458
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000459 if (is_baseline) {
460 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
461 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
462 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000463
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000464 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
465
466 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
467 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
468 }
469 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100470
471 UpdateBlockedPairRegisters();
472}
473
474void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
475 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
476 ArmManagedRegister current =
477 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
478 if (blocked_core_registers_[current.AsRegisterPairLow()]
479 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
480 blocked_register_pairs_[i] = true;
481 }
482 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100483}
484
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100485InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
486 : HGraphVisitor(graph),
487 assembler_(codegen->GetAssembler()),
488 codegen_(codegen) {}
489
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000490static uint32_t LeastSignificantBit(uint32_t mask) {
491 // ffs starts at 1.
492 return ffs(mask) - 1;
493}
494
495void CodeGeneratorARM::ComputeSpillMask() {
496 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000497 // Save one extra register for baseline. Note that on thumb2, there is no easy
498 // instruction to restore just the PC, so this actually helps both baseline
499 // and non-baseline to save and restore at least two registers at entry and exit.
500 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000501 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
502 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
503 // We use vpush and vpop for saving and restoring floating point registers, which take
504 // a SRegister and the number of registers to save/restore after that SRegister. We
505 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
506 // but in the range.
507 if (fpu_spill_mask_ != 0) {
508 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
509 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
510 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
511 fpu_spill_mask_ |= (1 << i);
512 }
513 }
514}
515
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100516static dwarf::Reg DWARFReg(Register reg) {
517 return dwarf::Reg::ArmCore(static_cast<int>(reg));
518}
519
520static dwarf::Reg DWARFReg(SRegister reg) {
521 return dwarf::Reg::ArmFp(static_cast<int>(reg));
522}
523
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000524void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000525 bool skip_overflow_check =
526 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000527 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000528 __ Bind(&frame_entry_label_);
529
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000530 if (HasEmptyFrame()) {
531 return;
532 }
533
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100534 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000535 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
536 __ LoadFromOffset(kLoadWord, IP, IP, 0);
537 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100538 }
539
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000540 // PC is in the list of callee-save to mimic Quick, but we need to push
541 // LR at entry instead.
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100542 uint32_t push_mask = (core_spill_mask_ & (~(1 << PC))) | 1 << LR;
543 __ PushList(push_mask);
544 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(push_mask));
545 __ cfi().RelOffsetForMany(DWARFReg(Register(0)), 0, push_mask, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000546 if (fpu_spill_mask_ != 0) {
547 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
548 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100549 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
550 __ cfi().RelOffsetForMany(DWARFReg(SRegister(0)), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000551 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100552 int adjust = GetFrameSize() - FrameEntrySpillSize();
553 __ AddConstant(SP, -adjust);
554 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100555 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000556}
557
558void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000559 if (HasEmptyFrame()) {
560 __ bx(LR);
561 return;
562 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100563 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100564 int adjust = GetFrameSize() - FrameEntrySpillSize();
565 __ AddConstant(SP, adjust);
566 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000567 if (fpu_spill_mask_ != 0) {
568 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
569 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100570 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
571 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000572 }
573 __ PopList(core_spill_mask_);
David Srbeckyc34dc932015-04-12 09:27:43 +0100574 __ cfi().RestoreState();
575 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000576}
577
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100578void CodeGeneratorARM::Bind(HBasicBlock* block) {
579 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000580}
581
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100582Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
583 switch (load->GetType()) {
584 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100585 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100586 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100587
588 case Primitive::kPrimInt:
589 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100590 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100591 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100592
593 case Primitive::kPrimBoolean:
594 case Primitive::kPrimByte:
595 case Primitive::kPrimChar:
596 case Primitive::kPrimShort:
597 case Primitive::kPrimVoid:
598 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700599 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100600 }
601
602 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700603 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100604}
605
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100606Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
607 switch (type) {
608 case Primitive::kPrimBoolean:
609 case Primitive::kPrimByte:
610 case Primitive::kPrimChar:
611 case Primitive::kPrimShort:
612 case Primitive::kPrimInt:
613 case Primitive::kPrimNot: {
614 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000615 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100616 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100617 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100618 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000619 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100620 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100621 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100622
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000623 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100624 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000625 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100626 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000627 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100628 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000629 if (calling_convention.GetRegisterAt(index) == R1) {
630 // Skip R1, and use R2_R3 instead.
631 gp_index_++;
632 index++;
633 }
634 }
635 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
636 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000637 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000638 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000639 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100640 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000641 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
642 }
643 }
644
645 case Primitive::kPrimFloat: {
646 uint32_t stack_index = stack_index_++;
647 if (float_index_ % 2 == 0) {
648 float_index_ = std::max(double_index_, float_index_);
649 }
650 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
651 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
652 } else {
653 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
654 }
655 }
656
657 case Primitive::kPrimDouble: {
658 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
659 uint32_t stack_index = stack_index_;
660 stack_index_ += 2;
661 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
662 uint32_t index = double_index_;
663 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000664 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000665 calling_convention.GetFpuRegisterAt(index),
666 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000667 DCHECK(ExpectedPairLayout(result));
668 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000669 } else {
670 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100671 }
672 }
673
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100674 case Primitive::kPrimVoid:
675 LOG(FATAL) << "Unexpected parameter type " << type;
676 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100677 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100678 return Location();
679}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100680
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000681Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
682 switch (type) {
683 case Primitive::kPrimBoolean:
684 case Primitive::kPrimByte:
685 case Primitive::kPrimChar:
686 case Primitive::kPrimShort:
687 case Primitive::kPrimInt:
688 case Primitive::kPrimNot: {
689 return Location::RegisterLocation(R0);
690 }
691
692 case Primitive::kPrimFloat: {
693 return Location::FpuRegisterLocation(S0);
694 }
695
696 case Primitive::kPrimLong: {
697 return Location::RegisterPairLocation(R0, R1);
698 }
699
700 case Primitive::kPrimDouble: {
701 return Location::FpuRegisterPairLocation(S0, S1);
702 }
703
704 case Primitive::kPrimVoid:
705 return Location();
706 }
707 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000708}
709
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100710void CodeGeneratorARM::Move32(Location destination, Location source) {
711 if (source.Equals(destination)) {
712 return;
713 }
714 if (destination.IsRegister()) {
715 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000716 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100717 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000718 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100719 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000720 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100721 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100722 } else if (destination.IsFpuRegister()) {
723 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000724 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100725 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000726 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100727 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000728 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100729 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100730 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000731 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100732 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000733 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100734 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000735 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100736 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000737 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100738 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
739 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100740 }
741 }
742}
743
744void CodeGeneratorARM::Move64(Location destination, Location source) {
745 if (source.Equals(destination)) {
746 return;
747 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100748 if (destination.IsRegisterPair()) {
749 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000750 EmitParallelMoves(
751 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
752 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
753 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
754 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100755 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000756 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100757 } else {
758 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000759 DCHECK(ExpectedPairLayout(destination));
760 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
761 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100762 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000763 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100764 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000765 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
766 SP,
767 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100768 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000769 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100770 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100771 } else {
772 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100773 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000774 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100775 if (source.AsRegisterPairLow<Register>() == R1) {
776 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100777 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
778 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100779 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100780 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100781 SP, destination.GetStackIndex());
782 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000783 } else if (source.IsFpuRegisterPair()) {
784 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
785 SP,
786 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100787 } else {
788 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000789 EmitParallelMoves(
790 Location::StackSlot(source.GetStackIndex()),
791 Location::StackSlot(destination.GetStackIndex()),
792 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
793 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100794 }
795 }
796}
797
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100798void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100799 LocationSummary* locations = instruction->GetLocations();
800 if (locations != nullptr && locations->Out().Equals(location)) {
801 return;
802 }
803
Calin Juravlea21f5982014-11-13 15:53:04 +0000804 if (locations != nullptr && locations->Out().IsConstant()) {
805 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000806 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
807 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000808 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000809 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000810 } else {
811 DCHECK(location.IsStackSlot());
812 __ LoadImmediate(IP, value);
813 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
814 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000815 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000816 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000817 int64_t value = const_to_move->AsLongConstant()->GetValue();
818 if (location.IsRegisterPair()) {
819 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
820 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
821 } else {
822 DCHECK(location.IsDoubleStackSlot());
823 __ LoadImmediate(IP, Low32Bits(value));
824 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
825 __ LoadImmediate(IP, High32Bits(value));
826 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
827 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100828 }
Roland Levillain476df552014-10-09 17:51:36 +0100829 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100830 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
831 switch (instruction->GetType()) {
832 case Primitive::kPrimBoolean:
833 case Primitive::kPrimByte:
834 case Primitive::kPrimChar:
835 case Primitive::kPrimShort:
836 case Primitive::kPrimInt:
837 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100838 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100839 Move32(location, Location::StackSlot(stack_slot));
840 break;
841
842 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100843 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100844 Move64(location, Location::DoubleStackSlot(stack_slot));
845 break;
846
847 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100848 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100849 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000850 } else if (instruction->IsTemporary()) {
851 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000852 if (temp_location.IsStackSlot()) {
853 Move32(location, temp_location);
854 } else {
855 DCHECK(temp_location.IsDoubleStackSlot());
856 Move64(location, temp_location);
857 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000858 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100859 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100860 switch (instruction->GetType()) {
861 case Primitive::kPrimBoolean:
862 case Primitive::kPrimByte:
863 case Primitive::kPrimChar:
864 case Primitive::kPrimShort:
865 case Primitive::kPrimNot:
866 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100867 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100868 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100869 break;
870
871 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100872 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100873 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100874 break;
875
876 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100877 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100878 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000879 }
880}
881
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100882void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
883 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000884 uint32_t dex_pc,
885 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100886 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
887 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000888 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100889 DCHECK(instruction->IsSuspendCheck()
890 || instruction->IsBoundsCheck()
891 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000892 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000893 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100894 || !IsLeafMethod());
895}
896
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000897void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000898 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000899}
900
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000901void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000902 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100903 DCHECK(!successor->IsExitBlock());
904
905 HBasicBlock* block = got->GetBlock();
906 HInstruction* previous = got->GetPrevious();
907
908 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000909 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100910 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
911 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
912 return;
913 }
914
915 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
916 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
917 }
918 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000919 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000920 }
921}
922
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000923void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000924 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000925}
926
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000927void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700928 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000929}
930
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700931void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
932 Label* true_target,
933 Label* false_target,
934 Label* always_true_target) {
935 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100936 if (cond->IsIntConstant()) {
937 // Constant condition, statically compared against 1.
938 int32_t cond_value = cond->AsIntConstant()->GetValue();
939 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700940 if (always_true_target != nullptr) {
941 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100942 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100943 return;
944 } else {
945 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100946 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100947 } else {
948 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
949 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700950 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
951 __ cmp(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100952 ShifterOperand(0));
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700953 __ b(true_target, NE);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100954 } else {
955 // Condition has not been materialized, use its inputs as the
956 // comparison and its condition as the branch condition.
957 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000958 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000959 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100960 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000961 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100962 } else {
963 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000964 HConstant* constant = locations->InAt(1).GetConstant();
965 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100966 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000967 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
968 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100969 } else {
970 Register temp = IP;
971 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000972 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100973 }
974 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700975 __ b(true_target, ARMCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100976 }
Dave Allison20dfc792014-06-16 20:44:29 -0700977 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700978 if (false_target != nullptr) {
979 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000980 }
981}
982
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700983void LocationsBuilderARM::VisitIf(HIf* if_instr) {
984 LocationSummary* locations =
985 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
986 HInstruction* cond = if_instr->InputAt(0);
987 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
988 locations->SetInAt(0, Location::RequiresRegister());
989 }
990}
991
992void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
993 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
994 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
995 Label* always_true_target = true_target;
996 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
997 if_instr->IfTrueSuccessor())) {
998 always_true_target = nullptr;
999 }
1000 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1001 if_instr->IfFalseSuccessor())) {
1002 false_target = nullptr;
1003 }
1004 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1005}
1006
1007void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1008 LocationSummary* locations = new (GetGraph()->GetArena())
1009 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1010 HInstruction* cond = deoptimize->InputAt(0);
1011 DCHECK(cond->IsCondition());
1012 if (cond->AsCondition()->NeedsMaterialization()) {
1013 locations->SetInAt(0, Location::RequiresRegister());
1014 }
1015}
1016
1017void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1018 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1019 DeoptimizationSlowPathARM(deoptimize);
1020 codegen_->AddSlowPath(slow_path);
1021 Label* slow_path_entry = slow_path->GetEntryLabel();
1022 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1023}
Dave Allison20dfc792014-06-16 20:44:29 -07001024
1025void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001026 LocationSummary* locations =
1027 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001028 locations->SetInAt(0, Location::RequiresRegister());
1029 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001030 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001031 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001032 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001033}
1034
Dave Allison20dfc792014-06-16 20:44:29 -07001035void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001036 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001037 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001038 Register left = locations->InAt(0).AsRegister<Register>();
1039
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001040 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001041 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001042 } else {
1043 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -08001044 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001045 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001046 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1047 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001048 } else {
1049 Register temp = IP;
1050 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001051 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001052 }
Dave Allison20dfc792014-06-16 20:44:29 -07001053 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001054 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001055 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001056 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001057 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001058 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001059}
1060
1061void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1062 VisitCondition(comp);
1063}
1064
1065void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1066 VisitCondition(comp);
1067}
1068
1069void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1070 VisitCondition(comp);
1071}
1072
1073void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1074 VisitCondition(comp);
1075}
1076
1077void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1078 VisitCondition(comp);
1079}
1080
1081void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1082 VisitCondition(comp);
1083}
1084
1085void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1086 VisitCondition(comp);
1087}
1088
1089void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1090 VisitCondition(comp);
1091}
1092
1093void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1094 VisitCondition(comp);
1095}
1096
1097void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1098 VisitCondition(comp);
1099}
1100
1101void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1102 VisitCondition(comp);
1103}
1104
1105void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1106 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001107}
1108
1109void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001110 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001111}
1112
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001113void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1114 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001115}
1116
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001117void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001118 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001119}
1120
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001121void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001122 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001123 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001124}
1125
1126void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001127 LocationSummary* locations =
1128 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001129 switch (store->InputAt(1)->GetType()) {
1130 case Primitive::kPrimBoolean:
1131 case Primitive::kPrimByte:
1132 case Primitive::kPrimChar:
1133 case Primitive::kPrimShort:
1134 case Primitive::kPrimInt:
1135 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001136 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001137 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1138 break;
1139
1140 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001141 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001142 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1143 break;
1144
1145 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001146 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001147 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001148}
1149
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001150void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001151 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001152}
1153
1154void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001155 LocationSummary* locations =
1156 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001157 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001158}
1159
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001160void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001161 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001162 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001163}
1164
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001165void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1166 LocationSummary* locations =
1167 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1168 locations->SetOut(Location::ConstantLocation(constant));
1169}
1170
1171void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1172 // Will be generated at use site.
1173 UNUSED(constant);
1174}
1175
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001176void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001177 LocationSummary* locations =
1178 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001179 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001180}
1181
1182void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1183 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001184 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001185}
1186
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001187void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1188 LocationSummary* locations =
1189 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1190 locations->SetOut(Location::ConstantLocation(constant));
1191}
1192
1193void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1194 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001195 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001196}
1197
1198void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1199 LocationSummary* locations =
1200 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1201 locations->SetOut(Location::ConstantLocation(constant));
1202}
1203
1204void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1205 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001206 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001207}
1208
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001209void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001210 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001211}
1212
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001213void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001214 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001215 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001216}
1217
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001218void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001219 LocationSummary* locations =
1220 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001221 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001222}
1223
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001224void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001225 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001226 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001227}
1228
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001229void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001230 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1231 codegen_->GetInstructionSetFeatures());
1232 if (intrinsic.TryDispatch(invoke)) {
1233 return;
1234 }
1235
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001236 HandleInvoke(invoke);
1237}
1238
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001239void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001240 DCHECK(RequiresCurrentMethod());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001241 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001242}
1243
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001244static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1245 if (invoke->GetLocations()->Intrinsified()) {
1246 IntrinsicCodeGeneratorARM intrinsic(codegen);
1247 intrinsic.Dispatch(invoke);
1248 return true;
1249 }
1250 return false;
1251}
1252
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001253void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001254 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1255 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001256 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001257
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001258 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
1259
1260 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001261 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001262}
1263
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001264void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001265 LocationSummary* locations =
1266 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001267 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001268
1269 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001270 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001271 HInstruction* input = invoke->InputAt(i);
1272 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1273 }
1274
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001275 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001276}
1277
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001278void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001279 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1280 codegen_->GetInstructionSetFeatures());
1281 if (intrinsic.TryDispatch(invoke)) {
1282 return;
1283 }
1284
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001285 HandleInvoke(invoke);
1286}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001287
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001288void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001289 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1290 return;
1291 }
1292
Roland Levillain271ab9c2014-11-27 15:23:57 +00001293 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001294 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1295 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1296 LocationSummary* locations = invoke->GetLocations();
1297 Location receiver = locations->InAt(0);
1298 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1299 // temp = object->GetClass();
1300 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001301 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1302 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001303 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001304 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001305 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001306 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001307 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001308 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001309 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001310 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001311 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001312 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001313 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001314 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001315 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001316 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001317}
1318
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001319void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1320 HandleInvoke(invoke);
1321 // Add the hidden argument.
1322 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1323}
1324
1325void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1326 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001327 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001328 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1329 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1330 LocationSummary* locations = invoke->GetLocations();
1331 Location receiver = locations->InAt(0);
1332 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1333
1334 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001335 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1336 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001337
1338 // temp = object->GetClass();
1339 if (receiver.IsStackSlot()) {
1340 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1341 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1342 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001343 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001344 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001345 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001346 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001347 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001348 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001349 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1350 // LR = temp->GetEntryPoint();
1351 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1352 // LR();
1353 __ blx(LR);
1354 DCHECK(!codegen_->IsLeafMethod());
1355 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1356}
1357
Roland Levillain88cb1752014-10-20 16:36:47 +01001358void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1359 LocationSummary* locations =
1360 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1361 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001362 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001363 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001364 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1365 break;
1366 }
1367 case Primitive::kPrimLong: {
1368 locations->SetInAt(0, Location::RequiresRegister());
1369 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001370 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001371 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001372
Roland Levillain88cb1752014-10-20 16:36:47 +01001373 case Primitive::kPrimFloat:
1374 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001375 locations->SetInAt(0, Location::RequiresFpuRegister());
1376 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001377 break;
1378
1379 default:
1380 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1381 }
1382}
1383
1384void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1385 LocationSummary* locations = neg->GetLocations();
1386 Location out = locations->Out();
1387 Location in = locations->InAt(0);
1388 switch (neg->GetResultType()) {
1389 case Primitive::kPrimInt:
1390 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001391 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001392 break;
1393
1394 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001395 DCHECK(in.IsRegisterPair());
1396 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1397 __ rsbs(out.AsRegisterPairLow<Register>(),
1398 in.AsRegisterPairLow<Register>(),
1399 ShifterOperand(0));
1400 // We cannot emit an RSC (Reverse Subtract with Carry)
1401 // instruction here, as it does not exist in the Thumb-2
1402 // instruction set. We use the following approach
1403 // using SBC and SUB instead.
1404 //
1405 // out.hi = -C
1406 __ sbc(out.AsRegisterPairHigh<Register>(),
1407 out.AsRegisterPairHigh<Register>(),
1408 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1409 // out.hi = out.hi - in.hi
1410 __ sub(out.AsRegisterPairHigh<Register>(),
1411 out.AsRegisterPairHigh<Register>(),
1412 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1413 break;
1414
Roland Levillain88cb1752014-10-20 16:36:47 +01001415 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001416 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001417 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001418 break;
1419
Roland Levillain88cb1752014-10-20 16:36:47 +01001420 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001421 DCHECK(in.IsFpuRegisterPair());
1422 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1423 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001424 break;
1425
1426 default:
1427 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1428 }
1429}
1430
Roland Levillaindff1f282014-11-05 14:15:05 +00001431void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001432 Primitive::Type result_type = conversion->GetResultType();
1433 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001434 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001435
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001436 // The float-to-long and double-to-long type conversions rely on a
1437 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001438 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001439 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1440 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001441 ? LocationSummary::kCall
1442 : LocationSummary::kNoCall;
1443 LocationSummary* locations =
1444 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1445
David Brazdilb2bd1c52015-03-25 11:17:37 +00001446 // The Java language does not allow treating boolean as an integral type but
1447 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001448
Roland Levillaindff1f282014-11-05 14:15:05 +00001449 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001450 case Primitive::kPrimByte:
1451 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001452 case Primitive::kPrimBoolean:
1453 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001454 case Primitive::kPrimShort:
1455 case Primitive::kPrimInt:
1456 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001457 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001458 locations->SetInAt(0, Location::RequiresRegister());
1459 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1460 break;
1461
1462 default:
1463 LOG(FATAL) << "Unexpected type conversion from " << input_type
1464 << " to " << result_type;
1465 }
1466 break;
1467
Roland Levillain01a8d712014-11-14 16:27:39 +00001468 case Primitive::kPrimShort:
1469 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001470 case Primitive::kPrimBoolean:
1471 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001472 case Primitive::kPrimByte:
1473 case Primitive::kPrimInt:
1474 case Primitive::kPrimChar:
1475 // Processing a Dex `int-to-short' instruction.
1476 locations->SetInAt(0, Location::RequiresRegister());
1477 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1478 break;
1479
1480 default:
1481 LOG(FATAL) << "Unexpected type conversion from " << input_type
1482 << " to " << result_type;
1483 }
1484 break;
1485
Roland Levillain946e1432014-11-11 17:35:19 +00001486 case Primitive::kPrimInt:
1487 switch (input_type) {
1488 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001489 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001490 locations->SetInAt(0, Location::Any());
1491 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1492 break;
1493
1494 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001495 // Processing a Dex `float-to-int' instruction.
1496 locations->SetInAt(0, Location::RequiresFpuRegister());
1497 locations->SetOut(Location::RequiresRegister());
1498 locations->AddTemp(Location::RequiresFpuRegister());
1499 break;
1500
Roland Levillain946e1432014-11-11 17:35:19 +00001501 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001502 // Processing a Dex `double-to-int' instruction.
1503 locations->SetInAt(0, Location::RequiresFpuRegister());
1504 locations->SetOut(Location::RequiresRegister());
1505 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001506 break;
1507
1508 default:
1509 LOG(FATAL) << "Unexpected type conversion from " << input_type
1510 << " to " << result_type;
1511 }
1512 break;
1513
Roland Levillaindff1f282014-11-05 14:15:05 +00001514 case Primitive::kPrimLong:
1515 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001516 case Primitive::kPrimBoolean:
1517 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001518 case Primitive::kPrimByte:
1519 case Primitive::kPrimShort:
1520 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001521 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001522 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001523 locations->SetInAt(0, Location::RequiresRegister());
1524 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1525 break;
1526
Roland Levillain624279f2014-12-04 11:54:28 +00001527 case Primitive::kPrimFloat: {
1528 // Processing a Dex `float-to-long' instruction.
1529 InvokeRuntimeCallingConvention calling_convention;
1530 locations->SetInAt(0, Location::FpuRegisterLocation(
1531 calling_convention.GetFpuRegisterAt(0)));
1532 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1533 break;
1534 }
1535
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001536 case Primitive::kPrimDouble: {
1537 // Processing a Dex `double-to-long' instruction.
1538 InvokeRuntimeCallingConvention calling_convention;
1539 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1540 calling_convention.GetFpuRegisterAt(0),
1541 calling_convention.GetFpuRegisterAt(1)));
1542 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001543 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001544 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001545
1546 default:
1547 LOG(FATAL) << "Unexpected type conversion from " << input_type
1548 << " to " << result_type;
1549 }
1550 break;
1551
Roland Levillain981e4542014-11-14 11:47:14 +00001552 case Primitive::kPrimChar:
1553 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001554 case Primitive::kPrimBoolean:
1555 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001556 case Primitive::kPrimByte:
1557 case Primitive::kPrimShort:
1558 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001559 // Processing a Dex `int-to-char' instruction.
1560 locations->SetInAt(0, Location::RequiresRegister());
1561 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1562 break;
1563
1564 default:
1565 LOG(FATAL) << "Unexpected type conversion from " << input_type
1566 << " to " << result_type;
1567 }
1568 break;
1569
Roland Levillaindff1f282014-11-05 14:15:05 +00001570 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001571 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001572 case Primitive::kPrimBoolean:
1573 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001574 case Primitive::kPrimByte:
1575 case Primitive::kPrimShort:
1576 case Primitive::kPrimInt:
1577 case Primitive::kPrimChar:
1578 // Processing a Dex `int-to-float' instruction.
1579 locations->SetInAt(0, Location::RequiresRegister());
1580 locations->SetOut(Location::RequiresFpuRegister());
1581 break;
1582
1583 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001584 // Processing a Dex `long-to-float' instruction.
1585 locations->SetInAt(0, Location::RequiresRegister());
1586 locations->SetOut(Location::RequiresFpuRegister());
1587 locations->AddTemp(Location::RequiresRegister());
1588 locations->AddTemp(Location::RequiresRegister());
1589 locations->AddTemp(Location::RequiresFpuRegister());
1590 locations->AddTemp(Location::RequiresFpuRegister());
1591 break;
1592
Roland Levillaincff13742014-11-17 14:32:17 +00001593 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001594 // Processing a Dex `double-to-float' instruction.
1595 locations->SetInAt(0, Location::RequiresFpuRegister());
1596 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001597 break;
1598
1599 default:
1600 LOG(FATAL) << "Unexpected type conversion from " << input_type
1601 << " to " << result_type;
1602 };
1603 break;
1604
Roland Levillaindff1f282014-11-05 14:15:05 +00001605 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001606 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001607 case Primitive::kPrimBoolean:
1608 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001609 case Primitive::kPrimByte:
1610 case Primitive::kPrimShort:
1611 case Primitive::kPrimInt:
1612 case Primitive::kPrimChar:
1613 // Processing a Dex `int-to-double' instruction.
1614 locations->SetInAt(0, Location::RequiresRegister());
1615 locations->SetOut(Location::RequiresFpuRegister());
1616 break;
1617
1618 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001619 // Processing a Dex `long-to-double' instruction.
1620 locations->SetInAt(0, Location::RequiresRegister());
1621 locations->SetOut(Location::RequiresFpuRegister());
1622 locations->AddTemp(Location::RequiresRegister());
1623 locations->AddTemp(Location::RequiresRegister());
1624 locations->AddTemp(Location::RequiresFpuRegister());
1625 break;
1626
Roland Levillaincff13742014-11-17 14:32:17 +00001627 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001628 // Processing a Dex `float-to-double' instruction.
1629 locations->SetInAt(0, Location::RequiresFpuRegister());
1630 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001631 break;
1632
1633 default:
1634 LOG(FATAL) << "Unexpected type conversion from " << input_type
1635 << " to " << result_type;
1636 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001637 break;
1638
1639 default:
1640 LOG(FATAL) << "Unexpected type conversion from " << input_type
1641 << " to " << result_type;
1642 }
1643}
1644
1645void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1646 LocationSummary* locations = conversion->GetLocations();
1647 Location out = locations->Out();
1648 Location in = locations->InAt(0);
1649 Primitive::Type result_type = conversion->GetResultType();
1650 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001651 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001652 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001653 case Primitive::kPrimByte:
1654 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001655 case Primitive::kPrimBoolean:
1656 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001657 case Primitive::kPrimShort:
1658 case Primitive::kPrimInt:
1659 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001660 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001661 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001662 break;
1663
1664 default:
1665 LOG(FATAL) << "Unexpected type conversion from " << input_type
1666 << " to " << result_type;
1667 }
1668 break;
1669
Roland Levillain01a8d712014-11-14 16:27:39 +00001670 case Primitive::kPrimShort:
1671 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001672 case Primitive::kPrimBoolean:
1673 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001674 case Primitive::kPrimByte:
1675 case Primitive::kPrimInt:
1676 case Primitive::kPrimChar:
1677 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001678 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001679 break;
1680
1681 default:
1682 LOG(FATAL) << "Unexpected type conversion from " << input_type
1683 << " to " << result_type;
1684 }
1685 break;
1686
Roland Levillain946e1432014-11-11 17:35:19 +00001687 case Primitive::kPrimInt:
1688 switch (input_type) {
1689 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001690 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001691 DCHECK(out.IsRegister());
1692 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001693 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001694 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001695 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001696 } else {
1697 DCHECK(in.IsConstant());
1698 DCHECK(in.GetConstant()->IsLongConstant());
1699 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001700 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001701 }
1702 break;
1703
Roland Levillain3f8f9362014-12-02 17:45:01 +00001704 case Primitive::kPrimFloat: {
1705 // Processing a Dex `float-to-int' instruction.
1706 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1707 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1708 __ vcvtis(temp, temp);
1709 __ vmovrs(out.AsRegister<Register>(), temp);
1710 break;
1711 }
1712
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001713 case Primitive::kPrimDouble: {
1714 // Processing a Dex `double-to-int' instruction.
1715 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1716 DRegister temp_d = FromLowSToD(temp_s);
1717 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1718 __ vcvtid(temp_s, temp_d);
1719 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001720 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001721 }
Roland Levillain946e1432014-11-11 17:35:19 +00001722
1723 default:
1724 LOG(FATAL) << "Unexpected type conversion from " << input_type
1725 << " to " << result_type;
1726 }
1727 break;
1728
Roland Levillaindff1f282014-11-05 14:15:05 +00001729 case Primitive::kPrimLong:
1730 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001731 case Primitive::kPrimBoolean:
1732 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001733 case Primitive::kPrimByte:
1734 case Primitive::kPrimShort:
1735 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001736 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001737 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001738 DCHECK(out.IsRegisterPair());
1739 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001740 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001741 // Sign extension.
1742 __ Asr(out.AsRegisterPairHigh<Register>(),
1743 out.AsRegisterPairLow<Register>(),
1744 31);
1745 break;
1746
1747 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001748 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001749 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1750 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001751 conversion->GetDexPc(),
1752 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001753 break;
1754
Roland Levillaindff1f282014-11-05 14:15:05 +00001755 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001756 // Processing a Dex `double-to-long' instruction.
1757 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1758 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001759 conversion->GetDexPc(),
1760 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001761 break;
1762
1763 default:
1764 LOG(FATAL) << "Unexpected type conversion from " << input_type
1765 << " to " << result_type;
1766 }
1767 break;
1768
Roland Levillain981e4542014-11-14 11:47:14 +00001769 case Primitive::kPrimChar:
1770 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001771 case Primitive::kPrimBoolean:
1772 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001773 case Primitive::kPrimByte:
1774 case Primitive::kPrimShort:
1775 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001776 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001777 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001778 break;
1779
1780 default:
1781 LOG(FATAL) << "Unexpected type conversion from " << input_type
1782 << " to " << result_type;
1783 }
1784 break;
1785
Roland Levillaindff1f282014-11-05 14:15:05 +00001786 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001787 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001788 case Primitive::kPrimBoolean:
1789 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001790 case Primitive::kPrimByte:
1791 case Primitive::kPrimShort:
1792 case Primitive::kPrimInt:
1793 case Primitive::kPrimChar: {
1794 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001795 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1796 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001797 break;
1798 }
1799
Roland Levillain6d0e4832014-11-27 18:31:21 +00001800 case Primitive::kPrimLong: {
1801 // Processing a Dex `long-to-float' instruction.
1802 Register low = in.AsRegisterPairLow<Register>();
1803 Register high = in.AsRegisterPairHigh<Register>();
1804 SRegister output = out.AsFpuRegister<SRegister>();
1805 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1806 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1807 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1808 DRegister temp1_d = FromLowSToD(temp1_s);
1809 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1810 DRegister temp2_d = FromLowSToD(temp2_s);
1811
1812 // Operations use doubles for precision reasons (each 32-bit
1813 // half of a long fits in the 53-bit mantissa of a double,
1814 // but not in the 24-bit mantissa of a float). This is
1815 // especially important for the low bits. The result is
1816 // eventually converted to float.
1817
1818 // temp1_d = int-to-double(high)
1819 __ vmovsr(temp1_s, high);
1820 __ vcvtdi(temp1_d, temp1_s);
1821 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1822 // as an immediate value into `temp2_d` does not work, as
1823 // this instruction only transfers 8 significant bits of its
1824 // immediate operand. Instead, use two 32-bit core
1825 // registers to load `k2Pow32EncodingForDouble` into
1826 // `temp2_d`.
1827 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1828 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1829 __ vmovdrr(temp2_d, constant_low, constant_high);
1830 // temp1_d = temp1_d * 2^32
1831 __ vmuld(temp1_d, temp1_d, temp2_d);
1832 // temp2_d = unsigned-to-double(low)
1833 __ vmovsr(temp2_s, low);
1834 __ vcvtdu(temp2_d, temp2_s);
1835 // temp1_d = temp1_d + temp2_d
1836 __ vaddd(temp1_d, temp1_d, temp2_d);
1837 // output = double-to-float(temp1_d);
1838 __ vcvtsd(output, temp1_d);
1839 break;
1840 }
1841
Roland Levillaincff13742014-11-17 14:32:17 +00001842 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001843 // Processing a Dex `double-to-float' instruction.
1844 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1845 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001846 break;
1847
1848 default:
1849 LOG(FATAL) << "Unexpected type conversion from " << input_type
1850 << " to " << result_type;
1851 };
1852 break;
1853
Roland Levillaindff1f282014-11-05 14:15:05 +00001854 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001855 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001856 case Primitive::kPrimBoolean:
1857 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001858 case Primitive::kPrimByte:
1859 case Primitive::kPrimShort:
1860 case Primitive::kPrimInt:
1861 case Primitive::kPrimChar: {
1862 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001863 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001864 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1865 out.AsFpuRegisterPairLow<SRegister>());
1866 break;
1867 }
1868
Roland Levillain647b9ed2014-11-27 12:06:00 +00001869 case Primitive::kPrimLong: {
1870 // Processing a Dex `long-to-double' instruction.
1871 Register low = in.AsRegisterPairLow<Register>();
1872 Register high = in.AsRegisterPairHigh<Register>();
1873 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1874 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001875 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1876 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001877 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1878 DRegister temp_d = FromLowSToD(temp_s);
1879
Roland Levillain647b9ed2014-11-27 12:06:00 +00001880 // out_d = int-to-double(high)
1881 __ vmovsr(out_s, high);
1882 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001883 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1884 // as an immediate value into `temp_d` does not work, as
1885 // this instruction only transfers 8 significant bits of its
1886 // immediate operand. Instead, use two 32-bit core
1887 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1888 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1889 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001890 __ vmovdrr(temp_d, constant_low, constant_high);
1891 // out_d = out_d * 2^32
1892 __ vmuld(out_d, out_d, temp_d);
1893 // temp_d = unsigned-to-double(low)
1894 __ vmovsr(temp_s, low);
1895 __ vcvtdu(temp_d, temp_s);
1896 // out_d = out_d + temp_d
1897 __ vaddd(out_d, out_d, temp_d);
1898 break;
1899 }
1900
Roland Levillaincff13742014-11-17 14:32:17 +00001901 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001902 // Processing a Dex `float-to-double' instruction.
1903 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1904 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001905 break;
1906
1907 default:
1908 LOG(FATAL) << "Unexpected type conversion from " << input_type
1909 << " to " << result_type;
1910 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001911 break;
1912
1913 default:
1914 LOG(FATAL) << "Unexpected type conversion from " << input_type
1915 << " to " << result_type;
1916 }
1917}
1918
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001919void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001920 LocationSummary* locations =
1921 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001922 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001923 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001924 locations->SetInAt(0, Location::RequiresRegister());
1925 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001926 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1927 break;
1928 }
1929
1930 case Primitive::kPrimLong: {
1931 locations->SetInAt(0, Location::RequiresRegister());
1932 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001933 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001934 break;
1935 }
1936
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001937 case Primitive::kPrimFloat:
1938 case Primitive::kPrimDouble: {
1939 locations->SetInAt(0, Location::RequiresFpuRegister());
1940 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001941 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001942 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001943 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001944
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001945 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001946 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001947 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001948}
1949
1950void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1951 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001952 Location out = locations->Out();
1953 Location first = locations->InAt(0);
1954 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001955 switch (add->GetResultType()) {
1956 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001957 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001958 __ add(out.AsRegister<Register>(),
1959 first.AsRegister<Register>(),
1960 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001961 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001962 __ AddConstant(out.AsRegister<Register>(),
1963 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001964 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001965 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001966 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001967
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001968 case Primitive::kPrimLong: {
1969 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001970 __ adds(out.AsRegisterPairLow<Register>(),
1971 first.AsRegisterPairLow<Register>(),
1972 ShifterOperand(second.AsRegisterPairLow<Register>()));
1973 __ adc(out.AsRegisterPairHigh<Register>(),
1974 first.AsRegisterPairHigh<Register>(),
1975 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001976 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001977 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001978
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001979 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001980 __ vadds(out.AsFpuRegister<SRegister>(),
1981 first.AsFpuRegister<SRegister>(),
1982 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001983 break;
1984
1985 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001986 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1987 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1988 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001989 break;
1990
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001991 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001992 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001993 }
1994}
1995
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001996void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001997 LocationSummary* locations =
1998 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001999 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002000 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002001 locations->SetInAt(0, Location::RequiresRegister());
2002 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002003 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2004 break;
2005 }
2006
2007 case Primitive::kPrimLong: {
2008 locations->SetInAt(0, Location::RequiresRegister());
2009 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002010 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002011 break;
2012 }
Calin Juravle11351682014-10-23 15:38:15 +01002013 case Primitive::kPrimFloat:
2014 case Primitive::kPrimDouble: {
2015 locations->SetInAt(0, Location::RequiresFpuRegister());
2016 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002017 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002018 break;
Calin Juravle11351682014-10-23 15:38:15 +01002019 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002020 default:
Calin Juravle11351682014-10-23 15:38:15 +01002021 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002022 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002023}
2024
2025void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2026 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002027 Location out = locations->Out();
2028 Location first = locations->InAt(0);
2029 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002030 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002031 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002032 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002033 __ sub(out.AsRegister<Register>(),
2034 first.AsRegister<Register>(),
2035 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002036 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002037 __ AddConstant(out.AsRegister<Register>(),
2038 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002039 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002040 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002041 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002042 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002043
Calin Juravle11351682014-10-23 15:38:15 +01002044 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002045 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002046 __ subs(out.AsRegisterPairLow<Register>(),
2047 first.AsRegisterPairLow<Register>(),
2048 ShifterOperand(second.AsRegisterPairLow<Register>()));
2049 __ sbc(out.AsRegisterPairHigh<Register>(),
2050 first.AsRegisterPairHigh<Register>(),
2051 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002052 break;
Calin Juravle11351682014-10-23 15:38:15 +01002053 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002054
Calin Juravle11351682014-10-23 15:38:15 +01002055 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002056 __ vsubs(out.AsFpuRegister<SRegister>(),
2057 first.AsFpuRegister<SRegister>(),
2058 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002059 break;
Calin Juravle11351682014-10-23 15:38:15 +01002060 }
2061
2062 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002063 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2064 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2065 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002066 break;
2067 }
2068
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002069
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002070 default:
Calin Juravle11351682014-10-23 15:38:15 +01002071 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002072 }
2073}
2074
Calin Juravle34bacdf2014-10-07 20:23:36 +01002075void LocationsBuilderARM::VisitMul(HMul* mul) {
2076 LocationSummary* locations =
2077 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2078 switch (mul->GetResultType()) {
2079 case Primitive::kPrimInt:
2080 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002081 locations->SetInAt(0, Location::RequiresRegister());
2082 locations->SetInAt(1, Location::RequiresRegister());
2083 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002084 break;
2085 }
2086
Calin Juravleb5bfa962014-10-21 18:02:24 +01002087 case Primitive::kPrimFloat:
2088 case Primitive::kPrimDouble: {
2089 locations->SetInAt(0, Location::RequiresFpuRegister());
2090 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002091 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002092 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002093 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002094
2095 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002096 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002097 }
2098}
2099
2100void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2101 LocationSummary* locations = mul->GetLocations();
2102 Location out = locations->Out();
2103 Location first = locations->InAt(0);
2104 Location second = locations->InAt(1);
2105 switch (mul->GetResultType()) {
2106 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002107 __ mul(out.AsRegister<Register>(),
2108 first.AsRegister<Register>(),
2109 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002110 break;
2111 }
2112 case Primitive::kPrimLong: {
2113 Register out_hi = out.AsRegisterPairHigh<Register>();
2114 Register out_lo = out.AsRegisterPairLow<Register>();
2115 Register in1_hi = first.AsRegisterPairHigh<Register>();
2116 Register in1_lo = first.AsRegisterPairLow<Register>();
2117 Register in2_hi = second.AsRegisterPairHigh<Register>();
2118 Register in2_lo = second.AsRegisterPairLow<Register>();
2119
2120 // Extra checks to protect caused by the existence of R1_R2.
2121 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2122 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2123 DCHECK_NE(out_hi, in1_lo);
2124 DCHECK_NE(out_hi, in2_lo);
2125
2126 // input: in1 - 64 bits, in2 - 64 bits
2127 // output: out
2128 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2129 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2130 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2131
2132 // IP <- in1.lo * in2.hi
2133 __ mul(IP, in1_lo, in2_hi);
2134 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2135 __ mla(out_hi, in1_hi, in2_lo, IP);
2136 // out.lo <- (in1.lo * in2.lo)[31:0];
2137 __ umull(out_lo, IP, in1_lo, in2_lo);
2138 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2139 __ add(out_hi, out_hi, ShifterOperand(IP));
2140 break;
2141 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002142
2143 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002144 __ vmuls(out.AsFpuRegister<SRegister>(),
2145 first.AsFpuRegister<SRegister>(),
2146 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002147 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002148 }
2149
2150 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002151 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2152 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2153 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002154 break;
2155 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002156
2157 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002158 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002159 }
2160}
2161
Calin Juravle7c4954d2014-10-28 16:57:40 +00002162void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002163 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2164 if (div->GetResultType() == Primitive::kPrimLong) {
2165 // pLdiv runtime call.
2166 call_kind = LocationSummary::kCall;
2167 } else if (div->GetResultType() == Primitive::kPrimInt &&
2168 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2169 // pIdivmod runtime call.
2170 call_kind = LocationSummary::kCall;
2171 }
2172
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002173 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2174
Calin Juravle7c4954d2014-10-28 16:57:40 +00002175 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002176 case Primitive::kPrimInt: {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002177 if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2178 locations->SetInAt(0, Location::RequiresRegister());
2179 locations->SetInAt(1, Location::RequiresRegister());
2180 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2181 } else {
2182 InvokeRuntimeCallingConvention calling_convention;
2183 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2184 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2185 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2186 // we only need the former.
2187 locations->SetOut(Location::RegisterLocation(R0));
2188 }
Calin Juravled0d48522014-11-04 16:40:20 +00002189 break;
2190 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002191 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002192 InvokeRuntimeCallingConvention calling_convention;
2193 locations->SetInAt(0, Location::RegisterPairLocation(
2194 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2195 locations->SetInAt(1, Location::RegisterPairLocation(
2196 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002197 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002198 break;
2199 }
2200 case Primitive::kPrimFloat:
2201 case Primitive::kPrimDouble: {
2202 locations->SetInAt(0, Location::RequiresFpuRegister());
2203 locations->SetInAt(1, Location::RequiresFpuRegister());
2204 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2205 break;
2206 }
2207
2208 default:
2209 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2210 }
2211}
2212
2213void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2214 LocationSummary* locations = div->GetLocations();
2215 Location out = locations->Out();
2216 Location first = locations->InAt(0);
2217 Location second = locations->InAt(1);
2218
2219 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002220 case Primitive::kPrimInt: {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002221 if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2222 __ sdiv(out.AsRegister<Register>(),
2223 first.AsRegister<Register>(),
2224 second.AsRegister<Register>());
2225 } else {
2226 InvokeRuntimeCallingConvention calling_convention;
2227 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2228 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2229 DCHECK_EQ(R0, out.AsRegister<Register>());
2230
2231 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2232 }
Calin Juravled0d48522014-11-04 16:40:20 +00002233 break;
2234 }
2235
Calin Juravle7c4954d2014-10-28 16:57:40 +00002236 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002237 InvokeRuntimeCallingConvention calling_convention;
2238 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2239 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2240 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2241 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2242 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002243 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002244
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002245 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002246 break;
2247 }
2248
2249 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002250 __ vdivs(out.AsFpuRegister<SRegister>(),
2251 first.AsFpuRegister<SRegister>(),
2252 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002253 break;
2254 }
2255
2256 case Primitive::kPrimDouble: {
2257 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2258 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2259 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2260 break;
2261 }
2262
2263 default:
2264 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2265 }
2266}
2267
Calin Juravlebacfec32014-11-14 15:54:36 +00002268void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002269 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002270
2271 // Most remainders are implemented in the runtime.
2272 LocationSummary::CallKind call_kind = LocationSummary::kCall;
2273 if (rem->GetResultType() == Primitive::kPrimInt &&
2274 codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2275 // Have hardware divide instruction for int, do it with three instructions.
2276 call_kind = LocationSummary::kNoCall;
2277 }
2278
Calin Juravlebacfec32014-11-14 15:54:36 +00002279 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2280
Calin Juravled2ec87d2014-12-08 14:24:46 +00002281 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002282 case Primitive::kPrimInt: {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002283 if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2284 locations->SetInAt(0, Location::RequiresRegister());
2285 locations->SetInAt(1, Location::RequiresRegister());
2286 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2287 locations->AddTemp(Location::RequiresRegister());
2288 } else {
2289 InvokeRuntimeCallingConvention calling_convention;
2290 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2291 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2292 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2293 // we only need the latter.
2294 locations->SetOut(Location::RegisterLocation(R1));
2295 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002296 break;
2297 }
2298 case Primitive::kPrimLong: {
2299 InvokeRuntimeCallingConvention calling_convention;
2300 locations->SetInAt(0, Location::RegisterPairLocation(
2301 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2302 locations->SetInAt(1, Location::RegisterPairLocation(
2303 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2304 // The runtime helper puts the output in R2,R3.
2305 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2306 break;
2307 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002308 case Primitive::kPrimFloat: {
2309 InvokeRuntimeCallingConvention calling_convention;
2310 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2311 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2312 locations->SetOut(Location::FpuRegisterLocation(S0));
2313 break;
2314 }
2315
Calin Juravlebacfec32014-11-14 15:54:36 +00002316 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002317 InvokeRuntimeCallingConvention calling_convention;
2318 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2319 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2320 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2321 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2322 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002323 break;
2324 }
2325
2326 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002327 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002328 }
2329}
2330
2331void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2332 LocationSummary* locations = rem->GetLocations();
2333 Location out = locations->Out();
2334 Location first = locations->InAt(0);
2335 Location second = locations->InAt(1);
2336
Calin Juravled2ec87d2014-12-08 14:24:46 +00002337 Primitive::Type type = rem->GetResultType();
2338 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002339 case Primitive::kPrimInt: {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002340 if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2341 Register reg1 = first.AsRegister<Register>();
2342 Register reg2 = second.AsRegister<Register>();
2343 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002344
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002345 // temp = reg1 / reg2 (integer division)
2346 // temp = temp * reg2
2347 // dest = reg1 - temp
2348 __ sdiv(temp, reg1, reg2);
2349 __ mul(temp, temp, reg2);
2350 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2351 } else {
2352 InvokeRuntimeCallingConvention calling_convention;
2353 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2354 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2355 DCHECK_EQ(R1, out.AsRegister<Register>());
2356
2357 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2358 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002359 break;
2360 }
2361
2362 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002363 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002364 break;
2365 }
2366
Calin Juravled2ec87d2014-12-08 14:24:46 +00002367 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002368 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002369 break;
2370 }
2371
Calin Juravlebacfec32014-11-14 15:54:36 +00002372 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002373 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002374 break;
2375 }
2376
2377 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002378 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002379 }
2380}
2381
Calin Juravled0d48522014-11-04 16:40:20 +00002382void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2383 LocationSummary* locations =
2384 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002385 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002386 if (instruction->HasUses()) {
2387 locations->SetOut(Location::SameAsFirstInput());
2388 }
2389}
2390
2391void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2392 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2393 codegen_->AddSlowPath(slow_path);
2394
2395 LocationSummary* locations = instruction->GetLocations();
2396 Location value = locations->InAt(0);
2397
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002398 switch (instruction->GetType()) {
2399 case Primitive::kPrimInt: {
2400 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002401 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002402 __ b(slow_path->GetEntryLabel(), EQ);
2403 } else {
2404 DCHECK(value.IsConstant()) << value;
2405 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2406 __ b(slow_path->GetEntryLabel());
2407 }
2408 }
2409 break;
2410 }
2411 case Primitive::kPrimLong: {
2412 if (value.IsRegisterPair()) {
2413 __ orrs(IP,
2414 value.AsRegisterPairLow<Register>(),
2415 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2416 __ b(slow_path->GetEntryLabel(), EQ);
2417 } else {
2418 DCHECK(value.IsConstant()) << value;
2419 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2420 __ b(slow_path->GetEntryLabel());
2421 }
2422 }
2423 break;
2424 default:
2425 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2426 }
2427 }
Calin Juravled0d48522014-11-04 16:40:20 +00002428}
2429
Calin Juravle9aec02f2014-11-18 23:06:35 +00002430void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2431 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2432
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002433 LocationSummary* locations =
2434 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002435
2436 switch (op->GetResultType()) {
2437 case Primitive::kPrimInt: {
2438 locations->SetInAt(0, Location::RequiresRegister());
2439 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002440 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002441 break;
2442 }
2443 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002444 locations->SetInAt(0, Location::RequiresRegister());
2445 locations->SetInAt(1, Location::RequiresRegister());
2446 locations->AddTemp(Location::RequiresRegister());
2447 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002448 break;
2449 }
2450 default:
2451 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2452 }
2453}
2454
2455void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2456 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2457
2458 LocationSummary* locations = op->GetLocations();
2459 Location out = locations->Out();
2460 Location first = locations->InAt(0);
2461 Location second = locations->InAt(1);
2462
2463 Primitive::Type type = op->GetResultType();
2464 switch (type) {
2465 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002466 Register out_reg = out.AsRegister<Register>();
2467 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002468 // Arm doesn't mask the shift count so we need to do it ourselves.
2469 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002470 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002471 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2472 if (op->IsShl()) {
2473 __ Lsl(out_reg, first_reg, second_reg);
2474 } else if (op->IsShr()) {
2475 __ Asr(out_reg, first_reg, second_reg);
2476 } else {
2477 __ Lsr(out_reg, first_reg, second_reg);
2478 }
2479 } else {
2480 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2481 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2482 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2483 __ Mov(out_reg, first_reg);
2484 } else if (op->IsShl()) {
2485 __ Lsl(out_reg, first_reg, shift_value);
2486 } else if (op->IsShr()) {
2487 __ Asr(out_reg, first_reg, shift_value);
2488 } else {
2489 __ Lsr(out_reg, first_reg, shift_value);
2490 }
2491 }
2492 break;
2493 }
2494 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002495 Register o_h = out.AsRegisterPairHigh<Register>();
2496 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002497
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002498 Register temp = locations->GetTemp(0).AsRegister<Register>();
2499
2500 Register high = first.AsRegisterPairHigh<Register>();
2501 Register low = first.AsRegisterPairLow<Register>();
2502
2503 Register second_reg = second.AsRegister<Register>();
2504
Calin Juravle9aec02f2014-11-18 23:06:35 +00002505 if (op->IsShl()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002506 // Shift the high part
2507 __ and_(second_reg, second_reg, ShifterOperand(63));
2508 __ Lsl(o_h, high, second_reg);
2509 // Shift the low part and `or` what overflew on the high part
2510 __ rsb(temp, second_reg, ShifterOperand(32));
2511 __ Lsr(temp, low, temp);
2512 __ orr(o_h, o_h, ShifterOperand(temp));
2513 // If the shift is > 32 bits, override the high part
2514 __ subs(temp, second_reg, ShifterOperand(32));
2515 __ it(PL);
2516 __ Lsl(o_h, low, temp, false, PL);
2517 // Shift the low part
2518 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002519 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002520 // Shift the low part
2521 __ and_(second_reg, second_reg, ShifterOperand(63));
2522 __ Lsr(o_l, low, second_reg);
2523 // Shift the high part and `or` what underflew on the low part
2524 __ rsb(temp, second_reg, ShifterOperand(32));
2525 __ Lsl(temp, high, temp);
2526 __ orr(o_l, o_l, ShifterOperand(temp));
2527 // If the shift is > 32 bits, override the low part
2528 __ subs(temp, second_reg, ShifterOperand(32));
2529 __ it(PL);
2530 __ Asr(o_l, high, temp, false, PL);
2531 // Shift the high part
2532 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002533 } else {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002534 // same as Shr except we use `Lsr`s and not `Asr`s
2535 __ and_(second_reg, second_reg, ShifterOperand(63));
2536 __ Lsr(o_l, low, second_reg);
2537 __ rsb(temp, second_reg, ShifterOperand(32));
2538 __ Lsl(temp, high, temp);
2539 __ orr(o_l, o_l, ShifterOperand(temp));
2540 __ subs(temp, second_reg, ShifterOperand(32));
2541 __ it(PL);
2542 __ Lsr(o_l, high, temp, false, PL);
2543 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002544 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002545 break;
2546 }
2547 default:
2548 LOG(FATAL) << "Unexpected operation type " << type;
2549 }
2550}
2551
2552void LocationsBuilderARM::VisitShl(HShl* shl) {
2553 HandleShift(shl);
2554}
2555
2556void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2557 HandleShift(shl);
2558}
2559
2560void LocationsBuilderARM::VisitShr(HShr* shr) {
2561 HandleShift(shr);
2562}
2563
2564void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2565 HandleShift(shr);
2566}
2567
2568void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2569 HandleShift(ushr);
2570}
2571
2572void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2573 HandleShift(ushr);
2574}
2575
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002576void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002577 LocationSummary* locations =
2578 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002579 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002580 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2581 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2582 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002583}
2584
2585void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2586 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002587 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002588 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002589 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2590 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002591 instruction->GetDexPc(),
2592 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002593}
2594
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002595void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2596 LocationSummary* locations =
2597 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2598 InvokeRuntimeCallingConvention calling_convention;
2599 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002600 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002601 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002602 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002603}
2604
2605void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2606 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002607 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002608 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002609 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2610 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002611 instruction->GetDexPc(),
2612 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002613}
2614
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002615void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002616 LocationSummary* locations =
2617 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002618 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2619 if (location.IsStackSlot()) {
2620 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2621 } else if (location.IsDoubleStackSlot()) {
2622 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002623 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002624 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002625}
2626
2627void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002628 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002629 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002630}
2631
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002632void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002633 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002634 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002635 locations->SetInAt(0, Location::RequiresRegister());
2636 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002637}
2638
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002639void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2640 LocationSummary* locations = not_->GetLocations();
2641 Location out = locations->Out();
2642 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002643 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002644 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002645 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002646 break;
2647
2648 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002649 __ mvn(out.AsRegisterPairLow<Register>(),
2650 ShifterOperand(in.AsRegisterPairLow<Register>()));
2651 __ mvn(out.AsRegisterPairHigh<Register>(),
2652 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002653 break;
2654
2655 default:
2656 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2657 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002658}
2659
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002660void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002661 LocationSummary* locations =
2662 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002663 switch (compare->InputAt(0)->GetType()) {
2664 case Primitive::kPrimLong: {
2665 locations->SetInAt(0, Location::RequiresRegister());
2666 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002667 // Output overlaps because it is written before doing the low comparison.
2668 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002669 break;
2670 }
2671 case Primitive::kPrimFloat:
2672 case Primitive::kPrimDouble: {
2673 locations->SetInAt(0, Location::RequiresFpuRegister());
2674 locations->SetInAt(1, Location::RequiresFpuRegister());
2675 locations->SetOut(Location::RequiresRegister());
2676 break;
2677 }
2678 default:
2679 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2680 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002681}
2682
2683void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002684 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002685 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002686 Location left = locations->InAt(0);
2687 Location right = locations->InAt(1);
2688
2689 Label less, greater, done;
2690 Primitive::Type type = compare->InputAt(0)->GetType();
2691 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002692 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002693 __ cmp(left.AsRegisterPairHigh<Register>(),
2694 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002695 __ b(&less, LT);
2696 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002697 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2698 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002699 __ cmp(left.AsRegisterPairLow<Register>(),
2700 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002701 break;
2702 }
2703 case Primitive::kPrimFloat:
2704 case Primitive::kPrimDouble: {
2705 __ LoadImmediate(out, 0);
2706 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002707 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002708 } else {
2709 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2710 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2711 }
2712 __ vmstat(); // transfer FP status register to ARM APSR.
2713 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002714 break;
2715 }
2716 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002717 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002718 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002719 __ b(&done, EQ);
2720 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2721
2722 __ Bind(&greater);
2723 __ LoadImmediate(out, 1);
2724 __ b(&done);
2725
2726 __ Bind(&less);
2727 __ LoadImmediate(out, -1);
2728
2729 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002730}
2731
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002732void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002733 LocationSummary* locations =
2734 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002735 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2736 locations->SetInAt(i, Location::Any());
2737 }
2738 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002739}
2740
2741void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002742 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002743 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002744}
2745
Calin Juravle52c48962014-12-16 17:02:57 +00002746void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2747 // TODO (ported from quick): revisit Arm barrier kinds
2748 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2749 switch (kind) {
2750 case MemBarrierKind::kAnyStore:
2751 case MemBarrierKind::kLoadAny:
2752 case MemBarrierKind::kAnyAny: {
2753 flavour = DmbOptions::ISH;
2754 break;
2755 }
2756 case MemBarrierKind::kStoreStore: {
2757 flavour = DmbOptions::ISHST;
2758 break;
2759 }
2760 default:
2761 LOG(FATAL) << "Unexpected memory barrier " << kind;
2762 }
2763 __ dmb(flavour);
2764}
2765
2766void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2767 uint32_t offset,
2768 Register out_lo,
2769 Register out_hi) {
2770 if (offset != 0) {
2771 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002772 __ add(IP, addr, ShifterOperand(out_lo));
2773 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002774 }
2775 __ ldrexd(out_lo, out_hi, addr);
2776}
2777
2778void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2779 uint32_t offset,
2780 Register value_lo,
2781 Register value_hi,
2782 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002783 Register temp2,
2784 HInstruction* instruction) {
Calin Juravle52c48962014-12-16 17:02:57 +00002785 Label fail;
2786 if (offset != 0) {
2787 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002788 __ add(IP, addr, ShifterOperand(temp1));
2789 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002790 }
2791 __ Bind(&fail);
2792 // We need a load followed by store. (The address used in a STREX instruction must
2793 // be the same as the address in the most recently executed LDREX instruction.)
2794 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002795 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002796 __ strexd(temp1, value_lo, value_hi, addr);
2797 __ cmp(temp1, ShifterOperand(0));
2798 __ b(&fail, NE);
2799}
2800
2801void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2802 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2803
Nicolas Geoffray39468442014-09-02 15:17:15 +01002804 LocationSummary* locations =
2805 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002806 locations->SetInAt(0, Location::RequiresRegister());
2807 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002808
Calin Juravle34166012014-12-19 17:22:29 +00002809
Calin Juravle52c48962014-12-16 17:02:57 +00002810 Primitive::Type field_type = field_info.GetFieldType();
2811 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002812 bool generate_volatile = field_info.IsVolatile()
2813 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002814 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002815 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002816 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2817 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002818 locations->AddTemp(Location::RequiresRegister());
2819 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002820 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002821 // Arm encoding have some additional constraints for ldrexd/strexd:
2822 // - registers need to be consecutive
2823 // - the first register should be even but not R14.
2824 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2825 // enable Arm encoding.
2826 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2827
2828 locations->AddTemp(Location::RequiresRegister());
2829 locations->AddTemp(Location::RequiresRegister());
2830 if (field_type == Primitive::kPrimDouble) {
2831 // For doubles we need two more registers to copy the value.
2832 locations->AddTemp(Location::RegisterLocation(R2));
2833 locations->AddTemp(Location::RegisterLocation(R3));
2834 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002835 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002836}
2837
Calin Juravle52c48962014-12-16 17:02:57 +00002838void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2839 const FieldInfo& field_info) {
2840 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2841
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002842 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002843 Register base = locations->InAt(0).AsRegister<Register>();
2844 Location value = locations->InAt(1);
2845
2846 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002847 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002848 Primitive::Type field_type = field_info.GetFieldType();
2849 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2850
2851 if (is_volatile) {
2852 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2853 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002854
2855 switch (field_type) {
2856 case Primitive::kPrimBoolean:
2857 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002858 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002859 break;
2860 }
2861
2862 case Primitive::kPrimShort:
2863 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002864 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002865 break;
2866 }
2867
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002868 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002869 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00002870 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002871 break;
2872 }
2873
2874 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002875 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002876 GenerateWideAtomicStore(base, offset,
2877 value.AsRegisterPairLow<Register>(),
2878 value.AsRegisterPairHigh<Register>(),
2879 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002880 locations->GetTemp(1).AsRegister<Register>(),
2881 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002882 } else {
2883 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002884 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002885 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002886 break;
2887 }
2888
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002889 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002890 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002891 break;
2892 }
2893
2894 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002895 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002896 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002897 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2898 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2899
2900 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2901
2902 GenerateWideAtomicStore(base, offset,
2903 value_reg_lo,
2904 value_reg_hi,
2905 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00002906 locations->GetTemp(3).AsRegister<Register>(),
2907 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002908 } else {
2909 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00002910 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002911 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002912 break;
2913 }
2914
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002915 case Primitive::kPrimVoid:
2916 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002917 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002918 }
Calin Juravle52c48962014-12-16 17:02:57 +00002919
Calin Juravle77520bc2015-01-12 18:45:46 +00002920 // Longs and doubles are handled in the switch.
2921 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
2922 codegen_->MaybeRecordImplicitNullCheck(instruction);
2923 }
2924
2925 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
2926 Register temp = locations->GetTemp(0).AsRegister<Register>();
2927 Register card = locations->GetTemp(1).AsRegister<Register>();
2928 codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>());
2929 }
2930
Calin Juravle52c48962014-12-16 17:02:57 +00002931 if (is_volatile) {
2932 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2933 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002934}
2935
Calin Juravle52c48962014-12-16 17:02:57 +00002936void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2937 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002938 LocationSummary* locations =
2939 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002940 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002941
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002942 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00002943 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002944 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002945 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
2946 locations->SetOut(Location::RequiresRegister(),
2947 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
2948 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00002949 // Arm encoding have some additional constraints for ldrexd/strexd:
2950 // - registers need to be consecutive
2951 // - the first register should be even but not R14.
2952 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2953 // enable Arm encoding.
2954 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2955 locations->AddTemp(Location::RequiresRegister());
2956 locations->AddTemp(Location::RequiresRegister());
2957 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002958}
2959
Calin Juravle52c48962014-12-16 17:02:57 +00002960void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2961 const FieldInfo& field_info) {
2962 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002963
Calin Juravle52c48962014-12-16 17:02:57 +00002964 LocationSummary* locations = instruction->GetLocations();
2965 Register base = locations->InAt(0).AsRegister<Register>();
2966 Location out = locations->Out();
2967 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002968 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002969 Primitive::Type field_type = field_info.GetFieldType();
2970 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2971
2972 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002973 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002974 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002975 break;
2976 }
2977
2978 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002979 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002980 break;
2981 }
2982
2983 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002984 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002985 break;
2986 }
2987
2988 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002989 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002990 break;
2991 }
2992
2993 case Primitive::kPrimInt:
2994 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002995 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002996 break;
2997 }
2998
2999 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003000 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003001 GenerateWideAtomicLoad(base, offset,
3002 out.AsRegisterPairLow<Register>(),
3003 out.AsRegisterPairHigh<Register>());
3004 } else {
3005 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3006 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003007 break;
3008 }
3009
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003010 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003011 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003012 break;
3013 }
3014
3015 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003016 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003017 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003018 Register lo = locations->GetTemp(0).AsRegister<Register>();
3019 Register hi = locations->GetTemp(1).AsRegister<Register>();
3020 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003021 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003022 __ vmovdrr(out_reg, lo, hi);
3023 } else {
3024 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003025 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003026 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003027 break;
3028 }
3029
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003030 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003031 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003032 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003033 }
Calin Juravle52c48962014-12-16 17:02:57 +00003034
Calin Juravle77520bc2015-01-12 18:45:46 +00003035 // Doubles are handled in the switch.
3036 if (field_type != Primitive::kPrimDouble) {
3037 codegen_->MaybeRecordImplicitNullCheck(instruction);
3038 }
3039
Calin Juravle52c48962014-12-16 17:02:57 +00003040 if (is_volatile) {
3041 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3042 }
3043}
3044
3045void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3046 HandleFieldSet(instruction, instruction->GetFieldInfo());
3047}
3048
3049void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3050 HandleFieldSet(instruction, instruction->GetFieldInfo());
3051}
3052
3053void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3054 HandleFieldGet(instruction, instruction->GetFieldInfo());
3055}
3056
3057void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3058 HandleFieldGet(instruction, instruction->GetFieldInfo());
3059}
3060
3061void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3062 HandleFieldGet(instruction, instruction->GetFieldInfo());
3063}
3064
3065void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3066 HandleFieldGet(instruction, instruction->GetFieldInfo());
3067}
3068
3069void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3070 HandleFieldSet(instruction, instruction->GetFieldInfo());
3071}
3072
3073void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3074 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003075}
3076
3077void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003078 LocationSummary* locations =
3079 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003080 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003081 if (instruction->HasUses()) {
3082 locations->SetOut(Location::SameAsFirstInput());
3083 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003084}
3085
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003086void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003087 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3088 return;
3089 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003090 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003091
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003092 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3093 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3094}
3095
3096void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003097 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003098 codegen_->AddSlowPath(slow_path);
3099
3100 LocationSummary* locations = instruction->GetLocations();
3101 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003102
Calin Juravle77520bc2015-01-12 18:45:46 +00003103 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
3104 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003105}
3106
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003107void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3108 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3109 GenerateImplicitNullCheck(instruction);
3110 } else {
3111 GenerateExplicitNullCheck(instruction);
3112 }
3113}
3114
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003115void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003116 LocationSummary* locations =
3117 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003118 locations->SetInAt(0, Location::RequiresRegister());
3119 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3120 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003121}
3122
3123void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3124 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003125 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003126 Location index = locations->InAt(1);
3127
3128 switch (instruction->GetType()) {
3129 case Primitive::kPrimBoolean: {
3130 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003131 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003132 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003133 size_t offset =
3134 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003135 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3136 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003137 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003138 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3139 }
3140 break;
3141 }
3142
3143 case Primitive::kPrimByte: {
3144 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003145 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003146 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003147 size_t offset =
3148 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003149 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3150 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003151 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003152 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3153 }
3154 break;
3155 }
3156
3157 case Primitive::kPrimShort: {
3158 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003159 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003160 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003161 size_t offset =
3162 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003163 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3164 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003165 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003166 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3167 }
3168 break;
3169 }
3170
3171 case Primitive::kPrimChar: {
3172 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003173 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003174 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003175 size_t offset =
3176 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003177 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3178 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003179 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003180 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3181 }
3182 break;
3183 }
3184
3185 case Primitive::kPrimInt:
3186 case Primitive::kPrimNot: {
3187 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3188 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003189 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003190 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003191 size_t offset =
3192 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003193 __ LoadFromOffset(kLoadWord, out, obj, offset);
3194 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003195 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003196 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3197 }
3198 break;
3199 }
3200
3201 case Primitive::kPrimLong: {
3202 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003203 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003204 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003205 size_t offset =
3206 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003207 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003208 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003209 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003210 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003211 }
3212 break;
3213 }
3214
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003215 case Primitive::kPrimFloat: {
3216 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3217 Location out = locations->Out();
3218 DCHECK(out.IsFpuRegister());
3219 if (index.IsConstant()) {
3220 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3221 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3222 } else {
3223 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3224 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3225 }
3226 break;
3227 }
3228
3229 case Primitive::kPrimDouble: {
3230 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3231 Location out = locations->Out();
3232 DCHECK(out.IsFpuRegisterPair());
3233 if (index.IsConstant()) {
3234 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3235 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3236 } else {
3237 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3238 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3239 }
3240 break;
3241 }
3242
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003243 case Primitive::kPrimVoid:
3244 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003245 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003246 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003247 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003248}
3249
3250void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003251 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003252
3253 bool needs_write_barrier =
3254 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3255 bool needs_runtime_call = instruction->NeedsTypeCheck();
3256
Nicolas Geoffray39468442014-09-02 15:17:15 +01003257 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003258 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3259 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003260 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003261 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3262 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3263 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003264 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003265 locations->SetInAt(0, Location::RequiresRegister());
3266 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3267 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003268
3269 if (needs_write_barrier) {
3270 // Temporary registers for the write barrier.
3271 locations->AddTemp(Location::RequiresRegister());
3272 locations->AddTemp(Location::RequiresRegister());
3273 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003274 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003275}
3276
3277void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3278 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003279 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003280 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003281 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003282 bool needs_runtime_call = locations->WillCall();
3283 bool needs_write_barrier =
3284 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003285
3286 switch (value_type) {
3287 case Primitive::kPrimBoolean:
3288 case Primitive::kPrimByte: {
3289 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003290 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003291 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003292 size_t offset =
3293 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003294 __ StoreToOffset(kStoreByte, value, obj, offset);
3295 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003296 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003297 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3298 }
3299 break;
3300 }
3301
3302 case Primitive::kPrimShort:
3303 case Primitive::kPrimChar: {
3304 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003305 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003306 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003307 size_t offset =
3308 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003309 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3310 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003311 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003312 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3313 }
3314 break;
3315 }
3316
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003317 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003318 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003319 if (!needs_runtime_call) {
3320 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003321 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003322 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003323 size_t offset =
3324 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003325 __ StoreToOffset(kStoreWord, value, obj, offset);
3326 } else {
3327 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003328 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003329 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3330 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003331 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003332 if (needs_write_barrier) {
3333 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003334 Register temp = locations->GetTemp(0).AsRegister<Register>();
3335 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003336 codegen_->MarkGCCard(temp, card, obj, value);
3337 }
3338 } else {
3339 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003340 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3341 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003342 instruction->GetDexPc(),
3343 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003344 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003345 break;
3346 }
3347
3348 case Primitive::kPrimLong: {
3349 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003350 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003351 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003352 size_t offset =
3353 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003354 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003355 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003356 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003357 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003358 }
3359 break;
3360 }
3361
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003362 case Primitive::kPrimFloat: {
3363 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3364 Location value = locations->InAt(2);
3365 DCHECK(value.IsFpuRegister());
3366 if (index.IsConstant()) {
3367 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3368 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3369 } else {
3370 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3371 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3372 }
3373 break;
3374 }
3375
3376 case Primitive::kPrimDouble: {
3377 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3378 Location value = locations->InAt(2);
3379 DCHECK(value.IsFpuRegisterPair());
3380 if (index.IsConstant()) {
3381 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3382 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3383 } else {
3384 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3385 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3386 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003387
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003388 break;
3389 }
3390
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003391 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003392 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003393 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003394 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003395
3396 // Ints and objects are handled in the switch.
3397 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3398 codegen_->MaybeRecordImplicitNullCheck(instruction);
3399 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003400}
3401
3402void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003403 LocationSummary* locations =
3404 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003405 locations->SetInAt(0, Location::RequiresRegister());
3406 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003407}
3408
3409void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3410 LocationSummary* locations = instruction->GetLocations();
3411 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003412 Register obj = locations->InAt(0).AsRegister<Register>();
3413 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003414 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003415 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003416}
3417
3418void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003419 LocationSummary* locations =
3420 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003421 locations->SetInAt(0, Location::RequiresRegister());
3422 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003423 if (instruction->HasUses()) {
3424 locations->SetOut(Location::SameAsFirstInput());
3425 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003426}
3427
3428void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3429 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003430 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003431 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003432 codegen_->AddSlowPath(slow_path);
3433
Roland Levillain271ab9c2014-11-27 15:23:57 +00003434 Register index = locations->InAt(0).AsRegister<Register>();
3435 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003436
3437 __ cmp(index, ShifterOperand(length));
3438 __ b(slow_path->GetEntryLabel(), CS);
3439}
3440
3441void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3442 Label is_null;
3443 __ CompareAndBranchIfZero(value, &is_null);
3444 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3445 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3446 __ strb(card, Address(card, temp));
3447 __ Bind(&is_null);
3448}
3449
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003450void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3451 temp->SetLocations(nullptr);
3452}
3453
3454void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3455 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003456 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003457}
3458
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003459void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003460 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003461 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003462}
3463
3464void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003465 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3466}
3467
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003468void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3469 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3470}
3471
3472void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003473 HBasicBlock* block = instruction->GetBlock();
3474 if (block->GetLoopInformation() != nullptr) {
3475 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3476 // The back edge will generate the suspend check.
3477 return;
3478 }
3479 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3480 // The goto will generate the suspend check.
3481 return;
3482 }
3483 GenerateSuspendCheck(instruction, nullptr);
3484}
3485
3486void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3487 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003488 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003489 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003490 codegen_->AddSlowPath(slow_path);
3491
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003492 __ LoadFromOffset(
3493 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3494 __ cmp(IP, ShifterOperand(0));
3495 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003496 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003497 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003498 __ Bind(slow_path->GetReturnLabel());
3499 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003500 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003501 __ b(slow_path->GetEntryLabel());
3502 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003503}
3504
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003505ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3506 return codegen_->GetAssembler();
3507}
3508
3509void ParallelMoveResolverARM::EmitMove(size_t index) {
3510 MoveOperands* move = moves_.Get(index);
3511 Location source = move->GetSource();
3512 Location destination = move->GetDestination();
3513
3514 if (source.IsRegister()) {
3515 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003516 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003517 } else {
3518 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003519 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003520 SP, destination.GetStackIndex());
3521 }
3522 } else if (source.IsStackSlot()) {
3523 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003524 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003525 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003526 } else if (destination.IsFpuRegister()) {
3527 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003528 } else {
3529 DCHECK(destination.IsStackSlot());
3530 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3531 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3532 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003533 } else if (source.IsFpuRegister()) {
3534 if (destination.IsFpuRegister()) {
3535 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003536 } else {
3537 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003538 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3539 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003540 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003541 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003542 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3543 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003544 } else if (destination.IsRegisterPair()) {
3545 DCHECK(ExpectedPairLayout(destination));
3546 __ LoadFromOffset(
3547 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3548 } else {
3549 DCHECK(destination.IsFpuRegisterPair()) << destination;
3550 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3551 SP,
3552 source.GetStackIndex());
3553 }
3554 } else if (source.IsRegisterPair()) {
3555 if (destination.IsRegisterPair()) {
3556 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3557 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3558 } else {
3559 DCHECK(destination.IsDoubleStackSlot()) << destination;
3560 DCHECK(ExpectedPairLayout(source));
3561 __ StoreToOffset(
3562 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3563 }
3564 } else if (source.IsFpuRegisterPair()) {
3565 if (destination.IsFpuRegisterPair()) {
3566 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3567 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3568 } else {
3569 DCHECK(destination.IsDoubleStackSlot()) << destination;
3570 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3571 SP,
3572 destination.GetStackIndex());
3573 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003574 } else {
3575 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003576 HConstant* constant = source.GetConstant();
3577 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3578 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003579 if (destination.IsRegister()) {
3580 __ LoadImmediate(destination.AsRegister<Register>(), value);
3581 } else {
3582 DCHECK(destination.IsStackSlot());
3583 __ LoadImmediate(IP, value);
3584 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3585 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003586 } else if (constant->IsLongConstant()) {
3587 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003588 if (destination.IsRegisterPair()) {
3589 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3590 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003591 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003592 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003593 __ LoadImmediate(IP, Low32Bits(value));
3594 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3595 __ LoadImmediate(IP, High32Bits(value));
3596 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3597 }
3598 } else if (constant->IsDoubleConstant()) {
3599 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003600 if (destination.IsFpuRegisterPair()) {
3601 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003602 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003603 DCHECK(destination.IsDoubleStackSlot()) << destination;
3604 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003605 __ LoadImmediate(IP, Low32Bits(int_value));
3606 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3607 __ LoadImmediate(IP, High32Bits(int_value));
3608 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3609 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003610 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003611 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003612 float value = constant->AsFloatConstant()->GetValue();
3613 if (destination.IsFpuRegister()) {
3614 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3615 } else {
3616 DCHECK(destination.IsStackSlot());
3617 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3618 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3619 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003620 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003621 }
3622}
3623
3624void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3625 __ Mov(IP, reg);
3626 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3627 __ StoreToOffset(kStoreWord, IP, SP, mem);
3628}
3629
3630void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3631 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3632 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3633 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3634 SP, mem1 + stack_offset);
3635 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3636 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3637 SP, mem2 + stack_offset);
3638 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3639}
3640
3641void ParallelMoveResolverARM::EmitSwap(size_t index) {
3642 MoveOperands* move = moves_.Get(index);
3643 Location source = move->GetSource();
3644 Location destination = move->GetDestination();
3645
3646 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003647 DCHECK_NE(source.AsRegister<Register>(), IP);
3648 DCHECK_NE(destination.AsRegister<Register>(), IP);
3649 __ Mov(IP, source.AsRegister<Register>());
3650 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3651 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003652 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003653 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003654 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003655 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003656 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3657 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003658 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003659 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003660 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003661 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003662 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003663 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003664 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003665 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003666 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3667 destination.AsRegisterPairHigh<Register>(),
3668 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003669 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003670 Register low_reg = source.IsRegisterPair()
3671 ? source.AsRegisterPairLow<Register>()
3672 : destination.AsRegisterPairLow<Register>();
3673 int mem = source.IsRegisterPair()
3674 ? destination.GetStackIndex()
3675 : source.GetStackIndex();
3676 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003677 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003678 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003679 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003680 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003681 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3682 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003683 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003684 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003685 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003686 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3687 DRegister reg = source.IsFpuRegisterPair()
3688 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3689 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3690 int mem = source.IsFpuRegisterPair()
3691 ? destination.GetStackIndex()
3692 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003693 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003694 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003695 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003696 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3697 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3698 : destination.AsFpuRegister<SRegister>();
3699 int mem = source.IsFpuRegister()
3700 ? destination.GetStackIndex()
3701 : source.GetStackIndex();
3702
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003703 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003704 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003705 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003706 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003707 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3708 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003709 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003710 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003711 }
3712}
3713
3714void ParallelMoveResolverARM::SpillScratch(int reg) {
3715 __ Push(static_cast<Register>(reg));
3716}
3717
3718void ParallelMoveResolverARM::RestoreScratch(int reg) {
3719 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003720}
3721
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003722void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003723 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3724 ? LocationSummary::kCallOnSlowPath
3725 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003726 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003727 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003728 locations->SetOut(Location::RequiresRegister());
3729}
3730
3731void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003732 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003733 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003734 DCHECK(!cls->CanCallRuntime());
3735 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003736 codegen_->LoadCurrentMethod(out);
3737 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3738 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003739 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003740 codegen_->LoadCurrentMethod(out);
3741 __ LoadFromOffset(
3742 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3743 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003744
3745 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3746 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3747 codegen_->AddSlowPath(slow_path);
3748 __ cmp(out, ShifterOperand(0));
3749 __ b(slow_path->GetEntryLabel(), EQ);
3750 if (cls->MustGenerateClinitCheck()) {
3751 GenerateClassInitializationCheck(slow_path, out);
3752 } else {
3753 __ Bind(slow_path->GetExitLabel());
3754 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003755 }
3756}
3757
3758void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3759 LocationSummary* locations =
3760 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3761 locations->SetInAt(0, Location::RequiresRegister());
3762 if (check->HasUses()) {
3763 locations->SetOut(Location::SameAsFirstInput());
3764 }
3765}
3766
3767void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003768 // We assume the class is not null.
3769 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3770 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003771 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003772 GenerateClassInitializationCheck(slow_path,
3773 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003774}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003775
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003776void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3777 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003778 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3779 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3780 __ b(slow_path->GetEntryLabel(), LT);
3781 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3782 // properly. Therefore, we do a memory fence.
3783 __ dmb(ISH);
3784 __ Bind(slow_path->GetExitLabel());
3785}
3786
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003787void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3788 LocationSummary* locations =
3789 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3790 locations->SetOut(Location::RequiresRegister());
3791}
3792
3793void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3794 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3795 codegen_->AddSlowPath(slow_path);
3796
Roland Levillain271ab9c2014-11-27 15:23:57 +00003797 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003798 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003799 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3800 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003801 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3802 __ cmp(out, ShifterOperand(0));
3803 __ b(slow_path->GetEntryLabel(), EQ);
3804 __ Bind(slow_path->GetExitLabel());
3805}
3806
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003807void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3808 LocationSummary* locations =
3809 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3810 locations->SetOut(Location::RequiresRegister());
3811}
3812
3813void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003814 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003815 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3816 __ LoadFromOffset(kLoadWord, out, TR, offset);
3817 __ LoadImmediate(IP, 0);
3818 __ StoreToOffset(kStoreWord, IP, TR, offset);
3819}
3820
3821void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3822 LocationSummary* locations =
3823 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3824 InvokeRuntimeCallingConvention calling_convention;
3825 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3826}
3827
3828void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3829 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003830 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003831}
3832
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003833void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003834 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3835 ? LocationSummary::kNoCall
3836 : LocationSummary::kCallOnSlowPath;
3837 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3838 locations->SetInAt(0, Location::RequiresRegister());
3839 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003840 // The out register is used as a temporary, so it overlaps with the inputs.
3841 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003842}
3843
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003844void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003845 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003846 Register obj = locations->InAt(0).AsRegister<Register>();
3847 Register cls = locations->InAt(1).AsRegister<Register>();
3848 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003849 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3850 Label done, zero;
3851 SlowPathCodeARM* slow_path = nullptr;
3852
3853 // Return 0 if `obj` is null.
3854 // TODO: avoid this check if we know obj is not null.
3855 __ cmp(obj, ShifterOperand(0));
3856 __ b(&zero, EQ);
3857 // Compare the class of `obj` with `cls`.
3858 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3859 __ cmp(out, ShifterOperand(cls));
3860 if (instruction->IsClassFinal()) {
3861 // Classes must be equal for the instanceof to succeed.
3862 __ b(&zero, NE);
3863 __ LoadImmediate(out, 1);
3864 __ b(&done);
3865 } else {
3866 // If the classes are not equal, we go into a slow path.
3867 DCHECK(locations->OnlyCallsOnSlowPath());
3868 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003869 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003870 codegen_->AddSlowPath(slow_path);
3871 __ b(slow_path->GetEntryLabel(), NE);
3872 __ LoadImmediate(out, 1);
3873 __ b(&done);
3874 }
3875 __ Bind(&zero);
3876 __ LoadImmediate(out, 0);
3877 if (slow_path != nullptr) {
3878 __ Bind(slow_path->GetExitLabel());
3879 }
3880 __ Bind(&done);
3881}
3882
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003883void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3884 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3885 instruction, LocationSummary::kCallOnSlowPath);
3886 locations->SetInAt(0, Location::RequiresRegister());
3887 locations->SetInAt(1, Location::RequiresRegister());
3888 locations->AddTemp(Location::RequiresRegister());
3889}
3890
3891void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3892 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003893 Register obj = locations->InAt(0).AsRegister<Register>();
3894 Register cls = locations->InAt(1).AsRegister<Register>();
3895 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003896 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3897
3898 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3899 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3900 codegen_->AddSlowPath(slow_path);
3901
3902 // TODO: avoid this check if we know obj is not null.
3903 __ cmp(obj, ShifterOperand(0));
3904 __ b(slow_path->GetExitLabel(), EQ);
3905 // Compare the class of `obj` with `cls`.
3906 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3907 __ cmp(temp, ShifterOperand(cls));
3908 __ b(slow_path->GetEntryLabel(), NE);
3909 __ Bind(slow_path->GetExitLabel());
3910}
3911
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003912void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3913 LocationSummary* locations =
3914 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3915 InvokeRuntimeCallingConvention calling_convention;
3916 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3917}
3918
3919void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3920 codegen_->InvokeRuntime(instruction->IsEnter()
3921 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3922 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003923 instruction->GetDexPc(),
3924 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003925}
3926
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003927void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3928void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3929void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3930
3931void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3932 LocationSummary* locations =
3933 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3934 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3935 || instruction->GetResultType() == Primitive::kPrimLong);
3936 locations->SetInAt(0, Location::RequiresRegister());
3937 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003938 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003939}
3940
3941void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3942 HandleBitwiseOperation(instruction);
3943}
3944
3945void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3946 HandleBitwiseOperation(instruction);
3947}
3948
3949void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3950 HandleBitwiseOperation(instruction);
3951}
3952
3953void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3954 LocationSummary* locations = instruction->GetLocations();
3955
3956 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003957 Register first = locations->InAt(0).AsRegister<Register>();
3958 Register second = locations->InAt(1).AsRegister<Register>();
3959 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003960 if (instruction->IsAnd()) {
3961 __ and_(out, first, ShifterOperand(second));
3962 } else if (instruction->IsOr()) {
3963 __ orr(out, first, ShifterOperand(second));
3964 } else {
3965 DCHECK(instruction->IsXor());
3966 __ eor(out, first, ShifterOperand(second));
3967 }
3968 } else {
3969 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3970 Location first = locations->InAt(0);
3971 Location second = locations->InAt(1);
3972 Location out = locations->Out();
3973 if (instruction->IsAnd()) {
3974 __ and_(out.AsRegisterPairLow<Register>(),
3975 first.AsRegisterPairLow<Register>(),
3976 ShifterOperand(second.AsRegisterPairLow<Register>()));
3977 __ and_(out.AsRegisterPairHigh<Register>(),
3978 first.AsRegisterPairHigh<Register>(),
3979 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3980 } else if (instruction->IsOr()) {
3981 __ orr(out.AsRegisterPairLow<Register>(),
3982 first.AsRegisterPairLow<Register>(),
3983 ShifterOperand(second.AsRegisterPairLow<Register>()));
3984 __ orr(out.AsRegisterPairHigh<Register>(),
3985 first.AsRegisterPairHigh<Register>(),
3986 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3987 } else {
3988 DCHECK(instruction->IsXor());
3989 __ eor(out.AsRegisterPairLow<Register>(),
3990 first.AsRegisterPairLow<Register>(),
3991 ShifterOperand(second.AsRegisterPairLow<Register>()));
3992 __ eor(out.AsRegisterPairHigh<Register>(),
3993 first.AsRegisterPairHigh<Register>(),
3994 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3995 }
3996 }
3997}
3998
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08003999void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
4000 DCHECK_EQ(temp, kArtMethodRegister);
4001
4002 // TODO: Implement all kinds of calls:
4003 // 1) boot -> boot
4004 // 2) app -> boot
4005 // 3) app -> app
4006 //
4007 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4008
4009 // temp = method;
4010 LoadCurrentMethod(temp);
4011 if (!invoke->IsRecursive()) {
4012 // temp = temp->dex_cache_resolved_methods_;
4013 __ LoadFromOffset(
4014 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
4015 // temp = temp[index_in_cache]
4016 __ LoadFromOffset(
4017 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4018 // LR = temp[offset_of_quick_compiled_code]
4019 __ LoadFromOffset(kLoadWord, LR, temp,
4020 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4021 kArmWordSize).Int32Value());
4022 // LR()
4023 __ blx(LR);
4024 } else {
4025 __ bl(GetFrameEntryLabel());
4026 }
4027
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004028 DCHECK(!IsLeafMethod());
4029}
4030
Calin Juravleb1498f62015-02-16 13:13:29 +00004031void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4032 // Nothing to do, this should be removed during prepare for register allocator.
4033 UNUSED(instruction);
4034 LOG(FATAL) << "Unreachable";
4035}
4036
4037void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4038 // Nothing to do, this should be removed during prepare for register allocator.
4039 UNUSED(instruction);
4040 LOG(FATAL) << "Unreachable";
4041}
4042
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004043} // namespace arm
4044} // namespace art