blob: 3d3e35d0fcbc2d05520b22c2374fca7a8702cd24 [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)) {
1257 return;
1258 }
1259
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001260 HandleInvoke(invoke);
1261}
1262
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001263static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1264 if (invoke->GetLocations()->Intrinsified()) {
1265 IntrinsicCodeGeneratorARM intrinsic(codegen);
1266 intrinsic.Dispatch(invoke);
1267 return true;
1268 }
1269 return false;
1270}
1271
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001272void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001273 // When we do not run baseline, explicit clinit checks triggered by static
1274 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1275 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001276
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001277 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1278 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001279 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001280
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001281 LocationSummary* locations = invoke->GetLocations();
1282 codegen_->GenerateStaticOrDirectCall(
1283 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001284 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001285}
1286
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001287void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001288 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001289 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001290}
1291
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001292void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001293 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1294 codegen_->GetInstructionSetFeatures());
1295 if (intrinsic.TryDispatch(invoke)) {
1296 return;
1297 }
1298
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001299 HandleInvoke(invoke);
1300}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001301
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001302void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001303 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1304 return;
1305 }
1306
Roland Levillain271ab9c2014-11-27 15:23:57 +00001307 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001308 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
1309 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001310 LocationSummary* locations = invoke->GetLocations();
1311 Location receiver = locations->InAt(0);
1312 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1313 // temp = object->GetClass();
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001314 DCHECK(receiver.IsRegister());
1315 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00001316 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001317 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001318 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001319 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001320 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001321 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001322 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001323 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001324 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001325 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001326 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001327}
1328
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001329void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1330 HandleInvoke(invoke);
1331 // Add the hidden argument.
1332 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1333}
1334
1335void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1336 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001337 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001338 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1339 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001340 LocationSummary* locations = invoke->GetLocations();
1341 Location receiver = locations->InAt(0);
1342 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1343
1344 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001345 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1346 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001347
1348 // temp = object->GetClass();
1349 if (receiver.IsStackSlot()) {
1350 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1351 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1352 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001353 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001354 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001355 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001356 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001357 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001358 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001359 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1360 // LR = temp->GetEntryPoint();
1361 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1362 // LR();
1363 __ blx(LR);
1364 DCHECK(!codegen_->IsLeafMethod());
1365 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1366}
1367
Roland Levillain88cb1752014-10-20 16:36:47 +01001368void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1369 LocationSummary* locations =
1370 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1371 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001372 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001373 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001374 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1375 break;
1376 }
1377 case Primitive::kPrimLong: {
1378 locations->SetInAt(0, Location::RequiresRegister());
1379 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001380 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001381 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001382
Roland Levillain88cb1752014-10-20 16:36:47 +01001383 case Primitive::kPrimFloat:
1384 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001385 locations->SetInAt(0, Location::RequiresFpuRegister());
1386 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001387 break;
1388
1389 default:
1390 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1391 }
1392}
1393
1394void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1395 LocationSummary* locations = neg->GetLocations();
1396 Location out = locations->Out();
1397 Location in = locations->InAt(0);
1398 switch (neg->GetResultType()) {
1399 case Primitive::kPrimInt:
1400 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001401 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001402 break;
1403
1404 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001405 DCHECK(in.IsRegisterPair());
1406 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1407 __ rsbs(out.AsRegisterPairLow<Register>(),
1408 in.AsRegisterPairLow<Register>(),
1409 ShifterOperand(0));
1410 // We cannot emit an RSC (Reverse Subtract with Carry)
1411 // instruction here, as it does not exist in the Thumb-2
1412 // instruction set. We use the following approach
1413 // using SBC and SUB instead.
1414 //
1415 // out.hi = -C
1416 __ sbc(out.AsRegisterPairHigh<Register>(),
1417 out.AsRegisterPairHigh<Register>(),
1418 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1419 // out.hi = out.hi - in.hi
1420 __ sub(out.AsRegisterPairHigh<Register>(),
1421 out.AsRegisterPairHigh<Register>(),
1422 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1423 break;
1424
Roland Levillain88cb1752014-10-20 16:36:47 +01001425 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001426 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001427 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001428 break;
1429
Roland Levillain88cb1752014-10-20 16:36:47 +01001430 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001431 DCHECK(in.IsFpuRegisterPair());
1432 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1433 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001434 break;
1435
1436 default:
1437 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1438 }
1439}
1440
Roland Levillaindff1f282014-11-05 14:15:05 +00001441void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001442 Primitive::Type result_type = conversion->GetResultType();
1443 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001444 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001445
Roland Levillain5b3ee562015-04-14 16:02:41 +01001446 // The float-to-long, double-to-long and long-to-float type conversions
1447 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001448 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001449 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1450 && result_type == Primitive::kPrimLong)
1451 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001452 ? LocationSummary::kCall
1453 : LocationSummary::kNoCall;
1454 LocationSummary* locations =
1455 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1456
David Brazdilb2bd1c52015-03-25 11:17:37 +00001457 // The Java language does not allow treating boolean as an integral type but
1458 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001459
Roland Levillaindff1f282014-11-05 14:15:05 +00001460 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001461 case Primitive::kPrimByte:
1462 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001463 case Primitive::kPrimBoolean:
1464 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001465 case Primitive::kPrimShort:
1466 case Primitive::kPrimInt:
1467 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001468 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001469 locations->SetInAt(0, Location::RequiresRegister());
1470 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1471 break;
1472
1473 default:
1474 LOG(FATAL) << "Unexpected type conversion from " << input_type
1475 << " to " << result_type;
1476 }
1477 break;
1478
Roland Levillain01a8d712014-11-14 16:27:39 +00001479 case Primitive::kPrimShort:
1480 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001481 case Primitive::kPrimBoolean:
1482 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001483 case Primitive::kPrimByte:
1484 case Primitive::kPrimInt:
1485 case Primitive::kPrimChar:
1486 // Processing a Dex `int-to-short' instruction.
1487 locations->SetInAt(0, Location::RequiresRegister());
1488 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1489 break;
1490
1491 default:
1492 LOG(FATAL) << "Unexpected type conversion from " << input_type
1493 << " to " << result_type;
1494 }
1495 break;
1496
Roland Levillain946e1432014-11-11 17:35:19 +00001497 case Primitive::kPrimInt:
1498 switch (input_type) {
1499 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001500 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001501 locations->SetInAt(0, Location::Any());
1502 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1503 break;
1504
1505 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001506 // Processing a Dex `float-to-int' instruction.
1507 locations->SetInAt(0, Location::RequiresFpuRegister());
1508 locations->SetOut(Location::RequiresRegister());
1509 locations->AddTemp(Location::RequiresFpuRegister());
1510 break;
1511
Roland Levillain946e1432014-11-11 17:35:19 +00001512 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001513 // Processing a Dex `double-to-int' instruction.
1514 locations->SetInAt(0, Location::RequiresFpuRegister());
1515 locations->SetOut(Location::RequiresRegister());
1516 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001517 break;
1518
1519 default:
1520 LOG(FATAL) << "Unexpected type conversion from " << input_type
1521 << " to " << result_type;
1522 }
1523 break;
1524
Roland Levillaindff1f282014-11-05 14:15:05 +00001525 case Primitive::kPrimLong:
1526 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001527 case Primitive::kPrimBoolean:
1528 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001529 case Primitive::kPrimByte:
1530 case Primitive::kPrimShort:
1531 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001532 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001533 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001534 locations->SetInAt(0, Location::RequiresRegister());
1535 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1536 break;
1537
Roland Levillain624279f2014-12-04 11:54:28 +00001538 case Primitive::kPrimFloat: {
1539 // Processing a Dex `float-to-long' instruction.
1540 InvokeRuntimeCallingConvention calling_convention;
1541 locations->SetInAt(0, Location::FpuRegisterLocation(
1542 calling_convention.GetFpuRegisterAt(0)));
1543 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1544 break;
1545 }
1546
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001547 case Primitive::kPrimDouble: {
1548 // Processing a Dex `double-to-long' instruction.
1549 InvokeRuntimeCallingConvention calling_convention;
1550 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1551 calling_convention.GetFpuRegisterAt(0),
1552 calling_convention.GetFpuRegisterAt(1)));
1553 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001554 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001555 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001556
1557 default:
1558 LOG(FATAL) << "Unexpected type conversion from " << input_type
1559 << " to " << result_type;
1560 }
1561 break;
1562
Roland Levillain981e4542014-11-14 11:47:14 +00001563 case Primitive::kPrimChar:
1564 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001565 case Primitive::kPrimBoolean:
1566 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001567 case Primitive::kPrimByte:
1568 case Primitive::kPrimShort:
1569 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001570 // Processing a Dex `int-to-char' instruction.
1571 locations->SetInAt(0, Location::RequiresRegister());
1572 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1573 break;
1574
1575 default:
1576 LOG(FATAL) << "Unexpected type conversion from " << input_type
1577 << " to " << result_type;
1578 }
1579 break;
1580
Roland Levillaindff1f282014-11-05 14:15:05 +00001581 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001582 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001583 case Primitive::kPrimBoolean:
1584 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001585 case Primitive::kPrimByte:
1586 case Primitive::kPrimShort:
1587 case Primitive::kPrimInt:
1588 case Primitive::kPrimChar:
1589 // Processing a Dex `int-to-float' instruction.
1590 locations->SetInAt(0, Location::RequiresRegister());
1591 locations->SetOut(Location::RequiresFpuRegister());
1592 break;
1593
Roland Levillain5b3ee562015-04-14 16:02:41 +01001594 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001595 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001596 InvokeRuntimeCallingConvention calling_convention;
1597 locations->SetInAt(0, Location::RegisterPairLocation(
1598 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1599 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001600 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001601 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001602
Roland Levillaincff13742014-11-17 14:32:17 +00001603 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001604 // Processing a Dex `double-to-float' instruction.
1605 locations->SetInAt(0, Location::RequiresFpuRegister());
1606 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001607 break;
1608
1609 default:
1610 LOG(FATAL) << "Unexpected type conversion from " << input_type
1611 << " to " << result_type;
1612 };
1613 break;
1614
Roland Levillaindff1f282014-11-05 14:15:05 +00001615 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001616 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001617 case Primitive::kPrimBoolean:
1618 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001619 case Primitive::kPrimByte:
1620 case Primitive::kPrimShort:
1621 case Primitive::kPrimInt:
1622 case Primitive::kPrimChar:
1623 // Processing a Dex `int-to-double' instruction.
1624 locations->SetInAt(0, Location::RequiresRegister());
1625 locations->SetOut(Location::RequiresFpuRegister());
1626 break;
1627
1628 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001629 // Processing a Dex `long-to-double' instruction.
1630 locations->SetInAt(0, Location::RequiresRegister());
1631 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01001632 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00001633 locations->AddTemp(Location::RequiresFpuRegister());
1634 break;
1635
Roland Levillaincff13742014-11-17 14:32:17 +00001636 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001637 // Processing a Dex `float-to-double' instruction.
1638 locations->SetInAt(0, Location::RequiresFpuRegister());
1639 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001640 break;
1641
1642 default:
1643 LOG(FATAL) << "Unexpected type conversion from " << input_type
1644 << " to " << result_type;
1645 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001646 break;
1647
1648 default:
1649 LOG(FATAL) << "Unexpected type conversion from " << input_type
1650 << " to " << result_type;
1651 }
1652}
1653
1654void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1655 LocationSummary* locations = conversion->GetLocations();
1656 Location out = locations->Out();
1657 Location in = locations->InAt(0);
1658 Primitive::Type result_type = conversion->GetResultType();
1659 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001660 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001661 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001662 case Primitive::kPrimByte:
1663 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001664 case Primitive::kPrimBoolean:
1665 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001666 case Primitive::kPrimShort:
1667 case Primitive::kPrimInt:
1668 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001669 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001670 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001671 break;
1672
1673 default:
1674 LOG(FATAL) << "Unexpected type conversion from " << input_type
1675 << " to " << result_type;
1676 }
1677 break;
1678
Roland Levillain01a8d712014-11-14 16:27:39 +00001679 case Primitive::kPrimShort:
1680 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001681 case Primitive::kPrimBoolean:
1682 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001683 case Primitive::kPrimByte:
1684 case Primitive::kPrimInt:
1685 case Primitive::kPrimChar:
1686 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001687 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001688 break;
1689
1690 default:
1691 LOG(FATAL) << "Unexpected type conversion from " << input_type
1692 << " to " << result_type;
1693 }
1694 break;
1695
Roland Levillain946e1432014-11-11 17:35:19 +00001696 case Primitive::kPrimInt:
1697 switch (input_type) {
1698 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001699 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001700 DCHECK(out.IsRegister());
1701 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001702 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001703 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001704 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001705 } else {
1706 DCHECK(in.IsConstant());
1707 DCHECK(in.GetConstant()->IsLongConstant());
1708 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001709 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001710 }
1711 break;
1712
Roland Levillain3f8f9362014-12-02 17:45:01 +00001713 case Primitive::kPrimFloat: {
1714 // Processing a Dex `float-to-int' instruction.
1715 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1716 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1717 __ vcvtis(temp, temp);
1718 __ vmovrs(out.AsRegister<Register>(), temp);
1719 break;
1720 }
1721
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001722 case Primitive::kPrimDouble: {
1723 // Processing a Dex `double-to-int' instruction.
1724 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1725 DRegister temp_d = FromLowSToD(temp_s);
1726 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1727 __ vcvtid(temp_s, temp_d);
1728 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001729 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001730 }
Roland Levillain946e1432014-11-11 17:35:19 +00001731
1732 default:
1733 LOG(FATAL) << "Unexpected type conversion from " << input_type
1734 << " to " << result_type;
1735 }
1736 break;
1737
Roland Levillaindff1f282014-11-05 14:15:05 +00001738 case Primitive::kPrimLong:
1739 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001740 case Primitive::kPrimBoolean:
1741 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001742 case Primitive::kPrimByte:
1743 case Primitive::kPrimShort:
1744 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001745 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001746 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001747 DCHECK(out.IsRegisterPair());
1748 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001749 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001750 // Sign extension.
1751 __ Asr(out.AsRegisterPairHigh<Register>(),
1752 out.AsRegisterPairLow<Register>(),
1753 31);
1754 break;
1755
1756 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001757 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001758 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1759 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001760 conversion->GetDexPc(),
1761 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001762 break;
1763
Roland Levillaindff1f282014-11-05 14:15:05 +00001764 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001765 // Processing a Dex `double-to-long' instruction.
1766 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1767 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001768 conversion->GetDexPc(),
1769 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001770 break;
1771
1772 default:
1773 LOG(FATAL) << "Unexpected type conversion from " << input_type
1774 << " to " << result_type;
1775 }
1776 break;
1777
Roland Levillain981e4542014-11-14 11:47:14 +00001778 case Primitive::kPrimChar:
1779 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001780 case Primitive::kPrimBoolean:
1781 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001782 case Primitive::kPrimByte:
1783 case Primitive::kPrimShort:
1784 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001785 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001786 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001787 break;
1788
1789 default:
1790 LOG(FATAL) << "Unexpected type conversion from " << input_type
1791 << " to " << result_type;
1792 }
1793 break;
1794
Roland Levillaindff1f282014-11-05 14:15:05 +00001795 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001796 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001797 case Primitive::kPrimBoolean:
1798 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001799 case Primitive::kPrimByte:
1800 case Primitive::kPrimShort:
1801 case Primitive::kPrimInt:
1802 case Primitive::kPrimChar: {
1803 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001804 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1805 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001806 break;
1807 }
1808
Roland Levillain5b3ee562015-04-14 16:02:41 +01001809 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001810 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001811 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
1812 conversion,
1813 conversion->GetDexPc(),
1814 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001815 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00001816
Roland Levillaincff13742014-11-17 14:32:17 +00001817 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001818 // Processing a Dex `double-to-float' instruction.
1819 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1820 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001821 break;
1822
1823 default:
1824 LOG(FATAL) << "Unexpected type conversion from " << input_type
1825 << " to " << result_type;
1826 };
1827 break;
1828
Roland Levillaindff1f282014-11-05 14:15:05 +00001829 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001830 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001831 case Primitive::kPrimBoolean:
1832 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001833 case Primitive::kPrimByte:
1834 case Primitive::kPrimShort:
1835 case Primitive::kPrimInt:
1836 case Primitive::kPrimChar: {
1837 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001838 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001839 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1840 out.AsFpuRegisterPairLow<SRegister>());
1841 break;
1842 }
1843
Roland Levillain647b9ed2014-11-27 12:06:00 +00001844 case Primitive::kPrimLong: {
1845 // Processing a Dex `long-to-double' instruction.
1846 Register low = in.AsRegisterPairLow<Register>();
1847 Register high = in.AsRegisterPairHigh<Register>();
1848 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1849 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001850 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001851 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001852 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
1853 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001854
Roland Levillain682393c2015-04-14 15:57:52 +01001855 // temp_d = int-to-double(high)
1856 __ vmovsr(temp_s, high);
1857 __ vcvtdi(temp_d, temp_s);
1858 // constant_d = k2Pow32EncodingForDouble
1859 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
1860 // out_d = unsigned-to-double(low)
1861 __ vmovsr(out_s, low);
1862 __ vcvtdu(out_d, out_s);
1863 // out_d += temp_d * constant_d
1864 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001865 break;
1866 }
1867
Roland Levillaincff13742014-11-17 14:32:17 +00001868 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001869 // Processing a Dex `float-to-double' instruction.
1870 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1871 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001872 break;
1873
1874 default:
1875 LOG(FATAL) << "Unexpected type conversion from " << input_type
1876 << " to " << result_type;
1877 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001878 break;
1879
1880 default:
1881 LOG(FATAL) << "Unexpected type conversion from " << input_type
1882 << " to " << result_type;
1883 }
1884}
1885
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001886void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001887 LocationSummary* locations =
1888 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001889 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001890 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001891 locations->SetInAt(0, Location::RequiresRegister());
1892 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001893 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1894 break;
1895 }
1896
1897 case Primitive::kPrimLong: {
1898 locations->SetInAt(0, Location::RequiresRegister());
1899 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001900 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001901 break;
1902 }
1903
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001904 case Primitive::kPrimFloat:
1905 case Primitive::kPrimDouble: {
1906 locations->SetInAt(0, Location::RequiresFpuRegister());
1907 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001908 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001909 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001910 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001911
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001912 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001913 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001914 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001915}
1916
1917void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1918 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001919 Location out = locations->Out();
1920 Location first = locations->InAt(0);
1921 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001922 switch (add->GetResultType()) {
1923 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001924 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001925 __ add(out.AsRegister<Register>(),
1926 first.AsRegister<Register>(),
1927 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001928 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001929 __ AddConstant(out.AsRegister<Register>(),
1930 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001931 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001932 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001933 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001934
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001935 case Primitive::kPrimLong: {
1936 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001937 __ adds(out.AsRegisterPairLow<Register>(),
1938 first.AsRegisterPairLow<Register>(),
1939 ShifterOperand(second.AsRegisterPairLow<Register>()));
1940 __ adc(out.AsRegisterPairHigh<Register>(),
1941 first.AsRegisterPairHigh<Register>(),
1942 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001943 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001944 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001945
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001946 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001947 __ vadds(out.AsFpuRegister<SRegister>(),
1948 first.AsFpuRegister<SRegister>(),
1949 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001950 break;
1951
1952 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001953 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1954 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1955 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001956 break;
1957
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001958 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001959 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001960 }
1961}
1962
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001963void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001964 LocationSummary* locations =
1965 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001966 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001967 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001968 locations->SetInAt(0, Location::RequiresRegister());
1969 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001970 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1971 break;
1972 }
1973
1974 case Primitive::kPrimLong: {
1975 locations->SetInAt(0, Location::RequiresRegister());
1976 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001977 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001978 break;
1979 }
Calin Juravle11351682014-10-23 15:38:15 +01001980 case Primitive::kPrimFloat:
1981 case Primitive::kPrimDouble: {
1982 locations->SetInAt(0, Location::RequiresFpuRegister());
1983 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001984 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001985 break;
Calin Juravle11351682014-10-23 15:38:15 +01001986 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001987 default:
Calin Juravle11351682014-10-23 15:38:15 +01001988 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001989 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001990}
1991
1992void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1993 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001994 Location out = locations->Out();
1995 Location first = locations->InAt(0);
1996 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001997 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001998 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001999 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002000 __ sub(out.AsRegister<Register>(),
2001 first.AsRegister<Register>(),
2002 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002003 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002004 __ AddConstant(out.AsRegister<Register>(),
2005 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002006 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002007 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002008 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002009 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002010
Calin Juravle11351682014-10-23 15:38:15 +01002011 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002012 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002013 __ subs(out.AsRegisterPairLow<Register>(),
2014 first.AsRegisterPairLow<Register>(),
2015 ShifterOperand(second.AsRegisterPairLow<Register>()));
2016 __ sbc(out.AsRegisterPairHigh<Register>(),
2017 first.AsRegisterPairHigh<Register>(),
2018 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002019 break;
Calin Juravle11351682014-10-23 15:38:15 +01002020 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002021
Calin Juravle11351682014-10-23 15:38:15 +01002022 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002023 __ vsubs(out.AsFpuRegister<SRegister>(),
2024 first.AsFpuRegister<SRegister>(),
2025 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002026 break;
Calin Juravle11351682014-10-23 15:38:15 +01002027 }
2028
2029 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002030 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2031 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2032 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002033 break;
2034 }
2035
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002036
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002037 default:
Calin Juravle11351682014-10-23 15:38:15 +01002038 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002039 }
2040}
2041
Calin Juravle34bacdf2014-10-07 20:23:36 +01002042void LocationsBuilderARM::VisitMul(HMul* mul) {
2043 LocationSummary* locations =
2044 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2045 switch (mul->GetResultType()) {
2046 case Primitive::kPrimInt:
2047 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002048 locations->SetInAt(0, Location::RequiresRegister());
2049 locations->SetInAt(1, Location::RequiresRegister());
2050 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002051 break;
2052 }
2053
Calin Juravleb5bfa962014-10-21 18:02:24 +01002054 case Primitive::kPrimFloat:
2055 case Primitive::kPrimDouble: {
2056 locations->SetInAt(0, Location::RequiresFpuRegister());
2057 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002058 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002059 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002060 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002061
2062 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002063 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002064 }
2065}
2066
2067void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2068 LocationSummary* locations = mul->GetLocations();
2069 Location out = locations->Out();
2070 Location first = locations->InAt(0);
2071 Location second = locations->InAt(1);
2072 switch (mul->GetResultType()) {
2073 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002074 __ mul(out.AsRegister<Register>(),
2075 first.AsRegister<Register>(),
2076 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002077 break;
2078 }
2079 case Primitive::kPrimLong: {
2080 Register out_hi = out.AsRegisterPairHigh<Register>();
2081 Register out_lo = out.AsRegisterPairLow<Register>();
2082 Register in1_hi = first.AsRegisterPairHigh<Register>();
2083 Register in1_lo = first.AsRegisterPairLow<Register>();
2084 Register in2_hi = second.AsRegisterPairHigh<Register>();
2085 Register in2_lo = second.AsRegisterPairLow<Register>();
2086
2087 // Extra checks to protect caused by the existence of R1_R2.
2088 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2089 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2090 DCHECK_NE(out_hi, in1_lo);
2091 DCHECK_NE(out_hi, in2_lo);
2092
2093 // input: in1 - 64 bits, in2 - 64 bits
2094 // output: out
2095 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2096 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2097 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2098
2099 // IP <- in1.lo * in2.hi
2100 __ mul(IP, in1_lo, in2_hi);
2101 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2102 __ mla(out_hi, in1_hi, in2_lo, IP);
2103 // out.lo <- (in1.lo * in2.lo)[31:0];
2104 __ umull(out_lo, IP, in1_lo, in2_lo);
2105 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2106 __ add(out_hi, out_hi, ShifterOperand(IP));
2107 break;
2108 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002109
2110 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002111 __ vmuls(out.AsFpuRegister<SRegister>(),
2112 first.AsFpuRegister<SRegister>(),
2113 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002114 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002115 }
2116
2117 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002118 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2119 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2120 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002121 break;
2122 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002123
2124 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002125 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002126 }
2127}
2128
Zheng Xuc6667102015-05-15 16:08:45 +08002129void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2130 DCHECK(instruction->IsDiv() || instruction->IsRem());
2131 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2132
2133 LocationSummary* locations = instruction->GetLocations();
2134 Location second = locations->InAt(1);
2135 DCHECK(second.IsConstant());
2136
2137 Register out = locations->Out().AsRegister<Register>();
2138 Register dividend = locations->InAt(0).AsRegister<Register>();
2139 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2140 DCHECK(imm == 1 || imm == -1);
2141
2142 if (instruction->IsRem()) {
2143 __ LoadImmediate(out, 0);
2144 } else {
2145 if (imm == 1) {
2146 __ Mov(out, dividend);
2147 } else {
2148 __ rsb(out, dividend, ShifterOperand(0));
2149 }
2150 }
2151}
2152
2153void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2154 DCHECK(instruction->IsDiv() || instruction->IsRem());
2155 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2156
2157 LocationSummary* locations = instruction->GetLocations();
2158 Location second = locations->InAt(1);
2159 DCHECK(second.IsConstant());
2160
2161 Register out = locations->Out().AsRegister<Register>();
2162 Register dividend = locations->InAt(0).AsRegister<Register>();
2163 Register temp = locations->GetTemp(0).AsRegister<Register>();
2164 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002165 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002166 DCHECK(IsPowerOfTwo(abs_imm));
2167 int ctz_imm = CTZ(abs_imm);
2168
2169 if (ctz_imm == 1) {
2170 __ Lsr(temp, dividend, 32 - ctz_imm);
2171 } else {
2172 __ Asr(temp, dividend, 31);
2173 __ Lsr(temp, temp, 32 - ctz_imm);
2174 }
2175 __ add(out, temp, ShifterOperand(dividend));
2176
2177 if (instruction->IsDiv()) {
2178 __ Asr(out, out, ctz_imm);
2179 if (imm < 0) {
2180 __ rsb(out, out, ShifterOperand(0));
2181 }
2182 } else {
2183 __ ubfx(out, out, 0, ctz_imm);
2184 __ sub(out, out, ShifterOperand(temp));
2185 }
2186}
2187
2188void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2189 DCHECK(instruction->IsDiv() || instruction->IsRem());
2190 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2191
2192 LocationSummary* locations = instruction->GetLocations();
2193 Location second = locations->InAt(1);
2194 DCHECK(second.IsConstant());
2195
2196 Register out = locations->Out().AsRegister<Register>();
2197 Register dividend = locations->InAt(0).AsRegister<Register>();
2198 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2199 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2200 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2201
2202 int64_t magic;
2203 int shift;
2204 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2205
2206 __ LoadImmediate(temp1, magic);
2207 __ smull(temp2, temp1, dividend, temp1);
2208
2209 if (imm > 0 && magic < 0) {
2210 __ add(temp1, temp1, ShifterOperand(dividend));
2211 } else if (imm < 0 && magic > 0) {
2212 __ sub(temp1, temp1, ShifterOperand(dividend));
2213 }
2214
2215 if (shift != 0) {
2216 __ Asr(temp1, temp1, shift);
2217 }
2218
2219 if (instruction->IsDiv()) {
2220 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2221 } else {
2222 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2223 // TODO: Strength reduction for mls.
2224 __ LoadImmediate(temp2, imm);
2225 __ mls(out, temp1, temp2, dividend);
2226 }
2227}
2228
2229void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2230 DCHECK(instruction->IsDiv() || instruction->IsRem());
2231 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2232
2233 LocationSummary* locations = instruction->GetLocations();
2234 Location second = locations->InAt(1);
2235 DCHECK(second.IsConstant());
2236
2237 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2238 if (imm == 0) {
2239 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2240 } else if (imm == 1 || imm == -1) {
2241 DivRemOneOrMinusOne(instruction);
2242 } else if (IsPowerOfTwo(std::abs(imm))) {
2243 DivRemByPowerOfTwo(instruction);
2244 } else {
2245 DCHECK(imm <= -2 || imm >= 2);
2246 GenerateDivRemWithAnyConstant(instruction);
2247 }
2248}
2249
Calin Juravle7c4954d2014-10-28 16:57:40 +00002250void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002251 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2252 if (div->GetResultType() == Primitive::kPrimLong) {
2253 // pLdiv runtime call.
2254 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002255 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2256 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002257 } else if (div->GetResultType() == Primitive::kPrimInt &&
2258 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2259 // pIdivmod runtime call.
2260 call_kind = LocationSummary::kCall;
2261 }
2262
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002263 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2264
Calin Juravle7c4954d2014-10-28 16:57:40 +00002265 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002266 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002267 if (div->InputAt(1)->IsConstant()) {
2268 locations->SetInAt(0, Location::RequiresRegister());
2269 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2270 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2271 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2272 if (abs_imm <= 1) {
2273 // No temp register required.
2274 } else {
2275 locations->AddTemp(Location::RequiresRegister());
2276 if (!IsPowerOfTwo(abs_imm)) {
2277 locations->AddTemp(Location::RequiresRegister());
2278 }
2279 }
2280 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002281 locations->SetInAt(0, Location::RequiresRegister());
2282 locations->SetInAt(1, Location::RequiresRegister());
2283 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2284 } else {
2285 InvokeRuntimeCallingConvention calling_convention;
2286 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2287 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2288 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2289 // we only need the former.
2290 locations->SetOut(Location::RegisterLocation(R0));
2291 }
Calin Juravled0d48522014-11-04 16:40:20 +00002292 break;
2293 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002294 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002295 InvokeRuntimeCallingConvention calling_convention;
2296 locations->SetInAt(0, Location::RegisterPairLocation(
2297 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2298 locations->SetInAt(1, Location::RegisterPairLocation(
2299 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002300 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002301 break;
2302 }
2303 case Primitive::kPrimFloat:
2304 case Primitive::kPrimDouble: {
2305 locations->SetInAt(0, Location::RequiresFpuRegister());
2306 locations->SetInAt(1, Location::RequiresFpuRegister());
2307 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2308 break;
2309 }
2310
2311 default:
2312 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2313 }
2314}
2315
2316void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2317 LocationSummary* locations = div->GetLocations();
2318 Location out = locations->Out();
2319 Location first = locations->InAt(0);
2320 Location second = locations->InAt(1);
2321
2322 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002323 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002324 if (second.IsConstant()) {
2325 GenerateDivRemConstantIntegral(div);
2326 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002327 __ sdiv(out.AsRegister<Register>(),
2328 first.AsRegister<Register>(),
2329 second.AsRegister<Register>());
2330 } else {
2331 InvokeRuntimeCallingConvention calling_convention;
2332 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2333 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2334 DCHECK_EQ(R0, out.AsRegister<Register>());
2335
2336 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2337 }
Calin Juravled0d48522014-11-04 16:40:20 +00002338 break;
2339 }
2340
Calin Juravle7c4954d2014-10-28 16:57:40 +00002341 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002342 InvokeRuntimeCallingConvention calling_convention;
2343 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2344 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2345 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2346 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2347 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002348 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002349
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002350 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002351 break;
2352 }
2353
2354 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002355 __ vdivs(out.AsFpuRegister<SRegister>(),
2356 first.AsFpuRegister<SRegister>(),
2357 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002358 break;
2359 }
2360
2361 case Primitive::kPrimDouble: {
2362 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2363 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2364 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2365 break;
2366 }
2367
2368 default:
2369 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2370 }
2371}
2372
Calin Juravlebacfec32014-11-14 15:54:36 +00002373void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002374 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002375
2376 // Most remainders are implemented in the runtime.
2377 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002378 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2379 // sdiv will be replaced by other instruction sequence.
2380 call_kind = LocationSummary::kNoCall;
2381 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2382 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002383 // Have hardware divide instruction for int, do it with three instructions.
2384 call_kind = LocationSummary::kNoCall;
2385 }
2386
Calin Juravlebacfec32014-11-14 15:54:36 +00002387 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2388
Calin Juravled2ec87d2014-12-08 14:24:46 +00002389 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002390 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002391 if (rem->InputAt(1)->IsConstant()) {
2392 locations->SetInAt(0, Location::RequiresRegister());
2393 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2394 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2395 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2396 if (abs_imm <= 1) {
2397 // No temp register required.
2398 } else {
2399 locations->AddTemp(Location::RequiresRegister());
2400 if (!IsPowerOfTwo(abs_imm)) {
2401 locations->AddTemp(Location::RequiresRegister());
2402 }
2403 }
2404 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002405 locations->SetInAt(0, Location::RequiresRegister());
2406 locations->SetInAt(1, Location::RequiresRegister());
2407 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2408 locations->AddTemp(Location::RequiresRegister());
2409 } else {
2410 InvokeRuntimeCallingConvention calling_convention;
2411 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2412 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2413 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2414 // we only need the latter.
2415 locations->SetOut(Location::RegisterLocation(R1));
2416 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002417 break;
2418 }
2419 case Primitive::kPrimLong: {
2420 InvokeRuntimeCallingConvention calling_convention;
2421 locations->SetInAt(0, Location::RegisterPairLocation(
2422 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2423 locations->SetInAt(1, Location::RegisterPairLocation(
2424 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2425 // The runtime helper puts the output in R2,R3.
2426 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2427 break;
2428 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002429 case Primitive::kPrimFloat: {
2430 InvokeRuntimeCallingConvention calling_convention;
2431 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2432 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2433 locations->SetOut(Location::FpuRegisterLocation(S0));
2434 break;
2435 }
2436
Calin Juravlebacfec32014-11-14 15:54:36 +00002437 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002438 InvokeRuntimeCallingConvention calling_convention;
2439 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2440 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2441 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2442 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2443 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002444 break;
2445 }
2446
2447 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002448 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002449 }
2450}
2451
2452void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2453 LocationSummary* locations = rem->GetLocations();
2454 Location out = locations->Out();
2455 Location first = locations->InAt(0);
2456 Location second = locations->InAt(1);
2457
Calin Juravled2ec87d2014-12-08 14:24:46 +00002458 Primitive::Type type = rem->GetResultType();
2459 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002460 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002461 if (second.IsConstant()) {
2462 GenerateDivRemConstantIntegral(rem);
2463 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002464 Register reg1 = first.AsRegister<Register>();
2465 Register reg2 = second.AsRegister<Register>();
2466 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002467
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002468 // temp = reg1 / reg2 (integer division)
2469 // temp = temp * reg2
2470 // dest = reg1 - temp
2471 __ sdiv(temp, reg1, reg2);
2472 __ mul(temp, temp, reg2);
2473 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2474 } else {
2475 InvokeRuntimeCallingConvention calling_convention;
2476 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2477 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2478 DCHECK_EQ(R1, out.AsRegister<Register>());
2479
2480 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2481 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002482 break;
2483 }
2484
2485 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002486 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002487 break;
2488 }
2489
Calin Juravled2ec87d2014-12-08 14:24:46 +00002490 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002491 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002492 break;
2493 }
2494
Calin Juravlebacfec32014-11-14 15:54:36 +00002495 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002496 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002497 break;
2498 }
2499
2500 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002501 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002502 }
2503}
2504
Calin Juravled0d48522014-11-04 16:40:20 +00002505void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2506 LocationSummary* locations =
2507 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002508 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002509 if (instruction->HasUses()) {
2510 locations->SetOut(Location::SameAsFirstInput());
2511 }
2512}
2513
2514void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2515 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2516 codegen_->AddSlowPath(slow_path);
2517
2518 LocationSummary* locations = instruction->GetLocations();
2519 Location value = locations->InAt(0);
2520
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002521 switch (instruction->GetType()) {
2522 case Primitive::kPrimInt: {
2523 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002524 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002525 __ b(slow_path->GetEntryLabel(), EQ);
2526 } else {
2527 DCHECK(value.IsConstant()) << value;
2528 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2529 __ b(slow_path->GetEntryLabel());
2530 }
2531 }
2532 break;
2533 }
2534 case Primitive::kPrimLong: {
2535 if (value.IsRegisterPair()) {
2536 __ orrs(IP,
2537 value.AsRegisterPairLow<Register>(),
2538 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2539 __ b(slow_path->GetEntryLabel(), EQ);
2540 } else {
2541 DCHECK(value.IsConstant()) << value;
2542 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2543 __ b(slow_path->GetEntryLabel());
2544 }
2545 }
2546 break;
2547 default:
2548 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2549 }
2550 }
Calin Juravled0d48522014-11-04 16:40:20 +00002551}
2552
Calin Juravle9aec02f2014-11-18 23:06:35 +00002553void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2554 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2555
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002556 LocationSummary* locations =
2557 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002558
2559 switch (op->GetResultType()) {
2560 case Primitive::kPrimInt: {
2561 locations->SetInAt(0, Location::RequiresRegister());
2562 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002563 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002564 break;
2565 }
2566 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002567 locations->SetInAt(0, Location::RequiresRegister());
2568 locations->SetInAt(1, Location::RequiresRegister());
2569 locations->AddTemp(Location::RequiresRegister());
2570 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002571 break;
2572 }
2573 default:
2574 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2575 }
2576}
2577
2578void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2579 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2580
2581 LocationSummary* locations = op->GetLocations();
2582 Location out = locations->Out();
2583 Location first = locations->InAt(0);
2584 Location second = locations->InAt(1);
2585
2586 Primitive::Type type = op->GetResultType();
2587 switch (type) {
2588 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002589 Register out_reg = out.AsRegister<Register>();
2590 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002591 // Arm doesn't mask the shift count so we need to do it ourselves.
2592 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002593 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002594 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2595 if (op->IsShl()) {
2596 __ Lsl(out_reg, first_reg, second_reg);
2597 } else if (op->IsShr()) {
2598 __ Asr(out_reg, first_reg, second_reg);
2599 } else {
2600 __ Lsr(out_reg, first_reg, second_reg);
2601 }
2602 } else {
2603 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2604 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2605 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2606 __ Mov(out_reg, first_reg);
2607 } else if (op->IsShl()) {
2608 __ Lsl(out_reg, first_reg, shift_value);
2609 } else if (op->IsShr()) {
2610 __ Asr(out_reg, first_reg, shift_value);
2611 } else {
2612 __ Lsr(out_reg, first_reg, shift_value);
2613 }
2614 }
2615 break;
2616 }
2617 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002618 Register o_h = out.AsRegisterPairHigh<Register>();
2619 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002620
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002621 Register temp = locations->GetTemp(0).AsRegister<Register>();
2622
2623 Register high = first.AsRegisterPairHigh<Register>();
2624 Register low = first.AsRegisterPairLow<Register>();
2625
2626 Register second_reg = second.AsRegister<Register>();
2627
Calin Juravle9aec02f2014-11-18 23:06:35 +00002628 if (op->IsShl()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002629 // Shift the high part
2630 __ and_(second_reg, second_reg, ShifterOperand(63));
2631 __ Lsl(o_h, high, second_reg);
2632 // Shift the low part and `or` what overflew on the high part
2633 __ rsb(temp, second_reg, ShifterOperand(32));
2634 __ Lsr(temp, low, temp);
2635 __ orr(o_h, o_h, ShifterOperand(temp));
2636 // If the shift is > 32 bits, override the high part
2637 __ subs(temp, second_reg, ShifterOperand(32));
2638 __ it(PL);
2639 __ Lsl(o_h, low, temp, false, PL);
2640 // Shift the low part
2641 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002642 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002643 // Shift the low part
2644 __ and_(second_reg, second_reg, ShifterOperand(63));
2645 __ Lsr(o_l, low, second_reg);
2646 // Shift the high part and `or` what underflew on the low part
2647 __ rsb(temp, second_reg, ShifterOperand(32));
2648 __ Lsl(temp, high, temp);
2649 __ orr(o_l, o_l, ShifterOperand(temp));
2650 // If the shift is > 32 bits, override the low part
2651 __ subs(temp, second_reg, ShifterOperand(32));
2652 __ it(PL);
2653 __ Asr(o_l, high, temp, false, PL);
2654 // Shift the high part
2655 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002656 } else {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002657 // same as Shr except we use `Lsr`s and not `Asr`s
2658 __ and_(second_reg, second_reg, ShifterOperand(63));
2659 __ Lsr(o_l, low, second_reg);
2660 __ rsb(temp, second_reg, ShifterOperand(32));
2661 __ Lsl(temp, high, temp);
2662 __ orr(o_l, o_l, ShifterOperand(temp));
2663 __ subs(temp, second_reg, ShifterOperand(32));
2664 __ it(PL);
2665 __ Lsr(o_l, high, temp, false, PL);
2666 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002667 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002668 break;
2669 }
2670 default:
2671 LOG(FATAL) << "Unexpected operation type " << type;
2672 }
2673}
2674
2675void LocationsBuilderARM::VisitShl(HShl* shl) {
2676 HandleShift(shl);
2677}
2678
2679void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2680 HandleShift(shl);
2681}
2682
2683void LocationsBuilderARM::VisitShr(HShr* shr) {
2684 HandleShift(shr);
2685}
2686
2687void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2688 HandleShift(shr);
2689}
2690
2691void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2692 HandleShift(ushr);
2693}
2694
2695void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2696 HandleShift(ushr);
2697}
2698
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002699void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002700 LocationSummary* locations =
2701 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002702 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002703 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002704 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002705 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002706}
2707
2708void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2709 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002710 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002711 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2712 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002713 instruction->GetDexPc(),
2714 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002715}
2716
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002717void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2718 LocationSummary* locations =
2719 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2720 InvokeRuntimeCallingConvention calling_convention;
2721 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002722 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002723 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002724 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002725}
2726
2727void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2728 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002729 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002730 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2731 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002732 instruction->GetDexPc(),
2733 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002734}
2735
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002736void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002737 LocationSummary* locations =
2738 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002739 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2740 if (location.IsStackSlot()) {
2741 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2742 } else if (location.IsDoubleStackSlot()) {
2743 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002744 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002745 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002746}
2747
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002748void InstructionCodeGeneratorARM::VisitParameterValue(
2749 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002750 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002751}
2752
2753void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
2754 LocationSummary* locations =
2755 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2756 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2757}
2758
2759void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
2760 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002761}
2762
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002763void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002764 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002765 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002766 locations->SetInAt(0, Location::RequiresRegister());
2767 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002768}
2769
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002770void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2771 LocationSummary* locations = not_->GetLocations();
2772 Location out = locations->Out();
2773 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002774 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002775 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002776 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002777 break;
2778
2779 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002780 __ mvn(out.AsRegisterPairLow<Register>(),
2781 ShifterOperand(in.AsRegisterPairLow<Register>()));
2782 __ mvn(out.AsRegisterPairHigh<Register>(),
2783 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002784 break;
2785
2786 default:
2787 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2788 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002789}
2790
David Brazdil66d126e2015-04-03 16:02:44 +01002791void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
2792 LocationSummary* locations =
2793 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
2794 locations->SetInAt(0, Location::RequiresRegister());
2795 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2796}
2797
2798void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01002799 LocationSummary* locations = bool_not->GetLocations();
2800 Location out = locations->Out();
2801 Location in = locations->InAt(0);
2802 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
2803}
2804
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002805void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002806 LocationSummary* locations =
2807 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002808 switch (compare->InputAt(0)->GetType()) {
2809 case Primitive::kPrimLong: {
2810 locations->SetInAt(0, Location::RequiresRegister());
2811 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002812 // Output overlaps because it is written before doing the low comparison.
2813 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002814 break;
2815 }
2816 case Primitive::kPrimFloat:
2817 case Primitive::kPrimDouble: {
2818 locations->SetInAt(0, Location::RequiresFpuRegister());
2819 locations->SetInAt(1, Location::RequiresFpuRegister());
2820 locations->SetOut(Location::RequiresRegister());
2821 break;
2822 }
2823 default:
2824 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2825 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002826}
2827
2828void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002829 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002830 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002831 Location left = locations->InAt(0);
2832 Location right = locations->InAt(1);
2833
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002834 NearLabel less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00002835 Primitive::Type type = compare->InputAt(0)->GetType();
2836 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002837 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002838 __ cmp(left.AsRegisterPairHigh<Register>(),
2839 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002840 __ b(&less, LT);
2841 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002842 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2843 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002844 __ cmp(left.AsRegisterPairLow<Register>(),
2845 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002846 break;
2847 }
2848 case Primitive::kPrimFloat:
2849 case Primitive::kPrimDouble: {
2850 __ LoadImmediate(out, 0);
2851 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002852 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002853 } else {
2854 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2855 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2856 }
2857 __ vmstat(); // transfer FP status register to ARM APSR.
2858 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002859 break;
2860 }
2861 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002862 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002863 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002864 __ b(&done, EQ);
2865 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2866
2867 __ Bind(&greater);
2868 __ LoadImmediate(out, 1);
2869 __ b(&done);
2870
2871 __ Bind(&less);
2872 __ LoadImmediate(out, -1);
2873
2874 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002875}
2876
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002877void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002878 LocationSummary* locations =
2879 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002880 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2881 locations->SetInAt(i, Location::Any());
2882 }
2883 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002884}
2885
2886void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002887 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002888 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002889}
2890
Calin Juravle52c48962014-12-16 17:02:57 +00002891void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2892 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07002893 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00002894 switch (kind) {
2895 case MemBarrierKind::kAnyStore:
2896 case MemBarrierKind::kLoadAny:
2897 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002898 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00002899 break;
2900 }
2901 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002902 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00002903 break;
2904 }
2905 default:
2906 LOG(FATAL) << "Unexpected memory barrier " << kind;
2907 }
Kenny Root1d8199d2015-06-02 11:01:10 -07002908 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00002909}
2910
2911void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2912 uint32_t offset,
2913 Register out_lo,
2914 Register out_hi) {
2915 if (offset != 0) {
2916 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002917 __ add(IP, addr, ShifterOperand(out_lo));
2918 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002919 }
2920 __ ldrexd(out_lo, out_hi, addr);
2921}
2922
2923void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2924 uint32_t offset,
2925 Register value_lo,
2926 Register value_hi,
2927 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002928 Register temp2,
2929 HInstruction* instruction) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002930 NearLabel fail;
Calin Juravle52c48962014-12-16 17:02:57 +00002931 if (offset != 0) {
2932 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002933 __ add(IP, addr, ShifterOperand(temp1));
2934 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002935 }
2936 __ Bind(&fail);
2937 // We need a load followed by store. (The address used in a STREX instruction must
2938 // be the same as the address in the most recently executed LDREX instruction.)
2939 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002940 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002941 __ strexd(temp1, value_lo, value_hi, addr);
2942 __ cmp(temp1, ShifterOperand(0));
2943 __ b(&fail, NE);
2944}
2945
2946void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2947 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2948
Nicolas Geoffray39468442014-09-02 15:17:15 +01002949 LocationSummary* locations =
2950 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002951 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002952
Calin Juravle52c48962014-12-16 17:02:57 +00002953 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01002954 if (Primitive::IsFloatingPointType(field_type)) {
2955 locations->SetInAt(1, Location::RequiresFpuRegister());
2956 } else {
2957 locations->SetInAt(1, Location::RequiresRegister());
2958 }
2959
Calin Juravle52c48962014-12-16 17:02:57 +00002960 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002961 bool generate_volatile = field_info.IsVolatile()
2962 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002963 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002964 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002965 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2966 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002967 locations->AddTemp(Location::RequiresRegister());
2968 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002969 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002970 // Arm encoding have some additional constraints for ldrexd/strexd:
2971 // - registers need to be consecutive
2972 // - the first register should be even but not R14.
2973 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2974 // enable Arm encoding.
2975 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2976
2977 locations->AddTemp(Location::RequiresRegister());
2978 locations->AddTemp(Location::RequiresRegister());
2979 if (field_type == Primitive::kPrimDouble) {
2980 // For doubles we need two more registers to copy the value.
2981 locations->AddTemp(Location::RegisterLocation(R2));
2982 locations->AddTemp(Location::RegisterLocation(R3));
2983 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002984 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002985}
2986
Calin Juravle52c48962014-12-16 17:02:57 +00002987void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01002988 const FieldInfo& field_info,
2989 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00002990 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2991
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002992 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002993 Register base = locations->InAt(0).AsRegister<Register>();
2994 Location value = locations->InAt(1);
2995
2996 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002997 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002998 Primitive::Type field_type = field_info.GetFieldType();
2999 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3000
3001 if (is_volatile) {
3002 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3003 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003004
3005 switch (field_type) {
3006 case Primitive::kPrimBoolean:
3007 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003008 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003009 break;
3010 }
3011
3012 case Primitive::kPrimShort:
3013 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003014 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003015 break;
3016 }
3017
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003018 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003019 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00003020 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003021 break;
3022 }
3023
3024 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003025 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003026 GenerateWideAtomicStore(base, offset,
3027 value.AsRegisterPairLow<Register>(),
3028 value.AsRegisterPairHigh<Register>(),
3029 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003030 locations->GetTemp(1).AsRegister<Register>(),
3031 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003032 } else {
3033 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003034 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003035 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003036 break;
3037 }
3038
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003039 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003040 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003041 break;
3042 }
3043
3044 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003045 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003046 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003047 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3048 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3049
3050 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3051
3052 GenerateWideAtomicStore(base, offset,
3053 value_reg_lo,
3054 value_reg_hi,
3055 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003056 locations->GetTemp(3).AsRegister<Register>(),
3057 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003058 } else {
3059 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003060 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003061 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003062 break;
3063 }
3064
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003065 case Primitive::kPrimVoid:
3066 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003067 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003068 }
Calin Juravle52c48962014-12-16 17:02:57 +00003069
Calin Juravle77520bc2015-01-12 18:45:46 +00003070 // Longs and doubles are handled in the switch.
3071 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3072 codegen_->MaybeRecordImplicitNullCheck(instruction);
3073 }
3074
3075 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3076 Register temp = locations->GetTemp(0).AsRegister<Register>();
3077 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003078 codegen_->MarkGCCard(
3079 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003080 }
3081
Calin Juravle52c48962014-12-16 17:02:57 +00003082 if (is_volatile) {
3083 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3084 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003085}
3086
Calin Juravle52c48962014-12-16 17:02:57 +00003087void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3088 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003089 LocationSummary* locations =
3090 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003091 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003092
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003093 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003094 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003095 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003096 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003097
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003098 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3099 locations->SetOut(Location::RequiresFpuRegister());
3100 } else {
3101 locations->SetOut(Location::RequiresRegister(),
3102 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3103 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003104 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003105 // Arm encoding have some additional constraints for ldrexd/strexd:
3106 // - registers need to be consecutive
3107 // - the first register should be even but not R14.
3108 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3109 // enable Arm encoding.
3110 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3111 locations->AddTemp(Location::RequiresRegister());
3112 locations->AddTemp(Location::RequiresRegister());
3113 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003114}
3115
Calin Juravle52c48962014-12-16 17:02:57 +00003116void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3117 const FieldInfo& field_info) {
3118 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003119
Calin Juravle52c48962014-12-16 17:02:57 +00003120 LocationSummary* locations = instruction->GetLocations();
3121 Register base = locations->InAt(0).AsRegister<Register>();
3122 Location out = locations->Out();
3123 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003124 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003125 Primitive::Type field_type = field_info.GetFieldType();
3126 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3127
3128 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003129 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003130 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003131 break;
3132 }
3133
3134 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003135 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003136 break;
3137 }
3138
3139 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003140 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003141 break;
3142 }
3143
3144 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003145 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003146 break;
3147 }
3148
3149 case Primitive::kPrimInt:
3150 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003151 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003152 break;
3153 }
3154
3155 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003156 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003157 GenerateWideAtomicLoad(base, offset,
3158 out.AsRegisterPairLow<Register>(),
3159 out.AsRegisterPairHigh<Register>());
3160 } else {
3161 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3162 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003163 break;
3164 }
3165
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003166 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003167 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003168 break;
3169 }
3170
3171 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003172 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003173 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003174 Register lo = locations->GetTemp(0).AsRegister<Register>();
3175 Register hi = locations->GetTemp(1).AsRegister<Register>();
3176 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003177 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003178 __ vmovdrr(out_reg, lo, hi);
3179 } else {
3180 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003181 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003182 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003183 break;
3184 }
3185
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003186 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003187 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003188 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003189 }
Calin Juravle52c48962014-12-16 17:02:57 +00003190
Calin Juravle77520bc2015-01-12 18:45:46 +00003191 // Doubles are handled in the switch.
3192 if (field_type != Primitive::kPrimDouble) {
3193 codegen_->MaybeRecordImplicitNullCheck(instruction);
3194 }
3195
Calin Juravle52c48962014-12-16 17:02:57 +00003196 if (is_volatile) {
3197 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3198 }
3199}
3200
3201void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3202 HandleFieldSet(instruction, instruction->GetFieldInfo());
3203}
3204
3205void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003206 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003207}
3208
3209void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3210 HandleFieldGet(instruction, instruction->GetFieldInfo());
3211}
3212
3213void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3214 HandleFieldGet(instruction, instruction->GetFieldInfo());
3215}
3216
3217void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3218 HandleFieldGet(instruction, instruction->GetFieldInfo());
3219}
3220
3221void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3222 HandleFieldGet(instruction, instruction->GetFieldInfo());
3223}
3224
3225void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3226 HandleFieldSet(instruction, instruction->GetFieldInfo());
3227}
3228
3229void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003230 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003231}
3232
3233void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003234 LocationSummary* locations =
3235 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003236 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003237 if (instruction->HasUses()) {
3238 locations->SetOut(Location::SameAsFirstInput());
3239 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003240}
3241
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003242void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003243 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3244 return;
3245 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003246 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003247
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003248 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3249 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3250}
3251
3252void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003253 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003254 codegen_->AddSlowPath(slow_path);
3255
3256 LocationSummary* locations = instruction->GetLocations();
3257 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003258
Calin Juravle77520bc2015-01-12 18:45:46 +00003259 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
3260 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003261}
3262
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003263void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3264 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3265 GenerateImplicitNullCheck(instruction);
3266 } else {
3267 GenerateExplicitNullCheck(instruction);
3268 }
3269}
3270
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003271void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003272 LocationSummary* locations =
3273 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003274 locations->SetInAt(0, Location::RequiresRegister());
3275 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003276 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3277 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3278 } else {
3279 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3280 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003281}
3282
3283void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3284 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003285 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003286 Location index = locations->InAt(1);
3287
3288 switch (instruction->GetType()) {
3289 case Primitive::kPrimBoolean: {
3290 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003291 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003292 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003293 size_t offset =
3294 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003295 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3296 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003297 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003298 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3299 }
3300 break;
3301 }
3302
3303 case Primitive::kPrimByte: {
3304 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003305 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003306 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003307 size_t offset =
3308 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003309 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3310 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003311 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003312 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3313 }
3314 break;
3315 }
3316
3317 case Primitive::kPrimShort: {
3318 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003319 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003320 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003321 size_t offset =
3322 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003323 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3324 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003325 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003326 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3327 }
3328 break;
3329 }
3330
3331 case Primitive::kPrimChar: {
3332 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003333 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003334 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003335 size_t offset =
3336 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003337 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3338 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003339 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003340 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3341 }
3342 break;
3343 }
3344
3345 case Primitive::kPrimInt:
3346 case Primitive::kPrimNot: {
3347 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3348 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003349 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003350 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003351 size_t offset =
3352 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003353 __ LoadFromOffset(kLoadWord, out, obj, offset);
3354 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003355 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003356 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3357 }
3358 break;
3359 }
3360
3361 case Primitive::kPrimLong: {
3362 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003363 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003364 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003365 size_t offset =
3366 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003367 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003368 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003369 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003370 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003371 }
3372 break;
3373 }
3374
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003375 case Primitive::kPrimFloat: {
3376 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3377 Location out = locations->Out();
3378 DCHECK(out.IsFpuRegister());
3379 if (index.IsConstant()) {
3380 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3381 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3382 } else {
3383 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3384 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3385 }
3386 break;
3387 }
3388
3389 case Primitive::kPrimDouble: {
3390 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3391 Location out = locations->Out();
3392 DCHECK(out.IsFpuRegisterPair());
3393 if (index.IsConstant()) {
3394 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3395 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3396 } else {
3397 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3398 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3399 }
3400 break;
3401 }
3402
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003403 case Primitive::kPrimVoid:
3404 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003405 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003406 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003407 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003408}
3409
3410void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003411 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003412
3413 bool needs_write_barrier =
3414 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3415 bool needs_runtime_call = instruction->NeedsTypeCheck();
3416
Nicolas Geoffray39468442014-09-02 15:17:15 +01003417 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003418 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3419 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003420 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003421 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3422 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3423 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003424 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003425 locations->SetInAt(0, Location::RequiresRegister());
3426 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003427 if (Primitive::IsFloatingPointType(value_type)) {
3428 locations->SetInAt(2, Location::RequiresFpuRegister());
3429 } else {
3430 locations->SetInAt(2, Location::RequiresRegister());
3431 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003432
3433 if (needs_write_barrier) {
3434 // Temporary registers for the write barrier.
3435 locations->AddTemp(Location::RequiresRegister());
3436 locations->AddTemp(Location::RequiresRegister());
3437 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003438 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003439}
3440
3441void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3442 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003443 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003444 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003445 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003446 bool needs_runtime_call = locations->WillCall();
3447 bool needs_write_barrier =
3448 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003449
3450 switch (value_type) {
3451 case Primitive::kPrimBoolean:
3452 case Primitive::kPrimByte: {
3453 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003454 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003455 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003456 size_t offset =
3457 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003458 __ StoreToOffset(kStoreByte, value, obj, offset);
3459 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003460 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003461 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3462 }
3463 break;
3464 }
3465
3466 case Primitive::kPrimShort:
3467 case Primitive::kPrimChar: {
3468 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003469 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003470 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003471 size_t offset =
3472 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003473 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3474 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003475 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003476 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3477 }
3478 break;
3479 }
3480
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003481 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003482 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003483 if (!needs_runtime_call) {
3484 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003485 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003486 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003487 size_t offset =
3488 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003489 __ StoreToOffset(kStoreWord, value, obj, offset);
3490 } else {
3491 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003492 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003493 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3494 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003495 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003496 if (needs_write_barrier) {
3497 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003498 Register temp = locations->GetTemp(0).AsRegister<Register>();
3499 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003500 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003501 }
3502 } else {
3503 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003504 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3505 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003506 instruction->GetDexPc(),
3507 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003508 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003509 break;
3510 }
3511
3512 case Primitive::kPrimLong: {
3513 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003514 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003515 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003516 size_t offset =
3517 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003518 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003519 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003520 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003521 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003522 }
3523 break;
3524 }
3525
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003526 case Primitive::kPrimFloat: {
3527 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3528 Location value = locations->InAt(2);
3529 DCHECK(value.IsFpuRegister());
3530 if (index.IsConstant()) {
3531 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3532 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3533 } else {
3534 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3535 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3536 }
3537 break;
3538 }
3539
3540 case Primitive::kPrimDouble: {
3541 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3542 Location value = locations->InAt(2);
3543 DCHECK(value.IsFpuRegisterPair());
3544 if (index.IsConstant()) {
3545 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3546 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3547 } else {
3548 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3549 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3550 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003551
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003552 break;
3553 }
3554
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003555 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003556 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003557 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003558 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003559
3560 // Ints and objects are handled in the switch.
3561 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3562 codegen_->MaybeRecordImplicitNullCheck(instruction);
3563 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003564}
3565
3566void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003567 LocationSummary* locations =
3568 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003569 locations->SetInAt(0, Location::RequiresRegister());
3570 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003571}
3572
3573void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3574 LocationSummary* locations = instruction->GetLocations();
3575 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003576 Register obj = locations->InAt(0).AsRegister<Register>();
3577 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003578 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003579 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003580}
3581
3582void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003583 LocationSummary* locations =
3584 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003585 locations->SetInAt(0, Location::RequiresRegister());
3586 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003587 if (instruction->HasUses()) {
3588 locations->SetOut(Location::SameAsFirstInput());
3589 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003590}
3591
3592void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3593 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003594 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003595 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003596 codegen_->AddSlowPath(slow_path);
3597
Roland Levillain271ab9c2014-11-27 15:23:57 +00003598 Register index = locations->InAt(0).AsRegister<Register>();
3599 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003600
3601 __ cmp(index, ShifterOperand(length));
3602 __ b(slow_path->GetEntryLabel(), CS);
3603}
3604
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003605void CodeGeneratorARM::MarkGCCard(Register temp,
3606 Register card,
3607 Register object,
3608 Register value,
3609 bool can_be_null) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00003610 NearLabel is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003611 if (can_be_null) {
3612 __ CompareAndBranchIfZero(value, &is_null);
3613 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003614 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3615 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3616 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003617 if (can_be_null) {
3618 __ Bind(&is_null);
3619 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003620}
3621
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003622void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3623 temp->SetLocations(nullptr);
3624}
3625
3626void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3627 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003628 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003629}
3630
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003631void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003632 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003633 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003634}
3635
3636void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003637 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3638}
3639
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003640void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3641 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3642}
3643
3644void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003645 HBasicBlock* block = instruction->GetBlock();
3646 if (block->GetLoopInformation() != nullptr) {
3647 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3648 // The back edge will generate the suspend check.
3649 return;
3650 }
3651 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3652 // The goto will generate the suspend check.
3653 return;
3654 }
3655 GenerateSuspendCheck(instruction, nullptr);
3656}
3657
3658void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3659 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003660 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003661 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3662 if (slow_path == nullptr) {
3663 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3664 instruction->SetSlowPath(slow_path);
3665 codegen_->AddSlowPath(slow_path);
3666 if (successor != nullptr) {
3667 DCHECK(successor->IsLoopHeader());
3668 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3669 }
3670 } else {
3671 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3672 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003673
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003674 __ LoadFromOffset(
3675 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3676 __ cmp(IP, ShifterOperand(0));
3677 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003678 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003679 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003680 __ Bind(slow_path->GetReturnLabel());
3681 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003682 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003683 __ b(slow_path->GetEntryLabel());
3684 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003685}
3686
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003687ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3688 return codegen_->GetAssembler();
3689}
3690
3691void ParallelMoveResolverARM::EmitMove(size_t index) {
3692 MoveOperands* move = moves_.Get(index);
3693 Location source = move->GetSource();
3694 Location destination = move->GetDestination();
3695
3696 if (source.IsRegister()) {
3697 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003698 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003699 } else {
3700 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003701 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003702 SP, destination.GetStackIndex());
3703 }
3704 } else if (source.IsStackSlot()) {
3705 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003706 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003707 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003708 } else if (destination.IsFpuRegister()) {
3709 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003710 } else {
3711 DCHECK(destination.IsStackSlot());
3712 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3713 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3714 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003715 } else if (source.IsFpuRegister()) {
3716 if (destination.IsFpuRegister()) {
3717 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003718 } else {
3719 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003720 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3721 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003722 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003723 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003724 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3725 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003726 } else if (destination.IsRegisterPair()) {
3727 DCHECK(ExpectedPairLayout(destination));
3728 __ LoadFromOffset(
3729 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3730 } else {
3731 DCHECK(destination.IsFpuRegisterPair()) << destination;
3732 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3733 SP,
3734 source.GetStackIndex());
3735 }
3736 } else if (source.IsRegisterPair()) {
3737 if (destination.IsRegisterPair()) {
3738 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3739 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3740 } else {
3741 DCHECK(destination.IsDoubleStackSlot()) << destination;
3742 DCHECK(ExpectedPairLayout(source));
3743 __ StoreToOffset(
3744 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3745 }
3746 } else if (source.IsFpuRegisterPair()) {
3747 if (destination.IsFpuRegisterPair()) {
3748 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3749 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3750 } else {
3751 DCHECK(destination.IsDoubleStackSlot()) << destination;
3752 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3753 SP,
3754 destination.GetStackIndex());
3755 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003756 } else {
3757 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003758 HConstant* constant = source.GetConstant();
3759 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3760 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003761 if (destination.IsRegister()) {
3762 __ LoadImmediate(destination.AsRegister<Register>(), value);
3763 } else {
3764 DCHECK(destination.IsStackSlot());
3765 __ LoadImmediate(IP, value);
3766 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3767 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003768 } else if (constant->IsLongConstant()) {
3769 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003770 if (destination.IsRegisterPair()) {
3771 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3772 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003773 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003774 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003775 __ LoadImmediate(IP, Low32Bits(value));
3776 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3777 __ LoadImmediate(IP, High32Bits(value));
3778 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3779 }
3780 } else if (constant->IsDoubleConstant()) {
3781 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003782 if (destination.IsFpuRegisterPair()) {
3783 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003784 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003785 DCHECK(destination.IsDoubleStackSlot()) << destination;
3786 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003787 __ LoadImmediate(IP, Low32Bits(int_value));
3788 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3789 __ LoadImmediate(IP, High32Bits(int_value));
3790 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3791 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003792 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003793 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003794 float value = constant->AsFloatConstant()->GetValue();
3795 if (destination.IsFpuRegister()) {
3796 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3797 } else {
3798 DCHECK(destination.IsStackSlot());
3799 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3800 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3801 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003802 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003803 }
3804}
3805
3806void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3807 __ Mov(IP, reg);
3808 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3809 __ StoreToOffset(kStoreWord, IP, SP, mem);
3810}
3811
3812void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3813 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3814 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3815 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3816 SP, mem1 + stack_offset);
3817 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3818 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3819 SP, mem2 + stack_offset);
3820 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3821}
3822
3823void ParallelMoveResolverARM::EmitSwap(size_t index) {
3824 MoveOperands* move = moves_.Get(index);
3825 Location source = move->GetSource();
3826 Location destination = move->GetDestination();
3827
3828 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003829 DCHECK_NE(source.AsRegister<Register>(), IP);
3830 DCHECK_NE(destination.AsRegister<Register>(), IP);
3831 __ Mov(IP, source.AsRegister<Register>());
3832 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3833 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003834 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003835 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003836 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003837 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003838 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3839 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003840 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003841 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003842 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003843 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003844 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003845 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003846 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003847 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003848 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3849 destination.AsRegisterPairHigh<Register>(),
3850 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003851 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003852 Register low_reg = source.IsRegisterPair()
3853 ? source.AsRegisterPairLow<Register>()
3854 : destination.AsRegisterPairLow<Register>();
3855 int mem = source.IsRegisterPair()
3856 ? destination.GetStackIndex()
3857 : source.GetStackIndex();
3858 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003859 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003860 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003861 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003862 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003863 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3864 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003865 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003866 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003867 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003868 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3869 DRegister reg = source.IsFpuRegisterPair()
3870 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3871 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3872 int mem = source.IsFpuRegisterPair()
3873 ? destination.GetStackIndex()
3874 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003875 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003876 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003877 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003878 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3879 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3880 : destination.AsFpuRegister<SRegister>();
3881 int mem = source.IsFpuRegister()
3882 ? destination.GetStackIndex()
3883 : source.GetStackIndex();
3884
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003885 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003886 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003887 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003888 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003889 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3890 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003891 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003892 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003893 }
3894}
3895
3896void ParallelMoveResolverARM::SpillScratch(int reg) {
3897 __ Push(static_cast<Register>(reg));
3898}
3899
3900void ParallelMoveResolverARM::RestoreScratch(int reg) {
3901 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003902}
3903
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003904void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003905 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3906 ? LocationSummary::kCallOnSlowPath
3907 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003908 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003909 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003910 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003911 locations->SetOut(Location::RequiresRegister());
3912}
3913
3914void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003915 LocationSummary* locations = cls->GetLocations();
3916 Register out = locations->Out().AsRegister<Register>();
3917 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003918 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003919 DCHECK(!cls->CanCallRuntime());
3920 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003921 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07003922 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003923 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003924 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003925 __ LoadFromOffset(kLoadWord,
3926 out,
3927 current_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -07003928 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003929 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003930
3931 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3932 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3933 codegen_->AddSlowPath(slow_path);
3934 __ cmp(out, ShifterOperand(0));
3935 __ b(slow_path->GetEntryLabel(), EQ);
3936 if (cls->MustGenerateClinitCheck()) {
3937 GenerateClassInitializationCheck(slow_path, out);
3938 } else {
3939 __ Bind(slow_path->GetExitLabel());
3940 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003941 }
3942}
3943
3944void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3945 LocationSummary* locations =
3946 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3947 locations->SetInAt(0, Location::RequiresRegister());
3948 if (check->HasUses()) {
3949 locations->SetOut(Location::SameAsFirstInput());
3950 }
3951}
3952
3953void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003954 // We assume the class is not null.
3955 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3956 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003957 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003958 GenerateClassInitializationCheck(slow_path,
3959 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003960}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003961
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003962void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3963 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003964 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3965 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3966 __ b(slow_path->GetEntryLabel(), LT);
3967 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3968 // properly. Therefore, we do a memory fence.
3969 __ dmb(ISH);
3970 __ Bind(slow_path->GetExitLabel());
3971}
3972
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003973void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3974 LocationSummary* locations =
3975 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01003976 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003977 locations->SetOut(Location::RequiresRegister());
3978}
3979
3980void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3981 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3982 codegen_->AddSlowPath(slow_path);
3983
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01003984 LocationSummary* locations = load->GetLocations();
3985 Register out = locations->Out().AsRegister<Register>();
3986 Register current_method = locations->InAt(0).AsRegister<Register>();
3987 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07003988 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08003989 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003990 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3991 __ cmp(out, ShifterOperand(0));
3992 __ b(slow_path->GetEntryLabel(), EQ);
3993 __ Bind(slow_path->GetExitLabel());
3994}
3995
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003996void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3997 LocationSummary* locations =
3998 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3999 locations->SetOut(Location::RequiresRegister());
4000}
4001
4002void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004003 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004004 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4005 __ LoadFromOffset(kLoadWord, out, TR, offset);
4006 __ LoadImmediate(IP, 0);
4007 __ StoreToOffset(kStoreWord, IP, TR, offset);
4008}
4009
4010void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4011 LocationSummary* locations =
4012 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4013 InvokeRuntimeCallingConvention calling_convention;
4014 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4015}
4016
4017void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4018 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004019 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004020}
4021
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004022void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004023 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4024 ? LocationSummary::kNoCall
4025 : LocationSummary::kCallOnSlowPath;
4026 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4027 locations->SetInAt(0, Location::RequiresRegister());
4028 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004029 // The out register is used as a temporary, so it overlaps with the inputs.
4030 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004031}
4032
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004033void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004034 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004035 Register obj = locations->InAt(0).AsRegister<Register>();
4036 Register cls = locations->InAt(1).AsRegister<Register>();
4037 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004038 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004039 NearLabel done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004040 SlowPathCodeARM* slow_path = nullptr;
4041
4042 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004043 // avoid null check if we know obj is not null.
4044 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004045 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004046 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004047 // Compare the class of `obj` with `cls`.
4048 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
4049 __ cmp(out, ShifterOperand(cls));
4050 if (instruction->IsClassFinal()) {
4051 // Classes must be equal for the instanceof to succeed.
4052 __ b(&zero, NE);
4053 __ LoadImmediate(out, 1);
4054 __ b(&done);
4055 } else {
4056 // If the classes are not equal, we go into a slow path.
4057 DCHECK(locations->OnlyCallsOnSlowPath());
4058 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004059 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004060 codegen_->AddSlowPath(slow_path);
4061 __ b(slow_path->GetEntryLabel(), NE);
4062 __ LoadImmediate(out, 1);
4063 __ b(&done);
4064 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004065
4066 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4067 __ Bind(&zero);
4068 __ LoadImmediate(out, 0);
4069 }
4070
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004071 if (slow_path != nullptr) {
4072 __ Bind(slow_path->GetExitLabel());
4073 }
4074 __ Bind(&done);
4075}
4076
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004077void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4078 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4079 instruction, LocationSummary::kCallOnSlowPath);
4080 locations->SetInAt(0, Location::RequiresRegister());
4081 locations->SetInAt(1, Location::RequiresRegister());
4082 locations->AddTemp(Location::RequiresRegister());
4083}
4084
4085void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4086 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004087 Register obj = locations->InAt(0).AsRegister<Register>();
4088 Register cls = locations->InAt(1).AsRegister<Register>();
4089 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004090 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4091
4092 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4093 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
4094 codegen_->AddSlowPath(slow_path);
4095
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004096 NearLabel done;
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004097 // avoid null check if we know obj is not null.
4098 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004099 __ CompareAndBranchIfZero(obj, &done);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004100 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004101 // Compare the class of `obj` with `cls`.
4102 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
4103 __ cmp(temp, ShifterOperand(cls));
4104 __ b(slow_path->GetEntryLabel(), NE);
4105 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004106 if (instruction->MustDoNullCheck()) {
4107 __ Bind(&done);
4108 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004109}
4110
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004111void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4112 LocationSummary* locations =
4113 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4114 InvokeRuntimeCallingConvention calling_convention;
4115 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4116}
4117
4118void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4119 codegen_->InvokeRuntime(instruction->IsEnter()
4120 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4121 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004122 instruction->GetDexPc(),
4123 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004124}
4125
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004126void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4127void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4128void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4129
4130void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4131 LocationSummary* locations =
4132 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4133 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4134 || instruction->GetResultType() == Primitive::kPrimLong);
4135 locations->SetInAt(0, Location::RequiresRegister());
4136 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004137 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004138}
4139
4140void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4141 HandleBitwiseOperation(instruction);
4142}
4143
4144void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4145 HandleBitwiseOperation(instruction);
4146}
4147
4148void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4149 HandleBitwiseOperation(instruction);
4150}
4151
4152void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4153 LocationSummary* locations = instruction->GetLocations();
4154
4155 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004156 Register first = locations->InAt(0).AsRegister<Register>();
4157 Register second = locations->InAt(1).AsRegister<Register>();
4158 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004159 if (instruction->IsAnd()) {
4160 __ and_(out, first, ShifterOperand(second));
4161 } else if (instruction->IsOr()) {
4162 __ orr(out, first, ShifterOperand(second));
4163 } else {
4164 DCHECK(instruction->IsXor());
4165 __ eor(out, first, ShifterOperand(second));
4166 }
4167 } else {
4168 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4169 Location first = locations->InAt(0);
4170 Location second = locations->InAt(1);
4171 Location out = locations->Out();
4172 if (instruction->IsAnd()) {
4173 __ and_(out.AsRegisterPairLow<Register>(),
4174 first.AsRegisterPairLow<Register>(),
4175 ShifterOperand(second.AsRegisterPairLow<Register>()));
4176 __ and_(out.AsRegisterPairHigh<Register>(),
4177 first.AsRegisterPairHigh<Register>(),
4178 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4179 } else if (instruction->IsOr()) {
4180 __ orr(out.AsRegisterPairLow<Register>(),
4181 first.AsRegisterPairLow<Register>(),
4182 ShifterOperand(second.AsRegisterPairLow<Register>()));
4183 __ orr(out.AsRegisterPairHigh<Register>(),
4184 first.AsRegisterPairHigh<Register>(),
4185 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4186 } else {
4187 DCHECK(instruction->IsXor());
4188 __ eor(out.AsRegisterPairLow<Register>(),
4189 first.AsRegisterPairLow<Register>(),
4190 ShifterOperand(second.AsRegisterPairLow<Register>()));
4191 __ eor(out.AsRegisterPairHigh<Register>(),
4192 first.AsRegisterPairHigh<Register>(),
4193 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4194 }
4195 }
4196}
4197
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004198void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004199 // TODO: Implement all kinds of calls:
4200 // 1) boot -> boot
4201 // 2) app -> boot
4202 // 3) app -> app
4203 //
4204 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4205
Jeff Hao848f70a2014-01-15 13:49:50 -08004206 if (invoke->IsStringInit()) {
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004207 Register reg = temp.AsRegister<Register>();
Jeff Hao848f70a2014-01-15 13:49:50 -08004208 // temp = thread->string_init_entrypoint
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004209 __ LoadFromOffset(kLoadWord, reg, TR, invoke->GetStringInitOffset());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004210 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004211 __ LoadFromOffset(kLoadWord, LR, reg,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004212 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004213 kArmWordSize).Int32Value());
4214 // LR()
4215 __ blx(LR);
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004216 } else if (invoke->IsRecursive()) {
4217 __ bl(GetFrameEntryLabel());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004218 } else {
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004219 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4220 Register method_reg;
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004221 Register reg = temp.AsRegister<Register>();
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004222 if (current_method.IsRegister()) {
4223 method_reg = current_method.AsRegister<Register>();
4224 } else {
4225 DCHECK(invoke->GetLocations()->Intrinsified());
4226 DCHECK(!current_method.IsValid());
4227 method_reg = reg;
4228 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
4229 }
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004230 // reg = current_method->dex_cache_resolved_methods_;
4231 __ LoadFromOffset(
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004232 kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004233 // reg = reg[index_in_cache]
4234 __ LoadFromOffset(
4235 kLoadWord, reg, reg, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4236 // LR = reg[offset_of_quick_compiled_code]
4237 __ LoadFromOffset(kLoadWord, LR, reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4238 kArmWordSize).Int32Value());
4239 // LR()
4240 __ blx(LR);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004241 }
4242
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004243 DCHECK(!IsLeafMethod());
4244}
4245
Calin Juravleb1498f62015-02-16 13:13:29 +00004246void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4247 // Nothing to do, this should be removed during prepare for register allocator.
4248 UNUSED(instruction);
4249 LOG(FATAL) << "Unreachable";
4250}
4251
4252void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4253 // Nothing to do, this should be removed during prepare for register allocator.
4254 UNUSED(instruction);
4255 LOG(FATAL) << "Unreachable";
4256}
4257
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004258} // namespace arm
4259} // namespace art