blob: 1c68654522f6c4d4484e26948818cd24a05e5513 [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
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100684Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) {
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 Geoffray01bc96d2014-04-11 17:43:50 +0100713void CodeGeneratorARM::Move32(Location destination, Location source) {
714 if (source.Equals(destination)) {
715 return;
716 }
717 if (destination.IsRegister()) {
718 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000719 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100720 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000721 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100722 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000723 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100724 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100725 } else if (destination.IsFpuRegister()) {
726 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000727 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100728 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000729 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100730 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000731 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100732 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100733 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000734 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100735 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000736 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100737 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000738 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100739 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000740 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100741 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
742 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100743 }
744 }
745}
746
747void CodeGeneratorARM::Move64(Location destination, Location source) {
748 if (source.Equals(destination)) {
749 return;
750 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100751 if (destination.IsRegisterPair()) {
752 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000753 EmitParallelMoves(
754 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
755 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100756 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000757 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100758 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
759 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100760 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000761 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100762 } else {
763 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000764 DCHECK(ExpectedPairLayout(destination));
765 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
766 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100767 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000768 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100769 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000770 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
771 SP,
772 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100773 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000774 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100775 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100776 } else {
777 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100778 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000779 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100780 if (source.AsRegisterPairLow<Register>() == R1) {
781 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100782 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
783 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100784 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100785 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100786 SP, destination.GetStackIndex());
787 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000788 } else if (source.IsFpuRegisterPair()) {
789 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
790 SP,
791 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100792 } else {
793 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000794 EmitParallelMoves(
795 Location::StackSlot(source.GetStackIndex()),
796 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100797 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000798 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100799 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
800 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100801 }
802 }
803}
804
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100805void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100806 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100807 if (instruction->IsCurrentMethod()) {
808 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
809 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100810 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100811 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000812 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000813 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
814 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000815 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000816 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000817 } else {
818 DCHECK(location.IsStackSlot());
819 __ LoadImmediate(IP, value);
820 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
821 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000822 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000823 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000824 int64_t value = const_to_move->AsLongConstant()->GetValue();
825 if (location.IsRegisterPair()) {
826 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
827 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
828 } else {
829 DCHECK(location.IsDoubleStackSlot());
830 __ LoadImmediate(IP, Low32Bits(value));
831 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
832 __ LoadImmediate(IP, High32Bits(value));
833 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
834 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100835 }
Roland Levillain476df552014-10-09 17:51:36 +0100836 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100837 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
838 switch (instruction->GetType()) {
839 case Primitive::kPrimBoolean:
840 case Primitive::kPrimByte:
841 case Primitive::kPrimChar:
842 case Primitive::kPrimShort:
843 case Primitive::kPrimInt:
844 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100845 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100846 Move32(location, Location::StackSlot(stack_slot));
847 break;
848
849 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100850 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100851 Move64(location, Location::DoubleStackSlot(stack_slot));
852 break;
853
854 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100855 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100856 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000857 } else if (instruction->IsTemporary()) {
858 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000859 if (temp_location.IsStackSlot()) {
860 Move32(location, temp_location);
861 } else {
862 DCHECK(temp_location.IsDoubleStackSlot());
863 Move64(location, temp_location);
864 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000865 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100866 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100867 switch (instruction->GetType()) {
868 case Primitive::kPrimBoolean:
869 case Primitive::kPrimByte:
870 case Primitive::kPrimChar:
871 case Primitive::kPrimShort:
872 case Primitive::kPrimNot:
873 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100874 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100875 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100876 break;
877
878 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100879 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100880 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100881 break;
882
883 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100884 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100885 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000886 }
887}
888
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100889void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
890 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000891 uint32_t dex_pc,
892 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100893 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
894 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000895 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100896 DCHECK(instruction->IsSuspendCheck()
897 || instruction->IsBoundsCheck()
898 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000899 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000900 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100901 || !IsLeafMethod());
902}
903
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000904void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000905 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000906}
907
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000908void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000909 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100910 DCHECK(!successor->IsExitBlock());
911
912 HBasicBlock* block = got->GetBlock();
913 HInstruction* previous = got->GetPrevious();
914
915 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000916 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100917 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
918 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
919 return;
920 }
921
922 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
923 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
924 }
925 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000926 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000927 }
928}
929
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000930void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000931 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000932}
933
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000934void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700935 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000936}
937
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700938void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
939 Label* true_target,
940 Label* false_target,
941 Label* always_true_target) {
942 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100943 if (cond->IsIntConstant()) {
944 // Constant condition, statically compared against 1.
945 int32_t cond_value = cond->AsIntConstant()->GetValue();
946 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700947 if (always_true_target != nullptr) {
948 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100949 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100950 return;
951 } else {
952 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100953 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100954 } else {
955 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
956 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700957 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
958 __ cmp(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100959 ShifterOperand(0));
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700960 __ b(true_target, NE);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100961 } else {
962 // Condition has not been materialized, use its inputs as the
963 // comparison and its condition as the branch condition.
964 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000965 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000966 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100967 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000968 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100969 } else {
970 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000971 HConstant* constant = locations->InAt(1).GetConstant();
972 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100973 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000974 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
975 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100976 } else {
977 Register temp = IP;
978 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000979 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100980 }
981 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700982 __ b(true_target, ARMCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100983 }
Dave Allison20dfc792014-06-16 20:44:29 -0700984 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700985 if (false_target != nullptr) {
986 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000987 }
988}
989
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700990void LocationsBuilderARM::VisitIf(HIf* if_instr) {
991 LocationSummary* locations =
992 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
993 HInstruction* cond = if_instr->InputAt(0);
994 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
995 locations->SetInAt(0, Location::RequiresRegister());
996 }
997}
998
999void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1000 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1001 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1002 Label* always_true_target = true_target;
1003 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1004 if_instr->IfTrueSuccessor())) {
1005 always_true_target = nullptr;
1006 }
1007 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1008 if_instr->IfFalseSuccessor())) {
1009 false_target = nullptr;
1010 }
1011 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1012}
1013
1014void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1015 LocationSummary* locations = new (GetGraph()->GetArena())
1016 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1017 HInstruction* cond = deoptimize->InputAt(0);
1018 DCHECK(cond->IsCondition());
1019 if (cond->AsCondition()->NeedsMaterialization()) {
1020 locations->SetInAt(0, Location::RequiresRegister());
1021 }
1022}
1023
1024void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1025 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1026 DeoptimizationSlowPathARM(deoptimize);
1027 codegen_->AddSlowPath(slow_path);
1028 Label* slow_path_entry = slow_path->GetEntryLabel();
1029 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1030}
Dave Allison20dfc792014-06-16 20:44:29 -07001031
Roland Levillain0d37cd02015-05-27 16:39:19 +01001032void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001033 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001034 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001035 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain0d37cd02015-05-27 16:39:19 +01001036 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1037 if (cond->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001038 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001039 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001040}
1041
Roland Levillain0d37cd02015-05-27 16:39:19 +01001042void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
1043 if (!cond->NeedsMaterialization()) return;
1044 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001045 Register left = locations->InAt(0).AsRegister<Register>();
1046
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001047 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001048 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001049 } else {
1050 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -08001051 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001052 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001053 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1054 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001055 } else {
1056 Register temp = IP;
1057 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001058 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001059 }
Dave Allison20dfc792014-06-16 20:44:29 -07001060 }
Roland Levillain0d37cd02015-05-27 16:39:19 +01001061 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001062 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001063 ARMCondition(cond->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001064 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001065 ARMOppositeCondition(cond->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001066}
1067
1068void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1069 VisitCondition(comp);
1070}
1071
1072void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1073 VisitCondition(comp);
1074}
1075
1076void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1077 VisitCondition(comp);
1078}
1079
1080void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1081 VisitCondition(comp);
1082}
1083
1084void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1085 VisitCondition(comp);
1086}
1087
1088void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1089 VisitCondition(comp);
1090}
1091
1092void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1093 VisitCondition(comp);
1094}
1095
1096void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1097 VisitCondition(comp);
1098}
1099
1100void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1101 VisitCondition(comp);
1102}
1103
1104void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1105 VisitCondition(comp);
1106}
1107
1108void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1109 VisitCondition(comp);
1110}
1111
1112void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1113 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001114}
1115
1116void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001117 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001118}
1119
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001120void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1121 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001122}
1123
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001124void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001125 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001126}
1127
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001128void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001129 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001130 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001131}
1132
1133void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001134 LocationSummary* locations =
1135 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001136 switch (store->InputAt(1)->GetType()) {
1137 case Primitive::kPrimBoolean:
1138 case Primitive::kPrimByte:
1139 case Primitive::kPrimChar:
1140 case Primitive::kPrimShort:
1141 case Primitive::kPrimInt:
1142 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001143 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001144 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1145 break;
1146
1147 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001148 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001149 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1150 break;
1151
1152 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001153 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001154 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001155}
1156
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001157void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001158 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001159}
1160
1161void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001162 LocationSummary* locations =
1163 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001164 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001165}
1166
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001167void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001168 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001169 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001170}
1171
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001172void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1173 LocationSummary* locations =
1174 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1175 locations->SetOut(Location::ConstantLocation(constant));
1176}
1177
1178void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1179 // Will be generated at use site.
1180 UNUSED(constant);
1181}
1182
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001183void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001184 LocationSummary* locations =
1185 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001186 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001187}
1188
1189void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1190 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001191 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001192}
1193
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001194void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1195 LocationSummary* locations =
1196 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1197 locations->SetOut(Location::ConstantLocation(constant));
1198}
1199
1200void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1201 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001202 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001203}
1204
1205void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1206 LocationSummary* locations =
1207 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1208 locations->SetOut(Location::ConstantLocation(constant));
1209}
1210
1211void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1212 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001213 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001214}
1215
Calin Juravle27df7582015-04-17 19:12:31 +01001216void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1217 memory_barrier->SetLocations(nullptr);
1218}
1219
1220void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1221 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1222}
1223
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001224void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001225 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001226}
1227
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001228void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001229 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001230 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001231}
1232
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001233void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001234 LocationSummary* locations =
1235 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001236 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001237}
1238
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001239void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001240 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001241 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001242}
1243
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001244void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001245 // When we do not run baseline, explicit clinit checks triggered by static
1246 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1247 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001248
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001249 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1250 codegen_->GetInstructionSetFeatures());
1251 if (intrinsic.TryDispatch(invoke)) {
1252 return;
1253 }
1254
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001255 HandleInvoke(invoke);
1256}
1257
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001258void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001259 DCHECK(RequiresCurrentMethod());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001260 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001261}
1262
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001263static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1264 if (invoke->GetLocations()->Intrinsified()) {
1265 IntrinsicCodeGeneratorARM intrinsic(codegen);
1266 intrinsic.Dispatch(invoke);
1267 return true;
1268 }
1269 return false;
1270}
1271
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001272void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001273 // When we do not run baseline, explicit clinit checks triggered by static
1274 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1275 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001276
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001277 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1278 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001279 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001280
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001281 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
1282
1283 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001284 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001285}
1286
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001287void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001288 LocationSummary* locations =
1289 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01001290 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001291
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001292 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Roland Levillain3e3d7332015-04-28 11:00:54 +01001293 for (size_t i = 0; i < invoke->GetNumberOfArguments(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001294 HInstruction* input = invoke->InputAt(i);
1295 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1296 }
1297
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001298 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001299}
1300
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001301void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001302 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1303 codegen_->GetInstructionSetFeatures());
1304 if (intrinsic.TryDispatch(invoke)) {
1305 return;
1306 }
1307
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001308 HandleInvoke(invoke);
1309}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001310
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001311void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001312 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1313 return;
1314 }
1315
Roland Levillain271ab9c2014-11-27 15:23:57 +00001316 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001317 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
1318 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001319 LocationSummary* locations = invoke->GetLocations();
1320 Location receiver = locations->InAt(0);
1321 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1322 // temp = object->GetClass();
1323 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001324 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1325 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001326 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001327 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001328 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001329 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001330 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001331 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001332 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001333 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001334 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001335 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001336 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001337 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001338 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001339 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001340}
1341
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001342void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1343 HandleInvoke(invoke);
1344 // Add the hidden argument.
1345 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1346}
1347
1348void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1349 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001350 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001351 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1352 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001353 LocationSummary* locations = invoke->GetLocations();
1354 Location receiver = locations->InAt(0);
1355 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1356
1357 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001358 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1359 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001360
1361 // temp = object->GetClass();
1362 if (receiver.IsStackSlot()) {
1363 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1364 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1365 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001366 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001367 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001368 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001369 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001370 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001371 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001372 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1373 // LR = temp->GetEntryPoint();
1374 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1375 // LR();
1376 __ blx(LR);
1377 DCHECK(!codegen_->IsLeafMethod());
1378 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1379}
1380
Roland Levillain88cb1752014-10-20 16:36:47 +01001381void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1382 LocationSummary* locations =
1383 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1384 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001385 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001386 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001387 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1388 break;
1389 }
1390 case Primitive::kPrimLong: {
1391 locations->SetInAt(0, Location::RequiresRegister());
1392 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001393 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001394 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001395
Roland Levillain88cb1752014-10-20 16:36:47 +01001396 case Primitive::kPrimFloat:
1397 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001398 locations->SetInAt(0, Location::RequiresFpuRegister());
1399 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001400 break;
1401
1402 default:
1403 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1404 }
1405}
1406
1407void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1408 LocationSummary* locations = neg->GetLocations();
1409 Location out = locations->Out();
1410 Location in = locations->InAt(0);
1411 switch (neg->GetResultType()) {
1412 case Primitive::kPrimInt:
1413 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001414 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001415 break;
1416
1417 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001418 DCHECK(in.IsRegisterPair());
1419 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1420 __ rsbs(out.AsRegisterPairLow<Register>(),
1421 in.AsRegisterPairLow<Register>(),
1422 ShifterOperand(0));
1423 // We cannot emit an RSC (Reverse Subtract with Carry)
1424 // instruction here, as it does not exist in the Thumb-2
1425 // instruction set. We use the following approach
1426 // using SBC and SUB instead.
1427 //
1428 // out.hi = -C
1429 __ sbc(out.AsRegisterPairHigh<Register>(),
1430 out.AsRegisterPairHigh<Register>(),
1431 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1432 // out.hi = out.hi - in.hi
1433 __ sub(out.AsRegisterPairHigh<Register>(),
1434 out.AsRegisterPairHigh<Register>(),
1435 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1436 break;
1437
Roland Levillain88cb1752014-10-20 16:36:47 +01001438 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001439 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001440 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001441 break;
1442
Roland Levillain88cb1752014-10-20 16:36:47 +01001443 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001444 DCHECK(in.IsFpuRegisterPair());
1445 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1446 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001447 break;
1448
1449 default:
1450 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1451 }
1452}
1453
Roland Levillaindff1f282014-11-05 14:15:05 +00001454void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001455 Primitive::Type result_type = conversion->GetResultType();
1456 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001457 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001458
Roland Levillain5b3ee562015-04-14 16:02:41 +01001459 // The float-to-long, double-to-long and long-to-float type conversions
1460 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001461 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001462 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1463 && result_type == Primitive::kPrimLong)
1464 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001465 ? LocationSummary::kCall
1466 : LocationSummary::kNoCall;
1467 LocationSummary* locations =
1468 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1469
David Brazdilb2bd1c52015-03-25 11:17:37 +00001470 // The Java language does not allow treating boolean as an integral type but
1471 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001472
Roland Levillaindff1f282014-11-05 14:15:05 +00001473 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001474 case Primitive::kPrimByte:
1475 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001476 case Primitive::kPrimBoolean:
1477 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001478 case Primitive::kPrimShort:
1479 case Primitive::kPrimInt:
1480 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001481 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001482 locations->SetInAt(0, Location::RequiresRegister());
1483 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1484 break;
1485
1486 default:
1487 LOG(FATAL) << "Unexpected type conversion from " << input_type
1488 << " to " << result_type;
1489 }
1490 break;
1491
Roland Levillain01a8d712014-11-14 16:27:39 +00001492 case Primitive::kPrimShort:
1493 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001494 case Primitive::kPrimBoolean:
1495 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001496 case Primitive::kPrimByte:
1497 case Primitive::kPrimInt:
1498 case Primitive::kPrimChar:
1499 // Processing a Dex `int-to-short' instruction.
1500 locations->SetInAt(0, Location::RequiresRegister());
1501 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1502 break;
1503
1504 default:
1505 LOG(FATAL) << "Unexpected type conversion from " << input_type
1506 << " to " << result_type;
1507 }
1508 break;
1509
Roland Levillain946e1432014-11-11 17:35:19 +00001510 case Primitive::kPrimInt:
1511 switch (input_type) {
1512 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001513 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001514 locations->SetInAt(0, Location::Any());
1515 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1516 break;
1517
1518 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001519 // Processing a Dex `float-to-int' instruction.
1520 locations->SetInAt(0, Location::RequiresFpuRegister());
1521 locations->SetOut(Location::RequiresRegister());
1522 locations->AddTemp(Location::RequiresFpuRegister());
1523 break;
1524
Roland Levillain946e1432014-11-11 17:35:19 +00001525 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001526 // Processing a Dex `double-to-int' instruction.
1527 locations->SetInAt(0, Location::RequiresFpuRegister());
1528 locations->SetOut(Location::RequiresRegister());
1529 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001530 break;
1531
1532 default:
1533 LOG(FATAL) << "Unexpected type conversion from " << input_type
1534 << " to " << result_type;
1535 }
1536 break;
1537
Roland Levillaindff1f282014-11-05 14:15:05 +00001538 case Primitive::kPrimLong:
1539 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001540 case Primitive::kPrimBoolean:
1541 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001542 case Primitive::kPrimByte:
1543 case Primitive::kPrimShort:
1544 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001545 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001546 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001547 locations->SetInAt(0, Location::RequiresRegister());
1548 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1549 break;
1550
Roland Levillain624279f2014-12-04 11:54:28 +00001551 case Primitive::kPrimFloat: {
1552 // Processing a Dex `float-to-long' instruction.
1553 InvokeRuntimeCallingConvention calling_convention;
1554 locations->SetInAt(0, Location::FpuRegisterLocation(
1555 calling_convention.GetFpuRegisterAt(0)));
1556 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1557 break;
1558 }
1559
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001560 case Primitive::kPrimDouble: {
1561 // Processing a Dex `double-to-long' instruction.
1562 InvokeRuntimeCallingConvention calling_convention;
1563 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1564 calling_convention.GetFpuRegisterAt(0),
1565 calling_convention.GetFpuRegisterAt(1)));
1566 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001567 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001568 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001569
1570 default:
1571 LOG(FATAL) << "Unexpected type conversion from " << input_type
1572 << " to " << result_type;
1573 }
1574 break;
1575
Roland Levillain981e4542014-11-14 11:47:14 +00001576 case Primitive::kPrimChar:
1577 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001578 case Primitive::kPrimBoolean:
1579 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001580 case Primitive::kPrimByte:
1581 case Primitive::kPrimShort:
1582 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001583 // Processing a Dex `int-to-char' instruction.
1584 locations->SetInAt(0, Location::RequiresRegister());
1585 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1586 break;
1587
1588 default:
1589 LOG(FATAL) << "Unexpected type conversion from " << input_type
1590 << " to " << result_type;
1591 }
1592 break;
1593
Roland Levillaindff1f282014-11-05 14:15:05 +00001594 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001595 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001596 case Primitive::kPrimBoolean:
1597 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001598 case Primitive::kPrimByte:
1599 case Primitive::kPrimShort:
1600 case Primitive::kPrimInt:
1601 case Primitive::kPrimChar:
1602 // Processing a Dex `int-to-float' instruction.
1603 locations->SetInAt(0, Location::RequiresRegister());
1604 locations->SetOut(Location::RequiresFpuRegister());
1605 break;
1606
Roland Levillain5b3ee562015-04-14 16:02:41 +01001607 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001608 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001609 InvokeRuntimeCallingConvention calling_convention;
1610 locations->SetInAt(0, Location::RegisterPairLocation(
1611 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1612 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001613 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001614 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001615
Roland Levillaincff13742014-11-17 14:32:17 +00001616 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001617 // Processing a Dex `double-to-float' instruction.
1618 locations->SetInAt(0, Location::RequiresFpuRegister());
1619 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001620 break;
1621
1622 default:
1623 LOG(FATAL) << "Unexpected type conversion from " << input_type
1624 << " to " << result_type;
1625 };
1626 break;
1627
Roland Levillaindff1f282014-11-05 14:15:05 +00001628 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001629 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001630 case Primitive::kPrimBoolean:
1631 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001632 case Primitive::kPrimByte:
1633 case Primitive::kPrimShort:
1634 case Primitive::kPrimInt:
1635 case Primitive::kPrimChar:
1636 // Processing a Dex `int-to-double' instruction.
1637 locations->SetInAt(0, Location::RequiresRegister());
1638 locations->SetOut(Location::RequiresFpuRegister());
1639 break;
1640
1641 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001642 // Processing a Dex `long-to-double' instruction.
1643 locations->SetInAt(0, Location::RequiresRegister());
1644 locations->SetOut(Location::RequiresFpuRegister());
1645 locations->AddTemp(Location::RequiresRegister());
1646 locations->AddTemp(Location::RequiresRegister());
1647 locations->AddTemp(Location::RequiresFpuRegister());
1648 break;
1649
Roland Levillaincff13742014-11-17 14:32:17 +00001650 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001651 // Processing a Dex `float-to-double' instruction.
1652 locations->SetInAt(0, Location::RequiresFpuRegister());
1653 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001654 break;
1655
1656 default:
1657 LOG(FATAL) << "Unexpected type conversion from " << input_type
1658 << " to " << result_type;
1659 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001660 break;
1661
1662 default:
1663 LOG(FATAL) << "Unexpected type conversion from " << input_type
1664 << " to " << result_type;
1665 }
1666}
1667
1668void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1669 LocationSummary* locations = conversion->GetLocations();
1670 Location out = locations->Out();
1671 Location in = locations->InAt(0);
1672 Primitive::Type result_type = conversion->GetResultType();
1673 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001674 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001675 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001676 case Primitive::kPrimByte:
1677 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001678 case Primitive::kPrimBoolean:
1679 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001680 case Primitive::kPrimShort:
1681 case Primitive::kPrimInt:
1682 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001683 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001684 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001685 break;
1686
1687 default:
1688 LOG(FATAL) << "Unexpected type conversion from " << input_type
1689 << " to " << result_type;
1690 }
1691 break;
1692
Roland Levillain01a8d712014-11-14 16:27:39 +00001693 case Primitive::kPrimShort:
1694 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001695 case Primitive::kPrimBoolean:
1696 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001697 case Primitive::kPrimByte:
1698 case Primitive::kPrimInt:
1699 case Primitive::kPrimChar:
1700 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001701 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001702 break;
1703
1704 default:
1705 LOG(FATAL) << "Unexpected type conversion from " << input_type
1706 << " to " << result_type;
1707 }
1708 break;
1709
Roland Levillain946e1432014-11-11 17:35:19 +00001710 case Primitive::kPrimInt:
1711 switch (input_type) {
1712 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001713 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001714 DCHECK(out.IsRegister());
1715 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001716 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001717 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001718 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001719 } else {
1720 DCHECK(in.IsConstant());
1721 DCHECK(in.GetConstant()->IsLongConstant());
1722 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001723 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001724 }
1725 break;
1726
Roland Levillain3f8f9362014-12-02 17:45:01 +00001727 case Primitive::kPrimFloat: {
1728 // Processing a Dex `float-to-int' instruction.
1729 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1730 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1731 __ vcvtis(temp, temp);
1732 __ vmovrs(out.AsRegister<Register>(), temp);
1733 break;
1734 }
1735
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001736 case Primitive::kPrimDouble: {
1737 // Processing a Dex `double-to-int' instruction.
1738 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1739 DRegister temp_d = FromLowSToD(temp_s);
1740 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1741 __ vcvtid(temp_s, temp_d);
1742 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001743 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001744 }
Roland Levillain946e1432014-11-11 17:35:19 +00001745
1746 default:
1747 LOG(FATAL) << "Unexpected type conversion from " << input_type
1748 << " to " << result_type;
1749 }
1750 break;
1751
Roland Levillaindff1f282014-11-05 14:15:05 +00001752 case Primitive::kPrimLong:
1753 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001754 case Primitive::kPrimBoolean:
1755 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001756 case Primitive::kPrimByte:
1757 case Primitive::kPrimShort:
1758 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001759 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001760 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001761 DCHECK(out.IsRegisterPair());
1762 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001763 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001764 // Sign extension.
1765 __ Asr(out.AsRegisterPairHigh<Register>(),
1766 out.AsRegisterPairLow<Register>(),
1767 31);
1768 break;
1769
1770 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001771 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001772 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1773 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001774 conversion->GetDexPc(),
1775 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001776 break;
1777
Roland Levillaindff1f282014-11-05 14:15:05 +00001778 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001779 // Processing a Dex `double-to-long' instruction.
1780 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1781 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001782 conversion->GetDexPc(),
1783 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001784 break;
1785
1786 default:
1787 LOG(FATAL) << "Unexpected type conversion from " << input_type
1788 << " to " << result_type;
1789 }
1790 break;
1791
Roland Levillain981e4542014-11-14 11:47:14 +00001792 case Primitive::kPrimChar:
1793 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001794 case Primitive::kPrimBoolean:
1795 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001796 case Primitive::kPrimByte:
1797 case Primitive::kPrimShort:
1798 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001799 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001800 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001801 break;
1802
1803 default:
1804 LOG(FATAL) << "Unexpected type conversion from " << input_type
1805 << " to " << result_type;
1806 }
1807 break;
1808
Roland Levillaindff1f282014-11-05 14:15:05 +00001809 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001810 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001811 case Primitive::kPrimBoolean:
1812 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001813 case Primitive::kPrimByte:
1814 case Primitive::kPrimShort:
1815 case Primitive::kPrimInt:
1816 case Primitive::kPrimChar: {
1817 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001818 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1819 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001820 break;
1821 }
1822
Roland Levillain5b3ee562015-04-14 16:02:41 +01001823 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001824 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001825 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
1826 conversion,
1827 conversion->GetDexPc(),
1828 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001829 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00001830
Roland Levillaincff13742014-11-17 14:32:17 +00001831 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001832 // Processing a Dex `double-to-float' instruction.
1833 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1834 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001835 break;
1836
1837 default:
1838 LOG(FATAL) << "Unexpected type conversion from " << input_type
1839 << " to " << result_type;
1840 };
1841 break;
1842
Roland Levillaindff1f282014-11-05 14:15:05 +00001843 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001844 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001845 case Primitive::kPrimBoolean:
1846 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001847 case Primitive::kPrimByte:
1848 case Primitive::kPrimShort:
1849 case Primitive::kPrimInt:
1850 case Primitive::kPrimChar: {
1851 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001852 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001853 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1854 out.AsFpuRegisterPairLow<SRegister>());
1855 break;
1856 }
1857
Roland Levillain647b9ed2014-11-27 12:06:00 +00001858 case Primitive::kPrimLong: {
1859 // Processing a Dex `long-to-double' instruction.
1860 Register low = in.AsRegisterPairLow<Register>();
1861 Register high = in.AsRegisterPairHigh<Register>();
1862 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1863 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001864 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1865 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001866 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1867 DRegister temp_d = FromLowSToD(temp_s);
1868
Roland Levillain647b9ed2014-11-27 12:06:00 +00001869 // out_d = int-to-double(high)
1870 __ vmovsr(out_s, high);
1871 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001872 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1873 // as an immediate value into `temp_d` does not work, as
1874 // this instruction only transfers 8 significant bits of its
1875 // immediate operand. Instead, use two 32-bit core
1876 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1877 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1878 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001879 __ vmovdrr(temp_d, constant_low, constant_high);
1880 // out_d = out_d * 2^32
1881 __ vmuld(out_d, out_d, temp_d);
1882 // temp_d = unsigned-to-double(low)
1883 __ vmovsr(temp_s, low);
1884 __ vcvtdu(temp_d, temp_s);
1885 // out_d = out_d + temp_d
1886 __ vaddd(out_d, out_d, temp_d);
1887 break;
1888 }
1889
Roland Levillaincff13742014-11-17 14:32:17 +00001890 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001891 // Processing a Dex `float-to-double' instruction.
1892 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1893 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001894 break;
1895
1896 default:
1897 LOG(FATAL) << "Unexpected type conversion from " << input_type
1898 << " to " << result_type;
1899 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001900 break;
1901
1902 default:
1903 LOG(FATAL) << "Unexpected type conversion from " << input_type
1904 << " to " << result_type;
1905 }
1906}
1907
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001908void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001909 LocationSummary* locations =
1910 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001911 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001912 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001913 locations->SetInAt(0, Location::RequiresRegister());
1914 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001915 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1916 break;
1917 }
1918
1919 case Primitive::kPrimLong: {
1920 locations->SetInAt(0, Location::RequiresRegister());
1921 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001922 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001923 break;
1924 }
1925
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001926 case Primitive::kPrimFloat:
1927 case Primitive::kPrimDouble: {
1928 locations->SetInAt(0, Location::RequiresFpuRegister());
1929 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001930 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001931 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001932 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001933
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001934 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001935 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001936 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001937}
1938
1939void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1940 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001941 Location out = locations->Out();
1942 Location first = locations->InAt(0);
1943 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001944 switch (add->GetResultType()) {
1945 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001946 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001947 __ add(out.AsRegister<Register>(),
1948 first.AsRegister<Register>(),
1949 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001950 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001951 __ AddConstant(out.AsRegister<Register>(),
1952 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001953 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001954 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001955 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001956
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001957 case Primitive::kPrimLong: {
1958 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001959 __ adds(out.AsRegisterPairLow<Register>(),
1960 first.AsRegisterPairLow<Register>(),
1961 ShifterOperand(second.AsRegisterPairLow<Register>()));
1962 __ adc(out.AsRegisterPairHigh<Register>(),
1963 first.AsRegisterPairHigh<Register>(),
1964 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001965 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001966 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001967
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001968 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001969 __ vadds(out.AsFpuRegister<SRegister>(),
1970 first.AsFpuRegister<SRegister>(),
1971 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001972 break;
1973
1974 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001975 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1976 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1977 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001978 break;
1979
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001980 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001981 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001982 }
1983}
1984
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001985void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001986 LocationSummary* locations =
1987 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001988 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001989 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001990 locations->SetInAt(0, Location::RequiresRegister());
1991 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001992 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1993 break;
1994 }
1995
1996 case Primitive::kPrimLong: {
1997 locations->SetInAt(0, Location::RequiresRegister());
1998 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001999 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002000 break;
2001 }
Calin Juravle11351682014-10-23 15:38:15 +01002002 case Primitive::kPrimFloat:
2003 case Primitive::kPrimDouble: {
2004 locations->SetInAt(0, Location::RequiresFpuRegister());
2005 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002006 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002007 break;
Calin Juravle11351682014-10-23 15:38:15 +01002008 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002009 default:
Calin Juravle11351682014-10-23 15:38:15 +01002010 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002011 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002012}
2013
2014void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2015 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002016 Location out = locations->Out();
2017 Location first = locations->InAt(0);
2018 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002019 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002020 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002021 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002022 __ sub(out.AsRegister<Register>(),
2023 first.AsRegister<Register>(),
2024 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002025 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002026 __ AddConstant(out.AsRegister<Register>(),
2027 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002028 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002029 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002030 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002031 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002032
Calin Juravle11351682014-10-23 15:38:15 +01002033 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002034 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002035 __ subs(out.AsRegisterPairLow<Register>(),
2036 first.AsRegisterPairLow<Register>(),
2037 ShifterOperand(second.AsRegisterPairLow<Register>()));
2038 __ sbc(out.AsRegisterPairHigh<Register>(),
2039 first.AsRegisterPairHigh<Register>(),
2040 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002041 break;
Calin Juravle11351682014-10-23 15:38:15 +01002042 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002043
Calin Juravle11351682014-10-23 15:38:15 +01002044 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002045 __ vsubs(out.AsFpuRegister<SRegister>(),
2046 first.AsFpuRegister<SRegister>(),
2047 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002048 break;
Calin Juravle11351682014-10-23 15:38:15 +01002049 }
2050
2051 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002052 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2053 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2054 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002055 break;
2056 }
2057
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002058
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002059 default:
Calin Juravle11351682014-10-23 15:38:15 +01002060 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002061 }
2062}
2063
Calin Juravle34bacdf2014-10-07 20:23:36 +01002064void LocationsBuilderARM::VisitMul(HMul* mul) {
2065 LocationSummary* locations =
2066 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2067 switch (mul->GetResultType()) {
2068 case Primitive::kPrimInt:
2069 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002070 locations->SetInAt(0, Location::RequiresRegister());
2071 locations->SetInAt(1, Location::RequiresRegister());
2072 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002073 break;
2074 }
2075
Calin Juravleb5bfa962014-10-21 18:02:24 +01002076 case Primitive::kPrimFloat:
2077 case Primitive::kPrimDouble: {
2078 locations->SetInAt(0, Location::RequiresFpuRegister());
2079 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002080 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002081 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002082 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002083
2084 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002085 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002086 }
2087}
2088
2089void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2090 LocationSummary* locations = mul->GetLocations();
2091 Location out = locations->Out();
2092 Location first = locations->InAt(0);
2093 Location second = locations->InAt(1);
2094 switch (mul->GetResultType()) {
2095 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002096 __ mul(out.AsRegister<Register>(),
2097 first.AsRegister<Register>(),
2098 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002099 break;
2100 }
2101 case Primitive::kPrimLong: {
2102 Register out_hi = out.AsRegisterPairHigh<Register>();
2103 Register out_lo = out.AsRegisterPairLow<Register>();
2104 Register in1_hi = first.AsRegisterPairHigh<Register>();
2105 Register in1_lo = first.AsRegisterPairLow<Register>();
2106 Register in2_hi = second.AsRegisterPairHigh<Register>();
2107 Register in2_lo = second.AsRegisterPairLow<Register>();
2108
2109 // Extra checks to protect caused by the existence of R1_R2.
2110 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2111 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2112 DCHECK_NE(out_hi, in1_lo);
2113 DCHECK_NE(out_hi, in2_lo);
2114
2115 // input: in1 - 64 bits, in2 - 64 bits
2116 // output: out
2117 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2118 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2119 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2120
2121 // IP <- in1.lo * in2.hi
2122 __ mul(IP, in1_lo, in2_hi);
2123 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2124 __ mla(out_hi, in1_hi, in2_lo, IP);
2125 // out.lo <- (in1.lo * in2.lo)[31:0];
2126 __ umull(out_lo, IP, in1_lo, in2_lo);
2127 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2128 __ add(out_hi, out_hi, ShifterOperand(IP));
2129 break;
2130 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002131
2132 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002133 __ vmuls(out.AsFpuRegister<SRegister>(),
2134 first.AsFpuRegister<SRegister>(),
2135 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002136 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002137 }
2138
2139 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002140 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2141 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2142 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002143 break;
2144 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002145
2146 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002147 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002148 }
2149}
2150
Zheng Xuc6667102015-05-15 16:08:45 +08002151void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2152 DCHECK(instruction->IsDiv() || instruction->IsRem());
2153 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2154
2155 LocationSummary* locations = instruction->GetLocations();
2156 Location second = locations->InAt(1);
2157 DCHECK(second.IsConstant());
2158
2159 Register out = locations->Out().AsRegister<Register>();
2160 Register dividend = locations->InAt(0).AsRegister<Register>();
2161 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2162 DCHECK(imm == 1 || imm == -1);
2163
2164 if (instruction->IsRem()) {
2165 __ LoadImmediate(out, 0);
2166 } else {
2167 if (imm == 1) {
2168 __ Mov(out, dividend);
2169 } else {
2170 __ rsb(out, dividend, ShifterOperand(0));
2171 }
2172 }
2173}
2174
2175void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2176 DCHECK(instruction->IsDiv() || instruction->IsRem());
2177 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2178
2179 LocationSummary* locations = instruction->GetLocations();
2180 Location second = locations->InAt(1);
2181 DCHECK(second.IsConstant());
2182
2183 Register out = locations->Out().AsRegister<Register>();
2184 Register dividend = locations->InAt(0).AsRegister<Register>();
2185 Register temp = locations->GetTemp(0).AsRegister<Register>();
2186 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002187 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002188 DCHECK(IsPowerOfTwo(abs_imm));
2189 int ctz_imm = CTZ(abs_imm);
2190
2191 if (ctz_imm == 1) {
2192 __ Lsr(temp, dividend, 32 - ctz_imm);
2193 } else {
2194 __ Asr(temp, dividend, 31);
2195 __ Lsr(temp, temp, 32 - ctz_imm);
2196 }
2197 __ add(out, temp, ShifterOperand(dividend));
2198
2199 if (instruction->IsDiv()) {
2200 __ Asr(out, out, ctz_imm);
2201 if (imm < 0) {
2202 __ rsb(out, out, ShifterOperand(0));
2203 }
2204 } else {
2205 __ ubfx(out, out, 0, ctz_imm);
2206 __ sub(out, out, ShifterOperand(temp));
2207 }
2208}
2209
2210void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2211 DCHECK(instruction->IsDiv() || instruction->IsRem());
2212 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2213
2214 LocationSummary* locations = instruction->GetLocations();
2215 Location second = locations->InAt(1);
2216 DCHECK(second.IsConstant());
2217
2218 Register out = locations->Out().AsRegister<Register>();
2219 Register dividend = locations->InAt(0).AsRegister<Register>();
2220 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2221 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2222 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2223
2224 int64_t magic;
2225 int shift;
2226 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2227
2228 __ LoadImmediate(temp1, magic);
2229 __ smull(temp2, temp1, dividend, temp1);
2230
2231 if (imm > 0 && magic < 0) {
2232 __ add(temp1, temp1, ShifterOperand(dividend));
2233 } else if (imm < 0 && magic > 0) {
2234 __ sub(temp1, temp1, ShifterOperand(dividend));
2235 }
2236
2237 if (shift != 0) {
2238 __ Asr(temp1, temp1, shift);
2239 }
2240
2241 if (instruction->IsDiv()) {
2242 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2243 } else {
2244 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2245 // TODO: Strength reduction for mls.
2246 __ LoadImmediate(temp2, imm);
2247 __ mls(out, temp1, temp2, dividend);
2248 }
2249}
2250
2251void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2252 DCHECK(instruction->IsDiv() || instruction->IsRem());
2253 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2254
2255 LocationSummary* locations = instruction->GetLocations();
2256 Location second = locations->InAt(1);
2257 DCHECK(second.IsConstant());
2258
2259 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2260 if (imm == 0) {
2261 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2262 } else if (imm == 1 || imm == -1) {
2263 DivRemOneOrMinusOne(instruction);
2264 } else if (IsPowerOfTwo(std::abs(imm))) {
2265 DivRemByPowerOfTwo(instruction);
2266 } else {
2267 DCHECK(imm <= -2 || imm >= 2);
2268 GenerateDivRemWithAnyConstant(instruction);
2269 }
2270}
2271
Calin Juravle7c4954d2014-10-28 16:57:40 +00002272void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002273 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2274 if (div->GetResultType() == Primitive::kPrimLong) {
2275 // pLdiv runtime call.
2276 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002277 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2278 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002279 } else if (div->GetResultType() == Primitive::kPrimInt &&
2280 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2281 // pIdivmod runtime call.
2282 call_kind = LocationSummary::kCall;
2283 }
2284
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002285 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2286
Calin Juravle7c4954d2014-10-28 16:57:40 +00002287 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002288 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002289 if (div->InputAt(1)->IsConstant()) {
2290 locations->SetInAt(0, Location::RequiresRegister());
2291 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2292 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2293 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2294 if (abs_imm <= 1) {
2295 // No temp register required.
2296 } else {
2297 locations->AddTemp(Location::RequiresRegister());
2298 if (!IsPowerOfTwo(abs_imm)) {
2299 locations->AddTemp(Location::RequiresRegister());
2300 }
2301 }
2302 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002303 locations->SetInAt(0, Location::RequiresRegister());
2304 locations->SetInAt(1, Location::RequiresRegister());
2305 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2306 } else {
2307 InvokeRuntimeCallingConvention calling_convention;
2308 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2309 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2310 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2311 // we only need the former.
2312 locations->SetOut(Location::RegisterLocation(R0));
2313 }
Calin Juravled0d48522014-11-04 16:40:20 +00002314 break;
2315 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002316 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002317 InvokeRuntimeCallingConvention calling_convention;
2318 locations->SetInAt(0, Location::RegisterPairLocation(
2319 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2320 locations->SetInAt(1, Location::RegisterPairLocation(
2321 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002322 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002323 break;
2324 }
2325 case Primitive::kPrimFloat:
2326 case Primitive::kPrimDouble: {
2327 locations->SetInAt(0, Location::RequiresFpuRegister());
2328 locations->SetInAt(1, Location::RequiresFpuRegister());
2329 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2330 break;
2331 }
2332
2333 default:
2334 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2335 }
2336}
2337
2338void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2339 LocationSummary* locations = div->GetLocations();
2340 Location out = locations->Out();
2341 Location first = locations->InAt(0);
2342 Location second = locations->InAt(1);
2343
2344 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002345 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002346 if (second.IsConstant()) {
2347 GenerateDivRemConstantIntegral(div);
2348 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002349 __ sdiv(out.AsRegister<Register>(),
2350 first.AsRegister<Register>(),
2351 second.AsRegister<Register>());
2352 } else {
2353 InvokeRuntimeCallingConvention calling_convention;
2354 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2355 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2356 DCHECK_EQ(R0, out.AsRegister<Register>());
2357
2358 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2359 }
Calin Juravled0d48522014-11-04 16:40:20 +00002360 break;
2361 }
2362
Calin Juravle7c4954d2014-10-28 16:57:40 +00002363 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002364 InvokeRuntimeCallingConvention calling_convention;
2365 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2366 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2367 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2368 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2369 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002370 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002371
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002372 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002373 break;
2374 }
2375
2376 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002377 __ vdivs(out.AsFpuRegister<SRegister>(),
2378 first.AsFpuRegister<SRegister>(),
2379 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002380 break;
2381 }
2382
2383 case Primitive::kPrimDouble: {
2384 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2385 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2386 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2387 break;
2388 }
2389
2390 default:
2391 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2392 }
2393}
2394
Calin Juravlebacfec32014-11-14 15:54:36 +00002395void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002396 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002397
2398 // Most remainders are implemented in the runtime.
2399 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002400 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2401 // sdiv will be replaced by other instruction sequence.
2402 call_kind = LocationSummary::kNoCall;
2403 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2404 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002405 // Have hardware divide instruction for int, do it with three instructions.
2406 call_kind = LocationSummary::kNoCall;
2407 }
2408
Calin Juravlebacfec32014-11-14 15:54:36 +00002409 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2410
Calin Juravled2ec87d2014-12-08 14:24:46 +00002411 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002412 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002413 if (rem->InputAt(1)->IsConstant()) {
2414 locations->SetInAt(0, Location::RequiresRegister());
2415 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2416 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2417 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2418 if (abs_imm <= 1) {
2419 // No temp register required.
2420 } else {
2421 locations->AddTemp(Location::RequiresRegister());
2422 if (!IsPowerOfTwo(abs_imm)) {
2423 locations->AddTemp(Location::RequiresRegister());
2424 }
2425 }
2426 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002427 locations->SetInAt(0, Location::RequiresRegister());
2428 locations->SetInAt(1, Location::RequiresRegister());
2429 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2430 locations->AddTemp(Location::RequiresRegister());
2431 } else {
2432 InvokeRuntimeCallingConvention calling_convention;
2433 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2434 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2435 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2436 // we only need the latter.
2437 locations->SetOut(Location::RegisterLocation(R1));
2438 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002439 break;
2440 }
2441 case Primitive::kPrimLong: {
2442 InvokeRuntimeCallingConvention calling_convention;
2443 locations->SetInAt(0, Location::RegisterPairLocation(
2444 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2445 locations->SetInAt(1, Location::RegisterPairLocation(
2446 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2447 // The runtime helper puts the output in R2,R3.
2448 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2449 break;
2450 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002451 case Primitive::kPrimFloat: {
2452 InvokeRuntimeCallingConvention calling_convention;
2453 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2454 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2455 locations->SetOut(Location::FpuRegisterLocation(S0));
2456 break;
2457 }
2458
Calin Juravlebacfec32014-11-14 15:54:36 +00002459 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002460 InvokeRuntimeCallingConvention calling_convention;
2461 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2462 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2463 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2464 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2465 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002466 break;
2467 }
2468
2469 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002470 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002471 }
2472}
2473
2474void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2475 LocationSummary* locations = rem->GetLocations();
2476 Location out = locations->Out();
2477 Location first = locations->InAt(0);
2478 Location second = locations->InAt(1);
2479
Calin Juravled2ec87d2014-12-08 14:24:46 +00002480 Primitive::Type type = rem->GetResultType();
2481 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002482 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002483 if (second.IsConstant()) {
2484 GenerateDivRemConstantIntegral(rem);
2485 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002486 Register reg1 = first.AsRegister<Register>();
2487 Register reg2 = second.AsRegister<Register>();
2488 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002489
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002490 // temp = reg1 / reg2 (integer division)
2491 // temp = temp * reg2
2492 // dest = reg1 - temp
2493 __ sdiv(temp, reg1, reg2);
2494 __ mul(temp, temp, reg2);
2495 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2496 } else {
2497 InvokeRuntimeCallingConvention calling_convention;
2498 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2499 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2500 DCHECK_EQ(R1, out.AsRegister<Register>());
2501
2502 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2503 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002504 break;
2505 }
2506
2507 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002508 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002509 break;
2510 }
2511
Calin Juravled2ec87d2014-12-08 14:24:46 +00002512 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002513 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002514 break;
2515 }
2516
Calin Juravlebacfec32014-11-14 15:54:36 +00002517 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002518 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002519 break;
2520 }
2521
2522 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002523 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002524 }
2525}
2526
Calin Juravled0d48522014-11-04 16:40:20 +00002527void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2528 LocationSummary* locations =
2529 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002530 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002531 if (instruction->HasUses()) {
2532 locations->SetOut(Location::SameAsFirstInput());
2533 }
2534}
2535
2536void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2537 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2538 codegen_->AddSlowPath(slow_path);
2539
2540 LocationSummary* locations = instruction->GetLocations();
2541 Location value = locations->InAt(0);
2542
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002543 switch (instruction->GetType()) {
2544 case Primitive::kPrimInt: {
2545 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002546 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002547 __ b(slow_path->GetEntryLabel(), EQ);
2548 } else {
2549 DCHECK(value.IsConstant()) << value;
2550 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2551 __ b(slow_path->GetEntryLabel());
2552 }
2553 }
2554 break;
2555 }
2556 case Primitive::kPrimLong: {
2557 if (value.IsRegisterPair()) {
2558 __ orrs(IP,
2559 value.AsRegisterPairLow<Register>(),
2560 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2561 __ b(slow_path->GetEntryLabel(), EQ);
2562 } else {
2563 DCHECK(value.IsConstant()) << value;
2564 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2565 __ b(slow_path->GetEntryLabel());
2566 }
2567 }
2568 break;
2569 default:
2570 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2571 }
2572 }
Calin Juravled0d48522014-11-04 16:40:20 +00002573}
2574
Calin Juravle9aec02f2014-11-18 23:06:35 +00002575void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2576 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2577
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002578 LocationSummary* locations =
2579 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002580
2581 switch (op->GetResultType()) {
2582 case Primitive::kPrimInt: {
2583 locations->SetInAt(0, Location::RequiresRegister());
2584 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002585 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002586 break;
2587 }
2588 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002589 locations->SetInAt(0, Location::RequiresRegister());
2590 locations->SetInAt(1, Location::RequiresRegister());
2591 locations->AddTemp(Location::RequiresRegister());
2592 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002593 break;
2594 }
2595 default:
2596 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2597 }
2598}
2599
2600void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2601 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2602
2603 LocationSummary* locations = op->GetLocations();
2604 Location out = locations->Out();
2605 Location first = locations->InAt(0);
2606 Location second = locations->InAt(1);
2607
2608 Primitive::Type type = op->GetResultType();
2609 switch (type) {
2610 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002611 Register out_reg = out.AsRegister<Register>();
2612 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002613 // Arm doesn't mask the shift count so we need to do it ourselves.
2614 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002615 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002616 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2617 if (op->IsShl()) {
2618 __ Lsl(out_reg, first_reg, second_reg);
2619 } else if (op->IsShr()) {
2620 __ Asr(out_reg, first_reg, second_reg);
2621 } else {
2622 __ Lsr(out_reg, first_reg, second_reg);
2623 }
2624 } else {
2625 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2626 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2627 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2628 __ Mov(out_reg, first_reg);
2629 } else if (op->IsShl()) {
2630 __ Lsl(out_reg, first_reg, shift_value);
2631 } else if (op->IsShr()) {
2632 __ Asr(out_reg, first_reg, shift_value);
2633 } else {
2634 __ Lsr(out_reg, first_reg, shift_value);
2635 }
2636 }
2637 break;
2638 }
2639 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002640 Register o_h = out.AsRegisterPairHigh<Register>();
2641 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002642
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002643 Register temp = locations->GetTemp(0).AsRegister<Register>();
2644
2645 Register high = first.AsRegisterPairHigh<Register>();
2646 Register low = first.AsRegisterPairLow<Register>();
2647
2648 Register second_reg = second.AsRegister<Register>();
2649
Calin Juravle9aec02f2014-11-18 23:06:35 +00002650 if (op->IsShl()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002651 // Shift the high part
2652 __ and_(second_reg, second_reg, ShifterOperand(63));
2653 __ Lsl(o_h, high, second_reg);
2654 // Shift the low part and `or` what overflew on the high part
2655 __ rsb(temp, second_reg, ShifterOperand(32));
2656 __ Lsr(temp, low, temp);
2657 __ orr(o_h, o_h, ShifterOperand(temp));
2658 // If the shift is > 32 bits, override the high part
2659 __ subs(temp, second_reg, ShifterOperand(32));
2660 __ it(PL);
2661 __ Lsl(o_h, low, temp, false, PL);
2662 // Shift the low part
2663 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002664 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002665 // Shift the low part
2666 __ and_(second_reg, second_reg, ShifterOperand(63));
2667 __ Lsr(o_l, low, second_reg);
2668 // Shift the high part and `or` what underflew on the low part
2669 __ rsb(temp, second_reg, ShifterOperand(32));
2670 __ Lsl(temp, high, temp);
2671 __ orr(o_l, o_l, ShifterOperand(temp));
2672 // If the shift is > 32 bits, override the low part
2673 __ subs(temp, second_reg, ShifterOperand(32));
2674 __ it(PL);
2675 __ Asr(o_l, high, temp, false, PL);
2676 // Shift the high part
2677 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002678 } else {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002679 // same as Shr except we use `Lsr`s and not `Asr`s
2680 __ and_(second_reg, second_reg, ShifterOperand(63));
2681 __ Lsr(o_l, low, second_reg);
2682 __ rsb(temp, second_reg, ShifterOperand(32));
2683 __ Lsl(temp, high, temp);
2684 __ orr(o_l, o_l, ShifterOperand(temp));
2685 __ subs(temp, second_reg, ShifterOperand(32));
2686 __ it(PL);
2687 __ Lsr(o_l, high, temp, false, PL);
2688 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002689 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002690 break;
2691 }
2692 default:
2693 LOG(FATAL) << "Unexpected operation type " << type;
2694 }
2695}
2696
2697void LocationsBuilderARM::VisitShl(HShl* shl) {
2698 HandleShift(shl);
2699}
2700
2701void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2702 HandleShift(shl);
2703}
2704
2705void LocationsBuilderARM::VisitShr(HShr* shr) {
2706 HandleShift(shr);
2707}
2708
2709void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2710 HandleShift(shr);
2711}
2712
2713void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2714 HandleShift(ushr);
2715}
2716
2717void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2718 HandleShift(ushr);
2719}
2720
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002721void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002722 LocationSummary* locations =
2723 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002724 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002725 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2726 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2727 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002728}
2729
2730void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2731 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002732 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002733 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002734 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2735 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002736 instruction->GetDexPc(),
2737 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002738}
2739
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002740void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2741 LocationSummary* locations =
2742 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2743 InvokeRuntimeCallingConvention calling_convention;
2744 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002745 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002746 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002747 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002748}
2749
2750void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2751 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002752 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002753 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002754 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2755 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002756 instruction->GetDexPc(),
2757 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002758}
2759
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002760void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002761 LocationSummary* locations =
2762 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002763 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2764 if (location.IsStackSlot()) {
2765 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2766 } else if (location.IsDoubleStackSlot()) {
2767 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002768 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002769 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002770}
2771
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002772void InstructionCodeGeneratorARM::VisitParameterValue(
2773 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002774 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002775}
2776
2777void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
2778 LocationSummary* locations =
2779 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2780 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2781}
2782
2783void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
2784 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002785}
2786
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002787void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002788 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002789 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002790 locations->SetInAt(0, Location::RequiresRegister());
2791 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002792}
2793
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002794void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2795 LocationSummary* locations = not_->GetLocations();
2796 Location out = locations->Out();
2797 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002798 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002799 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002800 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002801 break;
2802
2803 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002804 __ mvn(out.AsRegisterPairLow<Register>(),
2805 ShifterOperand(in.AsRegisterPairLow<Register>()));
2806 __ mvn(out.AsRegisterPairHigh<Register>(),
2807 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002808 break;
2809
2810 default:
2811 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2812 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002813}
2814
David Brazdil66d126e2015-04-03 16:02:44 +01002815void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
2816 LocationSummary* locations =
2817 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
2818 locations->SetInAt(0, Location::RequiresRegister());
2819 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2820}
2821
2822void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01002823 LocationSummary* locations = bool_not->GetLocations();
2824 Location out = locations->Out();
2825 Location in = locations->InAt(0);
2826 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
2827}
2828
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002829void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002830 LocationSummary* locations =
2831 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002832 switch (compare->InputAt(0)->GetType()) {
2833 case Primitive::kPrimLong: {
2834 locations->SetInAt(0, Location::RequiresRegister());
2835 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002836 // Output overlaps because it is written before doing the low comparison.
2837 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002838 break;
2839 }
2840 case Primitive::kPrimFloat:
2841 case Primitive::kPrimDouble: {
2842 locations->SetInAt(0, Location::RequiresFpuRegister());
2843 locations->SetInAt(1, Location::RequiresFpuRegister());
2844 locations->SetOut(Location::RequiresRegister());
2845 break;
2846 }
2847 default:
2848 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2849 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002850}
2851
2852void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002853 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002854 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002855 Location left = locations->InAt(0);
2856 Location right = locations->InAt(1);
2857
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002858 NearLabel less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00002859 Primitive::Type type = compare->InputAt(0)->GetType();
2860 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002861 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002862 __ cmp(left.AsRegisterPairHigh<Register>(),
2863 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002864 __ b(&less, LT);
2865 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002866 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2867 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002868 __ cmp(left.AsRegisterPairLow<Register>(),
2869 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002870 break;
2871 }
2872 case Primitive::kPrimFloat:
2873 case Primitive::kPrimDouble: {
2874 __ LoadImmediate(out, 0);
2875 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002876 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002877 } else {
2878 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2879 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2880 }
2881 __ vmstat(); // transfer FP status register to ARM APSR.
2882 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002883 break;
2884 }
2885 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002886 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002887 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002888 __ b(&done, EQ);
2889 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2890
2891 __ Bind(&greater);
2892 __ LoadImmediate(out, 1);
2893 __ b(&done);
2894
2895 __ Bind(&less);
2896 __ LoadImmediate(out, -1);
2897
2898 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002899}
2900
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002901void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002902 LocationSummary* locations =
2903 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002904 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2905 locations->SetInAt(i, Location::Any());
2906 }
2907 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002908}
2909
2910void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002911 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002912 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002913}
2914
Calin Juravle52c48962014-12-16 17:02:57 +00002915void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2916 // TODO (ported from quick): revisit Arm barrier kinds
2917 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2918 switch (kind) {
2919 case MemBarrierKind::kAnyStore:
2920 case MemBarrierKind::kLoadAny:
2921 case MemBarrierKind::kAnyAny: {
2922 flavour = DmbOptions::ISH;
2923 break;
2924 }
2925 case MemBarrierKind::kStoreStore: {
2926 flavour = DmbOptions::ISHST;
2927 break;
2928 }
2929 default:
2930 LOG(FATAL) << "Unexpected memory barrier " << kind;
2931 }
2932 __ dmb(flavour);
2933}
2934
2935void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2936 uint32_t offset,
2937 Register out_lo,
2938 Register out_hi) {
2939 if (offset != 0) {
2940 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002941 __ add(IP, addr, ShifterOperand(out_lo));
2942 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002943 }
2944 __ ldrexd(out_lo, out_hi, addr);
2945}
2946
2947void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2948 uint32_t offset,
2949 Register value_lo,
2950 Register value_hi,
2951 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002952 Register temp2,
2953 HInstruction* instruction) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002954 NearLabel fail;
Calin Juravle52c48962014-12-16 17:02:57 +00002955 if (offset != 0) {
2956 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002957 __ add(IP, addr, ShifterOperand(temp1));
2958 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002959 }
2960 __ Bind(&fail);
2961 // We need a load followed by store. (The address used in a STREX instruction must
2962 // be the same as the address in the most recently executed LDREX instruction.)
2963 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002964 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002965 __ strexd(temp1, value_lo, value_hi, addr);
2966 __ cmp(temp1, ShifterOperand(0));
2967 __ b(&fail, NE);
2968}
2969
2970void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2971 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2972
Nicolas Geoffray39468442014-09-02 15:17:15 +01002973 LocationSummary* locations =
2974 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002975 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002976
Calin Juravle52c48962014-12-16 17:02:57 +00002977 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01002978 if (Primitive::IsFloatingPointType(field_type)) {
2979 locations->SetInAt(1, Location::RequiresFpuRegister());
2980 } else {
2981 locations->SetInAt(1, Location::RequiresRegister());
2982 }
2983
Calin Juravle52c48962014-12-16 17:02:57 +00002984 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002985 bool generate_volatile = field_info.IsVolatile()
2986 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002987 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002988 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002989 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2990 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002991 locations->AddTemp(Location::RequiresRegister());
2992 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002993 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002994 // Arm encoding have some additional constraints for ldrexd/strexd:
2995 // - registers need to be consecutive
2996 // - the first register should be even but not R14.
2997 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2998 // enable Arm encoding.
2999 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3000
3001 locations->AddTemp(Location::RequiresRegister());
3002 locations->AddTemp(Location::RequiresRegister());
3003 if (field_type == Primitive::kPrimDouble) {
3004 // For doubles we need two more registers to copy the value.
3005 locations->AddTemp(Location::RegisterLocation(R2));
3006 locations->AddTemp(Location::RegisterLocation(R3));
3007 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003008 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003009}
3010
Calin Juravle52c48962014-12-16 17:02:57 +00003011void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003012 const FieldInfo& field_info,
3013 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003014 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3015
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003016 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003017 Register base = locations->InAt(0).AsRegister<Register>();
3018 Location value = locations->InAt(1);
3019
3020 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003021 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003022 Primitive::Type field_type = field_info.GetFieldType();
3023 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3024
3025 if (is_volatile) {
3026 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3027 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003028
3029 switch (field_type) {
3030 case Primitive::kPrimBoolean:
3031 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003032 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003033 break;
3034 }
3035
3036 case Primitive::kPrimShort:
3037 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003038 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003039 break;
3040 }
3041
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003042 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003043 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00003044 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003045 break;
3046 }
3047
3048 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003049 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003050 GenerateWideAtomicStore(base, offset,
3051 value.AsRegisterPairLow<Register>(),
3052 value.AsRegisterPairHigh<Register>(),
3053 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003054 locations->GetTemp(1).AsRegister<Register>(),
3055 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003056 } else {
3057 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003058 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003059 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003060 break;
3061 }
3062
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003063 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003064 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003065 break;
3066 }
3067
3068 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003069 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003070 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003071 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3072 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3073
3074 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3075
3076 GenerateWideAtomicStore(base, offset,
3077 value_reg_lo,
3078 value_reg_hi,
3079 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003080 locations->GetTemp(3).AsRegister<Register>(),
3081 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003082 } else {
3083 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003084 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003085 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003086 break;
3087 }
3088
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003089 case Primitive::kPrimVoid:
3090 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003091 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003092 }
Calin Juravle52c48962014-12-16 17:02:57 +00003093
Calin Juravle77520bc2015-01-12 18:45:46 +00003094 // Longs and doubles are handled in the switch.
3095 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3096 codegen_->MaybeRecordImplicitNullCheck(instruction);
3097 }
3098
3099 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3100 Register temp = locations->GetTemp(0).AsRegister<Register>();
3101 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003102 codegen_->MarkGCCard(
3103 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003104 }
3105
Calin Juravle52c48962014-12-16 17:02:57 +00003106 if (is_volatile) {
3107 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3108 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003109}
3110
Calin Juravle52c48962014-12-16 17:02:57 +00003111void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3112 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003113 LocationSummary* locations =
3114 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003115 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003116
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003117 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003118 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003119 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003120 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003121
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003122 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3123 locations->SetOut(Location::RequiresFpuRegister());
3124 } else {
3125 locations->SetOut(Location::RequiresRegister(),
3126 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3127 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003128 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003129 // Arm encoding have some additional constraints for ldrexd/strexd:
3130 // - registers need to be consecutive
3131 // - the first register should be even but not R14.
3132 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3133 // enable Arm encoding.
3134 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3135 locations->AddTemp(Location::RequiresRegister());
3136 locations->AddTemp(Location::RequiresRegister());
3137 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003138}
3139
Calin Juravle52c48962014-12-16 17:02:57 +00003140void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3141 const FieldInfo& field_info) {
3142 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003143
Calin Juravle52c48962014-12-16 17:02:57 +00003144 LocationSummary* locations = instruction->GetLocations();
3145 Register base = locations->InAt(0).AsRegister<Register>();
3146 Location out = locations->Out();
3147 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003148 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003149 Primitive::Type field_type = field_info.GetFieldType();
3150 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3151
3152 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003153 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003154 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003155 break;
3156 }
3157
3158 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003159 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003160 break;
3161 }
3162
3163 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003164 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003165 break;
3166 }
3167
3168 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003169 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003170 break;
3171 }
3172
3173 case Primitive::kPrimInt:
3174 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003175 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003176 break;
3177 }
3178
3179 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003180 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003181 GenerateWideAtomicLoad(base, offset,
3182 out.AsRegisterPairLow<Register>(),
3183 out.AsRegisterPairHigh<Register>());
3184 } else {
3185 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3186 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003187 break;
3188 }
3189
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003190 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003191 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003192 break;
3193 }
3194
3195 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003196 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003197 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003198 Register lo = locations->GetTemp(0).AsRegister<Register>();
3199 Register hi = locations->GetTemp(1).AsRegister<Register>();
3200 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003201 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003202 __ vmovdrr(out_reg, lo, hi);
3203 } else {
3204 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003205 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003206 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003207 break;
3208 }
3209
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003210 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003211 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003212 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003213 }
Calin Juravle52c48962014-12-16 17:02:57 +00003214
Calin Juravle77520bc2015-01-12 18:45:46 +00003215 // Doubles are handled in the switch.
3216 if (field_type != Primitive::kPrimDouble) {
3217 codegen_->MaybeRecordImplicitNullCheck(instruction);
3218 }
3219
Calin Juravle52c48962014-12-16 17:02:57 +00003220 if (is_volatile) {
3221 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3222 }
3223}
3224
3225void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3226 HandleFieldSet(instruction, instruction->GetFieldInfo());
3227}
3228
3229void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003230 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003231}
3232
3233void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3234 HandleFieldGet(instruction, instruction->GetFieldInfo());
3235}
3236
3237void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3238 HandleFieldGet(instruction, instruction->GetFieldInfo());
3239}
3240
3241void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3242 HandleFieldGet(instruction, instruction->GetFieldInfo());
3243}
3244
3245void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3246 HandleFieldGet(instruction, instruction->GetFieldInfo());
3247}
3248
3249void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3250 HandleFieldSet(instruction, instruction->GetFieldInfo());
3251}
3252
3253void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003254 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003255}
3256
3257void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003258 LocationSummary* locations =
3259 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003260 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003261 if (instruction->HasUses()) {
3262 locations->SetOut(Location::SameAsFirstInput());
3263 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003264}
3265
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003266void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003267 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3268 return;
3269 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003270 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003271
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003272 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3273 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3274}
3275
3276void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003277 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003278 codegen_->AddSlowPath(slow_path);
3279
3280 LocationSummary* locations = instruction->GetLocations();
3281 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003282
Calin Juravle77520bc2015-01-12 18:45:46 +00003283 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
3284 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003285}
3286
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003287void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3288 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3289 GenerateImplicitNullCheck(instruction);
3290 } else {
3291 GenerateExplicitNullCheck(instruction);
3292 }
3293}
3294
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003295void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003296 LocationSummary* locations =
3297 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003298 locations->SetInAt(0, Location::RequiresRegister());
3299 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003300 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3301 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3302 } else {
3303 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3304 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003305}
3306
3307void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3308 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003309 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003310 Location index = locations->InAt(1);
3311
3312 switch (instruction->GetType()) {
3313 case Primitive::kPrimBoolean: {
3314 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003315 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003316 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003317 size_t offset =
3318 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003319 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3320 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003321 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003322 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3323 }
3324 break;
3325 }
3326
3327 case Primitive::kPrimByte: {
3328 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003329 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003330 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003331 size_t offset =
3332 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003333 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3334 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003335 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003336 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3337 }
3338 break;
3339 }
3340
3341 case Primitive::kPrimShort: {
3342 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003343 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003344 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003345 size_t offset =
3346 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003347 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3348 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003349 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003350 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3351 }
3352 break;
3353 }
3354
3355 case Primitive::kPrimChar: {
3356 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003357 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003358 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003359 size_t offset =
3360 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003361 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3362 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003363 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003364 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3365 }
3366 break;
3367 }
3368
3369 case Primitive::kPrimInt:
3370 case Primitive::kPrimNot: {
3371 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3372 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003373 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003374 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003375 size_t offset =
3376 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003377 __ LoadFromOffset(kLoadWord, out, obj, offset);
3378 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003379 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003380 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3381 }
3382 break;
3383 }
3384
3385 case Primitive::kPrimLong: {
3386 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003387 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003388 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003389 size_t offset =
3390 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003391 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003392 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003393 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003394 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003395 }
3396 break;
3397 }
3398
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003399 case Primitive::kPrimFloat: {
3400 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3401 Location out = locations->Out();
3402 DCHECK(out.IsFpuRegister());
3403 if (index.IsConstant()) {
3404 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3405 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3406 } else {
3407 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3408 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3409 }
3410 break;
3411 }
3412
3413 case Primitive::kPrimDouble: {
3414 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3415 Location out = locations->Out();
3416 DCHECK(out.IsFpuRegisterPair());
3417 if (index.IsConstant()) {
3418 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3419 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3420 } else {
3421 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3422 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3423 }
3424 break;
3425 }
3426
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003427 case Primitive::kPrimVoid:
3428 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003429 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003430 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003431 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003432}
3433
3434void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003435 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003436
3437 bool needs_write_barrier =
3438 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3439 bool needs_runtime_call = instruction->NeedsTypeCheck();
3440
Nicolas Geoffray39468442014-09-02 15:17:15 +01003441 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003442 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3443 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003444 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003445 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3446 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3447 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003448 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003449 locations->SetInAt(0, Location::RequiresRegister());
3450 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003451 if (Primitive::IsFloatingPointType(value_type)) {
3452 locations->SetInAt(2, Location::RequiresFpuRegister());
3453 } else {
3454 locations->SetInAt(2, Location::RequiresRegister());
3455 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003456
3457 if (needs_write_barrier) {
3458 // Temporary registers for the write barrier.
3459 locations->AddTemp(Location::RequiresRegister());
3460 locations->AddTemp(Location::RequiresRegister());
3461 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003462 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003463}
3464
3465void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3466 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003467 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003468 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003469 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003470 bool needs_runtime_call = locations->WillCall();
3471 bool needs_write_barrier =
3472 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003473
3474 switch (value_type) {
3475 case Primitive::kPrimBoolean:
3476 case Primitive::kPrimByte: {
3477 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003478 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003479 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003480 size_t offset =
3481 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003482 __ StoreToOffset(kStoreByte, value, obj, offset);
3483 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003484 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003485 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3486 }
3487 break;
3488 }
3489
3490 case Primitive::kPrimShort:
3491 case Primitive::kPrimChar: {
3492 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003493 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003494 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003495 size_t offset =
3496 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003497 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3498 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003499 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003500 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3501 }
3502 break;
3503 }
3504
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003505 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003506 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003507 if (!needs_runtime_call) {
3508 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003509 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003510 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003511 size_t offset =
3512 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003513 __ StoreToOffset(kStoreWord, value, obj, offset);
3514 } else {
3515 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003516 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003517 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3518 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003519 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003520 if (needs_write_barrier) {
3521 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003522 Register temp = locations->GetTemp(0).AsRegister<Register>();
3523 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003524 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003525 }
3526 } else {
3527 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003528 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3529 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003530 instruction->GetDexPc(),
3531 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003532 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003533 break;
3534 }
3535
3536 case Primitive::kPrimLong: {
3537 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003538 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003539 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003540 size_t offset =
3541 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003542 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003543 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003544 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003545 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003546 }
3547 break;
3548 }
3549
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003550 case Primitive::kPrimFloat: {
3551 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3552 Location value = locations->InAt(2);
3553 DCHECK(value.IsFpuRegister());
3554 if (index.IsConstant()) {
3555 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3556 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3557 } else {
3558 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3559 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3560 }
3561 break;
3562 }
3563
3564 case Primitive::kPrimDouble: {
3565 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3566 Location value = locations->InAt(2);
3567 DCHECK(value.IsFpuRegisterPair());
3568 if (index.IsConstant()) {
3569 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3570 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3571 } else {
3572 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3573 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3574 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003575
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003576 break;
3577 }
3578
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003579 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003580 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003581 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003582 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003583
3584 // Ints and objects are handled in the switch.
3585 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3586 codegen_->MaybeRecordImplicitNullCheck(instruction);
3587 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003588}
3589
3590void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003591 LocationSummary* locations =
3592 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003593 locations->SetInAt(0, Location::RequiresRegister());
3594 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003595}
3596
3597void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3598 LocationSummary* locations = instruction->GetLocations();
3599 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003600 Register obj = locations->InAt(0).AsRegister<Register>();
3601 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003602 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003603 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003604}
3605
3606void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003607 LocationSummary* locations =
3608 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003609 locations->SetInAt(0, Location::RequiresRegister());
3610 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003611 if (instruction->HasUses()) {
3612 locations->SetOut(Location::SameAsFirstInput());
3613 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003614}
3615
3616void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3617 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003618 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003619 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003620 codegen_->AddSlowPath(slow_path);
3621
Roland Levillain271ab9c2014-11-27 15:23:57 +00003622 Register index = locations->InAt(0).AsRegister<Register>();
3623 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003624
3625 __ cmp(index, ShifterOperand(length));
3626 __ b(slow_path->GetEntryLabel(), CS);
3627}
3628
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003629void CodeGeneratorARM::MarkGCCard(Register temp,
3630 Register card,
3631 Register object,
3632 Register value,
3633 bool can_be_null) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00003634 NearLabel is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003635 if (can_be_null) {
3636 __ CompareAndBranchIfZero(value, &is_null);
3637 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003638 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3639 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3640 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003641 if (can_be_null) {
3642 __ Bind(&is_null);
3643 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003644}
3645
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003646void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3647 temp->SetLocations(nullptr);
3648}
3649
3650void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3651 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003652 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003653}
3654
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003655void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003656 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003657 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003658}
3659
3660void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003661 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3662}
3663
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003664void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3665 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3666}
3667
3668void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003669 HBasicBlock* block = instruction->GetBlock();
3670 if (block->GetLoopInformation() != nullptr) {
3671 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3672 // The back edge will generate the suspend check.
3673 return;
3674 }
3675 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3676 // The goto will generate the suspend check.
3677 return;
3678 }
3679 GenerateSuspendCheck(instruction, nullptr);
3680}
3681
3682void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3683 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003684 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003685 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3686 if (slow_path == nullptr) {
3687 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3688 instruction->SetSlowPath(slow_path);
3689 codegen_->AddSlowPath(slow_path);
3690 if (successor != nullptr) {
3691 DCHECK(successor->IsLoopHeader());
3692 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3693 }
3694 } else {
3695 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3696 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003697
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003698 __ LoadFromOffset(
3699 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3700 __ cmp(IP, ShifterOperand(0));
3701 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003702 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003703 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003704 __ Bind(slow_path->GetReturnLabel());
3705 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003706 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003707 __ b(slow_path->GetEntryLabel());
3708 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003709}
3710
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003711ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3712 return codegen_->GetAssembler();
3713}
3714
3715void ParallelMoveResolverARM::EmitMove(size_t index) {
3716 MoveOperands* move = moves_.Get(index);
3717 Location source = move->GetSource();
3718 Location destination = move->GetDestination();
3719
3720 if (source.IsRegister()) {
3721 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003722 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003723 } else {
3724 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003725 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003726 SP, destination.GetStackIndex());
3727 }
3728 } else if (source.IsStackSlot()) {
3729 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003730 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003731 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003732 } else if (destination.IsFpuRegister()) {
3733 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003734 } else {
3735 DCHECK(destination.IsStackSlot());
3736 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3737 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3738 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003739 } else if (source.IsFpuRegister()) {
3740 if (destination.IsFpuRegister()) {
3741 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003742 } else {
3743 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003744 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3745 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003746 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003747 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003748 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3749 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003750 } else if (destination.IsRegisterPair()) {
3751 DCHECK(ExpectedPairLayout(destination));
3752 __ LoadFromOffset(
3753 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3754 } else {
3755 DCHECK(destination.IsFpuRegisterPair()) << destination;
3756 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3757 SP,
3758 source.GetStackIndex());
3759 }
3760 } else if (source.IsRegisterPair()) {
3761 if (destination.IsRegisterPair()) {
3762 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3763 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3764 } else {
3765 DCHECK(destination.IsDoubleStackSlot()) << destination;
3766 DCHECK(ExpectedPairLayout(source));
3767 __ StoreToOffset(
3768 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3769 }
3770 } else if (source.IsFpuRegisterPair()) {
3771 if (destination.IsFpuRegisterPair()) {
3772 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3773 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3774 } else {
3775 DCHECK(destination.IsDoubleStackSlot()) << destination;
3776 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3777 SP,
3778 destination.GetStackIndex());
3779 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003780 } else {
3781 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003782 HConstant* constant = source.GetConstant();
3783 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3784 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003785 if (destination.IsRegister()) {
3786 __ LoadImmediate(destination.AsRegister<Register>(), value);
3787 } else {
3788 DCHECK(destination.IsStackSlot());
3789 __ LoadImmediate(IP, value);
3790 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3791 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003792 } else if (constant->IsLongConstant()) {
3793 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003794 if (destination.IsRegisterPair()) {
3795 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3796 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003797 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003798 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003799 __ LoadImmediate(IP, Low32Bits(value));
3800 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3801 __ LoadImmediate(IP, High32Bits(value));
3802 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3803 }
3804 } else if (constant->IsDoubleConstant()) {
3805 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003806 if (destination.IsFpuRegisterPair()) {
3807 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003808 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003809 DCHECK(destination.IsDoubleStackSlot()) << destination;
3810 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003811 __ LoadImmediate(IP, Low32Bits(int_value));
3812 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3813 __ LoadImmediate(IP, High32Bits(int_value));
3814 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3815 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003816 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003817 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003818 float value = constant->AsFloatConstant()->GetValue();
3819 if (destination.IsFpuRegister()) {
3820 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3821 } else {
3822 DCHECK(destination.IsStackSlot());
3823 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3824 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3825 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003826 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003827 }
3828}
3829
3830void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3831 __ Mov(IP, reg);
3832 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3833 __ StoreToOffset(kStoreWord, IP, SP, mem);
3834}
3835
3836void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3837 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3838 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3839 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3840 SP, mem1 + stack_offset);
3841 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3842 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3843 SP, mem2 + stack_offset);
3844 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3845}
3846
3847void ParallelMoveResolverARM::EmitSwap(size_t index) {
3848 MoveOperands* move = moves_.Get(index);
3849 Location source = move->GetSource();
3850 Location destination = move->GetDestination();
3851
3852 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003853 DCHECK_NE(source.AsRegister<Register>(), IP);
3854 DCHECK_NE(destination.AsRegister<Register>(), IP);
3855 __ Mov(IP, source.AsRegister<Register>());
3856 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3857 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003858 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003859 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003860 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003861 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003862 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3863 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003864 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003865 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003866 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003867 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003868 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003869 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003870 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003871 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003872 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3873 destination.AsRegisterPairHigh<Register>(),
3874 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003875 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003876 Register low_reg = source.IsRegisterPair()
3877 ? source.AsRegisterPairLow<Register>()
3878 : destination.AsRegisterPairLow<Register>();
3879 int mem = source.IsRegisterPair()
3880 ? destination.GetStackIndex()
3881 : source.GetStackIndex();
3882 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003883 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003884 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003885 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003886 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003887 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3888 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003889 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003890 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003891 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003892 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3893 DRegister reg = source.IsFpuRegisterPair()
3894 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3895 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3896 int mem = source.IsFpuRegisterPair()
3897 ? destination.GetStackIndex()
3898 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003899 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003900 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003901 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003902 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3903 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3904 : destination.AsFpuRegister<SRegister>();
3905 int mem = source.IsFpuRegister()
3906 ? destination.GetStackIndex()
3907 : source.GetStackIndex();
3908
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003909 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003910 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003911 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003912 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003913 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3914 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003915 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003916 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003917 }
3918}
3919
3920void ParallelMoveResolverARM::SpillScratch(int reg) {
3921 __ Push(static_cast<Register>(reg));
3922}
3923
3924void ParallelMoveResolverARM::RestoreScratch(int reg) {
3925 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003926}
3927
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003928void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003929 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3930 ? LocationSummary::kCallOnSlowPath
3931 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003932 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003933 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003934 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003935 locations->SetOut(Location::RequiresRegister());
3936}
3937
3938void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003939 LocationSummary* locations = cls->GetLocations();
3940 Register out = locations->Out().AsRegister<Register>();
3941 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003942 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003943 DCHECK(!cls->CanCallRuntime());
3944 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003945 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07003946 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003947 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003948 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003949 __ LoadFromOffset(kLoadWord,
3950 out,
3951 current_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -07003952 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003953 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003954
3955 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3956 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3957 codegen_->AddSlowPath(slow_path);
3958 __ cmp(out, ShifterOperand(0));
3959 __ b(slow_path->GetEntryLabel(), EQ);
3960 if (cls->MustGenerateClinitCheck()) {
3961 GenerateClassInitializationCheck(slow_path, out);
3962 } else {
3963 __ Bind(slow_path->GetExitLabel());
3964 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003965 }
3966}
3967
3968void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3969 LocationSummary* locations =
3970 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3971 locations->SetInAt(0, Location::RequiresRegister());
3972 if (check->HasUses()) {
3973 locations->SetOut(Location::SameAsFirstInput());
3974 }
3975}
3976
3977void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003978 // We assume the class is not null.
3979 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3980 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003981 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003982 GenerateClassInitializationCheck(slow_path,
3983 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003984}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003985
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003986void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3987 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003988 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3989 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3990 __ b(slow_path->GetEntryLabel(), LT);
3991 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3992 // properly. Therefore, we do a memory fence.
3993 __ dmb(ISH);
3994 __ Bind(slow_path->GetExitLabel());
3995}
3996
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003997void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3998 LocationSummary* locations =
3999 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004000 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004001 locations->SetOut(Location::RequiresRegister());
4002}
4003
4004void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
4005 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
4006 codegen_->AddSlowPath(slow_path);
4007
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004008 LocationSummary* locations = load->GetLocations();
4009 Register out = locations->Out().AsRegister<Register>();
4010 Register current_method = locations->InAt(0).AsRegister<Register>();
4011 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004012 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004013 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004014 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
4015 __ cmp(out, ShifterOperand(0));
4016 __ b(slow_path->GetEntryLabel(), EQ);
4017 __ Bind(slow_path->GetExitLabel());
4018}
4019
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004020void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4021 LocationSummary* locations =
4022 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4023 locations->SetOut(Location::RequiresRegister());
4024}
4025
4026void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004027 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004028 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4029 __ LoadFromOffset(kLoadWord, out, TR, offset);
4030 __ LoadImmediate(IP, 0);
4031 __ StoreToOffset(kStoreWord, IP, TR, offset);
4032}
4033
4034void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4035 LocationSummary* locations =
4036 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4037 InvokeRuntimeCallingConvention calling_convention;
4038 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4039}
4040
4041void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4042 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004043 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004044}
4045
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004046void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004047 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4048 ? LocationSummary::kNoCall
4049 : LocationSummary::kCallOnSlowPath;
4050 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4051 locations->SetInAt(0, Location::RequiresRegister());
4052 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004053 // The out register is used as a temporary, so it overlaps with the inputs.
4054 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004055}
4056
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004057void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004058 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004059 Register obj = locations->InAt(0).AsRegister<Register>();
4060 Register cls = locations->InAt(1).AsRegister<Register>();
4061 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004062 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004063 NearLabel done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004064 SlowPathCodeARM* slow_path = nullptr;
4065
4066 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004067 // avoid null check if we know obj is not null.
4068 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004069 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004070 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004071 // Compare the class of `obj` with `cls`.
4072 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
4073 __ cmp(out, ShifterOperand(cls));
4074 if (instruction->IsClassFinal()) {
4075 // Classes must be equal for the instanceof to succeed.
4076 __ b(&zero, NE);
4077 __ LoadImmediate(out, 1);
4078 __ b(&done);
4079 } else {
4080 // If the classes are not equal, we go into a slow path.
4081 DCHECK(locations->OnlyCallsOnSlowPath());
4082 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004083 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004084 codegen_->AddSlowPath(slow_path);
4085 __ b(slow_path->GetEntryLabel(), NE);
4086 __ LoadImmediate(out, 1);
4087 __ b(&done);
4088 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004089
4090 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4091 __ Bind(&zero);
4092 __ LoadImmediate(out, 0);
4093 }
4094
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004095 if (slow_path != nullptr) {
4096 __ Bind(slow_path->GetExitLabel());
4097 }
4098 __ Bind(&done);
4099}
4100
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004101void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4102 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4103 instruction, LocationSummary::kCallOnSlowPath);
4104 locations->SetInAt(0, Location::RequiresRegister());
4105 locations->SetInAt(1, Location::RequiresRegister());
4106 locations->AddTemp(Location::RequiresRegister());
4107}
4108
4109void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4110 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004111 Register obj = locations->InAt(0).AsRegister<Register>();
4112 Register cls = locations->InAt(1).AsRegister<Register>();
4113 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004114 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4115
4116 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4117 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
4118 codegen_->AddSlowPath(slow_path);
4119
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004120 NearLabel done;
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004121 // avoid null check if we know obj is not null.
4122 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004123 __ CompareAndBranchIfZero(obj, &done);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004124 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004125 // Compare the class of `obj` with `cls`.
4126 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
4127 __ cmp(temp, ShifterOperand(cls));
4128 __ b(slow_path->GetEntryLabel(), NE);
4129 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004130 if (instruction->MustDoNullCheck()) {
4131 __ Bind(&done);
4132 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004133}
4134
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004135void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4136 LocationSummary* locations =
4137 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4138 InvokeRuntimeCallingConvention calling_convention;
4139 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4140}
4141
4142void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4143 codegen_->InvokeRuntime(instruction->IsEnter()
4144 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4145 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004146 instruction->GetDexPc(),
4147 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004148}
4149
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004150void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4151void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4152void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4153
4154void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4155 LocationSummary* locations =
4156 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4157 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4158 || instruction->GetResultType() == Primitive::kPrimLong);
4159 locations->SetInAt(0, Location::RequiresRegister());
4160 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004161 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004162}
4163
4164void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4165 HandleBitwiseOperation(instruction);
4166}
4167
4168void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4169 HandleBitwiseOperation(instruction);
4170}
4171
4172void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4173 HandleBitwiseOperation(instruction);
4174}
4175
4176void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4177 LocationSummary* locations = instruction->GetLocations();
4178
4179 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004180 Register first = locations->InAt(0).AsRegister<Register>();
4181 Register second = locations->InAt(1).AsRegister<Register>();
4182 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004183 if (instruction->IsAnd()) {
4184 __ and_(out, first, ShifterOperand(second));
4185 } else if (instruction->IsOr()) {
4186 __ orr(out, first, ShifterOperand(second));
4187 } else {
4188 DCHECK(instruction->IsXor());
4189 __ eor(out, first, ShifterOperand(second));
4190 }
4191 } else {
4192 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4193 Location first = locations->InAt(0);
4194 Location second = locations->InAt(1);
4195 Location out = locations->Out();
4196 if (instruction->IsAnd()) {
4197 __ and_(out.AsRegisterPairLow<Register>(),
4198 first.AsRegisterPairLow<Register>(),
4199 ShifterOperand(second.AsRegisterPairLow<Register>()));
4200 __ and_(out.AsRegisterPairHigh<Register>(),
4201 first.AsRegisterPairHigh<Register>(),
4202 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4203 } else if (instruction->IsOr()) {
4204 __ orr(out.AsRegisterPairLow<Register>(),
4205 first.AsRegisterPairLow<Register>(),
4206 ShifterOperand(second.AsRegisterPairLow<Register>()));
4207 __ orr(out.AsRegisterPairHigh<Register>(),
4208 first.AsRegisterPairHigh<Register>(),
4209 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4210 } else {
4211 DCHECK(instruction->IsXor());
4212 __ eor(out.AsRegisterPairLow<Register>(),
4213 first.AsRegisterPairLow<Register>(),
4214 ShifterOperand(second.AsRegisterPairLow<Register>()));
4215 __ eor(out.AsRegisterPairHigh<Register>(),
4216 first.AsRegisterPairHigh<Register>(),
4217 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4218 }
4219 }
4220}
4221
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004222void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
4223 DCHECK_EQ(temp, kArtMethodRegister);
4224
4225 // TODO: Implement all kinds of calls:
4226 // 1) boot -> boot
4227 // 2) app -> boot
4228 // 3) app -> app
4229 //
4230 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4231
Jeff Hao848f70a2014-01-15 13:49:50 -08004232 if (invoke->IsStringInit()) {
4233 // temp = thread->string_init_entrypoint
4234 __ LoadFromOffset(kLoadWord, temp, TR, invoke->GetStringInitOffset());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004235 // LR = temp[offset_of_quick_compiled_code]
4236 __ LoadFromOffset(kLoadWord, LR, temp,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004237 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004238 kArmWordSize).Int32Value());
4239 // LR()
4240 __ blx(LR);
4241 } else {
Jeff Hao848f70a2014-01-15 13:49:50 -08004242 // temp = method;
4243 LoadCurrentMethod(temp);
4244 if (!invoke->IsRecursive()) {
4245 // temp = temp->dex_cache_resolved_methods_;
4246 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004247 kLoadWord, temp, temp, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Jeff Hao848f70a2014-01-15 13:49:50 -08004248 // temp = temp[index_in_cache]
4249 __ LoadFromOffset(
4250 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4251 // LR = temp[offset_of_quick_compiled_code]
Mathieu Chartiere401d142015-04-22 13:56:20 -07004252 __ LoadFromOffset(kLoadWord, LR, temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4253 kArmWordSize).Int32Value());
Jeff Hao848f70a2014-01-15 13:49:50 -08004254 // LR()
4255 __ blx(LR);
4256 } else {
4257 __ bl(GetFrameEntryLabel());
4258 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004259 }
4260
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004261 DCHECK(!IsLeafMethod());
4262}
4263
Calin Juravleb1498f62015-02-16 13:13:29 +00004264void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4265 // Nothing to do, this should be removed during prepare for register allocator.
4266 UNUSED(instruction);
4267 LOG(FATAL) << "Unreachable";
4268}
4269
4270void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4271 // Nothing to do, this should be removed during prepare for register allocator.
4272 UNUSED(instruction);
4273 LOG(FATAL) << "Unreachable";
4274}
4275
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004276} // namespace arm
4277} // namespace art