blob: 6168c2046ff39e6fa80e0f9920b6c9338b6b32a5 [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
Nicolas Geoffray7b0e3532015-06-09 09:25:50 +00001263void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
1264 DCHECK(RequiresCurrentMethod());
1265 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
1266}
1267
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001268static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1269 if (invoke->GetLocations()->Intrinsified()) {
1270 IntrinsicCodeGeneratorARM intrinsic(codegen);
1271 intrinsic.Dispatch(invoke);
1272 return true;
1273 }
1274 return false;
1275}
1276
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001277void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001278 // When we do not run baseline, explicit clinit checks triggered by static
1279 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1280 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001281
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001282 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1283 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001284 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001285
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001286 LocationSummary* locations = invoke->GetLocations();
1287 codegen_->GenerateStaticOrDirectCall(
1288 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001289 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001290}
1291
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001292void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001293 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001294 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001295}
1296
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001297void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001298 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1299 codegen_->GetInstructionSetFeatures());
1300 if (intrinsic.TryDispatch(invoke)) {
1301 return;
1302 }
1303
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001304 HandleInvoke(invoke);
1305}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001306
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001307void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001308 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1309 return;
1310 }
1311
Roland Levillain271ab9c2014-11-27 15:23:57 +00001312 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001313 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
1314 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001315 LocationSummary* locations = invoke->GetLocations();
1316 Location receiver = locations->InAt(0);
1317 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1318 // temp = object->GetClass();
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001319 DCHECK(receiver.IsRegister());
1320 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00001321 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001322 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001323 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001324 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001325 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001326 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001327 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001328 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001329 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001330 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001331 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001332}
1333
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001334void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1335 HandleInvoke(invoke);
1336 // Add the hidden argument.
1337 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1338}
1339
1340void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1341 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001342 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001343 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1344 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001345 LocationSummary* locations = invoke->GetLocations();
1346 Location receiver = locations->InAt(0);
1347 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1348
1349 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001350 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1351 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001352
1353 // temp = object->GetClass();
1354 if (receiver.IsStackSlot()) {
1355 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1356 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1357 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001358 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001359 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001360 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001361 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001362 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001363 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001364 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1365 // LR = temp->GetEntryPoint();
1366 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1367 // LR();
1368 __ blx(LR);
1369 DCHECK(!codegen_->IsLeafMethod());
1370 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1371}
1372
Roland Levillain88cb1752014-10-20 16:36:47 +01001373void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1374 LocationSummary* locations =
1375 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1376 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001377 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001378 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001379 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1380 break;
1381 }
1382 case Primitive::kPrimLong: {
1383 locations->SetInAt(0, Location::RequiresRegister());
1384 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001385 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001386 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001387
Roland Levillain88cb1752014-10-20 16:36:47 +01001388 case Primitive::kPrimFloat:
1389 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001390 locations->SetInAt(0, Location::RequiresFpuRegister());
1391 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001392 break;
1393
1394 default:
1395 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1396 }
1397}
1398
1399void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1400 LocationSummary* locations = neg->GetLocations();
1401 Location out = locations->Out();
1402 Location in = locations->InAt(0);
1403 switch (neg->GetResultType()) {
1404 case Primitive::kPrimInt:
1405 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001406 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001407 break;
1408
1409 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001410 DCHECK(in.IsRegisterPair());
1411 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1412 __ rsbs(out.AsRegisterPairLow<Register>(),
1413 in.AsRegisterPairLow<Register>(),
1414 ShifterOperand(0));
1415 // We cannot emit an RSC (Reverse Subtract with Carry)
1416 // instruction here, as it does not exist in the Thumb-2
1417 // instruction set. We use the following approach
1418 // using SBC and SUB instead.
1419 //
1420 // out.hi = -C
1421 __ sbc(out.AsRegisterPairHigh<Register>(),
1422 out.AsRegisterPairHigh<Register>(),
1423 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1424 // out.hi = out.hi - in.hi
1425 __ sub(out.AsRegisterPairHigh<Register>(),
1426 out.AsRegisterPairHigh<Register>(),
1427 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1428 break;
1429
Roland Levillain88cb1752014-10-20 16:36:47 +01001430 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001431 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001432 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001433 break;
1434
Roland Levillain88cb1752014-10-20 16:36:47 +01001435 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001436 DCHECK(in.IsFpuRegisterPair());
1437 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1438 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001439 break;
1440
1441 default:
1442 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1443 }
1444}
1445
Roland Levillaindff1f282014-11-05 14:15:05 +00001446void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001447 Primitive::Type result_type = conversion->GetResultType();
1448 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001449 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001450
Roland Levillain5b3ee562015-04-14 16:02:41 +01001451 // The float-to-long, double-to-long and long-to-float type conversions
1452 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001453 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001454 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1455 && result_type == Primitive::kPrimLong)
1456 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001457 ? LocationSummary::kCall
1458 : LocationSummary::kNoCall;
1459 LocationSummary* locations =
1460 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1461
David Brazdilb2bd1c52015-03-25 11:17:37 +00001462 // The Java language does not allow treating boolean as an integral type but
1463 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001464
Roland Levillaindff1f282014-11-05 14:15:05 +00001465 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001466 case Primitive::kPrimByte:
1467 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001468 case Primitive::kPrimBoolean:
1469 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001470 case Primitive::kPrimShort:
1471 case Primitive::kPrimInt:
1472 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001473 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001474 locations->SetInAt(0, Location::RequiresRegister());
1475 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1476 break;
1477
1478 default:
1479 LOG(FATAL) << "Unexpected type conversion from " << input_type
1480 << " to " << result_type;
1481 }
1482 break;
1483
Roland Levillain01a8d712014-11-14 16:27:39 +00001484 case Primitive::kPrimShort:
1485 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001486 case Primitive::kPrimBoolean:
1487 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001488 case Primitive::kPrimByte:
1489 case Primitive::kPrimInt:
1490 case Primitive::kPrimChar:
1491 // Processing a Dex `int-to-short' instruction.
1492 locations->SetInAt(0, Location::RequiresRegister());
1493 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1494 break;
1495
1496 default:
1497 LOG(FATAL) << "Unexpected type conversion from " << input_type
1498 << " to " << result_type;
1499 }
1500 break;
1501
Roland Levillain946e1432014-11-11 17:35:19 +00001502 case Primitive::kPrimInt:
1503 switch (input_type) {
1504 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001505 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001506 locations->SetInAt(0, Location::Any());
1507 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1508 break;
1509
1510 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001511 // Processing a Dex `float-to-int' instruction.
1512 locations->SetInAt(0, Location::RequiresFpuRegister());
1513 locations->SetOut(Location::RequiresRegister());
1514 locations->AddTemp(Location::RequiresFpuRegister());
1515 break;
1516
Roland Levillain946e1432014-11-11 17:35:19 +00001517 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001518 // Processing a Dex `double-to-int' instruction.
1519 locations->SetInAt(0, Location::RequiresFpuRegister());
1520 locations->SetOut(Location::RequiresRegister());
1521 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001522 break;
1523
1524 default:
1525 LOG(FATAL) << "Unexpected type conversion from " << input_type
1526 << " to " << result_type;
1527 }
1528 break;
1529
Roland Levillaindff1f282014-11-05 14:15:05 +00001530 case Primitive::kPrimLong:
1531 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001532 case Primitive::kPrimBoolean:
1533 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001534 case Primitive::kPrimByte:
1535 case Primitive::kPrimShort:
1536 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001537 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001538 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001539 locations->SetInAt(0, Location::RequiresRegister());
1540 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1541 break;
1542
Roland Levillain624279f2014-12-04 11:54:28 +00001543 case Primitive::kPrimFloat: {
1544 // Processing a Dex `float-to-long' instruction.
1545 InvokeRuntimeCallingConvention calling_convention;
1546 locations->SetInAt(0, Location::FpuRegisterLocation(
1547 calling_convention.GetFpuRegisterAt(0)));
1548 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1549 break;
1550 }
1551
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001552 case Primitive::kPrimDouble: {
1553 // Processing a Dex `double-to-long' instruction.
1554 InvokeRuntimeCallingConvention calling_convention;
1555 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1556 calling_convention.GetFpuRegisterAt(0),
1557 calling_convention.GetFpuRegisterAt(1)));
1558 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001559 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001560 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001561
1562 default:
1563 LOG(FATAL) << "Unexpected type conversion from " << input_type
1564 << " to " << result_type;
1565 }
1566 break;
1567
Roland Levillain981e4542014-11-14 11:47:14 +00001568 case Primitive::kPrimChar:
1569 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001570 case Primitive::kPrimBoolean:
1571 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001572 case Primitive::kPrimByte:
1573 case Primitive::kPrimShort:
1574 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001575 // Processing a Dex `int-to-char' instruction.
1576 locations->SetInAt(0, Location::RequiresRegister());
1577 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1578 break;
1579
1580 default:
1581 LOG(FATAL) << "Unexpected type conversion from " << input_type
1582 << " to " << result_type;
1583 }
1584 break;
1585
Roland Levillaindff1f282014-11-05 14:15:05 +00001586 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001587 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001588 case Primitive::kPrimBoolean:
1589 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001590 case Primitive::kPrimByte:
1591 case Primitive::kPrimShort:
1592 case Primitive::kPrimInt:
1593 case Primitive::kPrimChar:
1594 // Processing a Dex `int-to-float' instruction.
1595 locations->SetInAt(0, Location::RequiresRegister());
1596 locations->SetOut(Location::RequiresFpuRegister());
1597 break;
1598
Roland Levillain5b3ee562015-04-14 16:02:41 +01001599 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001600 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001601 InvokeRuntimeCallingConvention calling_convention;
1602 locations->SetInAt(0, Location::RegisterPairLocation(
1603 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1604 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001605 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001606 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001607
Roland Levillaincff13742014-11-17 14:32:17 +00001608 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001609 // Processing a Dex `double-to-float' instruction.
1610 locations->SetInAt(0, Location::RequiresFpuRegister());
1611 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001612 break;
1613
1614 default:
1615 LOG(FATAL) << "Unexpected type conversion from " << input_type
1616 << " to " << result_type;
1617 };
1618 break;
1619
Roland Levillaindff1f282014-11-05 14:15:05 +00001620 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001621 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001622 case Primitive::kPrimBoolean:
1623 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001624 case Primitive::kPrimByte:
1625 case Primitive::kPrimShort:
1626 case Primitive::kPrimInt:
1627 case Primitive::kPrimChar:
1628 // Processing a Dex `int-to-double' instruction.
1629 locations->SetInAt(0, Location::RequiresRegister());
1630 locations->SetOut(Location::RequiresFpuRegister());
1631 break;
1632
1633 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001634 // Processing a Dex `long-to-double' instruction.
1635 locations->SetInAt(0, Location::RequiresRegister());
1636 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01001637 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00001638 locations->AddTemp(Location::RequiresFpuRegister());
1639 break;
1640
Roland Levillaincff13742014-11-17 14:32:17 +00001641 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001642 // Processing a Dex `float-to-double' instruction.
1643 locations->SetInAt(0, Location::RequiresFpuRegister());
1644 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001645 break;
1646
1647 default:
1648 LOG(FATAL) << "Unexpected type conversion from " << input_type
1649 << " to " << result_type;
1650 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001651 break;
1652
1653 default:
1654 LOG(FATAL) << "Unexpected type conversion from " << input_type
1655 << " to " << result_type;
1656 }
1657}
1658
1659void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1660 LocationSummary* locations = conversion->GetLocations();
1661 Location out = locations->Out();
1662 Location in = locations->InAt(0);
1663 Primitive::Type result_type = conversion->GetResultType();
1664 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001665 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001666 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001667 case Primitive::kPrimByte:
1668 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001669 case Primitive::kPrimBoolean:
1670 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001671 case Primitive::kPrimShort:
1672 case Primitive::kPrimInt:
1673 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001674 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001675 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001676 break;
1677
1678 default:
1679 LOG(FATAL) << "Unexpected type conversion from " << input_type
1680 << " to " << result_type;
1681 }
1682 break;
1683
Roland Levillain01a8d712014-11-14 16:27:39 +00001684 case Primitive::kPrimShort:
1685 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001686 case Primitive::kPrimBoolean:
1687 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001688 case Primitive::kPrimByte:
1689 case Primitive::kPrimInt:
1690 case Primitive::kPrimChar:
1691 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001692 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001693 break;
1694
1695 default:
1696 LOG(FATAL) << "Unexpected type conversion from " << input_type
1697 << " to " << result_type;
1698 }
1699 break;
1700
Roland Levillain946e1432014-11-11 17:35:19 +00001701 case Primitive::kPrimInt:
1702 switch (input_type) {
1703 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001704 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001705 DCHECK(out.IsRegister());
1706 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001707 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001708 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001709 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001710 } else {
1711 DCHECK(in.IsConstant());
1712 DCHECK(in.GetConstant()->IsLongConstant());
1713 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001714 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001715 }
1716 break;
1717
Roland Levillain3f8f9362014-12-02 17:45:01 +00001718 case Primitive::kPrimFloat: {
1719 // Processing a Dex `float-to-int' instruction.
1720 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1721 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1722 __ vcvtis(temp, temp);
1723 __ vmovrs(out.AsRegister<Register>(), temp);
1724 break;
1725 }
1726
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001727 case Primitive::kPrimDouble: {
1728 // Processing a Dex `double-to-int' instruction.
1729 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1730 DRegister temp_d = FromLowSToD(temp_s);
1731 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1732 __ vcvtid(temp_s, temp_d);
1733 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001734 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001735 }
Roland Levillain946e1432014-11-11 17:35:19 +00001736
1737 default:
1738 LOG(FATAL) << "Unexpected type conversion from " << input_type
1739 << " to " << result_type;
1740 }
1741 break;
1742
Roland Levillaindff1f282014-11-05 14:15:05 +00001743 case Primitive::kPrimLong:
1744 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001745 case Primitive::kPrimBoolean:
1746 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001747 case Primitive::kPrimByte:
1748 case Primitive::kPrimShort:
1749 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001750 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001751 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001752 DCHECK(out.IsRegisterPair());
1753 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001754 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001755 // Sign extension.
1756 __ Asr(out.AsRegisterPairHigh<Register>(),
1757 out.AsRegisterPairLow<Register>(),
1758 31);
1759 break;
1760
1761 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001762 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001763 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1764 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001765 conversion->GetDexPc(),
1766 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001767 break;
1768
Roland Levillaindff1f282014-11-05 14:15:05 +00001769 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001770 // Processing a Dex `double-to-long' instruction.
1771 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1772 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001773 conversion->GetDexPc(),
1774 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001775 break;
1776
1777 default:
1778 LOG(FATAL) << "Unexpected type conversion from " << input_type
1779 << " to " << result_type;
1780 }
1781 break;
1782
Roland Levillain981e4542014-11-14 11:47:14 +00001783 case Primitive::kPrimChar:
1784 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001785 case Primitive::kPrimBoolean:
1786 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001787 case Primitive::kPrimByte:
1788 case Primitive::kPrimShort:
1789 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001790 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001791 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001792 break;
1793
1794 default:
1795 LOG(FATAL) << "Unexpected type conversion from " << input_type
1796 << " to " << result_type;
1797 }
1798 break;
1799
Roland Levillaindff1f282014-11-05 14:15:05 +00001800 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001801 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001802 case Primitive::kPrimBoolean:
1803 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001804 case Primitive::kPrimByte:
1805 case Primitive::kPrimShort:
1806 case Primitive::kPrimInt:
1807 case Primitive::kPrimChar: {
1808 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001809 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1810 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001811 break;
1812 }
1813
Roland Levillain5b3ee562015-04-14 16:02:41 +01001814 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001815 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001816 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
1817 conversion,
1818 conversion->GetDexPc(),
1819 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001820 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00001821
Roland Levillaincff13742014-11-17 14:32:17 +00001822 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001823 // Processing a Dex `double-to-float' instruction.
1824 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1825 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001826 break;
1827
1828 default:
1829 LOG(FATAL) << "Unexpected type conversion from " << input_type
1830 << " to " << result_type;
1831 };
1832 break;
1833
Roland Levillaindff1f282014-11-05 14:15:05 +00001834 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001835 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001836 case Primitive::kPrimBoolean:
1837 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001838 case Primitive::kPrimByte:
1839 case Primitive::kPrimShort:
1840 case Primitive::kPrimInt:
1841 case Primitive::kPrimChar: {
1842 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001843 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001844 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1845 out.AsFpuRegisterPairLow<SRegister>());
1846 break;
1847 }
1848
Roland Levillain647b9ed2014-11-27 12:06:00 +00001849 case Primitive::kPrimLong: {
1850 // Processing a Dex `long-to-double' instruction.
1851 Register low = in.AsRegisterPairLow<Register>();
1852 Register high = in.AsRegisterPairHigh<Register>();
1853 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1854 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001855 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001856 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001857 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
1858 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001859
Roland Levillain682393c2015-04-14 15:57:52 +01001860 // temp_d = int-to-double(high)
1861 __ vmovsr(temp_s, high);
1862 __ vcvtdi(temp_d, temp_s);
1863 // constant_d = k2Pow32EncodingForDouble
1864 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
1865 // out_d = unsigned-to-double(low)
1866 __ vmovsr(out_s, low);
1867 __ vcvtdu(out_d, out_s);
1868 // out_d += temp_d * constant_d
1869 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001870 break;
1871 }
1872
Roland Levillaincff13742014-11-17 14:32:17 +00001873 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001874 // Processing a Dex `float-to-double' instruction.
1875 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1876 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001877 break;
1878
1879 default:
1880 LOG(FATAL) << "Unexpected type conversion from " << input_type
1881 << " to " << result_type;
1882 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001883 break;
1884
1885 default:
1886 LOG(FATAL) << "Unexpected type conversion from " << input_type
1887 << " to " << result_type;
1888 }
1889}
1890
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001891void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001892 LocationSummary* locations =
1893 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001894 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001895 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001896 locations->SetInAt(0, Location::RequiresRegister());
1897 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001898 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1899 break;
1900 }
1901
1902 case Primitive::kPrimLong: {
1903 locations->SetInAt(0, Location::RequiresRegister());
1904 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001905 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001906 break;
1907 }
1908
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001909 case Primitive::kPrimFloat:
1910 case Primitive::kPrimDouble: {
1911 locations->SetInAt(0, Location::RequiresFpuRegister());
1912 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001913 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001914 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001915 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001916
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001917 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001918 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001919 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001920}
1921
1922void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1923 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001924 Location out = locations->Out();
1925 Location first = locations->InAt(0);
1926 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001927 switch (add->GetResultType()) {
1928 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001929 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001930 __ add(out.AsRegister<Register>(),
1931 first.AsRegister<Register>(),
1932 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001933 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001934 __ AddConstant(out.AsRegister<Register>(),
1935 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001936 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001937 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001938 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001939
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001940 case Primitive::kPrimLong: {
1941 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001942 __ adds(out.AsRegisterPairLow<Register>(),
1943 first.AsRegisterPairLow<Register>(),
1944 ShifterOperand(second.AsRegisterPairLow<Register>()));
1945 __ adc(out.AsRegisterPairHigh<Register>(),
1946 first.AsRegisterPairHigh<Register>(),
1947 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001948 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001949 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001950
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001951 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001952 __ vadds(out.AsFpuRegister<SRegister>(),
1953 first.AsFpuRegister<SRegister>(),
1954 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001955 break;
1956
1957 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001958 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1959 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1960 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001961 break;
1962
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001963 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001964 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001965 }
1966}
1967
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001968void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001969 LocationSummary* locations =
1970 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001971 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001972 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001973 locations->SetInAt(0, Location::RequiresRegister());
1974 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001975 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1976 break;
1977 }
1978
1979 case Primitive::kPrimLong: {
1980 locations->SetInAt(0, Location::RequiresRegister());
1981 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001982 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001983 break;
1984 }
Calin Juravle11351682014-10-23 15:38:15 +01001985 case Primitive::kPrimFloat:
1986 case Primitive::kPrimDouble: {
1987 locations->SetInAt(0, Location::RequiresFpuRegister());
1988 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001989 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001990 break;
Calin Juravle11351682014-10-23 15:38:15 +01001991 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001992 default:
Calin Juravle11351682014-10-23 15:38:15 +01001993 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001994 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001995}
1996
1997void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1998 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001999 Location out = locations->Out();
2000 Location first = locations->InAt(0);
2001 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002002 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002003 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002004 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002005 __ sub(out.AsRegister<Register>(),
2006 first.AsRegister<Register>(),
2007 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002008 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002009 __ AddConstant(out.AsRegister<Register>(),
2010 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002011 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002012 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002013 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002014 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002015
Calin Juravle11351682014-10-23 15:38:15 +01002016 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002017 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002018 __ subs(out.AsRegisterPairLow<Register>(),
2019 first.AsRegisterPairLow<Register>(),
2020 ShifterOperand(second.AsRegisterPairLow<Register>()));
2021 __ sbc(out.AsRegisterPairHigh<Register>(),
2022 first.AsRegisterPairHigh<Register>(),
2023 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002024 break;
Calin Juravle11351682014-10-23 15:38:15 +01002025 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002026
Calin Juravle11351682014-10-23 15:38:15 +01002027 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002028 __ vsubs(out.AsFpuRegister<SRegister>(),
2029 first.AsFpuRegister<SRegister>(),
2030 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002031 break;
Calin Juravle11351682014-10-23 15:38:15 +01002032 }
2033
2034 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002035 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2036 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2037 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002038 break;
2039 }
2040
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002041
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002042 default:
Calin Juravle11351682014-10-23 15:38:15 +01002043 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002044 }
2045}
2046
Calin Juravle34bacdf2014-10-07 20:23:36 +01002047void LocationsBuilderARM::VisitMul(HMul* mul) {
2048 LocationSummary* locations =
2049 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2050 switch (mul->GetResultType()) {
2051 case Primitive::kPrimInt:
2052 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002053 locations->SetInAt(0, Location::RequiresRegister());
2054 locations->SetInAt(1, Location::RequiresRegister());
2055 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002056 break;
2057 }
2058
Calin Juravleb5bfa962014-10-21 18:02:24 +01002059 case Primitive::kPrimFloat:
2060 case Primitive::kPrimDouble: {
2061 locations->SetInAt(0, Location::RequiresFpuRegister());
2062 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002063 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002064 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002065 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002066
2067 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002068 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002069 }
2070}
2071
2072void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2073 LocationSummary* locations = mul->GetLocations();
2074 Location out = locations->Out();
2075 Location first = locations->InAt(0);
2076 Location second = locations->InAt(1);
2077 switch (mul->GetResultType()) {
2078 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002079 __ mul(out.AsRegister<Register>(),
2080 first.AsRegister<Register>(),
2081 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002082 break;
2083 }
2084 case Primitive::kPrimLong: {
2085 Register out_hi = out.AsRegisterPairHigh<Register>();
2086 Register out_lo = out.AsRegisterPairLow<Register>();
2087 Register in1_hi = first.AsRegisterPairHigh<Register>();
2088 Register in1_lo = first.AsRegisterPairLow<Register>();
2089 Register in2_hi = second.AsRegisterPairHigh<Register>();
2090 Register in2_lo = second.AsRegisterPairLow<Register>();
2091
2092 // Extra checks to protect caused by the existence of R1_R2.
2093 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2094 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2095 DCHECK_NE(out_hi, in1_lo);
2096 DCHECK_NE(out_hi, in2_lo);
2097
2098 // input: in1 - 64 bits, in2 - 64 bits
2099 // output: out
2100 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2101 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2102 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2103
2104 // IP <- in1.lo * in2.hi
2105 __ mul(IP, in1_lo, in2_hi);
2106 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2107 __ mla(out_hi, in1_hi, in2_lo, IP);
2108 // out.lo <- (in1.lo * in2.lo)[31:0];
2109 __ umull(out_lo, IP, in1_lo, in2_lo);
2110 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2111 __ add(out_hi, out_hi, ShifterOperand(IP));
2112 break;
2113 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002114
2115 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002116 __ vmuls(out.AsFpuRegister<SRegister>(),
2117 first.AsFpuRegister<SRegister>(),
2118 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002119 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002120 }
2121
2122 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002123 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2124 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2125 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002126 break;
2127 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002128
2129 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002130 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002131 }
2132}
2133
Zheng Xuc6667102015-05-15 16:08:45 +08002134void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2135 DCHECK(instruction->IsDiv() || instruction->IsRem());
2136 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2137
2138 LocationSummary* locations = instruction->GetLocations();
2139 Location second = locations->InAt(1);
2140 DCHECK(second.IsConstant());
2141
2142 Register out = locations->Out().AsRegister<Register>();
2143 Register dividend = locations->InAt(0).AsRegister<Register>();
2144 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2145 DCHECK(imm == 1 || imm == -1);
2146
2147 if (instruction->IsRem()) {
2148 __ LoadImmediate(out, 0);
2149 } else {
2150 if (imm == 1) {
2151 __ Mov(out, dividend);
2152 } else {
2153 __ rsb(out, dividend, ShifterOperand(0));
2154 }
2155 }
2156}
2157
2158void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2159 DCHECK(instruction->IsDiv() || instruction->IsRem());
2160 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2161
2162 LocationSummary* locations = instruction->GetLocations();
2163 Location second = locations->InAt(1);
2164 DCHECK(second.IsConstant());
2165
2166 Register out = locations->Out().AsRegister<Register>();
2167 Register dividend = locations->InAt(0).AsRegister<Register>();
2168 Register temp = locations->GetTemp(0).AsRegister<Register>();
2169 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002170 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002171 DCHECK(IsPowerOfTwo(abs_imm));
2172 int ctz_imm = CTZ(abs_imm);
2173
2174 if (ctz_imm == 1) {
2175 __ Lsr(temp, dividend, 32 - ctz_imm);
2176 } else {
2177 __ Asr(temp, dividend, 31);
2178 __ Lsr(temp, temp, 32 - ctz_imm);
2179 }
2180 __ add(out, temp, ShifterOperand(dividend));
2181
2182 if (instruction->IsDiv()) {
2183 __ Asr(out, out, ctz_imm);
2184 if (imm < 0) {
2185 __ rsb(out, out, ShifterOperand(0));
2186 }
2187 } else {
2188 __ ubfx(out, out, 0, ctz_imm);
2189 __ sub(out, out, ShifterOperand(temp));
2190 }
2191}
2192
2193void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2194 DCHECK(instruction->IsDiv() || instruction->IsRem());
2195 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2196
2197 LocationSummary* locations = instruction->GetLocations();
2198 Location second = locations->InAt(1);
2199 DCHECK(second.IsConstant());
2200
2201 Register out = locations->Out().AsRegister<Register>();
2202 Register dividend = locations->InAt(0).AsRegister<Register>();
2203 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2204 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2205 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2206
2207 int64_t magic;
2208 int shift;
2209 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2210
2211 __ LoadImmediate(temp1, magic);
2212 __ smull(temp2, temp1, dividend, temp1);
2213
2214 if (imm > 0 && magic < 0) {
2215 __ add(temp1, temp1, ShifterOperand(dividend));
2216 } else if (imm < 0 && magic > 0) {
2217 __ sub(temp1, temp1, ShifterOperand(dividend));
2218 }
2219
2220 if (shift != 0) {
2221 __ Asr(temp1, temp1, shift);
2222 }
2223
2224 if (instruction->IsDiv()) {
2225 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2226 } else {
2227 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2228 // TODO: Strength reduction for mls.
2229 __ LoadImmediate(temp2, imm);
2230 __ mls(out, temp1, temp2, dividend);
2231 }
2232}
2233
2234void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2235 DCHECK(instruction->IsDiv() || instruction->IsRem());
2236 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2237
2238 LocationSummary* locations = instruction->GetLocations();
2239 Location second = locations->InAt(1);
2240 DCHECK(second.IsConstant());
2241
2242 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2243 if (imm == 0) {
2244 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2245 } else if (imm == 1 || imm == -1) {
2246 DivRemOneOrMinusOne(instruction);
2247 } else if (IsPowerOfTwo(std::abs(imm))) {
2248 DivRemByPowerOfTwo(instruction);
2249 } else {
2250 DCHECK(imm <= -2 || imm >= 2);
2251 GenerateDivRemWithAnyConstant(instruction);
2252 }
2253}
2254
Calin Juravle7c4954d2014-10-28 16:57:40 +00002255void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002256 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2257 if (div->GetResultType() == Primitive::kPrimLong) {
2258 // pLdiv runtime call.
2259 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002260 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2261 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002262 } else if (div->GetResultType() == Primitive::kPrimInt &&
2263 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2264 // pIdivmod runtime call.
2265 call_kind = LocationSummary::kCall;
2266 }
2267
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002268 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2269
Calin Juravle7c4954d2014-10-28 16:57:40 +00002270 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002271 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002272 if (div->InputAt(1)->IsConstant()) {
2273 locations->SetInAt(0, Location::RequiresRegister());
2274 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2275 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2276 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2277 if (abs_imm <= 1) {
2278 // No temp register required.
2279 } else {
2280 locations->AddTemp(Location::RequiresRegister());
2281 if (!IsPowerOfTwo(abs_imm)) {
2282 locations->AddTemp(Location::RequiresRegister());
2283 }
2284 }
2285 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002286 locations->SetInAt(0, Location::RequiresRegister());
2287 locations->SetInAt(1, Location::RequiresRegister());
2288 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2289 } else {
2290 InvokeRuntimeCallingConvention calling_convention;
2291 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2292 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2293 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2294 // we only need the former.
2295 locations->SetOut(Location::RegisterLocation(R0));
2296 }
Calin Juravled0d48522014-11-04 16:40:20 +00002297 break;
2298 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002299 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002300 InvokeRuntimeCallingConvention calling_convention;
2301 locations->SetInAt(0, Location::RegisterPairLocation(
2302 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2303 locations->SetInAt(1, Location::RegisterPairLocation(
2304 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002305 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002306 break;
2307 }
2308 case Primitive::kPrimFloat:
2309 case Primitive::kPrimDouble: {
2310 locations->SetInAt(0, Location::RequiresFpuRegister());
2311 locations->SetInAt(1, Location::RequiresFpuRegister());
2312 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2313 break;
2314 }
2315
2316 default:
2317 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2318 }
2319}
2320
2321void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2322 LocationSummary* locations = div->GetLocations();
2323 Location out = locations->Out();
2324 Location first = locations->InAt(0);
2325 Location second = locations->InAt(1);
2326
2327 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002328 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002329 if (second.IsConstant()) {
2330 GenerateDivRemConstantIntegral(div);
2331 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002332 __ sdiv(out.AsRegister<Register>(),
2333 first.AsRegister<Register>(),
2334 second.AsRegister<Register>());
2335 } else {
2336 InvokeRuntimeCallingConvention calling_convention;
2337 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2338 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2339 DCHECK_EQ(R0, out.AsRegister<Register>());
2340
2341 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2342 }
Calin Juravled0d48522014-11-04 16:40:20 +00002343 break;
2344 }
2345
Calin Juravle7c4954d2014-10-28 16:57:40 +00002346 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002347 InvokeRuntimeCallingConvention calling_convention;
2348 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2349 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2350 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2351 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2352 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002353 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002354
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002355 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002356 break;
2357 }
2358
2359 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002360 __ vdivs(out.AsFpuRegister<SRegister>(),
2361 first.AsFpuRegister<SRegister>(),
2362 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002363 break;
2364 }
2365
2366 case Primitive::kPrimDouble: {
2367 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2368 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2369 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2370 break;
2371 }
2372
2373 default:
2374 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2375 }
2376}
2377
Calin Juravlebacfec32014-11-14 15:54:36 +00002378void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002379 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002380
2381 // Most remainders are implemented in the runtime.
2382 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002383 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2384 // sdiv will be replaced by other instruction sequence.
2385 call_kind = LocationSummary::kNoCall;
2386 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2387 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002388 // Have hardware divide instruction for int, do it with three instructions.
2389 call_kind = LocationSummary::kNoCall;
2390 }
2391
Calin Juravlebacfec32014-11-14 15:54:36 +00002392 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2393
Calin Juravled2ec87d2014-12-08 14:24:46 +00002394 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002395 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002396 if (rem->InputAt(1)->IsConstant()) {
2397 locations->SetInAt(0, Location::RequiresRegister());
2398 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2399 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2400 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2401 if (abs_imm <= 1) {
2402 // No temp register required.
2403 } else {
2404 locations->AddTemp(Location::RequiresRegister());
2405 if (!IsPowerOfTwo(abs_imm)) {
2406 locations->AddTemp(Location::RequiresRegister());
2407 }
2408 }
2409 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002410 locations->SetInAt(0, Location::RequiresRegister());
2411 locations->SetInAt(1, Location::RequiresRegister());
2412 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2413 locations->AddTemp(Location::RequiresRegister());
2414 } else {
2415 InvokeRuntimeCallingConvention calling_convention;
2416 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2417 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2418 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2419 // we only need the latter.
2420 locations->SetOut(Location::RegisterLocation(R1));
2421 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002422 break;
2423 }
2424 case Primitive::kPrimLong: {
2425 InvokeRuntimeCallingConvention calling_convention;
2426 locations->SetInAt(0, Location::RegisterPairLocation(
2427 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2428 locations->SetInAt(1, Location::RegisterPairLocation(
2429 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2430 // The runtime helper puts the output in R2,R3.
2431 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2432 break;
2433 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002434 case Primitive::kPrimFloat: {
2435 InvokeRuntimeCallingConvention calling_convention;
2436 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2437 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2438 locations->SetOut(Location::FpuRegisterLocation(S0));
2439 break;
2440 }
2441
Calin Juravlebacfec32014-11-14 15:54:36 +00002442 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002443 InvokeRuntimeCallingConvention calling_convention;
2444 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2445 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2446 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2447 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2448 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002449 break;
2450 }
2451
2452 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002453 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002454 }
2455}
2456
2457void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2458 LocationSummary* locations = rem->GetLocations();
2459 Location out = locations->Out();
2460 Location first = locations->InAt(0);
2461 Location second = locations->InAt(1);
2462
Calin Juravled2ec87d2014-12-08 14:24:46 +00002463 Primitive::Type type = rem->GetResultType();
2464 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002465 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002466 if (second.IsConstant()) {
2467 GenerateDivRemConstantIntegral(rem);
2468 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002469 Register reg1 = first.AsRegister<Register>();
2470 Register reg2 = second.AsRegister<Register>();
2471 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002472
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002473 // temp = reg1 / reg2 (integer division)
2474 // temp = temp * reg2
2475 // dest = reg1 - temp
2476 __ sdiv(temp, reg1, reg2);
2477 __ mul(temp, temp, reg2);
2478 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2479 } else {
2480 InvokeRuntimeCallingConvention calling_convention;
2481 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2482 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2483 DCHECK_EQ(R1, out.AsRegister<Register>());
2484
2485 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2486 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002487 break;
2488 }
2489
2490 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002491 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002492 break;
2493 }
2494
Calin Juravled2ec87d2014-12-08 14:24:46 +00002495 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002496 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002497 break;
2498 }
2499
Calin Juravlebacfec32014-11-14 15:54:36 +00002500 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002501 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002502 break;
2503 }
2504
2505 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002506 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002507 }
2508}
2509
Calin Juravled0d48522014-11-04 16:40:20 +00002510void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2511 LocationSummary* locations =
2512 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002513 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002514 if (instruction->HasUses()) {
2515 locations->SetOut(Location::SameAsFirstInput());
2516 }
2517}
2518
2519void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2520 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2521 codegen_->AddSlowPath(slow_path);
2522
2523 LocationSummary* locations = instruction->GetLocations();
2524 Location value = locations->InAt(0);
2525
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002526 switch (instruction->GetType()) {
2527 case Primitive::kPrimInt: {
2528 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002529 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002530 __ b(slow_path->GetEntryLabel(), EQ);
2531 } else {
2532 DCHECK(value.IsConstant()) << value;
2533 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2534 __ b(slow_path->GetEntryLabel());
2535 }
2536 }
2537 break;
2538 }
2539 case Primitive::kPrimLong: {
2540 if (value.IsRegisterPair()) {
2541 __ orrs(IP,
2542 value.AsRegisterPairLow<Register>(),
2543 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2544 __ b(slow_path->GetEntryLabel(), EQ);
2545 } else {
2546 DCHECK(value.IsConstant()) << value;
2547 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2548 __ b(slow_path->GetEntryLabel());
2549 }
2550 }
2551 break;
2552 default:
2553 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2554 }
2555 }
Calin Juravled0d48522014-11-04 16:40:20 +00002556}
2557
Calin Juravle9aec02f2014-11-18 23:06:35 +00002558void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2559 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2560
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002561 LocationSummary* locations =
2562 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002563
2564 switch (op->GetResultType()) {
2565 case Primitive::kPrimInt: {
2566 locations->SetInAt(0, Location::RequiresRegister());
2567 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002568 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002569 break;
2570 }
2571 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002572 locations->SetInAt(0, Location::RequiresRegister());
2573 locations->SetInAt(1, Location::RequiresRegister());
2574 locations->AddTemp(Location::RequiresRegister());
2575 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002576 break;
2577 }
2578 default:
2579 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2580 }
2581}
2582
2583void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2584 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2585
2586 LocationSummary* locations = op->GetLocations();
2587 Location out = locations->Out();
2588 Location first = locations->InAt(0);
2589 Location second = locations->InAt(1);
2590
2591 Primitive::Type type = op->GetResultType();
2592 switch (type) {
2593 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002594 Register out_reg = out.AsRegister<Register>();
2595 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002596 // Arm doesn't mask the shift count so we need to do it ourselves.
2597 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002598 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002599 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2600 if (op->IsShl()) {
2601 __ Lsl(out_reg, first_reg, second_reg);
2602 } else if (op->IsShr()) {
2603 __ Asr(out_reg, first_reg, second_reg);
2604 } else {
2605 __ Lsr(out_reg, first_reg, second_reg);
2606 }
2607 } else {
2608 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2609 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2610 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2611 __ Mov(out_reg, first_reg);
2612 } else if (op->IsShl()) {
2613 __ Lsl(out_reg, first_reg, shift_value);
2614 } else if (op->IsShr()) {
2615 __ Asr(out_reg, first_reg, shift_value);
2616 } else {
2617 __ Lsr(out_reg, first_reg, shift_value);
2618 }
2619 }
2620 break;
2621 }
2622 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002623 Register o_h = out.AsRegisterPairHigh<Register>();
2624 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002625
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002626 Register temp = locations->GetTemp(0).AsRegister<Register>();
2627
2628 Register high = first.AsRegisterPairHigh<Register>();
2629 Register low = first.AsRegisterPairLow<Register>();
2630
2631 Register second_reg = second.AsRegister<Register>();
2632
Calin Juravle9aec02f2014-11-18 23:06:35 +00002633 if (op->IsShl()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002634 // Shift the high part
2635 __ and_(second_reg, second_reg, ShifterOperand(63));
2636 __ Lsl(o_h, high, second_reg);
2637 // Shift the low part and `or` what overflew on the high part
2638 __ rsb(temp, second_reg, ShifterOperand(32));
2639 __ Lsr(temp, low, temp);
2640 __ orr(o_h, o_h, ShifterOperand(temp));
2641 // If the shift is > 32 bits, override the high part
2642 __ subs(temp, second_reg, ShifterOperand(32));
2643 __ it(PL);
2644 __ Lsl(o_h, low, temp, false, PL);
2645 // Shift the low part
2646 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002647 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002648 // Shift the low part
2649 __ and_(second_reg, second_reg, ShifterOperand(63));
2650 __ Lsr(o_l, low, second_reg);
2651 // Shift the high part and `or` what underflew on the low part
2652 __ rsb(temp, second_reg, ShifterOperand(32));
2653 __ Lsl(temp, high, temp);
2654 __ orr(o_l, o_l, ShifterOperand(temp));
2655 // If the shift is > 32 bits, override the low part
2656 __ subs(temp, second_reg, ShifterOperand(32));
2657 __ it(PL);
2658 __ Asr(o_l, high, temp, false, PL);
2659 // Shift the high part
2660 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002661 } else {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002662 // same as Shr except we use `Lsr`s and not `Asr`s
2663 __ and_(second_reg, second_reg, ShifterOperand(63));
2664 __ Lsr(o_l, low, second_reg);
2665 __ rsb(temp, second_reg, ShifterOperand(32));
2666 __ Lsl(temp, high, temp);
2667 __ orr(o_l, o_l, ShifterOperand(temp));
2668 __ subs(temp, second_reg, ShifterOperand(32));
2669 __ it(PL);
2670 __ Lsr(o_l, high, temp, false, PL);
2671 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002672 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002673 break;
2674 }
2675 default:
2676 LOG(FATAL) << "Unexpected operation type " << type;
2677 }
2678}
2679
2680void LocationsBuilderARM::VisitShl(HShl* shl) {
2681 HandleShift(shl);
2682}
2683
2684void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2685 HandleShift(shl);
2686}
2687
2688void LocationsBuilderARM::VisitShr(HShr* shr) {
2689 HandleShift(shr);
2690}
2691
2692void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2693 HandleShift(shr);
2694}
2695
2696void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2697 HandleShift(ushr);
2698}
2699
2700void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2701 HandleShift(ushr);
2702}
2703
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002704void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002705 LocationSummary* locations =
2706 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002707 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002708 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray7b0e3532015-06-09 09:25:50 +00002709 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002710 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002711}
2712
2713void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2714 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray7b0e3532015-06-09 09:25:50 +00002715 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002716 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002717 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2718 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002719 instruction->GetDexPc(),
2720 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002721}
2722
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002723void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2724 LocationSummary* locations =
2725 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2726 InvokeRuntimeCallingConvention calling_convention;
2727 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray7b0e3532015-06-09 09:25:50 +00002728 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002729 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002730 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002731}
2732
2733void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2734 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray7b0e3532015-06-09 09:25:50 +00002735 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002736 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002737 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2738 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002739 instruction->GetDexPc(),
2740 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002741}
2742
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002743void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002744 LocationSummary* locations =
2745 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002746 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2747 if (location.IsStackSlot()) {
2748 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2749 } else if (location.IsDoubleStackSlot()) {
2750 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002751 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002752 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002753}
2754
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002755void InstructionCodeGeneratorARM::VisitParameterValue(
2756 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002757 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002758}
2759
2760void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
2761 LocationSummary* locations =
2762 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2763 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2764}
2765
2766void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
2767 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002768}
2769
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002770void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002771 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002772 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002773 locations->SetInAt(0, Location::RequiresRegister());
2774 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002775}
2776
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002777void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2778 LocationSummary* locations = not_->GetLocations();
2779 Location out = locations->Out();
2780 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002781 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002782 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002783 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002784 break;
2785
2786 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002787 __ mvn(out.AsRegisterPairLow<Register>(),
2788 ShifterOperand(in.AsRegisterPairLow<Register>()));
2789 __ mvn(out.AsRegisterPairHigh<Register>(),
2790 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002791 break;
2792
2793 default:
2794 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2795 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002796}
2797
David Brazdil66d126e2015-04-03 16:02:44 +01002798void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
2799 LocationSummary* locations =
2800 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
2801 locations->SetInAt(0, Location::RequiresRegister());
2802 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2803}
2804
2805void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01002806 LocationSummary* locations = bool_not->GetLocations();
2807 Location out = locations->Out();
2808 Location in = locations->InAt(0);
2809 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
2810}
2811
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002812void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002813 LocationSummary* locations =
2814 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002815 switch (compare->InputAt(0)->GetType()) {
2816 case Primitive::kPrimLong: {
2817 locations->SetInAt(0, Location::RequiresRegister());
2818 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002819 // Output overlaps because it is written before doing the low comparison.
2820 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002821 break;
2822 }
2823 case Primitive::kPrimFloat:
2824 case Primitive::kPrimDouble: {
2825 locations->SetInAt(0, Location::RequiresFpuRegister());
2826 locations->SetInAt(1, Location::RequiresFpuRegister());
2827 locations->SetOut(Location::RequiresRegister());
2828 break;
2829 }
2830 default:
2831 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2832 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002833}
2834
2835void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002836 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002837 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002838 Location left = locations->InAt(0);
2839 Location right = locations->InAt(1);
2840
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002841 NearLabel less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00002842 Primitive::Type type = compare->InputAt(0)->GetType();
2843 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002844 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002845 __ cmp(left.AsRegisterPairHigh<Register>(),
2846 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002847 __ b(&less, LT);
2848 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002849 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2850 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002851 __ cmp(left.AsRegisterPairLow<Register>(),
2852 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002853 break;
2854 }
2855 case Primitive::kPrimFloat:
2856 case Primitive::kPrimDouble: {
2857 __ LoadImmediate(out, 0);
2858 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002859 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002860 } else {
2861 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2862 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2863 }
2864 __ vmstat(); // transfer FP status register to ARM APSR.
2865 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002866 break;
2867 }
2868 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002869 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002870 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002871 __ b(&done, EQ);
2872 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2873
2874 __ Bind(&greater);
2875 __ LoadImmediate(out, 1);
2876 __ b(&done);
2877
2878 __ Bind(&less);
2879 __ LoadImmediate(out, -1);
2880
2881 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002882}
2883
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002884void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002885 LocationSummary* locations =
2886 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002887 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2888 locations->SetInAt(i, Location::Any());
2889 }
2890 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002891}
2892
2893void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002894 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002895 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002896}
2897
Calin Juravle52c48962014-12-16 17:02:57 +00002898void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2899 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07002900 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00002901 switch (kind) {
2902 case MemBarrierKind::kAnyStore:
2903 case MemBarrierKind::kLoadAny:
2904 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002905 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00002906 break;
2907 }
2908 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002909 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00002910 break;
2911 }
2912 default:
2913 LOG(FATAL) << "Unexpected memory barrier " << kind;
2914 }
Kenny Root1d8199d2015-06-02 11:01:10 -07002915 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00002916}
2917
2918void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2919 uint32_t offset,
2920 Register out_lo,
2921 Register out_hi) {
2922 if (offset != 0) {
2923 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002924 __ add(IP, addr, ShifterOperand(out_lo));
2925 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002926 }
2927 __ ldrexd(out_lo, out_hi, addr);
2928}
2929
2930void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2931 uint32_t offset,
2932 Register value_lo,
2933 Register value_hi,
2934 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002935 Register temp2,
2936 HInstruction* instruction) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002937 NearLabel fail;
Calin Juravle52c48962014-12-16 17:02:57 +00002938 if (offset != 0) {
2939 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002940 __ add(IP, addr, ShifterOperand(temp1));
2941 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002942 }
2943 __ Bind(&fail);
2944 // We need a load followed by store. (The address used in a STREX instruction must
2945 // be the same as the address in the most recently executed LDREX instruction.)
2946 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002947 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002948 __ strexd(temp1, value_lo, value_hi, addr);
2949 __ cmp(temp1, ShifterOperand(0));
2950 __ b(&fail, NE);
2951}
2952
2953void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2954 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2955
Nicolas Geoffray39468442014-09-02 15:17:15 +01002956 LocationSummary* locations =
2957 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002958 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002959
Calin Juravle52c48962014-12-16 17:02:57 +00002960 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01002961 if (Primitive::IsFloatingPointType(field_type)) {
2962 locations->SetInAt(1, Location::RequiresFpuRegister());
2963 } else {
2964 locations->SetInAt(1, Location::RequiresRegister());
2965 }
2966
Calin Juravle52c48962014-12-16 17:02:57 +00002967 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002968 bool generate_volatile = field_info.IsVolatile()
2969 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002970 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002971 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002972 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2973 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002974 locations->AddTemp(Location::RequiresRegister());
2975 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002976 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002977 // Arm encoding have some additional constraints for ldrexd/strexd:
2978 // - registers need to be consecutive
2979 // - the first register should be even but not R14.
2980 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2981 // enable Arm encoding.
2982 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2983
2984 locations->AddTemp(Location::RequiresRegister());
2985 locations->AddTemp(Location::RequiresRegister());
2986 if (field_type == Primitive::kPrimDouble) {
2987 // For doubles we need two more registers to copy the value.
2988 locations->AddTemp(Location::RegisterLocation(R2));
2989 locations->AddTemp(Location::RegisterLocation(R3));
2990 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002991 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002992}
2993
Calin Juravle52c48962014-12-16 17:02:57 +00002994void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01002995 const FieldInfo& field_info,
2996 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00002997 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2998
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002999 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003000 Register base = locations->InAt(0).AsRegister<Register>();
3001 Location value = locations->InAt(1);
3002
3003 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003004 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003005 Primitive::Type field_type = field_info.GetFieldType();
3006 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3007
3008 if (is_volatile) {
3009 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3010 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003011
3012 switch (field_type) {
3013 case Primitive::kPrimBoolean:
3014 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003015 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003016 break;
3017 }
3018
3019 case Primitive::kPrimShort:
3020 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003021 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003022 break;
3023 }
3024
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003025 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003026 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00003027 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003028 break;
3029 }
3030
3031 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003032 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003033 GenerateWideAtomicStore(base, offset,
3034 value.AsRegisterPairLow<Register>(),
3035 value.AsRegisterPairHigh<Register>(),
3036 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003037 locations->GetTemp(1).AsRegister<Register>(),
3038 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003039 } else {
3040 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003041 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003042 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003043 break;
3044 }
3045
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003046 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003047 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003048 break;
3049 }
3050
3051 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003052 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003053 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003054 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3055 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3056
3057 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3058
3059 GenerateWideAtomicStore(base, offset,
3060 value_reg_lo,
3061 value_reg_hi,
3062 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003063 locations->GetTemp(3).AsRegister<Register>(),
3064 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003065 } else {
3066 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003067 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003068 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003069 break;
3070 }
3071
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003072 case Primitive::kPrimVoid:
3073 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003074 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003075 }
Calin Juravle52c48962014-12-16 17:02:57 +00003076
Calin Juravle77520bc2015-01-12 18:45:46 +00003077 // Longs and doubles are handled in the switch.
3078 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3079 codegen_->MaybeRecordImplicitNullCheck(instruction);
3080 }
3081
3082 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3083 Register temp = locations->GetTemp(0).AsRegister<Register>();
3084 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003085 codegen_->MarkGCCard(
3086 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003087 }
3088
Calin Juravle52c48962014-12-16 17:02:57 +00003089 if (is_volatile) {
3090 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3091 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003092}
3093
Calin Juravle52c48962014-12-16 17:02:57 +00003094void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3095 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003096 LocationSummary* locations =
3097 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003098 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003099
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003100 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003101 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003102 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003103 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003104
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003105 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3106 locations->SetOut(Location::RequiresFpuRegister());
3107 } else {
3108 locations->SetOut(Location::RequiresRegister(),
3109 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3110 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003111 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003112 // Arm encoding have some additional constraints for ldrexd/strexd:
3113 // - registers need to be consecutive
3114 // - the first register should be even but not R14.
3115 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3116 // enable Arm encoding.
3117 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3118 locations->AddTemp(Location::RequiresRegister());
3119 locations->AddTemp(Location::RequiresRegister());
3120 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003121}
3122
Calin Juravle52c48962014-12-16 17:02:57 +00003123void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3124 const FieldInfo& field_info) {
3125 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003126
Calin Juravle52c48962014-12-16 17:02:57 +00003127 LocationSummary* locations = instruction->GetLocations();
3128 Register base = locations->InAt(0).AsRegister<Register>();
3129 Location out = locations->Out();
3130 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003131 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003132 Primitive::Type field_type = field_info.GetFieldType();
3133 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3134
3135 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003136 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003137 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003138 break;
3139 }
3140
3141 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003142 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003143 break;
3144 }
3145
3146 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003147 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003148 break;
3149 }
3150
3151 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003152 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003153 break;
3154 }
3155
3156 case Primitive::kPrimInt:
3157 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003158 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003159 break;
3160 }
3161
3162 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003163 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003164 GenerateWideAtomicLoad(base, offset,
3165 out.AsRegisterPairLow<Register>(),
3166 out.AsRegisterPairHigh<Register>());
3167 } else {
3168 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3169 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003170 break;
3171 }
3172
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003173 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003174 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003175 break;
3176 }
3177
3178 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003179 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003180 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003181 Register lo = locations->GetTemp(0).AsRegister<Register>();
3182 Register hi = locations->GetTemp(1).AsRegister<Register>();
3183 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003184 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003185 __ vmovdrr(out_reg, lo, hi);
3186 } else {
3187 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003188 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003189 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003190 break;
3191 }
3192
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003193 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003194 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003195 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003196 }
Calin Juravle52c48962014-12-16 17:02:57 +00003197
Calin Juravle77520bc2015-01-12 18:45:46 +00003198 // Doubles are handled in the switch.
3199 if (field_type != Primitive::kPrimDouble) {
3200 codegen_->MaybeRecordImplicitNullCheck(instruction);
3201 }
3202
Calin Juravle52c48962014-12-16 17:02:57 +00003203 if (is_volatile) {
3204 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3205 }
3206}
3207
3208void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3209 HandleFieldSet(instruction, instruction->GetFieldInfo());
3210}
3211
3212void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003213 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003214}
3215
3216void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3217 HandleFieldGet(instruction, instruction->GetFieldInfo());
3218}
3219
3220void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3221 HandleFieldGet(instruction, instruction->GetFieldInfo());
3222}
3223
3224void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3225 HandleFieldGet(instruction, instruction->GetFieldInfo());
3226}
3227
3228void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3229 HandleFieldGet(instruction, instruction->GetFieldInfo());
3230}
3231
3232void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3233 HandleFieldSet(instruction, instruction->GetFieldInfo());
3234}
3235
3236void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003237 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003238}
3239
3240void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003241 LocationSummary* locations =
3242 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003243 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003244 if (instruction->HasUses()) {
3245 locations->SetOut(Location::SameAsFirstInput());
3246 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003247}
3248
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003249void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003250 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3251 return;
3252 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003253 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003254
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003255 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3256 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3257}
3258
3259void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003260 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003261 codegen_->AddSlowPath(slow_path);
3262
3263 LocationSummary* locations = instruction->GetLocations();
3264 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003265
Calin Juravle77520bc2015-01-12 18:45:46 +00003266 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
3267 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003268}
3269
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003270void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3271 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3272 GenerateImplicitNullCheck(instruction);
3273 } else {
3274 GenerateExplicitNullCheck(instruction);
3275 }
3276}
3277
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003278void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003279 LocationSummary* locations =
3280 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003281 locations->SetInAt(0, Location::RequiresRegister());
3282 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003283 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3284 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3285 } else {
3286 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3287 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003288}
3289
3290void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3291 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003292 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003293 Location index = locations->InAt(1);
3294
3295 switch (instruction->GetType()) {
3296 case Primitive::kPrimBoolean: {
3297 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003298 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003299 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003300 size_t offset =
3301 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003302 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3303 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003304 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003305 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3306 }
3307 break;
3308 }
3309
3310 case Primitive::kPrimByte: {
3311 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003312 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003313 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003314 size_t offset =
3315 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003316 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3317 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003318 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003319 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3320 }
3321 break;
3322 }
3323
3324 case Primitive::kPrimShort: {
3325 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003326 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003327 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003328 size_t offset =
3329 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003330 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3331 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003332 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003333 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3334 }
3335 break;
3336 }
3337
3338 case Primitive::kPrimChar: {
3339 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003340 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003341 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003342 size_t offset =
3343 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003344 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3345 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003346 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003347 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3348 }
3349 break;
3350 }
3351
3352 case Primitive::kPrimInt:
3353 case Primitive::kPrimNot: {
3354 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3355 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003356 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003357 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003358 size_t offset =
3359 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003360 __ LoadFromOffset(kLoadWord, out, obj, offset);
3361 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003362 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003363 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3364 }
3365 break;
3366 }
3367
3368 case Primitive::kPrimLong: {
3369 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003370 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003371 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003372 size_t offset =
3373 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003374 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003375 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003376 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003377 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003378 }
3379 break;
3380 }
3381
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003382 case Primitive::kPrimFloat: {
3383 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3384 Location out = locations->Out();
3385 DCHECK(out.IsFpuRegister());
3386 if (index.IsConstant()) {
3387 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3388 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3389 } else {
3390 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3391 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3392 }
3393 break;
3394 }
3395
3396 case Primitive::kPrimDouble: {
3397 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3398 Location out = locations->Out();
3399 DCHECK(out.IsFpuRegisterPair());
3400 if (index.IsConstant()) {
3401 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3402 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3403 } else {
3404 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3405 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3406 }
3407 break;
3408 }
3409
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003410 case Primitive::kPrimVoid:
3411 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003412 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003413 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003414 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003415}
3416
3417void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003418 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003419
3420 bool needs_write_barrier =
3421 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3422 bool needs_runtime_call = instruction->NeedsTypeCheck();
3423
Nicolas Geoffray39468442014-09-02 15:17:15 +01003424 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003425 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3426 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003427 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003428 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3429 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3430 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003431 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003432 locations->SetInAt(0, Location::RequiresRegister());
3433 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003434 if (Primitive::IsFloatingPointType(value_type)) {
3435 locations->SetInAt(2, Location::RequiresFpuRegister());
3436 } else {
3437 locations->SetInAt(2, Location::RequiresRegister());
3438 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003439
3440 if (needs_write_barrier) {
3441 // Temporary registers for the write barrier.
3442 locations->AddTemp(Location::RequiresRegister());
3443 locations->AddTemp(Location::RequiresRegister());
3444 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003445 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003446}
3447
3448void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3449 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003450 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003451 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003452 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003453 bool needs_runtime_call = locations->WillCall();
3454 bool needs_write_barrier =
3455 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003456
3457 switch (value_type) {
3458 case Primitive::kPrimBoolean:
3459 case Primitive::kPrimByte: {
3460 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003461 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003462 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003463 size_t offset =
3464 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003465 __ StoreToOffset(kStoreByte, value, obj, offset);
3466 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003467 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003468 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3469 }
3470 break;
3471 }
3472
3473 case Primitive::kPrimShort:
3474 case Primitive::kPrimChar: {
3475 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003476 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003477 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003478 size_t offset =
3479 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003480 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3481 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003482 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003483 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3484 }
3485 break;
3486 }
3487
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003488 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003489 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003490 if (!needs_runtime_call) {
3491 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003492 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003493 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003494 size_t offset =
3495 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003496 __ StoreToOffset(kStoreWord, value, obj, offset);
3497 } else {
3498 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003499 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003500 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3501 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003502 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003503 if (needs_write_barrier) {
3504 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003505 Register temp = locations->GetTemp(0).AsRegister<Register>();
3506 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003507 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003508 }
3509 } else {
3510 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003511 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3512 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003513 instruction->GetDexPc(),
3514 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003515 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003516 break;
3517 }
3518
3519 case Primitive::kPrimLong: {
3520 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003521 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003522 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003523 size_t offset =
3524 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003525 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003526 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003527 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003528 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003529 }
3530 break;
3531 }
3532
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003533 case Primitive::kPrimFloat: {
3534 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3535 Location value = locations->InAt(2);
3536 DCHECK(value.IsFpuRegister());
3537 if (index.IsConstant()) {
3538 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3539 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3540 } else {
3541 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3542 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3543 }
3544 break;
3545 }
3546
3547 case Primitive::kPrimDouble: {
3548 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3549 Location value = locations->InAt(2);
3550 DCHECK(value.IsFpuRegisterPair());
3551 if (index.IsConstant()) {
3552 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3553 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3554 } else {
3555 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3556 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3557 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003558
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003559 break;
3560 }
3561
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003562 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003563 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003564 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003565 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003566
3567 // Ints and objects are handled in the switch.
3568 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3569 codegen_->MaybeRecordImplicitNullCheck(instruction);
3570 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003571}
3572
3573void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003574 LocationSummary* locations =
3575 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003576 locations->SetInAt(0, Location::RequiresRegister());
3577 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003578}
3579
3580void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3581 LocationSummary* locations = instruction->GetLocations();
3582 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003583 Register obj = locations->InAt(0).AsRegister<Register>();
3584 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003585 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003586 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003587}
3588
3589void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003590 LocationSummary* locations =
3591 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003592 locations->SetInAt(0, Location::RequiresRegister());
3593 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003594 if (instruction->HasUses()) {
3595 locations->SetOut(Location::SameAsFirstInput());
3596 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003597}
3598
3599void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3600 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003601 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003602 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003603 codegen_->AddSlowPath(slow_path);
3604
Roland Levillain271ab9c2014-11-27 15:23:57 +00003605 Register index = locations->InAt(0).AsRegister<Register>();
3606 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003607
3608 __ cmp(index, ShifterOperand(length));
3609 __ b(slow_path->GetEntryLabel(), CS);
3610}
3611
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003612void CodeGeneratorARM::MarkGCCard(Register temp,
3613 Register card,
3614 Register object,
3615 Register value,
3616 bool can_be_null) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00003617 NearLabel is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003618 if (can_be_null) {
3619 __ CompareAndBranchIfZero(value, &is_null);
3620 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003621 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3622 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3623 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003624 if (can_be_null) {
3625 __ Bind(&is_null);
3626 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003627}
3628
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003629void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3630 temp->SetLocations(nullptr);
3631}
3632
3633void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3634 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003635 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003636}
3637
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003638void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003639 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003640 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003641}
3642
3643void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003644 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3645}
3646
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003647void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3648 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3649}
3650
3651void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003652 HBasicBlock* block = instruction->GetBlock();
3653 if (block->GetLoopInformation() != nullptr) {
3654 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3655 // The back edge will generate the suspend check.
3656 return;
3657 }
3658 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3659 // The goto will generate the suspend check.
3660 return;
3661 }
3662 GenerateSuspendCheck(instruction, nullptr);
3663}
3664
3665void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3666 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003667 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003668 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3669 if (slow_path == nullptr) {
3670 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3671 instruction->SetSlowPath(slow_path);
3672 codegen_->AddSlowPath(slow_path);
3673 if (successor != nullptr) {
3674 DCHECK(successor->IsLoopHeader());
3675 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3676 }
3677 } else {
3678 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3679 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003680
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003681 __ LoadFromOffset(
3682 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3683 __ cmp(IP, ShifterOperand(0));
3684 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003685 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003686 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003687 __ Bind(slow_path->GetReturnLabel());
3688 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003689 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003690 __ b(slow_path->GetEntryLabel());
3691 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003692}
3693
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003694ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3695 return codegen_->GetAssembler();
3696}
3697
3698void ParallelMoveResolverARM::EmitMove(size_t index) {
3699 MoveOperands* move = moves_.Get(index);
3700 Location source = move->GetSource();
3701 Location destination = move->GetDestination();
3702
3703 if (source.IsRegister()) {
3704 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003705 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003706 } else {
3707 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003708 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003709 SP, destination.GetStackIndex());
3710 }
3711 } else if (source.IsStackSlot()) {
3712 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003713 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003714 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003715 } else if (destination.IsFpuRegister()) {
3716 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003717 } else {
3718 DCHECK(destination.IsStackSlot());
3719 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3720 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3721 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003722 } else if (source.IsFpuRegister()) {
3723 if (destination.IsFpuRegister()) {
3724 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003725 } else {
3726 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003727 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3728 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003729 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003730 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003731 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3732 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003733 } else if (destination.IsRegisterPair()) {
3734 DCHECK(ExpectedPairLayout(destination));
3735 __ LoadFromOffset(
3736 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3737 } else {
3738 DCHECK(destination.IsFpuRegisterPair()) << destination;
3739 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3740 SP,
3741 source.GetStackIndex());
3742 }
3743 } else if (source.IsRegisterPair()) {
3744 if (destination.IsRegisterPair()) {
3745 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3746 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3747 } else {
3748 DCHECK(destination.IsDoubleStackSlot()) << destination;
3749 DCHECK(ExpectedPairLayout(source));
3750 __ StoreToOffset(
3751 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3752 }
3753 } else if (source.IsFpuRegisterPair()) {
3754 if (destination.IsFpuRegisterPair()) {
3755 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3756 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3757 } else {
3758 DCHECK(destination.IsDoubleStackSlot()) << destination;
3759 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3760 SP,
3761 destination.GetStackIndex());
3762 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003763 } else {
3764 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003765 HConstant* constant = source.GetConstant();
3766 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3767 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003768 if (destination.IsRegister()) {
3769 __ LoadImmediate(destination.AsRegister<Register>(), value);
3770 } else {
3771 DCHECK(destination.IsStackSlot());
3772 __ LoadImmediate(IP, value);
3773 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3774 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003775 } else if (constant->IsLongConstant()) {
3776 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003777 if (destination.IsRegisterPair()) {
3778 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3779 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003780 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003781 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003782 __ LoadImmediate(IP, Low32Bits(value));
3783 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3784 __ LoadImmediate(IP, High32Bits(value));
3785 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3786 }
3787 } else if (constant->IsDoubleConstant()) {
3788 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003789 if (destination.IsFpuRegisterPair()) {
3790 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003791 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003792 DCHECK(destination.IsDoubleStackSlot()) << destination;
3793 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003794 __ LoadImmediate(IP, Low32Bits(int_value));
3795 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3796 __ LoadImmediate(IP, High32Bits(int_value));
3797 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3798 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003799 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003800 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003801 float value = constant->AsFloatConstant()->GetValue();
3802 if (destination.IsFpuRegister()) {
3803 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3804 } else {
3805 DCHECK(destination.IsStackSlot());
3806 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3807 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3808 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003809 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003810 }
3811}
3812
3813void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3814 __ Mov(IP, reg);
3815 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3816 __ StoreToOffset(kStoreWord, IP, SP, mem);
3817}
3818
3819void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3820 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3821 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3822 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3823 SP, mem1 + stack_offset);
3824 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3825 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3826 SP, mem2 + stack_offset);
3827 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3828}
3829
3830void ParallelMoveResolverARM::EmitSwap(size_t index) {
3831 MoveOperands* move = moves_.Get(index);
3832 Location source = move->GetSource();
3833 Location destination = move->GetDestination();
3834
3835 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003836 DCHECK_NE(source.AsRegister<Register>(), IP);
3837 DCHECK_NE(destination.AsRegister<Register>(), IP);
3838 __ Mov(IP, source.AsRegister<Register>());
3839 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3840 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003841 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003842 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003843 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003844 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003845 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3846 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003847 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003848 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003849 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003850 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003851 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003852 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003853 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003854 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003855 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3856 destination.AsRegisterPairHigh<Register>(),
3857 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003858 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003859 Register low_reg = source.IsRegisterPair()
3860 ? source.AsRegisterPairLow<Register>()
3861 : destination.AsRegisterPairLow<Register>();
3862 int mem = source.IsRegisterPair()
3863 ? destination.GetStackIndex()
3864 : source.GetStackIndex();
3865 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003866 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003867 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003868 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003869 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003870 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3871 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003872 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003873 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003874 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003875 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3876 DRegister reg = source.IsFpuRegisterPair()
3877 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3878 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3879 int mem = source.IsFpuRegisterPair()
3880 ? destination.GetStackIndex()
3881 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003882 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003883 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003884 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003885 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3886 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3887 : destination.AsFpuRegister<SRegister>();
3888 int mem = source.IsFpuRegister()
3889 ? destination.GetStackIndex()
3890 : source.GetStackIndex();
3891
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003892 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003893 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003894 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003895 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003896 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3897 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003898 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003899 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003900 }
3901}
3902
3903void ParallelMoveResolverARM::SpillScratch(int reg) {
3904 __ Push(static_cast<Register>(reg));
3905}
3906
3907void ParallelMoveResolverARM::RestoreScratch(int reg) {
3908 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003909}
3910
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003911void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003912 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3913 ? LocationSummary::kCallOnSlowPath
3914 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003915 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003916 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003917 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003918 locations->SetOut(Location::RequiresRegister());
3919}
3920
3921void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003922 LocationSummary* locations = cls->GetLocations();
3923 Register out = locations->Out().AsRegister<Register>();
3924 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003925 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003926 DCHECK(!cls->CanCallRuntime());
3927 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003928 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07003929 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003930 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003931 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003932 __ LoadFromOffset(kLoadWord,
3933 out,
3934 current_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -07003935 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003936 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003937
3938 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3939 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3940 codegen_->AddSlowPath(slow_path);
3941 __ cmp(out, ShifterOperand(0));
3942 __ b(slow_path->GetEntryLabel(), EQ);
3943 if (cls->MustGenerateClinitCheck()) {
3944 GenerateClassInitializationCheck(slow_path, out);
3945 } else {
3946 __ Bind(slow_path->GetExitLabel());
3947 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003948 }
3949}
3950
3951void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3952 LocationSummary* locations =
3953 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3954 locations->SetInAt(0, Location::RequiresRegister());
3955 if (check->HasUses()) {
3956 locations->SetOut(Location::SameAsFirstInput());
3957 }
3958}
3959
3960void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003961 // We assume the class is not null.
3962 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3963 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003964 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003965 GenerateClassInitializationCheck(slow_path,
3966 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003967}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003968
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003969void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3970 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003971 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3972 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3973 __ b(slow_path->GetEntryLabel(), LT);
3974 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3975 // properly. Therefore, we do a memory fence.
3976 __ dmb(ISH);
3977 __ Bind(slow_path->GetExitLabel());
3978}
3979
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003980void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3981 LocationSummary* locations =
3982 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01003983 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003984 locations->SetOut(Location::RequiresRegister());
3985}
3986
3987void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3988 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3989 codegen_->AddSlowPath(slow_path);
3990
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01003991 LocationSummary* locations = load->GetLocations();
3992 Register out = locations->Out().AsRegister<Register>();
3993 Register current_method = locations->InAt(0).AsRegister<Register>();
3994 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07003995 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08003996 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003997 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3998 __ cmp(out, ShifterOperand(0));
3999 __ b(slow_path->GetEntryLabel(), EQ);
4000 __ Bind(slow_path->GetExitLabel());
4001}
4002
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004003void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4004 LocationSummary* locations =
4005 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4006 locations->SetOut(Location::RequiresRegister());
4007}
4008
4009void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004010 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004011 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4012 __ LoadFromOffset(kLoadWord, out, TR, offset);
4013 __ LoadImmediate(IP, 0);
4014 __ StoreToOffset(kStoreWord, IP, TR, offset);
4015}
4016
4017void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4018 LocationSummary* locations =
4019 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4020 InvokeRuntimeCallingConvention calling_convention;
4021 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4022}
4023
4024void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4025 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004026 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004027}
4028
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004029void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004030 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4031 ? LocationSummary::kNoCall
4032 : LocationSummary::kCallOnSlowPath;
4033 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4034 locations->SetInAt(0, Location::RequiresRegister());
4035 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004036 // The out register is used as a temporary, so it overlaps with the inputs.
4037 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004038}
4039
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004040void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004041 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004042 Register obj = locations->InAt(0).AsRegister<Register>();
4043 Register cls = locations->InAt(1).AsRegister<Register>();
4044 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004045 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004046 NearLabel done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004047 SlowPathCodeARM* slow_path = nullptr;
4048
4049 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004050 // avoid null check if we know obj is not null.
4051 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004052 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004053 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004054 // Compare the class of `obj` with `cls`.
4055 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
4056 __ cmp(out, ShifterOperand(cls));
4057 if (instruction->IsClassFinal()) {
4058 // Classes must be equal for the instanceof to succeed.
4059 __ b(&zero, NE);
4060 __ LoadImmediate(out, 1);
4061 __ b(&done);
4062 } else {
4063 // If the classes are not equal, we go into a slow path.
4064 DCHECK(locations->OnlyCallsOnSlowPath());
4065 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004066 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004067 codegen_->AddSlowPath(slow_path);
4068 __ b(slow_path->GetEntryLabel(), NE);
4069 __ LoadImmediate(out, 1);
4070 __ b(&done);
4071 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004072
4073 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4074 __ Bind(&zero);
4075 __ LoadImmediate(out, 0);
4076 }
4077
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004078 if (slow_path != nullptr) {
4079 __ Bind(slow_path->GetExitLabel());
4080 }
4081 __ Bind(&done);
4082}
4083
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004084void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4085 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4086 instruction, LocationSummary::kCallOnSlowPath);
4087 locations->SetInAt(0, Location::RequiresRegister());
4088 locations->SetInAt(1, Location::RequiresRegister());
4089 locations->AddTemp(Location::RequiresRegister());
4090}
4091
4092void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4093 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004094 Register obj = locations->InAt(0).AsRegister<Register>();
4095 Register cls = locations->InAt(1).AsRegister<Register>();
4096 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004097 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4098
4099 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4100 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
4101 codegen_->AddSlowPath(slow_path);
4102
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004103 NearLabel done;
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004104 // avoid null check if we know obj is not null.
4105 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004106 __ CompareAndBranchIfZero(obj, &done);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004107 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004108 // Compare the class of `obj` with `cls`.
4109 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
4110 __ cmp(temp, ShifterOperand(cls));
4111 __ b(slow_path->GetEntryLabel(), NE);
4112 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004113 if (instruction->MustDoNullCheck()) {
4114 __ Bind(&done);
4115 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004116}
4117
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004118void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4119 LocationSummary* locations =
4120 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4121 InvokeRuntimeCallingConvention calling_convention;
4122 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4123}
4124
4125void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4126 codegen_->InvokeRuntime(instruction->IsEnter()
4127 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4128 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004129 instruction->GetDexPc(),
4130 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004131}
4132
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004133void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4134void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4135void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4136
4137void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4138 LocationSummary* locations =
4139 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4140 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4141 || instruction->GetResultType() == Primitive::kPrimLong);
4142 locations->SetInAt(0, Location::RequiresRegister());
4143 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004144 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004145}
4146
4147void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4148 HandleBitwiseOperation(instruction);
4149}
4150
4151void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4152 HandleBitwiseOperation(instruction);
4153}
4154
4155void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4156 HandleBitwiseOperation(instruction);
4157}
4158
4159void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4160 LocationSummary* locations = instruction->GetLocations();
4161
4162 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004163 Register first = locations->InAt(0).AsRegister<Register>();
4164 Register second = locations->InAt(1).AsRegister<Register>();
4165 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004166 if (instruction->IsAnd()) {
4167 __ and_(out, first, ShifterOperand(second));
4168 } else if (instruction->IsOr()) {
4169 __ orr(out, first, ShifterOperand(second));
4170 } else {
4171 DCHECK(instruction->IsXor());
4172 __ eor(out, first, ShifterOperand(second));
4173 }
4174 } else {
4175 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4176 Location first = locations->InAt(0);
4177 Location second = locations->InAt(1);
4178 Location out = locations->Out();
4179 if (instruction->IsAnd()) {
4180 __ and_(out.AsRegisterPairLow<Register>(),
4181 first.AsRegisterPairLow<Register>(),
4182 ShifterOperand(second.AsRegisterPairLow<Register>()));
4183 __ and_(out.AsRegisterPairHigh<Register>(),
4184 first.AsRegisterPairHigh<Register>(),
4185 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4186 } else if (instruction->IsOr()) {
4187 __ orr(out.AsRegisterPairLow<Register>(),
4188 first.AsRegisterPairLow<Register>(),
4189 ShifterOperand(second.AsRegisterPairLow<Register>()));
4190 __ orr(out.AsRegisterPairHigh<Register>(),
4191 first.AsRegisterPairHigh<Register>(),
4192 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4193 } else {
4194 DCHECK(instruction->IsXor());
4195 __ eor(out.AsRegisterPairLow<Register>(),
4196 first.AsRegisterPairLow<Register>(),
4197 ShifterOperand(second.AsRegisterPairLow<Register>()));
4198 __ eor(out.AsRegisterPairHigh<Register>(),
4199 first.AsRegisterPairHigh<Register>(),
4200 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4201 }
4202 }
4203}
4204
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004205void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004206 // TODO: Implement all kinds of calls:
4207 // 1) boot -> boot
4208 // 2) app -> boot
4209 // 3) app -> app
4210 //
4211 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4212
Jeff Hao848f70a2014-01-15 13:49:50 -08004213 if (invoke->IsStringInit()) {
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004214 Register reg = temp.AsRegister<Register>();
Jeff Hao848f70a2014-01-15 13:49:50 -08004215 // temp = thread->string_init_entrypoint
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004216 __ LoadFromOffset(kLoadWord, reg, TR, invoke->GetStringInitOffset());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004217 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004218 __ LoadFromOffset(kLoadWord, LR, reg,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004219 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004220 kArmWordSize).Int32Value());
4221 // LR()
4222 __ blx(LR);
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004223 } else if (invoke->IsRecursive()) {
4224 __ bl(GetFrameEntryLabel());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004225 } else {
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004226 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4227 Register method_reg;
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004228 Register reg = temp.AsRegister<Register>();
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004229 if (current_method.IsRegister()) {
4230 method_reg = current_method.AsRegister<Register>();
4231 } else {
4232 DCHECK(invoke->GetLocations()->Intrinsified());
4233 DCHECK(!current_method.IsValid());
4234 method_reg = reg;
4235 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
4236 }
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004237 // reg = current_method->dex_cache_resolved_methods_;
4238 __ LoadFromOffset(
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004239 kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004240 // reg = reg[index_in_cache]
4241 __ LoadFromOffset(
4242 kLoadWord, reg, reg, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4243 // LR = reg[offset_of_quick_compiled_code]
4244 __ LoadFromOffset(kLoadWord, LR, reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4245 kArmWordSize).Int32Value());
4246 // LR()
4247 __ blx(LR);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004248 }
4249
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004250 DCHECK(!IsLeafMethod());
4251}
4252
Calin Juravleb1498f62015-02-16 13:13:29 +00004253void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4254 // Nothing to do, this should be removed during prepare for register allocator.
4255 UNUSED(instruction);
4256 LOG(FATAL) << "Unreachable";
4257}
4258
4259void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4260 // Nothing to do, this should be removed during prepare for register allocator.
4261 UNUSED(instruction);
4262 LOG(FATAL) << "Unreachable";
4263}
4264
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004265} // namespace arm
4266} // namespace art