blob: bb5debba29df867a982702b4b6cff7cc39d09674 [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),
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000395 assembler_(),
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
Vladimir Markocf93a5c2015-06-16 11:33:24 +0000401void CodeGeneratorARM::Finalize(CodeAllocator* allocator) {
402 // Ensure that we fix up branches and literal loads and emit the literal pool.
403 __ FinalizeCode();
404
405 // Adjust native pc offsets in stack maps.
406 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
407 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
408 uint32_t new_position = __ GetAdjustedPosition(old_position);
409 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
410 }
411 // Adjust native pc offsets of block labels.
412 for (size_t block_idx = 0u, end = block_order_->Size(); block_idx != end; ++block_idx) {
413 HBasicBlock* block = block_order_->Get(block_idx);
414 // Get the label directly from block_labels_ rather than through GetLabelOf() to avoid
415 // FirstNonEmptyBlock() which could lead to adjusting a label more than once.
416 DCHECK_LT(static_cast<size_t>(block->GetBlockId()), block_labels_.Size());
417 Label* block_label = &block_labels_.GetRawStorage()[block->GetBlockId()];
418 DCHECK_EQ(block_label->IsBound(), !block->IsSingleGoto());
419 if (block_label->IsBound()) {
420 __ AdjustLabelPosition(block_label);
421 }
422 }
423
424 CodeGenerator::Finalize(allocator);
425}
426
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100427Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100428 switch (type) {
429 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100430 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100431 ArmManagedRegister pair =
432 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100433 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
434 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
435
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100436 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
437 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100438 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100439 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100440 }
441
442 case Primitive::kPrimByte:
443 case Primitive::kPrimBoolean:
444 case Primitive::kPrimChar:
445 case Primitive::kPrimShort:
446 case Primitive::kPrimInt:
447 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100448 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100449 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100450 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
451 ArmManagedRegister current =
452 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
453 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100454 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100455 }
456 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100457 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100458 }
459
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000460 case Primitive::kPrimFloat: {
461 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100462 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100463 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100464
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000465 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000466 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
467 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000468 return Location::FpuRegisterPairLocation(reg, reg + 1);
469 }
470
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100471 case Primitive::kPrimVoid:
472 LOG(FATAL) << "Unreachable type " << type;
473 }
474
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100475 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100476}
477
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000478void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100479 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100480 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100481
482 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100483 blocked_core_registers_[SP] = true;
484 blocked_core_registers_[LR] = true;
485 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100486
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100487 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100488 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100489
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100490 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100491 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100492
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000493 if (is_baseline) {
494 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
495 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
496 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000497
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000498 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
499
500 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
501 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
502 }
503 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100504
505 UpdateBlockedPairRegisters();
506}
507
508void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
509 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
510 ArmManagedRegister current =
511 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
512 if (blocked_core_registers_[current.AsRegisterPairLow()]
513 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
514 blocked_register_pairs_[i] = true;
515 }
516 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100517}
518
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100519InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
520 : HGraphVisitor(graph),
521 assembler_(codegen->GetAssembler()),
522 codegen_(codegen) {}
523
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000524void CodeGeneratorARM::ComputeSpillMask() {
525 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000526 // Save one extra register for baseline. Note that on thumb2, there is no easy
527 // instruction to restore just the PC, so this actually helps both baseline
528 // and non-baseline to save and restore at least two registers at entry and exit.
529 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000530 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
531 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
532 // We use vpush and vpop for saving and restoring floating point registers, which take
533 // a SRegister and the number of registers to save/restore after that SRegister. We
534 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
535 // but in the range.
536 if (fpu_spill_mask_ != 0) {
537 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
538 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
539 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
540 fpu_spill_mask_ |= (1 << i);
541 }
542 }
543}
544
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100545static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100546 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100547}
548
549static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100550 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100551}
552
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000553void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000554 bool skip_overflow_check =
555 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000556 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000557 __ Bind(&frame_entry_label_);
558
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000559 if (HasEmptyFrame()) {
560 return;
561 }
562
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100563 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000564 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
565 __ LoadFromOffset(kLoadWord, IP, IP, 0);
566 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100567 }
568
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000569 // PC is in the list of callee-save to mimic Quick, but we need to push
570 // LR at entry instead.
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100571 uint32_t push_mask = (core_spill_mask_ & (~(1 << PC))) | 1 << LR;
572 __ PushList(push_mask);
573 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(push_mask));
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100574 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, push_mask, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000575 if (fpu_spill_mask_ != 0) {
576 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
577 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100578 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100579 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000580 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100581 int adjust = GetFrameSize() - FrameEntrySpillSize();
582 __ AddConstant(SP, -adjust);
583 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100584 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000585}
586
587void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000588 if (HasEmptyFrame()) {
589 __ bx(LR);
590 return;
591 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100592 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100593 int adjust = GetFrameSize() - FrameEntrySpillSize();
594 __ AddConstant(SP, adjust);
595 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000596 if (fpu_spill_mask_ != 0) {
597 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
598 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100599 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
600 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000601 }
602 __ PopList(core_spill_mask_);
David Srbeckyc34dc932015-04-12 09:27:43 +0100603 __ cfi().RestoreState();
604 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000605}
606
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100607void CodeGeneratorARM::Bind(HBasicBlock* block) {
608 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000609}
610
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100611Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
612 switch (load->GetType()) {
613 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100614 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100615 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100616
617 case Primitive::kPrimInt:
618 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100619 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100620 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100621
622 case Primitive::kPrimBoolean:
623 case Primitive::kPrimByte:
624 case Primitive::kPrimChar:
625 case Primitive::kPrimShort:
626 case Primitive::kPrimVoid:
627 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700628 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100629 }
630
631 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700632 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100633}
634
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100635Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100636 switch (type) {
637 case Primitive::kPrimBoolean:
638 case Primitive::kPrimByte:
639 case Primitive::kPrimChar:
640 case Primitive::kPrimShort:
641 case Primitive::kPrimInt:
642 case Primitive::kPrimNot: {
643 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000644 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100645 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100646 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100647 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000648 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100649 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100650 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100651
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000652 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100653 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000654 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100655 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000656 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100657 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000658 if (calling_convention.GetRegisterAt(index) == R1) {
659 // Skip R1, and use R2_R3 instead.
660 gp_index_++;
661 index++;
662 }
663 }
664 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
665 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000666 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000667 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000668 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100669 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000670 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
671 }
672 }
673
674 case Primitive::kPrimFloat: {
675 uint32_t stack_index = stack_index_++;
676 if (float_index_ % 2 == 0) {
677 float_index_ = std::max(double_index_, float_index_);
678 }
679 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
680 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
681 } else {
682 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
683 }
684 }
685
686 case Primitive::kPrimDouble: {
687 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
688 uint32_t stack_index = stack_index_;
689 stack_index_ += 2;
690 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
691 uint32_t index = double_index_;
692 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000693 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000694 calling_convention.GetFpuRegisterAt(index),
695 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000696 DCHECK(ExpectedPairLayout(result));
697 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000698 } else {
699 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100700 }
701 }
702
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100703 case Primitive::kPrimVoid:
704 LOG(FATAL) << "Unexpected parameter type " << type;
705 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100706 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100707 return Location();
708}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100709
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100710Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000711 switch (type) {
712 case Primitive::kPrimBoolean:
713 case Primitive::kPrimByte:
714 case Primitive::kPrimChar:
715 case Primitive::kPrimShort:
716 case Primitive::kPrimInt:
717 case Primitive::kPrimNot: {
718 return Location::RegisterLocation(R0);
719 }
720
721 case Primitive::kPrimFloat: {
722 return Location::FpuRegisterLocation(S0);
723 }
724
725 case Primitive::kPrimLong: {
726 return Location::RegisterPairLocation(R0, R1);
727 }
728
729 case Primitive::kPrimDouble: {
730 return Location::FpuRegisterPairLocation(S0, S1);
731 }
732
733 case Primitive::kPrimVoid:
734 return Location();
735 }
Nicolas Geoffray0d1652e2015-06-03 12:12:19 +0100736
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000737 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000738}
739
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100740Location InvokeDexCallingConventionVisitorARM::GetMethodLocation() const {
741 return Location::RegisterLocation(kMethodRegisterArgument);
742}
743
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100744void CodeGeneratorARM::Move32(Location destination, Location source) {
745 if (source.Equals(destination)) {
746 return;
747 }
748 if (destination.IsRegister()) {
749 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000750 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100751 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000752 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100753 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000754 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100755 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100756 } else if (destination.IsFpuRegister()) {
757 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000758 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100759 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000760 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100761 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000762 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100763 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100764 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000765 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100766 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000767 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100768 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000769 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100770 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000771 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100772 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
773 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100774 }
775 }
776}
777
778void CodeGeneratorARM::Move64(Location destination, Location source) {
779 if (source.Equals(destination)) {
780 return;
781 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100782 if (destination.IsRegisterPair()) {
783 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000784 EmitParallelMoves(
785 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
786 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100787 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000788 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100789 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
790 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100791 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000792 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100793 } else {
794 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000795 DCHECK(ExpectedPairLayout(destination));
796 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
797 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100798 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000799 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100800 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000801 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
802 SP,
803 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100804 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000805 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100806 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100807 } else {
808 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100809 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000810 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100811 if (source.AsRegisterPairLow<Register>() == R1) {
812 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100813 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
814 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100815 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100816 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100817 SP, destination.GetStackIndex());
818 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000819 } else if (source.IsFpuRegisterPair()) {
820 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
821 SP,
822 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100823 } else {
824 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000825 EmitParallelMoves(
826 Location::StackSlot(source.GetStackIndex()),
827 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100828 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000829 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100830 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
831 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100832 }
833 }
834}
835
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100836void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100837 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100838 if (instruction->IsCurrentMethod()) {
839 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
840 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100841 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100842 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000843 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000844 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
845 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000846 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000847 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000848 } else {
849 DCHECK(location.IsStackSlot());
850 __ LoadImmediate(IP, value);
851 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
852 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000853 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000854 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000855 int64_t value = const_to_move->AsLongConstant()->GetValue();
856 if (location.IsRegisterPair()) {
857 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
858 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
859 } else {
860 DCHECK(location.IsDoubleStackSlot());
861 __ LoadImmediate(IP, Low32Bits(value));
862 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
863 __ LoadImmediate(IP, High32Bits(value));
864 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
865 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100866 }
Roland Levillain476df552014-10-09 17:51:36 +0100867 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100868 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
869 switch (instruction->GetType()) {
870 case Primitive::kPrimBoolean:
871 case Primitive::kPrimByte:
872 case Primitive::kPrimChar:
873 case Primitive::kPrimShort:
874 case Primitive::kPrimInt:
875 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100876 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100877 Move32(location, Location::StackSlot(stack_slot));
878 break;
879
880 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100881 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100882 Move64(location, Location::DoubleStackSlot(stack_slot));
883 break;
884
885 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100886 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100887 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000888 } else if (instruction->IsTemporary()) {
889 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000890 if (temp_location.IsStackSlot()) {
891 Move32(location, temp_location);
892 } else {
893 DCHECK(temp_location.IsDoubleStackSlot());
894 Move64(location, temp_location);
895 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000896 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100897 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100898 switch (instruction->GetType()) {
899 case Primitive::kPrimBoolean:
900 case Primitive::kPrimByte:
901 case Primitive::kPrimChar:
902 case Primitive::kPrimShort:
903 case Primitive::kPrimNot:
904 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100905 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100906 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100907 break;
908
909 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100910 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100911 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100912 break;
913
914 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100915 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100916 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000917 }
918}
919
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100920void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
921 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000922 uint32_t dex_pc,
923 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100924 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
925 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000926 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100927 DCHECK(instruction->IsSuspendCheck()
928 || instruction->IsBoundsCheck()
929 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000930 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000931 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100932 || !IsLeafMethod());
933}
934
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000935void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000936 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000937}
938
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000939void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000940 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100941 DCHECK(!successor->IsExitBlock());
942
943 HBasicBlock* block = got->GetBlock();
944 HInstruction* previous = got->GetPrevious();
945
946 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000947 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100948 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
949 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
950 return;
951 }
952
953 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
954 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
955 }
956 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000957 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000958 }
959}
960
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000961void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000962 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000963}
964
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000965void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700966 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000967}
968
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700969void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
970 Label* true_target,
971 Label* false_target,
972 Label* always_true_target) {
973 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100974 if (cond->IsIntConstant()) {
975 // Constant condition, statically compared against 1.
976 int32_t cond_value = cond->AsIntConstant()->GetValue();
977 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700978 if (always_true_target != nullptr) {
979 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100980 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100981 return;
982 } else {
983 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100984 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100985 } else {
986 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
987 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700988 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
989 __ cmp(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100990 ShifterOperand(0));
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700991 __ b(true_target, NE);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100992 } else {
993 // Condition has not been materialized, use its inputs as the
994 // comparison and its condition as the branch condition.
995 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000996 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000997 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100998 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000999 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001000 } else {
1001 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001002 HConstant* constant = locations->InAt(1).GetConstant();
1003 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001004 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001005 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1006 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001007 } else {
1008 Register temp = IP;
1009 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001010 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001011 }
1012 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001013 __ b(true_target, ARMCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001014 }
Dave Allison20dfc792014-06-16 20:44:29 -07001015 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001016 if (false_target != nullptr) {
1017 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001018 }
1019}
1020
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001021void LocationsBuilderARM::VisitIf(HIf* if_instr) {
1022 LocationSummary* locations =
1023 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
1024 HInstruction* cond = if_instr->InputAt(0);
1025 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1026 locations->SetInAt(0, Location::RequiresRegister());
1027 }
1028}
1029
1030void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1031 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1032 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1033 Label* always_true_target = true_target;
1034 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1035 if_instr->IfTrueSuccessor())) {
1036 always_true_target = nullptr;
1037 }
1038 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1039 if_instr->IfFalseSuccessor())) {
1040 false_target = nullptr;
1041 }
1042 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1043}
1044
1045void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1046 LocationSummary* locations = new (GetGraph()->GetArena())
1047 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1048 HInstruction* cond = deoptimize->InputAt(0);
1049 DCHECK(cond->IsCondition());
1050 if (cond->AsCondition()->NeedsMaterialization()) {
1051 locations->SetInAt(0, Location::RequiresRegister());
1052 }
1053}
1054
1055void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1056 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1057 DeoptimizationSlowPathARM(deoptimize);
1058 codegen_->AddSlowPath(slow_path);
1059 Label* slow_path_entry = slow_path->GetEntryLabel();
1060 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1061}
Dave Allison20dfc792014-06-16 20:44:29 -07001062
Roland Levillain0d37cd02015-05-27 16:39:19 +01001063void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001064 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001065 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001066 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain0d37cd02015-05-27 16:39:19 +01001067 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1068 if (cond->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001069 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001070 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001071}
1072
Roland Levillain0d37cd02015-05-27 16:39:19 +01001073void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
1074 if (!cond->NeedsMaterialization()) return;
1075 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001076 Register left = locations->InAt(0).AsRegister<Register>();
1077
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001078 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001079 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001080 } else {
1081 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -08001082 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001083 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001084 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1085 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001086 } else {
1087 Register temp = IP;
1088 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001089 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001090 }
Dave Allison20dfc792014-06-16 20:44:29 -07001091 }
Roland Levillain0d37cd02015-05-27 16:39:19 +01001092 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001093 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001094 ARMCondition(cond->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001095 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001096 ARMOppositeCondition(cond->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001097}
1098
1099void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1100 VisitCondition(comp);
1101}
1102
1103void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1104 VisitCondition(comp);
1105}
1106
1107void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1108 VisitCondition(comp);
1109}
1110
1111void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1112 VisitCondition(comp);
1113}
1114
1115void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1116 VisitCondition(comp);
1117}
1118
1119void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1120 VisitCondition(comp);
1121}
1122
1123void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1124 VisitCondition(comp);
1125}
1126
1127void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1128 VisitCondition(comp);
1129}
1130
1131void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1132 VisitCondition(comp);
1133}
1134
1135void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1136 VisitCondition(comp);
1137}
1138
1139void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1140 VisitCondition(comp);
1141}
1142
1143void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1144 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001145}
1146
1147void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001148 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001149}
1150
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001151void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1152 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001153}
1154
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001155void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001156 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001157}
1158
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001159void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001160 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001161 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001162}
1163
1164void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001165 LocationSummary* locations =
1166 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001167 switch (store->InputAt(1)->GetType()) {
1168 case Primitive::kPrimBoolean:
1169 case Primitive::kPrimByte:
1170 case Primitive::kPrimChar:
1171 case Primitive::kPrimShort:
1172 case Primitive::kPrimInt:
1173 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001174 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001175 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1176 break;
1177
1178 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001179 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001180 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1181 break;
1182
1183 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001184 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001185 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001186}
1187
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001188void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001189 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001190}
1191
1192void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001193 LocationSummary* locations =
1194 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001195 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001196}
1197
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001198void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001199 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001200 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001201}
1202
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001203void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1204 LocationSummary* locations =
1205 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1206 locations->SetOut(Location::ConstantLocation(constant));
1207}
1208
1209void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1210 // Will be generated at use site.
1211 UNUSED(constant);
1212}
1213
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001214void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001215 LocationSummary* locations =
1216 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001217 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001218}
1219
1220void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1221 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001222 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001223}
1224
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001225void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1226 LocationSummary* locations =
1227 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1228 locations->SetOut(Location::ConstantLocation(constant));
1229}
1230
1231void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1232 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001233 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001234}
1235
1236void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1237 LocationSummary* locations =
1238 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1239 locations->SetOut(Location::ConstantLocation(constant));
1240}
1241
1242void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1243 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001244 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001245}
1246
Calin Juravle27df7582015-04-17 19:12:31 +01001247void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1248 memory_barrier->SetLocations(nullptr);
1249}
1250
1251void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1252 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1253}
1254
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001255void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001256 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001257}
1258
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001259void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001260 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001261 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001262}
1263
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001264void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001265 LocationSummary* locations =
1266 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001267 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001268}
1269
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001270void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001271 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001272 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001273}
1274
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001275void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001276 // When we do not run baseline, explicit clinit checks triggered by static
1277 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1278 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001279
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001280 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1281 codegen_->GetInstructionSetFeatures());
1282 if (intrinsic.TryDispatch(invoke)) {
1283 return;
1284 }
1285
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001286 HandleInvoke(invoke);
1287}
1288
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001289static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1290 if (invoke->GetLocations()->Intrinsified()) {
1291 IntrinsicCodeGeneratorARM intrinsic(codegen);
1292 intrinsic.Dispatch(invoke);
1293 return true;
1294 }
1295 return false;
1296}
1297
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001298void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001299 // When we do not run baseline, explicit clinit checks triggered by static
1300 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1301 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001302
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001303 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1304 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001305 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001306
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001307 LocationSummary* locations = invoke->GetLocations();
1308 codegen_->GenerateStaticOrDirectCall(
1309 invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001310 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001311}
1312
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001313void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001314 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +01001315 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001316}
1317
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001318void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001319 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1320 codegen_->GetInstructionSetFeatures());
1321 if (intrinsic.TryDispatch(invoke)) {
1322 return;
1323 }
1324
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001325 HandleInvoke(invoke);
1326}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001327
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001328void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001329 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1330 return;
1331 }
1332
Roland Levillain271ab9c2014-11-27 15:23:57 +00001333 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001334 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
1335 invoke->GetVTableIndex(), kArmPointerSize).Uint32Value();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001336 LocationSummary* locations = invoke->GetLocations();
1337 Location receiver = locations->InAt(0);
1338 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1339 // temp = object->GetClass();
Nicolas Geoffray38207af2015-06-01 15:46:22 +01001340 DCHECK(receiver.IsRegister());
1341 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00001342 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001343 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001344 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001345 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001346 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001347 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001348 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001349 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001350 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001351 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001352 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001353}
1354
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001355void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1356 HandleInvoke(invoke);
1357 // Add the hidden argument.
1358 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1359}
1360
1361void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1362 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001363 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001364 uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset(
1365 invoke->GetImtIndex() % mirror::Class::kImtSize, kArmPointerSize).Uint32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001366 LocationSummary* locations = invoke->GetLocations();
1367 Location receiver = locations->InAt(0);
1368 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1369
1370 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001371 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1372 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001373
1374 // temp = object->GetClass();
1375 if (receiver.IsStackSlot()) {
1376 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1377 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1378 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001379 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001380 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001381 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001382 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartiere401d142015-04-22 13:56:20 -07001383 uint32_t entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001384 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001385 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1386 // LR = temp->GetEntryPoint();
1387 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1388 // LR();
1389 __ blx(LR);
1390 DCHECK(!codegen_->IsLeafMethod());
1391 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1392}
1393
Roland Levillain88cb1752014-10-20 16:36:47 +01001394void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1395 LocationSummary* locations =
1396 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1397 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001398 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001399 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001400 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1401 break;
1402 }
1403 case Primitive::kPrimLong: {
1404 locations->SetInAt(0, Location::RequiresRegister());
1405 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001406 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001407 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001408
Roland Levillain88cb1752014-10-20 16:36:47 +01001409 case Primitive::kPrimFloat:
1410 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001411 locations->SetInAt(0, Location::RequiresFpuRegister());
1412 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001413 break;
1414
1415 default:
1416 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1417 }
1418}
1419
1420void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1421 LocationSummary* locations = neg->GetLocations();
1422 Location out = locations->Out();
1423 Location in = locations->InAt(0);
1424 switch (neg->GetResultType()) {
1425 case Primitive::kPrimInt:
1426 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001427 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001428 break;
1429
1430 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001431 DCHECK(in.IsRegisterPair());
1432 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1433 __ rsbs(out.AsRegisterPairLow<Register>(),
1434 in.AsRegisterPairLow<Register>(),
1435 ShifterOperand(0));
1436 // We cannot emit an RSC (Reverse Subtract with Carry)
1437 // instruction here, as it does not exist in the Thumb-2
1438 // instruction set. We use the following approach
1439 // using SBC and SUB instead.
1440 //
1441 // out.hi = -C
1442 __ sbc(out.AsRegisterPairHigh<Register>(),
1443 out.AsRegisterPairHigh<Register>(),
1444 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1445 // out.hi = out.hi - in.hi
1446 __ sub(out.AsRegisterPairHigh<Register>(),
1447 out.AsRegisterPairHigh<Register>(),
1448 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1449 break;
1450
Roland Levillain88cb1752014-10-20 16:36:47 +01001451 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001452 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001453 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001454 break;
1455
Roland Levillain88cb1752014-10-20 16:36:47 +01001456 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001457 DCHECK(in.IsFpuRegisterPair());
1458 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1459 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001460 break;
1461
1462 default:
1463 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1464 }
1465}
1466
Roland Levillaindff1f282014-11-05 14:15:05 +00001467void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001468 Primitive::Type result_type = conversion->GetResultType();
1469 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001470 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001471
Roland Levillain5b3ee562015-04-14 16:02:41 +01001472 // The float-to-long, double-to-long and long-to-float type conversions
1473 // rely on a call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001474 LocationSummary::CallKind call_kind =
Roland Levillain5b3ee562015-04-14 16:02:41 +01001475 (((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1476 && result_type == Primitive::kPrimLong)
1477 || (input_type == Primitive::kPrimLong && result_type == Primitive::kPrimFloat))
Roland Levillain624279f2014-12-04 11:54:28 +00001478 ? LocationSummary::kCall
1479 : LocationSummary::kNoCall;
1480 LocationSummary* locations =
1481 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1482
David Brazdilb2bd1c52015-03-25 11:17:37 +00001483 // The Java language does not allow treating boolean as an integral type but
1484 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001485
Roland Levillaindff1f282014-11-05 14:15:05 +00001486 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001487 case Primitive::kPrimByte:
1488 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001489 case Primitive::kPrimBoolean:
1490 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001491 case Primitive::kPrimShort:
1492 case Primitive::kPrimInt:
1493 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001494 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001495 locations->SetInAt(0, Location::RequiresRegister());
1496 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1497 break;
1498
1499 default:
1500 LOG(FATAL) << "Unexpected type conversion from " << input_type
1501 << " to " << result_type;
1502 }
1503 break;
1504
Roland Levillain01a8d712014-11-14 16:27:39 +00001505 case Primitive::kPrimShort:
1506 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001507 case Primitive::kPrimBoolean:
1508 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001509 case Primitive::kPrimByte:
1510 case Primitive::kPrimInt:
1511 case Primitive::kPrimChar:
1512 // Processing a Dex `int-to-short' instruction.
1513 locations->SetInAt(0, Location::RequiresRegister());
1514 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1515 break;
1516
1517 default:
1518 LOG(FATAL) << "Unexpected type conversion from " << input_type
1519 << " to " << result_type;
1520 }
1521 break;
1522
Roland Levillain946e1432014-11-11 17:35:19 +00001523 case Primitive::kPrimInt:
1524 switch (input_type) {
1525 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001526 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001527 locations->SetInAt(0, Location::Any());
1528 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1529 break;
1530
1531 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001532 // Processing a Dex `float-to-int' instruction.
1533 locations->SetInAt(0, Location::RequiresFpuRegister());
1534 locations->SetOut(Location::RequiresRegister());
1535 locations->AddTemp(Location::RequiresFpuRegister());
1536 break;
1537
Roland Levillain946e1432014-11-11 17:35:19 +00001538 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001539 // Processing a Dex `double-to-int' instruction.
1540 locations->SetInAt(0, Location::RequiresFpuRegister());
1541 locations->SetOut(Location::RequiresRegister());
1542 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001543 break;
1544
1545 default:
1546 LOG(FATAL) << "Unexpected type conversion from " << input_type
1547 << " to " << result_type;
1548 }
1549 break;
1550
Roland Levillaindff1f282014-11-05 14:15:05 +00001551 case Primitive::kPrimLong:
1552 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001553 case Primitive::kPrimBoolean:
1554 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001555 case Primitive::kPrimByte:
1556 case Primitive::kPrimShort:
1557 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001558 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001559 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001560 locations->SetInAt(0, Location::RequiresRegister());
1561 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1562 break;
1563
Roland Levillain624279f2014-12-04 11:54:28 +00001564 case Primitive::kPrimFloat: {
1565 // Processing a Dex `float-to-long' instruction.
1566 InvokeRuntimeCallingConvention calling_convention;
1567 locations->SetInAt(0, Location::FpuRegisterLocation(
1568 calling_convention.GetFpuRegisterAt(0)));
1569 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1570 break;
1571 }
1572
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001573 case Primitive::kPrimDouble: {
1574 // Processing a Dex `double-to-long' instruction.
1575 InvokeRuntimeCallingConvention calling_convention;
1576 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1577 calling_convention.GetFpuRegisterAt(0),
1578 calling_convention.GetFpuRegisterAt(1)));
1579 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001580 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001581 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001582
1583 default:
1584 LOG(FATAL) << "Unexpected type conversion from " << input_type
1585 << " to " << result_type;
1586 }
1587 break;
1588
Roland Levillain981e4542014-11-14 11:47:14 +00001589 case Primitive::kPrimChar:
1590 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001591 case Primitive::kPrimBoolean:
1592 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001593 case Primitive::kPrimByte:
1594 case Primitive::kPrimShort:
1595 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001596 // Processing a Dex `int-to-char' instruction.
1597 locations->SetInAt(0, Location::RequiresRegister());
1598 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1599 break;
1600
1601 default:
1602 LOG(FATAL) << "Unexpected type conversion from " << input_type
1603 << " to " << result_type;
1604 }
1605 break;
1606
Roland Levillaindff1f282014-11-05 14:15:05 +00001607 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001608 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001609 case Primitive::kPrimBoolean:
1610 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001611 case Primitive::kPrimByte:
1612 case Primitive::kPrimShort:
1613 case Primitive::kPrimInt:
1614 case Primitive::kPrimChar:
1615 // Processing a Dex `int-to-float' instruction.
1616 locations->SetInAt(0, Location::RequiresRegister());
1617 locations->SetOut(Location::RequiresFpuRegister());
1618 break;
1619
Roland Levillain5b3ee562015-04-14 16:02:41 +01001620 case Primitive::kPrimLong: {
Roland Levillain6d0e4832014-11-27 18:31:21 +00001621 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001622 InvokeRuntimeCallingConvention calling_convention;
1623 locations->SetInAt(0, Location::RegisterPairLocation(
1624 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
1625 locations->SetOut(Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
Roland Levillain6d0e4832014-11-27 18:31:21 +00001626 break;
Roland Levillain5b3ee562015-04-14 16:02:41 +01001627 }
Roland Levillain6d0e4832014-11-27 18:31:21 +00001628
Roland Levillaincff13742014-11-17 14:32:17 +00001629 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001630 // Processing a Dex `double-to-float' instruction.
1631 locations->SetInAt(0, Location::RequiresFpuRegister());
1632 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001633 break;
1634
1635 default:
1636 LOG(FATAL) << "Unexpected type conversion from " << input_type
1637 << " to " << result_type;
1638 };
1639 break;
1640
Roland Levillaindff1f282014-11-05 14:15:05 +00001641 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001642 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001643 case Primitive::kPrimBoolean:
1644 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001645 case Primitive::kPrimByte:
1646 case Primitive::kPrimShort:
1647 case Primitive::kPrimInt:
1648 case Primitive::kPrimChar:
1649 // Processing a Dex `int-to-double' instruction.
1650 locations->SetInAt(0, Location::RequiresRegister());
1651 locations->SetOut(Location::RequiresFpuRegister());
1652 break;
1653
1654 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001655 // Processing a Dex `long-to-double' instruction.
1656 locations->SetInAt(0, Location::RequiresRegister());
1657 locations->SetOut(Location::RequiresFpuRegister());
Roland Levillain682393c2015-04-14 15:57:52 +01001658 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain647b9ed2014-11-27 12:06:00 +00001659 locations->AddTemp(Location::RequiresFpuRegister());
1660 break;
1661
Roland Levillaincff13742014-11-17 14:32:17 +00001662 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001663 // Processing a Dex `float-to-double' instruction.
1664 locations->SetInAt(0, Location::RequiresFpuRegister());
1665 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001666 break;
1667
1668 default:
1669 LOG(FATAL) << "Unexpected type conversion from " << input_type
1670 << " to " << result_type;
1671 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001672 break;
1673
1674 default:
1675 LOG(FATAL) << "Unexpected type conversion from " << input_type
1676 << " to " << result_type;
1677 }
1678}
1679
1680void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1681 LocationSummary* locations = conversion->GetLocations();
1682 Location out = locations->Out();
1683 Location in = locations->InAt(0);
1684 Primitive::Type result_type = conversion->GetResultType();
1685 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001686 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001687 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001688 case Primitive::kPrimByte:
1689 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001690 case Primitive::kPrimBoolean:
1691 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001692 case Primitive::kPrimShort:
1693 case Primitive::kPrimInt:
1694 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001695 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001696 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001697 break;
1698
1699 default:
1700 LOG(FATAL) << "Unexpected type conversion from " << input_type
1701 << " to " << result_type;
1702 }
1703 break;
1704
Roland Levillain01a8d712014-11-14 16:27:39 +00001705 case Primitive::kPrimShort:
1706 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001707 case Primitive::kPrimBoolean:
1708 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001709 case Primitive::kPrimByte:
1710 case Primitive::kPrimInt:
1711 case Primitive::kPrimChar:
1712 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001713 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001714 break;
1715
1716 default:
1717 LOG(FATAL) << "Unexpected type conversion from " << input_type
1718 << " to " << result_type;
1719 }
1720 break;
1721
Roland Levillain946e1432014-11-11 17:35:19 +00001722 case Primitive::kPrimInt:
1723 switch (input_type) {
1724 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001725 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001726 DCHECK(out.IsRegister());
1727 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001728 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001729 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001730 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001731 } else {
1732 DCHECK(in.IsConstant());
1733 DCHECK(in.GetConstant()->IsLongConstant());
1734 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001735 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001736 }
1737 break;
1738
Roland Levillain3f8f9362014-12-02 17:45:01 +00001739 case Primitive::kPrimFloat: {
1740 // Processing a Dex `float-to-int' instruction.
1741 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1742 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1743 __ vcvtis(temp, temp);
1744 __ vmovrs(out.AsRegister<Register>(), temp);
1745 break;
1746 }
1747
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001748 case Primitive::kPrimDouble: {
1749 // Processing a Dex `double-to-int' instruction.
1750 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1751 DRegister temp_d = FromLowSToD(temp_s);
1752 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1753 __ vcvtid(temp_s, temp_d);
1754 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001755 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001756 }
Roland Levillain946e1432014-11-11 17:35:19 +00001757
1758 default:
1759 LOG(FATAL) << "Unexpected type conversion from " << input_type
1760 << " to " << result_type;
1761 }
1762 break;
1763
Roland Levillaindff1f282014-11-05 14:15:05 +00001764 case Primitive::kPrimLong:
1765 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001766 case Primitive::kPrimBoolean:
1767 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001768 case Primitive::kPrimByte:
1769 case Primitive::kPrimShort:
1770 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001771 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001772 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001773 DCHECK(out.IsRegisterPair());
1774 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001775 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001776 // Sign extension.
1777 __ Asr(out.AsRegisterPairHigh<Register>(),
1778 out.AsRegisterPairLow<Register>(),
1779 31);
1780 break;
1781
1782 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001783 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001784 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1785 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001786 conversion->GetDexPc(),
1787 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001788 break;
1789
Roland Levillaindff1f282014-11-05 14:15:05 +00001790 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001791 // Processing a Dex `double-to-long' instruction.
1792 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1793 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001794 conversion->GetDexPc(),
1795 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001796 break;
1797
1798 default:
1799 LOG(FATAL) << "Unexpected type conversion from " << input_type
1800 << " to " << result_type;
1801 }
1802 break;
1803
Roland Levillain981e4542014-11-14 11:47:14 +00001804 case Primitive::kPrimChar:
1805 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001806 case Primitive::kPrimBoolean:
1807 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001808 case Primitive::kPrimByte:
1809 case Primitive::kPrimShort:
1810 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001811 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001812 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001813 break;
1814
1815 default:
1816 LOG(FATAL) << "Unexpected type conversion from " << input_type
1817 << " to " << result_type;
1818 }
1819 break;
1820
Roland Levillaindff1f282014-11-05 14:15:05 +00001821 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001822 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001823 case Primitive::kPrimBoolean:
1824 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001825 case Primitive::kPrimByte:
1826 case Primitive::kPrimShort:
1827 case Primitive::kPrimInt:
1828 case Primitive::kPrimChar: {
1829 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001830 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1831 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001832 break;
1833 }
1834
Roland Levillain5b3ee562015-04-14 16:02:41 +01001835 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001836 // Processing a Dex `long-to-float' instruction.
Roland Levillain5b3ee562015-04-14 16:02:41 +01001837 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pL2f),
1838 conversion,
1839 conversion->GetDexPc(),
1840 nullptr);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001841 break;
Roland Levillain6d0e4832014-11-27 18:31:21 +00001842
Roland Levillaincff13742014-11-17 14:32:17 +00001843 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001844 // Processing a Dex `double-to-float' instruction.
1845 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1846 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001847 break;
1848
1849 default:
1850 LOG(FATAL) << "Unexpected type conversion from " << input_type
1851 << " to " << result_type;
1852 };
1853 break;
1854
Roland Levillaindff1f282014-11-05 14:15:05 +00001855 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001856 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001857 case Primitive::kPrimBoolean:
1858 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001859 case Primitive::kPrimByte:
1860 case Primitive::kPrimShort:
1861 case Primitive::kPrimInt:
1862 case Primitive::kPrimChar: {
1863 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001864 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001865 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1866 out.AsFpuRegisterPairLow<SRegister>());
1867 break;
1868 }
1869
Roland Levillain647b9ed2014-11-27 12:06:00 +00001870 case Primitive::kPrimLong: {
1871 // Processing a Dex `long-to-double' instruction.
1872 Register low = in.AsRegisterPairLow<Register>();
1873 Register high = in.AsRegisterPairHigh<Register>();
1874 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1875 DRegister out_d = FromLowSToD(out_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001876 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001877 DRegister temp_d = FromLowSToD(temp_s);
Roland Levillain682393c2015-04-14 15:57:52 +01001878 SRegister constant_s = locations->GetTemp(1).AsFpuRegisterPairLow<SRegister>();
1879 DRegister constant_d = FromLowSToD(constant_s);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001880
Roland Levillain682393c2015-04-14 15:57:52 +01001881 // temp_d = int-to-double(high)
1882 __ vmovsr(temp_s, high);
1883 __ vcvtdi(temp_d, temp_s);
1884 // constant_d = k2Pow32EncodingForDouble
1885 __ LoadDImmediate(constant_d, bit_cast<double, int64_t>(k2Pow32EncodingForDouble));
1886 // out_d = unsigned-to-double(low)
1887 __ vmovsr(out_s, low);
1888 __ vcvtdu(out_d, out_s);
1889 // out_d += temp_d * constant_d
1890 __ vmlad(out_d, temp_d, constant_d);
Roland Levillain647b9ed2014-11-27 12:06:00 +00001891 break;
1892 }
1893
Roland Levillaincff13742014-11-17 14:32:17 +00001894 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001895 // Processing a Dex `float-to-double' instruction.
1896 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1897 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001898 break;
1899
1900 default:
1901 LOG(FATAL) << "Unexpected type conversion from " << input_type
1902 << " to " << result_type;
1903 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001904 break;
1905
1906 default:
1907 LOG(FATAL) << "Unexpected type conversion from " << input_type
1908 << " to " << result_type;
1909 }
1910}
1911
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001912void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001913 LocationSummary* locations =
1914 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001915 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001916 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001917 locations->SetInAt(0, Location::RequiresRegister());
1918 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001919 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1920 break;
1921 }
1922
1923 case Primitive::kPrimLong: {
1924 locations->SetInAt(0, Location::RequiresRegister());
1925 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001926 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001927 break;
1928 }
1929
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001930 case Primitive::kPrimFloat:
1931 case Primitive::kPrimDouble: {
1932 locations->SetInAt(0, Location::RequiresFpuRegister());
1933 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001934 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001935 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001936 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001937
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001938 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001939 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001940 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001941}
1942
1943void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1944 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001945 Location out = locations->Out();
1946 Location first = locations->InAt(0);
1947 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001948 switch (add->GetResultType()) {
1949 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001950 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001951 __ add(out.AsRegister<Register>(),
1952 first.AsRegister<Register>(),
1953 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001954 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001955 __ AddConstant(out.AsRegister<Register>(),
1956 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001957 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001958 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001959 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001960
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001961 case Primitive::kPrimLong: {
1962 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001963 __ adds(out.AsRegisterPairLow<Register>(),
1964 first.AsRegisterPairLow<Register>(),
1965 ShifterOperand(second.AsRegisterPairLow<Register>()));
1966 __ adc(out.AsRegisterPairHigh<Register>(),
1967 first.AsRegisterPairHigh<Register>(),
1968 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001969 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001970 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001971
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001972 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001973 __ vadds(out.AsFpuRegister<SRegister>(),
1974 first.AsFpuRegister<SRegister>(),
1975 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001976 break;
1977
1978 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001979 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1980 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1981 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001982 break;
1983
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001984 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001985 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001986 }
1987}
1988
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001989void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001990 LocationSummary* locations =
1991 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001992 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001993 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001994 locations->SetInAt(0, Location::RequiresRegister());
1995 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001996 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1997 break;
1998 }
1999
2000 case Primitive::kPrimLong: {
2001 locations->SetInAt(0, Location::RequiresRegister());
2002 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002003 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002004 break;
2005 }
Calin Juravle11351682014-10-23 15:38:15 +01002006 case Primitive::kPrimFloat:
2007 case Primitive::kPrimDouble: {
2008 locations->SetInAt(0, Location::RequiresFpuRegister());
2009 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002010 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002011 break;
Calin Juravle11351682014-10-23 15:38:15 +01002012 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002013 default:
Calin Juravle11351682014-10-23 15:38:15 +01002014 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002015 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002016}
2017
2018void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2019 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002020 Location out = locations->Out();
2021 Location first = locations->InAt(0);
2022 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002023 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002024 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002025 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002026 __ sub(out.AsRegister<Register>(),
2027 first.AsRegister<Register>(),
2028 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002029 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002030 __ AddConstant(out.AsRegister<Register>(),
2031 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002032 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002033 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002034 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002035 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002036
Calin Juravle11351682014-10-23 15:38:15 +01002037 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002038 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002039 __ subs(out.AsRegisterPairLow<Register>(),
2040 first.AsRegisterPairLow<Register>(),
2041 ShifterOperand(second.AsRegisterPairLow<Register>()));
2042 __ sbc(out.AsRegisterPairHigh<Register>(),
2043 first.AsRegisterPairHigh<Register>(),
2044 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002045 break;
Calin Juravle11351682014-10-23 15:38:15 +01002046 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002047
Calin Juravle11351682014-10-23 15:38:15 +01002048 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002049 __ vsubs(out.AsFpuRegister<SRegister>(),
2050 first.AsFpuRegister<SRegister>(),
2051 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002052 break;
Calin Juravle11351682014-10-23 15:38:15 +01002053 }
2054
2055 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002056 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2057 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2058 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002059 break;
2060 }
2061
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002062
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002063 default:
Calin Juravle11351682014-10-23 15:38:15 +01002064 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002065 }
2066}
2067
Calin Juravle34bacdf2014-10-07 20:23:36 +01002068void LocationsBuilderARM::VisitMul(HMul* mul) {
2069 LocationSummary* locations =
2070 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2071 switch (mul->GetResultType()) {
2072 case Primitive::kPrimInt:
2073 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002074 locations->SetInAt(0, Location::RequiresRegister());
2075 locations->SetInAt(1, Location::RequiresRegister());
2076 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002077 break;
2078 }
2079
Calin Juravleb5bfa962014-10-21 18:02:24 +01002080 case Primitive::kPrimFloat:
2081 case Primitive::kPrimDouble: {
2082 locations->SetInAt(0, Location::RequiresFpuRegister());
2083 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002084 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002085 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002086 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002087
2088 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002089 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002090 }
2091}
2092
2093void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2094 LocationSummary* locations = mul->GetLocations();
2095 Location out = locations->Out();
2096 Location first = locations->InAt(0);
2097 Location second = locations->InAt(1);
2098 switch (mul->GetResultType()) {
2099 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002100 __ mul(out.AsRegister<Register>(),
2101 first.AsRegister<Register>(),
2102 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002103 break;
2104 }
2105 case Primitive::kPrimLong: {
2106 Register out_hi = out.AsRegisterPairHigh<Register>();
2107 Register out_lo = out.AsRegisterPairLow<Register>();
2108 Register in1_hi = first.AsRegisterPairHigh<Register>();
2109 Register in1_lo = first.AsRegisterPairLow<Register>();
2110 Register in2_hi = second.AsRegisterPairHigh<Register>();
2111 Register in2_lo = second.AsRegisterPairLow<Register>();
2112
2113 // Extra checks to protect caused by the existence of R1_R2.
2114 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2115 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2116 DCHECK_NE(out_hi, in1_lo);
2117 DCHECK_NE(out_hi, in2_lo);
2118
2119 // input: in1 - 64 bits, in2 - 64 bits
2120 // output: out
2121 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2122 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2123 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2124
2125 // IP <- in1.lo * in2.hi
2126 __ mul(IP, in1_lo, in2_hi);
2127 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2128 __ mla(out_hi, in1_hi, in2_lo, IP);
2129 // out.lo <- (in1.lo * in2.lo)[31:0];
2130 __ umull(out_lo, IP, in1_lo, in2_lo);
2131 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2132 __ add(out_hi, out_hi, ShifterOperand(IP));
2133 break;
2134 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002135
2136 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002137 __ vmuls(out.AsFpuRegister<SRegister>(),
2138 first.AsFpuRegister<SRegister>(),
2139 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002140 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002141 }
2142
2143 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002144 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2145 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2146 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002147 break;
2148 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002149
2150 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002151 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002152 }
2153}
2154
Zheng Xuc6667102015-05-15 16:08:45 +08002155void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2156 DCHECK(instruction->IsDiv() || instruction->IsRem());
2157 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2158
2159 LocationSummary* locations = instruction->GetLocations();
2160 Location second = locations->InAt(1);
2161 DCHECK(second.IsConstant());
2162
2163 Register out = locations->Out().AsRegister<Register>();
2164 Register dividend = locations->InAt(0).AsRegister<Register>();
2165 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2166 DCHECK(imm == 1 || imm == -1);
2167
2168 if (instruction->IsRem()) {
2169 __ LoadImmediate(out, 0);
2170 } else {
2171 if (imm == 1) {
2172 __ Mov(out, dividend);
2173 } else {
2174 __ rsb(out, dividend, ShifterOperand(0));
2175 }
2176 }
2177}
2178
2179void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2180 DCHECK(instruction->IsDiv() || instruction->IsRem());
2181 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2182
2183 LocationSummary* locations = instruction->GetLocations();
2184 Location second = locations->InAt(1);
2185 DCHECK(second.IsConstant());
2186
2187 Register out = locations->Out().AsRegister<Register>();
2188 Register dividend = locations->InAt(0).AsRegister<Register>();
2189 Register temp = locations->GetTemp(0).AsRegister<Register>();
2190 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002191 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002192 DCHECK(IsPowerOfTwo(abs_imm));
2193 int ctz_imm = CTZ(abs_imm);
2194
2195 if (ctz_imm == 1) {
2196 __ Lsr(temp, dividend, 32 - ctz_imm);
2197 } else {
2198 __ Asr(temp, dividend, 31);
2199 __ Lsr(temp, temp, 32 - ctz_imm);
2200 }
2201 __ add(out, temp, ShifterOperand(dividend));
2202
2203 if (instruction->IsDiv()) {
2204 __ Asr(out, out, ctz_imm);
2205 if (imm < 0) {
2206 __ rsb(out, out, ShifterOperand(0));
2207 }
2208 } else {
2209 __ ubfx(out, out, 0, ctz_imm);
2210 __ sub(out, out, ShifterOperand(temp));
2211 }
2212}
2213
2214void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2215 DCHECK(instruction->IsDiv() || instruction->IsRem());
2216 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2217
2218 LocationSummary* locations = instruction->GetLocations();
2219 Location second = locations->InAt(1);
2220 DCHECK(second.IsConstant());
2221
2222 Register out = locations->Out().AsRegister<Register>();
2223 Register dividend = locations->InAt(0).AsRegister<Register>();
2224 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2225 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2226 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2227
2228 int64_t magic;
2229 int shift;
2230 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2231
2232 __ LoadImmediate(temp1, magic);
2233 __ smull(temp2, temp1, dividend, temp1);
2234
2235 if (imm > 0 && magic < 0) {
2236 __ add(temp1, temp1, ShifterOperand(dividend));
2237 } else if (imm < 0 && magic > 0) {
2238 __ sub(temp1, temp1, ShifterOperand(dividend));
2239 }
2240
2241 if (shift != 0) {
2242 __ Asr(temp1, temp1, shift);
2243 }
2244
2245 if (instruction->IsDiv()) {
2246 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2247 } else {
2248 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2249 // TODO: Strength reduction for mls.
2250 __ LoadImmediate(temp2, imm);
2251 __ mls(out, temp1, temp2, dividend);
2252 }
2253}
2254
2255void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2256 DCHECK(instruction->IsDiv() || instruction->IsRem());
2257 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2258
2259 LocationSummary* locations = instruction->GetLocations();
2260 Location second = locations->InAt(1);
2261 DCHECK(second.IsConstant());
2262
2263 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2264 if (imm == 0) {
2265 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2266 } else if (imm == 1 || imm == -1) {
2267 DivRemOneOrMinusOne(instruction);
2268 } else if (IsPowerOfTwo(std::abs(imm))) {
2269 DivRemByPowerOfTwo(instruction);
2270 } else {
2271 DCHECK(imm <= -2 || imm >= 2);
2272 GenerateDivRemWithAnyConstant(instruction);
2273 }
2274}
2275
Calin Juravle7c4954d2014-10-28 16:57:40 +00002276void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002277 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2278 if (div->GetResultType() == Primitive::kPrimLong) {
2279 // pLdiv runtime call.
2280 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002281 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2282 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002283 } else if (div->GetResultType() == Primitive::kPrimInt &&
2284 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2285 // pIdivmod runtime call.
2286 call_kind = LocationSummary::kCall;
2287 }
2288
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002289 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2290
Calin Juravle7c4954d2014-10-28 16:57:40 +00002291 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002292 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002293 if (div->InputAt(1)->IsConstant()) {
2294 locations->SetInAt(0, Location::RequiresRegister());
2295 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2296 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2297 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2298 if (abs_imm <= 1) {
2299 // No temp register required.
2300 } else {
2301 locations->AddTemp(Location::RequiresRegister());
2302 if (!IsPowerOfTwo(abs_imm)) {
2303 locations->AddTemp(Location::RequiresRegister());
2304 }
2305 }
2306 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002307 locations->SetInAt(0, Location::RequiresRegister());
2308 locations->SetInAt(1, Location::RequiresRegister());
2309 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2310 } else {
2311 InvokeRuntimeCallingConvention calling_convention;
2312 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2313 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2314 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2315 // we only need the former.
2316 locations->SetOut(Location::RegisterLocation(R0));
2317 }
Calin Juravled0d48522014-11-04 16:40:20 +00002318 break;
2319 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002320 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002321 InvokeRuntimeCallingConvention calling_convention;
2322 locations->SetInAt(0, Location::RegisterPairLocation(
2323 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2324 locations->SetInAt(1, Location::RegisterPairLocation(
2325 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002326 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002327 break;
2328 }
2329 case Primitive::kPrimFloat:
2330 case Primitive::kPrimDouble: {
2331 locations->SetInAt(0, Location::RequiresFpuRegister());
2332 locations->SetInAt(1, Location::RequiresFpuRegister());
2333 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2334 break;
2335 }
2336
2337 default:
2338 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2339 }
2340}
2341
2342void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2343 LocationSummary* locations = div->GetLocations();
2344 Location out = locations->Out();
2345 Location first = locations->InAt(0);
2346 Location second = locations->InAt(1);
2347
2348 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002349 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002350 if (second.IsConstant()) {
2351 GenerateDivRemConstantIntegral(div);
2352 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002353 __ sdiv(out.AsRegister<Register>(),
2354 first.AsRegister<Register>(),
2355 second.AsRegister<Register>());
2356 } else {
2357 InvokeRuntimeCallingConvention calling_convention;
2358 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2359 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2360 DCHECK_EQ(R0, out.AsRegister<Register>());
2361
2362 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2363 }
Calin Juravled0d48522014-11-04 16:40:20 +00002364 break;
2365 }
2366
Calin Juravle7c4954d2014-10-28 16:57:40 +00002367 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002368 InvokeRuntimeCallingConvention calling_convention;
2369 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2370 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2371 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2372 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2373 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002374 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002375
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002376 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002377 break;
2378 }
2379
2380 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002381 __ vdivs(out.AsFpuRegister<SRegister>(),
2382 first.AsFpuRegister<SRegister>(),
2383 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002384 break;
2385 }
2386
2387 case Primitive::kPrimDouble: {
2388 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2389 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2390 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2391 break;
2392 }
2393
2394 default:
2395 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2396 }
2397}
2398
Calin Juravlebacfec32014-11-14 15:54:36 +00002399void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002400 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002401
2402 // Most remainders are implemented in the runtime.
2403 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002404 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2405 // sdiv will be replaced by other instruction sequence.
2406 call_kind = LocationSummary::kNoCall;
2407 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2408 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002409 // Have hardware divide instruction for int, do it with three instructions.
2410 call_kind = LocationSummary::kNoCall;
2411 }
2412
Calin Juravlebacfec32014-11-14 15:54:36 +00002413 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2414
Calin Juravled2ec87d2014-12-08 14:24:46 +00002415 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002416 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002417 if (rem->InputAt(1)->IsConstant()) {
2418 locations->SetInAt(0, Location::RequiresRegister());
2419 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2420 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2421 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2422 if (abs_imm <= 1) {
2423 // No temp register required.
2424 } else {
2425 locations->AddTemp(Location::RequiresRegister());
2426 if (!IsPowerOfTwo(abs_imm)) {
2427 locations->AddTemp(Location::RequiresRegister());
2428 }
2429 }
2430 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002431 locations->SetInAt(0, Location::RequiresRegister());
2432 locations->SetInAt(1, Location::RequiresRegister());
2433 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2434 locations->AddTemp(Location::RequiresRegister());
2435 } else {
2436 InvokeRuntimeCallingConvention calling_convention;
2437 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2438 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2439 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2440 // we only need the latter.
2441 locations->SetOut(Location::RegisterLocation(R1));
2442 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002443 break;
2444 }
2445 case Primitive::kPrimLong: {
2446 InvokeRuntimeCallingConvention calling_convention;
2447 locations->SetInAt(0, Location::RegisterPairLocation(
2448 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2449 locations->SetInAt(1, Location::RegisterPairLocation(
2450 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2451 // The runtime helper puts the output in R2,R3.
2452 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2453 break;
2454 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002455 case Primitive::kPrimFloat: {
2456 InvokeRuntimeCallingConvention calling_convention;
2457 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2458 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2459 locations->SetOut(Location::FpuRegisterLocation(S0));
2460 break;
2461 }
2462
Calin Juravlebacfec32014-11-14 15:54:36 +00002463 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002464 InvokeRuntimeCallingConvention calling_convention;
2465 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2466 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2467 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2468 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2469 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002470 break;
2471 }
2472
2473 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002474 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002475 }
2476}
2477
2478void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2479 LocationSummary* locations = rem->GetLocations();
2480 Location out = locations->Out();
2481 Location first = locations->InAt(0);
2482 Location second = locations->InAt(1);
2483
Calin Juravled2ec87d2014-12-08 14:24:46 +00002484 Primitive::Type type = rem->GetResultType();
2485 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002486 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002487 if (second.IsConstant()) {
2488 GenerateDivRemConstantIntegral(rem);
2489 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002490 Register reg1 = first.AsRegister<Register>();
2491 Register reg2 = second.AsRegister<Register>();
2492 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002493
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002494 // temp = reg1 / reg2 (integer division)
2495 // temp = temp * reg2
2496 // dest = reg1 - temp
2497 __ sdiv(temp, reg1, reg2);
2498 __ mul(temp, temp, reg2);
2499 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2500 } else {
2501 InvokeRuntimeCallingConvention calling_convention;
2502 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2503 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2504 DCHECK_EQ(R1, out.AsRegister<Register>());
2505
2506 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2507 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002508 break;
2509 }
2510
2511 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002512 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002513 break;
2514 }
2515
Calin Juravled2ec87d2014-12-08 14:24:46 +00002516 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002517 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002518 break;
2519 }
2520
Calin Juravlebacfec32014-11-14 15:54:36 +00002521 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002522 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002523 break;
2524 }
2525
2526 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002527 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002528 }
2529}
2530
Calin Juravled0d48522014-11-04 16:40:20 +00002531void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2532 LocationSummary* locations =
2533 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002534 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002535 if (instruction->HasUses()) {
2536 locations->SetOut(Location::SameAsFirstInput());
2537 }
2538}
2539
2540void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2541 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2542 codegen_->AddSlowPath(slow_path);
2543
2544 LocationSummary* locations = instruction->GetLocations();
2545 Location value = locations->InAt(0);
2546
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002547 switch (instruction->GetType()) {
2548 case Primitive::kPrimInt: {
2549 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002550 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002551 __ b(slow_path->GetEntryLabel(), EQ);
2552 } else {
2553 DCHECK(value.IsConstant()) << value;
2554 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2555 __ b(slow_path->GetEntryLabel());
2556 }
2557 }
2558 break;
2559 }
2560 case Primitive::kPrimLong: {
2561 if (value.IsRegisterPair()) {
2562 __ orrs(IP,
2563 value.AsRegisterPairLow<Register>(),
2564 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2565 __ b(slow_path->GetEntryLabel(), EQ);
2566 } else {
2567 DCHECK(value.IsConstant()) << value;
2568 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2569 __ b(slow_path->GetEntryLabel());
2570 }
2571 }
2572 break;
2573 default:
2574 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2575 }
2576 }
Calin Juravled0d48522014-11-04 16:40:20 +00002577}
2578
Calin Juravle9aec02f2014-11-18 23:06:35 +00002579void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2580 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2581
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002582 LocationSummary* locations =
2583 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002584
2585 switch (op->GetResultType()) {
2586 case Primitive::kPrimInt: {
2587 locations->SetInAt(0, Location::RequiresRegister());
2588 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002589 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002590 break;
2591 }
2592 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002593 locations->SetInAt(0, Location::RequiresRegister());
2594 locations->SetInAt(1, Location::RequiresRegister());
2595 locations->AddTemp(Location::RequiresRegister());
2596 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002597 break;
2598 }
2599 default:
2600 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2601 }
2602}
2603
2604void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2605 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2606
2607 LocationSummary* locations = op->GetLocations();
2608 Location out = locations->Out();
2609 Location first = locations->InAt(0);
2610 Location second = locations->InAt(1);
2611
2612 Primitive::Type type = op->GetResultType();
2613 switch (type) {
2614 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002615 Register out_reg = out.AsRegister<Register>();
2616 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002617 // Arm doesn't mask the shift count so we need to do it ourselves.
2618 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002619 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002620 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2621 if (op->IsShl()) {
2622 __ Lsl(out_reg, first_reg, second_reg);
2623 } else if (op->IsShr()) {
2624 __ Asr(out_reg, first_reg, second_reg);
2625 } else {
2626 __ Lsr(out_reg, first_reg, second_reg);
2627 }
2628 } else {
2629 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2630 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2631 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2632 __ Mov(out_reg, first_reg);
2633 } else if (op->IsShl()) {
2634 __ Lsl(out_reg, first_reg, shift_value);
2635 } else if (op->IsShr()) {
2636 __ Asr(out_reg, first_reg, shift_value);
2637 } else {
2638 __ Lsr(out_reg, first_reg, shift_value);
2639 }
2640 }
2641 break;
2642 }
2643 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002644 Register o_h = out.AsRegisterPairHigh<Register>();
2645 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002646
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002647 Register temp = locations->GetTemp(0).AsRegister<Register>();
2648
2649 Register high = first.AsRegisterPairHigh<Register>();
2650 Register low = first.AsRegisterPairLow<Register>();
2651
2652 Register second_reg = second.AsRegister<Register>();
2653
Calin Juravle9aec02f2014-11-18 23:06:35 +00002654 if (op->IsShl()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002655 // Shift the high part
2656 __ and_(second_reg, second_reg, ShifterOperand(63));
2657 __ Lsl(o_h, high, second_reg);
2658 // Shift the low part and `or` what overflew on the high part
2659 __ rsb(temp, second_reg, ShifterOperand(32));
2660 __ Lsr(temp, low, temp);
2661 __ orr(o_h, o_h, ShifterOperand(temp));
2662 // If the shift is > 32 bits, override the high part
2663 __ subs(temp, second_reg, ShifterOperand(32));
2664 __ it(PL);
2665 __ Lsl(o_h, low, temp, false, PL);
2666 // Shift the low part
2667 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002668 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002669 // Shift the low part
2670 __ and_(second_reg, second_reg, ShifterOperand(63));
2671 __ Lsr(o_l, low, second_reg);
2672 // Shift the high part and `or` what underflew on the low part
2673 __ rsb(temp, second_reg, ShifterOperand(32));
2674 __ Lsl(temp, high, temp);
2675 __ orr(o_l, o_l, ShifterOperand(temp));
2676 // If the shift is > 32 bits, override the low part
2677 __ subs(temp, second_reg, ShifterOperand(32));
2678 __ it(PL);
2679 __ Asr(o_l, high, temp, false, PL);
2680 // Shift the high part
2681 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002682 } else {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002683 // same as Shr except we use `Lsr`s and not `Asr`s
2684 __ and_(second_reg, second_reg, ShifterOperand(63));
2685 __ Lsr(o_l, low, second_reg);
2686 __ rsb(temp, second_reg, ShifterOperand(32));
2687 __ Lsl(temp, high, temp);
2688 __ orr(o_l, o_l, ShifterOperand(temp));
2689 __ subs(temp, second_reg, ShifterOperand(32));
2690 __ it(PL);
2691 __ Lsr(o_l, high, temp, false, PL);
2692 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002693 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002694 break;
2695 }
2696 default:
2697 LOG(FATAL) << "Unexpected operation type " << type;
2698 }
2699}
2700
2701void LocationsBuilderARM::VisitShl(HShl* shl) {
2702 HandleShift(shl);
2703}
2704
2705void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2706 HandleShift(shl);
2707}
2708
2709void LocationsBuilderARM::VisitShr(HShr* shr) {
2710 HandleShift(shr);
2711}
2712
2713void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2714 HandleShift(shr);
2715}
2716
2717void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2718 HandleShift(ushr);
2719}
2720
2721void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2722 HandleShift(ushr);
2723}
2724
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002725void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002726 LocationSummary* locations =
2727 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002728 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002729 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002730 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002731 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002732}
2733
2734void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2735 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002736 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002737 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2738 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002739 instruction->GetDexPc(),
2740 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002741}
2742
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002743void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2744 LocationSummary* locations =
2745 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2746 InvokeRuntimeCallingConvention calling_convention;
2747 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002748 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002749 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray69aa6012015-06-09 10:34:25 +01002750 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002751}
2752
2753void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2754 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002755 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002756 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2757 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002758 instruction->GetDexPc(),
2759 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002760}
2761
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002762void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002763 LocationSummary* locations =
2764 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002765 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2766 if (location.IsStackSlot()) {
2767 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2768 } else if (location.IsDoubleStackSlot()) {
2769 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002770 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002771 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002772}
2773
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002774void InstructionCodeGeneratorARM::VisitParameterValue(
2775 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002776 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002777}
2778
2779void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
2780 LocationSummary* locations =
2781 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2782 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2783}
2784
2785void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
2786 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002787}
2788
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002789void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002790 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002791 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002792 locations->SetInAt(0, Location::RequiresRegister());
2793 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002794}
2795
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002796void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2797 LocationSummary* locations = not_->GetLocations();
2798 Location out = locations->Out();
2799 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002800 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002801 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002802 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002803 break;
2804
2805 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002806 __ mvn(out.AsRegisterPairLow<Register>(),
2807 ShifterOperand(in.AsRegisterPairLow<Register>()));
2808 __ mvn(out.AsRegisterPairHigh<Register>(),
2809 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002810 break;
2811
2812 default:
2813 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2814 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002815}
2816
David Brazdil66d126e2015-04-03 16:02:44 +01002817void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
2818 LocationSummary* locations =
2819 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
2820 locations->SetInAt(0, Location::RequiresRegister());
2821 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2822}
2823
2824void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01002825 LocationSummary* locations = bool_not->GetLocations();
2826 Location out = locations->Out();
2827 Location in = locations->InAt(0);
2828 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
2829}
2830
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002831void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002832 LocationSummary* locations =
2833 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002834 switch (compare->InputAt(0)->GetType()) {
2835 case Primitive::kPrimLong: {
2836 locations->SetInAt(0, Location::RequiresRegister());
2837 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002838 // Output overlaps because it is written before doing the low comparison.
2839 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002840 break;
2841 }
2842 case Primitive::kPrimFloat:
2843 case Primitive::kPrimDouble: {
2844 locations->SetInAt(0, Location::RequiresFpuRegister());
2845 locations->SetInAt(1, Location::RequiresFpuRegister());
2846 locations->SetOut(Location::RequiresRegister());
2847 break;
2848 }
2849 default:
2850 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2851 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002852}
2853
2854void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002855 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002856 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002857 Location left = locations->InAt(0);
2858 Location right = locations->InAt(1);
2859
Vladimir Markocf93a5c2015-06-16 11:33:24 +00002860 Label less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00002861 Primitive::Type type = compare->InputAt(0)->GetType();
2862 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002863 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002864 __ cmp(left.AsRegisterPairHigh<Register>(),
2865 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002866 __ b(&less, LT);
2867 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002868 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2869 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002870 __ cmp(left.AsRegisterPairLow<Register>(),
2871 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002872 break;
2873 }
2874 case Primitive::kPrimFloat:
2875 case Primitive::kPrimDouble: {
2876 __ LoadImmediate(out, 0);
2877 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002878 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002879 } else {
2880 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2881 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2882 }
2883 __ vmstat(); // transfer FP status register to ARM APSR.
2884 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002885 break;
2886 }
2887 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002888 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002889 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002890 __ b(&done, EQ);
2891 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2892
2893 __ Bind(&greater);
2894 __ LoadImmediate(out, 1);
2895 __ b(&done);
2896
2897 __ Bind(&less);
2898 __ LoadImmediate(out, -1);
2899
2900 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002901}
2902
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002903void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002904 LocationSummary* locations =
2905 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002906 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2907 locations->SetInAt(i, Location::Any());
2908 }
2909 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002910}
2911
2912void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002913 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002914 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002915}
2916
Calin Juravle52c48962014-12-16 17:02:57 +00002917void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2918 // TODO (ported from quick): revisit Arm barrier kinds
Kenny Root1d8199d2015-06-02 11:01:10 -07002919 DmbOptions flavor = DmbOptions::ISH; // quiet c++ warnings
Calin Juravle52c48962014-12-16 17:02:57 +00002920 switch (kind) {
2921 case MemBarrierKind::kAnyStore:
2922 case MemBarrierKind::kLoadAny:
2923 case MemBarrierKind::kAnyAny: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002924 flavor = DmbOptions::ISH;
Calin Juravle52c48962014-12-16 17:02:57 +00002925 break;
2926 }
2927 case MemBarrierKind::kStoreStore: {
Kenny Root1d8199d2015-06-02 11:01:10 -07002928 flavor = DmbOptions::ISHST;
Calin Juravle52c48962014-12-16 17:02:57 +00002929 break;
2930 }
2931 default:
2932 LOG(FATAL) << "Unexpected memory barrier " << kind;
2933 }
Kenny Root1d8199d2015-06-02 11:01:10 -07002934 __ dmb(flavor);
Calin Juravle52c48962014-12-16 17:02:57 +00002935}
2936
2937void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2938 uint32_t offset,
2939 Register out_lo,
2940 Register out_hi) {
2941 if (offset != 0) {
2942 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002943 __ add(IP, addr, ShifterOperand(out_lo));
2944 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002945 }
2946 __ ldrexd(out_lo, out_hi, addr);
2947}
2948
2949void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2950 uint32_t offset,
2951 Register value_lo,
2952 Register value_hi,
2953 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002954 Register temp2,
2955 HInstruction* instruction) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00002956 Label fail;
Calin Juravle52c48962014-12-16 17:02:57 +00002957 if (offset != 0) {
2958 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002959 __ add(IP, addr, ShifterOperand(temp1));
2960 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002961 }
2962 __ Bind(&fail);
2963 // We need a load followed by store. (The address used in a STREX instruction must
2964 // be the same as the address in the most recently executed LDREX instruction.)
2965 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002966 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002967 __ strexd(temp1, value_lo, value_hi, addr);
2968 __ cmp(temp1, ShifterOperand(0));
2969 __ b(&fail, NE);
2970}
2971
2972void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2973 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2974
Nicolas Geoffray39468442014-09-02 15:17:15 +01002975 LocationSummary* locations =
2976 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002977 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002978
Calin Juravle52c48962014-12-16 17:02:57 +00002979 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01002980 if (Primitive::IsFloatingPointType(field_type)) {
2981 locations->SetInAt(1, Location::RequiresFpuRegister());
2982 } else {
2983 locations->SetInAt(1, Location::RequiresRegister());
2984 }
2985
Calin Juravle52c48962014-12-16 17:02:57 +00002986 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002987 bool generate_volatile = field_info.IsVolatile()
2988 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002989 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002990 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002991 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2992 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002993 locations->AddTemp(Location::RequiresRegister());
2994 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002995 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002996 // Arm encoding have some additional constraints for ldrexd/strexd:
2997 // - registers need to be consecutive
2998 // - the first register should be even but not R14.
2999 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3000 // enable Arm encoding.
3001 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3002
3003 locations->AddTemp(Location::RequiresRegister());
3004 locations->AddTemp(Location::RequiresRegister());
3005 if (field_type == Primitive::kPrimDouble) {
3006 // For doubles we need two more registers to copy the value.
3007 locations->AddTemp(Location::RegisterLocation(R2));
3008 locations->AddTemp(Location::RegisterLocation(R3));
3009 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003010 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003011}
3012
Calin Juravle52c48962014-12-16 17:02:57 +00003013void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003014 const FieldInfo& field_info,
3015 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003016 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3017
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003018 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003019 Register base = locations->InAt(0).AsRegister<Register>();
3020 Location value = locations->InAt(1);
3021
3022 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003023 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003024 Primitive::Type field_type = field_info.GetFieldType();
3025 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3026
3027 if (is_volatile) {
3028 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3029 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003030
3031 switch (field_type) {
3032 case Primitive::kPrimBoolean:
3033 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003034 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003035 break;
3036 }
3037
3038 case Primitive::kPrimShort:
3039 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003040 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003041 break;
3042 }
3043
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003044 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003045 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00003046 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003047 break;
3048 }
3049
3050 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003051 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003052 GenerateWideAtomicStore(base, offset,
3053 value.AsRegisterPairLow<Register>(),
3054 value.AsRegisterPairHigh<Register>(),
3055 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003056 locations->GetTemp(1).AsRegister<Register>(),
3057 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003058 } else {
3059 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003060 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003061 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003062 break;
3063 }
3064
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003065 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003066 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003067 break;
3068 }
3069
3070 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003071 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003072 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003073 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3074 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3075
3076 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3077
3078 GenerateWideAtomicStore(base, offset,
3079 value_reg_lo,
3080 value_reg_hi,
3081 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003082 locations->GetTemp(3).AsRegister<Register>(),
3083 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003084 } else {
3085 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003086 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003087 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003088 break;
3089 }
3090
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003091 case Primitive::kPrimVoid:
3092 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003093 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003094 }
Calin Juravle52c48962014-12-16 17:02:57 +00003095
Calin Juravle77520bc2015-01-12 18:45:46 +00003096 // Longs and doubles are handled in the switch.
3097 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3098 codegen_->MaybeRecordImplicitNullCheck(instruction);
3099 }
3100
3101 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3102 Register temp = locations->GetTemp(0).AsRegister<Register>();
3103 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003104 codegen_->MarkGCCard(
3105 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003106 }
3107
Calin Juravle52c48962014-12-16 17:02:57 +00003108 if (is_volatile) {
3109 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3110 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003111}
3112
Calin Juravle52c48962014-12-16 17:02:57 +00003113void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3114 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003115 LocationSummary* locations =
3116 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003117 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003118
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003119 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003120 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003121 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003122 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003123
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003124 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3125 locations->SetOut(Location::RequiresFpuRegister());
3126 } else {
3127 locations->SetOut(Location::RequiresRegister(),
3128 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3129 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003130 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003131 // Arm encoding have some additional constraints for ldrexd/strexd:
3132 // - registers need to be consecutive
3133 // - the first register should be even but not R14.
3134 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3135 // enable Arm encoding.
3136 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3137 locations->AddTemp(Location::RequiresRegister());
3138 locations->AddTemp(Location::RequiresRegister());
3139 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003140}
3141
Calin Juravle52c48962014-12-16 17:02:57 +00003142void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3143 const FieldInfo& field_info) {
3144 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003145
Calin Juravle52c48962014-12-16 17:02:57 +00003146 LocationSummary* locations = instruction->GetLocations();
3147 Register base = locations->InAt(0).AsRegister<Register>();
3148 Location out = locations->Out();
3149 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003150 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003151 Primitive::Type field_type = field_info.GetFieldType();
3152 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3153
3154 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003155 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003156 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003157 break;
3158 }
3159
3160 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003161 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003162 break;
3163 }
3164
3165 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003166 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003167 break;
3168 }
3169
3170 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003171 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003172 break;
3173 }
3174
3175 case Primitive::kPrimInt:
3176 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003177 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003178 break;
3179 }
3180
3181 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003182 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003183 GenerateWideAtomicLoad(base, offset,
3184 out.AsRegisterPairLow<Register>(),
3185 out.AsRegisterPairHigh<Register>());
3186 } else {
3187 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3188 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003189 break;
3190 }
3191
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003192 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003193 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003194 break;
3195 }
3196
3197 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003198 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003199 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003200 Register lo = locations->GetTemp(0).AsRegister<Register>();
3201 Register hi = locations->GetTemp(1).AsRegister<Register>();
3202 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003203 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003204 __ vmovdrr(out_reg, lo, hi);
3205 } else {
3206 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003207 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003208 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003209 break;
3210 }
3211
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003212 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003213 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003214 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003215 }
Calin Juravle52c48962014-12-16 17:02:57 +00003216
Calin Juravle77520bc2015-01-12 18:45:46 +00003217 // Doubles are handled in the switch.
3218 if (field_type != Primitive::kPrimDouble) {
3219 codegen_->MaybeRecordImplicitNullCheck(instruction);
3220 }
3221
Calin Juravle52c48962014-12-16 17:02:57 +00003222 if (is_volatile) {
3223 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3224 }
3225}
3226
3227void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3228 HandleFieldSet(instruction, instruction->GetFieldInfo());
3229}
3230
3231void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003232 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003233}
3234
3235void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3236 HandleFieldGet(instruction, instruction->GetFieldInfo());
3237}
3238
3239void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3240 HandleFieldGet(instruction, instruction->GetFieldInfo());
3241}
3242
3243void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3244 HandleFieldGet(instruction, instruction->GetFieldInfo());
3245}
3246
3247void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3248 HandleFieldGet(instruction, instruction->GetFieldInfo());
3249}
3250
3251void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3252 HandleFieldSet(instruction, instruction->GetFieldInfo());
3253}
3254
3255void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003256 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003257}
3258
3259void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003260 LocationSummary* locations =
3261 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003262 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003263 if (instruction->HasUses()) {
3264 locations->SetOut(Location::SameAsFirstInput());
3265 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003266}
3267
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003268void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003269 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3270 return;
3271 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003272 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003273
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003274 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3275 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3276}
3277
3278void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003279 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003280 codegen_->AddSlowPath(slow_path);
3281
3282 LocationSummary* locations = instruction->GetLocations();
3283 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003284
Calin Juravle77520bc2015-01-12 18:45:46 +00003285 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
3286 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003287}
3288
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003289void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3290 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3291 GenerateImplicitNullCheck(instruction);
3292 } else {
3293 GenerateExplicitNullCheck(instruction);
3294 }
3295}
3296
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003297void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003298 LocationSummary* locations =
3299 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003300 locations->SetInAt(0, Location::RequiresRegister());
3301 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003302 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3303 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3304 } else {
3305 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3306 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003307}
3308
3309void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3310 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003311 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003312 Location index = locations->InAt(1);
3313
3314 switch (instruction->GetType()) {
3315 case Primitive::kPrimBoolean: {
3316 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003317 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003318 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003319 size_t offset =
3320 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003321 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3322 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003323 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003324 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3325 }
3326 break;
3327 }
3328
3329 case Primitive::kPrimByte: {
3330 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003331 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003332 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003333 size_t offset =
3334 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003335 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3336 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003337 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003338 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3339 }
3340 break;
3341 }
3342
3343 case Primitive::kPrimShort: {
3344 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003345 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003346 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003347 size_t offset =
3348 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003349 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3350 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003351 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003352 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3353 }
3354 break;
3355 }
3356
3357 case Primitive::kPrimChar: {
3358 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003359 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003360 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003361 size_t offset =
3362 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003363 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3364 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003365 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003366 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3367 }
3368 break;
3369 }
3370
3371 case Primitive::kPrimInt:
3372 case Primitive::kPrimNot: {
Roland Levillain33d69032015-06-18 18:20:59 +01003373 static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
3374 "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes.");
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003375 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003376 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003377 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003378 size_t offset =
3379 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003380 __ LoadFromOffset(kLoadWord, out, obj, offset);
3381 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003382 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003383 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3384 }
3385 break;
3386 }
3387
3388 case Primitive::kPrimLong: {
3389 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003390 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003391 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003392 size_t offset =
3393 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003394 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003395 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003396 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003397 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003398 }
3399 break;
3400 }
3401
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003402 case Primitive::kPrimFloat: {
3403 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3404 Location out = locations->Out();
3405 DCHECK(out.IsFpuRegister());
3406 if (index.IsConstant()) {
3407 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3408 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3409 } else {
3410 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3411 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3412 }
3413 break;
3414 }
3415
3416 case Primitive::kPrimDouble: {
3417 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3418 Location out = locations->Out();
3419 DCHECK(out.IsFpuRegisterPair());
3420 if (index.IsConstant()) {
3421 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3422 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3423 } else {
3424 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3425 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3426 }
3427 break;
3428 }
3429
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003430 case Primitive::kPrimVoid:
3431 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003432 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003433 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003434 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003435}
3436
3437void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003438 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003439
3440 bool needs_write_barrier =
3441 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3442 bool needs_runtime_call = instruction->NeedsTypeCheck();
3443
Nicolas Geoffray39468442014-09-02 15:17:15 +01003444 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003445 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3446 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003447 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003448 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3449 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3450 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003451 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003452 locations->SetInAt(0, Location::RequiresRegister());
3453 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003454 if (Primitive::IsFloatingPointType(value_type)) {
3455 locations->SetInAt(2, Location::RequiresFpuRegister());
3456 } else {
3457 locations->SetInAt(2, Location::RequiresRegister());
3458 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003459
3460 if (needs_write_barrier) {
3461 // Temporary registers for the write barrier.
3462 locations->AddTemp(Location::RequiresRegister());
3463 locations->AddTemp(Location::RequiresRegister());
3464 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003465 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003466}
3467
3468void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3469 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003470 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003471 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003472 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003473 bool needs_runtime_call = locations->WillCall();
3474 bool needs_write_barrier =
3475 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003476
3477 switch (value_type) {
3478 case Primitive::kPrimBoolean:
3479 case Primitive::kPrimByte: {
3480 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003481 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003482 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003483 size_t offset =
3484 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003485 __ StoreToOffset(kStoreByte, value, obj, offset);
3486 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003487 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003488 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3489 }
3490 break;
3491 }
3492
3493 case Primitive::kPrimShort:
3494 case Primitive::kPrimChar: {
3495 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003496 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003497 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003498 size_t offset =
3499 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003500 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3501 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003502 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003503 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3504 }
3505 break;
3506 }
3507
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003508 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003509 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003510 if (!needs_runtime_call) {
3511 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003512 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003513 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003514 size_t offset =
3515 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003516 __ StoreToOffset(kStoreWord, value, obj, offset);
3517 } else {
3518 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003519 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003520 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3521 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003522 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003523 if (needs_write_barrier) {
3524 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003525 Register temp = locations->GetTemp(0).AsRegister<Register>();
3526 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003527 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003528 }
3529 } else {
3530 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003531 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3532 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003533 instruction->GetDexPc(),
3534 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003535 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003536 break;
3537 }
3538
3539 case Primitive::kPrimLong: {
3540 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003541 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003542 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003543 size_t offset =
3544 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003545 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003546 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003547 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003548 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003549 }
3550 break;
3551 }
3552
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003553 case Primitive::kPrimFloat: {
3554 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3555 Location value = locations->InAt(2);
3556 DCHECK(value.IsFpuRegister());
3557 if (index.IsConstant()) {
3558 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3559 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3560 } else {
3561 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3562 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3563 }
3564 break;
3565 }
3566
3567 case Primitive::kPrimDouble: {
3568 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3569 Location value = locations->InAt(2);
3570 DCHECK(value.IsFpuRegisterPair());
3571 if (index.IsConstant()) {
3572 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3573 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3574 } else {
3575 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3576 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3577 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003578
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003579 break;
3580 }
3581
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003582 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003583 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003584 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003585 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003586
3587 // Ints and objects are handled in the switch.
3588 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3589 codegen_->MaybeRecordImplicitNullCheck(instruction);
3590 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003591}
3592
3593void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003594 LocationSummary* locations =
3595 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003596 locations->SetInAt(0, Location::RequiresRegister());
3597 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003598}
3599
3600void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3601 LocationSummary* locations = instruction->GetLocations();
3602 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003603 Register obj = locations->InAt(0).AsRegister<Register>();
3604 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003605 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003606 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003607}
3608
3609void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003610 LocationSummary* locations =
3611 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003612 locations->SetInAt(0, Location::RequiresRegister());
3613 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003614 if (instruction->HasUses()) {
3615 locations->SetOut(Location::SameAsFirstInput());
3616 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003617}
3618
3619void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3620 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003621 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003622 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003623 codegen_->AddSlowPath(slow_path);
3624
Roland Levillain271ab9c2014-11-27 15:23:57 +00003625 Register index = locations->InAt(0).AsRegister<Register>();
3626 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003627
3628 __ cmp(index, ShifterOperand(length));
3629 __ b(slow_path->GetEntryLabel(), CS);
3630}
3631
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003632void CodeGeneratorARM::MarkGCCard(Register temp,
3633 Register card,
3634 Register object,
3635 Register value,
3636 bool can_be_null) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00003637 Label is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003638 if (can_be_null) {
3639 __ CompareAndBranchIfZero(value, &is_null);
3640 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003641 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3642 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3643 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003644 if (can_be_null) {
3645 __ Bind(&is_null);
3646 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003647}
3648
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003649void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3650 temp->SetLocations(nullptr);
3651}
3652
3653void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3654 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003655 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003656}
3657
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003658void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003659 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003660 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003661}
3662
3663void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003664 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3665}
3666
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003667void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3668 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3669}
3670
3671void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003672 HBasicBlock* block = instruction->GetBlock();
3673 if (block->GetLoopInformation() != nullptr) {
3674 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3675 // The back edge will generate the suspend check.
3676 return;
3677 }
3678 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3679 // The goto will generate the suspend check.
3680 return;
3681 }
3682 GenerateSuspendCheck(instruction, nullptr);
3683}
3684
3685void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3686 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003687 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003688 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3689 if (slow_path == nullptr) {
3690 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3691 instruction->SetSlowPath(slow_path);
3692 codegen_->AddSlowPath(slow_path);
3693 if (successor != nullptr) {
3694 DCHECK(successor->IsLoopHeader());
3695 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3696 }
3697 } else {
3698 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3699 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003700
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003701 __ LoadFromOffset(
3702 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3703 __ cmp(IP, ShifterOperand(0));
3704 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003705 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003706 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003707 __ Bind(slow_path->GetReturnLabel());
3708 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003709 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003710 __ b(slow_path->GetEntryLabel());
3711 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003712}
3713
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003714ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3715 return codegen_->GetAssembler();
3716}
3717
3718void ParallelMoveResolverARM::EmitMove(size_t index) {
3719 MoveOperands* move = moves_.Get(index);
3720 Location source = move->GetSource();
3721 Location destination = move->GetDestination();
3722
3723 if (source.IsRegister()) {
3724 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003725 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003726 } else {
3727 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003728 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003729 SP, destination.GetStackIndex());
3730 }
3731 } else if (source.IsStackSlot()) {
3732 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003733 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003734 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003735 } else if (destination.IsFpuRegister()) {
3736 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003737 } else {
3738 DCHECK(destination.IsStackSlot());
3739 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3740 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3741 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003742 } else if (source.IsFpuRegister()) {
3743 if (destination.IsFpuRegister()) {
3744 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003745 } else {
3746 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003747 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3748 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003749 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003750 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003751 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3752 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003753 } else if (destination.IsRegisterPair()) {
3754 DCHECK(ExpectedPairLayout(destination));
3755 __ LoadFromOffset(
3756 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3757 } else {
3758 DCHECK(destination.IsFpuRegisterPair()) << destination;
3759 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3760 SP,
3761 source.GetStackIndex());
3762 }
3763 } else if (source.IsRegisterPair()) {
3764 if (destination.IsRegisterPair()) {
3765 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3766 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3767 } else {
3768 DCHECK(destination.IsDoubleStackSlot()) << destination;
3769 DCHECK(ExpectedPairLayout(source));
3770 __ StoreToOffset(
3771 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3772 }
3773 } else if (source.IsFpuRegisterPair()) {
3774 if (destination.IsFpuRegisterPair()) {
3775 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3776 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3777 } else {
3778 DCHECK(destination.IsDoubleStackSlot()) << destination;
3779 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3780 SP,
3781 destination.GetStackIndex());
3782 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003783 } else {
3784 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003785 HConstant* constant = source.GetConstant();
3786 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3787 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003788 if (destination.IsRegister()) {
3789 __ LoadImmediate(destination.AsRegister<Register>(), value);
3790 } else {
3791 DCHECK(destination.IsStackSlot());
3792 __ LoadImmediate(IP, value);
3793 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3794 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003795 } else if (constant->IsLongConstant()) {
3796 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003797 if (destination.IsRegisterPair()) {
3798 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3799 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003800 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003801 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003802 __ LoadImmediate(IP, Low32Bits(value));
3803 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3804 __ LoadImmediate(IP, High32Bits(value));
3805 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3806 }
3807 } else if (constant->IsDoubleConstant()) {
3808 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003809 if (destination.IsFpuRegisterPair()) {
3810 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003811 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003812 DCHECK(destination.IsDoubleStackSlot()) << destination;
3813 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003814 __ LoadImmediate(IP, Low32Bits(int_value));
3815 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3816 __ LoadImmediate(IP, High32Bits(int_value));
3817 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3818 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003819 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003820 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003821 float value = constant->AsFloatConstant()->GetValue();
3822 if (destination.IsFpuRegister()) {
3823 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3824 } else {
3825 DCHECK(destination.IsStackSlot());
3826 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3827 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3828 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003829 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003830 }
3831}
3832
3833void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3834 __ Mov(IP, reg);
3835 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3836 __ StoreToOffset(kStoreWord, IP, SP, mem);
3837}
3838
3839void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3840 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3841 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3842 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3843 SP, mem1 + stack_offset);
3844 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3845 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3846 SP, mem2 + stack_offset);
3847 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3848}
3849
3850void ParallelMoveResolverARM::EmitSwap(size_t index) {
3851 MoveOperands* move = moves_.Get(index);
3852 Location source = move->GetSource();
3853 Location destination = move->GetDestination();
3854
3855 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003856 DCHECK_NE(source.AsRegister<Register>(), IP);
3857 DCHECK_NE(destination.AsRegister<Register>(), IP);
3858 __ Mov(IP, source.AsRegister<Register>());
3859 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3860 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003861 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003862 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003863 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003864 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003865 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3866 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003867 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003868 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003869 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003870 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003871 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003872 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003873 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003874 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003875 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3876 destination.AsRegisterPairHigh<Register>(),
3877 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003878 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003879 Register low_reg = source.IsRegisterPair()
3880 ? source.AsRegisterPairLow<Register>()
3881 : destination.AsRegisterPairLow<Register>();
3882 int mem = source.IsRegisterPair()
3883 ? destination.GetStackIndex()
3884 : source.GetStackIndex();
3885 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003886 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003887 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003888 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003889 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003890 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3891 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003892 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003893 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003894 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003895 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3896 DRegister reg = source.IsFpuRegisterPair()
3897 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3898 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3899 int mem = source.IsFpuRegisterPair()
3900 ? destination.GetStackIndex()
3901 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003902 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003903 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003904 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003905 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3906 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3907 : destination.AsFpuRegister<SRegister>();
3908 int mem = source.IsFpuRegister()
3909 ? destination.GetStackIndex()
3910 : source.GetStackIndex();
3911
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003912 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003913 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003914 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003915 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003916 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3917 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003918 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003919 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003920 }
3921}
3922
3923void ParallelMoveResolverARM::SpillScratch(int reg) {
3924 __ Push(static_cast<Register>(reg));
3925}
3926
3927void ParallelMoveResolverARM::RestoreScratch(int reg) {
3928 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003929}
3930
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003931void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003932 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3933 ? LocationSummary::kCallOnSlowPath
3934 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003935 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003936 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003937 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003938 locations->SetOut(Location::RequiresRegister());
3939}
3940
3941void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003942 LocationSummary* locations = cls->GetLocations();
3943 Register out = locations->Out().AsRegister<Register>();
3944 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003945 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003946 DCHECK(!cls->CanCallRuntime());
3947 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003948 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07003949 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003950 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003951 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003952 __ LoadFromOffset(kLoadWord,
3953 out,
3954 current_method,
Mathieu Chartiere401d142015-04-22 13:56:20 -07003955 ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003956 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003957
3958 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3959 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3960 codegen_->AddSlowPath(slow_path);
3961 __ cmp(out, ShifterOperand(0));
3962 __ b(slow_path->GetEntryLabel(), EQ);
3963 if (cls->MustGenerateClinitCheck()) {
3964 GenerateClassInitializationCheck(slow_path, out);
3965 } else {
3966 __ Bind(slow_path->GetExitLabel());
3967 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003968 }
3969}
3970
3971void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3972 LocationSummary* locations =
3973 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3974 locations->SetInAt(0, Location::RequiresRegister());
3975 if (check->HasUses()) {
3976 locations->SetOut(Location::SameAsFirstInput());
3977 }
3978}
3979
3980void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003981 // We assume the class is not null.
3982 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3983 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003984 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003985 GenerateClassInitializationCheck(slow_path,
3986 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003987}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003988
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003989void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3990 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003991 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3992 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3993 __ b(slow_path->GetEntryLabel(), LT);
3994 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3995 // properly. Therefore, we do a memory fence.
3996 __ dmb(ISH);
3997 __ Bind(slow_path->GetExitLabel());
3998}
3999
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004000void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
4001 LocationSummary* locations =
4002 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004003 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004004 locations->SetOut(Location::RequiresRegister());
4005}
4006
4007void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
4008 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
4009 codegen_->AddSlowPath(slow_path);
4010
Nicolas Geoffrayfbdaa302015-05-29 12:06:56 +01004011 LocationSummary* locations = load->GetLocations();
4012 Register out = locations->Out().AsRegister<Register>();
4013 Register current_method = locations->InAt(0).AsRegister<Register>();
4014 __ LoadFromOffset(
Mathieu Chartiere401d142015-04-22 13:56:20 -07004015 kLoadWord, out, current_method, ArtMethod::DeclaringClassOffset().Int32Value());
Mathieu Chartiereace4582014-11-24 18:29:54 -08004016 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004017 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
4018 __ cmp(out, ShifterOperand(0));
4019 __ b(slow_path->GetEntryLabel(), EQ);
4020 __ Bind(slow_path->GetExitLabel());
4021}
4022
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004023void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4024 LocationSummary* locations =
4025 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4026 locations->SetOut(Location::RequiresRegister());
4027}
4028
4029void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004030 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004031 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4032 __ LoadFromOffset(kLoadWord, out, TR, offset);
4033 __ LoadImmediate(IP, 0);
4034 __ StoreToOffset(kStoreWord, IP, TR, offset);
4035}
4036
4037void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4038 LocationSummary* locations =
4039 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4040 InvokeRuntimeCallingConvention calling_convention;
4041 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4042}
4043
4044void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4045 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004046 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004047}
4048
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004049void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004050 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4051 ? LocationSummary::kNoCall
4052 : LocationSummary::kCallOnSlowPath;
4053 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4054 locations->SetInAt(0, Location::RequiresRegister());
4055 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004056 // The out register is used as a temporary, so it overlaps with the inputs.
4057 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004058}
4059
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004060void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004061 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004062 Register obj = locations->InAt(0).AsRegister<Register>();
4063 Register cls = locations->InAt(1).AsRegister<Register>();
4064 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004065 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004066 Label done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004067 SlowPathCodeARM* slow_path = nullptr;
4068
4069 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004070 // avoid null check if we know obj is not null.
4071 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004072 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004073 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004074 // Compare the class of `obj` with `cls`.
4075 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
4076 __ cmp(out, ShifterOperand(cls));
4077 if (instruction->IsClassFinal()) {
4078 // Classes must be equal for the instanceof to succeed.
4079 __ b(&zero, NE);
4080 __ LoadImmediate(out, 1);
4081 __ b(&done);
4082 } else {
4083 // If the classes are not equal, we go into a slow path.
4084 DCHECK(locations->OnlyCallsOnSlowPath());
4085 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004086 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004087 codegen_->AddSlowPath(slow_path);
4088 __ b(slow_path->GetEntryLabel(), NE);
4089 __ LoadImmediate(out, 1);
4090 __ b(&done);
4091 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004092
4093 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4094 __ Bind(&zero);
4095 __ LoadImmediate(out, 0);
4096 }
4097
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004098 if (slow_path != nullptr) {
4099 __ Bind(slow_path->GetExitLabel());
4100 }
4101 __ Bind(&done);
4102}
4103
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004104void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4105 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4106 instruction, LocationSummary::kCallOnSlowPath);
4107 locations->SetInAt(0, Location::RequiresRegister());
4108 locations->SetInAt(1, Location::RequiresRegister());
4109 locations->AddTemp(Location::RequiresRegister());
4110}
4111
4112void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4113 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004114 Register obj = locations->InAt(0).AsRegister<Register>();
4115 Register cls = locations->InAt(1).AsRegister<Register>();
4116 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004117 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4118
4119 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4120 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
4121 codegen_->AddSlowPath(slow_path);
4122
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004123 // avoid null check if we know obj is not null.
4124 if (instruction->MustDoNullCheck()) {
Vladimir Markocf93a5c2015-06-16 11:33:24 +00004125 __ CompareAndBranchIfZero(obj, slow_path->GetExitLabel());
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004126 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004127 // Compare the class of `obj` with `cls`.
4128 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
4129 __ cmp(temp, ShifterOperand(cls));
4130 __ b(slow_path->GetEntryLabel(), NE);
4131 __ Bind(slow_path->GetExitLabel());
4132}
4133
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004134void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4135 LocationSummary* locations =
4136 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4137 InvokeRuntimeCallingConvention calling_convention;
4138 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4139}
4140
4141void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4142 codegen_->InvokeRuntime(instruction->IsEnter()
4143 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4144 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004145 instruction->GetDexPc(),
4146 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004147}
4148
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004149void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4150void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4151void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4152
4153void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4154 LocationSummary* locations =
4155 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4156 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4157 || instruction->GetResultType() == Primitive::kPrimLong);
4158 locations->SetInAt(0, Location::RequiresRegister());
4159 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004160 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004161}
4162
4163void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4164 HandleBitwiseOperation(instruction);
4165}
4166
4167void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4168 HandleBitwiseOperation(instruction);
4169}
4170
4171void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4172 HandleBitwiseOperation(instruction);
4173}
4174
4175void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4176 LocationSummary* locations = instruction->GetLocations();
4177
4178 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004179 Register first = locations->InAt(0).AsRegister<Register>();
4180 Register second = locations->InAt(1).AsRegister<Register>();
4181 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004182 if (instruction->IsAnd()) {
4183 __ and_(out, first, ShifterOperand(second));
4184 } else if (instruction->IsOr()) {
4185 __ orr(out, first, ShifterOperand(second));
4186 } else {
4187 DCHECK(instruction->IsXor());
4188 __ eor(out, first, ShifterOperand(second));
4189 }
4190 } else {
4191 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4192 Location first = locations->InAt(0);
4193 Location second = locations->InAt(1);
4194 Location out = locations->Out();
4195 if (instruction->IsAnd()) {
4196 __ and_(out.AsRegisterPairLow<Register>(),
4197 first.AsRegisterPairLow<Register>(),
4198 ShifterOperand(second.AsRegisterPairLow<Register>()));
4199 __ and_(out.AsRegisterPairHigh<Register>(),
4200 first.AsRegisterPairHigh<Register>(),
4201 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4202 } else if (instruction->IsOr()) {
4203 __ orr(out.AsRegisterPairLow<Register>(),
4204 first.AsRegisterPairLow<Register>(),
4205 ShifterOperand(second.AsRegisterPairLow<Register>()));
4206 __ orr(out.AsRegisterPairHigh<Register>(),
4207 first.AsRegisterPairHigh<Register>(),
4208 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4209 } else {
4210 DCHECK(instruction->IsXor());
4211 __ eor(out.AsRegisterPairLow<Register>(),
4212 first.AsRegisterPairLow<Register>(),
4213 ShifterOperand(second.AsRegisterPairLow<Register>()));
4214 __ eor(out.AsRegisterPairHigh<Register>(),
4215 first.AsRegisterPairHigh<Register>(),
4216 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4217 }
4218 }
4219}
4220
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004221void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004222 // TODO: Implement all kinds of calls:
4223 // 1) boot -> boot
4224 // 2) app -> boot
4225 // 3) app -> app
4226 //
4227 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4228
Jeff Hao848f70a2014-01-15 13:49:50 -08004229 if (invoke->IsStringInit()) {
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004230 Register reg = temp.AsRegister<Register>();
Jeff Hao848f70a2014-01-15 13:49:50 -08004231 // temp = thread->string_init_entrypoint
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004232 __ LoadFromOffset(kLoadWord, reg, TR, invoke->GetStringInitOffset());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004233 // LR = temp[offset_of_quick_compiled_code]
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004234 __ LoadFromOffset(kLoadWord, LR, reg,
Mathieu Chartiere401d142015-04-22 13:56:20 -07004235 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004236 kArmWordSize).Int32Value());
4237 // LR()
4238 __ blx(LR);
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004239 } else if (invoke->IsRecursive()) {
4240 __ bl(GetFrameEntryLabel());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004241 } else {
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004242 Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex());
4243 Register method_reg;
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004244 Register reg = temp.AsRegister<Register>();
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004245 if (current_method.IsRegister()) {
4246 method_reg = current_method.AsRegister<Register>();
4247 } else {
4248 DCHECK(invoke->GetLocations()->Intrinsified());
4249 DCHECK(!current_method.IsValid());
4250 method_reg = reg;
4251 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
4252 }
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004253 // reg = current_method->dex_cache_resolved_methods_;
4254 __ LoadFromOffset(
Nicolas Geoffrayae71a052015-06-09 14:12:28 +01004255 kLoadWord, reg, method_reg, ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray38207af2015-06-01 15:46:22 +01004256 // reg = reg[index_in_cache]
4257 __ LoadFromOffset(
4258 kLoadWord, reg, reg, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4259 // LR = reg[offset_of_quick_compiled_code]
4260 __ LoadFromOffset(kLoadWord, LR, reg, ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4261 kArmWordSize).Int32Value());
4262 // LR()
4263 __ blx(LR);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004264 }
4265
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004266 DCHECK(!IsLeafMethod());
4267}
4268
Calin Juravleb1498f62015-02-16 13:13:29 +00004269void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4270 // Nothing to do, this should be removed during prepare for register allocator.
4271 UNUSED(instruction);
4272 LOG(FATAL) << "Unreachable";
4273}
4274
4275void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4276 // Nothing to do, this should be removed during prepare for register allocator.
4277 UNUSED(instruction);
4278 LOG(FATAL) << "Unreachable";
4279}
4280
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004281} // namespace arm
4282} // namespace art