blob: 022948e0e7fed12604d8f55c0c74b3572ed36c11 [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 }
710 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000711}
712
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100713Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
714 return Location::RegisterLocation(kMethodRegisterArgument);
715}
716
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100717void CodeGeneratorARM::Move32(Location destination, Location source) {
718 if (source.Equals(destination)) {
719 return;
720 }
721 if (destination.IsRegister()) {
722 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000723 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100724 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000725 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100726 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000727 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100728 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100729 } else if (destination.IsFpuRegister()) {
730 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000731 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100732 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000733 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100734 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000735 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100736 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100737 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000738 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100739 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000740 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100741 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000742 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100743 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000744 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100745 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
746 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100747 }
748 }
749}
750
751void CodeGeneratorARM::Move64(Location destination, Location source) {
752 if (source.Equals(destination)) {
753 return;
754 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100755 if (destination.IsRegisterPair()) {
756 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000757 EmitParallelMoves(
758 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
759 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100760 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000761 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100762 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
763 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100764 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000765 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100766 } else {
767 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000768 DCHECK(ExpectedPairLayout(destination));
769 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
770 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100771 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000772 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100773 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000774 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
775 SP,
776 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100777 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000778 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100779 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100780 } else {
781 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100782 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000783 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100784 if (source.AsRegisterPairLow<Register>() == R1) {
785 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100786 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
787 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100788 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100789 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100790 SP, destination.GetStackIndex());
791 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000792 } else if (source.IsFpuRegisterPair()) {
793 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
794 SP,
795 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100796 } else {
797 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000798 EmitParallelMoves(
799 Location::StackSlot(source.GetStackIndex()),
800 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100801 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000802 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100803 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
804 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100805 }
806 }
807}
808
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100809void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100810 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100811 if (instruction->IsCurrentMethod()) {
812 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
813 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100814 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100815 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000816 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000817 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
818 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000819 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000820 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000821 } else {
822 DCHECK(location.IsStackSlot());
823 __ LoadImmediate(IP, value);
824 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
825 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000826 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000827 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000828 int64_t value = const_to_move->AsLongConstant()->GetValue();
829 if (location.IsRegisterPair()) {
830 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
831 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
832 } else {
833 DCHECK(location.IsDoubleStackSlot());
834 __ LoadImmediate(IP, Low32Bits(value));
835 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
836 __ LoadImmediate(IP, High32Bits(value));
837 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
838 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100839 }
Roland Levillain476df552014-10-09 17:51:36 +0100840 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100841 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
842 switch (instruction->GetType()) {
843 case Primitive::kPrimBoolean:
844 case Primitive::kPrimByte:
845 case Primitive::kPrimChar:
846 case Primitive::kPrimShort:
847 case Primitive::kPrimInt:
848 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100849 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100850 Move32(location, Location::StackSlot(stack_slot));
851 break;
852
853 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100854 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100855 Move64(location, Location::DoubleStackSlot(stack_slot));
856 break;
857
858 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100859 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100860 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000861 } else if (instruction->IsTemporary()) {
862 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000863 if (temp_location.IsStackSlot()) {
864 Move32(location, temp_location);
865 } else {
866 DCHECK(temp_location.IsDoubleStackSlot());
867 Move64(location, temp_location);
868 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000869 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100870 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100871 switch (instruction->GetType()) {
872 case Primitive::kPrimBoolean:
873 case Primitive::kPrimByte:
874 case Primitive::kPrimChar:
875 case Primitive::kPrimShort:
876 case Primitive::kPrimNot:
877 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100878 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100879 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100880 break;
881
882 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100883 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100884 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100885 break;
886
887 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100888 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100889 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000890 }
891}
892
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100893void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
894 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000895 uint32_t dex_pc,
896 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100897 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
898 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000899 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100900 DCHECK(instruction->IsSuspendCheck()
901 || instruction->IsBoundsCheck()
902 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000903 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000904 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100905 || !IsLeafMethod());
906}
907
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000908void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000909 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000910}
911
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000912void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000913 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100914 DCHECK(!successor->IsExitBlock());
915
916 HBasicBlock* block = got->GetBlock();
917 HInstruction* previous = got->GetPrevious();
918
919 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000920 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100921 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
922 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
923 return;
924 }
925
926 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
927 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
928 }
929 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000930 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000931 }
932}
933
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000934void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000935 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000936}
937
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000938void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700939 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000940}
941
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700942void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
943 Label* true_target,
944 Label* false_target,
945 Label* always_true_target) {
946 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100947 if (cond->IsIntConstant()) {
948 // Constant condition, statically compared against 1.
949 int32_t cond_value = cond->AsIntConstant()->GetValue();
950 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700951 if (always_true_target != nullptr) {
952 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100953 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100954 return;
955 } else {
956 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100957 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100958 } else {
959 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
960 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700961 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
962 __ cmp(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100963 ShifterOperand(0));
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700964 __ b(true_target, NE);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100965 } else {
966 // Condition has not been materialized, use its inputs as the
967 // comparison and its condition as the branch condition.
968 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000969 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000970 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100971 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000972 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100973 } else {
974 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000975 HConstant* constant = locations->InAt(1).GetConstant();
976 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100977 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000978 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
979 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100980 } else {
981 Register temp = IP;
982 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000983 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100984 }
985 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700986 __ b(true_target, ARMCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100987 }
Dave Allison20dfc792014-06-16 20:44:29 -0700988 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700989 if (false_target != nullptr) {
990 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000991 }
992}
993
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700994void LocationsBuilderARM::VisitIf(HIf* if_instr) {
995 LocationSummary* locations =
996 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
997 HInstruction* cond = if_instr->InputAt(0);
998 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
999 locations->SetInAt(0, Location::RequiresRegister());
1000 }
1001}
1002
1003void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1004 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1005 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1006 Label* always_true_target = true_target;
1007 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1008 if_instr->IfTrueSuccessor())) {
1009 always_true_target = nullptr;
1010 }
1011 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1012 if_instr->IfFalseSuccessor())) {
1013 false_target = nullptr;
1014 }
1015 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1016}
1017
1018void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1019 LocationSummary* locations = new (GetGraph()->GetArena())
1020 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1021 HInstruction* cond = deoptimize->InputAt(0);
1022 DCHECK(cond->IsCondition());
1023 if (cond->AsCondition()->NeedsMaterialization()) {
1024 locations->SetInAt(0, Location::RequiresRegister());
1025 }
1026}
1027
1028void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1029 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1030 DeoptimizationSlowPathARM(deoptimize);
1031 codegen_->AddSlowPath(slow_path);
1032 Label* slow_path_entry = slow_path->GetEntryLabel();
1033 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1034}
Dave Allison20dfc792014-06-16 20:44:29 -07001035
Roland Levillain0d37cd02015-05-27 16:39:19 +01001036void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001037 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001038 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001039 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain0d37cd02015-05-27 16:39:19 +01001040 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1041 if (cond->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001042 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001043 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001044}
1045
Roland Levillain0d37cd02015-05-27 16:39:19 +01001046void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
1047 if (!cond->NeedsMaterialization()) return;
1048 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001049 Register left = locations->InAt(0).AsRegister<Register>();
1050
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001051 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001052 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001053 } else {
1054 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -08001055 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001056 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001057 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1058 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001059 } else {
1060 Register temp = IP;
1061 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001062 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001063 }
Dave Allison20dfc792014-06-16 20:44:29 -07001064 }
Roland Levillain0d37cd02015-05-27 16:39:19 +01001065 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001066 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001067 ARMCondition(cond->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001068 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001069 ARMOppositeCondition(cond->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001070}
1071
1072void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1073 VisitCondition(comp);
1074}
1075
1076void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1077 VisitCondition(comp);
1078}
1079
1080void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1081 VisitCondition(comp);
1082}
1083
1084void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1085 VisitCondition(comp);
1086}
1087
1088void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1089 VisitCondition(comp);
1090}
1091
1092void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1093 VisitCondition(comp);
1094}
1095
1096void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1097 VisitCondition(comp);
1098}
1099
1100void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1101 VisitCondition(comp);
1102}
1103
1104void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1105 VisitCondition(comp);
1106}
1107
1108void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1109 VisitCondition(comp);
1110}
1111
1112void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1113 VisitCondition(comp);
1114}
1115
1116void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1117 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001118}
1119
1120void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001121 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001122}
1123
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001124void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1125 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001126}
1127
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001128void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001129 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001130}
1131
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001132void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001133 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001134 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001135}
1136
1137void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001138 LocationSummary* locations =
1139 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001140 switch (store->InputAt(1)->GetType()) {
1141 case Primitive::kPrimBoolean:
1142 case Primitive::kPrimByte:
1143 case Primitive::kPrimChar:
1144 case Primitive::kPrimShort:
1145 case Primitive::kPrimInt:
1146 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001147 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001148 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1149 break;
1150
1151 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001152 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001153 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1154 break;
1155
1156 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001157 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001158 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001159}
1160
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001161void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001162 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001163}
1164
1165void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001166 LocationSummary* locations =
1167 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001168 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001169}
1170
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001171void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001172 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001173 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001174}
1175
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001176void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1177 LocationSummary* locations =
1178 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1179 locations->SetOut(Location::ConstantLocation(constant));
1180}
1181
1182void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1183 // Will be generated at use site.
1184 UNUSED(constant);
1185}
1186
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001187void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001188 LocationSummary* locations =
1189 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001190 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001191}
1192
1193void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1194 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001195 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001196}
1197
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001198void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1199 LocationSummary* locations =
1200 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1201 locations->SetOut(Location::ConstantLocation(constant));
1202}
1203
1204void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1205 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001206 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001207}
1208
1209void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1210 LocationSummary* locations =
1211 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1212 locations->SetOut(Location::ConstantLocation(constant));
1213}
1214
1215void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1216 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001217 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001218}
1219
Calin Juravle27df7582015-04-17 19:12:31 +01001220void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1221 memory_barrier->SetLocations(nullptr);
1222}
1223
1224void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1225 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1226}
1227
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001228void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001229 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001230}
1231
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001232void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001233 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001234 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001235}
1236
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001237void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001238 LocationSummary* locations =
1239 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001240 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001241}
1242
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001243void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001244 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001245 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001246}
1247
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001248void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001249 // When we do not run baseline, explicit clinit checks triggered by static
1250 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1251 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001252
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001253 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1254 codegen_->GetInstructionSetFeatures());
1255 if (intrinsic.TryDispatch(invoke)) {
1256 return;
1257 }
1258
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001259 HandleInvoke(invoke);
1260}
1261
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001262void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001263 DCHECK(RequiresCurrentMethod());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001264 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001265}
1266
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001267static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1268 if (invoke->GetLocations()->Intrinsified()) {
1269 IntrinsicCodeGeneratorARM intrinsic(codegen);
1270 intrinsic.Dispatch(invoke);
1271 return true;
1272 }
1273 return false;
1274}
1275
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001276void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001277 // When we do not run baseline, explicit clinit checks triggered by static
1278 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1279 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001280
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001281 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1282 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001283 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001284
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001285 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
1286
1287 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001288 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001289}
1290
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001291void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001292 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001293 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001294}
1295
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001296void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001297 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1298 codegen_->GetInstructionSetFeatures());
1299 if (intrinsic.TryDispatch(invoke)) {
1300 return;
1301 }
1302
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001303 HandleInvoke(invoke);
1304}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001305
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001306void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001307 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1308 return;
1309 }
1310
Roland Levillain271ab9c2014-11-27 15:23:57 +00001311 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001312 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
1313 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001314 LocationSummary* locations = invoke->GetLocations();
1315 Location receiver = locations->InAt(0);
1316 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1317 // temp = object->GetClass();
1318 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001319 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1320 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001321 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001322 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001323 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001324 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001325 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001326 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001327 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001328 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001329 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001330 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001331 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001332 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001333 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001334 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001335}
1336
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001337void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1338 HandleInvoke(invoke);
1339 // Add the hidden argument.
1340 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1341}
1342
1343void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1344 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001345 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001346 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1347 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001348 LocationSummary* locations = invoke->GetLocations();
1349 Location receiver = locations->InAt(0);
1350 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1351
1352 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001353 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1354 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001355
1356 // temp = object->GetClass();
1357 if (receiver.IsStackSlot()) {
1358 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1359 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1360 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001361 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001362 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001363 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001364 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001365 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001366 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001367 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1368 // LR = temp->GetEntryPoint();
1369 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1370 // LR();
1371 __ blx(LR);
1372 DCHECK(!codegen_->IsLeafMethod());
1373 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1374}
1375
Roland Levillain88cb1752014-10-20 16:36:47 +01001376void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1377 LocationSummary* locations =
1378 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1379 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001380 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001381 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001382 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1383 break;
1384 }
1385 case Primitive::kPrimLong: {
1386 locations->SetInAt(0, Location::RequiresRegister());
1387 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001388 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001389 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001390
Roland Levillain88cb1752014-10-20 16:36:47 +01001391 case Primitive::kPrimFloat:
1392 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001393 locations->SetInAt(0, Location::RequiresFpuRegister());
1394 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001395 break;
1396
1397 default:
1398 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1399 }
1400}
1401
1402void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1403 LocationSummary* locations = neg->GetLocations();
1404 Location out = locations->Out();
1405 Location in = locations->InAt(0);
1406 switch (neg->GetResultType()) {
1407 case Primitive::kPrimInt:
1408 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001409 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001410 break;
1411
1412 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001413 DCHECK(in.IsRegisterPair());
1414 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1415 __ rsbs(out.AsRegisterPairLow<Register>(),
1416 in.AsRegisterPairLow<Register>(),
1417 ShifterOperand(0));
1418 // We cannot emit an RSC (Reverse Subtract with Carry)
1419 // instruction here, as it does not exist in the Thumb-2
1420 // instruction set. We use the following approach
1421 // using SBC and SUB instead.
1422 //
1423 // out.hi = -C
1424 __ sbc(out.AsRegisterPairHigh<Register>(),
1425 out.AsRegisterPairHigh<Register>(),
1426 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1427 // out.hi = out.hi - in.hi
1428 __ sub(out.AsRegisterPairHigh<Register>(),
1429 out.AsRegisterPairHigh<Register>(),
1430 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1431 break;
1432
Roland Levillain88cb1752014-10-20 16:36:47 +01001433 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001434 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001435 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001436 break;
1437
Roland Levillain88cb1752014-10-20 16:36:47 +01001438 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001439 DCHECK(in.IsFpuRegisterPair());
1440 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1441 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001442 break;
1443
1444 default:
1445 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1446 }
1447}
1448
Roland Levillaindff1f282014-11-05 14:15:05 +00001449void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001450 Primitive::Type result_type = conversion->GetResultType();
1451 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001452 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001453
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001454 // The float-to-long and double-to-long type conversions rely on a
1455 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001456 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001457 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1458 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001459 ? LocationSummary::kCall
1460 : LocationSummary::kNoCall;
1461 LocationSummary* locations =
1462 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1463
David Brazdilb2bd1c52015-03-25 11:17:37 +00001464 // The Java language does not allow treating boolean as an integral type but
1465 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001466
Roland Levillaindff1f282014-11-05 14:15:05 +00001467 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001468 case Primitive::kPrimByte:
1469 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001470 case Primitive::kPrimBoolean:
1471 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001472 case Primitive::kPrimShort:
1473 case Primitive::kPrimInt:
1474 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001475 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001476 locations->SetInAt(0, Location::RequiresRegister());
1477 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1478 break;
1479
1480 default:
1481 LOG(FATAL) << "Unexpected type conversion from " << input_type
1482 << " to " << result_type;
1483 }
1484 break;
1485
Roland Levillain01a8d712014-11-14 16:27:39 +00001486 case Primitive::kPrimShort:
1487 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001488 case Primitive::kPrimBoolean:
1489 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001490 case Primitive::kPrimByte:
1491 case Primitive::kPrimInt:
1492 case Primitive::kPrimChar:
1493 // Processing a Dex `int-to-short' instruction.
1494 locations->SetInAt(0, Location::RequiresRegister());
1495 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1496 break;
1497
1498 default:
1499 LOG(FATAL) << "Unexpected type conversion from " << input_type
1500 << " to " << result_type;
1501 }
1502 break;
1503
Roland Levillain946e1432014-11-11 17:35:19 +00001504 case Primitive::kPrimInt:
1505 switch (input_type) {
1506 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001507 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001508 locations->SetInAt(0, Location::Any());
1509 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1510 break;
1511
1512 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001513 // Processing a Dex `float-to-int' instruction.
1514 locations->SetInAt(0, Location::RequiresFpuRegister());
1515 locations->SetOut(Location::RequiresRegister());
1516 locations->AddTemp(Location::RequiresFpuRegister());
1517 break;
1518
Roland Levillain946e1432014-11-11 17:35:19 +00001519 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001520 // Processing a Dex `double-to-int' instruction.
1521 locations->SetInAt(0, Location::RequiresFpuRegister());
1522 locations->SetOut(Location::RequiresRegister());
1523 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001524 break;
1525
1526 default:
1527 LOG(FATAL) << "Unexpected type conversion from " << input_type
1528 << " to " << result_type;
1529 }
1530 break;
1531
Roland Levillaindff1f282014-11-05 14:15:05 +00001532 case Primitive::kPrimLong:
1533 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001534 case Primitive::kPrimBoolean:
1535 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001536 case Primitive::kPrimByte:
1537 case Primitive::kPrimShort:
1538 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001539 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001540 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001541 locations->SetInAt(0, Location::RequiresRegister());
1542 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1543 break;
1544
Roland Levillain624279f2014-12-04 11:54:28 +00001545 case Primitive::kPrimFloat: {
1546 // Processing a Dex `float-to-long' instruction.
1547 InvokeRuntimeCallingConvention calling_convention;
1548 locations->SetInAt(0, Location::FpuRegisterLocation(
1549 calling_convention.GetFpuRegisterAt(0)));
1550 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1551 break;
1552 }
1553
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001554 case Primitive::kPrimDouble: {
1555 // Processing a Dex `double-to-long' instruction.
1556 InvokeRuntimeCallingConvention calling_convention;
1557 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1558 calling_convention.GetFpuRegisterAt(0),
1559 calling_convention.GetFpuRegisterAt(1)));
1560 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001561 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001562 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001563
1564 default:
1565 LOG(FATAL) << "Unexpected type conversion from " << input_type
1566 << " to " << result_type;
1567 }
1568 break;
1569
Roland Levillain981e4542014-11-14 11:47:14 +00001570 case Primitive::kPrimChar:
1571 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001572 case Primitive::kPrimBoolean:
1573 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001574 case Primitive::kPrimByte:
1575 case Primitive::kPrimShort:
1576 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001577 // Processing a Dex `int-to-char' instruction.
1578 locations->SetInAt(0, Location::RequiresRegister());
1579 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1580 break;
1581
1582 default:
1583 LOG(FATAL) << "Unexpected type conversion from " << input_type
1584 << " to " << result_type;
1585 }
1586 break;
1587
Roland Levillaindff1f282014-11-05 14:15:05 +00001588 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001589 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001590 case Primitive::kPrimBoolean:
1591 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001592 case Primitive::kPrimByte:
1593 case Primitive::kPrimShort:
1594 case Primitive::kPrimInt:
1595 case Primitive::kPrimChar:
1596 // Processing a Dex `int-to-float' instruction.
1597 locations->SetInAt(0, Location::RequiresRegister());
1598 locations->SetOut(Location::RequiresFpuRegister());
1599 break;
1600
1601 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001602 // Processing a Dex `long-to-float' instruction.
1603 locations->SetInAt(0, Location::RequiresRegister());
1604 locations->SetOut(Location::RequiresFpuRegister());
1605 locations->AddTemp(Location::RequiresRegister());
1606 locations->AddTemp(Location::RequiresRegister());
1607 locations->AddTemp(Location::RequiresFpuRegister());
1608 locations->AddTemp(Location::RequiresFpuRegister());
1609 break;
1610
Roland Levillaincff13742014-11-17 14:32:17 +00001611 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001612 // Processing a Dex `double-to-float' instruction.
1613 locations->SetInAt(0, Location::RequiresFpuRegister());
1614 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001615 break;
1616
1617 default:
1618 LOG(FATAL) << "Unexpected type conversion from " << input_type
1619 << " to " << result_type;
1620 };
1621 break;
1622
Roland Levillaindff1f282014-11-05 14:15:05 +00001623 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001624 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001625 case Primitive::kPrimBoolean:
1626 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001627 case Primitive::kPrimByte:
1628 case Primitive::kPrimShort:
1629 case Primitive::kPrimInt:
1630 case Primitive::kPrimChar:
1631 // Processing a Dex `int-to-double' instruction.
1632 locations->SetInAt(0, Location::RequiresRegister());
1633 locations->SetOut(Location::RequiresFpuRegister());
1634 break;
1635
1636 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001637 // Processing a Dex `long-to-double' instruction.
1638 locations->SetInAt(0, Location::RequiresRegister());
1639 locations->SetOut(Location::RequiresFpuRegister());
1640 locations->AddTemp(Location::RequiresRegister());
1641 locations->AddTemp(Location::RequiresRegister());
1642 locations->AddTemp(Location::RequiresFpuRegister());
1643 break;
1644
Roland Levillaincff13742014-11-17 14:32:17 +00001645 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001646 // Processing a Dex `float-to-double' instruction.
1647 locations->SetInAt(0, Location::RequiresFpuRegister());
1648 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001649 break;
1650
1651 default:
1652 LOG(FATAL) << "Unexpected type conversion from " << input_type
1653 << " to " << result_type;
1654 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001655 break;
1656
1657 default:
1658 LOG(FATAL) << "Unexpected type conversion from " << input_type
1659 << " to " << result_type;
1660 }
1661}
1662
1663void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1664 LocationSummary* locations = conversion->GetLocations();
1665 Location out = locations->Out();
1666 Location in = locations->InAt(0);
1667 Primitive::Type result_type = conversion->GetResultType();
1668 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001669 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001670 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001671 case Primitive::kPrimByte:
1672 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001673 case Primitive::kPrimBoolean:
1674 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001675 case Primitive::kPrimShort:
1676 case Primitive::kPrimInt:
1677 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001678 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001679 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001680 break;
1681
1682 default:
1683 LOG(FATAL) << "Unexpected type conversion from " << input_type
1684 << " to " << result_type;
1685 }
1686 break;
1687
Roland Levillain01a8d712014-11-14 16:27:39 +00001688 case Primitive::kPrimShort:
1689 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001690 case Primitive::kPrimBoolean:
1691 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001692 case Primitive::kPrimByte:
1693 case Primitive::kPrimInt:
1694 case Primitive::kPrimChar:
1695 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001696 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001697 break;
1698
1699 default:
1700 LOG(FATAL) << "Unexpected type conversion from " << input_type
1701 << " to " << result_type;
1702 }
1703 break;
1704
Roland Levillain946e1432014-11-11 17:35:19 +00001705 case Primitive::kPrimInt:
1706 switch (input_type) {
1707 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001708 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001709 DCHECK(out.IsRegister());
1710 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001711 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001712 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001713 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001714 } else {
1715 DCHECK(in.IsConstant());
1716 DCHECK(in.GetConstant()->IsLongConstant());
1717 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001718 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001719 }
1720 break;
1721
Roland Levillain3f8f9362014-12-02 17:45:01 +00001722 case Primitive::kPrimFloat: {
1723 // Processing a Dex `float-to-int' instruction.
1724 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1725 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1726 __ vcvtis(temp, temp);
1727 __ vmovrs(out.AsRegister<Register>(), temp);
1728 break;
1729 }
1730
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001731 case Primitive::kPrimDouble: {
1732 // Processing a Dex `double-to-int' instruction.
1733 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1734 DRegister temp_d = FromLowSToD(temp_s);
1735 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1736 __ vcvtid(temp_s, temp_d);
1737 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001738 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001739 }
Roland Levillain946e1432014-11-11 17:35:19 +00001740
1741 default:
1742 LOG(FATAL) << "Unexpected type conversion from " << input_type
1743 << " to " << result_type;
1744 }
1745 break;
1746
Roland Levillaindff1f282014-11-05 14:15:05 +00001747 case Primitive::kPrimLong:
1748 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001749 case Primitive::kPrimBoolean:
1750 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001751 case Primitive::kPrimByte:
1752 case Primitive::kPrimShort:
1753 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001754 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001755 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001756 DCHECK(out.IsRegisterPair());
1757 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001758 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001759 // Sign extension.
1760 __ Asr(out.AsRegisterPairHigh<Register>(),
1761 out.AsRegisterPairLow<Register>(),
1762 31);
1763 break;
1764
1765 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001766 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001767 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1768 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001769 conversion->GetDexPc(),
1770 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001771 break;
1772
Roland Levillaindff1f282014-11-05 14:15:05 +00001773 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001774 // Processing a Dex `double-to-long' instruction.
1775 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1776 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001777 conversion->GetDexPc(),
1778 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001779 break;
1780
1781 default:
1782 LOG(FATAL) << "Unexpected type conversion from " << input_type
1783 << " to " << result_type;
1784 }
1785 break;
1786
Roland Levillain981e4542014-11-14 11:47:14 +00001787 case Primitive::kPrimChar:
1788 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001789 case Primitive::kPrimBoolean:
1790 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001791 case Primitive::kPrimByte:
1792 case Primitive::kPrimShort:
1793 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001794 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001795 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001796 break;
1797
1798 default:
1799 LOG(FATAL) << "Unexpected type conversion from " << input_type
1800 << " to " << result_type;
1801 }
1802 break;
1803
Roland Levillaindff1f282014-11-05 14:15:05 +00001804 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001805 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001806 case Primitive::kPrimBoolean:
1807 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001808 case Primitive::kPrimByte:
1809 case Primitive::kPrimShort:
1810 case Primitive::kPrimInt:
1811 case Primitive::kPrimChar: {
1812 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001813 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1814 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001815 break;
1816 }
1817
Roland Levillain6d0e4832014-11-27 18:31:21 +00001818 case Primitive::kPrimLong: {
1819 // Processing a Dex `long-to-float' instruction.
1820 Register low = in.AsRegisterPairLow<Register>();
1821 Register high = in.AsRegisterPairHigh<Register>();
1822 SRegister output = out.AsFpuRegister<SRegister>();
1823 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1824 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1825 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1826 DRegister temp1_d = FromLowSToD(temp1_s);
1827 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1828 DRegister temp2_d = FromLowSToD(temp2_s);
1829
1830 // Operations use doubles for precision reasons (each 32-bit
1831 // half of a long fits in the 53-bit mantissa of a double,
1832 // but not in the 24-bit mantissa of a float). This is
1833 // especially important for the low bits. The result is
1834 // eventually converted to float.
1835
1836 // temp1_d = int-to-double(high)
1837 __ vmovsr(temp1_s, high);
1838 __ vcvtdi(temp1_d, temp1_s);
1839 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1840 // as an immediate value into `temp2_d` does not work, as
1841 // this instruction only transfers 8 significant bits of its
1842 // immediate operand. Instead, use two 32-bit core
1843 // registers to load `k2Pow32EncodingForDouble` into
1844 // `temp2_d`.
1845 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1846 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1847 __ vmovdrr(temp2_d, constant_low, constant_high);
1848 // temp1_d = temp1_d * 2^32
1849 __ vmuld(temp1_d, temp1_d, temp2_d);
1850 // temp2_d = unsigned-to-double(low)
1851 __ vmovsr(temp2_s, low);
1852 __ vcvtdu(temp2_d, temp2_s);
1853 // temp1_d = temp1_d + temp2_d
1854 __ vaddd(temp1_d, temp1_d, temp2_d);
1855 // output = double-to-float(temp1_d);
1856 __ vcvtsd(output, temp1_d);
1857 break;
1858 }
1859
Roland Levillaincff13742014-11-17 14:32:17 +00001860 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001861 // Processing a Dex `double-to-float' instruction.
1862 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1863 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001864 break;
1865
1866 default:
1867 LOG(FATAL) << "Unexpected type conversion from " << input_type
1868 << " to " << result_type;
1869 };
1870 break;
1871
Roland Levillaindff1f282014-11-05 14:15:05 +00001872 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001873 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001874 case Primitive::kPrimBoolean:
1875 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001876 case Primitive::kPrimByte:
1877 case Primitive::kPrimShort:
1878 case Primitive::kPrimInt:
1879 case Primitive::kPrimChar: {
1880 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001881 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001882 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1883 out.AsFpuRegisterPairLow<SRegister>());
1884 break;
1885 }
1886
Roland Levillain647b9ed2014-11-27 12:06:00 +00001887 case Primitive::kPrimLong: {
1888 // Processing a Dex `long-to-double' instruction.
1889 Register low = in.AsRegisterPairLow<Register>();
1890 Register high = in.AsRegisterPairHigh<Register>();
1891 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1892 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001893 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1894 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001895 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1896 DRegister temp_d = FromLowSToD(temp_s);
1897
Roland Levillain647b9ed2014-11-27 12:06:00 +00001898 // out_d = int-to-double(high)
1899 __ vmovsr(out_s, high);
1900 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001901 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1902 // as an immediate value into `temp_d` does not work, as
1903 // this instruction only transfers 8 significant bits of its
1904 // immediate operand. Instead, use two 32-bit core
1905 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1906 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1907 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001908 __ vmovdrr(temp_d, constant_low, constant_high);
1909 // out_d = out_d * 2^32
1910 __ vmuld(out_d, out_d, temp_d);
1911 // temp_d = unsigned-to-double(low)
1912 __ vmovsr(temp_s, low);
1913 __ vcvtdu(temp_d, temp_s);
1914 // out_d = out_d + temp_d
1915 __ vaddd(out_d, out_d, temp_d);
1916 break;
1917 }
1918
Roland Levillaincff13742014-11-17 14:32:17 +00001919 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001920 // Processing a Dex `float-to-double' instruction.
1921 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1922 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001923 break;
1924
1925 default:
1926 LOG(FATAL) << "Unexpected type conversion from " << input_type
1927 << " to " << result_type;
1928 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001929 break;
1930
1931 default:
1932 LOG(FATAL) << "Unexpected type conversion from " << input_type
1933 << " to " << result_type;
1934 }
1935}
1936
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001937void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001938 LocationSummary* locations =
1939 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001940 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001941 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001942 locations->SetInAt(0, Location::RequiresRegister());
1943 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001944 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1945 break;
1946 }
1947
1948 case Primitive::kPrimLong: {
1949 locations->SetInAt(0, Location::RequiresRegister());
1950 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001951 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001952 break;
1953 }
1954
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001955 case Primitive::kPrimFloat:
1956 case Primitive::kPrimDouble: {
1957 locations->SetInAt(0, Location::RequiresFpuRegister());
1958 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001959 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001960 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001961 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001962
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 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001966}
1967
1968void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1969 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001970 Location out = locations->Out();
1971 Location first = locations->InAt(0);
1972 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001973 switch (add->GetResultType()) {
1974 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001975 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001976 __ add(out.AsRegister<Register>(),
1977 first.AsRegister<Register>(),
1978 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001979 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001980 __ AddConstant(out.AsRegister<Register>(),
1981 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001982 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001983 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001984 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001985
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001986 case Primitive::kPrimLong: {
1987 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001988 __ adds(out.AsRegisterPairLow<Register>(),
1989 first.AsRegisterPairLow<Register>(),
1990 ShifterOperand(second.AsRegisterPairLow<Register>()));
1991 __ adc(out.AsRegisterPairHigh<Register>(),
1992 first.AsRegisterPairHigh<Register>(),
1993 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001994 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001995 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001996
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001997 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001998 __ vadds(out.AsFpuRegister<SRegister>(),
1999 first.AsFpuRegister<SRegister>(),
2000 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002001 break;
2002
2003 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002004 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2005 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2006 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002007 break;
2008
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002009 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002010 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002011 }
2012}
2013
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002014void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002015 LocationSummary* locations =
2016 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002017 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002018 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002019 locations->SetInAt(0, Location::RequiresRegister());
2020 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002021 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2022 break;
2023 }
2024
2025 case Primitive::kPrimLong: {
2026 locations->SetInAt(0, Location::RequiresRegister());
2027 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002028 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002029 break;
2030 }
Calin Juravle11351682014-10-23 15:38:15 +01002031 case Primitive::kPrimFloat:
2032 case Primitive::kPrimDouble: {
2033 locations->SetInAt(0, Location::RequiresFpuRegister());
2034 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002035 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002036 break;
Calin Juravle11351682014-10-23 15:38:15 +01002037 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002038 default:
Calin Juravle11351682014-10-23 15:38:15 +01002039 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002040 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002041}
2042
2043void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2044 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002045 Location out = locations->Out();
2046 Location first = locations->InAt(0);
2047 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002048 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002049 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002050 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002051 __ sub(out.AsRegister<Register>(),
2052 first.AsRegister<Register>(),
2053 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002054 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002055 __ AddConstant(out.AsRegister<Register>(),
2056 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002057 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002058 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002059 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002060 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002061
Calin Juravle11351682014-10-23 15:38:15 +01002062 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002063 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002064 __ subs(out.AsRegisterPairLow<Register>(),
2065 first.AsRegisterPairLow<Register>(),
2066 ShifterOperand(second.AsRegisterPairLow<Register>()));
2067 __ sbc(out.AsRegisterPairHigh<Register>(),
2068 first.AsRegisterPairHigh<Register>(),
2069 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002070 break;
Calin Juravle11351682014-10-23 15:38:15 +01002071 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002072
Calin Juravle11351682014-10-23 15:38:15 +01002073 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002074 __ vsubs(out.AsFpuRegister<SRegister>(),
2075 first.AsFpuRegister<SRegister>(),
2076 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002077 break;
Calin Juravle11351682014-10-23 15:38:15 +01002078 }
2079
2080 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002081 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2082 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2083 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002084 break;
2085 }
2086
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002087
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002088 default:
Calin Juravle11351682014-10-23 15:38:15 +01002089 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002090 }
2091}
2092
Calin Juravle34bacdf2014-10-07 20:23:36 +01002093void LocationsBuilderARM::VisitMul(HMul* mul) {
2094 LocationSummary* locations =
2095 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2096 switch (mul->GetResultType()) {
2097 case Primitive::kPrimInt:
2098 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002099 locations->SetInAt(0, Location::RequiresRegister());
2100 locations->SetInAt(1, Location::RequiresRegister());
2101 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002102 break;
2103 }
2104
Calin Juravleb5bfa962014-10-21 18:02:24 +01002105 case Primitive::kPrimFloat:
2106 case Primitive::kPrimDouble: {
2107 locations->SetInAt(0, Location::RequiresFpuRegister());
2108 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002109 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002110 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002111 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002112
2113 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002114 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002115 }
2116}
2117
2118void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2119 LocationSummary* locations = mul->GetLocations();
2120 Location out = locations->Out();
2121 Location first = locations->InAt(0);
2122 Location second = locations->InAt(1);
2123 switch (mul->GetResultType()) {
2124 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002125 __ mul(out.AsRegister<Register>(),
2126 first.AsRegister<Register>(),
2127 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002128 break;
2129 }
2130 case Primitive::kPrimLong: {
2131 Register out_hi = out.AsRegisterPairHigh<Register>();
2132 Register out_lo = out.AsRegisterPairLow<Register>();
2133 Register in1_hi = first.AsRegisterPairHigh<Register>();
2134 Register in1_lo = first.AsRegisterPairLow<Register>();
2135 Register in2_hi = second.AsRegisterPairHigh<Register>();
2136 Register in2_lo = second.AsRegisterPairLow<Register>();
2137
2138 // Extra checks to protect caused by the existence of R1_R2.
2139 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2140 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2141 DCHECK_NE(out_hi, in1_lo);
2142 DCHECK_NE(out_hi, in2_lo);
2143
2144 // input: in1 - 64 bits, in2 - 64 bits
2145 // output: out
2146 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2147 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2148 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2149
2150 // IP <- in1.lo * in2.hi
2151 __ mul(IP, in1_lo, in2_hi);
2152 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2153 __ mla(out_hi, in1_hi, in2_lo, IP);
2154 // out.lo <- (in1.lo * in2.lo)[31:0];
2155 __ umull(out_lo, IP, in1_lo, in2_lo);
2156 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2157 __ add(out_hi, out_hi, ShifterOperand(IP));
2158 break;
2159 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002160
2161 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002162 __ vmuls(out.AsFpuRegister<SRegister>(),
2163 first.AsFpuRegister<SRegister>(),
2164 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002165 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002166 }
2167
2168 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002169 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2170 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2171 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002172 break;
2173 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002174
2175 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002176 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002177 }
2178}
2179
Zheng Xuc6667102015-05-15 16:08:45 +08002180void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2181 DCHECK(instruction->IsDiv() || instruction->IsRem());
2182 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2183
2184 LocationSummary* locations = instruction->GetLocations();
2185 Location second = locations->InAt(1);
2186 DCHECK(second.IsConstant());
2187
2188 Register out = locations->Out().AsRegister<Register>();
2189 Register dividend = locations->InAt(0).AsRegister<Register>();
2190 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2191 DCHECK(imm == 1 || imm == -1);
2192
2193 if (instruction->IsRem()) {
2194 __ LoadImmediate(out, 0);
2195 } else {
2196 if (imm == 1) {
2197 __ Mov(out, dividend);
2198 } else {
2199 __ rsb(out, dividend, ShifterOperand(0));
2200 }
2201 }
2202}
2203
2204void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2205 DCHECK(instruction->IsDiv() || instruction->IsRem());
2206 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2207
2208 LocationSummary* locations = instruction->GetLocations();
2209 Location second = locations->InAt(1);
2210 DCHECK(second.IsConstant());
2211
2212 Register out = locations->Out().AsRegister<Register>();
2213 Register dividend = locations->InAt(0).AsRegister<Register>();
2214 Register temp = locations->GetTemp(0).AsRegister<Register>();
2215 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002216 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002217 DCHECK(IsPowerOfTwo(abs_imm));
2218 int ctz_imm = CTZ(abs_imm);
2219
2220 if (ctz_imm == 1) {
2221 __ Lsr(temp, dividend, 32 - ctz_imm);
2222 } else {
2223 __ Asr(temp, dividend, 31);
2224 __ Lsr(temp, temp, 32 - ctz_imm);
2225 }
2226 __ add(out, temp, ShifterOperand(dividend));
2227
2228 if (instruction->IsDiv()) {
2229 __ Asr(out, out, ctz_imm);
2230 if (imm < 0) {
2231 __ rsb(out, out, ShifterOperand(0));
2232 }
2233 } else {
2234 __ ubfx(out, out, 0, ctz_imm);
2235 __ sub(out, out, ShifterOperand(temp));
2236 }
2237}
2238
2239void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2240 DCHECK(instruction->IsDiv() || instruction->IsRem());
2241 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2242
2243 LocationSummary* locations = instruction->GetLocations();
2244 Location second = locations->InAt(1);
2245 DCHECK(second.IsConstant());
2246
2247 Register out = locations->Out().AsRegister<Register>();
2248 Register dividend = locations->InAt(0).AsRegister<Register>();
2249 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2250 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2251 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2252
2253 int64_t magic;
2254 int shift;
2255 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2256
2257 __ LoadImmediate(temp1, magic);
2258 __ smull(temp2, temp1, dividend, temp1);
2259
2260 if (imm > 0 && magic < 0) {
2261 __ add(temp1, temp1, ShifterOperand(dividend));
2262 } else if (imm < 0 && magic > 0) {
2263 __ sub(temp1, temp1, ShifterOperand(dividend));
2264 }
2265
2266 if (shift != 0) {
2267 __ Asr(temp1, temp1, shift);
2268 }
2269
2270 if (instruction->IsDiv()) {
2271 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2272 } else {
2273 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2274 // TODO: Strength reduction for mls.
2275 __ LoadImmediate(temp2, imm);
2276 __ mls(out, temp1, temp2, dividend);
2277 }
2278}
2279
2280void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2281 DCHECK(instruction->IsDiv() || instruction->IsRem());
2282 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2283
2284 LocationSummary* locations = instruction->GetLocations();
2285 Location second = locations->InAt(1);
2286 DCHECK(second.IsConstant());
2287
2288 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2289 if (imm == 0) {
2290 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2291 } else if (imm == 1 || imm == -1) {
2292 DivRemOneOrMinusOne(instruction);
2293 } else if (IsPowerOfTwo(std::abs(imm))) {
2294 DivRemByPowerOfTwo(instruction);
2295 } else {
2296 DCHECK(imm <= -2 || imm >= 2);
2297 GenerateDivRemWithAnyConstant(instruction);
2298 }
2299}
2300
Calin Juravle7c4954d2014-10-28 16:57:40 +00002301void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002302 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2303 if (div->GetResultType() == Primitive::kPrimLong) {
2304 // pLdiv runtime call.
2305 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002306 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2307 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002308 } else if (div->GetResultType() == Primitive::kPrimInt &&
2309 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2310 // pIdivmod runtime call.
2311 call_kind = LocationSummary::kCall;
2312 }
2313
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002314 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2315
Calin Juravle7c4954d2014-10-28 16:57:40 +00002316 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002317 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002318 if (div->InputAt(1)->IsConstant()) {
2319 locations->SetInAt(0, Location::RequiresRegister());
2320 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2321 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2322 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2323 if (abs_imm <= 1) {
2324 // No temp register required.
2325 } else {
2326 locations->AddTemp(Location::RequiresRegister());
2327 if (!IsPowerOfTwo(abs_imm)) {
2328 locations->AddTemp(Location::RequiresRegister());
2329 }
2330 }
2331 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002332 locations->SetInAt(0, Location::RequiresRegister());
2333 locations->SetInAt(1, Location::RequiresRegister());
2334 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2335 } else {
2336 InvokeRuntimeCallingConvention calling_convention;
2337 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2338 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2339 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2340 // we only need the former.
2341 locations->SetOut(Location::RegisterLocation(R0));
2342 }
Calin Juravled0d48522014-11-04 16:40:20 +00002343 break;
2344 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002345 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002346 InvokeRuntimeCallingConvention calling_convention;
2347 locations->SetInAt(0, Location::RegisterPairLocation(
2348 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2349 locations->SetInAt(1, Location::RegisterPairLocation(
2350 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002351 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002352 break;
2353 }
2354 case Primitive::kPrimFloat:
2355 case Primitive::kPrimDouble: {
2356 locations->SetInAt(0, Location::RequiresFpuRegister());
2357 locations->SetInAt(1, Location::RequiresFpuRegister());
2358 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2359 break;
2360 }
2361
2362 default:
2363 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2364 }
2365}
2366
2367void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2368 LocationSummary* locations = div->GetLocations();
2369 Location out = locations->Out();
2370 Location first = locations->InAt(0);
2371 Location second = locations->InAt(1);
2372
2373 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002374 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002375 if (second.IsConstant()) {
2376 GenerateDivRemConstantIntegral(div);
2377 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002378 __ sdiv(out.AsRegister<Register>(),
2379 first.AsRegister<Register>(),
2380 second.AsRegister<Register>());
2381 } else {
2382 InvokeRuntimeCallingConvention calling_convention;
2383 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2384 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2385 DCHECK_EQ(R0, out.AsRegister<Register>());
2386
2387 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2388 }
Calin Juravled0d48522014-11-04 16:40:20 +00002389 break;
2390 }
2391
Calin Juravle7c4954d2014-10-28 16:57:40 +00002392 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002393 InvokeRuntimeCallingConvention calling_convention;
2394 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2395 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2396 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2397 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2398 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002399 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002400
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002401 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002402 break;
2403 }
2404
2405 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002406 __ vdivs(out.AsFpuRegister<SRegister>(),
2407 first.AsFpuRegister<SRegister>(),
2408 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002409 break;
2410 }
2411
2412 case Primitive::kPrimDouble: {
2413 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2414 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2415 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2416 break;
2417 }
2418
2419 default:
2420 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2421 }
2422}
2423
Calin Juravlebacfec32014-11-14 15:54:36 +00002424void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002425 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002426
2427 // Most remainders are implemented in the runtime.
2428 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002429 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2430 // sdiv will be replaced by other instruction sequence.
2431 call_kind = LocationSummary::kNoCall;
2432 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2433 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002434 // Have hardware divide instruction for int, do it with three instructions.
2435 call_kind = LocationSummary::kNoCall;
2436 }
2437
Calin Juravlebacfec32014-11-14 15:54:36 +00002438 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2439
Calin Juravled2ec87d2014-12-08 14:24:46 +00002440 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002441 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002442 if (rem->InputAt(1)->IsConstant()) {
2443 locations->SetInAt(0, Location::RequiresRegister());
2444 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2445 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2446 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2447 if (abs_imm <= 1) {
2448 // No temp register required.
2449 } else {
2450 locations->AddTemp(Location::RequiresRegister());
2451 if (!IsPowerOfTwo(abs_imm)) {
2452 locations->AddTemp(Location::RequiresRegister());
2453 }
2454 }
2455 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002456 locations->SetInAt(0, Location::RequiresRegister());
2457 locations->SetInAt(1, Location::RequiresRegister());
2458 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2459 locations->AddTemp(Location::RequiresRegister());
2460 } else {
2461 InvokeRuntimeCallingConvention calling_convention;
2462 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2463 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2464 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2465 // we only need the latter.
2466 locations->SetOut(Location::RegisterLocation(R1));
2467 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002468 break;
2469 }
2470 case Primitive::kPrimLong: {
2471 InvokeRuntimeCallingConvention calling_convention;
2472 locations->SetInAt(0, Location::RegisterPairLocation(
2473 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2474 locations->SetInAt(1, Location::RegisterPairLocation(
2475 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2476 // The runtime helper puts the output in R2,R3.
2477 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2478 break;
2479 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002480 case Primitive::kPrimFloat: {
2481 InvokeRuntimeCallingConvention calling_convention;
2482 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2483 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2484 locations->SetOut(Location::FpuRegisterLocation(S0));
2485 break;
2486 }
2487
Calin Juravlebacfec32014-11-14 15:54:36 +00002488 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002489 InvokeRuntimeCallingConvention calling_convention;
2490 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2491 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2492 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2493 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2494 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002495 break;
2496 }
2497
2498 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002499 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002500 }
2501}
2502
2503void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2504 LocationSummary* locations = rem->GetLocations();
2505 Location out = locations->Out();
2506 Location first = locations->InAt(0);
2507 Location second = locations->InAt(1);
2508
Calin Juravled2ec87d2014-12-08 14:24:46 +00002509 Primitive::Type type = rem->GetResultType();
2510 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002511 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002512 if (second.IsConstant()) {
2513 GenerateDivRemConstantIntegral(rem);
2514 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002515 Register reg1 = first.AsRegister<Register>();
2516 Register reg2 = second.AsRegister<Register>();
2517 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002518
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002519 // temp = reg1 / reg2 (integer division)
2520 // temp = temp * reg2
2521 // dest = reg1 - temp
2522 __ sdiv(temp, reg1, reg2);
2523 __ mul(temp, temp, reg2);
2524 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2525 } else {
2526 InvokeRuntimeCallingConvention calling_convention;
2527 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2528 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2529 DCHECK_EQ(R1, out.AsRegister<Register>());
2530
2531 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2532 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002533 break;
2534 }
2535
2536 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002537 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002538 break;
2539 }
2540
Calin Juravled2ec87d2014-12-08 14:24:46 +00002541 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002542 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002543 break;
2544 }
2545
Calin Juravlebacfec32014-11-14 15:54:36 +00002546 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002547 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002548 break;
2549 }
2550
2551 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002552 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002553 }
2554}
2555
Calin Juravled0d48522014-11-04 16:40:20 +00002556void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2557 LocationSummary* locations =
2558 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002559 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002560 if (instruction->HasUses()) {
2561 locations->SetOut(Location::SameAsFirstInput());
2562 }
2563}
2564
2565void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2566 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2567 codegen_->AddSlowPath(slow_path);
2568
2569 LocationSummary* locations = instruction->GetLocations();
2570 Location value = locations->InAt(0);
2571
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002572 switch (instruction->GetType()) {
2573 case Primitive::kPrimInt: {
2574 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002575 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002576 __ b(slow_path->GetEntryLabel(), EQ);
2577 } else {
2578 DCHECK(value.IsConstant()) << value;
2579 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2580 __ b(slow_path->GetEntryLabel());
2581 }
2582 }
2583 break;
2584 }
2585 case Primitive::kPrimLong: {
2586 if (value.IsRegisterPair()) {
2587 __ orrs(IP,
2588 value.AsRegisterPairLow<Register>(),
2589 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2590 __ b(slow_path->GetEntryLabel(), EQ);
2591 } else {
2592 DCHECK(value.IsConstant()) << value;
2593 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2594 __ b(slow_path->GetEntryLabel());
2595 }
2596 }
2597 break;
2598 default:
2599 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2600 }
2601 }
Calin Juravled0d48522014-11-04 16:40:20 +00002602}
2603
Calin Juravle9aec02f2014-11-18 23:06:35 +00002604void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2605 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2606
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002607 LocationSummary* locations =
2608 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002609
2610 switch (op->GetResultType()) {
2611 case Primitive::kPrimInt: {
2612 locations->SetInAt(0, Location::RequiresRegister());
2613 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002614 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002615 break;
2616 }
2617 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002618 locations->SetInAt(0, Location::RequiresRegister());
2619 locations->SetInAt(1, Location::RequiresRegister());
2620 locations->AddTemp(Location::RequiresRegister());
2621 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002622 break;
2623 }
2624 default:
2625 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2626 }
2627}
2628
2629void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2630 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2631
2632 LocationSummary* locations = op->GetLocations();
2633 Location out = locations->Out();
2634 Location first = locations->InAt(0);
2635 Location second = locations->InAt(1);
2636
2637 Primitive::Type type = op->GetResultType();
2638 switch (type) {
2639 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002640 Register out_reg = out.AsRegister<Register>();
2641 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002642 // Arm doesn't mask the shift count so we need to do it ourselves.
2643 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002644 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002645 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2646 if (op->IsShl()) {
2647 __ Lsl(out_reg, first_reg, second_reg);
2648 } else if (op->IsShr()) {
2649 __ Asr(out_reg, first_reg, second_reg);
2650 } else {
2651 __ Lsr(out_reg, first_reg, second_reg);
2652 }
2653 } else {
2654 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2655 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2656 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2657 __ Mov(out_reg, first_reg);
2658 } else if (op->IsShl()) {
2659 __ Lsl(out_reg, first_reg, shift_value);
2660 } else if (op->IsShr()) {
2661 __ Asr(out_reg, first_reg, shift_value);
2662 } else {
2663 __ Lsr(out_reg, first_reg, shift_value);
2664 }
2665 }
2666 break;
2667 }
2668 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002669 Register o_h = out.AsRegisterPairHigh<Register>();
2670 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002671
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002672 Register temp = locations->GetTemp(0).AsRegister<Register>();
2673
2674 Register high = first.AsRegisterPairHigh<Register>();
2675 Register low = first.AsRegisterPairLow<Register>();
2676
2677 Register second_reg = second.AsRegister<Register>();
2678
Calin Juravle9aec02f2014-11-18 23:06:35 +00002679 if (op->IsShl()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002680 // Shift the high part
2681 __ and_(second_reg, second_reg, ShifterOperand(63));
2682 __ Lsl(o_h, high, second_reg);
2683 // Shift the low part and `or` what overflew on the high part
2684 __ rsb(temp, second_reg, ShifterOperand(32));
2685 __ Lsr(temp, low, temp);
2686 __ orr(o_h, o_h, ShifterOperand(temp));
2687 // If the shift is > 32 bits, override the high part
2688 __ subs(temp, second_reg, ShifterOperand(32));
2689 __ it(PL);
2690 __ Lsl(o_h, low, temp, false, PL);
2691 // Shift the low part
2692 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002693 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002694 // Shift the low part
2695 __ and_(second_reg, second_reg, ShifterOperand(63));
2696 __ Lsr(o_l, low, second_reg);
2697 // Shift the high part and `or` what underflew on the low part
2698 __ rsb(temp, second_reg, ShifterOperand(32));
2699 __ Lsl(temp, high, temp);
2700 __ orr(o_l, o_l, ShifterOperand(temp));
2701 // If the shift is > 32 bits, override the low part
2702 __ subs(temp, second_reg, ShifterOperand(32));
2703 __ it(PL);
2704 __ Asr(o_l, high, temp, false, PL);
2705 // Shift the high part
2706 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002707 } else {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002708 // same as Shr except we use `Lsr`s and not `Asr`s
2709 __ and_(second_reg, second_reg, ShifterOperand(63));
2710 __ Lsr(o_l, low, second_reg);
2711 __ rsb(temp, second_reg, ShifterOperand(32));
2712 __ Lsl(temp, high, temp);
2713 __ orr(o_l, o_l, ShifterOperand(temp));
2714 __ subs(temp, second_reg, ShifterOperand(32));
2715 __ it(PL);
2716 __ Lsr(o_l, high, temp, false, PL);
2717 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002718 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002719 break;
2720 }
2721 default:
2722 LOG(FATAL) << "Unexpected operation type " << type;
2723 }
2724}
2725
2726void LocationsBuilderARM::VisitShl(HShl* shl) {
2727 HandleShift(shl);
2728}
2729
2730void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2731 HandleShift(shl);
2732}
2733
2734void LocationsBuilderARM::VisitShr(HShr* shr) {
2735 HandleShift(shr);
2736}
2737
2738void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2739 HandleShift(shr);
2740}
2741
2742void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2743 HandleShift(ushr);
2744}
2745
2746void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2747 HandleShift(ushr);
2748}
2749
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002750void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002751 LocationSummary* locations =
2752 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002753 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002754 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2755 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2756 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002757}
2758
2759void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2760 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002761 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002762 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002763 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2764 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002765 instruction->GetDexPc(),
2766 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002767}
2768
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002769void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2770 LocationSummary* locations =
2771 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2772 InvokeRuntimeCallingConvention calling_convention;
2773 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002774 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002775 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002776 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002777}
2778
2779void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2780 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002781 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002782 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002783 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2784 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002785 instruction->GetDexPc(),
2786 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002787}
2788
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002789void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002790 LocationSummary* locations =
2791 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002792 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2793 if (location.IsStackSlot()) {
2794 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2795 } else if (location.IsDoubleStackSlot()) {
2796 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002797 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002798 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002799}
2800
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002801void InstructionCodeGeneratorARM::VisitParameterValue(
2802 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002803 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002804}
2805
2806void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
2807 LocationSummary* locations =
2808 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2809 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2810}
2811
2812void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
2813 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002814}
2815
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002816void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002817 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002818 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002819 locations->SetInAt(0, Location::RequiresRegister());
2820 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002821}
2822
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002823void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2824 LocationSummary* locations = not_->GetLocations();
2825 Location out = locations->Out();
2826 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002827 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002828 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002829 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002830 break;
2831
2832 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002833 __ mvn(out.AsRegisterPairLow<Register>(),
2834 ShifterOperand(in.AsRegisterPairLow<Register>()));
2835 __ mvn(out.AsRegisterPairHigh<Register>(),
2836 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002837 break;
2838
2839 default:
2840 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2841 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002842}
2843
David Brazdil66d126e2015-04-03 16:02:44 +01002844void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
2845 LocationSummary* locations =
2846 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
2847 locations->SetInAt(0, Location::RequiresRegister());
2848 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2849}
2850
2851void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01002852 LocationSummary* locations = bool_not->GetLocations();
2853 Location out = locations->Out();
2854 Location in = locations->InAt(0);
2855 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
2856}
2857
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002858void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002859 LocationSummary* locations =
2860 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002861 switch (compare->InputAt(0)->GetType()) {
2862 case Primitive::kPrimLong: {
2863 locations->SetInAt(0, Location::RequiresRegister());
2864 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002865 // Output overlaps because it is written before doing the low comparison.
2866 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002867 break;
2868 }
2869 case Primitive::kPrimFloat:
2870 case Primitive::kPrimDouble: {
2871 locations->SetInAt(0, Location::RequiresFpuRegister());
2872 locations->SetInAt(1, Location::RequiresFpuRegister());
2873 locations->SetOut(Location::RequiresRegister());
2874 break;
2875 }
2876 default:
2877 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2878 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002879}
2880
2881void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002882 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002883 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002884 Location left = locations->InAt(0);
2885 Location right = locations->InAt(1);
2886
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002887 NearLabel less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00002888 Primitive::Type type = compare->InputAt(0)->GetType();
2889 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002890 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002891 __ cmp(left.AsRegisterPairHigh<Register>(),
2892 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002893 __ b(&less, LT);
2894 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002895 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2896 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002897 __ cmp(left.AsRegisterPairLow<Register>(),
2898 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002899 break;
2900 }
2901 case Primitive::kPrimFloat:
2902 case Primitive::kPrimDouble: {
2903 __ LoadImmediate(out, 0);
2904 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002905 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002906 } else {
2907 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2908 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2909 }
2910 __ vmstat(); // transfer FP status register to ARM APSR.
2911 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002912 break;
2913 }
2914 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002915 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002916 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002917 __ b(&done, EQ);
2918 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2919
2920 __ Bind(&greater);
2921 __ LoadImmediate(out, 1);
2922 __ b(&done);
2923
2924 __ Bind(&less);
2925 __ LoadImmediate(out, -1);
2926
2927 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002928}
2929
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002930void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002931 LocationSummary* locations =
2932 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002933 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2934 locations->SetInAt(i, Location::Any());
2935 }
2936 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002937}
2938
2939void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002940 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002941 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002942}
2943
Calin Juravle52c48962014-12-16 17:02:57 +00002944void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2945 // TODO (ported from quick): revisit Arm barrier kinds
2946 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2947 switch (kind) {
2948 case MemBarrierKind::kAnyStore:
2949 case MemBarrierKind::kLoadAny:
2950 case MemBarrierKind::kAnyAny: {
2951 flavour = DmbOptions::ISH;
2952 break;
2953 }
2954 case MemBarrierKind::kStoreStore: {
2955 flavour = DmbOptions::ISHST;
2956 break;
2957 }
2958 default:
2959 LOG(FATAL) << "Unexpected memory barrier " << kind;
2960 }
2961 __ dmb(flavour);
2962}
2963
2964void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2965 uint32_t offset,
2966 Register out_lo,
2967 Register out_hi) {
2968 if (offset != 0) {
2969 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002970 __ add(IP, addr, ShifterOperand(out_lo));
2971 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002972 }
2973 __ ldrexd(out_lo, out_hi, addr);
2974}
2975
2976void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2977 uint32_t offset,
2978 Register value_lo,
2979 Register value_hi,
2980 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002981 Register temp2,
2982 HInstruction* instruction) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002983 NearLabel fail;
Calin Juravle52c48962014-12-16 17:02:57 +00002984 if (offset != 0) {
2985 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002986 __ add(IP, addr, ShifterOperand(temp1));
2987 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002988 }
2989 __ Bind(&fail);
2990 // We need a load followed by store. (The address used in a STREX instruction must
2991 // be the same as the address in the most recently executed LDREX instruction.)
2992 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002993 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002994 __ strexd(temp1, value_lo, value_hi, addr);
2995 __ cmp(temp1, ShifterOperand(0));
2996 __ b(&fail, NE);
2997}
2998
2999void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3000 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3001
Nicolas Geoffray39468442014-09-02 15:17:15 +01003002 LocationSummary* locations =
3003 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003004 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003005
Calin Juravle52c48962014-12-16 17:02:57 +00003006 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003007 if (Primitive::IsFloatingPointType(field_type)) {
3008 locations->SetInAt(1, Location::RequiresFpuRegister());
3009 } else {
3010 locations->SetInAt(1, Location::RequiresRegister());
3011 }
3012
Calin Juravle52c48962014-12-16 17:02:57 +00003013 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003014 bool generate_volatile = field_info.IsVolatile()
3015 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003016 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003017 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003018 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
3019 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003020 locations->AddTemp(Location::RequiresRegister());
3021 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003022 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00003023 // Arm encoding have some additional constraints for ldrexd/strexd:
3024 // - registers need to be consecutive
3025 // - the first register should be even but not R14.
3026 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3027 // enable Arm encoding.
3028 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3029
3030 locations->AddTemp(Location::RequiresRegister());
3031 locations->AddTemp(Location::RequiresRegister());
3032 if (field_type == Primitive::kPrimDouble) {
3033 // For doubles we need two more registers to copy the value.
3034 locations->AddTemp(Location::RegisterLocation(R2));
3035 locations->AddTemp(Location::RegisterLocation(R3));
3036 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003037 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003038}
3039
Calin Juravle52c48962014-12-16 17:02:57 +00003040void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003041 const FieldInfo& field_info,
3042 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003043 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3044
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003045 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003046 Register base = locations->InAt(0).AsRegister<Register>();
3047 Location value = locations->InAt(1);
3048
3049 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003050 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003051 Primitive::Type field_type = field_info.GetFieldType();
3052 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3053
3054 if (is_volatile) {
3055 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3056 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003057
3058 switch (field_type) {
3059 case Primitive::kPrimBoolean:
3060 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003061 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003062 break;
3063 }
3064
3065 case Primitive::kPrimShort:
3066 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003067 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003068 break;
3069 }
3070
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003071 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003072 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00003073 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003074 break;
3075 }
3076
3077 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003078 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003079 GenerateWideAtomicStore(base, offset,
3080 value.AsRegisterPairLow<Register>(),
3081 value.AsRegisterPairHigh<Register>(),
3082 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003083 locations->GetTemp(1).AsRegister<Register>(),
3084 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003085 } else {
3086 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003087 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003088 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003089 break;
3090 }
3091
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003092 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003093 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003094 break;
3095 }
3096
3097 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003098 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003099 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003100 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3101 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3102
3103 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3104
3105 GenerateWideAtomicStore(base, offset,
3106 value_reg_lo,
3107 value_reg_hi,
3108 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003109 locations->GetTemp(3).AsRegister<Register>(),
3110 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003111 } else {
3112 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003113 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003114 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003115 break;
3116 }
3117
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003118 case Primitive::kPrimVoid:
3119 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003120 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003121 }
Calin Juravle52c48962014-12-16 17:02:57 +00003122
Calin Juravle77520bc2015-01-12 18:45:46 +00003123 // Longs and doubles are handled in the switch.
3124 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3125 codegen_->MaybeRecordImplicitNullCheck(instruction);
3126 }
3127
3128 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3129 Register temp = locations->GetTemp(0).AsRegister<Register>();
3130 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003131 codegen_->MarkGCCard(
3132 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003133 }
3134
Calin Juravle52c48962014-12-16 17:02:57 +00003135 if (is_volatile) {
3136 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3137 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003138}
3139
Calin Juravle52c48962014-12-16 17:02:57 +00003140void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3141 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003142 LocationSummary* locations =
3143 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003144 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003145
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003146 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003147 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003148 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003149 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003150
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003151 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3152 locations->SetOut(Location::RequiresFpuRegister());
3153 } else {
3154 locations->SetOut(Location::RequiresRegister(),
3155 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3156 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003157 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003158 // Arm encoding have some additional constraints for ldrexd/strexd:
3159 // - registers need to be consecutive
3160 // - the first register should be even but not R14.
3161 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3162 // enable Arm encoding.
3163 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3164 locations->AddTemp(Location::RequiresRegister());
3165 locations->AddTemp(Location::RequiresRegister());
3166 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003167}
3168
Calin Juravle52c48962014-12-16 17:02:57 +00003169void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3170 const FieldInfo& field_info) {
3171 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003172
Calin Juravle52c48962014-12-16 17:02:57 +00003173 LocationSummary* locations = instruction->GetLocations();
3174 Register base = locations->InAt(0).AsRegister<Register>();
3175 Location out = locations->Out();
3176 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003177 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003178 Primitive::Type field_type = field_info.GetFieldType();
3179 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3180
3181 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003182 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003183 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003184 break;
3185 }
3186
3187 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003188 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003189 break;
3190 }
3191
3192 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003193 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003194 break;
3195 }
3196
3197 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003198 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003199 break;
3200 }
3201
3202 case Primitive::kPrimInt:
3203 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003204 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003205 break;
3206 }
3207
3208 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003209 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003210 GenerateWideAtomicLoad(base, offset,
3211 out.AsRegisterPairLow<Register>(),
3212 out.AsRegisterPairHigh<Register>());
3213 } else {
3214 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3215 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003216 break;
3217 }
3218
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003219 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003220 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003221 break;
3222 }
3223
3224 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003225 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003226 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003227 Register lo = locations->GetTemp(0).AsRegister<Register>();
3228 Register hi = locations->GetTemp(1).AsRegister<Register>();
3229 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003230 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003231 __ vmovdrr(out_reg, lo, hi);
3232 } else {
3233 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003234 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003235 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003236 break;
3237 }
3238
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003239 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003240 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003241 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003242 }
Calin Juravle52c48962014-12-16 17:02:57 +00003243
Calin Juravle77520bc2015-01-12 18:45:46 +00003244 // Doubles are handled in the switch.
3245 if (field_type != Primitive::kPrimDouble) {
3246 codegen_->MaybeRecordImplicitNullCheck(instruction);
3247 }
3248
Calin Juravle52c48962014-12-16 17:02:57 +00003249 if (is_volatile) {
3250 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3251 }
3252}
3253
3254void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3255 HandleFieldSet(instruction, instruction->GetFieldInfo());
3256}
3257
3258void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003259 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003260}
3261
3262void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3263 HandleFieldGet(instruction, instruction->GetFieldInfo());
3264}
3265
3266void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3267 HandleFieldGet(instruction, instruction->GetFieldInfo());
3268}
3269
3270void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3271 HandleFieldGet(instruction, instruction->GetFieldInfo());
3272}
3273
3274void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3275 HandleFieldGet(instruction, instruction->GetFieldInfo());
3276}
3277
3278void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3279 HandleFieldSet(instruction, instruction->GetFieldInfo());
3280}
3281
3282void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003283 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003284}
3285
3286void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003287 LocationSummary* locations =
3288 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003289 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003290 if (instruction->HasUses()) {
3291 locations->SetOut(Location::SameAsFirstInput());
3292 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003293}
3294
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003295void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003296 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3297 return;
3298 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003299 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003300
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003301 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3302 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3303}
3304
3305void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003306 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003307 codegen_->AddSlowPath(slow_path);
3308
3309 LocationSummary* locations = instruction->GetLocations();
3310 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003311
Calin Juravle77520bc2015-01-12 18:45:46 +00003312 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
3313 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003314}
3315
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003316void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3317 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3318 GenerateImplicitNullCheck(instruction);
3319 } else {
3320 GenerateExplicitNullCheck(instruction);
3321 }
3322}
3323
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003324void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003325 LocationSummary* locations =
3326 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003327 locations->SetInAt(0, Location::RequiresRegister());
3328 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003329 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3330 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3331 } else {
3332 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3333 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003334}
3335
3336void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3337 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003338 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003339 Location index = locations->InAt(1);
3340
3341 switch (instruction->GetType()) {
3342 case Primitive::kPrimBoolean: {
3343 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003344 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003345 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003346 size_t offset =
3347 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003348 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3349 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003350 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003351 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3352 }
3353 break;
3354 }
3355
3356 case Primitive::kPrimByte: {
3357 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003358 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003359 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003360 size_t offset =
3361 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003362 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3363 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003364 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003365 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3366 }
3367 break;
3368 }
3369
3370 case Primitive::kPrimShort: {
3371 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003372 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003373 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003374 size_t offset =
3375 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003376 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3377 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003378 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003379 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3380 }
3381 break;
3382 }
3383
3384 case Primitive::kPrimChar: {
3385 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003386 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003387 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003388 size_t offset =
3389 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003390 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3391 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003392 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003393 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3394 }
3395 break;
3396 }
3397
3398 case Primitive::kPrimInt:
3399 case Primitive::kPrimNot: {
3400 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3401 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003402 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003403 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003404 size_t offset =
3405 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003406 __ LoadFromOffset(kLoadWord, out, obj, offset);
3407 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003408 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003409 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3410 }
3411 break;
3412 }
3413
3414 case Primitive::kPrimLong: {
3415 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003416 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003417 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003418 size_t offset =
3419 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003420 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003421 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003422 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003423 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003424 }
3425 break;
3426 }
3427
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003428 case Primitive::kPrimFloat: {
3429 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3430 Location out = locations->Out();
3431 DCHECK(out.IsFpuRegister());
3432 if (index.IsConstant()) {
3433 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3434 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3435 } else {
3436 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3437 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3438 }
3439 break;
3440 }
3441
3442 case Primitive::kPrimDouble: {
3443 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3444 Location out = locations->Out();
3445 DCHECK(out.IsFpuRegisterPair());
3446 if (index.IsConstant()) {
3447 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3448 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3449 } else {
3450 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3451 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3452 }
3453 break;
3454 }
3455
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003456 case Primitive::kPrimVoid:
3457 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003458 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003459 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003460 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003461}
3462
3463void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003464 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003465
3466 bool needs_write_barrier =
3467 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3468 bool needs_runtime_call = instruction->NeedsTypeCheck();
3469
Nicolas Geoffray39468442014-09-02 15:17:15 +01003470 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003471 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3472 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003473 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003474 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3475 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3476 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003477 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003478 locations->SetInAt(0, Location::RequiresRegister());
3479 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003480 if (Primitive::IsFloatingPointType(value_type)) {
3481 locations->SetInAt(2, Location::RequiresFpuRegister());
3482 } else {
3483 locations->SetInAt(2, Location::RequiresRegister());
3484 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003485
3486 if (needs_write_barrier) {
3487 // Temporary registers for the write barrier.
3488 locations->AddTemp(Location::RequiresRegister());
3489 locations->AddTemp(Location::RequiresRegister());
3490 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003491 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003492}
3493
3494void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3495 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003496 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003497 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003498 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003499 bool needs_runtime_call = locations->WillCall();
3500 bool needs_write_barrier =
3501 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003502
3503 switch (value_type) {
3504 case Primitive::kPrimBoolean:
3505 case Primitive::kPrimByte: {
3506 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003507 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003508 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003509 size_t offset =
3510 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003511 __ StoreToOffset(kStoreByte, value, obj, offset);
3512 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003513 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003514 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3515 }
3516 break;
3517 }
3518
3519 case Primitive::kPrimShort:
3520 case Primitive::kPrimChar: {
3521 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003522 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003523 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003524 size_t offset =
3525 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003526 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3527 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003528 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003529 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3530 }
3531 break;
3532 }
3533
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003534 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003535 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003536 if (!needs_runtime_call) {
3537 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003538 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003539 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003540 size_t offset =
3541 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003542 __ StoreToOffset(kStoreWord, value, obj, offset);
3543 } else {
3544 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003545 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003546 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3547 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003548 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003549 if (needs_write_barrier) {
3550 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003551 Register temp = locations->GetTemp(0).AsRegister<Register>();
3552 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003553 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003554 }
3555 } else {
3556 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003557 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3558 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003559 instruction->GetDexPc(),
3560 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003561 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003562 break;
3563 }
3564
3565 case Primitive::kPrimLong: {
3566 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003567 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003568 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003569 size_t offset =
3570 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003571 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003572 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003573 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003574 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003575 }
3576 break;
3577 }
3578
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003579 case Primitive::kPrimFloat: {
3580 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3581 Location value = locations->InAt(2);
3582 DCHECK(value.IsFpuRegister());
3583 if (index.IsConstant()) {
3584 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3585 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3586 } else {
3587 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3588 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3589 }
3590 break;
3591 }
3592
3593 case Primitive::kPrimDouble: {
3594 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3595 Location value = locations->InAt(2);
3596 DCHECK(value.IsFpuRegisterPair());
3597 if (index.IsConstant()) {
3598 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3599 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3600 } else {
3601 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3602 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3603 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003604
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003605 break;
3606 }
3607
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003608 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003609 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003610 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003611 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003612
3613 // Ints and objects are handled in the switch.
3614 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3615 codegen_->MaybeRecordImplicitNullCheck(instruction);
3616 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003617}
3618
3619void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003620 LocationSummary* locations =
3621 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003622 locations->SetInAt(0, Location::RequiresRegister());
3623 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003624}
3625
3626void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3627 LocationSummary* locations = instruction->GetLocations();
3628 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003629 Register obj = locations->InAt(0).AsRegister<Register>();
3630 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003631 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003632 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003633}
3634
3635void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003636 LocationSummary* locations =
3637 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003638 locations->SetInAt(0, Location::RequiresRegister());
3639 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003640 if (instruction->HasUses()) {
3641 locations->SetOut(Location::SameAsFirstInput());
3642 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003643}
3644
3645void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3646 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003647 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003648 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003649 codegen_->AddSlowPath(slow_path);
3650
Roland Levillain271ab9c2014-11-27 15:23:57 +00003651 Register index = locations->InAt(0).AsRegister<Register>();
3652 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003653
3654 __ cmp(index, ShifterOperand(length));
3655 __ b(slow_path->GetEntryLabel(), CS);
3656}
3657
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003658void CodeGeneratorARM::MarkGCCard(Register temp,
3659 Register card,
3660 Register object,
3661 Register value,
3662 bool can_be_null) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00003663 NearLabel is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003664 if (can_be_null) {
3665 __ CompareAndBranchIfZero(value, &is_null);
3666 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003667 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3668 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3669 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003670 if (can_be_null) {
3671 __ Bind(&is_null);
3672 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003673}
3674
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003675void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3676 temp->SetLocations(nullptr);
3677}
3678
3679void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3680 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003681 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003682}
3683
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003684void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003685 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003686 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003687}
3688
3689void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003690 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3691}
3692
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003693void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3694 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3695}
3696
3697void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003698 HBasicBlock* block = instruction->GetBlock();
3699 if (block->GetLoopInformation() != nullptr) {
3700 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3701 // The back edge will generate the suspend check.
3702 return;
3703 }
3704 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3705 // The goto will generate the suspend check.
3706 return;
3707 }
3708 GenerateSuspendCheck(instruction, nullptr);
3709}
3710
3711void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3712 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003713 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003714 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3715 if (slow_path == nullptr) {
3716 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3717 instruction->SetSlowPath(slow_path);
3718 codegen_->AddSlowPath(slow_path);
3719 if (successor != nullptr) {
3720 DCHECK(successor->IsLoopHeader());
3721 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3722 }
3723 } else {
3724 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3725 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003726
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003727 __ LoadFromOffset(
3728 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3729 __ cmp(IP, ShifterOperand(0));
3730 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003731 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003732 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003733 __ Bind(slow_path->GetReturnLabel());
3734 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003735 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003736 __ b(slow_path->GetEntryLabel());
3737 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003738}
3739
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003740ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3741 return codegen_->GetAssembler();
3742}
3743
3744void ParallelMoveResolverARM::EmitMove(size_t index) {
3745 MoveOperands* move = moves_.Get(index);
3746 Location source = move->GetSource();
3747 Location destination = move->GetDestination();
3748
3749 if (source.IsRegister()) {
3750 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003751 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003752 } else {
3753 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003754 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003755 SP, destination.GetStackIndex());
3756 }
3757 } else if (source.IsStackSlot()) {
3758 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003759 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003760 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003761 } else if (destination.IsFpuRegister()) {
3762 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003763 } else {
3764 DCHECK(destination.IsStackSlot());
3765 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3766 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3767 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003768 } else if (source.IsFpuRegister()) {
3769 if (destination.IsFpuRegister()) {
3770 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003771 } else {
3772 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003773 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3774 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003775 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003776 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003777 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3778 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003779 } else if (destination.IsRegisterPair()) {
3780 DCHECK(ExpectedPairLayout(destination));
3781 __ LoadFromOffset(
3782 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3783 } else {
3784 DCHECK(destination.IsFpuRegisterPair()) << destination;
3785 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3786 SP,
3787 source.GetStackIndex());
3788 }
3789 } else if (source.IsRegisterPair()) {
3790 if (destination.IsRegisterPair()) {
3791 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3792 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3793 } else {
3794 DCHECK(destination.IsDoubleStackSlot()) << destination;
3795 DCHECK(ExpectedPairLayout(source));
3796 __ StoreToOffset(
3797 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3798 }
3799 } else if (source.IsFpuRegisterPair()) {
3800 if (destination.IsFpuRegisterPair()) {
3801 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3802 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3803 } else {
3804 DCHECK(destination.IsDoubleStackSlot()) << destination;
3805 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3806 SP,
3807 destination.GetStackIndex());
3808 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003809 } else {
3810 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003811 HConstant* constant = source.GetConstant();
3812 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3813 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003814 if (destination.IsRegister()) {
3815 __ LoadImmediate(destination.AsRegister<Register>(), value);
3816 } else {
3817 DCHECK(destination.IsStackSlot());
3818 __ LoadImmediate(IP, value);
3819 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3820 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003821 } else if (constant->IsLongConstant()) {
3822 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003823 if (destination.IsRegisterPair()) {
3824 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3825 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003826 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003827 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003828 __ LoadImmediate(IP, Low32Bits(value));
3829 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3830 __ LoadImmediate(IP, High32Bits(value));
3831 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3832 }
3833 } else if (constant->IsDoubleConstant()) {
3834 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003835 if (destination.IsFpuRegisterPair()) {
3836 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003837 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003838 DCHECK(destination.IsDoubleStackSlot()) << destination;
3839 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003840 __ LoadImmediate(IP, Low32Bits(int_value));
3841 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3842 __ LoadImmediate(IP, High32Bits(int_value));
3843 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3844 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003845 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003846 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003847 float value = constant->AsFloatConstant()->GetValue();
3848 if (destination.IsFpuRegister()) {
3849 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3850 } else {
3851 DCHECK(destination.IsStackSlot());
3852 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3853 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3854 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003855 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003856 }
3857}
3858
3859void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3860 __ Mov(IP, reg);
3861 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3862 __ StoreToOffset(kStoreWord, IP, SP, mem);
3863}
3864
3865void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3866 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3867 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3868 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3869 SP, mem1 + stack_offset);
3870 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3871 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3872 SP, mem2 + stack_offset);
3873 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3874}
3875
3876void ParallelMoveResolverARM::EmitSwap(size_t index) {
3877 MoveOperands* move = moves_.Get(index);
3878 Location source = move->GetSource();
3879 Location destination = move->GetDestination();
3880
3881 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003882 DCHECK_NE(source.AsRegister<Register>(), IP);
3883 DCHECK_NE(destination.AsRegister<Register>(), IP);
3884 __ Mov(IP, source.AsRegister<Register>());
3885 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3886 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003887 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003888 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003889 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003890 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003891 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3892 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003893 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003894 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003895 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003896 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003897 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003898 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003899 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003900 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003901 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3902 destination.AsRegisterPairHigh<Register>(),
3903 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003904 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003905 Register low_reg = source.IsRegisterPair()
3906 ? source.AsRegisterPairLow<Register>()
3907 : destination.AsRegisterPairLow<Register>();
3908 int mem = source.IsRegisterPair()
3909 ? destination.GetStackIndex()
3910 : source.GetStackIndex();
3911 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003912 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003913 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003914 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003915 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003916 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3917 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003918 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003919 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003920 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003921 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3922 DRegister reg = source.IsFpuRegisterPair()
3923 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3924 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3925 int mem = source.IsFpuRegisterPair()
3926 ? destination.GetStackIndex()
3927 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003928 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003929 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003930 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003931 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3932 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3933 : destination.AsFpuRegister<SRegister>();
3934 int mem = source.IsFpuRegister()
3935 ? destination.GetStackIndex()
3936 : source.GetStackIndex();
3937
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003938 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003939 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003940 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003941 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003942 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3943 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003944 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003945 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003946 }
3947}
3948
3949void ParallelMoveResolverARM::SpillScratch(int reg) {
3950 __ Push(static_cast<Register>(reg));
3951}
3952
3953void ParallelMoveResolverARM::RestoreScratch(int reg) {
3954 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003955}
3956
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003957void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003958 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3959 ? LocationSummary::kCallOnSlowPath
3960 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003961 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003962 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003963 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003964 locations->SetOut(Location::RequiresRegister());
3965}
3966
3967void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003968 LocationSummary* locations = cls->GetLocations();
3969 Register out = locations->Out().AsRegister<Register>();
3970 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003971 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003972 DCHECK(!cls->CanCallRuntime());
3973 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003974 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07003975 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003976 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003977 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003978 __ LoadFromOffset(kLoadWord,
3979 out,
3980 current_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -07003981 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003982 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003983
3984 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3985 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3986 codegen_->AddSlowPath(slow_path);
3987 __ cmp(out, ShifterOperand(0));
3988 __ b(slow_path->GetEntryLabel(), EQ);
3989 if (cls->MustGenerateClinitCheck()) {
3990 GenerateClassInitializationCheck(slow_path, out);
3991 } else {
3992 __ Bind(slow_path->GetExitLabel());
3993 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003994 }
3995}
3996
3997void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3998 LocationSummary* locations =
3999 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
4000 locations->SetInAt(0, Location::RequiresRegister());
4001 if (check->HasUses()) {
4002 locations->SetOut(Location::SameAsFirstInput());
4003 }
4004}
4005
4006void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004007 // We assume the class is not null.
4008 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4009 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004010 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00004011 GenerateClassInitializationCheck(slow_path,
4012 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004013}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004014
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004015void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
4016 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004017 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
4018 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
4019 __ b(slow_path->GetEntryLabel(), LT);
4020 // Even if the initialized flag is set, we may be in a situation where caches are not synced
4021 // properly. Therefore, we do a memory fence.
4022 __ dmb(ISH);
4023 __ Bind(slow_path->GetExitLabel());
4024}
4025
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004026void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
4027 LocationSummary* locations =
4028 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004029 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004030 locations->SetOut(Location::RequiresRegister());
4031}
4032
4033void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
4034 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
4035 codegen_->AddSlowPath(slow_path);
4036
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004037 LocationSummary* locations = load->GetLocations();
4038 Register out = locations->Out().AsRegister<Register>();
4039 Register current_method = locations->InAt(0).AsRegister<Register>();
4040 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004041 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004042 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004043 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
4044 __ cmp(out, ShifterOperand(0));
4045 __ b(slow_path->GetEntryLabel(), EQ);
4046 __ Bind(slow_path->GetExitLabel());
4047}
4048
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004049void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4050 LocationSummary* locations =
4051 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4052 locations->SetOut(Location::RequiresRegister());
4053}
4054
4055void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004056 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004057 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4058 __ LoadFromOffset(kLoadWord, out, TR, offset);
4059 __ LoadImmediate(IP, 0);
4060 __ StoreToOffset(kStoreWord, IP, TR, offset);
4061}
4062
4063void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4064 LocationSummary* locations =
4065 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4066 InvokeRuntimeCallingConvention calling_convention;
4067 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4068}
4069
4070void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4071 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004072 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004073}
4074
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004075void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004076 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4077 ? LocationSummary::kNoCall
4078 : LocationSummary::kCallOnSlowPath;
4079 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4080 locations->SetInAt(0, Location::RequiresRegister());
4081 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004082 // The out register is used as a temporary, so it overlaps with the inputs.
4083 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004084}
4085
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004086void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004087 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004088 Register obj = locations->InAt(0).AsRegister<Register>();
4089 Register cls = locations->InAt(1).AsRegister<Register>();
4090 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004091 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004092 NearLabel done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004093 SlowPathCodeARM* slow_path = nullptr;
4094
4095 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004096 // avoid null check if we know obj is not null.
4097 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004098 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004099 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004100 // Compare the class of `obj` with `cls`.
4101 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
4102 __ cmp(out, ShifterOperand(cls));
4103 if (instruction->IsClassFinal()) {
4104 // Classes must be equal for the instanceof to succeed.
4105 __ b(&zero, NE);
4106 __ LoadImmediate(out, 1);
4107 __ b(&done);
4108 } else {
4109 // If the classes are not equal, we go into a slow path.
4110 DCHECK(locations->OnlyCallsOnSlowPath());
4111 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004112 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004113 codegen_->AddSlowPath(slow_path);
4114 __ b(slow_path->GetEntryLabel(), NE);
4115 __ LoadImmediate(out, 1);
4116 __ b(&done);
4117 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004118
4119 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4120 __ Bind(&zero);
4121 __ LoadImmediate(out, 0);
4122 }
4123
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004124 if (slow_path != nullptr) {
4125 __ Bind(slow_path->GetExitLabel());
4126 }
4127 __ Bind(&done);
4128}
4129
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004130void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4131 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4132 instruction, LocationSummary::kCallOnSlowPath);
4133 locations->SetInAt(0, Location::RequiresRegister());
4134 locations->SetInAt(1, Location::RequiresRegister());
4135 locations->AddTemp(Location::RequiresRegister());
4136}
4137
4138void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4139 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004140 Register obj = locations->InAt(0).AsRegister<Register>();
4141 Register cls = locations->InAt(1).AsRegister<Register>();
4142 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004143 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4144
4145 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4146 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
4147 codegen_->AddSlowPath(slow_path);
4148
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004149 NearLabel done;
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004150 // avoid null check if we know obj is not null.
4151 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004152 __ CompareAndBranchIfZero(obj, &done);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004153 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004154 // Compare the class of `obj` with `cls`.
4155 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
4156 __ cmp(temp, ShifterOperand(cls));
4157 __ b(slow_path->GetEntryLabel(), NE);
4158 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004159 if (instruction->MustDoNullCheck()) {
4160 __ Bind(&done);
4161 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004162}
4163
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004164void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4165 LocationSummary* locations =
4166 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4167 InvokeRuntimeCallingConvention calling_convention;
4168 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4169}
4170
4171void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4172 codegen_->InvokeRuntime(instruction->IsEnter()
4173 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4174 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004175 instruction->GetDexPc(),
4176 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004177}
4178
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004179void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4180void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4181void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4182
4183void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4184 LocationSummary* locations =
4185 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4186 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4187 || instruction->GetResultType() == Primitive::kPrimLong);
4188 locations->SetInAt(0, Location::RequiresRegister());
4189 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004190 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004191}
4192
4193void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4194 HandleBitwiseOperation(instruction);
4195}
4196
4197void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4198 HandleBitwiseOperation(instruction);
4199}
4200
4201void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4202 HandleBitwiseOperation(instruction);
4203}
4204
4205void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4206 LocationSummary* locations = instruction->GetLocations();
4207
4208 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004209 Register first = locations->InAt(0).AsRegister<Register>();
4210 Register second = locations->InAt(1).AsRegister<Register>();
4211 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004212 if (instruction->IsAnd()) {
4213 __ and_(out, first, ShifterOperand(second));
4214 } else if (instruction->IsOr()) {
4215 __ orr(out, first, ShifterOperand(second));
4216 } else {
4217 DCHECK(instruction->IsXor());
4218 __ eor(out, first, ShifterOperand(second));
4219 }
4220 } else {
4221 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4222 Location first = locations->InAt(0);
4223 Location second = locations->InAt(1);
4224 Location out = locations->Out();
4225 if (instruction->IsAnd()) {
4226 __ and_(out.AsRegisterPairLow<Register>(),
4227 first.AsRegisterPairLow<Register>(),
4228 ShifterOperand(second.AsRegisterPairLow<Register>()));
4229 __ and_(out.AsRegisterPairHigh<Register>(),
4230 first.AsRegisterPairHigh<Register>(),
4231 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4232 } else if (instruction->IsOr()) {
4233 __ orr(out.AsRegisterPairLow<Register>(),
4234 first.AsRegisterPairLow<Register>(),
4235 ShifterOperand(second.AsRegisterPairLow<Register>()));
4236 __ orr(out.AsRegisterPairHigh<Register>(),
4237 first.AsRegisterPairHigh<Register>(),
4238 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4239 } else {
4240 DCHECK(instruction->IsXor());
4241 __ eor(out.AsRegisterPairLow<Register>(),
4242 first.AsRegisterPairLow<Register>(),
4243 ShifterOperand(second.AsRegisterPairLow<Register>()));
4244 __ eor(out.AsRegisterPairHigh<Register>(),
4245 first.AsRegisterPairHigh<Register>(),
4246 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4247 }
4248 }
4249}
4250
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004251void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
4252 DCHECK_EQ(temp, kArtMethodRegister);
4253
4254 // TODO: Implement all kinds of calls:
4255 // 1) boot -> boot
4256 // 2) app -> boot
4257 // 3) app -> app
4258 //
4259 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4260
Jeff Hao848f70a2014-01-15 13:49:50 -08004261 if (invoke->IsStringInit()) {
4262 // temp = thread->string_init_entrypoint
4263 __ LoadFromOffset(kLoadWord, temp, TR, invoke->GetStringInitOffset());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004264 // LR = temp[offset_of_quick_compiled_code]
4265 __ LoadFromOffset(kLoadWord, LR, temp,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004266 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004267 kArmWordSize).Int32Value());
4268 // LR()
4269 __ blx(LR);
4270 } else {
Jeff Hao848f70a2014-01-15 13:49:50 -08004271 // temp = method;
4272 LoadCurrentMethod(temp);
4273 if (!invoke->IsRecursive()) {
4274 // temp = temp->dex_cache_resolved_methods_;
4275 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004276 kLoadWord, temp, temp, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Jeff Hao848f70a2014-01-15 13:49:50 -08004277 // temp = temp[index_in_cache]
4278 __ LoadFromOffset(
4279 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4280 // LR = temp[offset_of_quick_compiled_code]
Mathieu Chartiere401d142015-04-22 13:56:20 -07004281 __ LoadFromOffset(kLoadWord, LR, temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4282 kArmWordSize).Int32Value());
Jeff Hao848f70a2014-01-15 13:49:50 -08004283 // LR()
4284 __ blx(LR);
4285 } else {
4286 __ bl(GetFrameEntryLabel());
4287 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004288 }
4289
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004290 DCHECK(!IsLeafMethod());
4291}
4292
Calin Juravleb1498f62015-02-16 13:13:29 +00004293void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4294 // Nothing to do, this should be removed during prepare for register allocator.
4295 UNUSED(instruction);
4296 LOG(FATAL) << "Unreachable";
4297}
4298
4299void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4300 // Nothing to do, this should be removed during prepare for register allocator.
4301 UNUSED(instruction);
4302 LOG(FATAL) << "Unreachable";
4303}
4304
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004305} // namespace arm
4306} // namespace art