blob: 696f5a8718447eae6e5a316e3c5b65406e067177 [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 Levillain5b3ee562015-04-14 16:02:41 +01001454 // The float-to-long, double-to-long and long-to-float type conversions
1455 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001456 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001457 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1458 && result_type == Primitive::kPrimLong)
1459 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001460 ? LocationSummary::kCall
1461 : LocationSummary::kNoCall;
1462 LocationSummary* locations =
1463 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1464
David Brazdilb2bd1c52015-03-25 11:17:37 +00001465 // The Java language does not allow treating boolean as an integral type but
1466 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001467
Roland Levillaindff1f282014-11-05 14:15:05 +00001468 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001469 case Primitive::kPrimByte:
1470 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001471 case Primitive::kPrimBoolean:
1472 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001473 case Primitive::kPrimShort:
1474 case Primitive::kPrimInt:
1475 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001476 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001477 locations->SetInAt(0, Location::RequiresRegister());
1478 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1479 break;
1480
1481 default:
1482 LOG(FATAL) << "Unexpected type conversion from " << input_type
1483 << " to " << result_type;
1484 }
1485 break;
1486
Roland Levillain01a8d712014-11-14 16:27:39 +00001487 case Primitive::kPrimShort:
1488 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001489 case Primitive::kPrimBoolean:
1490 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001491 case Primitive::kPrimByte:
1492 case Primitive::kPrimInt:
1493 case Primitive::kPrimChar:
1494 // Processing a Dex `int-to-short' instruction.
1495 locations->SetInAt(0, Location::RequiresRegister());
1496 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1497 break;
1498
1499 default:
1500 LOG(FATAL) << "Unexpected type conversion from " << input_type
1501 << " to " << result_type;
1502 }
1503 break;
1504
Roland Levillain946e1432014-11-11 17:35:19 +00001505 case Primitive::kPrimInt:
1506 switch (input_type) {
1507 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001508 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001509 locations->SetInAt(0, Location::Any());
1510 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1511 break;
1512
1513 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001514 // Processing a Dex `float-to-int' instruction.
1515 locations->SetInAt(0, Location::RequiresFpuRegister());
1516 locations->SetOut(Location::RequiresRegister());
1517 locations->AddTemp(Location::RequiresFpuRegister());
1518 break;
1519
Roland Levillain946e1432014-11-11 17:35:19 +00001520 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001521 // Processing a Dex `double-to-int' instruction.
1522 locations->SetInAt(0, Location::RequiresFpuRegister());
1523 locations->SetOut(Location::RequiresRegister());
1524 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001525 break;
1526
1527 default:
1528 LOG(FATAL) << "Unexpected type conversion from " << input_type
1529 << " to " << result_type;
1530 }
1531 break;
1532
Roland Levillaindff1f282014-11-05 14:15:05 +00001533 case Primitive::kPrimLong:
1534 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001535 case Primitive::kPrimBoolean:
1536 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001537 case Primitive::kPrimByte:
1538 case Primitive::kPrimShort:
1539 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001540 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001541 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001542 locations->SetInAt(0, Location::RequiresRegister());
1543 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1544 break;
1545
Roland Levillain624279f2014-12-04 11:54:28 +00001546 case Primitive::kPrimFloat: {
1547 // Processing a Dex `float-to-long' instruction.
1548 InvokeRuntimeCallingConvention calling_convention;
1549 locations->SetInAt(0, Location::FpuRegisterLocation(
1550 calling_convention.GetFpuRegisterAt(0)));
1551 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1552 break;
1553 }
1554
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001555 case Primitive::kPrimDouble: {
1556 // Processing a Dex `double-to-long' instruction.
1557 InvokeRuntimeCallingConvention calling_convention;
1558 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1559 calling_convention.GetFpuRegisterAt(0),
1560 calling_convention.GetFpuRegisterAt(1)));
1561 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001562 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001563 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001564
1565 default:
1566 LOG(FATAL) << "Unexpected type conversion from " << input_type
1567 << " to " << result_type;
1568 }
1569 break;
1570
Roland Levillain981e4542014-11-14 11:47:14 +00001571 case Primitive::kPrimChar:
1572 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001573 case Primitive::kPrimBoolean:
1574 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001575 case Primitive::kPrimByte:
1576 case Primitive::kPrimShort:
1577 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001578 // Processing a Dex `int-to-char' instruction.
1579 locations->SetInAt(0, Location::RequiresRegister());
1580 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1581 break;
1582
1583 default:
1584 LOG(FATAL) << "Unexpected type conversion from " << input_type
1585 << " to " << result_type;
1586 }
1587 break;
1588
Roland Levillaindff1f282014-11-05 14:15:05 +00001589 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001590 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001591 case Primitive::kPrimBoolean:
1592 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001593 case Primitive::kPrimByte:
1594 case Primitive::kPrimShort:
1595 case Primitive::kPrimInt:
1596 case Primitive::kPrimChar:
1597 // Processing a Dex `int-to-float' instruction.
1598 locations->SetInAt(0, Location::RequiresRegister());
1599 locations->SetOut(Location::RequiresFpuRegister());
1600 break;
1601
Roland Levillain5b3ee562015-04-14 16:02:41 +01001602 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001603 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001604 InvokeRuntimeCallingConvention calling_convention;
1605 locations->SetInAt(0, Location::RegisterPairLocation(
1606 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1607 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001608 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001609 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001610
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 Levillain5b3ee562015-04-14 16:02:41 +01001818 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001819 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001820 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
1821 conversion,
1822 conversion->GetDexPc(),
1823 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001824 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00001825
Roland Levillaincff13742014-11-17 14:32:17 +00001826 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001827 // Processing a Dex `double-to-float' instruction.
1828 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1829 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001830 break;
1831
1832 default:
1833 LOG(FATAL) << "Unexpected type conversion from " << input_type
1834 << " to " << result_type;
1835 };
1836 break;
1837
Roland Levillaindff1f282014-11-05 14:15:05 +00001838 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001839 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001840 case Primitive::kPrimBoolean:
1841 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001842 case Primitive::kPrimByte:
1843 case Primitive::kPrimShort:
1844 case Primitive::kPrimInt:
1845 case Primitive::kPrimChar: {
1846 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001847 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001848 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1849 out.AsFpuRegisterPairLow<SRegister>());
1850 break;
1851 }
1852
Roland Levillain647b9ed2014-11-27 12:06:00 +00001853 case Primitive::kPrimLong: {
1854 // Processing a Dex `long-to-double' instruction.
1855 Register low = in.AsRegisterPairLow<Register>();
1856 Register high = in.AsRegisterPairHigh<Register>();
1857 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1858 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001859 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1860 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001861 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1862 DRegister temp_d = FromLowSToD(temp_s);
1863
Roland Levillain647b9ed2014-11-27 12:06:00 +00001864 // out_d = int-to-double(high)
1865 __ vmovsr(out_s, high);
1866 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001867 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1868 // as an immediate value into `temp_d` does not work, as
1869 // this instruction only transfers 8 significant bits of its
1870 // immediate operand. Instead, use two 32-bit core
1871 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1872 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1873 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001874 __ vmovdrr(temp_d, constant_low, constant_high);
1875 // out_d = out_d * 2^32
1876 __ vmuld(out_d, out_d, temp_d);
1877 // temp_d = unsigned-to-double(low)
1878 __ vmovsr(temp_s, low);
1879 __ vcvtdu(temp_d, temp_s);
1880 // out_d = out_d + temp_d
1881 __ vaddd(out_d, out_d, temp_d);
1882 break;
1883 }
1884
Roland Levillaincff13742014-11-17 14:32:17 +00001885 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001886 // Processing a Dex `float-to-double' instruction.
1887 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1888 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001889 break;
1890
1891 default:
1892 LOG(FATAL) << "Unexpected type conversion from " << input_type
1893 << " to " << result_type;
1894 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001895 break;
1896
1897 default:
1898 LOG(FATAL) << "Unexpected type conversion from " << input_type
1899 << " to " << result_type;
1900 }
1901}
1902
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001903void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001904 LocationSummary* locations =
1905 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001906 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001907 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001908 locations->SetInAt(0, Location::RequiresRegister());
1909 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001910 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1911 break;
1912 }
1913
1914 case Primitive::kPrimLong: {
1915 locations->SetInAt(0, Location::RequiresRegister());
1916 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001917 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001918 break;
1919 }
1920
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001921 case Primitive::kPrimFloat:
1922 case Primitive::kPrimDouble: {
1923 locations->SetInAt(0, Location::RequiresFpuRegister());
1924 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001925 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001926 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001927 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001928
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001929 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001930 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001931 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001932}
1933
1934void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1935 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001936 Location out = locations->Out();
1937 Location first = locations->InAt(0);
1938 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001939 switch (add->GetResultType()) {
1940 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001941 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001942 __ add(out.AsRegister<Register>(),
1943 first.AsRegister<Register>(),
1944 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001945 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001946 __ AddConstant(out.AsRegister<Register>(),
1947 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001948 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001949 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001950 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001951
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001952 case Primitive::kPrimLong: {
1953 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001954 __ adds(out.AsRegisterPairLow<Register>(),
1955 first.AsRegisterPairLow<Register>(),
1956 ShifterOperand(second.AsRegisterPairLow<Register>()));
1957 __ adc(out.AsRegisterPairHigh<Register>(),
1958 first.AsRegisterPairHigh<Register>(),
1959 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001960 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001961 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001962
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001963 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001964 __ vadds(out.AsFpuRegister<SRegister>(),
1965 first.AsFpuRegister<SRegister>(),
1966 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001967 break;
1968
1969 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001970 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1971 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1972 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001973 break;
1974
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001975 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001976 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001977 }
1978}
1979
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001980void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001981 LocationSummary* locations =
1982 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001983 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001984 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001985 locations->SetInAt(0, Location::RequiresRegister());
1986 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001987 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1988 break;
1989 }
1990
1991 case Primitive::kPrimLong: {
1992 locations->SetInAt(0, Location::RequiresRegister());
1993 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001994 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001995 break;
1996 }
Calin Juravle11351682014-10-23 15:38:15 +01001997 case Primitive::kPrimFloat:
1998 case Primitive::kPrimDouble: {
1999 locations->SetInAt(0, Location::RequiresFpuRegister());
2000 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002001 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002002 break;
Calin Juravle11351682014-10-23 15:38:15 +01002003 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002004 default:
Calin Juravle11351682014-10-23 15:38:15 +01002005 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002006 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002007}
2008
2009void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2010 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002011 Location out = locations->Out();
2012 Location first = locations->InAt(0);
2013 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002014 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002015 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002016 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002017 __ sub(out.AsRegister<Register>(),
2018 first.AsRegister<Register>(),
2019 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002020 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002021 __ AddConstant(out.AsRegister<Register>(),
2022 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002023 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002024 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002025 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002026 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002027
Calin Juravle11351682014-10-23 15:38:15 +01002028 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002029 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002030 __ subs(out.AsRegisterPairLow<Register>(),
2031 first.AsRegisterPairLow<Register>(),
2032 ShifterOperand(second.AsRegisterPairLow<Register>()));
2033 __ sbc(out.AsRegisterPairHigh<Register>(),
2034 first.AsRegisterPairHigh<Register>(),
2035 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002036 break;
Calin Juravle11351682014-10-23 15:38:15 +01002037 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002038
Calin Juravle11351682014-10-23 15:38:15 +01002039 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002040 __ vsubs(out.AsFpuRegister<SRegister>(),
2041 first.AsFpuRegister<SRegister>(),
2042 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002043 break;
Calin Juravle11351682014-10-23 15:38:15 +01002044 }
2045
2046 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002047 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2048 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2049 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002050 break;
2051 }
2052
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002053
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002054 default:
Calin Juravle11351682014-10-23 15:38:15 +01002055 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002056 }
2057}
2058
Calin Juravle34bacdf2014-10-07 20:23:36 +01002059void LocationsBuilderARM::VisitMul(HMul* mul) {
2060 LocationSummary* locations =
2061 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2062 switch (mul->GetResultType()) {
2063 case Primitive::kPrimInt:
2064 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002065 locations->SetInAt(0, Location::RequiresRegister());
2066 locations->SetInAt(1, Location::RequiresRegister());
2067 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002068 break;
2069 }
2070
Calin Juravleb5bfa962014-10-21 18:02:24 +01002071 case Primitive::kPrimFloat:
2072 case Primitive::kPrimDouble: {
2073 locations->SetInAt(0, Location::RequiresFpuRegister());
2074 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002075 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002076 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002077 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002078
2079 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002080 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002081 }
2082}
2083
2084void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2085 LocationSummary* locations = mul->GetLocations();
2086 Location out = locations->Out();
2087 Location first = locations->InAt(0);
2088 Location second = locations->InAt(1);
2089 switch (mul->GetResultType()) {
2090 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002091 __ mul(out.AsRegister<Register>(),
2092 first.AsRegister<Register>(),
2093 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002094 break;
2095 }
2096 case Primitive::kPrimLong: {
2097 Register out_hi = out.AsRegisterPairHigh<Register>();
2098 Register out_lo = out.AsRegisterPairLow<Register>();
2099 Register in1_hi = first.AsRegisterPairHigh<Register>();
2100 Register in1_lo = first.AsRegisterPairLow<Register>();
2101 Register in2_hi = second.AsRegisterPairHigh<Register>();
2102 Register in2_lo = second.AsRegisterPairLow<Register>();
2103
2104 // Extra checks to protect caused by the existence of R1_R2.
2105 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2106 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2107 DCHECK_NE(out_hi, in1_lo);
2108 DCHECK_NE(out_hi, in2_lo);
2109
2110 // input: in1 - 64 bits, in2 - 64 bits
2111 // output: out
2112 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2113 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2114 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2115
2116 // IP <- in1.lo * in2.hi
2117 __ mul(IP, in1_lo, in2_hi);
2118 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2119 __ mla(out_hi, in1_hi, in2_lo, IP);
2120 // out.lo <- (in1.lo * in2.lo)[31:0];
2121 __ umull(out_lo, IP, in1_lo, in2_lo);
2122 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2123 __ add(out_hi, out_hi, ShifterOperand(IP));
2124 break;
2125 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002126
2127 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002128 __ vmuls(out.AsFpuRegister<SRegister>(),
2129 first.AsFpuRegister<SRegister>(),
2130 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002131 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002132 }
2133
2134 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002135 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2136 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2137 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002138 break;
2139 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002140
2141 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002142 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002143 }
2144}
2145
Zheng Xuc6667102015-05-15 16:08:45 +08002146void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2147 DCHECK(instruction->IsDiv() || instruction->IsRem());
2148 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2149
2150 LocationSummary* locations = instruction->GetLocations();
2151 Location second = locations->InAt(1);
2152 DCHECK(second.IsConstant());
2153
2154 Register out = locations->Out().AsRegister<Register>();
2155 Register dividend = locations->InAt(0).AsRegister<Register>();
2156 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2157 DCHECK(imm == 1 || imm == -1);
2158
2159 if (instruction->IsRem()) {
2160 __ LoadImmediate(out, 0);
2161 } else {
2162 if (imm == 1) {
2163 __ Mov(out, dividend);
2164 } else {
2165 __ rsb(out, dividend, ShifterOperand(0));
2166 }
2167 }
2168}
2169
2170void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2171 DCHECK(instruction->IsDiv() || instruction->IsRem());
2172 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2173
2174 LocationSummary* locations = instruction->GetLocations();
2175 Location second = locations->InAt(1);
2176 DCHECK(second.IsConstant());
2177
2178 Register out = locations->Out().AsRegister<Register>();
2179 Register dividend = locations->InAt(0).AsRegister<Register>();
2180 Register temp = locations->GetTemp(0).AsRegister<Register>();
2181 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002182 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002183 DCHECK(IsPowerOfTwo(abs_imm));
2184 int ctz_imm = CTZ(abs_imm);
2185
2186 if (ctz_imm == 1) {
2187 __ Lsr(temp, dividend, 32 - ctz_imm);
2188 } else {
2189 __ Asr(temp, dividend, 31);
2190 __ Lsr(temp, temp, 32 - ctz_imm);
2191 }
2192 __ add(out, temp, ShifterOperand(dividend));
2193
2194 if (instruction->IsDiv()) {
2195 __ Asr(out, out, ctz_imm);
2196 if (imm < 0) {
2197 __ rsb(out, out, ShifterOperand(0));
2198 }
2199 } else {
2200 __ ubfx(out, out, 0, ctz_imm);
2201 __ sub(out, out, ShifterOperand(temp));
2202 }
2203}
2204
2205void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2206 DCHECK(instruction->IsDiv() || instruction->IsRem());
2207 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2208
2209 LocationSummary* locations = instruction->GetLocations();
2210 Location second = locations->InAt(1);
2211 DCHECK(second.IsConstant());
2212
2213 Register out = locations->Out().AsRegister<Register>();
2214 Register dividend = locations->InAt(0).AsRegister<Register>();
2215 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2216 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2217 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2218
2219 int64_t magic;
2220 int shift;
2221 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2222
2223 __ LoadImmediate(temp1, magic);
2224 __ smull(temp2, temp1, dividend, temp1);
2225
2226 if (imm > 0 && magic < 0) {
2227 __ add(temp1, temp1, ShifterOperand(dividend));
2228 } else if (imm < 0 && magic > 0) {
2229 __ sub(temp1, temp1, ShifterOperand(dividend));
2230 }
2231
2232 if (shift != 0) {
2233 __ Asr(temp1, temp1, shift);
2234 }
2235
2236 if (instruction->IsDiv()) {
2237 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2238 } else {
2239 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2240 // TODO: Strength reduction for mls.
2241 __ LoadImmediate(temp2, imm);
2242 __ mls(out, temp1, temp2, dividend);
2243 }
2244}
2245
2246void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2247 DCHECK(instruction->IsDiv() || instruction->IsRem());
2248 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2249
2250 LocationSummary* locations = instruction->GetLocations();
2251 Location second = locations->InAt(1);
2252 DCHECK(second.IsConstant());
2253
2254 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2255 if (imm == 0) {
2256 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2257 } else if (imm == 1 || imm == -1) {
2258 DivRemOneOrMinusOne(instruction);
2259 } else if (IsPowerOfTwo(std::abs(imm))) {
2260 DivRemByPowerOfTwo(instruction);
2261 } else {
2262 DCHECK(imm <= -2 || imm >= 2);
2263 GenerateDivRemWithAnyConstant(instruction);
2264 }
2265}
2266
Calin Juravle7c4954d2014-10-28 16:57:40 +00002267void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002268 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2269 if (div->GetResultType() == Primitive::kPrimLong) {
2270 // pLdiv runtime call.
2271 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002272 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2273 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002274 } else if (div->GetResultType() == Primitive::kPrimInt &&
2275 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2276 // pIdivmod runtime call.
2277 call_kind = LocationSummary::kCall;
2278 }
2279
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002280 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2281
Calin Juravle7c4954d2014-10-28 16:57:40 +00002282 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002283 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002284 if (div->InputAt(1)->IsConstant()) {
2285 locations->SetInAt(0, Location::RequiresRegister());
2286 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2287 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2288 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2289 if (abs_imm <= 1) {
2290 // No temp register required.
2291 } else {
2292 locations->AddTemp(Location::RequiresRegister());
2293 if (!IsPowerOfTwo(abs_imm)) {
2294 locations->AddTemp(Location::RequiresRegister());
2295 }
2296 }
2297 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002298 locations->SetInAt(0, Location::RequiresRegister());
2299 locations->SetInAt(1, Location::RequiresRegister());
2300 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2301 } else {
2302 InvokeRuntimeCallingConvention calling_convention;
2303 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2304 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2305 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2306 // we only need the former.
2307 locations->SetOut(Location::RegisterLocation(R0));
2308 }
Calin Juravled0d48522014-11-04 16:40:20 +00002309 break;
2310 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002311 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002312 InvokeRuntimeCallingConvention calling_convention;
2313 locations->SetInAt(0, Location::RegisterPairLocation(
2314 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2315 locations->SetInAt(1, Location::RegisterPairLocation(
2316 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002317 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002318 break;
2319 }
2320 case Primitive::kPrimFloat:
2321 case Primitive::kPrimDouble: {
2322 locations->SetInAt(0, Location::RequiresFpuRegister());
2323 locations->SetInAt(1, Location::RequiresFpuRegister());
2324 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2325 break;
2326 }
2327
2328 default:
2329 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2330 }
2331}
2332
2333void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2334 LocationSummary* locations = div->GetLocations();
2335 Location out = locations->Out();
2336 Location first = locations->InAt(0);
2337 Location second = locations->InAt(1);
2338
2339 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002340 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002341 if (second.IsConstant()) {
2342 GenerateDivRemConstantIntegral(div);
2343 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002344 __ sdiv(out.AsRegister<Register>(),
2345 first.AsRegister<Register>(),
2346 second.AsRegister<Register>());
2347 } else {
2348 InvokeRuntimeCallingConvention calling_convention;
2349 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2350 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2351 DCHECK_EQ(R0, out.AsRegister<Register>());
2352
2353 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2354 }
Calin Juravled0d48522014-11-04 16:40:20 +00002355 break;
2356 }
2357
Calin Juravle7c4954d2014-10-28 16:57:40 +00002358 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002359 InvokeRuntimeCallingConvention calling_convention;
2360 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2361 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2362 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2363 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2364 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002365 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002366
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002367 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002368 break;
2369 }
2370
2371 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002372 __ vdivs(out.AsFpuRegister<SRegister>(),
2373 first.AsFpuRegister<SRegister>(),
2374 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002375 break;
2376 }
2377
2378 case Primitive::kPrimDouble: {
2379 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2380 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2381 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2382 break;
2383 }
2384
2385 default:
2386 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2387 }
2388}
2389
Calin Juravlebacfec32014-11-14 15:54:36 +00002390void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002391 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002392
2393 // Most remainders are implemented in the runtime.
2394 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002395 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2396 // sdiv will be replaced by other instruction sequence.
2397 call_kind = LocationSummary::kNoCall;
2398 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2399 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002400 // Have hardware divide instruction for int, do it with three instructions.
2401 call_kind = LocationSummary::kNoCall;
2402 }
2403
Calin Juravlebacfec32014-11-14 15:54:36 +00002404 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2405
Calin Juravled2ec87d2014-12-08 14:24:46 +00002406 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002407 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002408 if (rem->InputAt(1)->IsConstant()) {
2409 locations->SetInAt(0, Location::RequiresRegister());
2410 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2411 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2412 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2413 if (abs_imm <= 1) {
2414 // No temp register required.
2415 } else {
2416 locations->AddTemp(Location::RequiresRegister());
2417 if (!IsPowerOfTwo(abs_imm)) {
2418 locations->AddTemp(Location::RequiresRegister());
2419 }
2420 }
2421 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002422 locations->SetInAt(0, Location::RequiresRegister());
2423 locations->SetInAt(1, Location::RequiresRegister());
2424 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2425 locations->AddTemp(Location::RequiresRegister());
2426 } else {
2427 InvokeRuntimeCallingConvention calling_convention;
2428 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2429 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2430 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2431 // we only need the latter.
2432 locations->SetOut(Location::RegisterLocation(R1));
2433 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002434 break;
2435 }
2436 case Primitive::kPrimLong: {
2437 InvokeRuntimeCallingConvention calling_convention;
2438 locations->SetInAt(0, Location::RegisterPairLocation(
2439 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2440 locations->SetInAt(1, Location::RegisterPairLocation(
2441 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2442 // The runtime helper puts the output in R2,R3.
2443 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2444 break;
2445 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002446 case Primitive::kPrimFloat: {
2447 InvokeRuntimeCallingConvention calling_convention;
2448 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2449 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2450 locations->SetOut(Location::FpuRegisterLocation(S0));
2451 break;
2452 }
2453
Calin Juravlebacfec32014-11-14 15:54:36 +00002454 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002455 InvokeRuntimeCallingConvention calling_convention;
2456 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2457 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2458 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2459 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2460 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002461 break;
2462 }
2463
2464 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002465 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002466 }
2467}
2468
2469void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2470 LocationSummary* locations = rem->GetLocations();
2471 Location out = locations->Out();
2472 Location first = locations->InAt(0);
2473 Location second = locations->InAt(1);
2474
Calin Juravled2ec87d2014-12-08 14:24:46 +00002475 Primitive::Type type = rem->GetResultType();
2476 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002477 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002478 if (second.IsConstant()) {
2479 GenerateDivRemConstantIntegral(rem);
2480 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002481 Register reg1 = first.AsRegister<Register>();
2482 Register reg2 = second.AsRegister<Register>();
2483 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002484
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002485 // temp = reg1 / reg2 (integer division)
2486 // temp = temp * reg2
2487 // dest = reg1 - temp
2488 __ sdiv(temp, reg1, reg2);
2489 __ mul(temp, temp, reg2);
2490 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2491 } else {
2492 InvokeRuntimeCallingConvention calling_convention;
2493 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2494 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2495 DCHECK_EQ(R1, out.AsRegister<Register>());
2496
2497 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2498 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002499 break;
2500 }
2501
2502 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002503 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002504 break;
2505 }
2506
Calin Juravled2ec87d2014-12-08 14:24:46 +00002507 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002508 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002509 break;
2510 }
2511
Calin Juravlebacfec32014-11-14 15:54:36 +00002512 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002513 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002514 break;
2515 }
2516
2517 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002518 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002519 }
2520}
2521
Calin Juravled0d48522014-11-04 16:40:20 +00002522void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2523 LocationSummary* locations =
2524 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002525 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002526 if (instruction->HasUses()) {
2527 locations->SetOut(Location::SameAsFirstInput());
2528 }
2529}
2530
2531void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2532 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2533 codegen_->AddSlowPath(slow_path);
2534
2535 LocationSummary* locations = instruction->GetLocations();
2536 Location value = locations->InAt(0);
2537
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002538 switch (instruction->GetType()) {
2539 case Primitive::kPrimInt: {
2540 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002541 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002542 __ b(slow_path->GetEntryLabel(), EQ);
2543 } else {
2544 DCHECK(value.IsConstant()) << value;
2545 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2546 __ b(slow_path->GetEntryLabel());
2547 }
2548 }
2549 break;
2550 }
2551 case Primitive::kPrimLong: {
2552 if (value.IsRegisterPair()) {
2553 __ orrs(IP,
2554 value.AsRegisterPairLow<Register>(),
2555 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2556 __ b(slow_path->GetEntryLabel(), EQ);
2557 } else {
2558 DCHECK(value.IsConstant()) << value;
2559 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2560 __ b(slow_path->GetEntryLabel());
2561 }
2562 }
2563 break;
2564 default:
2565 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2566 }
2567 }
Calin Juravled0d48522014-11-04 16:40:20 +00002568}
2569
Calin Juravle9aec02f2014-11-18 23:06:35 +00002570void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2571 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2572
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002573 LocationSummary* locations =
2574 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002575
2576 switch (op->GetResultType()) {
2577 case Primitive::kPrimInt: {
2578 locations->SetInAt(0, Location::RequiresRegister());
2579 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002580 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002581 break;
2582 }
2583 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002584 locations->SetInAt(0, Location::RequiresRegister());
2585 locations->SetInAt(1, Location::RequiresRegister());
2586 locations->AddTemp(Location::RequiresRegister());
2587 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002588 break;
2589 }
2590 default:
2591 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2592 }
2593}
2594
2595void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2596 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2597
2598 LocationSummary* locations = op->GetLocations();
2599 Location out = locations->Out();
2600 Location first = locations->InAt(0);
2601 Location second = locations->InAt(1);
2602
2603 Primitive::Type type = op->GetResultType();
2604 switch (type) {
2605 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002606 Register out_reg = out.AsRegister<Register>();
2607 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002608 // Arm doesn't mask the shift count so we need to do it ourselves.
2609 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002610 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002611 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2612 if (op->IsShl()) {
2613 __ Lsl(out_reg, first_reg, second_reg);
2614 } else if (op->IsShr()) {
2615 __ Asr(out_reg, first_reg, second_reg);
2616 } else {
2617 __ Lsr(out_reg, first_reg, second_reg);
2618 }
2619 } else {
2620 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2621 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2622 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2623 __ Mov(out_reg, first_reg);
2624 } else if (op->IsShl()) {
2625 __ Lsl(out_reg, first_reg, shift_value);
2626 } else if (op->IsShr()) {
2627 __ Asr(out_reg, first_reg, shift_value);
2628 } else {
2629 __ Lsr(out_reg, first_reg, shift_value);
2630 }
2631 }
2632 break;
2633 }
2634 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002635 Register o_h = out.AsRegisterPairHigh<Register>();
2636 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002637
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002638 Register temp = locations->GetTemp(0).AsRegister<Register>();
2639
2640 Register high = first.AsRegisterPairHigh<Register>();
2641 Register low = first.AsRegisterPairLow<Register>();
2642
2643 Register second_reg = second.AsRegister<Register>();
2644
Calin Juravle9aec02f2014-11-18 23:06:35 +00002645 if (op->IsShl()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002646 // Shift the high part
2647 __ and_(second_reg, second_reg, ShifterOperand(63));
2648 __ Lsl(o_h, high, second_reg);
2649 // Shift the low part and `or` what overflew on the high part
2650 __ rsb(temp, second_reg, ShifterOperand(32));
2651 __ Lsr(temp, low, temp);
2652 __ orr(o_h, o_h, ShifterOperand(temp));
2653 // If the shift is > 32 bits, override the high part
2654 __ subs(temp, second_reg, ShifterOperand(32));
2655 __ it(PL);
2656 __ Lsl(o_h, low, temp, false, PL);
2657 // Shift the low part
2658 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002659 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002660 // Shift the low part
2661 __ and_(second_reg, second_reg, ShifterOperand(63));
2662 __ Lsr(o_l, low, second_reg);
2663 // Shift the high part and `or` what underflew on the low part
2664 __ rsb(temp, second_reg, ShifterOperand(32));
2665 __ Lsl(temp, high, temp);
2666 __ orr(o_l, o_l, ShifterOperand(temp));
2667 // If the shift is > 32 bits, override the low part
2668 __ subs(temp, second_reg, ShifterOperand(32));
2669 __ it(PL);
2670 __ Asr(o_l, high, temp, false, PL);
2671 // Shift the high part
2672 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002673 } else {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002674 // same as Shr except we use `Lsr`s and not `Asr`s
2675 __ and_(second_reg, second_reg, ShifterOperand(63));
2676 __ Lsr(o_l, low, second_reg);
2677 __ rsb(temp, second_reg, ShifterOperand(32));
2678 __ Lsl(temp, high, temp);
2679 __ orr(o_l, o_l, ShifterOperand(temp));
2680 __ subs(temp, second_reg, ShifterOperand(32));
2681 __ it(PL);
2682 __ Lsr(o_l, high, temp, false, PL);
2683 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002684 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002685 break;
2686 }
2687 default:
2688 LOG(FATAL) << "Unexpected operation type " << type;
2689 }
2690}
2691
2692void LocationsBuilderARM::VisitShl(HShl* shl) {
2693 HandleShift(shl);
2694}
2695
2696void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2697 HandleShift(shl);
2698}
2699
2700void LocationsBuilderARM::VisitShr(HShr* shr) {
2701 HandleShift(shr);
2702}
2703
2704void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2705 HandleShift(shr);
2706}
2707
2708void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2709 HandleShift(ushr);
2710}
2711
2712void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2713 HandleShift(ushr);
2714}
2715
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002716void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002717 LocationSummary* locations =
2718 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002719 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002720 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2721 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2722 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002723}
2724
2725void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2726 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002727 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002728 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002729 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2730 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002731 instruction->GetDexPc(),
2732 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002733}
2734
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002735void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2736 LocationSummary* locations =
2737 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2738 InvokeRuntimeCallingConvention calling_convention;
2739 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002740 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002741 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002742 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002743}
2744
2745void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2746 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002747 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002748 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002749 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2750 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002751 instruction->GetDexPc(),
2752 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002753}
2754
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002755void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002756 LocationSummary* locations =
2757 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002758 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2759 if (location.IsStackSlot()) {
2760 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2761 } else if (location.IsDoubleStackSlot()) {
2762 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002763 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002764 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002765}
2766
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002767void InstructionCodeGeneratorARM::VisitParameterValue(
2768 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002769 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002770}
2771
2772void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
2773 LocationSummary* locations =
2774 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2775 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2776}
2777
2778void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
2779 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002780}
2781
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002782void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002783 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002784 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002785 locations->SetInAt(0, Location::RequiresRegister());
2786 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002787}
2788
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002789void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2790 LocationSummary* locations = not_->GetLocations();
2791 Location out = locations->Out();
2792 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002793 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002794 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002795 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002796 break;
2797
2798 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002799 __ mvn(out.AsRegisterPairLow<Register>(),
2800 ShifterOperand(in.AsRegisterPairLow<Register>()));
2801 __ mvn(out.AsRegisterPairHigh<Register>(),
2802 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002803 break;
2804
2805 default:
2806 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2807 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002808}
2809
David Brazdil66d126e2015-04-03 16:02:44 +01002810void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
2811 LocationSummary* locations =
2812 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
2813 locations->SetInAt(0, Location::RequiresRegister());
2814 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2815}
2816
2817void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01002818 LocationSummary* locations = bool_not->GetLocations();
2819 Location out = locations->Out();
2820 Location in = locations->InAt(0);
2821 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
2822}
2823
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002824void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002825 LocationSummary* locations =
2826 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002827 switch (compare->InputAt(0)->GetType()) {
2828 case Primitive::kPrimLong: {
2829 locations->SetInAt(0, Location::RequiresRegister());
2830 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002831 // Output overlaps because it is written before doing the low comparison.
2832 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002833 break;
2834 }
2835 case Primitive::kPrimFloat:
2836 case Primitive::kPrimDouble: {
2837 locations->SetInAt(0, Location::RequiresFpuRegister());
2838 locations->SetInAt(1, Location::RequiresFpuRegister());
2839 locations->SetOut(Location::RequiresRegister());
2840 break;
2841 }
2842 default:
2843 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2844 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002845}
2846
2847void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002848 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002849 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002850 Location left = locations->InAt(0);
2851 Location right = locations->InAt(1);
2852
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002853 NearLabel less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00002854 Primitive::Type type = compare->InputAt(0)->GetType();
2855 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002856 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002857 __ cmp(left.AsRegisterPairHigh<Register>(),
2858 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002859 __ b(&less, LT);
2860 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002861 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2862 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002863 __ cmp(left.AsRegisterPairLow<Register>(),
2864 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002865 break;
2866 }
2867 case Primitive::kPrimFloat:
2868 case Primitive::kPrimDouble: {
2869 __ LoadImmediate(out, 0);
2870 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002871 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002872 } else {
2873 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2874 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2875 }
2876 __ vmstat(); // transfer FP status register to ARM APSR.
2877 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002878 break;
2879 }
2880 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002881 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002882 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002883 __ b(&done, EQ);
2884 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2885
2886 __ Bind(&greater);
2887 __ LoadImmediate(out, 1);
2888 __ b(&done);
2889
2890 __ Bind(&less);
2891 __ LoadImmediate(out, -1);
2892
2893 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002894}
2895
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002896void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002897 LocationSummary* locations =
2898 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002899 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2900 locations->SetInAt(i, Location::Any());
2901 }
2902 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002903}
2904
2905void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002906 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002907 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002908}
2909
Calin Juravle52c48962014-12-16 17:02:57 +00002910void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2911 // TODO (ported from quick): revisit Arm barrier kinds
2912 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2913 switch (kind) {
2914 case MemBarrierKind::kAnyStore:
2915 case MemBarrierKind::kLoadAny:
2916 case MemBarrierKind::kAnyAny: {
2917 flavour = DmbOptions::ISH;
2918 break;
2919 }
2920 case MemBarrierKind::kStoreStore: {
2921 flavour = DmbOptions::ISHST;
2922 break;
2923 }
2924 default:
2925 LOG(FATAL) << "Unexpected memory barrier " << kind;
2926 }
2927 __ dmb(flavour);
2928}
2929
2930void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2931 uint32_t offset,
2932 Register out_lo,
2933 Register out_hi) {
2934 if (offset != 0) {
2935 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002936 __ add(IP, addr, ShifterOperand(out_lo));
2937 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002938 }
2939 __ ldrexd(out_lo, out_hi, addr);
2940}
2941
2942void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2943 uint32_t offset,
2944 Register value_lo,
2945 Register value_hi,
2946 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002947 Register temp2,
2948 HInstruction* instruction) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002949 NearLabel fail;
Calin Juravle52c48962014-12-16 17:02:57 +00002950 if (offset != 0) {
2951 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002952 __ add(IP, addr, ShifterOperand(temp1));
2953 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002954 }
2955 __ Bind(&fail);
2956 // We need a load followed by store. (The address used in a STREX instruction must
2957 // be the same as the address in the most recently executed LDREX instruction.)
2958 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002959 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002960 __ strexd(temp1, value_lo, value_hi, addr);
2961 __ cmp(temp1, ShifterOperand(0));
2962 __ b(&fail, NE);
2963}
2964
2965void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2966 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2967
Nicolas Geoffray39468442014-09-02 15:17:15 +01002968 LocationSummary* locations =
2969 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002970 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002971
Calin Juravle52c48962014-12-16 17:02:57 +00002972 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01002973 if (Primitive::IsFloatingPointType(field_type)) {
2974 locations->SetInAt(1, Location::RequiresFpuRegister());
2975 } else {
2976 locations->SetInAt(1, Location::RequiresRegister());
2977 }
2978
Calin Juravle52c48962014-12-16 17:02:57 +00002979 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002980 bool generate_volatile = field_info.IsVolatile()
2981 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002982 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002983 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002984 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2985 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002986 locations->AddTemp(Location::RequiresRegister());
2987 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002988 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002989 // Arm encoding have some additional constraints for ldrexd/strexd:
2990 // - registers need to be consecutive
2991 // - the first register should be even but not R14.
2992 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2993 // enable Arm encoding.
2994 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2995
2996 locations->AddTemp(Location::RequiresRegister());
2997 locations->AddTemp(Location::RequiresRegister());
2998 if (field_type == Primitive::kPrimDouble) {
2999 // For doubles we need two more registers to copy the value.
3000 locations->AddTemp(Location::RegisterLocation(R2));
3001 locations->AddTemp(Location::RegisterLocation(R3));
3002 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003003 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003004}
3005
Calin Juravle52c48962014-12-16 17:02:57 +00003006void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003007 const FieldInfo& field_info,
3008 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003009 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3010
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003011 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003012 Register base = locations->InAt(0).AsRegister<Register>();
3013 Location value = locations->InAt(1);
3014
3015 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003016 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003017 Primitive::Type field_type = field_info.GetFieldType();
3018 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3019
3020 if (is_volatile) {
3021 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3022 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003023
3024 switch (field_type) {
3025 case Primitive::kPrimBoolean:
3026 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003027 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003028 break;
3029 }
3030
3031 case Primitive::kPrimShort:
3032 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003033 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003034 break;
3035 }
3036
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003037 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003038 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00003039 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003040 break;
3041 }
3042
3043 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003044 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003045 GenerateWideAtomicStore(base, offset,
3046 value.AsRegisterPairLow<Register>(),
3047 value.AsRegisterPairHigh<Register>(),
3048 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003049 locations->GetTemp(1).AsRegister<Register>(),
3050 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003051 } else {
3052 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003053 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003054 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003055 break;
3056 }
3057
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003058 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003059 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003060 break;
3061 }
3062
3063 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003064 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003065 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003066 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3067 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3068
3069 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3070
3071 GenerateWideAtomicStore(base, offset,
3072 value_reg_lo,
3073 value_reg_hi,
3074 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003075 locations->GetTemp(3).AsRegister<Register>(),
3076 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003077 } else {
3078 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003079 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003080 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003081 break;
3082 }
3083
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003084 case Primitive::kPrimVoid:
3085 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003086 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003087 }
Calin Juravle52c48962014-12-16 17:02:57 +00003088
Calin Juravle77520bc2015-01-12 18:45:46 +00003089 // Longs and doubles are handled in the switch.
3090 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3091 codegen_->MaybeRecordImplicitNullCheck(instruction);
3092 }
3093
3094 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3095 Register temp = locations->GetTemp(0).AsRegister<Register>();
3096 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003097 codegen_->MarkGCCard(
3098 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003099 }
3100
Calin Juravle52c48962014-12-16 17:02:57 +00003101 if (is_volatile) {
3102 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3103 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003104}
3105
Calin Juravle52c48962014-12-16 17:02:57 +00003106void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3107 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003108 LocationSummary* locations =
3109 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003110 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003111
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003112 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003113 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003114 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003115 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003116
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003117 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3118 locations->SetOut(Location::RequiresFpuRegister());
3119 } else {
3120 locations->SetOut(Location::RequiresRegister(),
3121 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3122 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003123 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003124 // Arm encoding have some additional constraints for ldrexd/strexd:
3125 // - registers need to be consecutive
3126 // - the first register should be even but not R14.
3127 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3128 // enable Arm encoding.
3129 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3130 locations->AddTemp(Location::RequiresRegister());
3131 locations->AddTemp(Location::RequiresRegister());
3132 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003133}
3134
Calin Juravle52c48962014-12-16 17:02:57 +00003135void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3136 const FieldInfo& field_info) {
3137 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003138
Calin Juravle52c48962014-12-16 17:02:57 +00003139 LocationSummary* locations = instruction->GetLocations();
3140 Register base = locations->InAt(0).AsRegister<Register>();
3141 Location out = locations->Out();
3142 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003143 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003144 Primitive::Type field_type = field_info.GetFieldType();
3145 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3146
3147 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003148 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003149 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003150 break;
3151 }
3152
3153 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003154 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003155 break;
3156 }
3157
3158 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003159 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003160 break;
3161 }
3162
3163 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003164 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003165 break;
3166 }
3167
3168 case Primitive::kPrimInt:
3169 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003170 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003171 break;
3172 }
3173
3174 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003175 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003176 GenerateWideAtomicLoad(base, offset,
3177 out.AsRegisterPairLow<Register>(),
3178 out.AsRegisterPairHigh<Register>());
3179 } else {
3180 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3181 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003182 break;
3183 }
3184
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003185 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003186 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003187 break;
3188 }
3189
3190 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003191 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003192 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003193 Register lo = locations->GetTemp(0).AsRegister<Register>();
3194 Register hi = locations->GetTemp(1).AsRegister<Register>();
3195 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003196 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003197 __ vmovdrr(out_reg, lo, hi);
3198 } else {
3199 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003200 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003201 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003202 break;
3203 }
3204
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003205 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003206 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003207 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003208 }
Calin Juravle52c48962014-12-16 17:02:57 +00003209
Calin Juravle77520bc2015-01-12 18:45:46 +00003210 // Doubles are handled in the switch.
3211 if (field_type != Primitive::kPrimDouble) {
3212 codegen_->MaybeRecordImplicitNullCheck(instruction);
3213 }
3214
Calin Juravle52c48962014-12-16 17:02:57 +00003215 if (is_volatile) {
3216 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3217 }
3218}
3219
3220void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3221 HandleFieldSet(instruction, instruction->GetFieldInfo());
3222}
3223
3224void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003225 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003226}
3227
3228void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3229 HandleFieldGet(instruction, instruction->GetFieldInfo());
3230}
3231
3232void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3233 HandleFieldGet(instruction, instruction->GetFieldInfo());
3234}
3235
3236void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3237 HandleFieldGet(instruction, instruction->GetFieldInfo());
3238}
3239
3240void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3241 HandleFieldGet(instruction, instruction->GetFieldInfo());
3242}
3243
3244void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3245 HandleFieldSet(instruction, instruction->GetFieldInfo());
3246}
3247
3248void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003249 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003250}
3251
3252void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003253 LocationSummary* locations =
3254 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003255 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003256 if (instruction->HasUses()) {
3257 locations->SetOut(Location::SameAsFirstInput());
3258 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003259}
3260
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003261void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003262 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3263 return;
3264 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003265 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003266
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003267 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3268 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3269}
3270
3271void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003272 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003273 codegen_->AddSlowPath(slow_path);
3274
3275 LocationSummary* locations = instruction->GetLocations();
3276 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003277
Calin Juravle77520bc2015-01-12 18:45:46 +00003278 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
3279 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003280}
3281
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003282void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3283 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3284 GenerateImplicitNullCheck(instruction);
3285 } else {
3286 GenerateExplicitNullCheck(instruction);
3287 }
3288}
3289
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003290void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003291 LocationSummary* locations =
3292 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003293 locations->SetInAt(0, Location::RequiresRegister());
3294 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003295 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3296 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3297 } else {
3298 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3299 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003300}
3301
3302void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3303 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003304 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003305 Location index = locations->InAt(1);
3306
3307 switch (instruction->GetType()) {
3308 case Primitive::kPrimBoolean: {
3309 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003310 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003311 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003312 size_t offset =
3313 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003314 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3315 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003316 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003317 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3318 }
3319 break;
3320 }
3321
3322 case Primitive::kPrimByte: {
3323 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003324 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003325 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003326 size_t offset =
3327 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003328 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3329 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003330 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003331 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3332 }
3333 break;
3334 }
3335
3336 case Primitive::kPrimShort: {
3337 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003338 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003339 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003340 size_t offset =
3341 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003342 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3343 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003344 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003345 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3346 }
3347 break;
3348 }
3349
3350 case Primitive::kPrimChar: {
3351 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003352 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003353 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003354 size_t offset =
3355 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003356 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3357 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003358 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003359 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3360 }
3361 break;
3362 }
3363
3364 case Primitive::kPrimInt:
3365 case Primitive::kPrimNot: {
3366 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3367 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003368 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003369 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003370 size_t offset =
3371 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003372 __ LoadFromOffset(kLoadWord, out, obj, offset);
3373 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003374 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003375 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3376 }
3377 break;
3378 }
3379
3380 case Primitive::kPrimLong: {
3381 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003382 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003383 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003384 size_t offset =
3385 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003386 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003387 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003388 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003389 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003390 }
3391 break;
3392 }
3393
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003394 case Primitive::kPrimFloat: {
3395 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3396 Location out = locations->Out();
3397 DCHECK(out.IsFpuRegister());
3398 if (index.IsConstant()) {
3399 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3400 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3401 } else {
3402 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3403 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3404 }
3405 break;
3406 }
3407
3408 case Primitive::kPrimDouble: {
3409 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3410 Location out = locations->Out();
3411 DCHECK(out.IsFpuRegisterPair());
3412 if (index.IsConstant()) {
3413 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3414 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3415 } else {
3416 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3417 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3418 }
3419 break;
3420 }
3421
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003422 case Primitive::kPrimVoid:
3423 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003424 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003425 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003426 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003427}
3428
3429void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003430 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003431
3432 bool needs_write_barrier =
3433 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3434 bool needs_runtime_call = instruction->NeedsTypeCheck();
3435
Nicolas Geoffray39468442014-09-02 15:17:15 +01003436 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003437 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3438 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003439 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003440 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3441 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3442 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003443 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003444 locations->SetInAt(0, Location::RequiresRegister());
3445 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003446 if (Primitive::IsFloatingPointType(value_type)) {
3447 locations->SetInAt(2, Location::RequiresFpuRegister());
3448 } else {
3449 locations->SetInAt(2, Location::RequiresRegister());
3450 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003451
3452 if (needs_write_barrier) {
3453 // Temporary registers for the write barrier.
3454 locations->AddTemp(Location::RequiresRegister());
3455 locations->AddTemp(Location::RequiresRegister());
3456 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003457 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003458}
3459
3460void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3461 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003462 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003463 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003464 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003465 bool needs_runtime_call = locations->WillCall();
3466 bool needs_write_barrier =
3467 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003468
3469 switch (value_type) {
3470 case Primitive::kPrimBoolean:
3471 case Primitive::kPrimByte: {
3472 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003473 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003474 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003475 size_t offset =
3476 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003477 __ StoreToOffset(kStoreByte, value, obj, offset);
3478 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003479 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003480 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3481 }
3482 break;
3483 }
3484
3485 case Primitive::kPrimShort:
3486 case Primitive::kPrimChar: {
3487 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003488 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003489 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003490 size_t offset =
3491 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003492 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3493 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003494 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003495 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3496 }
3497 break;
3498 }
3499
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003500 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003501 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003502 if (!needs_runtime_call) {
3503 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003504 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003505 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003506 size_t offset =
3507 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003508 __ StoreToOffset(kStoreWord, value, obj, offset);
3509 } else {
3510 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003511 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003512 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3513 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003514 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003515 if (needs_write_barrier) {
3516 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003517 Register temp = locations->GetTemp(0).AsRegister<Register>();
3518 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003519 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003520 }
3521 } else {
3522 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003523 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3524 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003525 instruction->GetDexPc(),
3526 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003527 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003528 break;
3529 }
3530
3531 case Primitive::kPrimLong: {
3532 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003533 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003534 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003535 size_t offset =
3536 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003537 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003538 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003539 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003540 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003541 }
3542 break;
3543 }
3544
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003545 case Primitive::kPrimFloat: {
3546 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3547 Location value = locations->InAt(2);
3548 DCHECK(value.IsFpuRegister());
3549 if (index.IsConstant()) {
3550 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3551 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3552 } else {
3553 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3554 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3555 }
3556 break;
3557 }
3558
3559 case Primitive::kPrimDouble: {
3560 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3561 Location value = locations->InAt(2);
3562 DCHECK(value.IsFpuRegisterPair());
3563 if (index.IsConstant()) {
3564 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3565 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3566 } else {
3567 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3568 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3569 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003570
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003571 break;
3572 }
3573
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003574 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003575 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003576 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003577 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003578
3579 // Ints and objects are handled in the switch.
3580 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3581 codegen_->MaybeRecordImplicitNullCheck(instruction);
3582 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003583}
3584
3585void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003586 LocationSummary* locations =
3587 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003588 locations->SetInAt(0, Location::RequiresRegister());
3589 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003590}
3591
3592void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3593 LocationSummary* locations = instruction->GetLocations();
3594 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003595 Register obj = locations->InAt(0).AsRegister<Register>();
3596 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003597 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003598 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003599}
3600
3601void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003602 LocationSummary* locations =
3603 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003604 locations->SetInAt(0, Location::RequiresRegister());
3605 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003606 if (instruction->HasUses()) {
3607 locations->SetOut(Location::SameAsFirstInput());
3608 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003609}
3610
3611void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3612 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003613 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003614 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003615 codegen_->AddSlowPath(slow_path);
3616
Roland Levillain271ab9c2014-11-27 15:23:57 +00003617 Register index = locations->InAt(0).AsRegister<Register>();
3618 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003619
3620 __ cmp(index, ShifterOperand(length));
3621 __ b(slow_path->GetEntryLabel(), CS);
3622}
3623
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003624void CodeGeneratorARM::MarkGCCard(Register temp,
3625 Register card,
3626 Register object,
3627 Register value,
3628 bool can_be_null) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00003629 NearLabel is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003630 if (can_be_null) {
3631 __ CompareAndBranchIfZero(value, &is_null);
3632 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003633 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3634 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3635 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003636 if (can_be_null) {
3637 __ Bind(&is_null);
3638 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003639}
3640
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003641void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3642 temp->SetLocations(nullptr);
3643}
3644
3645void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3646 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003647 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003648}
3649
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003650void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003651 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003652 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003653}
3654
3655void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003656 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3657}
3658
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003659void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3660 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3661}
3662
3663void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003664 HBasicBlock* block = instruction->GetBlock();
3665 if (block->GetLoopInformation() != nullptr) {
3666 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3667 // The back edge will generate the suspend check.
3668 return;
3669 }
3670 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3671 // The goto will generate the suspend check.
3672 return;
3673 }
3674 GenerateSuspendCheck(instruction, nullptr);
3675}
3676
3677void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3678 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003679 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003680 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3681 if (slow_path == nullptr) {
3682 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3683 instruction->SetSlowPath(slow_path);
3684 codegen_->AddSlowPath(slow_path);
3685 if (successor != nullptr) {
3686 DCHECK(successor->IsLoopHeader());
3687 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3688 }
3689 } else {
3690 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3691 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003692
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003693 __ LoadFromOffset(
3694 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3695 __ cmp(IP, ShifterOperand(0));
3696 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003697 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003698 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003699 __ Bind(slow_path->GetReturnLabel());
3700 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003701 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003702 __ b(slow_path->GetEntryLabel());
3703 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003704}
3705
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003706ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3707 return codegen_->GetAssembler();
3708}
3709
3710void ParallelMoveResolverARM::EmitMove(size_t index) {
3711 MoveOperands* move = moves_.Get(index);
3712 Location source = move->GetSource();
3713 Location destination = move->GetDestination();
3714
3715 if (source.IsRegister()) {
3716 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003717 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003718 } else {
3719 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003720 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003721 SP, destination.GetStackIndex());
3722 }
3723 } else if (source.IsStackSlot()) {
3724 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003725 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003726 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003727 } else if (destination.IsFpuRegister()) {
3728 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003729 } else {
3730 DCHECK(destination.IsStackSlot());
3731 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3732 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3733 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003734 } else if (source.IsFpuRegister()) {
3735 if (destination.IsFpuRegister()) {
3736 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003737 } else {
3738 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003739 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3740 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003741 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003742 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003743 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3744 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003745 } else if (destination.IsRegisterPair()) {
3746 DCHECK(ExpectedPairLayout(destination));
3747 __ LoadFromOffset(
3748 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3749 } else {
3750 DCHECK(destination.IsFpuRegisterPair()) << destination;
3751 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3752 SP,
3753 source.GetStackIndex());
3754 }
3755 } else if (source.IsRegisterPair()) {
3756 if (destination.IsRegisterPair()) {
3757 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3758 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3759 } else {
3760 DCHECK(destination.IsDoubleStackSlot()) << destination;
3761 DCHECK(ExpectedPairLayout(source));
3762 __ StoreToOffset(
3763 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3764 }
3765 } else if (source.IsFpuRegisterPair()) {
3766 if (destination.IsFpuRegisterPair()) {
3767 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3768 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3769 } else {
3770 DCHECK(destination.IsDoubleStackSlot()) << destination;
3771 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3772 SP,
3773 destination.GetStackIndex());
3774 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003775 } else {
3776 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003777 HConstant* constant = source.GetConstant();
3778 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3779 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003780 if (destination.IsRegister()) {
3781 __ LoadImmediate(destination.AsRegister<Register>(), value);
3782 } else {
3783 DCHECK(destination.IsStackSlot());
3784 __ LoadImmediate(IP, value);
3785 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3786 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003787 } else if (constant->IsLongConstant()) {
3788 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003789 if (destination.IsRegisterPair()) {
3790 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3791 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003792 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003793 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003794 __ LoadImmediate(IP, Low32Bits(value));
3795 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3796 __ LoadImmediate(IP, High32Bits(value));
3797 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3798 }
3799 } else if (constant->IsDoubleConstant()) {
3800 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003801 if (destination.IsFpuRegisterPair()) {
3802 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003803 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003804 DCHECK(destination.IsDoubleStackSlot()) << destination;
3805 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003806 __ LoadImmediate(IP, Low32Bits(int_value));
3807 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3808 __ LoadImmediate(IP, High32Bits(int_value));
3809 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3810 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003811 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003812 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003813 float value = constant->AsFloatConstant()->GetValue();
3814 if (destination.IsFpuRegister()) {
3815 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3816 } else {
3817 DCHECK(destination.IsStackSlot());
3818 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3819 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3820 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003821 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003822 }
3823}
3824
3825void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3826 __ Mov(IP, reg);
3827 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3828 __ StoreToOffset(kStoreWord, IP, SP, mem);
3829}
3830
3831void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3832 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3833 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3834 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3835 SP, mem1 + stack_offset);
3836 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3837 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3838 SP, mem2 + stack_offset);
3839 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3840}
3841
3842void ParallelMoveResolverARM::EmitSwap(size_t index) {
3843 MoveOperands* move = moves_.Get(index);
3844 Location source = move->GetSource();
3845 Location destination = move->GetDestination();
3846
3847 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003848 DCHECK_NE(source.AsRegister<Register>(), IP);
3849 DCHECK_NE(destination.AsRegister<Register>(), IP);
3850 __ Mov(IP, source.AsRegister<Register>());
3851 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3852 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003853 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003854 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003855 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003856 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003857 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3858 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003859 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003860 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003861 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003862 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003863 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003864 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003865 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003866 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003867 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3868 destination.AsRegisterPairHigh<Register>(),
3869 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003870 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003871 Register low_reg = source.IsRegisterPair()
3872 ? source.AsRegisterPairLow<Register>()
3873 : destination.AsRegisterPairLow<Register>();
3874 int mem = source.IsRegisterPair()
3875 ? destination.GetStackIndex()
3876 : source.GetStackIndex();
3877 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003878 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003879 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003880 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003881 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003882 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3883 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003884 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003885 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003886 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003887 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3888 DRegister reg = source.IsFpuRegisterPair()
3889 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3890 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3891 int mem = source.IsFpuRegisterPair()
3892 ? destination.GetStackIndex()
3893 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003894 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003895 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003896 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003897 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3898 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3899 : destination.AsFpuRegister<SRegister>();
3900 int mem = source.IsFpuRegister()
3901 ? destination.GetStackIndex()
3902 : source.GetStackIndex();
3903
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003904 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003905 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003906 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003907 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003908 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3909 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003910 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003911 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003912 }
3913}
3914
3915void ParallelMoveResolverARM::SpillScratch(int reg) {
3916 __ Push(static_cast<Register>(reg));
3917}
3918
3919void ParallelMoveResolverARM::RestoreScratch(int reg) {
3920 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003921}
3922
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003923void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003924 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3925 ? LocationSummary::kCallOnSlowPath
3926 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003927 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003928 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003929 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003930 locations->SetOut(Location::RequiresRegister());
3931}
3932
3933void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003934 LocationSummary* locations = cls->GetLocations();
3935 Register out = locations->Out().AsRegister<Register>();
3936 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003937 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003938 DCHECK(!cls->CanCallRuntime());
3939 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003940 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07003941 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003942 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003943 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003944 __ LoadFromOffset(kLoadWord,
3945 out,
3946 current_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -07003947 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003948 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003949
3950 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3951 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3952 codegen_->AddSlowPath(slow_path);
3953 __ cmp(out, ShifterOperand(0));
3954 __ b(slow_path->GetEntryLabel(), EQ);
3955 if (cls->MustGenerateClinitCheck()) {
3956 GenerateClassInitializationCheck(slow_path, out);
3957 } else {
3958 __ Bind(slow_path->GetExitLabel());
3959 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003960 }
3961}
3962
3963void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3964 LocationSummary* locations =
3965 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3966 locations->SetInAt(0, Location::RequiresRegister());
3967 if (check->HasUses()) {
3968 locations->SetOut(Location::SameAsFirstInput());
3969 }
3970}
3971
3972void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003973 // We assume the class is not null.
3974 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3975 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003976 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003977 GenerateClassInitializationCheck(slow_path,
3978 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003979}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003980
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003981void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3982 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003983 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3984 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3985 __ b(slow_path->GetEntryLabel(), LT);
3986 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3987 // properly. Therefore, we do a memory fence.
3988 __ dmb(ISH);
3989 __ Bind(slow_path->GetExitLabel());
3990}
3991
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003992void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3993 LocationSummary* locations =
3994 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01003995 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003996 locations->SetOut(Location::RequiresRegister());
3997}
3998
3999void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
4000 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
4001 codegen_->AddSlowPath(slow_path);
4002
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004003 LocationSummary* locations = load->GetLocations();
4004 Register out = locations->Out().AsRegister<Register>();
4005 Register current_method = locations->InAt(0).AsRegister<Register>();
4006 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004007 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004008 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004009 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
4010 __ cmp(out, ShifterOperand(0));
4011 __ b(slow_path->GetEntryLabel(), EQ);
4012 __ Bind(slow_path->GetExitLabel());
4013}
4014
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004015void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4016 LocationSummary* locations =
4017 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4018 locations->SetOut(Location::RequiresRegister());
4019}
4020
4021void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004022 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004023 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4024 __ LoadFromOffset(kLoadWord, out, TR, offset);
4025 __ LoadImmediate(IP, 0);
4026 __ StoreToOffset(kStoreWord, IP, TR, offset);
4027}
4028
4029void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4030 LocationSummary* locations =
4031 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4032 InvokeRuntimeCallingConvention calling_convention;
4033 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4034}
4035
4036void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4037 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004038 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004039}
4040
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004041void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004042 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4043 ? LocationSummary::kNoCall
4044 : LocationSummary::kCallOnSlowPath;
4045 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4046 locations->SetInAt(0, Location::RequiresRegister());
4047 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004048 // The out register is used as a temporary, so it overlaps with the inputs.
4049 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004050}
4051
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004052void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004053 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004054 Register obj = locations->InAt(0).AsRegister<Register>();
4055 Register cls = locations->InAt(1).AsRegister<Register>();
4056 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004057 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004058 NearLabel done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004059 SlowPathCodeARM* slow_path = nullptr;
4060
4061 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004062 // avoid null check if we know obj is not null.
4063 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004064 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004065 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004066 // Compare the class of `obj` with `cls`.
4067 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
4068 __ cmp(out, ShifterOperand(cls));
4069 if (instruction->IsClassFinal()) {
4070 // Classes must be equal for the instanceof to succeed.
4071 __ b(&zero, NE);
4072 __ LoadImmediate(out, 1);
4073 __ b(&done);
4074 } else {
4075 // If the classes are not equal, we go into a slow path.
4076 DCHECK(locations->OnlyCallsOnSlowPath());
4077 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004078 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004079 codegen_->AddSlowPath(slow_path);
4080 __ b(slow_path->GetEntryLabel(), NE);
4081 __ LoadImmediate(out, 1);
4082 __ b(&done);
4083 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004084
4085 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4086 __ Bind(&zero);
4087 __ LoadImmediate(out, 0);
4088 }
4089
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004090 if (slow_path != nullptr) {
4091 __ Bind(slow_path->GetExitLabel());
4092 }
4093 __ Bind(&done);
4094}
4095
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004096void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4097 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4098 instruction, LocationSummary::kCallOnSlowPath);
4099 locations->SetInAt(0, Location::RequiresRegister());
4100 locations->SetInAt(1, Location::RequiresRegister());
4101 locations->AddTemp(Location::RequiresRegister());
4102}
4103
4104void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4105 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004106 Register obj = locations->InAt(0).AsRegister<Register>();
4107 Register cls = locations->InAt(1).AsRegister<Register>();
4108 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004109 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4110
4111 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4112 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
4113 codegen_->AddSlowPath(slow_path);
4114
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004115 NearLabel done;
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004116 // avoid null check if we know obj is not null.
4117 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004118 __ CompareAndBranchIfZero(obj, &done);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004119 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004120 // Compare the class of `obj` with `cls`.
4121 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
4122 __ cmp(temp, ShifterOperand(cls));
4123 __ b(slow_path->GetEntryLabel(), NE);
4124 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004125 if (instruction->MustDoNullCheck()) {
4126 __ Bind(&done);
4127 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004128}
4129
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004130void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4131 LocationSummary* locations =
4132 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4133 InvokeRuntimeCallingConvention calling_convention;
4134 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4135}
4136
4137void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4138 codegen_->InvokeRuntime(instruction->IsEnter()
4139 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4140 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004141 instruction->GetDexPc(),
4142 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004143}
4144
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004145void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4146void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4147void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4148
4149void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4150 LocationSummary* locations =
4151 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4152 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4153 || instruction->GetResultType() == Primitive::kPrimLong);
4154 locations->SetInAt(0, Location::RequiresRegister());
4155 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004156 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004157}
4158
4159void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4160 HandleBitwiseOperation(instruction);
4161}
4162
4163void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4164 HandleBitwiseOperation(instruction);
4165}
4166
4167void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4168 HandleBitwiseOperation(instruction);
4169}
4170
4171void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4172 LocationSummary* locations = instruction->GetLocations();
4173
4174 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004175 Register first = locations->InAt(0).AsRegister<Register>();
4176 Register second = locations->InAt(1).AsRegister<Register>();
4177 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004178 if (instruction->IsAnd()) {
4179 __ and_(out, first, ShifterOperand(second));
4180 } else if (instruction->IsOr()) {
4181 __ orr(out, first, ShifterOperand(second));
4182 } else {
4183 DCHECK(instruction->IsXor());
4184 __ eor(out, first, ShifterOperand(second));
4185 }
4186 } else {
4187 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4188 Location first = locations->InAt(0);
4189 Location second = locations->InAt(1);
4190 Location out = locations->Out();
4191 if (instruction->IsAnd()) {
4192 __ and_(out.AsRegisterPairLow<Register>(),
4193 first.AsRegisterPairLow<Register>(),
4194 ShifterOperand(second.AsRegisterPairLow<Register>()));
4195 __ and_(out.AsRegisterPairHigh<Register>(),
4196 first.AsRegisterPairHigh<Register>(),
4197 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4198 } else if (instruction->IsOr()) {
4199 __ orr(out.AsRegisterPairLow<Register>(),
4200 first.AsRegisterPairLow<Register>(),
4201 ShifterOperand(second.AsRegisterPairLow<Register>()));
4202 __ orr(out.AsRegisterPairHigh<Register>(),
4203 first.AsRegisterPairHigh<Register>(),
4204 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4205 } else {
4206 DCHECK(instruction->IsXor());
4207 __ eor(out.AsRegisterPairLow<Register>(),
4208 first.AsRegisterPairLow<Register>(),
4209 ShifterOperand(second.AsRegisterPairLow<Register>()));
4210 __ eor(out.AsRegisterPairHigh<Register>(),
4211 first.AsRegisterPairHigh<Register>(),
4212 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4213 }
4214 }
4215}
4216
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004217void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
4218 DCHECK_EQ(temp, kArtMethodRegister);
4219
4220 // TODO: Implement all kinds of calls:
4221 // 1) boot -> boot
4222 // 2) app -> boot
4223 // 3) app -> app
4224 //
4225 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4226
Jeff Hao848f70a2014-01-15 13:49:50 -08004227 if (invoke->IsStringInit()) {
4228 // temp = thread->string_init_entrypoint
4229 __ LoadFromOffset(kLoadWord, temp, TR, invoke->GetStringInitOffset());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004230 // LR = temp[offset_of_quick_compiled_code]
4231 __ LoadFromOffset(kLoadWord, LR, temp,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004232 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004233 kArmWordSize).Int32Value());
4234 // LR()
4235 __ blx(LR);
4236 } else {
Jeff Hao848f70a2014-01-15 13:49:50 -08004237 // temp = method;
4238 LoadCurrentMethod(temp);
4239 if (!invoke->IsRecursive()) {
4240 // temp = temp->dex_cache_resolved_methods_;
4241 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004242 kLoadWord, temp, temp, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Jeff Hao848f70a2014-01-15 13:49:50 -08004243 // temp = temp[index_in_cache]
4244 __ LoadFromOffset(
4245 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4246 // LR = temp[offset_of_quick_compiled_code]
Mathieu Chartiere401d142015-04-22 13:56:20 -07004247 __ LoadFromOffset(kLoadWord, LR, temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4248 kArmWordSize).Int32Value());
Jeff Hao848f70a2014-01-15 13:49:50 -08004249 // LR()
4250 __ blx(LR);
4251 } else {
4252 __ bl(GetFrameEntryLabel());
4253 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004254 }
4255
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004256 DCHECK(!IsLeafMethod());
4257}
4258
Calin Juravleb1498f62015-02-16 13:13:29 +00004259void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4260 // Nothing to do, this should be removed during prepare for register allocator.
4261 UNUSED(instruction);
4262 LOG(FATAL) << "Unreachable";
4263}
4264
4265void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4266 // Nothing to do, this should be removed during prepare for register allocator.
4267 UNUSED(instruction);
4268 LOG(FATAL) << "Unreachable";
4269}
4270
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004271} // namespace arm
4272} // namespace art