blob: 69f9ca468652a1a997b7d67b9ce8b20979b47f7c [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"
Mathieu Chartiere401d142015-04-22 13:56:20 -070020#include "art_method.h"
Zheng Xuc6667102015-05-15 16:08:45 +080021#include "code_generator_utils.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070022#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010023#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080024#include "intrinsics.h"
25#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070026#include "mirror/array-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070027#include "mirror/class-inl.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070028#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010029#include "utils/arm/assembler_arm.h"
30#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000031#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010032#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000033
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000034namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010035
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000036namespace arm {
37
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +000038static bool ExpectedPairLayout(Location location) {
39 // We expected this for both core and fpu register pairs.
40 return ((location.low() & 1) == 0) && (location.low() + 1 == location.high());
41}
42
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010043static constexpr int kCurrentMethodStackOffset = 0;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +010044static constexpr Register kMethodRegisterArgument = R0;
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010045
Nicolas Geoffray4dee6362015-01-23 18:23:14 +000046// We unconditionally allocate R5 to ensure we can do long operations
47// with baseline.
48static constexpr Register kCoreSavedRegisterForBaseline = R5;
49static constexpr Register kCoreCalleeSaves[] =
50 { R5, R6, R7, R8, R10, R11, PC };
51static constexpr SRegister kFpuCalleeSaves[] =
52 { S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, S30, S31 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010053
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +000054// D31 cannot be split into two S registers, and the register allocator only works on
55// S registers. Therefore there is no need to block it.
56static constexpr DRegister DTMP = D31;
57
Roland Levillain62a46b22015-06-01 18:24:13 +010058#define __ down_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010059#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010060
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010061class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010062 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010063 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010064
Alexandre Rames67555f72014-11-18 10:55:16 +000065 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010066 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010067 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010068 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000069 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010070 }
71
72 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010073 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010074 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
75};
76
Calin Juravled0d48522014-11-04 16:40:20 +000077class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
78 public:
79 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
80
Alexandre Rames67555f72014-11-18 10:55:16 +000081 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +000082 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
83 __ Bind(GetEntryLabel());
84 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +000085 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Calin Juravled0d48522014-11-04 16:40:20 +000086 }
87
88 private:
89 HDivZeroCheck* const instruction_;
90 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
91};
92
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010093class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000094 public:
Alexandre Rames67555f72014-11-18 10:55:16 +000095 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +010096 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +000097
Alexandre Rames67555f72014-11-18 10:55:16 +000098 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010099 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000100 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000101 SaveLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100102 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000103 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000104 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100105 if (successor_ == nullptr) {
106 __ b(GetReturnLabel());
107 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100108 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100109 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000110 }
111
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100112 Label* GetReturnLabel() {
113 DCHECK(successor_ == nullptr);
114 return &return_label_;
115 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000116
Nicolas Geoffraydb216f42015-05-05 17:02:20 +0100117 HBasicBlock* GetSuccessor() const {
118 return successor_;
119 }
120
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000121 private:
122 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100123 // If not null, the block to branch to after the suspend check.
124 HBasicBlock* const successor_;
125
126 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000127 Label return_label_;
128
129 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
130};
131
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100132class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100133 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100134 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
135 Location index_location,
136 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100137 : instruction_(instruction),
138 index_location_(index_location),
139 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100140
Alexandre Rames67555f72014-11-18 10:55:16 +0000141 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100142 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100143 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000144 // We're moving two locations to locations that could overlap, so we need a parallel
145 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100146 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000147 codegen->EmitParallelMoves(
148 index_location_,
149 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100150 Primitive::kPrimInt,
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000151 length_location_,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100152 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
153 Primitive::kPrimInt);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100154 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000155 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100156 }
157
158 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100159 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100160 const Location index_location_;
161 const Location length_location_;
162
163 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
164};
165
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000166class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100167 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000168 LoadClassSlowPathARM(HLoadClass* cls,
169 HInstruction* at,
170 uint32_t dex_pc,
171 bool do_clinit)
172 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
173 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
174 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100175
Alexandre Rames67555f72014-11-18 10:55:16 +0000176 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000177 LocationSummary* locations = at_->GetLocations();
178
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100179 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
180 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000181 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100182
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100183 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000184 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000185 int32_t entry_point_offset = do_clinit_
186 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
187 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000188 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000189
190 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000191 Location out = locations->Out();
192 if (out.IsValid()) {
193 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000194 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
195 }
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000196 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100197 __ b(GetExitLabel());
198 }
199
200 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000201 // The class this slow path will load.
202 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100203
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000204 // The instruction where this slow path is happening.
205 // (Might be the load class or an initialization check).
206 HInstruction* const at_;
207
208 // The dex PC of `at_`.
209 const uint32_t dex_pc_;
210
211 // Whether to initialize the class.
212 const bool do_clinit_;
213
214 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100215};
216
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000217class LoadStringSlowPathARM : public SlowPathCodeARM {
218 public:
219 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
220
Alexandre Rames67555f72014-11-18 10:55:16 +0000221 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000222 LocationSummary* locations = instruction_->GetLocations();
223 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
224
225 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
226 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000227 SaveLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000228
229 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800230 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000231 arm_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000232 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000233 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
234
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000235 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000236 __ b(GetExitLabel());
237 }
238
239 private:
240 HLoadString* const instruction_;
241
242 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
243};
244
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000245class TypeCheckSlowPathARM : public SlowPathCodeARM {
246 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000247 TypeCheckSlowPathARM(HInstruction* instruction,
248 Location class_to_check,
249 Location object_class,
250 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000251 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000252 class_to_check_(class_to_check),
253 object_class_(object_class),
254 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000255
Alexandre Rames67555f72014-11-18 10:55:16 +0000256 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000257 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000258 DCHECK(instruction_->IsCheckCast()
259 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000260
261 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
262 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000263 SaveLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000264
265 // We're moving two locations to locations that could overlap, so we need a parallel
266 // move resolver.
267 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000268 codegen->EmitParallelMoves(
269 class_to_check_,
270 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100271 Primitive::kPrimNot,
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000272 object_class_,
Nicolas Geoffray90218252015-04-15 11:56:51 +0100273 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
274 Primitive::kPrimNot);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000275
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000276 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000277 arm_codegen->InvokeRuntime(
278 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000279 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
280 } else {
281 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000282 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000283 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000284
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000285 RestoreLiveRegisters(codegen, locations);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000286 __ b(GetExitLabel());
287 }
288
289 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000290 HInstruction* const instruction_;
291 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000292 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000293 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000294
295 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
296};
297
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700298class DeoptimizationSlowPathARM : public SlowPathCodeARM {
299 public:
300 explicit DeoptimizationSlowPathARM(HInstruction* instruction)
301 : instruction_(instruction) {}
302
303 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
304 __ Bind(GetEntryLabel());
305 SaveLiveRegisters(codegen, instruction_->GetLocations());
306 DCHECK(instruction_->IsDeoptimize());
307 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
308 uint32_t dex_pc = deoptimize->GetDexPc();
309 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
310 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
311 }
312
313 private:
314 HInstruction* const instruction_;
315 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM);
316};
317
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000318#undef __
319
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100320#undef __
Roland Levillain62a46b22015-06-01 18:24:13 +0100321#define __ down_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700322
323inline Condition ARMCondition(IfCondition cond) {
324 switch (cond) {
325 case kCondEQ: return EQ;
326 case kCondNE: return NE;
327 case kCondLT: return LT;
328 case kCondLE: return LE;
329 case kCondGT: return GT;
330 case kCondGE: return GE;
331 default:
332 LOG(FATAL) << "Unknown if condition";
333 }
334 return EQ; // Unreachable.
335}
336
337inline Condition ARMOppositeCondition(IfCondition cond) {
338 switch (cond) {
339 case kCondEQ: return NE;
340 case kCondNE: return EQ;
341 case kCondLT: return GE;
342 case kCondLE: return GT;
343 case kCondGT: return LE;
344 case kCondGE: return LT;
345 default:
346 LOG(FATAL) << "Unknown if condition";
347 }
348 return EQ; // Unreachable.
349}
350
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100351void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100352 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100353}
354
355void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100356 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100357}
358
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100359size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
360 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
361 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100362}
363
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100364size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
365 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
366 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100367}
368
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000369size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
370 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
371 return kArmWordSize;
372}
373
374size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
375 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
376 return kArmWordSize;
377}
378
Calin Juravle34166012014-12-19 17:22:29 +0000379CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000380 const ArmInstructionSetFeatures& isa_features,
381 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000382 : CodeGenerator(graph,
383 kNumberOfCoreRegisters,
384 kNumberOfSRegisters,
385 kNumberOfRegisterPairs,
386 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
387 arraysize(kCoreCalleeSaves)),
388 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
389 arraysize(kFpuCalleeSaves)),
390 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100391 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100392 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100393 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100394 move_resolver_(graph->GetArena(), this),
Nicolas Geoffrayd126ba12015-05-20 11:25:27 +0100395 assembler_(false /* can_relocate_branches */),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000396 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000397 // Save the PC register to mimic Quick.
398 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100399}
400
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100401Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100402 switch (type) {
403 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100404 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100405 ArmManagedRegister pair =
406 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100407 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
408 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
409
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100410 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
411 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100412 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100413 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100414 }
415
416 case Primitive::kPrimByte:
417 case Primitive::kPrimBoolean:
418 case Primitive::kPrimChar:
419 case Primitive::kPrimShort:
420 case Primitive::kPrimInt:
421 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100422 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100423 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100424 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
425 ArmManagedRegister current =
426 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
427 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100428 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100429 }
430 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100431 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100432 }
433
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000434 case Primitive::kPrimFloat: {
435 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100436 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100437 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100438
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000439 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000440 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
441 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000442 return Location::FpuRegisterPairLocation(reg, reg + 1);
443 }
444
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100445 case Primitive::kPrimVoid:
446 LOG(FATAL) << "Unreachable type " << type;
447 }
448
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100449 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100450}
451
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000452void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100453 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100454 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100455
456 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100457 blocked_core_registers_[SP] = true;
458 blocked_core_registers_[LR] = true;
459 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100460
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100461 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100462 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100463
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100464 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100465 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100466
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000467 if (is_baseline) {
468 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
469 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
470 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000471
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000472 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
473
474 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
475 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
476 }
477 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100478
479 UpdateBlockedPairRegisters();
480}
481
482void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
483 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
484 ArmManagedRegister current =
485 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
486 if (blocked_core_registers_[current.AsRegisterPairLow()]
487 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
488 blocked_register_pairs_[i] = true;
489 }
490 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100491}
492
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100493InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
494 : HGraphVisitor(graph),
495 assembler_(codegen->GetAssembler()),
496 codegen_(codegen) {}
497
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000498void CodeGeneratorARM::ComputeSpillMask() {
499 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000500 // Save one extra register for baseline. Note that on thumb2, there is no easy
501 // instruction to restore just the PC, so this actually helps both baseline
502 // and non-baseline to save and restore at least two registers at entry and exit.
503 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000504 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
505 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
506 // We use vpush and vpop for saving and restoring floating point registers, which take
507 // a SRegister and the number of registers to save/restore after that SRegister. We
508 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
509 // but in the range.
510 if (fpu_spill_mask_ != 0) {
511 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
512 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
513 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
514 fpu_spill_mask_ |= (1 << i);
515 }
516 }
517}
518
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100519static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100520 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100521}
522
523static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100524 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100525}
526
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000527void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000528 bool skip_overflow_check =
529 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000530 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000531 __ Bind(&frame_entry_label_);
532
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000533 if (HasEmptyFrame()) {
534 return;
535 }
536
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100537 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000538 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
539 __ LoadFromOffset(kLoadWord, IP, IP, 0);
540 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100541 }
542
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000543 // PC is in the list of callee-save to mimic Quick, but we need to push
544 // LR at entry instead.
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100545 uint32_t push_mask = (core_spill_mask_ & (~(1 << PC))) | 1 << LR;
546 __ PushList(push_mask);
547 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(push_mask));
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100548 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, push_mask, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000549 if (fpu_spill_mask_ != 0) {
550 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
551 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100552 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100553 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000554 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100555 int adjust = GetFrameSize() - FrameEntrySpillSize();
556 __ AddConstant(SP, -adjust);
557 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100558 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000559}
560
561void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000562 if (HasEmptyFrame()) {
563 __ bx(LR);
564 return;
565 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100566 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100567 int adjust = GetFrameSize() - FrameEntrySpillSize();
568 __ AddConstant(SP, adjust);
569 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000570 if (fpu_spill_mask_ != 0) {
571 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
572 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100573 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
574 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000575 }
576 __ PopList(core_spill_mask_);
David Srbeckyc34dc932015-04-12 09:27:43 +0100577 __ cfi().RestoreState();
578 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000579}
580
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100581void CodeGeneratorARM::Bind(HBasicBlock* block) {
582 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000583}
584
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100585Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
586 switch (load->GetType()) {
587 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100588 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100589 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100590
591 case Primitive::kPrimInt:
592 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100593 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100594 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100595
596 case Primitive::kPrimBoolean:
597 case Primitive::kPrimByte:
598 case Primitive::kPrimChar:
599 case Primitive::kPrimShort:
600 case Primitive::kPrimVoid:
601 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700602 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100603 }
604
605 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700606 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100607}
608
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100609Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100610 switch (type) {
611 case Primitive::kPrimBoolean:
612 case Primitive::kPrimByte:
613 case Primitive::kPrimChar:
614 case Primitive::kPrimShort:
615 case Primitive::kPrimInt:
616 case Primitive::kPrimNot: {
617 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000618 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100619 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100620 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100621 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000622 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100623 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100624 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100625
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000626 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100627 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000628 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100629 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000630 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100631 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000632 if (calling_convention.GetRegisterAt(index) == R1) {
633 // Skip R1, and use R2_R3 instead.
634 gp_index_++;
635 index++;
636 }
637 }
638 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
639 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000640 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000641 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000642 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100643 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000644 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
645 }
646 }
647
648 case Primitive::kPrimFloat: {
649 uint32_t stack_index = stack_index_++;
650 if (float_index_ % 2 == 0) {
651 float_index_ = std::max(double_index_, float_index_);
652 }
653 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
654 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
655 } else {
656 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
657 }
658 }
659
660 case Primitive::kPrimDouble: {
661 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
662 uint32_t stack_index = stack_index_;
663 stack_index_ += 2;
664 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
665 uint32_t index = double_index_;
666 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000667 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000668 calling_convention.GetFpuRegisterAt(index),
669 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000670 DCHECK(ExpectedPairLayout(result));
671 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000672 } else {
673 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100674 }
675 }
676
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100677 case Primitive::kPrimVoid:
678 LOG(FATAL) << "Unexpected parameter type " << type;
679 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100680 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100681 return Location();
682}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100683
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100684Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000685 switch (type) {
686 case Primitive::kPrimBoolean:
687 case Primitive::kPrimByte:
688 case Primitive::kPrimChar:
689 case Primitive::kPrimShort:
690 case Primitive::kPrimInt:
691 case Primitive::kPrimNot: {
692 return Location::RegisterLocation(R0);
693 }
694
695 case Primitive::kPrimFloat: {
696 return Location::FpuRegisterLocation(S0);
697 }
698
699 case Primitive::kPrimLong: {
700 return Location::RegisterPairLocation(R0, R1);
701 }
702
703 case Primitive::kPrimDouble: {
704 return Location::FpuRegisterPairLocation(S0, S1);
705 }
706
707 case Primitive::kPrimVoid:
708 return Location();
709 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +0100710
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000711 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000712}
713
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100714Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
715 return Location::RegisterLocation(kMethodRegisterArgument);
716}
717
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100718void CodeGeneratorARM::Move32(Location destination, Location source) {
719 if (source.Equals(destination)) {
720 return;
721 }
722 if (destination.IsRegister()) {
723 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000724 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100725 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000726 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100727 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000728 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100729 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100730 } else if (destination.IsFpuRegister()) {
731 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000732 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100733 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000734 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100735 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000736 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100737 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100738 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000739 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100740 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000741 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100742 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000743 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100744 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000745 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100746 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
747 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100748 }
749 }
750}
751
752void CodeGeneratorARM::Move64(Location destination, Location source) {
753 if (source.Equals(destination)) {
754 return;
755 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100756 if (destination.IsRegisterPair()) {
757 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000758 EmitParallelMoves(
759 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
760 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100761 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000762 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100763 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
764 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100765 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000766 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100767 } else {
768 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000769 DCHECK(ExpectedPairLayout(destination));
770 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
771 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100772 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000773 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100774 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000775 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
776 SP,
777 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100778 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000779 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100780 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100781 } else {
782 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100783 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000784 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100785 if (source.AsRegisterPairLow<Register>() == R1) {
786 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100787 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
788 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100789 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100790 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100791 SP, destination.GetStackIndex());
792 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000793 } else if (source.IsFpuRegisterPair()) {
794 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
795 SP,
796 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100797 } else {
798 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000799 EmitParallelMoves(
800 Location::StackSlot(source.GetStackIndex()),
801 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100802 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000803 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100804 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
805 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100806 }
807 }
808}
809
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100810void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100811 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100812 if (instruction->IsCurrentMethod()) {
813 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
814 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100815 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100816 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000817 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000818 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
819 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000820 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000821 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000822 } else {
823 DCHECK(location.IsStackSlot());
824 __ LoadImmediate(IP, value);
825 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
826 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000827 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000828 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000829 int64_t value = const_to_move->AsLongConstant()->GetValue();
830 if (location.IsRegisterPair()) {
831 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
832 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
833 } else {
834 DCHECK(location.IsDoubleStackSlot());
835 __ LoadImmediate(IP, Low32Bits(value));
836 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
837 __ LoadImmediate(IP, High32Bits(value));
838 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
839 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100840 }
Roland Levillain476df552014-10-09 17:51:36 +0100841 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100842 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
843 switch (instruction->GetType()) {
844 case Primitive::kPrimBoolean:
845 case Primitive::kPrimByte:
846 case Primitive::kPrimChar:
847 case Primitive::kPrimShort:
848 case Primitive::kPrimInt:
849 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100850 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100851 Move32(location, Location::StackSlot(stack_slot));
852 break;
853
854 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100855 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100856 Move64(location, Location::DoubleStackSlot(stack_slot));
857 break;
858
859 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100860 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100861 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000862 } else if (instruction->IsTemporary()) {
863 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000864 if (temp_location.IsStackSlot()) {
865 Move32(location, temp_location);
866 } else {
867 DCHECK(temp_location.IsDoubleStackSlot());
868 Move64(location, temp_location);
869 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000870 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100871 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100872 switch (instruction->GetType()) {
873 case Primitive::kPrimBoolean:
874 case Primitive::kPrimByte:
875 case Primitive::kPrimChar:
876 case Primitive::kPrimShort:
877 case Primitive::kPrimNot:
878 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100879 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100880 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100881 break;
882
883 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100884 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100885 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100886 break;
887
888 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100889 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100890 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000891 }
892}
893
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100894void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
895 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000896 uint32_t dex_pc,
897 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100898 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
899 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000900 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100901 DCHECK(instruction->IsSuspendCheck()
902 || instruction->IsBoundsCheck()
903 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000904 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000905 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100906 || !IsLeafMethod());
907}
908
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000909void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000910 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000911}
912
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000913void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000914 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100915 DCHECK(!successor->IsExitBlock());
916
917 HBasicBlock* block = got->GetBlock();
918 HInstruction* previous = got->GetPrevious();
919
920 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000921 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100922 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
923 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
924 return;
925 }
926
927 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
928 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
929 }
930 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000931 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000932 }
933}
934
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000935void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000936 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000937}
938
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000939void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700940 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000941}
942
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700943void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
944 Label* true_target,
945 Label* false_target,
946 Label* always_true_target) {
947 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100948 if (cond->IsIntConstant()) {
949 // Constant condition, statically compared against 1.
950 int32_t cond_value = cond->AsIntConstant()->GetValue();
951 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700952 if (always_true_target != nullptr) {
953 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100954 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100955 return;
956 } else {
957 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100958 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100959 } else {
960 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
961 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700962 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
963 __ cmp(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100964 ShifterOperand(0));
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700965 __ b(true_target, NE);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100966 } else {
967 // Condition has not been materialized, use its inputs as the
968 // comparison and its condition as the branch condition.
969 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000970 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000971 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100972 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000973 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100974 } else {
975 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000976 HConstant* constant = locations->InAt(1).GetConstant();
977 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100978 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000979 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
980 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100981 } else {
982 Register temp = IP;
983 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000984 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100985 }
986 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700987 __ b(true_target, ARMCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100988 }
Dave Allison20dfc792014-06-16 20:44:29 -0700989 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700990 if (false_target != nullptr) {
991 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000992 }
993}
994
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700995void LocationsBuilderARM::VisitIf(HIf* if_instr) {
996 LocationSummary* locations =
997 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
998 HInstruction* cond = if_instr->InputAt(0);
999 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1000 locations->SetInAt(0, Location::RequiresRegister());
1001 }
1002}
1003
1004void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1005 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1006 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1007 Label* always_true_target = true_target;
1008 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1009 if_instr->IfTrueSuccessor())) {
1010 always_true_target = nullptr;
1011 }
1012 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1013 if_instr->IfFalseSuccessor())) {
1014 false_target = nullptr;
1015 }
1016 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1017}
1018
1019void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1020 LocationSummary* locations = new (GetGraph()->GetArena())
1021 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1022 HInstruction* cond = deoptimize->InputAt(0);
1023 DCHECK(cond->IsCondition());
1024 if (cond->AsCondition()->NeedsMaterialization()) {
1025 locations->SetInAt(0, Location::RequiresRegister());
1026 }
1027}
1028
1029void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1030 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1031 DeoptimizationSlowPathARM(deoptimize);
1032 codegen_->AddSlowPath(slow_path);
1033 Label* slow_path_entry = slow_path->GetEntryLabel();
1034 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1035}
Dave Allison20dfc792014-06-16 20:44:29 -07001036
Roland Levillain0d37cd02015-05-27 16:39:19 +01001037void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001038 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001039 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001040 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain0d37cd02015-05-27 16:39:19 +01001041 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1042 if (cond->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001043 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001044 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001045}
1046
Roland Levillain0d37cd02015-05-27 16:39:19 +01001047void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
1048 if (!cond->NeedsMaterialization()) return;
1049 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001050 Register left = locations->InAt(0).AsRegister<Register>();
1051
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001052 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001053 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001054 } else {
1055 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -08001056 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001057 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001058 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1059 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001060 } else {
1061 Register temp = IP;
1062 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001063 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001064 }
Dave Allison20dfc792014-06-16 20:44:29 -07001065 }
Roland Levillain0d37cd02015-05-27 16:39:19 +01001066 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001067 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001068 ARMCondition(cond->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001069 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001070 ARMOppositeCondition(cond->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001071}
1072
1073void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1074 VisitCondition(comp);
1075}
1076
1077void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1078 VisitCondition(comp);
1079}
1080
1081void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1082 VisitCondition(comp);
1083}
1084
1085void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1086 VisitCondition(comp);
1087}
1088
1089void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1090 VisitCondition(comp);
1091}
1092
1093void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1094 VisitCondition(comp);
1095}
1096
1097void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1098 VisitCondition(comp);
1099}
1100
1101void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1102 VisitCondition(comp);
1103}
1104
1105void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1106 VisitCondition(comp);
1107}
1108
1109void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1110 VisitCondition(comp);
1111}
1112
1113void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1114 VisitCondition(comp);
1115}
1116
1117void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1118 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001119}
1120
1121void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001122 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001123}
1124
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001125void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1126 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001127}
1128
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001129void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001130 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001131}
1132
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001133void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001134 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001135 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001136}
1137
1138void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001139 LocationSummary* locations =
1140 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001141 switch (store->InputAt(1)->GetType()) {
1142 case Primitive::kPrimBoolean:
1143 case Primitive::kPrimByte:
1144 case Primitive::kPrimChar:
1145 case Primitive::kPrimShort:
1146 case Primitive::kPrimInt:
1147 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001148 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001149 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1150 break;
1151
1152 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001153 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001154 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1155 break;
1156
1157 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001158 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001159 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001160}
1161
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001162void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001163 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001164}
1165
1166void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001167 LocationSummary* locations =
1168 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001169 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001170}
1171
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001172void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001173 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001174 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001175}
1176
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001177void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1178 LocationSummary* locations =
1179 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1180 locations->SetOut(Location::ConstantLocation(constant));
1181}
1182
1183void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1184 // Will be generated at use site.
1185 UNUSED(constant);
1186}
1187
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001188void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001189 LocationSummary* locations =
1190 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001191 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001192}
1193
1194void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1195 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001196 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001197}
1198
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001199void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1200 LocationSummary* locations =
1201 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1202 locations->SetOut(Location::ConstantLocation(constant));
1203}
1204
1205void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1206 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001207 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001208}
1209
1210void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1211 LocationSummary* locations =
1212 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1213 locations->SetOut(Location::ConstantLocation(constant));
1214}
1215
1216void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1217 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001218 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001219}
1220
Calin Juravle27df7582015-04-17 19:12:31 +01001221void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1222 memory_barrier->SetLocations(nullptr);
1223}
1224
1225void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1226 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1227}
1228
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001229void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001230 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001231}
1232
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001233void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001234 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001235 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001236}
1237
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001238void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001239 LocationSummary* locations =
1240 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001241 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001242}
1243
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001244void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001245 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001246 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001247}
1248
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001249void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001250 // When we do not run baseline, explicit clinit checks triggered by static
1251 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1252 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001253
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001254 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1255 codegen_->GetInstructionSetFeatures());
1256 if (intrinsic.TryDispatch(invoke)) {
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001257 LocationSummary* locations = invoke->GetLocations();
1258 if (locations->CanCall()) {
1259 locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::RequiresRegister());
1260 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001261 return;
1262 }
1263
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001264 HandleInvoke(invoke);
1265}
1266
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001267static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1268 if (invoke->GetLocations()->Intrinsified()) {
1269 IntrinsicCodeGeneratorARM intrinsic(codegen);
1270 intrinsic.Dispatch(invoke);
1271 return true;
1272 }
1273 return false;
1274}
1275
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001276void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001277 // When we do not run baseline, explicit clinit checks triggered by static
1278 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1279 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001280
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001281 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1282 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001283 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001284
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001285 LocationSummary* locations = invoke->GetLocations();
1286 codegen_->GenerateStaticOrDirectCall(
1287 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001288 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001289}
1290
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001291void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001292 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001293 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001294}
1295
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001296void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001297 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1298 codegen_->GetInstructionSetFeatures());
1299 if (intrinsic.TryDispatch(invoke)) {
1300 return;
1301 }
1302
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001303 HandleInvoke(invoke);
1304}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001305
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001306void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001307 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1308 return;
1309 }
1310
Roland Levillain271ab9c2014-11-27 15:23:57 +00001311 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001312 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
1313 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001314 LocationSummary* locations = invoke->GetLocations();
1315 Location receiver = locations->InAt(0);
1316 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1317 // temp = object->GetClass();
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001318 DCHECK(receiver.IsRegister());
1319 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00001320 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001321 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001322 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001323 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001324 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001325 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001326 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001327 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001328 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001329 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001330 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001331}
1332
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001333void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1334 HandleInvoke(invoke);
1335 // Add the hidden argument.
1336 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1337}
1338
1339void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1340 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001341 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001342 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1343 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001344 LocationSummary* locations = invoke->GetLocations();
1345 Location receiver = locations->InAt(0);
1346 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1347
1348 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001349 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1350 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001351
1352 // temp = object->GetClass();
1353 if (receiver.IsStackSlot()) {
1354 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1355 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1356 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001357 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001358 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001359 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001360 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001361 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001362 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001363 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1364 // LR = temp->GetEntryPoint();
1365 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1366 // LR();
1367 __ blx(LR);
1368 DCHECK(!codegen_->IsLeafMethod());
1369 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1370}
1371
Roland Levillain88cb1752014-10-20 16:36:47 +01001372void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1373 LocationSummary* locations =
1374 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1375 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001376 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001377 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001378 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1379 break;
1380 }
1381 case Primitive::kPrimLong: {
1382 locations->SetInAt(0, Location::RequiresRegister());
1383 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001384 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001385 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001386
Roland Levillain88cb1752014-10-20 16:36:47 +01001387 case Primitive::kPrimFloat:
1388 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001389 locations->SetInAt(0, Location::RequiresFpuRegister());
1390 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001391 break;
1392
1393 default:
1394 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1395 }
1396}
1397
1398void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1399 LocationSummary* locations = neg->GetLocations();
1400 Location out = locations->Out();
1401 Location in = locations->InAt(0);
1402 switch (neg->GetResultType()) {
1403 case Primitive::kPrimInt:
1404 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001405 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001406 break;
1407
1408 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001409 DCHECK(in.IsRegisterPair());
1410 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1411 __ rsbs(out.AsRegisterPairLow<Register>(),
1412 in.AsRegisterPairLow<Register>(),
1413 ShifterOperand(0));
1414 // We cannot emit an RSC (Reverse Subtract with Carry)
1415 // instruction here, as it does not exist in the Thumb-2
1416 // instruction set. We use the following approach
1417 // using SBC and SUB instead.
1418 //
1419 // out.hi = -C
1420 __ sbc(out.AsRegisterPairHigh<Register>(),
1421 out.AsRegisterPairHigh<Register>(),
1422 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1423 // out.hi = out.hi - in.hi
1424 __ sub(out.AsRegisterPairHigh<Register>(),
1425 out.AsRegisterPairHigh<Register>(),
1426 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1427 break;
1428
Roland Levillain88cb1752014-10-20 16:36:47 +01001429 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001430 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001431 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001432 break;
1433
Roland Levillain88cb1752014-10-20 16:36:47 +01001434 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001435 DCHECK(in.IsFpuRegisterPair());
1436 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1437 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001438 break;
1439
1440 default:
1441 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1442 }
1443}
1444
Roland Levillaindff1f282014-11-05 14:15:05 +00001445void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001446 Primitive::Type result_type = conversion->GetResultType();
1447 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001448 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001449
Roland Levillain5b3ee562015-04-14 16:02:41 +01001450 // The float-to-long, double-to-long and long-to-float type conversions
1451 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001452 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001453 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1454 && result_type == Primitive::kPrimLong)
1455 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001456 ? LocationSummary::kCall
1457 : LocationSummary::kNoCall;
1458 LocationSummary* locations =
1459 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1460
David Brazdilb2bd1c52015-03-25 11:17:37 +00001461 // The Java language does not allow treating boolean as an integral type but
1462 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001463
Roland Levillaindff1f282014-11-05 14:15:05 +00001464 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001465 case Primitive::kPrimByte:
1466 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001467 case Primitive::kPrimBoolean:
1468 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001469 case Primitive::kPrimShort:
1470 case Primitive::kPrimInt:
1471 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001472 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001473 locations->SetInAt(0, Location::RequiresRegister());
1474 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1475 break;
1476
1477 default:
1478 LOG(FATAL) << "Unexpected type conversion from " << input_type
1479 << " to " << result_type;
1480 }
1481 break;
1482
Roland Levillain01a8d712014-11-14 16:27:39 +00001483 case Primitive::kPrimShort:
1484 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001485 case Primitive::kPrimBoolean:
1486 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001487 case Primitive::kPrimByte:
1488 case Primitive::kPrimInt:
1489 case Primitive::kPrimChar:
1490 // Processing a Dex `int-to-short' instruction.
1491 locations->SetInAt(0, Location::RequiresRegister());
1492 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1493 break;
1494
1495 default:
1496 LOG(FATAL) << "Unexpected type conversion from " << input_type
1497 << " to " << result_type;
1498 }
1499 break;
1500
Roland Levillain946e1432014-11-11 17:35:19 +00001501 case Primitive::kPrimInt:
1502 switch (input_type) {
1503 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001504 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001505 locations->SetInAt(0, Location::Any());
1506 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1507 break;
1508
1509 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001510 // Processing a Dex `float-to-int' instruction.
1511 locations->SetInAt(0, Location::RequiresFpuRegister());
1512 locations->SetOut(Location::RequiresRegister());
1513 locations->AddTemp(Location::RequiresFpuRegister());
1514 break;
1515
Roland Levillain946e1432014-11-11 17:35:19 +00001516 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001517 // Processing a Dex `double-to-int' instruction.
1518 locations->SetInAt(0, Location::RequiresFpuRegister());
1519 locations->SetOut(Location::RequiresRegister());
1520 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001521 break;
1522
1523 default:
1524 LOG(FATAL) << "Unexpected type conversion from " << input_type
1525 << " to " << result_type;
1526 }
1527 break;
1528
Roland Levillaindff1f282014-11-05 14:15:05 +00001529 case Primitive::kPrimLong:
1530 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001531 case Primitive::kPrimBoolean:
1532 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001533 case Primitive::kPrimByte:
1534 case Primitive::kPrimShort:
1535 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001536 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001537 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001538 locations->SetInAt(0, Location::RequiresRegister());
1539 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1540 break;
1541
Roland Levillain624279f2014-12-04 11:54:28 +00001542 case Primitive::kPrimFloat: {
1543 // Processing a Dex `float-to-long' instruction.
1544 InvokeRuntimeCallingConvention calling_convention;
1545 locations->SetInAt(0, Location::FpuRegisterLocation(
1546 calling_convention.GetFpuRegisterAt(0)));
1547 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1548 break;
1549 }
1550
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001551 case Primitive::kPrimDouble: {
1552 // Processing a Dex `double-to-long' instruction.
1553 InvokeRuntimeCallingConvention calling_convention;
1554 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1555 calling_convention.GetFpuRegisterAt(0),
1556 calling_convention.GetFpuRegisterAt(1)));
1557 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001558 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001559 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001560
1561 default:
1562 LOG(FATAL) << "Unexpected type conversion from " << input_type
1563 << " to " << result_type;
1564 }
1565 break;
1566
Roland Levillain981e4542014-11-14 11:47:14 +00001567 case Primitive::kPrimChar:
1568 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001569 case Primitive::kPrimBoolean:
1570 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001571 case Primitive::kPrimByte:
1572 case Primitive::kPrimShort:
1573 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001574 // Processing a Dex `int-to-char' instruction.
1575 locations->SetInAt(0, Location::RequiresRegister());
1576 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1577 break;
1578
1579 default:
1580 LOG(FATAL) << "Unexpected type conversion from " << input_type
1581 << " to " << result_type;
1582 }
1583 break;
1584
Roland Levillaindff1f282014-11-05 14:15:05 +00001585 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001586 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001587 case Primitive::kPrimBoolean:
1588 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001589 case Primitive::kPrimByte:
1590 case Primitive::kPrimShort:
1591 case Primitive::kPrimInt:
1592 case Primitive::kPrimChar:
1593 // Processing a Dex `int-to-float' instruction.
1594 locations->SetInAt(0, Location::RequiresRegister());
1595 locations->SetOut(Location::RequiresFpuRegister());
1596 break;
1597
Roland Levillain5b3ee562015-04-14 16:02:41 +01001598 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001599 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001600 InvokeRuntimeCallingConvention calling_convention;
1601 locations->SetInAt(0, Location::RegisterPairLocation(
1602 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1603 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001604 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001605 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001606
Roland Levillaincff13742014-11-17 14:32:17 +00001607 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001608 // Processing a Dex `double-to-float' instruction.
1609 locations->SetInAt(0, Location::RequiresFpuRegister());
1610 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001611 break;
1612
1613 default:
1614 LOG(FATAL) << "Unexpected type conversion from " << input_type
1615 << " to " << result_type;
1616 };
1617 break;
1618
Roland Levillaindff1f282014-11-05 14:15:05 +00001619 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001620 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001621 case Primitive::kPrimBoolean:
1622 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001623 case Primitive::kPrimByte:
1624 case Primitive::kPrimShort:
1625 case Primitive::kPrimInt:
1626 case Primitive::kPrimChar:
1627 // Processing a Dex `int-to-double' instruction.
1628 locations->SetInAt(0, Location::RequiresRegister());
1629 locations->SetOut(Location::RequiresFpuRegister());
1630 break;
1631
1632 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001633 // Processing a Dex `long-to-double' instruction.
1634 locations->SetInAt(0, Location::RequiresRegister());
1635 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01001636 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00001637 locations->AddTemp(Location::RequiresFpuRegister());
1638 break;
1639
Roland Levillaincff13742014-11-17 14:32:17 +00001640 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001641 // Processing a Dex `float-to-double' instruction.
1642 locations->SetInAt(0, Location::RequiresFpuRegister());
1643 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001644 break;
1645
1646 default:
1647 LOG(FATAL) << "Unexpected type conversion from " << input_type
1648 << " to " << result_type;
1649 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001650 break;
1651
1652 default:
1653 LOG(FATAL) << "Unexpected type conversion from " << input_type
1654 << " to " << result_type;
1655 }
1656}
1657
1658void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1659 LocationSummary* locations = conversion->GetLocations();
1660 Location out = locations->Out();
1661 Location in = locations->InAt(0);
1662 Primitive::Type result_type = conversion->GetResultType();
1663 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001664 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001665 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001666 case Primitive::kPrimByte:
1667 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001668 case Primitive::kPrimBoolean:
1669 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001670 case Primitive::kPrimShort:
1671 case Primitive::kPrimInt:
1672 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001673 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001674 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001675 break;
1676
1677 default:
1678 LOG(FATAL) << "Unexpected type conversion from " << input_type
1679 << " to " << result_type;
1680 }
1681 break;
1682
Roland Levillain01a8d712014-11-14 16:27:39 +00001683 case Primitive::kPrimShort:
1684 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001685 case Primitive::kPrimBoolean:
1686 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001687 case Primitive::kPrimByte:
1688 case Primitive::kPrimInt:
1689 case Primitive::kPrimChar:
1690 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001691 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001692 break;
1693
1694 default:
1695 LOG(FATAL) << "Unexpected type conversion from " << input_type
1696 << " to " << result_type;
1697 }
1698 break;
1699
Roland Levillain946e1432014-11-11 17:35:19 +00001700 case Primitive::kPrimInt:
1701 switch (input_type) {
1702 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001703 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001704 DCHECK(out.IsRegister());
1705 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001706 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001707 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001708 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001709 } else {
1710 DCHECK(in.IsConstant());
1711 DCHECK(in.GetConstant()->IsLongConstant());
1712 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001713 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001714 }
1715 break;
1716
Roland Levillain3f8f9362014-12-02 17:45:01 +00001717 case Primitive::kPrimFloat: {
1718 // Processing a Dex `float-to-int' instruction.
1719 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1720 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1721 __ vcvtis(temp, temp);
1722 __ vmovrs(out.AsRegister<Register>(), temp);
1723 break;
1724 }
1725
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001726 case Primitive::kPrimDouble: {
1727 // Processing a Dex `double-to-int' instruction.
1728 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1729 DRegister temp_d = FromLowSToD(temp_s);
1730 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1731 __ vcvtid(temp_s, temp_d);
1732 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001733 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001734 }
Roland Levillain946e1432014-11-11 17:35:19 +00001735
1736 default:
1737 LOG(FATAL) << "Unexpected type conversion from " << input_type
1738 << " to " << result_type;
1739 }
1740 break;
1741
Roland Levillaindff1f282014-11-05 14:15:05 +00001742 case Primitive::kPrimLong:
1743 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001744 case Primitive::kPrimBoolean:
1745 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001746 case Primitive::kPrimByte:
1747 case Primitive::kPrimShort:
1748 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001749 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001750 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001751 DCHECK(out.IsRegisterPair());
1752 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001753 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001754 // Sign extension.
1755 __ Asr(out.AsRegisterPairHigh<Register>(),
1756 out.AsRegisterPairLow<Register>(),
1757 31);
1758 break;
1759
1760 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001761 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001762 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1763 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001764 conversion->GetDexPc(),
1765 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001766 break;
1767
Roland Levillaindff1f282014-11-05 14:15:05 +00001768 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001769 // Processing a Dex `double-to-long' instruction.
1770 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1771 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001772 conversion->GetDexPc(),
1773 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001774 break;
1775
1776 default:
1777 LOG(FATAL) << "Unexpected type conversion from " << input_type
1778 << " to " << result_type;
1779 }
1780 break;
1781
Roland Levillain981e4542014-11-14 11:47:14 +00001782 case Primitive::kPrimChar:
1783 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001784 case Primitive::kPrimBoolean:
1785 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001786 case Primitive::kPrimByte:
1787 case Primitive::kPrimShort:
1788 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001789 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001790 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001791 break;
1792
1793 default:
1794 LOG(FATAL) << "Unexpected type conversion from " << input_type
1795 << " to " << result_type;
1796 }
1797 break;
1798
Roland Levillaindff1f282014-11-05 14:15:05 +00001799 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001800 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001801 case Primitive::kPrimBoolean:
1802 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001803 case Primitive::kPrimByte:
1804 case Primitive::kPrimShort:
1805 case Primitive::kPrimInt:
1806 case Primitive::kPrimChar: {
1807 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001808 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1809 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001810 break;
1811 }
1812
Roland Levillain5b3ee562015-04-14 16:02:41 +01001813 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001814 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001815 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
1816 conversion,
1817 conversion->GetDexPc(),
1818 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001819 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00001820
Roland Levillaincff13742014-11-17 14:32:17 +00001821 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001822 // Processing a Dex `double-to-float' instruction.
1823 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1824 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001825 break;
1826
1827 default:
1828 LOG(FATAL) << "Unexpected type conversion from " << input_type
1829 << " to " << result_type;
1830 };
1831 break;
1832
Roland Levillaindff1f282014-11-05 14:15:05 +00001833 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001834 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001835 case Primitive::kPrimBoolean:
1836 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001837 case Primitive::kPrimByte:
1838 case Primitive::kPrimShort:
1839 case Primitive::kPrimInt:
1840 case Primitive::kPrimChar: {
1841 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001842 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001843 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1844 out.AsFpuRegisterPairLow<SRegister>());
1845 break;
1846 }
1847
Roland Levillain647b9ed2014-11-27 12:06:00 +00001848 case Primitive::kPrimLong: {
1849 // Processing a Dex `long-to-double' instruction.
1850 Register low = in.AsRegisterPairLow<Register>();
1851 Register high = in.AsRegisterPairHigh<Register>();
1852 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1853 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001854 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001855 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001856 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
1857 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001858
Roland Levillain682393c2015-04-14 15:57:52 +01001859 // temp_d = int-to-double(high)
1860 __ vmovsr(temp_s, high);
1861 __ vcvtdi(temp_d, temp_s);
1862 // constant_d = k2Pow32EncodingForDouble
1863 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
1864 // out_d = unsigned-to-double(low)
1865 __ vmovsr(out_s, low);
1866 __ vcvtdu(out_d, out_s);
1867 // out_d += temp_d * constant_d
1868 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001869 break;
1870 }
1871
Roland Levillaincff13742014-11-17 14:32:17 +00001872 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001873 // Processing a Dex `float-to-double' instruction.
1874 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1875 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001876 break;
1877
1878 default:
1879 LOG(FATAL) << "Unexpected type conversion from " << input_type
1880 << " to " << result_type;
1881 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001882 break;
1883
1884 default:
1885 LOG(FATAL) << "Unexpected type conversion from " << input_type
1886 << " to " << result_type;
1887 }
1888}
1889
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001890void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001891 LocationSummary* locations =
1892 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001893 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001894 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001895 locations->SetInAt(0, Location::RequiresRegister());
1896 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001897 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1898 break;
1899 }
1900
1901 case Primitive::kPrimLong: {
1902 locations->SetInAt(0, Location::RequiresRegister());
1903 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001904 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001905 break;
1906 }
1907
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001908 case Primitive::kPrimFloat:
1909 case Primitive::kPrimDouble: {
1910 locations->SetInAt(0, Location::RequiresFpuRegister());
1911 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001912 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001913 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001914 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001915
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001916 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001917 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001918 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001919}
1920
1921void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1922 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001923 Location out = locations->Out();
1924 Location first = locations->InAt(0);
1925 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001926 switch (add->GetResultType()) {
1927 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001928 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001929 __ add(out.AsRegister<Register>(),
1930 first.AsRegister<Register>(),
1931 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001932 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001933 __ AddConstant(out.AsRegister<Register>(),
1934 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001935 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001936 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001937 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001938
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001939 case Primitive::kPrimLong: {
1940 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001941 __ adds(out.AsRegisterPairLow<Register>(),
1942 first.AsRegisterPairLow<Register>(),
1943 ShifterOperand(second.AsRegisterPairLow<Register>()));
1944 __ adc(out.AsRegisterPairHigh<Register>(),
1945 first.AsRegisterPairHigh<Register>(),
1946 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001947 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001948 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001949
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001950 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001951 __ vadds(out.AsFpuRegister<SRegister>(),
1952 first.AsFpuRegister<SRegister>(),
1953 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001954 break;
1955
1956 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001957 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1958 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1959 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001960 break;
1961
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001962 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001963 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001964 }
1965}
1966
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001967void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001968 LocationSummary* locations =
1969 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001970 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001971 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001972 locations->SetInAt(0, Location::RequiresRegister());
1973 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001974 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1975 break;
1976 }
1977
1978 case Primitive::kPrimLong: {
1979 locations->SetInAt(0, Location::RequiresRegister());
1980 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001981 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001982 break;
1983 }
Calin Juravle11351682014-10-23 15:38:15 +01001984 case Primitive::kPrimFloat:
1985 case Primitive::kPrimDouble: {
1986 locations->SetInAt(0, Location::RequiresFpuRegister());
1987 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001988 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001989 break;
Calin Juravle11351682014-10-23 15:38:15 +01001990 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001991 default:
Calin Juravle11351682014-10-23 15:38:15 +01001992 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001993 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001994}
1995
1996void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1997 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001998 Location out = locations->Out();
1999 Location first = locations->InAt(0);
2000 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002001 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002002 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002003 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002004 __ sub(out.AsRegister<Register>(),
2005 first.AsRegister<Register>(),
2006 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002007 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002008 __ AddConstant(out.AsRegister<Register>(),
2009 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002010 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002011 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002012 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002013 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002014
Calin Juravle11351682014-10-23 15:38:15 +01002015 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002016 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002017 __ subs(out.AsRegisterPairLow<Register>(),
2018 first.AsRegisterPairLow<Register>(),
2019 ShifterOperand(second.AsRegisterPairLow<Register>()));
2020 __ sbc(out.AsRegisterPairHigh<Register>(),
2021 first.AsRegisterPairHigh<Register>(),
2022 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002023 break;
Calin Juravle11351682014-10-23 15:38:15 +01002024 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002025
Calin Juravle11351682014-10-23 15:38:15 +01002026 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002027 __ vsubs(out.AsFpuRegister<SRegister>(),
2028 first.AsFpuRegister<SRegister>(),
2029 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002030 break;
Calin Juravle11351682014-10-23 15:38:15 +01002031 }
2032
2033 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002034 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2035 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2036 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002037 break;
2038 }
2039
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002040
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002041 default:
Calin Juravle11351682014-10-23 15:38:15 +01002042 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002043 }
2044}
2045
Calin Juravle34bacdf2014-10-07 20:23:36 +01002046void LocationsBuilderARM::VisitMul(HMul* mul) {
2047 LocationSummary* locations =
2048 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2049 switch (mul->GetResultType()) {
2050 case Primitive::kPrimInt:
2051 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002052 locations->SetInAt(0, Location::RequiresRegister());
2053 locations->SetInAt(1, Location::RequiresRegister());
2054 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002055 break;
2056 }
2057
Calin Juravleb5bfa962014-10-21 18:02:24 +01002058 case Primitive::kPrimFloat:
2059 case Primitive::kPrimDouble: {
2060 locations->SetInAt(0, Location::RequiresFpuRegister());
2061 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002062 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002063 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002064 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002065
2066 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002067 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002068 }
2069}
2070
2071void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2072 LocationSummary* locations = mul->GetLocations();
2073 Location out = locations->Out();
2074 Location first = locations->InAt(0);
2075 Location second = locations->InAt(1);
2076 switch (mul->GetResultType()) {
2077 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002078 __ mul(out.AsRegister<Register>(),
2079 first.AsRegister<Register>(),
2080 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002081 break;
2082 }
2083 case Primitive::kPrimLong: {
2084 Register out_hi = out.AsRegisterPairHigh<Register>();
2085 Register out_lo = out.AsRegisterPairLow<Register>();
2086 Register in1_hi = first.AsRegisterPairHigh<Register>();
2087 Register in1_lo = first.AsRegisterPairLow<Register>();
2088 Register in2_hi = second.AsRegisterPairHigh<Register>();
2089 Register in2_lo = second.AsRegisterPairLow<Register>();
2090
2091 // Extra checks to protect caused by the existence of R1_R2.
2092 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2093 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2094 DCHECK_NE(out_hi, in1_lo);
2095 DCHECK_NE(out_hi, in2_lo);
2096
2097 // input: in1 - 64 bits, in2 - 64 bits
2098 // output: out
2099 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2100 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2101 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2102
2103 // IP <- in1.lo * in2.hi
2104 __ mul(IP, in1_lo, in2_hi);
2105 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2106 __ mla(out_hi, in1_hi, in2_lo, IP);
2107 // out.lo <- (in1.lo * in2.lo)[31:0];
2108 __ umull(out_lo, IP, in1_lo, in2_lo);
2109 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2110 __ add(out_hi, out_hi, ShifterOperand(IP));
2111 break;
2112 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002113
2114 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002115 __ vmuls(out.AsFpuRegister<SRegister>(),
2116 first.AsFpuRegister<SRegister>(),
2117 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002118 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002119 }
2120
2121 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002122 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2123 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2124 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002125 break;
2126 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002127
2128 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002129 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002130 }
2131}
2132
Zheng Xuc6667102015-05-15 16:08:45 +08002133void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2134 DCHECK(instruction->IsDiv() || instruction->IsRem());
2135 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2136
2137 LocationSummary* locations = instruction->GetLocations();
2138 Location second = locations->InAt(1);
2139 DCHECK(second.IsConstant());
2140
2141 Register out = locations->Out().AsRegister<Register>();
2142 Register dividend = locations->InAt(0).AsRegister<Register>();
2143 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2144 DCHECK(imm == 1 || imm == -1);
2145
2146 if (instruction->IsRem()) {
2147 __ LoadImmediate(out, 0);
2148 } else {
2149 if (imm == 1) {
2150 __ Mov(out, dividend);
2151 } else {
2152 __ rsb(out, dividend, ShifterOperand(0));
2153 }
2154 }
2155}
2156
2157void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2158 DCHECK(instruction->IsDiv() || instruction->IsRem());
2159 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2160
2161 LocationSummary* locations = instruction->GetLocations();
2162 Location second = locations->InAt(1);
2163 DCHECK(second.IsConstant());
2164
2165 Register out = locations->Out().AsRegister<Register>();
2166 Register dividend = locations->InAt(0).AsRegister<Register>();
2167 Register temp = locations->GetTemp(0).AsRegister<Register>();
2168 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002169 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002170 DCHECK(IsPowerOfTwo(abs_imm));
2171 int ctz_imm = CTZ(abs_imm);
2172
2173 if (ctz_imm == 1) {
2174 __ Lsr(temp, dividend, 32 - ctz_imm);
2175 } else {
2176 __ Asr(temp, dividend, 31);
2177 __ Lsr(temp, temp, 32 - ctz_imm);
2178 }
2179 __ add(out, temp, ShifterOperand(dividend));
2180
2181 if (instruction->IsDiv()) {
2182 __ Asr(out, out, ctz_imm);
2183 if (imm < 0) {
2184 __ rsb(out, out, ShifterOperand(0));
2185 }
2186 } else {
2187 __ ubfx(out, out, 0, ctz_imm);
2188 __ sub(out, out, ShifterOperand(temp));
2189 }
2190}
2191
2192void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2193 DCHECK(instruction->IsDiv() || instruction->IsRem());
2194 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2195
2196 LocationSummary* locations = instruction->GetLocations();
2197 Location second = locations->InAt(1);
2198 DCHECK(second.IsConstant());
2199
2200 Register out = locations->Out().AsRegister<Register>();
2201 Register dividend = locations->InAt(0).AsRegister<Register>();
2202 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2203 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2204 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2205
2206 int64_t magic;
2207 int shift;
2208 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2209
2210 __ LoadImmediate(temp1, magic);
2211 __ smull(temp2, temp1, dividend, temp1);
2212
2213 if (imm > 0 && magic < 0) {
2214 __ add(temp1, temp1, ShifterOperand(dividend));
2215 } else if (imm < 0 && magic > 0) {
2216 __ sub(temp1, temp1, ShifterOperand(dividend));
2217 }
2218
2219 if (shift != 0) {
2220 __ Asr(temp1, temp1, shift);
2221 }
2222
2223 if (instruction->IsDiv()) {
2224 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2225 } else {
2226 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2227 // TODO: Strength reduction for mls.
2228 __ LoadImmediate(temp2, imm);
2229 __ mls(out, temp1, temp2, dividend);
2230 }
2231}
2232
2233void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2234 DCHECK(instruction->IsDiv() || instruction->IsRem());
2235 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2236
2237 LocationSummary* locations = instruction->GetLocations();
2238 Location second = locations->InAt(1);
2239 DCHECK(second.IsConstant());
2240
2241 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2242 if (imm == 0) {
2243 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2244 } else if (imm == 1 || imm == -1) {
2245 DivRemOneOrMinusOne(instruction);
2246 } else if (IsPowerOfTwo(std::abs(imm))) {
2247 DivRemByPowerOfTwo(instruction);
2248 } else {
2249 DCHECK(imm <= -2 || imm >= 2);
2250 GenerateDivRemWithAnyConstant(instruction);
2251 }
2252}
2253
Calin Juravle7c4954d2014-10-28 16:57:40 +00002254void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002255 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2256 if (div->GetResultType() == Primitive::kPrimLong) {
2257 // pLdiv runtime call.
2258 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002259 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2260 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002261 } else if (div->GetResultType() == Primitive::kPrimInt &&
2262 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2263 // pIdivmod runtime call.
2264 call_kind = LocationSummary::kCall;
2265 }
2266
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002267 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2268
Calin Juravle7c4954d2014-10-28 16:57:40 +00002269 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002270 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002271 if (div->InputAt(1)->IsConstant()) {
2272 locations->SetInAt(0, Location::RequiresRegister());
2273 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2274 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2275 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2276 if (abs_imm <= 1) {
2277 // No temp register required.
2278 } else {
2279 locations->AddTemp(Location::RequiresRegister());
2280 if (!IsPowerOfTwo(abs_imm)) {
2281 locations->AddTemp(Location::RequiresRegister());
2282 }
2283 }
2284 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002285 locations->SetInAt(0, Location::RequiresRegister());
2286 locations->SetInAt(1, Location::RequiresRegister());
2287 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
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 former.
2294 locations->SetOut(Location::RegisterLocation(R0));
2295 }
Calin Juravled0d48522014-11-04 16:40:20 +00002296 break;
2297 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002298 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002299 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)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002304 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002305 break;
2306 }
2307 case Primitive::kPrimFloat:
2308 case Primitive::kPrimDouble: {
2309 locations->SetInAt(0, Location::RequiresFpuRegister());
2310 locations->SetInAt(1, Location::RequiresFpuRegister());
2311 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2312 break;
2313 }
2314
2315 default:
2316 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2317 }
2318}
2319
2320void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2321 LocationSummary* locations = div->GetLocations();
2322 Location out = locations->Out();
2323 Location first = locations->InAt(0);
2324 Location second = locations->InAt(1);
2325
2326 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002327 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002328 if (second.IsConstant()) {
2329 GenerateDivRemConstantIntegral(div);
2330 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002331 __ sdiv(out.AsRegister<Register>(),
2332 first.AsRegister<Register>(),
2333 second.AsRegister<Register>());
2334 } else {
2335 InvokeRuntimeCallingConvention calling_convention;
2336 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2337 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2338 DCHECK_EQ(R0, out.AsRegister<Register>());
2339
2340 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2341 }
Calin Juravled0d48522014-11-04 16:40:20 +00002342 break;
2343 }
2344
Calin Juravle7c4954d2014-10-28 16:57:40 +00002345 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002346 InvokeRuntimeCallingConvention calling_convention;
2347 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2348 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2349 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2350 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2351 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002352 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002353
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002354 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002355 break;
2356 }
2357
2358 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002359 __ vdivs(out.AsFpuRegister<SRegister>(),
2360 first.AsFpuRegister<SRegister>(),
2361 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002362 break;
2363 }
2364
2365 case Primitive::kPrimDouble: {
2366 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2367 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2368 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2369 break;
2370 }
2371
2372 default:
2373 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2374 }
2375}
2376
Calin Juravlebacfec32014-11-14 15:54:36 +00002377void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002378 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002379
2380 // Most remainders are implemented in the runtime.
2381 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002382 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2383 // sdiv will be replaced by other instruction sequence.
2384 call_kind = LocationSummary::kNoCall;
2385 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2386 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002387 // Have hardware divide instruction for int, do it with three instructions.
2388 call_kind = LocationSummary::kNoCall;
2389 }
2390
Calin Juravlebacfec32014-11-14 15:54:36 +00002391 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2392
Calin Juravled2ec87d2014-12-08 14:24:46 +00002393 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002394 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002395 if (rem->InputAt(1)->IsConstant()) {
2396 locations->SetInAt(0, Location::RequiresRegister());
2397 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2398 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2399 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2400 if (abs_imm <= 1) {
2401 // No temp register required.
2402 } else {
2403 locations->AddTemp(Location::RequiresRegister());
2404 if (!IsPowerOfTwo(abs_imm)) {
2405 locations->AddTemp(Location::RequiresRegister());
2406 }
2407 }
2408 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002409 locations->SetInAt(0, Location::RequiresRegister());
2410 locations->SetInAt(1, Location::RequiresRegister());
2411 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2412 locations->AddTemp(Location::RequiresRegister());
2413 } else {
2414 InvokeRuntimeCallingConvention calling_convention;
2415 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2416 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2417 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2418 // we only need the latter.
2419 locations->SetOut(Location::RegisterLocation(R1));
2420 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002421 break;
2422 }
2423 case Primitive::kPrimLong: {
2424 InvokeRuntimeCallingConvention calling_convention;
2425 locations->SetInAt(0, Location::RegisterPairLocation(
2426 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2427 locations->SetInAt(1, Location::RegisterPairLocation(
2428 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2429 // The runtime helper puts the output in R2,R3.
2430 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2431 break;
2432 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002433 case Primitive::kPrimFloat: {
2434 InvokeRuntimeCallingConvention calling_convention;
2435 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2436 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2437 locations->SetOut(Location::FpuRegisterLocation(S0));
2438 break;
2439 }
2440
Calin Juravlebacfec32014-11-14 15:54:36 +00002441 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002442 InvokeRuntimeCallingConvention calling_convention;
2443 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2444 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2445 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2446 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2447 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002448 break;
2449 }
2450
2451 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002452 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002453 }
2454}
2455
2456void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2457 LocationSummary* locations = rem->GetLocations();
2458 Location out = locations->Out();
2459 Location first = locations->InAt(0);
2460 Location second = locations->InAt(1);
2461
Calin Juravled2ec87d2014-12-08 14:24:46 +00002462 Primitive::Type type = rem->GetResultType();
2463 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002464 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002465 if (second.IsConstant()) {
2466 GenerateDivRemConstantIntegral(rem);
2467 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002468 Register reg1 = first.AsRegister<Register>();
2469 Register reg2 = second.AsRegister<Register>();
2470 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002471
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002472 // temp = reg1 / reg2 (integer division)
2473 // temp = temp * reg2
2474 // dest = reg1 - temp
2475 __ sdiv(temp, reg1, reg2);
2476 __ mul(temp, temp, reg2);
2477 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2478 } else {
2479 InvokeRuntimeCallingConvention calling_convention;
2480 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2481 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2482 DCHECK_EQ(R1, out.AsRegister<Register>());
2483
2484 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2485 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002486 break;
2487 }
2488
2489 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002490 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002491 break;
2492 }
2493
Calin Juravled2ec87d2014-12-08 14:24:46 +00002494 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002495 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002496 break;
2497 }
2498
Calin Juravlebacfec32014-11-14 15:54:36 +00002499 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002500 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002501 break;
2502 }
2503
2504 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002505 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002506 }
2507}
2508
Calin Juravled0d48522014-11-04 16:40:20 +00002509void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2510 LocationSummary* locations =
2511 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002512 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002513 if (instruction->HasUses()) {
2514 locations->SetOut(Location::SameAsFirstInput());
2515 }
2516}
2517
2518void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2519 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2520 codegen_->AddSlowPath(slow_path);
2521
2522 LocationSummary* locations = instruction->GetLocations();
2523 Location value = locations->InAt(0);
2524
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002525 switch (instruction->GetType()) {
2526 case Primitive::kPrimInt: {
2527 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002528 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002529 __ b(slow_path->GetEntryLabel(), EQ);
2530 } else {
2531 DCHECK(value.IsConstant()) << value;
2532 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2533 __ b(slow_path->GetEntryLabel());
2534 }
2535 }
2536 break;
2537 }
2538 case Primitive::kPrimLong: {
2539 if (value.IsRegisterPair()) {
2540 __ orrs(IP,
2541 value.AsRegisterPairLow<Register>(),
2542 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2543 __ b(slow_path->GetEntryLabel(), EQ);
2544 } else {
2545 DCHECK(value.IsConstant()) << value;
2546 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2547 __ b(slow_path->GetEntryLabel());
2548 }
2549 }
2550 break;
2551 default:
2552 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2553 }
2554 }
Calin Juravled0d48522014-11-04 16:40:20 +00002555}
2556
Calin Juravle9aec02f2014-11-18 23:06:35 +00002557void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2558 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2559
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002560 LocationSummary* locations =
2561 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002562
2563 switch (op->GetResultType()) {
2564 case Primitive::kPrimInt: {
2565 locations->SetInAt(0, Location::RequiresRegister());
2566 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002567 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002568 break;
2569 }
2570 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002571 locations->SetInAt(0, Location::RequiresRegister());
2572 locations->SetInAt(1, Location::RequiresRegister());
2573 locations->AddTemp(Location::RequiresRegister());
2574 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002575 break;
2576 }
2577 default:
2578 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2579 }
2580}
2581
2582void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2583 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2584
2585 LocationSummary* locations = op->GetLocations();
2586 Location out = locations->Out();
2587 Location first = locations->InAt(0);
2588 Location second = locations->InAt(1);
2589
2590 Primitive::Type type = op->GetResultType();
2591 switch (type) {
2592 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002593 Register out_reg = out.AsRegister<Register>();
2594 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002595 // Arm doesn't mask the shift count so we need to do it ourselves.
2596 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002597 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002598 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2599 if (op->IsShl()) {
2600 __ Lsl(out_reg, first_reg, second_reg);
2601 } else if (op->IsShr()) {
2602 __ Asr(out_reg, first_reg, second_reg);
2603 } else {
2604 __ Lsr(out_reg, first_reg, second_reg);
2605 }
2606 } else {
2607 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2608 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2609 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2610 __ Mov(out_reg, first_reg);
2611 } else if (op->IsShl()) {
2612 __ Lsl(out_reg, first_reg, shift_value);
2613 } else if (op->IsShr()) {
2614 __ Asr(out_reg, first_reg, shift_value);
2615 } else {
2616 __ Lsr(out_reg, first_reg, shift_value);
2617 }
2618 }
2619 break;
2620 }
2621 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002622 Register o_h = out.AsRegisterPairHigh<Register>();
2623 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002624
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002625 Register temp = locations->GetTemp(0).AsRegister<Register>();
2626
2627 Register high = first.AsRegisterPairHigh<Register>();
2628 Register low = first.AsRegisterPairLow<Register>();
2629
2630 Register second_reg = second.AsRegister<Register>();
2631
Calin Juravle9aec02f2014-11-18 23:06:35 +00002632 if (op->IsShl()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002633 // Shift the high part
2634 __ and_(second_reg, second_reg, ShifterOperand(63));
2635 __ Lsl(o_h, high, second_reg);
2636 // Shift the low part and `or` what overflew on the high part
2637 __ rsb(temp, second_reg, ShifterOperand(32));
2638 __ Lsr(temp, low, temp);
2639 __ orr(o_h, o_h, ShifterOperand(temp));
2640 // If the shift is > 32 bits, override the high part
2641 __ subs(temp, second_reg, ShifterOperand(32));
2642 __ it(PL);
2643 __ Lsl(o_h, low, temp, false, PL);
2644 // Shift the low part
2645 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002646 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002647 // Shift the low part
2648 __ and_(second_reg, second_reg, ShifterOperand(63));
2649 __ Lsr(o_l, low, second_reg);
2650 // Shift the high part and `or` what underflew on the low part
2651 __ rsb(temp, second_reg, ShifterOperand(32));
2652 __ Lsl(temp, high, temp);
2653 __ orr(o_l, o_l, ShifterOperand(temp));
2654 // If the shift is > 32 bits, override the low part
2655 __ subs(temp, second_reg, ShifterOperand(32));
2656 __ it(PL);
2657 __ Asr(o_l, high, temp, false, PL);
2658 // Shift the high part
2659 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002660 } else {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002661 // same as Shr except we use `Lsr`s and not `Asr`s
2662 __ and_(second_reg, second_reg, ShifterOperand(63));
2663 __ Lsr(o_l, low, second_reg);
2664 __ rsb(temp, second_reg, ShifterOperand(32));
2665 __ Lsl(temp, high, temp);
2666 __ orr(o_l, o_l, ShifterOperand(temp));
2667 __ subs(temp, second_reg, ShifterOperand(32));
2668 __ it(PL);
2669 __ Lsr(o_l, high, temp, false, PL);
2670 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002671 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002672 break;
2673 }
2674 default:
2675 LOG(FATAL) << "Unexpected operation type " << type;
2676 }
2677}
2678
2679void LocationsBuilderARM::VisitShl(HShl* shl) {
2680 HandleShift(shl);
2681}
2682
2683void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2684 HandleShift(shl);
2685}
2686
2687void LocationsBuilderARM::VisitShr(HShr* shr) {
2688 HandleShift(shr);
2689}
2690
2691void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2692 HandleShift(shr);
2693}
2694
2695void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2696 HandleShift(ushr);
2697}
2698
2699void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2700 HandleShift(ushr);
2701}
2702
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002703void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002704 LocationSummary* locations =
2705 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002706 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002707 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraye21aa422015-06-08 15:35:07 +01002708 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002709 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002710}
2711
2712void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2713 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002714 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002715 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2716 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002717 instruction->GetDexPc(),
2718 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002719}
2720
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002721void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2722 LocationSummary* locations =
2723 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2724 InvokeRuntimeCallingConvention calling_convention;
2725 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002726 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002727 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraye21aa422015-06-08 15:35:07 +01002728 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002729}
2730
2731void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2732 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002733 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002734 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2735 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002736 instruction->GetDexPc(),
2737 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002738}
2739
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002740void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002741 LocationSummary* locations =
2742 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002743 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2744 if (location.IsStackSlot()) {
2745 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2746 } else if (location.IsDoubleStackSlot()) {
2747 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002748 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002749 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002750}
2751
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002752void InstructionCodeGeneratorARM::VisitParameterValue(
2753 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002754 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002755}
2756
2757void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
2758 LocationSummary* locations =
2759 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2760 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2761}
2762
2763void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
2764 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002765}
2766
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002767void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002768 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002769 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002770 locations->SetInAt(0, Location::RequiresRegister());
2771 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002772}
2773
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002774void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2775 LocationSummary* locations = not_->GetLocations();
2776 Location out = locations->Out();
2777 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002778 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002779 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002780 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002781 break;
2782
2783 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002784 __ mvn(out.AsRegisterPairLow<Register>(),
2785 ShifterOperand(in.AsRegisterPairLow<Register>()));
2786 __ mvn(out.AsRegisterPairHigh<Register>(),
2787 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002788 break;
2789
2790 default:
2791 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2792 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002793}
2794
David Brazdil66d126e2015-04-03 16:02:44 +01002795void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
2796 LocationSummary* locations =
2797 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
2798 locations->SetInAt(0, Location::RequiresRegister());
2799 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2800}
2801
2802void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01002803 LocationSummary* locations = bool_not->GetLocations();
2804 Location out = locations->Out();
2805 Location in = locations->InAt(0);
2806 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
2807}
2808
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002809void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002810 LocationSummary* locations =
2811 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002812 switch (compare->InputAt(0)->GetType()) {
2813 case Primitive::kPrimLong: {
2814 locations->SetInAt(0, Location::RequiresRegister());
2815 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002816 // Output overlaps because it is written before doing the low comparison.
2817 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002818 break;
2819 }
2820 case Primitive::kPrimFloat:
2821 case Primitive::kPrimDouble: {
2822 locations->SetInAt(0, Location::RequiresFpuRegister());
2823 locations->SetInAt(1, Location::RequiresFpuRegister());
2824 locations->SetOut(Location::RequiresRegister());
2825 break;
2826 }
2827 default:
2828 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2829 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002830}
2831
2832void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002833 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002834 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002835 Location left = locations->InAt(0);
2836 Location right = locations->InAt(1);
2837
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002838 NearLabel less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00002839 Primitive::Type type = compare->InputAt(0)->GetType();
2840 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002841 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002842 __ cmp(left.AsRegisterPairHigh<Register>(),
2843 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002844 __ b(&less, LT);
2845 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002846 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2847 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002848 __ cmp(left.AsRegisterPairLow<Register>(),
2849 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002850 break;
2851 }
2852 case Primitive::kPrimFloat:
2853 case Primitive::kPrimDouble: {
2854 __ LoadImmediate(out, 0);
2855 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002856 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002857 } else {
2858 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2859 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2860 }
2861 __ vmstat(); // transfer FP status register to ARM APSR.
2862 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002863 break;
2864 }
2865 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002866 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002867 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002868 __ b(&done, EQ);
2869 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2870
2871 __ Bind(&greater);
2872 __ LoadImmediate(out, 1);
2873 __ b(&done);
2874
2875 __ Bind(&less);
2876 __ LoadImmediate(out, -1);
2877
2878 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002879}
2880
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002881void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002882 LocationSummary* locations =
2883 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002884 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2885 locations->SetInAt(i, Location::Any());
2886 }
2887 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002888}
2889
2890void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002891 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002892 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002893}
2894
Calin Juravle52c48962014-12-16 17:02:57 +00002895void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2896 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07002897 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00002898 switch (kind) {
2899 case MemBarrierKind::kAnyStore:
2900 case MemBarrierKind::kLoadAny:
2901 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002902 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00002903 break;
2904 }
2905 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002906 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00002907 break;
2908 }
2909 default:
2910 LOG(FATAL) << "Unexpected memory barrier " << kind;
2911 }
Kenny Root1d8199d2015-06-02 11:01:10 -07002912 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00002913}
2914
2915void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2916 uint32_t offset,
2917 Register out_lo,
2918 Register out_hi) {
2919 if (offset != 0) {
2920 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002921 __ add(IP, addr, ShifterOperand(out_lo));
2922 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002923 }
2924 __ ldrexd(out_lo, out_hi, addr);
2925}
2926
2927void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2928 uint32_t offset,
2929 Register value_lo,
2930 Register value_hi,
2931 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002932 Register temp2,
2933 HInstruction* instruction) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002934 NearLabel fail;
Calin Juravle52c48962014-12-16 17:02:57 +00002935 if (offset != 0) {
2936 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002937 __ add(IP, addr, ShifterOperand(temp1));
2938 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002939 }
2940 __ Bind(&fail);
2941 // We need a load followed by store. (The address used in a STREX instruction must
2942 // be the same as the address in the most recently executed LDREX instruction.)
2943 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002944 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002945 __ strexd(temp1, value_lo, value_hi, addr);
2946 __ cmp(temp1, ShifterOperand(0));
2947 __ b(&fail, NE);
2948}
2949
2950void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2951 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2952
Nicolas Geoffray39468442014-09-02 15:17:15 +01002953 LocationSummary* locations =
2954 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002955 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002956
Calin Juravle52c48962014-12-16 17:02:57 +00002957 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01002958 if (Primitive::IsFloatingPointType(field_type)) {
2959 locations->SetInAt(1, Location::RequiresFpuRegister());
2960 } else {
2961 locations->SetInAt(1, Location::RequiresRegister());
2962 }
2963
Calin Juravle52c48962014-12-16 17:02:57 +00002964 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002965 bool generate_volatile = field_info.IsVolatile()
2966 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002967 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002968 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002969 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2970 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002971 locations->AddTemp(Location::RequiresRegister());
2972 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002973 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002974 // Arm encoding have some additional constraints for ldrexd/strexd:
2975 // - registers need to be consecutive
2976 // - the first register should be even but not R14.
2977 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2978 // enable Arm encoding.
2979 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2980
2981 locations->AddTemp(Location::RequiresRegister());
2982 locations->AddTemp(Location::RequiresRegister());
2983 if (field_type == Primitive::kPrimDouble) {
2984 // For doubles we need two more registers to copy the value.
2985 locations->AddTemp(Location::RegisterLocation(R2));
2986 locations->AddTemp(Location::RegisterLocation(R3));
2987 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002988 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002989}
2990
Calin Juravle52c48962014-12-16 17:02:57 +00002991void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01002992 const FieldInfo& field_info,
2993 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00002994 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2995
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002996 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002997 Register base = locations->InAt(0).AsRegister<Register>();
2998 Location value = locations->InAt(1);
2999
3000 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003001 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003002 Primitive::Type field_type = field_info.GetFieldType();
3003 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3004
3005 if (is_volatile) {
3006 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3007 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003008
3009 switch (field_type) {
3010 case Primitive::kPrimBoolean:
3011 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003012 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003013 break;
3014 }
3015
3016 case Primitive::kPrimShort:
3017 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003018 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003019 break;
3020 }
3021
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003022 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003023 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00003024 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003025 break;
3026 }
3027
3028 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003029 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003030 GenerateWideAtomicStore(base, offset,
3031 value.AsRegisterPairLow<Register>(),
3032 value.AsRegisterPairHigh<Register>(),
3033 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003034 locations->GetTemp(1).AsRegister<Register>(),
3035 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003036 } else {
3037 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003038 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003039 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003040 break;
3041 }
3042
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003043 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003044 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003045 break;
3046 }
3047
3048 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003049 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003050 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003051 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3052 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3053
3054 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3055
3056 GenerateWideAtomicStore(base, offset,
3057 value_reg_lo,
3058 value_reg_hi,
3059 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003060 locations->GetTemp(3).AsRegister<Register>(),
3061 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003062 } else {
3063 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003064 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003065 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003066 break;
3067 }
3068
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003069 case Primitive::kPrimVoid:
3070 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003071 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003072 }
Calin Juravle52c48962014-12-16 17:02:57 +00003073
Calin Juravle77520bc2015-01-12 18:45:46 +00003074 // Longs and doubles are handled in the switch.
3075 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3076 codegen_->MaybeRecordImplicitNullCheck(instruction);
3077 }
3078
3079 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3080 Register temp = locations->GetTemp(0).AsRegister<Register>();
3081 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003082 codegen_->MarkGCCard(
3083 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003084 }
3085
Calin Juravle52c48962014-12-16 17:02:57 +00003086 if (is_volatile) {
3087 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3088 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003089}
3090
Calin Juravle52c48962014-12-16 17:02:57 +00003091void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3092 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003093 LocationSummary* locations =
3094 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003095 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003096
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003097 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003098 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003099 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003100 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003101
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003102 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3103 locations->SetOut(Location::RequiresFpuRegister());
3104 } else {
3105 locations->SetOut(Location::RequiresRegister(),
3106 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3107 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003108 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003109 // Arm encoding have some additional constraints for ldrexd/strexd:
3110 // - registers need to be consecutive
3111 // - the first register should be even but not R14.
3112 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3113 // enable Arm encoding.
3114 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3115 locations->AddTemp(Location::RequiresRegister());
3116 locations->AddTemp(Location::RequiresRegister());
3117 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003118}
3119
Calin Juravle52c48962014-12-16 17:02:57 +00003120void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3121 const FieldInfo& field_info) {
3122 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003123
Calin Juravle52c48962014-12-16 17:02:57 +00003124 LocationSummary* locations = instruction->GetLocations();
3125 Register base = locations->InAt(0).AsRegister<Register>();
3126 Location out = locations->Out();
3127 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003128 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003129 Primitive::Type field_type = field_info.GetFieldType();
3130 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3131
3132 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003133 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003134 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003135 break;
3136 }
3137
3138 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003139 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003140 break;
3141 }
3142
3143 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003144 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003145 break;
3146 }
3147
3148 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003149 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003150 break;
3151 }
3152
3153 case Primitive::kPrimInt:
3154 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003155 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003156 break;
3157 }
3158
3159 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003160 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003161 GenerateWideAtomicLoad(base, offset,
3162 out.AsRegisterPairLow<Register>(),
3163 out.AsRegisterPairHigh<Register>());
3164 } else {
3165 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3166 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003167 break;
3168 }
3169
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003170 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003171 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003172 break;
3173 }
3174
3175 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003176 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003177 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003178 Register lo = locations->GetTemp(0).AsRegister<Register>();
3179 Register hi = locations->GetTemp(1).AsRegister<Register>();
3180 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003181 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003182 __ vmovdrr(out_reg, lo, hi);
3183 } else {
3184 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003185 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003186 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003187 break;
3188 }
3189
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003190 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003191 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003192 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003193 }
Calin Juravle52c48962014-12-16 17:02:57 +00003194
Calin Juravle77520bc2015-01-12 18:45:46 +00003195 // Doubles are handled in the switch.
3196 if (field_type != Primitive::kPrimDouble) {
3197 codegen_->MaybeRecordImplicitNullCheck(instruction);
3198 }
3199
Calin Juravle52c48962014-12-16 17:02:57 +00003200 if (is_volatile) {
3201 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3202 }
3203}
3204
3205void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3206 HandleFieldSet(instruction, instruction->GetFieldInfo());
3207}
3208
3209void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003210 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003211}
3212
3213void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3214 HandleFieldGet(instruction, instruction->GetFieldInfo());
3215}
3216
3217void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3218 HandleFieldGet(instruction, instruction->GetFieldInfo());
3219}
3220
3221void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3222 HandleFieldGet(instruction, instruction->GetFieldInfo());
3223}
3224
3225void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3226 HandleFieldGet(instruction, instruction->GetFieldInfo());
3227}
3228
3229void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3230 HandleFieldSet(instruction, instruction->GetFieldInfo());
3231}
3232
3233void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003234 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003235}
3236
3237void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003238 LocationSummary* locations =
3239 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003240 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003241 if (instruction->HasUses()) {
3242 locations->SetOut(Location::SameAsFirstInput());
3243 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003244}
3245
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003246void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003247 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3248 return;
3249 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003250 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003251
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003252 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3253 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3254}
3255
3256void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003257 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003258 codegen_->AddSlowPath(slow_path);
3259
3260 LocationSummary* locations = instruction->GetLocations();
3261 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003262
Calin Juravle77520bc2015-01-12 18:45:46 +00003263 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
3264 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003265}
3266
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003267void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3268 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3269 GenerateImplicitNullCheck(instruction);
3270 } else {
3271 GenerateExplicitNullCheck(instruction);
3272 }
3273}
3274
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003275void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003276 LocationSummary* locations =
3277 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003278 locations->SetInAt(0, Location::RequiresRegister());
3279 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003280 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3281 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3282 } else {
3283 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3284 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003285}
3286
3287void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3288 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003289 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003290 Location index = locations->InAt(1);
3291
3292 switch (instruction->GetType()) {
3293 case Primitive::kPrimBoolean: {
3294 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003295 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003296 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003297 size_t offset =
3298 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003299 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3300 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003301 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003302 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3303 }
3304 break;
3305 }
3306
3307 case Primitive::kPrimByte: {
3308 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003309 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003310 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003311 size_t offset =
3312 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003313 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3314 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003315 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003316 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3317 }
3318 break;
3319 }
3320
3321 case Primitive::kPrimShort: {
3322 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003323 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003324 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003325 size_t offset =
3326 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003327 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3328 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003329 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003330 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3331 }
3332 break;
3333 }
3334
3335 case Primitive::kPrimChar: {
3336 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003337 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003338 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003339 size_t offset =
3340 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003341 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3342 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003343 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003344 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3345 }
3346 break;
3347 }
3348
3349 case Primitive::kPrimInt:
3350 case Primitive::kPrimNot: {
3351 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3352 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003353 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003354 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003355 size_t offset =
3356 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003357 __ LoadFromOffset(kLoadWord, out, obj, offset);
3358 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003359 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003360 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3361 }
3362 break;
3363 }
3364
3365 case Primitive::kPrimLong: {
3366 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003367 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003368 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003369 size_t offset =
3370 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003371 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003372 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003373 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003374 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003375 }
3376 break;
3377 }
3378
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003379 case Primitive::kPrimFloat: {
3380 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3381 Location out = locations->Out();
3382 DCHECK(out.IsFpuRegister());
3383 if (index.IsConstant()) {
3384 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3385 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3386 } else {
3387 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3388 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3389 }
3390 break;
3391 }
3392
3393 case Primitive::kPrimDouble: {
3394 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3395 Location out = locations->Out();
3396 DCHECK(out.IsFpuRegisterPair());
3397 if (index.IsConstant()) {
3398 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3399 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3400 } else {
3401 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3402 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3403 }
3404 break;
3405 }
3406
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003407 case Primitive::kPrimVoid:
3408 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003409 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003410 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003411 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003412}
3413
3414void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003415 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003416
3417 bool needs_write_barrier =
3418 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3419 bool needs_runtime_call = instruction->NeedsTypeCheck();
3420
Nicolas Geoffray39468442014-09-02 15:17:15 +01003421 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003422 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3423 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003424 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003425 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3426 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3427 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003428 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003429 locations->SetInAt(0, Location::RequiresRegister());
3430 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003431 if (Primitive::IsFloatingPointType(value_type)) {
3432 locations->SetInAt(2, Location::RequiresFpuRegister());
3433 } else {
3434 locations->SetInAt(2, Location::RequiresRegister());
3435 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003436
3437 if (needs_write_barrier) {
3438 // Temporary registers for the write barrier.
3439 locations->AddTemp(Location::RequiresRegister());
3440 locations->AddTemp(Location::RequiresRegister());
3441 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003442 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003443}
3444
3445void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3446 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003447 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003448 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003449 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003450 bool needs_runtime_call = locations->WillCall();
3451 bool needs_write_barrier =
3452 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003453
3454 switch (value_type) {
3455 case Primitive::kPrimBoolean:
3456 case Primitive::kPrimByte: {
3457 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003458 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003459 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003460 size_t offset =
3461 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003462 __ StoreToOffset(kStoreByte, value, obj, offset);
3463 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003464 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003465 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3466 }
3467 break;
3468 }
3469
3470 case Primitive::kPrimShort:
3471 case Primitive::kPrimChar: {
3472 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003473 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003474 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003475 size_t offset =
3476 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003477 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3478 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003479 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003480 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3481 }
3482 break;
3483 }
3484
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003485 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003486 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003487 if (!needs_runtime_call) {
3488 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003489 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003490 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003491 size_t offset =
3492 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003493 __ StoreToOffset(kStoreWord, value, obj, offset);
3494 } else {
3495 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003496 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003497 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3498 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003499 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003500 if (needs_write_barrier) {
3501 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003502 Register temp = locations->GetTemp(0).AsRegister<Register>();
3503 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003504 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003505 }
3506 } else {
3507 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003508 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3509 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003510 instruction->GetDexPc(),
3511 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003512 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003513 break;
3514 }
3515
3516 case Primitive::kPrimLong: {
3517 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003518 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003519 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003520 size_t offset =
3521 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003522 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003523 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003524 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003525 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003526 }
3527 break;
3528 }
3529
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003530 case Primitive::kPrimFloat: {
3531 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3532 Location value = locations->InAt(2);
3533 DCHECK(value.IsFpuRegister());
3534 if (index.IsConstant()) {
3535 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3536 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3537 } else {
3538 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3539 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3540 }
3541 break;
3542 }
3543
3544 case Primitive::kPrimDouble: {
3545 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3546 Location value = locations->InAt(2);
3547 DCHECK(value.IsFpuRegisterPair());
3548 if (index.IsConstant()) {
3549 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3550 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3551 } else {
3552 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3553 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3554 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003555
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003556 break;
3557 }
3558
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003559 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003560 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003561 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003562 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003563
3564 // Ints and objects are handled in the switch.
3565 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3566 codegen_->MaybeRecordImplicitNullCheck(instruction);
3567 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003568}
3569
3570void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003571 LocationSummary* locations =
3572 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003573 locations->SetInAt(0, Location::RequiresRegister());
3574 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003575}
3576
3577void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3578 LocationSummary* locations = instruction->GetLocations();
3579 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003580 Register obj = locations->InAt(0).AsRegister<Register>();
3581 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003582 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003583 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003584}
3585
3586void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003587 LocationSummary* locations =
3588 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003589 locations->SetInAt(0, Location::RequiresRegister());
3590 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003591 if (instruction->HasUses()) {
3592 locations->SetOut(Location::SameAsFirstInput());
3593 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003594}
3595
3596void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3597 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003598 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003599 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003600 codegen_->AddSlowPath(slow_path);
3601
Roland Levillain271ab9c2014-11-27 15:23:57 +00003602 Register index = locations->InAt(0).AsRegister<Register>();
3603 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003604
3605 __ cmp(index, ShifterOperand(length));
3606 __ b(slow_path->GetEntryLabel(), CS);
3607}
3608
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003609void CodeGeneratorARM::MarkGCCard(Register temp,
3610 Register card,
3611 Register object,
3612 Register value,
3613 bool can_be_null) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00003614 NearLabel is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003615 if (can_be_null) {
3616 __ CompareAndBranchIfZero(value, &is_null);
3617 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003618 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3619 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3620 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003621 if (can_be_null) {
3622 __ Bind(&is_null);
3623 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003624}
3625
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003626void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3627 temp->SetLocations(nullptr);
3628}
3629
3630void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3631 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003632 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003633}
3634
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003635void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003636 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003637 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003638}
3639
3640void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003641 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3642}
3643
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003644void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3645 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3646}
3647
3648void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003649 HBasicBlock* block = instruction->GetBlock();
3650 if (block->GetLoopInformation() != nullptr) {
3651 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3652 // The back edge will generate the suspend check.
3653 return;
3654 }
3655 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3656 // The goto will generate the suspend check.
3657 return;
3658 }
3659 GenerateSuspendCheck(instruction, nullptr);
3660}
3661
3662void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3663 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003664 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003665 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3666 if (slow_path == nullptr) {
3667 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3668 instruction->SetSlowPath(slow_path);
3669 codegen_->AddSlowPath(slow_path);
3670 if (successor != nullptr) {
3671 DCHECK(successor->IsLoopHeader());
3672 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3673 }
3674 } else {
3675 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3676 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003677
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003678 __ LoadFromOffset(
3679 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3680 __ cmp(IP, ShifterOperand(0));
3681 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003682 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003683 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003684 __ Bind(slow_path->GetReturnLabel());
3685 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003686 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003687 __ b(slow_path->GetEntryLabel());
3688 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003689}
3690
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003691ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3692 return codegen_->GetAssembler();
3693}
3694
3695void ParallelMoveResolverARM::EmitMove(size_t index) {
3696 MoveOperands* move = moves_.Get(index);
3697 Location source = move->GetSource();
3698 Location destination = move->GetDestination();
3699
3700 if (source.IsRegister()) {
3701 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003702 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003703 } else {
3704 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003705 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003706 SP, destination.GetStackIndex());
3707 }
3708 } else if (source.IsStackSlot()) {
3709 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003710 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003711 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003712 } else if (destination.IsFpuRegister()) {
3713 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003714 } else {
3715 DCHECK(destination.IsStackSlot());
3716 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3717 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3718 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003719 } else if (source.IsFpuRegister()) {
3720 if (destination.IsFpuRegister()) {
3721 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003722 } else {
3723 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003724 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3725 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003726 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003727 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003728 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3729 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003730 } else if (destination.IsRegisterPair()) {
3731 DCHECK(ExpectedPairLayout(destination));
3732 __ LoadFromOffset(
3733 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3734 } else {
3735 DCHECK(destination.IsFpuRegisterPair()) << destination;
3736 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3737 SP,
3738 source.GetStackIndex());
3739 }
3740 } else if (source.IsRegisterPair()) {
3741 if (destination.IsRegisterPair()) {
3742 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3743 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3744 } else {
3745 DCHECK(destination.IsDoubleStackSlot()) << destination;
3746 DCHECK(ExpectedPairLayout(source));
3747 __ StoreToOffset(
3748 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3749 }
3750 } else if (source.IsFpuRegisterPair()) {
3751 if (destination.IsFpuRegisterPair()) {
3752 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3753 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3754 } else {
3755 DCHECK(destination.IsDoubleStackSlot()) << destination;
3756 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3757 SP,
3758 destination.GetStackIndex());
3759 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003760 } else {
3761 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003762 HConstant* constant = source.GetConstant();
3763 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3764 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003765 if (destination.IsRegister()) {
3766 __ LoadImmediate(destination.AsRegister<Register>(), value);
3767 } else {
3768 DCHECK(destination.IsStackSlot());
3769 __ LoadImmediate(IP, value);
3770 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3771 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003772 } else if (constant->IsLongConstant()) {
3773 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003774 if (destination.IsRegisterPair()) {
3775 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3776 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003777 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003778 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003779 __ LoadImmediate(IP, Low32Bits(value));
3780 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3781 __ LoadImmediate(IP, High32Bits(value));
3782 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3783 }
3784 } else if (constant->IsDoubleConstant()) {
3785 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003786 if (destination.IsFpuRegisterPair()) {
3787 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003788 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003789 DCHECK(destination.IsDoubleStackSlot()) << destination;
3790 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003791 __ LoadImmediate(IP, Low32Bits(int_value));
3792 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3793 __ LoadImmediate(IP, High32Bits(int_value));
3794 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3795 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003796 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003797 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003798 float value = constant->AsFloatConstant()->GetValue();
3799 if (destination.IsFpuRegister()) {
3800 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3801 } else {
3802 DCHECK(destination.IsStackSlot());
3803 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3804 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3805 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003806 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003807 }
3808}
3809
3810void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3811 __ Mov(IP, reg);
3812 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3813 __ StoreToOffset(kStoreWord, IP, SP, mem);
3814}
3815
3816void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3817 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3818 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3819 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3820 SP, mem1 + stack_offset);
3821 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3822 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3823 SP, mem2 + stack_offset);
3824 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3825}
3826
3827void ParallelMoveResolverARM::EmitSwap(size_t index) {
3828 MoveOperands* move = moves_.Get(index);
3829 Location source = move->GetSource();
3830 Location destination = move->GetDestination();
3831
3832 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003833 DCHECK_NE(source.AsRegister<Register>(), IP);
3834 DCHECK_NE(destination.AsRegister<Register>(), IP);
3835 __ Mov(IP, source.AsRegister<Register>());
3836 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3837 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003838 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003839 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003840 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003841 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003842 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3843 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003844 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003845 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003846 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003847 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003848 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003849 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003850 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003851 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003852 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3853 destination.AsRegisterPairHigh<Register>(),
3854 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003855 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003856 Register low_reg = source.IsRegisterPair()
3857 ? source.AsRegisterPairLow<Register>()
3858 : destination.AsRegisterPairLow<Register>();
3859 int mem = source.IsRegisterPair()
3860 ? destination.GetStackIndex()
3861 : source.GetStackIndex();
3862 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003863 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003864 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003865 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003866 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003867 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3868 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003869 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003870 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003871 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003872 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3873 DRegister reg = source.IsFpuRegisterPair()
3874 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3875 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3876 int mem = source.IsFpuRegisterPair()
3877 ? destination.GetStackIndex()
3878 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003879 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003880 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003881 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003882 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3883 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3884 : destination.AsFpuRegister<SRegister>();
3885 int mem = source.IsFpuRegister()
3886 ? destination.GetStackIndex()
3887 : source.GetStackIndex();
3888
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003889 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003890 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003891 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003892 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003893 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3894 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003895 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003896 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003897 }
3898}
3899
3900void ParallelMoveResolverARM::SpillScratch(int reg) {
3901 __ Push(static_cast<Register>(reg));
3902}
3903
3904void ParallelMoveResolverARM::RestoreScratch(int reg) {
3905 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003906}
3907
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003908void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003909 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3910 ? LocationSummary::kCallOnSlowPath
3911 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003912 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003913 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003914 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003915 locations->SetOut(Location::RequiresRegister());
3916}
3917
3918void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003919 LocationSummary* locations = cls->GetLocations();
3920 Register out = locations->Out().AsRegister<Register>();
3921 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003922 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003923 DCHECK(!cls->CanCallRuntime());
3924 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003925 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07003926 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003927 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003928 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003929 __ LoadFromOffset(kLoadWord,
3930 out,
3931 current_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -07003932 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003933 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003934
3935 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3936 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3937 codegen_->AddSlowPath(slow_path);
3938 __ cmp(out, ShifterOperand(0));
3939 __ b(slow_path->GetEntryLabel(), EQ);
3940 if (cls->MustGenerateClinitCheck()) {
3941 GenerateClassInitializationCheck(slow_path, out);
3942 } else {
3943 __ Bind(slow_path->GetExitLabel());
3944 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003945 }
3946}
3947
3948void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3949 LocationSummary* locations =
3950 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3951 locations->SetInAt(0, Location::RequiresRegister());
3952 if (check->HasUses()) {
3953 locations->SetOut(Location::SameAsFirstInput());
3954 }
3955}
3956
3957void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003958 // We assume the class is not null.
3959 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3960 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003961 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003962 GenerateClassInitializationCheck(slow_path,
3963 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003964}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003965
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003966void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3967 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003968 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3969 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3970 __ b(slow_path->GetEntryLabel(), LT);
3971 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3972 // properly. Therefore, we do a memory fence.
3973 __ dmb(ISH);
3974 __ Bind(slow_path->GetExitLabel());
3975}
3976
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003977void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3978 LocationSummary* locations =
3979 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01003980 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003981 locations->SetOut(Location::RequiresRegister());
3982}
3983
3984void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3985 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3986 codegen_->AddSlowPath(slow_path);
3987
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01003988 LocationSummary* locations = load->GetLocations();
3989 Register out = locations->Out().AsRegister<Register>();
3990 Register current_method = locations->InAt(0).AsRegister<Register>();
3991 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07003992 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08003993 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003994 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3995 __ cmp(out, ShifterOperand(0));
3996 __ b(slow_path->GetEntryLabel(), EQ);
3997 __ Bind(slow_path->GetExitLabel());
3998}
3999
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004000void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4001 LocationSummary* locations =
4002 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4003 locations->SetOut(Location::RequiresRegister());
4004}
4005
4006void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004007 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004008 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4009 __ LoadFromOffset(kLoadWord, out, TR, offset);
4010 __ LoadImmediate(IP, 0);
4011 __ StoreToOffset(kStoreWord, IP, TR, offset);
4012}
4013
4014void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4015 LocationSummary* locations =
4016 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4017 InvokeRuntimeCallingConvention calling_convention;
4018 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4019}
4020
4021void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4022 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004023 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004024}
4025
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004026void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004027 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4028 ? LocationSummary::kNoCall
4029 : LocationSummary::kCallOnSlowPath;
4030 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4031 locations->SetInAt(0, Location::RequiresRegister());
4032 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004033 // The out register is used as a temporary, so it overlaps with the inputs.
4034 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004035}
4036
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004037void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004038 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004039 Register obj = locations->InAt(0).AsRegister<Register>();
4040 Register cls = locations->InAt(1).AsRegister<Register>();
4041 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004042 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004043 NearLabel done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004044 SlowPathCodeARM* slow_path = nullptr;
4045
4046 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004047 // avoid null check if we know obj is not null.
4048 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004049 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004050 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004051 // Compare the class of `obj` with `cls`.
4052 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
4053 __ cmp(out, ShifterOperand(cls));
4054 if (instruction->IsClassFinal()) {
4055 // Classes must be equal for the instanceof to succeed.
4056 __ b(&zero, NE);
4057 __ LoadImmediate(out, 1);
4058 __ b(&done);
4059 } else {
4060 // If the classes are not equal, we go into a slow path.
4061 DCHECK(locations->OnlyCallsOnSlowPath());
4062 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004063 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004064 codegen_->AddSlowPath(slow_path);
4065 __ b(slow_path->GetEntryLabel(), NE);
4066 __ LoadImmediate(out, 1);
4067 __ b(&done);
4068 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004069
4070 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4071 __ Bind(&zero);
4072 __ LoadImmediate(out, 0);
4073 }
4074
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004075 if (slow_path != nullptr) {
4076 __ Bind(slow_path->GetExitLabel());
4077 }
4078 __ Bind(&done);
4079}
4080
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004081void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4082 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4083 instruction, LocationSummary::kCallOnSlowPath);
4084 locations->SetInAt(0, Location::RequiresRegister());
4085 locations->SetInAt(1, Location::RequiresRegister());
4086 locations->AddTemp(Location::RequiresRegister());
4087}
4088
4089void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4090 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004091 Register obj = locations->InAt(0).AsRegister<Register>();
4092 Register cls = locations->InAt(1).AsRegister<Register>();
4093 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004094 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4095
4096 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4097 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
4098 codegen_->AddSlowPath(slow_path);
4099
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004100 NearLabel done;
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004101 // avoid null check if we know obj is not null.
4102 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004103 __ CompareAndBranchIfZero(obj, &done);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004104 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004105 // Compare the class of `obj` with `cls`.
4106 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
4107 __ cmp(temp, ShifterOperand(cls));
4108 __ b(slow_path->GetEntryLabel(), NE);
4109 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004110 if (instruction->MustDoNullCheck()) {
4111 __ Bind(&done);
4112 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004113}
4114
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004115void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4116 LocationSummary* locations =
4117 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4118 InvokeRuntimeCallingConvention calling_convention;
4119 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4120}
4121
4122void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4123 codegen_->InvokeRuntime(instruction->IsEnter()
4124 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4125 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004126 instruction->GetDexPc(),
4127 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004128}
4129
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004130void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4131void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4132void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4133
4134void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4135 LocationSummary* locations =
4136 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4137 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4138 || instruction->GetResultType() == Primitive::kPrimLong);
4139 locations->SetInAt(0, Location::RequiresRegister());
4140 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004141 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004142}
4143
4144void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4145 HandleBitwiseOperation(instruction);
4146}
4147
4148void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4149 HandleBitwiseOperation(instruction);
4150}
4151
4152void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4153 HandleBitwiseOperation(instruction);
4154}
4155
4156void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4157 LocationSummary* locations = instruction->GetLocations();
4158
4159 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004160 Register first = locations->InAt(0).AsRegister<Register>();
4161 Register second = locations->InAt(1).AsRegister<Register>();
4162 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004163 if (instruction->IsAnd()) {
4164 __ and_(out, first, ShifterOperand(second));
4165 } else if (instruction->IsOr()) {
4166 __ orr(out, first, ShifterOperand(second));
4167 } else {
4168 DCHECK(instruction->IsXor());
4169 __ eor(out, first, ShifterOperand(second));
4170 }
4171 } else {
4172 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4173 Location first = locations->InAt(0);
4174 Location second = locations->InAt(1);
4175 Location out = locations->Out();
4176 if (instruction->IsAnd()) {
4177 __ and_(out.AsRegisterPairLow<Register>(),
4178 first.AsRegisterPairLow<Register>(),
4179 ShifterOperand(second.AsRegisterPairLow<Register>()));
4180 __ and_(out.AsRegisterPairHigh<Register>(),
4181 first.AsRegisterPairHigh<Register>(),
4182 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4183 } else if (instruction->IsOr()) {
4184 __ orr(out.AsRegisterPairLow<Register>(),
4185 first.AsRegisterPairLow<Register>(),
4186 ShifterOperand(second.AsRegisterPairLow<Register>()));
4187 __ orr(out.AsRegisterPairHigh<Register>(),
4188 first.AsRegisterPairHigh<Register>(),
4189 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4190 } else {
4191 DCHECK(instruction->IsXor());
4192 __ eor(out.AsRegisterPairLow<Register>(),
4193 first.AsRegisterPairLow<Register>(),
4194 ShifterOperand(second.AsRegisterPairLow<Register>()));
4195 __ eor(out.AsRegisterPairHigh<Register>(),
4196 first.AsRegisterPairHigh<Register>(),
4197 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4198 }
4199 }
4200}
4201
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004202void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004203 // TODO: Implement all kinds of calls:
4204 // 1) boot -> boot
4205 // 2) app -> boot
4206 // 3) app -> app
4207 //
4208 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4209
Jeff Hao848f70a2014-01-15 13:49:50 -08004210 if (invoke->IsStringInit()) {
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004211 Register reg = temp.AsRegister<Register>();
Jeff Hao848f70a2014-01-15 13:49:50 -08004212 // temp = thread->string_init_entrypoint
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004213 __ LoadFromOffset(kLoadWord, reg, TR, invoke->GetStringInitOffset());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004214 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004215 __ LoadFromOffset(kLoadWord, LR, reg,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004216 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004217 kArmWordSize).Int32Value());
4218 // LR()
4219 __ blx(LR);
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004220 } else if (invoke->IsRecursive()) {
4221 __ bl(GetFrameEntryLabel());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004222 } else {
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004223 Register current_method =
4224 invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()).AsRegister<Register>();
4225 Register reg = temp.AsRegister<Register>();
4226 // reg = current_method->dex_cache_resolved_methods_;
4227 __ LoadFromOffset(
4228 kLoadWord, reg, current_method, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
4229 // reg = reg[index_in_cache]
4230 __ LoadFromOffset(
4231 kLoadWord, reg, reg, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4232 // LR = reg[offset_of_quick_compiled_code]
4233 __ LoadFromOffset(kLoadWord, LR, reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4234 kArmWordSize).Int32Value());
4235 // LR()
4236 __ blx(LR);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004237 }
4238
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004239 DCHECK(!IsLeafMethod());
4240}
4241
Calin Juravleb1498f62015-02-16 13:13:29 +00004242void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4243 // Nothing to do, this should be removed during prepare for register allocator.
4244 UNUSED(instruction);
4245 LOG(FATAL) << "Unreachable";
4246}
4247
4248void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4249 // Nothing to do, this should be removed during prepare for register allocator.
4250 UNUSED(instruction);
4251 LOG(FATAL) << "Unreachable";
4252}
4253
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004254} // namespace arm
4255} // namespace art