blob: ab3b6b0b7019e82d52633e40d9879b4b4f96f75e [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"
Zheng Xuc6667102015-05-15 16:08:45 +080020#include "code_generator_utils.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070021#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010022#include "gc/accounting/card_table.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080023#include "intrinsics.h"
24#include "intrinsics_arm.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070025#include "mirror/array-inl.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000026#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010027#include "mirror/class.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
Nicolas Geoffraye5038322014-07-04 09:41:32 +010058#define __ reinterpret_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 __
321#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700322
323inline Condition ARMCondition(IfCondition cond) {
324 switch (cond) {
325 case kCondEQ: return EQ;
326 case kCondNE: return NE;
327 case kCondLT: return LT;
328 case kCondLE: return LE;
329 case kCondGT: return GT;
330 case kCondGE: return GE;
331 default:
332 LOG(FATAL) << "Unknown if condition";
333 }
334 return EQ; // Unreachable.
335}
336
337inline Condition ARMOppositeCondition(IfCondition cond) {
338 switch (cond) {
339 case kCondEQ: return NE;
340 case kCondNE: return EQ;
341 case kCondLT: return GE;
342 case kCondLE: return GT;
343 case kCondGT: return LE;
344 case kCondGE: return LT;
345 default:
346 LOG(FATAL) << "Unknown if condition";
347 }
348 return EQ; // Unreachable.
349}
350
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100351void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100352 stream << Register(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100353}
354
355void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
David Brazdilc74652862015-05-13 17:50:09 +0100356 stream << SRegister(reg);
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100357}
358
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100359size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
360 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
361 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100362}
363
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100364size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
365 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
366 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100367}
368
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000369size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
370 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
371 return kArmWordSize;
372}
373
374size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
375 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
376 return kArmWordSize;
377}
378
Calin Juravle34166012014-12-19 17:22:29 +0000379CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000380 const ArmInstructionSetFeatures& isa_features,
381 const CompilerOptions& compiler_options)
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000382 : CodeGenerator(graph,
383 kNumberOfCoreRegisters,
384 kNumberOfSRegisters,
385 kNumberOfRegisterPairs,
386 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
387 arraysize(kCoreCalleeSaves)),
388 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
389 arraysize(kFpuCalleeSaves)),
390 compiler_options),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100391 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100392 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100393 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100394 move_resolver_(graph->GetArena(), this),
Nicolas Geoffrayd126ba12015-05-20 11:25:27 +0100395 assembler_(false /* can_relocate_branches */),
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000396 isa_features_(isa_features) {
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000397 // Save the PC register to mimic Quick.
398 AddAllocatedRegister(Location::RegisterLocation(PC));
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100399}
400
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100401Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100402 switch (type) {
403 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100404 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100405 ArmManagedRegister pair =
406 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100407 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
408 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
409
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100410 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
411 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100412 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100413 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100414 }
415
416 case Primitive::kPrimByte:
417 case Primitive::kPrimBoolean:
418 case Primitive::kPrimChar:
419 case Primitive::kPrimShort:
420 case Primitive::kPrimInt:
421 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100422 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100423 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100424 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
425 ArmManagedRegister current =
426 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
427 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100428 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100429 }
430 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100431 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100432 }
433
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000434 case Primitive::kPrimFloat: {
435 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100436 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100437 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100438
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000439 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000440 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
441 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000442 return Location::FpuRegisterPairLocation(reg, reg + 1);
443 }
444
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100445 case Primitive::kPrimVoid:
446 LOG(FATAL) << "Unreachable type " << type;
447 }
448
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100449 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100450}
451
Nicolas Geoffraya0bb2bd2015-01-26 12:49:35 +0000452void CodeGeneratorARM::SetupBlockedRegisters(bool is_baseline) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100453 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100454 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100455
456 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100457 blocked_core_registers_[SP] = true;
458 blocked_core_registers_[LR] = true;
459 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100460
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100461 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100462 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100463
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100464 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100465 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100466
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000467 if (is_baseline) {
468 for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) {
469 blocked_core_registers_[kCoreCalleeSaves[i]] = true;
470 }
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000471
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000472 blocked_core_registers_[kCoreSavedRegisterForBaseline] = false;
473
474 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
475 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
476 }
477 }
Calin Juravle34bacdf2014-10-07 20:23:36 +0100478
479 UpdateBlockedPairRegisters();
480}
481
482void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
483 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
484 ArmManagedRegister current =
485 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
486 if (blocked_core_registers_[current.AsRegisterPairLow()]
487 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
488 blocked_register_pairs_[i] = true;
489 }
490 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100491}
492
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100493InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
494 : HGraphVisitor(graph),
495 assembler_(codegen->GetAssembler()),
496 codegen_(codegen) {}
497
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000498void CodeGeneratorARM::ComputeSpillMask() {
499 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000500 // Save one extra register for baseline. Note that on thumb2, there is no easy
501 // instruction to restore just the PC, so this actually helps both baseline
502 // and non-baseline to save and restore at least two registers at entry and exit.
503 core_spill_mask_ |= (1 << kCoreSavedRegisterForBaseline);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000504 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
505 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
506 // We use vpush and vpop for saving and restoring floating point registers, which take
507 // a SRegister and the number of registers to save/restore after that SRegister. We
508 // therefore update the `fpu_spill_mask_` to also contain those registers not allocated,
509 // but in the range.
510 if (fpu_spill_mask_ != 0) {
511 uint32_t least_significant_bit = LeastSignificantBit(fpu_spill_mask_);
512 uint32_t most_significant_bit = MostSignificantBit(fpu_spill_mask_);
513 for (uint32_t i = least_significant_bit + 1 ; i < most_significant_bit; ++i) {
514 fpu_spill_mask_ |= (1 << i);
515 }
516 }
517}
518
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100519static dwarf::Reg DWARFReg(Register reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100520 return dwarf::Reg::ArmCore(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100521}
522
523static dwarf::Reg DWARFReg(SRegister reg) {
David Srbecky9d8606d2015-04-12 09:35:32 +0100524 return dwarf::Reg::ArmFp(static_cast<int>(reg));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100525}
526
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000527void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000528 bool skip_overflow_check =
529 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000530 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000531 __ Bind(&frame_entry_label_);
532
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000533 if (HasEmptyFrame()) {
534 return;
535 }
536
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100537 if (!skip_overflow_check) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000538 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
539 __ LoadFromOffset(kLoadWord, IP, IP, 0);
540 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100541 }
542
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000543 // PC is in the list of callee-save to mimic Quick, but we need to push
544 // LR at entry instead.
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100545 uint32_t push_mask = (core_spill_mask_ & (~(1 << PC))) | 1 << LR;
546 __ PushList(push_mask);
547 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(push_mask));
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100548 __ cfi().RelOffsetForMany(DWARFReg(kMethodRegisterArgument), 0, push_mask, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000549 if (fpu_spill_mask_ != 0) {
550 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
551 __ vpushs(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100552 __ cfi().AdjustCFAOffset(kArmWordSize * POPCOUNT(fpu_spill_mask_));
David Srbecky9d8606d2015-04-12 09:35:32 +0100553 __ cfi().RelOffsetForMany(DWARFReg(S0), 0, fpu_spill_mask_, kArmWordSize);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000554 }
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100555 int adjust = GetFrameSize() - FrameEntrySpillSize();
556 __ AddConstant(SP, -adjust);
557 __ cfi().AdjustCFAOffset(adjust);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100558 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000559}
560
561void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000562 if (HasEmptyFrame()) {
563 __ bx(LR);
564 return;
565 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100566 __ cfi().RememberState();
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100567 int adjust = GetFrameSize() - FrameEntrySpillSize();
568 __ AddConstant(SP, adjust);
569 __ cfi().AdjustCFAOffset(-adjust);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000570 if (fpu_spill_mask_ != 0) {
571 SRegister start_register = SRegister(LeastSignificantBit(fpu_spill_mask_));
572 __ vpops(start_register, POPCOUNT(fpu_spill_mask_));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100573 __ cfi().AdjustCFAOffset(-kArmPointerSize * POPCOUNT(fpu_spill_mask_));
574 __ cfi().RestoreMany(DWARFReg(SRegister(0)), fpu_spill_mask_);
Nicolas Geoffray4dee6362015-01-23 18:23:14 +0000575 }
576 __ PopList(core_spill_mask_);
David Srbeckyc34dc932015-04-12 09:27:43 +0100577 __ cfi().RestoreState();
578 __ cfi().DefCFAOffset(GetFrameSize());
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000579}
580
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100581void CodeGeneratorARM::Bind(HBasicBlock* block) {
582 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000583}
584
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100585Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
586 switch (load->GetType()) {
587 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100588 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100589 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100590
591 case Primitive::kPrimInt:
592 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100593 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100594 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100595
596 case Primitive::kPrimBoolean:
597 case Primitive::kPrimByte:
598 case Primitive::kPrimChar:
599 case Primitive::kPrimShort:
600 case Primitive::kPrimVoid:
601 LOG(FATAL) << "Unexpected type " << load->GetType();
Andreas Gampe65b798e2015-04-06 09:35:22 -0700602 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100603 }
604
605 LOG(FATAL) << "Unreachable";
Andreas Gampe65b798e2015-04-06 09:35:22 -0700606 UNREACHABLE();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100607}
608
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100609Location InvokeDexCallingConventionVisitorARM::GetNextLocation(Primitive::Type type) {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100610 switch (type) {
611 case Primitive::kPrimBoolean:
612 case Primitive::kPrimByte:
613 case Primitive::kPrimChar:
614 case Primitive::kPrimShort:
615 case Primitive::kPrimInt:
616 case Primitive::kPrimNot: {
617 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000618 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100619 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100620 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100621 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000622 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100623 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100624 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100625
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000626 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100627 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000628 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100629 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000630 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100631 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000632 if (calling_convention.GetRegisterAt(index) == R1) {
633 // Skip R1, and use R2_R3 instead.
634 gp_index_++;
635 index++;
636 }
637 }
638 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
639 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000640 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000641 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
Nicolas Geoffrayaf2c65c2015-01-14 09:40:32 +0000642 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100643 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000644 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
645 }
646 }
647
648 case Primitive::kPrimFloat: {
649 uint32_t stack_index = stack_index_++;
650 if (float_index_ % 2 == 0) {
651 float_index_ = std::max(double_index_, float_index_);
652 }
653 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
654 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
655 } else {
656 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
657 }
658 }
659
660 case Primitive::kPrimDouble: {
661 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
662 uint32_t stack_index = stack_index_;
663 stack_index_ += 2;
664 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
665 uint32_t index = double_index_;
666 double_index_ += 2;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000667 Location result = Location::FpuRegisterPairLocation(
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000668 calling_convention.GetFpuRegisterAt(index),
669 calling_convention.GetFpuRegisterAt(index + 1));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000670 DCHECK(ExpectedPairLayout(result));
671 return result;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000672 } else {
673 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100674 }
675 }
676
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100677 case Primitive::kPrimVoid:
678 LOG(FATAL) << "Unexpected parameter type " << type;
679 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100680 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100681 return Location();
682}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100683
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100684Location InvokeDexCallingConventionVisitorARM::GetReturnLocation(Primitive::Type type) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000685 switch (type) {
686 case Primitive::kPrimBoolean:
687 case Primitive::kPrimByte:
688 case Primitive::kPrimChar:
689 case Primitive::kPrimShort:
690 case Primitive::kPrimInt:
691 case Primitive::kPrimNot: {
692 return Location::RegisterLocation(R0);
693 }
694
695 case Primitive::kPrimFloat: {
696 return Location::FpuRegisterLocation(S0);
697 }
698
699 case Primitive::kPrimLong: {
700 return Location::RegisterPairLocation(R0, R1);
701 }
702
703 case Primitive::kPrimDouble: {
704 return Location::FpuRegisterPairLocation(S0, S1);
705 }
706
707 case Primitive::kPrimVoid:
708 return Location();
709 }
710 UNREACHABLE();
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000711}
712
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100713void CodeGeneratorARM::Move32(Location destination, Location source) {
714 if (source.Equals(destination)) {
715 return;
716 }
717 if (destination.IsRegister()) {
718 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000719 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100720 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000721 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100722 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000723 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100724 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100725 } else if (destination.IsFpuRegister()) {
726 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000727 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100728 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000729 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100730 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000731 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100732 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100733 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000734 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100735 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000736 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100737 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000738 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100739 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000740 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100741 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
742 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100743 }
744 }
745}
746
747void CodeGeneratorARM::Move64(Location destination, Location source) {
748 if (source.Equals(destination)) {
749 return;
750 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100751 if (destination.IsRegisterPair()) {
752 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000753 EmitParallelMoves(
754 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
755 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100756 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000757 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100758 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
759 Primitive::kPrimInt);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100760 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000761 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100762 } else {
763 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000764 DCHECK(ExpectedPairLayout(destination));
765 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
766 SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100767 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000768 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100769 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000770 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
771 SP,
772 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100773 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000774 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100775 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100776 } else {
777 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100778 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000779 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100780 if (source.AsRegisterPairLow<Register>() == R1) {
781 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100782 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
783 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100784 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100785 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100786 SP, destination.GetStackIndex());
787 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000788 } else if (source.IsFpuRegisterPair()) {
789 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
790 SP,
791 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100792 } else {
793 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000794 EmitParallelMoves(
795 Location::StackSlot(source.GetStackIndex()),
796 Location::StackSlot(destination.GetStackIndex()),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100797 Primitive::kPrimInt,
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000798 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
Nicolas Geoffray90218252015-04-15 11:56:51 +0100799 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)),
800 Primitive::kPrimInt);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100801 }
802 }
803}
804
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100805void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100806 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100807 if (instruction->IsCurrentMethod()) {
808 Move32(location, Location::StackSlot(kCurrentMethodStackOffset));
809 } else if (locations != nullptr && locations->Out().Equals(location)) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100810 return;
Nicolas Geoffray76b1e172015-05-27 17:18:33 +0100811 } else if (locations != nullptr && locations->Out().IsConstant()) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000812 HConstant* const_to_move = locations->Out().GetConstant();
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000813 if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) {
814 int32_t value = GetInt32ValueOf(const_to_move);
Calin Juravlea21f5982014-11-13 15:53:04 +0000815 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000816 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000817 } else {
818 DCHECK(location.IsStackSlot());
819 __ LoadImmediate(IP, value);
820 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
821 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000822 } else {
Nicolas Geoffray3747b482015-01-19 17:17:16 +0000823 DCHECK(const_to_move->IsLongConstant()) << const_to_move->DebugName();
Calin Juravlea21f5982014-11-13 15:53:04 +0000824 int64_t value = const_to_move->AsLongConstant()->GetValue();
825 if (location.IsRegisterPair()) {
826 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
827 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
828 } else {
829 DCHECK(location.IsDoubleStackSlot());
830 __ LoadImmediate(IP, Low32Bits(value));
831 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
832 __ LoadImmediate(IP, High32Bits(value));
833 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
834 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100835 }
Roland Levillain476df552014-10-09 17:51:36 +0100836 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100837 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
838 switch (instruction->GetType()) {
839 case Primitive::kPrimBoolean:
840 case Primitive::kPrimByte:
841 case Primitive::kPrimChar:
842 case Primitive::kPrimShort:
843 case Primitive::kPrimInt:
844 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100845 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100846 Move32(location, Location::StackSlot(stack_slot));
847 break;
848
849 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100850 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100851 Move64(location, Location::DoubleStackSlot(stack_slot));
852 break;
853
854 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100855 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100856 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000857 } else if (instruction->IsTemporary()) {
858 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000859 if (temp_location.IsStackSlot()) {
860 Move32(location, temp_location);
861 } else {
862 DCHECK(temp_location.IsDoubleStackSlot());
863 Move64(location, temp_location);
864 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000865 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100866 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100867 switch (instruction->GetType()) {
868 case Primitive::kPrimBoolean:
869 case Primitive::kPrimByte:
870 case Primitive::kPrimChar:
871 case Primitive::kPrimShort:
872 case Primitive::kPrimNot:
873 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100874 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100875 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100876 break;
877
878 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100879 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100880 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100881 break;
882
883 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100884 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100885 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000886 }
887}
888
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100889void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
890 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000891 uint32_t dex_pc,
892 SlowPathCode* slow_path) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100893 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
894 __ blx(LR);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000895 RecordPcInfo(instruction, dex_pc, slow_path);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100896 DCHECK(instruction->IsSuspendCheck()
897 || instruction->IsBoundsCheck()
898 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000899 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000900 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100901 || !IsLeafMethod());
902}
903
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000904void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000905 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000906}
907
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000908void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000909 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100910 DCHECK(!successor->IsExitBlock());
911
912 HBasicBlock* block = got->GetBlock();
913 HInstruction* previous = got->GetPrevious();
914
915 HLoopInformation* info = block->GetLoopInformation();
David Brazdil46e2a392015-03-16 17:31:52 +0000916 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100917 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
918 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
919 return;
920 }
921
922 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
923 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
924 }
925 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000926 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000927 }
928}
929
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000930void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000931 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000932}
933
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000934void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700935 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000936}
937
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700938void InstructionCodeGeneratorARM::GenerateTestAndBranch(HInstruction* instruction,
939 Label* true_target,
940 Label* false_target,
941 Label* always_true_target) {
942 HInstruction* cond = instruction->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100943 if (cond->IsIntConstant()) {
944 // Constant condition, statically compared against 1.
945 int32_t cond_value = cond->AsIntConstant()->GetValue();
946 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700947 if (always_true_target != nullptr) {
948 __ b(always_true_target);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100949 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100950 return;
951 } else {
952 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100953 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100954 } else {
955 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
956 // Condition has been materialized, compare the output to 0
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700957 DCHECK(instruction->GetLocations()->InAt(0).IsRegister());
958 __ cmp(instruction->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100959 ShifterOperand(0));
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700960 __ b(true_target, NE);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100961 } else {
962 // Condition has not been materialized, use its inputs as the
963 // comparison and its condition as the branch condition.
964 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +0000965 DCHECK(locations->InAt(0).IsRegister()) << locations->InAt(0);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000966 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100967 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000968 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100969 } else {
970 DCHECK(locations->InAt(1).IsConstant());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000971 HConstant* constant = locations->InAt(1).GetConstant();
972 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100973 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000974 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
975 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100976 } else {
977 Register temp = IP;
978 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000979 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100980 }
981 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700982 __ b(true_target, ARMCondition(cond->AsCondition()->GetCondition()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100983 }
Dave Allison20dfc792014-06-16 20:44:29 -0700984 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700985 if (false_target != nullptr) {
986 __ b(false_target);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000987 }
988}
989
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700990void LocationsBuilderARM::VisitIf(HIf* if_instr) {
991 LocationSummary* locations =
992 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
993 HInstruction* cond = if_instr->InputAt(0);
994 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
995 locations->SetInAt(0, Location::RequiresRegister());
996 }
997}
998
999void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
1000 Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1001 Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1002 Label* always_true_target = true_target;
1003 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1004 if_instr->IfTrueSuccessor())) {
1005 always_true_target = nullptr;
1006 }
1007 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1008 if_instr->IfFalseSuccessor())) {
1009 false_target = nullptr;
1010 }
1011 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1012}
1013
1014void LocationsBuilderARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1015 LocationSummary* locations = new (GetGraph()->GetArena())
1016 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1017 HInstruction* cond = deoptimize->InputAt(0);
1018 DCHECK(cond->IsCondition());
1019 if (cond->AsCondition()->NeedsMaterialization()) {
1020 locations->SetInAt(0, Location::RequiresRegister());
1021 }
1022}
1023
1024void InstructionCodeGeneratorARM::VisitDeoptimize(HDeoptimize* deoptimize) {
1025 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena())
1026 DeoptimizationSlowPathARM(deoptimize);
1027 codegen_->AddSlowPath(slow_path);
1028 Label* slow_path_entry = slow_path->GetEntryLabel();
1029 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1030}
Dave Allison20dfc792014-06-16 20:44:29 -07001031
Roland Levillain0d37cd02015-05-27 16:39:19 +01001032void LocationsBuilderARM::VisitCondition(HCondition* cond) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001033 LocationSummary* locations =
Roland Levillain0d37cd02015-05-27 16:39:19 +01001034 new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001035 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain0d37cd02015-05-27 16:39:19 +01001036 locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1)));
1037 if (cond->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001038 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001039 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001040}
1041
Roland Levillain0d37cd02015-05-27 16:39:19 +01001042void InstructionCodeGeneratorARM::VisitCondition(HCondition* cond) {
1043 if (!cond->NeedsMaterialization()) return;
1044 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001045 Register left = locations->InAt(0).AsRegister<Register>();
1046
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001047 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001048 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001049 } else {
1050 DCHECK(locations->InAt(1).IsConstant());
Mingyao Yangdc5ac732015-02-25 11:28:05 -08001051 int32_t value = CodeGenerator::GetInt32ValueOf(locations->InAt(1).GetConstant());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001052 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001053 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
1054 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001055 } else {
1056 Register temp = IP;
1057 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +00001058 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001059 }
Dave Allison20dfc792014-06-16 20:44:29 -07001060 }
Roland Levillain0d37cd02015-05-27 16:39:19 +01001061 __ it(ARMCondition(cond->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001062 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001063 ARMCondition(cond->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001064 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Roland Levillain0d37cd02015-05-27 16:39:19 +01001065 ARMOppositeCondition(cond->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001066}
1067
1068void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1069 VisitCondition(comp);
1070}
1071
1072void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1073 VisitCondition(comp);
1074}
1075
1076void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1077 VisitCondition(comp);
1078}
1079
1080void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1081 VisitCondition(comp);
1082}
1083
1084void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1085 VisitCondition(comp);
1086}
1087
1088void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1089 VisitCondition(comp);
1090}
1091
1092void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1093 VisitCondition(comp);
1094}
1095
1096void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1097 VisitCondition(comp);
1098}
1099
1100void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1101 VisitCondition(comp);
1102}
1103
1104void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1105 VisitCondition(comp);
1106}
1107
1108void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1109 VisitCondition(comp);
1110}
1111
1112void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1113 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001114}
1115
1116void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001117 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001118}
1119
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001120void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1121 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001122}
1123
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001124void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001125 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001126}
1127
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001128void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001129 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001130 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001131}
1132
1133void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001134 LocationSummary* locations =
1135 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001136 switch (store->InputAt(1)->GetType()) {
1137 case Primitive::kPrimBoolean:
1138 case Primitive::kPrimByte:
1139 case Primitive::kPrimChar:
1140 case Primitive::kPrimShort:
1141 case Primitive::kPrimInt:
1142 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001143 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001144 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1145 break;
1146
1147 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001148 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001149 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1150 break;
1151
1152 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001153 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001154 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001155}
1156
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001157void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001158 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001159}
1160
1161void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001162 LocationSummary* locations =
1163 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001164 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001165}
1166
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001167void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001168 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001169 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001170}
1171
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001172void LocationsBuilderARM::VisitNullConstant(HNullConstant* constant) {
1173 LocationSummary* locations =
1174 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1175 locations->SetOut(Location::ConstantLocation(constant));
1176}
1177
1178void InstructionCodeGeneratorARM::VisitNullConstant(HNullConstant* constant) {
1179 // Will be generated at use site.
1180 UNUSED(constant);
1181}
1182
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001183void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001184 LocationSummary* locations =
1185 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001186 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001187}
1188
1189void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1190 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001191 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001192}
1193
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001194void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1195 LocationSummary* locations =
1196 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1197 locations->SetOut(Location::ConstantLocation(constant));
1198}
1199
1200void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1201 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001202 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001203}
1204
1205void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1206 LocationSummary* locations =
1207 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1208 locations->SetOut(Location::ConstantLocation(constant));
1209}
1210
1211void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1212 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001213 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001214}
1215
Calin Juravle27df7582015-04-17 19:12:31 +01001216void LocationsBuilderARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1217 memory_barrier->SetLocations(nullptr);
1218}
1219
1220void InstructionCodeGeneratorARM::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
1221 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
1222}
1223
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001224void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001225 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001226}
1227
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001228void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001229 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001230 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001231}
1232
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001233void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001234 LocationSummary* locations =
1235 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001236 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001237}
1238
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001239void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001240 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001241 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001242}
1243
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001244void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001245 // When we do not run baseline, explicit clinit checks triggered by static
1246 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1247 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001248
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001249 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1250 codegen_->GetInstructionSetFeatures());
1251 if (intrinsic.TryDispatch(invoke)) {
1252 return;
1253 }
1254
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001255 HandleInvoke(invoke);
1256}
1257
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001258void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001259 DCHECK(RequiresCurrentMethod());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001260 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001261}
1262
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001263static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM* codegen) {
1264 if (invoke->GetLocations()->Intrinsified()) {
1265 IntrinsicCodeGeneratorARM intrinsic(codegen);
1266 intrinsic.Dispatch(invoke);
1267 return true;
1268 }
1269 return false;
1270}
1271
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001272void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain3e3d7332015-04-28 11:00:54 +01001273 // When we do not run baseline, explicit clinit checks triggered by static
1274 // invokes must have been pruned by art::PrepareForRegisterAllocation.
1275 DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck());
Roland Levillain4c0eb422015-04-24 16:43:49 +01001276
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001277 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1278 return;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001279 }
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001280
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001281 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
1282
1283 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001284 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001285}
1286
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001287void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001288 LocationSummary* locations =
1289 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01001290 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001291
Roland Levillain2d27c8e2015-04-28 15:48:45 +01001292 InvokeDexCallingConventionVisitorARM calling_convention_visitor;
Roland Levillain3e3d7332015-04-28 11:00:54 +01001293 for (size_t i = 0; i < invoke->GetNumberOfArguments(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001294 HInstruction* input = invoke->InputAt(i);
1295 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1296 }
1297
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001298 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001299}
1300
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001301void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001302 IntrinsicLocationsBuilderARM intrinsic(GetGraph()->GetArena(),
1303 codegen_->GetInstructionSetFeatures());
1304 if (intrinsic.TryDispatch(invoke)) {
1305 return;
1306 }
1307
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001308 HandleInvoke(invoke);
1309}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001310
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001311void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001312 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1313 return;
1314 }
1315
Roland Levillain271ab9c2014-11-27 15:23:57 +00001316 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001317 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1318 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1319 LocationSummary* locations = invoke->GetLocations();
1320 Location receiver = locations->InAt(0);
1321 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1322 // temp = object->GetClass();
1323 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001324 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1325 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001326 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001327 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001328 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001329 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001330 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001331 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001332 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001333 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001334 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001335 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001336 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001337 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001338 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001339 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001340}
1341
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001342void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1343 HandleInvoke(invoke);
1344 // Add the hidden argument.
1345 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1346}
1347
1348void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1349 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001350 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001351 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1352 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1353 LocationSummary* locations = invoke->GetLocations();
1354 Location receiver = locations->InAt(0);
1355 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1356
1357 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001358 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1359 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001360
1361 // temp = object->GetClass();
1362 if (receiver.IsStackSlot()) {
1363 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1364 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1365 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001366 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001367 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001368 codegen_->MaybeRecordImplicitNullCheck(invoke);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001369 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001370 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001371 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001372 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1373 // LR = temp->GetEntryPoint();
1374 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1375 // LR();
1376 __ blx(LR);
1377 DCHECK(!codegen_->IsLeafMethod());
1378 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1379}
1380
Roland Levillain88cb1752014-10-20 16:36:47 +01001381void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1382 LocationSummary* locations =
1383 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1384 switch (neg->GetResultType()) {
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001385 case Primitive::kPrimInt: {
Roland Levillain88cb1752014-10-20 16:36:47 +01001386 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001387 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1388 break;
1389 }
1390 case Primitive::kPrimLong: {
1391 locations->SetInAt(0, Location::RequiresRegister());
1392 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001393 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001394 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001395
Roland Levillain88cb1752014-10-20 16:36:47 +01001396 case Primitive::kPrimFloat:
1397 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001398 locations->SetInAt(0, Location::RequiresFpuRegister());
1399 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001400 break;
1401
1402 default:
1403 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1404 }
1405}
1406
1407void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1408 LocationSummary* locations = neg->GetLocations();
1409 Location out = locations->Out();
1410 Location in = locations->InAt(0);
1411 switch (neg->GetResultType()) {
1412 case Primitive::kPrimInt:
1413 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001414 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001415 break;
1416
1417 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001418 DCHECK(in.IsRegisterPair());
1419 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1420 __ rsbs(out.AsRegisterPairLow<Register>(),
1421 in.AsRegisterPairLow<Register>(),
1422 ShifterOperand(0));
1423 // We cannot emit an RSC (Reverse Subtract with Carry)
1424 // instruction here, as it does not exist in the Thumb-2
1425 // instruction set. We use the following approach
1426 // using SBC and SUB instead.
1427 //
1428 // out.hi = -C
1429 __ sbc(out.AsRegisterPairHigh<Register>(),
1430 out.AsRegisterPairHigh<Register>(),
1431 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1432 // out.hi = out.hi - in.hi
1433 __ sub(out.AsRegisterPairHigh<Register>(),
1434 out.AsRegisterPairHigh<Register>(),
1435 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1436 break;
1437
Roland Levillain88cb1752014-10-20 16:36:47 +01001438 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001439 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001440 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001441 break;
1442
Roland Levillain88cb1752014-10-20 16:36:47 +01001443 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001444 DCHECK(in.IsFpuRegisterPair());
1445 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1446 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001447 break;
1448
1449 default:
1450 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1451 }
1452}
1453
Roland Levillaindff1f282014-11-05 14:15:05 +00001454void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001455 Primitive::Type result_type = conversion->GetResultType();
1456 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001457 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001458
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001459 // The float-to-long and double-to-long type conversions rely on a
1460 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001461 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001462 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1463 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001464 ? LocationSummary::kCall
1465 : LocationSummary::kNoCall;
1466 LocationSummary* locations =
1467 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1468
David Brazdilb2bd1c52015-03-25 11:17:37 +00001469 // The Java language does not allow treating boolean as an integral type but
1470 // our bit representation makes it safe.
David Brazdil46e2a392015-03-16 17:31:52 +00001471
Roland Levillaindff1f282014-11-05 14:15:05 +00001472 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001473 case Primitive::kPrimByte:
1474 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001475 case Primitive::kPrimBoolean:
1476 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001477 case Primitive::kPrimShort:
1478 case Primitive::kPrimInt:
1479 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001480 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001481 locations->SetInAt(0, Location::RequiresRegister());
1482 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1483 break;
1484
1485 default:
1486 LOG(FATAL) << "Unexpected type conversion from " << input_type
1487 << " to " << result_type;
1488 }
1489 break;
1490
Roland Levillain01a8d712014-11-14 16:27:39 +00001491 case Primitive::kPrimShort:
1492 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001493 case Primitive::kPrimBoolean:
1494 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001495 case Primitive::kPrimByte:
1496 case Primitive::kPrimInt:
1497 case Primitive::kPrimChar:
1498 // Processing a Dex `int-to-short' instruction.
1499 locations->SetInAt(0, Location::RequiresRegister());
1500 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1501 break;
1502
1503 default:
1504 LOG(FATAL) << "Unexpected type conversion from " << input_type
1505 << " to " << result_type;
1506 }
1507 break;
1508
Roland Levillain946e1432014-11-11 17:35:19 +00001509 case Primitive::kPrimInt:
1510 switch (input_type) {
1511 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001512 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001513 locations->SetInAt(0, Location::Any());
1514 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1515 break;
1516
1517 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001518 // Processing a Dex `float-to-int' instruction.
1519 locations->SetInAt(0, Location::RequiresFpuRegister());
1520 locations->SetOut(Location::RequiresRegister());
1521 locations->AddTemp(Location::RequiresFpuRegister());
1522 break;
1523
Roland Levillain946e1432014-11-11 17:35:19 +00001524 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001525 // Processing a Dex `double-to-int' instruction.
1526 locations->SetInAt(0, Location::RequiresFpuRegister());
1527 locations->SetOut(Location::RequiresRegister());
1528 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001529 break;
1530
1531 default:
1532 LOG(FATAL) << "Unexpected type conversion from " << input_type
1533 << " to " << result_type;
1534 }
1535 break;
1536
Roland Levillaindff1f282014-11-05 14:15:05 +00001537 case Primitive::kPrimLong:
1538 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001539 case Primitive::kPrimBoolean:
1540 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001541 case Primitive::kPrimByte:
1542 case Primitive::kPrimShort:
1543 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001544 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001545 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001546 locations->SetInAt(0, Location::RequiresRegister());
1547 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1548 break;
1549
Roland Levillain624279f2014-12-04 11:54:28 +00001550 case Primitive::kPrimFloat: {
1551 // Processing a Dex `float-to-long' instruction.
1552 InvokeRuntimeCallingConvention calling_convention;
1553 locations->SetInAt(0, Location::FpuRegisterLocation(
1554 calling_convention.GetFpuRegisterAt(0)));
1555 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1556 break;
1557 }
1558
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001559 case Primitive::kPrimDouble: {
1560 // Processing a Dex `double-to-long' instruction.
1561 InvokeRuntimeCallingConvention calling_convention;
1562 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1563 calling_convention.GetFpuRegisterAt(0),
1564 calling_convention.GetFpuRegisterAt(1)));
1565 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001566 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001567 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001568
1569 default:
1570 LOG(FATAL) << "Unexpected type conversion from " << input_type
1571 << " to " << result_type;
1572 }
1573 break;
1574
Roland Levillain981e4542014-11-14 11:47:14 +00001575 case Primitive::kPrimChar:
1576 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001577 case Primitive::kPrimBoolean:
1578 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001579 case Primitive::kPrimByte:
1580 case Primitive::kPrimShort:
1581 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001582 // Processing a Dex `int-to-char' instruction.
1583 locations->SetInAt(0, Location::RequiresRegister());
1584 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1585 break;
1586
1587 default:
1588 LOG(FATAL) << "Unexpected type conversion from " << input_type
1589 << " to " << result_type;
1590 }
1591 break;
1592
Roland Levillaindff1f282014-11-05 14:15:05 +00001593 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001594 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001595 case Primitive::kPrimBoolean:
1596 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001597 case Primitive::kPrimByte:
1598 case Primitive::kPrimShort:
1599 case Primitive::kPrimInt:
1600 case Primitive::kPrimChar:
1601 // Processing a Dex `int-to-float' instruction.
1602 locations->SetInAt(0, Location::RequiresRegister());
1603 locations->SetOut(Location::RequiresFpuRegister());
1604 break;
1605
1606 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001607 // Processing a Dex `long-to-float' instruction.
1608 locations->SetInAt(0, Location::RequiresRegister());
1609 locations->SetOut(Location::RequiresFpuRegister());
1610 locations->AddTemp(Location::RequiresRegister());
1611 locations->AddTemp(Location::RequiresRegister());
1612 locations->AddTemp(Location::RequiresFpuRegister());
1613 locations->AddTemp(Location::RequiresFpuRegister());
1614 break;
1615
Roland Levillaincff13742014-11-17 14:32:17 +00001616 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001617 // Processing a Dex `double-to-float' instruction.
1618 locations->SetInAt(0, Location::RequiresFpuRegister());
1619 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001620 break;
1621
1622 default:
1623 LOG(FATAL) << "Unexpected type conversion from " << input_type
1624 << " to " << result_type;
1625 };
1626 break;
1627
Roland Levillaindff1f282014-11-05 14:15:05 +00001628 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001629 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001630 case Primitive::kPrimBoolean:
1631 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001632 case Primitive::kPrimByte:
1633 case Primitive::kPrimShort:
1634 case Primitive::kPrimInt:
1635 case Primitive::kPrimChar:
1636 // Processing a Dex `int-to-double' instruction.
1637 locations->SetInAt(0, Location::RequiresRegister());
1638 locations->SetOut(Location::RequiresFpuRegister());
1639 break;
1640
1641 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001642 // Processing a Dex `long-to-double' instruction.
1643 locations->SetInAt(0, Location::RequiresRegister());
1644 locations->SetOut(Location::RequiresFpuRegister());
1645 locations->AddTemp(Location::RequiresRegister());
1646 locations->AddTemp(Location::RequiresRegister());
1647 locations->AddTemp(Location::RequiresFpuRegister());
1648 break;
1649
Roland Levillaincff13742014-11-17 14:32:17 +00001650 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001651 // Processing a Dex `float-to-double' instruction.
1652 locations->SetInAt(0, Location::RequiresFpuRegister());
1653 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001654 break;
1655
1656 default:
1657 LOG(FATAL) << "Unexpected type conversion from " << input_type
1658 << " to " << result_type;
1659 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001660 break;
1661
1662 default:
1663 LOG(FATAL) << "Unexpected type conversion from " << input_type
1664 << " to " << result_type;
1665 }
1666}
1667
1668void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1669 LocationSummary* locations = conversion->GetLocations();
1670 Location out = locations->Out();
1671 Location in = locations->InAt(0);
1672 Primitive::Type result_type = conversion->GetResultType();
1673 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001674 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001675 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001676 case Primitive::kPrimByte:
1677 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001678 case Primitive::kPrimBoolean:
1679 // Boolean input is a result of code transformations.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001680 case Primitive::kPrimShort:
1681 case Primitive::kPrimInt:
1682 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001683 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001684 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001685 break;
1686
1687 default:
1688 LOG(FATAL) << "Unexpected type conversion from " << input_type
1689 << " to " << result_type;
1690 }
1691 break;
1692
Roland Levillain01a8d712014-11-14 16:27:39 +00001693 case Primitive::kPrimShort:
1694 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001695 case Primitive::kPrimBoolean:
1696 // Boolean input is a result of code transformations.
Roland Levillain01a8d712014-11-14 16:27:39 +00001697 case Primitive::kPrimByte:
1698 case Primitive::kPrimInt:
1699 case Primitive::kPrimChar:
1700 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001701 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001702 break;
1703
1704 default:
1705 LOG(FATAL) << "Unexpected type conversion from " << input_type
1706 << " to " << result_type;
1707 }
1708 break;
1709
Roland Levillain946e1432014-11-11 17:35:19 +00001710 case Primitive::kPrimInt:
1711 switch (input_type) {
1712 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001713 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001714 DCHECK(out.IsRegister());
1715 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001716 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001717 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001718 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001719 } else {
1720 DCHECK(in.IsConstant());
1721 DCHECK(in.GetConstant()->IsLongConstant());
1722 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001723 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001724 }
1725 break;
1726
Roland Levillain3f8f9362014-12-02 17:45:01 +00001727 case Primitive::kPrimFloat: {
1728 // Processing a Dex `float-to-int' instruction.
1729 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1730 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1731 __ vcvtis(temp, temp);
1732 __ vmovrs(out.AsRegister<Register>(), temp);
1733 break;
1734 }
1735
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001736 case Primitive::kPrimDouble: {
1737 // Processing a Dex `double-to-int' instruction.
1738 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1739 DRegister temp_d = FromLowSToD(temp_s);
1740 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1741 __ vcvtid(temp_s, temp_d);
1742 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001743 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001744 }
Roland Levillain946e1432014-11-11 17:35:19 +00001745
1746 default:
1747 LOG(FATAL) << "Unexpected type conversion from " << input_type
1748 << " to " << result_type;
1749 }
1750 break;
1751
Roland Levillaindff1f282014-11-05 14:15:05 +00001752 case Primitive::kPrimLong:
1753 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001754 case Primitive::kPrimBoolean:
1755 // Boolean input is a result of code transformations.
Roland Levillaindff1f282014-11-05 14:15:05 +00001756 case Primitive::kPrimByte:
1757 case Primitive::kPrimShort:
1758 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001759 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001760 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001761 DCHECK(out.IsRegisterPair());
1762 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001763 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001764 // Sign extension.
1765 __ Asr(out.AsRegisterPairHigh<Register>(),
1766 out.AsRegisterPairLow<Register>(),
1767 31);
1768 break;
1769
1770 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001771 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001772 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1773 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001774 conversion->GetDexPc(),
1775 nullptr);
Roland Levillain624279f2014-12-04 11:54:28 +00001776 break;
1777
Roland Levillaindff1f282014-11-05 14:15:05 +00001778 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001779 // Processing a Dex `double-to-long' instruction.
1780 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1781 conversion,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001782 conversion->GetDexPc(),
1783 nullptr);
Roland Levillaindff1f282014-11-05 14:15:05 +00001784 break;
1785
1786 default:
1787 LOG(FATAL) << "Unexpected type conversion from " << input_type
1788 << " to " << result_type;
1789 }
1790 break;
1791
Roland Levillain981e4542014-11-14 11:47:14 +00001792 case Primitive::kPrimChar:
1793 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001794 case Primitive::kPrimBoolean:
1795 // Boolean input is a result of code transformations.
Roland Levillain981e4542014-11-14 11:47:14 +00001796 case Primitive::kPrimByte:
1797 case Primitive::kPrimShort:
1798 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001799 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001800 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001801 break;
1802
1803 default:
1804 LOG(FATAL) << "Unexpected type conversion from " << input_type
1805 << " to " << result_type;
1806 }
1807 break;
1808
Roland Levillaindff1f282014-11-05 14:15:05 +00001809 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001810 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001811 case Primitive::kPrimBoolean:
1812 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001813 case Primitive::kPrimByte:
1814 case Primitive::kPrimShort:
1815 case Primitive::kPrimInt:
1816 case Primitive::kPrimChar: {
1817 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001818 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1819 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001820 break;
1821 }
1822
Roland Levillain6d0e4832014-11-27 18:31:21 +00001823 case Primitive::kPrimLong: {
1824 // Processing a Dex `long-to-float' instruction.
1825 Register low = in.AsRegisterPairLow<Register>();
1826 Register high = in.AsRegisterPairHigh<Register>();
1827 SRegister output = out.AsFpuRegister<SRegister>();
1828 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1829 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1830 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1831 DRegister temp1_d = FromLowSToD(temp1_s);
1832 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1833 DRegister temp2_d = FromLowSToD(temp2_s);
1834
1835 // Operations use doubles for precision reasons (each 32-bit
1836 // half of a long fits in the 53-bit mantissa of a double,
1837 // but not in the 24-bit mantissa of a float). This is
1838 // especially important for the low bits. The result is
1839 // eventually converted to float.
1840
1841 // temp1_d = int-to-double(high)
1842 __ vmovsr(temp1_s, high);
1843 __ vcvtdi(temp1_d, temp1_s);
1844 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1845 // as an immediate value into `temp2_d` does not work, as
1846 // this instruction only transfers 8 significant bits of its
1847 // immediate operand. Instead, use two 32-bit core
1848 // registers to load `k2Pow32EncodingForDouble` into
1849 // `temp2_d`.
1850 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1851 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1852 __ vmovdrr(temp2_d, constant_low, constant_high);
1853 // temp1_d = temp1_d * 2^32
1854 __ vmuld(temp1_d, temp1_d, temp2_d);
1855 // temp2_d = unsigned-to-double(low)
1856 __ vmovsr(temp2_s, low);
1857 __ vcvtdu(temp2_d, temp2_s);
1858 // temp1_d = temp1_d + temp2_d
1859 __ vaddd(temp1_d, temp1_d, temp2_d);
1860 // output = double-to-float(temp1_d);
1861 __ vcvtsd(output, temp1_d);
1862 break;
1863 }
1864
Roland Levillaincff13742014-11-17 14:32:17 +00001865 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001866 // Processing a Dex `double-to-float' instruction.
1867 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1868 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001869 break;
1870
1871 default:
1872 LOG(FATAL) << "Unexpected type conversion from " << input_type
1873 << " to " << result_type;
1874 };
1875 break;
1876
Roland Levillaindff1f282014-11-05 14:15:05 +00001877 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001878 switch (input_type) {
David Brazdil46e2a392015-03-16 17:31:52 +00001879 case Primitive::kPrimBoolean:
1880 // Boolean input is a result of code transformations.
Roland Levillaincff13742014-11-17 14:32:17 +00001881 case Primitive::kPrimByte:
1882 case Primitive::kPrimShort:
1883 case Primitive::kPrimInt:
1884 case Primitive::kPrimChar: {
1885 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001886 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001887 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1888 out.AsFpuRegisterPairLow<SRegister>());
1889 break;
1890 }
1891
Roland Levillain647b9ed2014-11-27 12:06:00 +00001892 case Primitive::kPrimLong: {
1893 // Processing a Dex `long-to-double' instruction.
1894 Register low = in.AsRegisterPairLow<Register>();
1895 Register high = in.AsRegisterPairHigh<Register>();
1896 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1897 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001898 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1899 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001900 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1901 DRegister temp_d = FromLowSToD(temp_s);
1902
Roland Levillain647b9ed2014-11-27 12:06:00 +00001903 // out_d = int-to-double(high)
1904 __ vmovsr(out_s, high);
1905 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001906 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1907 // as an immediate value into `temp_d` does not work, as
1908 // this instruction only transfers 8 significant bits of its
1909 // immediate operand. Instead, use two 32-bit core
1910 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1911 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1912 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001913 __ vmovdrr(temp_d, constant_low, constant_high);
1914 // out_d = out_d * 2^32
1915 __ vmuld(out_d, out_d, temp_d);
1916 // temp_d = unsigned-to-double(low)
1917 __ vmovsr(temp_s, low);
1918 __ vcvtdu(temp_d, temp_s);
1919 // out_d = out_d + temp_d
1920 __ vaddd(out_d, out_d, temp_d);
1921 break;
1922 }
1923
Roland Levillaincff13742014-11-17 14:32:17 +00001924 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001925 // Processing a Dex `float-to-double' instruction.
1926 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1927 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001928 break;
1929
1930 default:
1931 LOG(FATAL) << "Unexpected type conversion from " << input_type
1932 << " to " << result_type;
1933 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001934 break;
1935
1936 default:
1937 LOG(FATAL) << "Unexpected type conversion from " << input_type
1938 << " to " << result_type;
1939 }
1940}
1941
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001942void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001943 LocationSummary* locations =
1944 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001945 switch (add->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001946 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001947 locations->SetInAt(0, Location::RequiresRegister());
1948 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001949 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1950 break;
1951 }
1952
1953 case Primitive::kPrimLong: {
1954 locations->SetInAt(0, Location::RequiresRegister());
1955 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00001956 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001957 break;
1958 }
1959
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001960 case Primitive::kPrimFloat:
1961 case Primitive::kPrimDouble: {
1962 locations->SetInAt(0, Location::RequiresFpuRegister());
1963 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001964 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001965 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001966 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001967
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001968 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001969 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001970 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001971}
1972
1973void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1974 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001975 Location out = locations->Out();
1976 Location first = locations->InAt(0);
1977 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001978 switch (add->GetResultType()) {
1979 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001980 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001981 __ add(out.AsRegister<Register>(),
1982 first.AsRegister<Register>(),
1983 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001984 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001985 __ AddConstant(out.AsRegister<Register>(),
1986 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001987 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001988 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001989 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001990
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001991 case Primitive::kPrimLong: {
1992 DCHECK(second.IsRegisterPair());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001993 __ adds(out.AsRegisterPairLow<Register>(),
1994 first.AsRegisterPairLow<Register>(),
1995 ShifterOperand(second.AsRegisterPairLow<Register>()));
1996 __ adc(out.AsRegisterPairHigh<Register>(),
1997 first.AsRegisterPairHigh<Register>(),
1998 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001999 break;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002000 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002001
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002002 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00002003 __ vadds(out.AsFpuRegister<SRegister>(),
2004 first.AsFpuRegister<SRegister>(),
2005 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002006 break;
2007
2008 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002009 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2010 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2011 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002012 break;
2013
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002014 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01002015 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002016 }
2017}
2018
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002019void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002020 LocationSummary* locations =
2021 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002022 switch (sub->GetResultType()) {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002023 case Primitive::kPrimInt: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002024 locations->SetInAt(0, Location::RequiresRegister());
2025 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002026 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2027 break;
2028 }
2029
2030 case Primitive::kPrimLong: {
2031 locations->SetInAt(0, Location::RequiresRegister());
2032 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002033 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002034 break;
2035 }
Calin Juravle11351682014-10-23 15:38:15 +01002036 case Primitive::kPrimFloat:
2037 case Primitive::kPrimDouble: {
2038 locations->SetInAt(0, Location::RequiresFpuRegister());
2039 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002040 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002041 break;
Calin Juravle11351682014-10-23 15:38:15 +01002042 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002043 default:
Calin Juravle11351682014-10-23 15:38:15 +01002044 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002045 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002046}
2047
2048void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
2049 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01002050 Location out = locations->Out();
2051 Location first = locations->InAt(0);
2052 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002053 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002054 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01002055 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002056 __ sub(out.AsRegister<Register>(),
2057 first.AsRegister<Register>(),
2058 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002059 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002060 __ AddConstant(out.AsRegister<Register>(),
2061 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01002062 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002063 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002064 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002065 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002066
Calin Juravle11351682014-10-23 15:38:15 +01002067 case Primitive::kPrimLong: {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002068 DCHECK(second.IsRegisterPair());
Calin Juravle11351682014-10-23 15:38:15 +01002069 __ subs(out.AsRegisterPairLow<Register>(),
2070 first.AsRegisterPairLow<Register>(),
2071 ShifterOperand(second.AsRegisterPairLow<Register>()));
2072 __ sbc(out.AsRegisterPairHigh<Register>(),
2073 first.AsRegisterPairHigh<Register>(),
2074 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002075 break;
Calin Juravle11351682014-10-23 15:38:15 +01002076 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002077
Calin Juravle11351682014-10-23 15:38:15 +01002078 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002079 __ vsubs(out.AsFpuRegister<SRegister>(),
2080 first.AsFpuRegister<SRegister>(),
2081 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002082 break;
Calin Juravle11351682014-10-23 15:38:15 +01002083 }
2084
2085 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002086 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2087 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2088 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01002089 break;
2090 }
2091
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002092
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002093 default:
Calin Juravle11351682014-10-23 15:38:15 +01002094 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002095 }
2096}
2097
Calin Juravle34bacdf2014-10-07 20:23:36 +01002098void LocationsBuilderARM::VisitMul(HMul* mul) {
2099 LocationSummary* locations =
2100 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2101 switch (mul->GetResultType()) {
2102 case Primitive::kPrimInt:
2103 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002104 locations->SetInAt(0, Location::RequiresRegister());
2105 locations->SetInAt(1, Location::RequiresRegister());
2106 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002107 break;
2108 }
2109
Calin Juravleb5bfa962014-10-21 18:02:24 +01002110 case Primitive::kPrimFloat:
2111 case Primitive::kPrimDouble: {
2112 locations->SetInAt(0, Location::RequiresFpuRegister());
2113 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002114 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01002115 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002116 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002117
2118 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002119 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002120 }
2121}
2122
2123void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
2124 LocationSummary* locations = mul->GetLocations();
2125 Location out = locations->Out();
2126 Location first = locations->InAt(0);
2127 Location second = locations->InAt(1);
2128 switch (mul->GetResultType()) {
2129 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002130 __ mul(out.AsRegister<Register>(),
2131 first.AsRegister<Register>(),
2132 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002133 break;
2134 }
2135 case Primitive::kPrimLong: {
2136 Register out_hi = out.AsRegisterPairHigh<Register>();
2137 Register out_lo = out.AsRegisterPairLow<Register>();
2138 Register in1_hi = first.AsRegisterPairHigh<Register>();
2139 Register in1_lo = first.AsRegisterPairLow<Register>();
2140 Register in2_hi = second.AsRegisterPairHigh<Register>();
2141 Register in2_lo = second.AsRegisterPairLow<Register>();
2142
2143 // Extra checks to protect caused by the existence of R1_R2.
2144 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
2145 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
2146 DCHECK_NE(out_hi, in1_lo);
2147 DCHECK_NE(out_hi, in2_lo);
2148
2149 // input: in1 - 64 bits, in2 - 64 bits
2150 // output: out
2151 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2152 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2153 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2154
2155 // IP <- in1.lo * in2.hi
2156 __ mul(IP, in1_lo, in2_hi);
2157 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2158 __ mla(out_hi, in1_hi, in2_lo, IP);
2159 // out.lo <- (in1.lo * in2.lo)[31:0];
2160 __ umull(out_lo, IP, in1_lo, in2_lo);
2161 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2162 __ add(out_hi, out_hi, ShifterOperand(IP));
2163 break;
2164 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002165
2166 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002167 __ vmuls(out.AsFpuRegister<SRegister>(),
2168 first.AsFpuRegister<SRegister>(),
2169 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002170 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002171 }
2172
2173 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002174 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2175 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2176 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002177 break;
2178 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002179
2180 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002181 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002182 }
2183}
2184
Zheng Xuc6667102015-05-15 16:08:45 +08002185void InstructionCodeGeneratorARM::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2186 DCHECK(instruction->IsDiv() || instruction->IsRem());
2187 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2188
2189 LocationSummary* locations = instruction->GetLocations();
2190 Location second = locations->InAt(1);
2191 DCHECK(second.IsConstant());
2192
2193 Register out = locations->Out().AsRegister<Register>();
2194 Register dividend = locations->InAt(0).AsRegister<Register>();
2195 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2196 DCHECK(imm == 1 || imm == -1);
2197
2198 if (instruction->IsRem()) {
2199 __ LoadImmediate(out, 0);
2200 } else {
2201 if (imm == 1) {
2202 __ Mov(out, dividend);
2203 } else {
2204 __ rsb(out, dividend, ShifterOperand(0));
2205 }
2206 }
2207}
2208
2209void InstructionCodeGeneratorARM::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2210 DCHECK(instruction->IsDiv() || instruction->IsRem());
2211 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2212
2213 LocationSummary* locations = instruction->GetLocations();
2214 Location second = locations->InAt(1);
2215 DCHECK(second.IsConstant());
2216
2217 Register out = locations->Out().AsRegister<Register>();
2218 Register dividend = locations->InAt(0).AsRegister<Register>();
2219 Register temp = locations->GetTemp(0).AsRegister<Register>();
2220 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Vladimir Marko80afd022015-05-19 18:08:00 +01002221 uint32_t abs_imm = static_cast<uint32_t>(std::abs(imm));
Zheng Xuc6667102015-05-15 16:08:45 +08002222 DCHECK(IsPowerOfTwo(abs_imm));
2223 int ctz_imm = CTZ(abs_imm);
2224
2225 if (ctz_imm == 1) {
2226 __ Lsr(temp, dividend, 32 - ctz_imm);
2227 } else {
2228 __ Asr(temp, dividend, 31);
2229 __ Lsr(temp, temp, 32 - ctz_imm);
2230 }
2231 __ add(out, temp, ShifterOperand(dividend));
2232
2233 if (instruction->IsDiv()) {
2234 __ Asr(out, out, ctz_imm);
2235 if (imm < 0) {
2236 __ rsb(out, out, ShifterOperand(0));
2237 }
2238 } else {
2239 __ ubfx(out, out, 0, ctz_imm);
2240 __ sub(out, out, ShifterOperand(temp));
2241 }
2242}
2243
2244void InstructionCodeGeneratorARM::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2245 DCHECK(instruction->IsDiv() || instruction->IsRem());
2246 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2247
2248 LocationSummary* locations = instruction->GetLocations();
2249 Location second = locations->InAt(1);
2250 DCHECK(second.IsConstant());
2251
2252 Register out = locations->Out().AsRegister<Register>();
2253 Register dividend = locations->InAt(0).AsRegister<Register>();
2254 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
2255 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
2256 int64_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2257
2258 int64_t magic;
2259 int shift;
2260 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2261
2262 __ LoadImmediate(temp1, magic);
2263 __ smull(temp2, temp1, dividend, temp1);
2264
2265 if (imm > 0 && magic < 0) {
2266 __ add(temp1, temp1, ShifterOperand(dividend));
2267 } else if (imm < 0 && magic > 0) {
2268 __ sub(temp1, temp1, ShifterOperand(dividend));
2269 }
2270
2271 if (shift != 0) {
2272 __ Asr(temp1, temp1, shift);
2273 }
2274
2275 if (instruction->IsDiv()) {
2276 __ sub(out, temp1, ShifterOperand(temp1, ASR, 31));
2277 } else {
2278 __ sub(temp1, temp1, ShifterOperand(temp1, ASR, 31));
2279 // TODO: Strength reduction for mls.
2280 __ LoadImmediate(temp2, imm);
2281 __ mls(out, temp1, temp2, dividend);
2282 }
2283}
2284
2285void InstructionCodeGeneratorARM::GenerateDivRemConstantIntegral(HBinaryOperation* instruction) {
2286 DCHECK(instruction->IsDiv() || instruction->IsRem());
2287 DCHECK(instruction->GetResultType() == Primitive::kPrimInt);
2288
2289 LocationSummary* locations = instruction->GetLocations();
2290 Location second = locations->InAt(1);
2291 DCHECK(second.IsConstant());
2292
2293 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2294 if (imm == 0) {
2295 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2296 } else if (imm == 1 || imm == -1) {
2297 DivRemOneOrMinusOne(instruction);
2298 } else if (IsPowerOfTwo(std::abs(imm))) {
2299 DivRemByPowerOfTwo(instruction);
2300 } else {
2301 DCHECK(imm <= -2 || imm >= 2);
2302 GenerateDivRemWithAnyConstant(instruction);
2303 }
2304}
2305
Calin Juravle7c4954d2014-10-28 16:57:40 +00002306void LocationsBuilderARM::VisitDiv(HDiv* div) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002307 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
2308 if (div->GetResultType() == Primitive::kPrimLong) {
2309 // pLdiv runtime call.
2310 call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002311 } else if (div->GetResultType() == Primitive::kPrimInt && div->InputAt(1)->IsConstant()) {
2312 // sdiv will be replaced by other instruction sequence.
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002313 } else if (div->GetResultType() == Primitive::kPrimInt &&
2314 !codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
2315 // pIdivmod runtime call.
2316 call_kind = LocationSummary::kCall;
2317 }
2318
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002319 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2320
Calin Juravle7c4954d2014-10-28 16:57:40 +00002321 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002322 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002323 if (div->InputAt(1)->IsConstant()) {
2324 locations->SetInAt(0, Location::RequiresRegister());
2325 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
2326 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2327 int32_t abs_imm = std::abs(div->InputAt(1)->AsIntConstant()->GetValue());
2328 if (abs_imm <= 1) {
2329 // No temp register required.
2330 } else {
2331 locations->AddTemp(Location::RequiresRegister());
2332 if (!IsPowerOfTwo(abs_imm)) {
2333 locations->AddTemp(Location::RequiresRegister());
2334 }
2335 }
2336 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002337 locations->SetInAt(0, Location::RequiresRegister());
2338 locations->SetInAt(1, Location::RequiresRegister());
2339 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2340 } else {
2341 InvokeRuntimeCallingConvention calling_convention;
2342 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2343 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2344 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2345 // we only need the former.
2346 locations->SetOut(Location::RegisterLocation(R0));
2347 }
Calin Juravled0d48522014-11-04 16:40:20 +00002348 break;
2349 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002350 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002351 InvokeRuntimeCallingConvention calling_convention;
2352 locations->SetInAt(0, Location::RegisterPairLocation(
2353 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2354 locations->SetInAt(1, Location::RegisterPairLocation(
2355 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002356 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002357 break;
2358 }
2359 case Primitive::kPrimFloat:
2360 case Primitive::kPrimDouble: {
2361 locations->SetInAt(0, Location::RequiresFpuRegister());
2362 locations->SetInAt(1, Location::RequiresFpuRegister());
2363 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2364 break;
2365 }
2366
2367 default:
2368 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2369 }
2370}
2371
2372void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2373 LocationSummary* locations = div->GetLocations();
2374 Location out = locations->Out();
2375 Location first = locations->InAt(0);
2376 Location second = locations->InAt(1);
2377
2378 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002379 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002380 if (second.IsConstant()) {
2381 GenerateDivRemConstantIntegral(div);
2382 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002383 __ sdiv(out.AsRegister<Register>(),
2384 first.AsRegister<Register>(),
2385 second.AsRegister<Register>());
2386 } else {
2387 InvokeRuntimeCallingConvention calling_convention;
2388 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2389 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2390 DCHECK_EQ(R0, out.AsRegister<Register>());
2391
2392 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), div, div->GetDexPc(), nullptr);
2393 }
Calin Juravled0d48522014-11-04 16:40:20 +00002394 break;
2395 }
2396
Calin Juravle7c4954d2014-10-28 16:57:40 +00002397 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002398 InvokeRuntimeCallingConvention calling_convention;
2399 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2400 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2401 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2402 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2403 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00002404 DCHECK_EQ(R1, out.AsRegisterPairHigh<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002405
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002406 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc(), nullptr);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002407 break;
2408 }
2409
2410 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002411 __ vdivs(out.AsFpuRegister<SRegister>(),
2412 first.AsFpuRegister<SRegister>(),
2413 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002414 break;
2415 }
2416
2417 case Primitive::kPrimDouble: {
2418 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2419 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2420 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2421 break;
2422 }
2423
2424 default:
2425 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2426 }
2427}
2428
Calin Juravlebacfec32014-11-14 15:54:36 +00002429void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002430 Primitive::Type type = rem->GetResultType();
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002431
2432 // Most remainders are implemented in the runtime.
2433 LocationSummary::CallKind call_kind = LocationSummary::kCall;
Zheng Xuc6667102015-05-15 16:08:45 +08002434 if (rem->GetResultType() == Primitive::kPrimInt && rem->InputAt(1)->IsConstant()) {
2435 // sdiv will be replaced by other instruction sequence.
2436 call_kind = LocationSummary::kNoCall;
2437 } else if ((rem->GetResultType() == Primitive::kPrimInt)
2438 && codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002439 // Have hardware divide instruction for int, do it with three instructions.
2440 call_kind = LocationSummary::kNoCall;
2441 }
2442
Calin Juravlebacfec32014-11-14 15:54:36 +00002443 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2444
Calin Juravled2ec87d2014-12-08 14:24:46 +00002445 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002446 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002447 if (rem->InputAt(1)->IsConstant()) {
2448 locations->SetInAt(0, Location::RequiresRegister());
2449 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
2450 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2451 int32_t abs_imm = std::abs(rem->InputAt(1)->AsIntConstant()->GetValue());
2452 if (abs_imm <= 1) {
2453 // No temp register required.
2454 } else {
2455 locations->AddTemp(Location::RequiresRegister());
2456 if (!IsPowerOfTwo(abs_imm)) {
2457 locations->AddTemp(Location::RequiresRegister());
2458 }
2459 }
2460 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002461 locations->SetInAt(0, Location::RequiresRegister());
2462 locations->SetInAt(1, Location::RequiresRegister());
2463 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2464 locations->AddTemp(Location::RequiresRegister());
2465 } else {
2466 InvokeRuntimeCallingConvention calling_convention;
2467 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2468 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2469 // Note: divrem will compute both the quotient and the remainder as the pair R0 and R1, but
2470 // we only need the latter.
2471 locations->SetOut(Location::RegisterLocation(R1));
2472 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002473 break;
2474 }
2475 case Primitive::kPrimLong: {
2476 InvokeRuntimeCallingConvention calling_convention;
2477 locations->SetInAt(0, Location::RegisterPairLocation(
2478 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2479 locations->SetInAt(1, Location::RegisterPairLocation(
2480 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2481 // The runtime helper puts the output in R2,R3.
2482 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2483 break;
2484 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002485 case Primitive::kPrimFloat: {
2486 InvokeRuntimeCallingConvention calling_convention;
2487 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2488 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2489 locations->SetOut(Location::FpuRegisterLocation(S0));
2490 break;
2491 }
2492
Calin Juravlebacfec32014-11-14 15:54:36 +00002493 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002494 InvokeRuntimeCallingConvention calling_convention;
2495 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2496 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2497 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2498 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2499 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002500 break;
2501 }
2502
2503 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002504 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002505 }
2506}
2507
2508void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2509 LocationSummary* locations = rem->GetLocations();
2510 Location out = locations->Out();
2511 Location first = locations->InAt(0);
2512 Location second = locations->InAt(1);
2513
Calin Juravled2ec87d2014-12-08 14:24:46 +00002514 Primitive::Type type = rem->GetResultType();
2515 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002516 case Primitive::kPrimInt: {
Zheng Xuc6667102015-05-15 16:08:45 +08002517 if (second.IsConstant()) {
2518 GenerateDivRemConstantIntegral(rem);
2519 } else if (codegen_->GetInstructionSetFeatures().HasDivideInstruction()) {
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002520 Register reg1 = first.AsRegister<Register>();
2521 Register reg2 = second.AsRegister<Register>();
2522 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002523
Andreas Gampeb51cdb32015-03-29 17:32:48 -07002524 // temp = reg1 / reg2 (integer division)
2525 // temp = temp * reg2
2526 // dest = reg1 - temp
2527 __ sdiv(temp, reg1, reg2);
2528 __ mul(temp, temp, reg2);
2529 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
2530 } else {
2531 InvokeRuntimeCallingConvention calling_convention;
2532 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegister<Register>());
2533 DCHECK_EQ(calling_convention.GetRegisterAt(1), second.AsRegister<Register>());
2534 DCHECK_EQ(R1, out.AsRegister<Register>());
2535
2536 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pIdivmod), rem, rem->GetDexPc(), nullptr);
2537 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002538 break;
2539 }
2540
2541 case Primitive::kPrimLong: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002542 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002543 break;
2544 }
2545
Calin Juravled2ec87d2014-12-08 14:24:46 +00002546 case Primitive::kPrimFloat: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002547 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc(), nullptr);
Calin Juravled2ec87d2014-12-08 14:24:46 +00002548 break;
2549 }
2550
Calin Juravlebacfec32014-11-14 15:54:36 +00002551 case Primitive::kPrimDouble: {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002552 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc(), nullptr);
Calin Juravlebacfec32014-11-14 15:54:36 +00002553 break;
2554 }
2555
2556 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002557 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002558 }
2559}
2560
Calin Juravled0d48522014-11-04 16:40:20 +00002561void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2562 LocationSummary* locations =
2563 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002564 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002565 if (instruction->HasUses()) {
2566 locations->SetOut(Location::SameAsFirstInput());
2567 }
2568}
2569
2570void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2571 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2572 codegen_->AddSlowPath(slow_path);
2573
2574 LocationSummary* locations = instruction->GetLocations();
2575 Location value = locations->InAt(0);
2576
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002577 switch (instruction->GetType()) {
2578 case Primitive::kPrimInt: {
2579 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002580 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002581 __ b(slow_path->GetEntryLabel(), EQ);
2582 } else {
2583 DCHECK(value.IsConstant()) << value;
2584 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2585 __ b(slow_path->GetEntryLabel());
2586 }
2587 }
2588 break;
2589 }
2590 case Primitive::kPrimLong: {
2591 if (value.IsRegisterPair()) {
2592 __ orrs(IP,
2593 value.AsRegisterPairLow<Register>(),
2594 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2595 __ b(slow_path->GetEntryLabel(), EQ);
2596 } else {
2597 DCHECK(value.IsConstant()) << value;
2598 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2599 __ b(slow_path->GetEntryLabel());
2600 }
2601 }
2602 break;
2603 default:
2604 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2605 }
2606 }
Calin Juravled0d48522014-11-04 16:40:20 +00002607}
2608
Calin Juravle9aec02f2014-11-18 23:06:35 +00002609void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2610 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2611
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002612 LocationSummary* locations =
2613 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002614
2615 switch (op->GetResultType()) {
2616 case Primitive::kPrimInt: {
2617 locations->SetInAt(0, Location::RequiresRegister());
2618 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002619 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002620 break;
2621 }
2622 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002623 locations->SetInAt(0, Location::RequiresRegister());
2624 locations->SetInAt(1, Location::RequiresRegister());
2625 locations->AddTemp(Location::RequiresRegister());
2626 locations->SetOut(Location::RequiresRegister());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002627 break;
2628 }
2629 default:
2630 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2631 }
2632}
2633
2634void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2635 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2636
2637 LocationSummary* locations = op->GetLocations();
2638 Location out = locations->Out();
2639 Location first = locations->InAt(0);
2640 Location second = locations->InAt(1);
2641
2642 Primitive::Type type = op->GetResultType();
2643 switch (type) {
2644 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002645 Register out_reg = out.AsRegister<Register>();
2646 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002647 // Arm doesn't mask the shift count so we need to do it ourselves.
2648 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002649 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002650 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2651 if (op->IsShl()) {
2652 __ Lsl(out_reg, first_reg, second_reg);
2653 } else if (op->IsShr()) {
2654 __ Asr(out_reg, first_reg, second_reg);
2655 } else {
2656 __ Lsr(out_reg, first_reg, second_reg);
2657 }
2658 } else {
2659 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2660 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2661 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2662 __ Mov(out_reg, first_reg);
2663 } else if (op->IsShl()) {
2664 __ Lsl(out_reg, first_reg, shift_value);
2665 } else if (op->IsShr()) {
2666 __ Asr(out_reg, first_reg, shift_value);
2667 } else {
2668 __ Lsr(out_reg, first_reg, shift_value);
2669 }
2670 }
2671 break;
2672 }
2673 case Primitive::kPrimLong: {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002674 Register o_h = out.AsRegisterPairHigh<Register>();
2675 Register o_l = out.AsRegisterPairLow<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002676
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002677 Register temp = locations->GetTemp(0).AsRegister<Register>();
2678
2679 Register high = first.AsRegisterPairHigh<Register>();
2680 Register low = first.AsRegisterPairLow<Register>();
2681
2682 Register second_reg = second.AsRegister<Register>();
2683
Calin Juravle9aec02f2014-11-18 23:06:35 +00002684 if (op->IsShl()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002685 // Shift the high part
2686 __ and_(second_reg, second_reg, ShifterOperand(63));
2687 __ Lsl(o_h, high, second_reg);
2688 // Shift the low part and `or` what overflew on the high part
2689 __ rsb(temp, second_reg, ShifterOperand(32));
2690 __ Lsr(temp, low, temp);
2691 __ orr(o_h, o_h, ShifterOperand(temp));
2692 // If the shift is > 32 bits, override the high part
2693 __ subs(temp, second_reg, ShifterOperand(32));
2694 __ it(PL);
2695 __ Lsl(o_h, low, temp, false, PL);
2696 // Shift the low part
2697 __ Lsl(o_l, low, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002698 } else if (op->IsShr()) {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002699 // Shift the low part
2700 __ and_(second_reg, second_reg, ShifterOperand(63));
2701 __ Lsr(o_l, low, second_reg);
2702 // Shift the high part and `or` what underflew on the low part
2703 __ rsb(temp, second_reg, ShifterOperand(32));
2704 __ Lsl(temp, high, temp);
2705 __ orr(o_l, o_l, ShifterOperand(temp));
2706 // If the shift is > 32 bits, override the low part
2707 __ subs(temp, second_reg, ShifterOperand(32));
2708 __ it(PL);
2709 __ Asr(o_l, high, temp, false, PL);
2710 // Shift the high part
2711 __ Asr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002712 } else {
Guillaume "Vermeille" Sanchezfd18f5a2015-03-11 14:57:40 +00002713 // same as Shr except we use `Lsr`s and not `Asr`s
2714 __ and_(second_reg, second_reg, ShifterOperand(63));
2715 __ Lsr(o_l, low, second_reg);
2716 __ rsb(temp, second_reg, ShifterOperand(32));
2717 __ Lsl(temp, high, temp);
2718 __ orr(o_l, o_l, ShifterOperand(temp));
2719 __ subs(temp, second_reg, ShifterOperand(32));
2720 __ it(PL);
2721 __ Lsr(o_l, high, temp, false, PL);
2722 __ Lsr(o_h, high, second_reg);
Calin Juravle9aec02f2014-11-18 23:06:35 +00002723 }
Calin Juravle9aec02f2014-11-18 23:06:35 +00002724 break;
2725 }
2726 default:
2727 LOG(FATAL) << "Unexpected operation type " << type;
2728 }
2729}
2730
2731void LocationsBuilderARM::VisitShl(HShl* shl) {
2732 HandleShift(shl);
2733}
2734
2735void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2736 HandleShift(shl);
2737}
2738
2739void LocationsBuilderARM::VisitShr(HShr* shr) {
2740 HandleShift(shr);
2741}
2742
2743void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2744 HandleShift(shr);
2745}
2746
2747void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2748 HandleShift(ushr);
2749}
2750
2751void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2752 HandleShift(ushr);
2753}
2754
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002755void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002756 LocationSummary* locations =
2757 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002758 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002759 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2760 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2761 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002762}
2763
2764void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2765 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002766 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002767 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002768 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2769 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002770 instruction->GetDexPc(),
2771 nullptr);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002772}
2773
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002774void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2775 LocationSummary* locations =
2776 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2777 InvokeRuntimeCallingConvention calling_convention;
2778 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002779 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002780 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002781 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002782}
2783
2784void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2785 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002786 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002787 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002788 codegen_->InvokeRuntime(GetThreadOffset<kArmWordSize>(instruction->GetEntrypoint()).Int32Value(),
2789 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002790 instruction->GetDexPc(),
2791 nullptr);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002792}
2793
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002794void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002795 LocationSummary* locations =
2796 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002797 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2798 if (location.IsStackSlot()) {
2799 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2800 } else if (location.IsDoubleStackSlot()) {
2801 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002802 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002803 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002804}
2805
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002806void InstructionCodeGeneratorARM::VisitParameterValue(
2807 HParameterValue* instruction ATTRIBUTE_UNUSED) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002808 // Nothing to do, the parameter is already at its location.
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01002809}
2810
2811void LocationsBuilderARM::VisitCurrentMethod(HCurrentMethod* instruction) {
2812 LocationSummary* locations =
2813 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2814 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
2815}
2816
2817void InstructionCodeGeneratorARM::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) {
2818 // Nothing to do, the method is already at its location.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002819}
2820
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002821void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002822 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002823 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002824 locations->SetInAt(0, Location::RequiresRegister());
2825 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002826}
2827
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002828void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2829 LocationSummary* locations = not_->GetLocations();
2830 Location out = locations->Out();
2831 Location in = locations->InAt(0);
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002832 switch (not_->GetResultType()) {
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002833 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002834 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002835 break;
2836
2837 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002838 __ mvn(out.AsRegisterPairLow<Register>(),
2839 ShifterOperand(in.AsRegisterPairLow<Register>()));
2840 __ mvn(out.AsRegisterPairHigh<Register>(),
2841 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002842 break;
2843
2844 default:
2845 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2846 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002847}
2848
David Brazdil66d126e2015-04-03 16:02:44 +01002849void LocationsBuilderARM::VisitBooleanNot(HBooleanNot* bool_not) {
2850 LocationSummary* locations =
2851 new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall);
2852 locations->SetInAt(0, Location::RequiresRegister());
2853 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2854}
2855
2856void InstructionCodeGeneratorARM::VisitBooleanNot(HBooleanNot* bool_not) {
David Brazdil66d126e2015-04-03 16:02:44 +01002857 LocationSummary* locations = bool_not->GetLocations();
2858 Location out = locations->Out();
2859 Location in = locations->InAt(0);
2860 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
2861}
2862
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002863void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002864 LocationSummary* locations =
2865 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002866 switch (compare->InputAt(0)->GetType()) {
2867 case Primitive::kPrimLong: {
2868 locations->SetInAt(0, Location::RequiresRegister());
2869 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00002870 // Output overlaps because it is written before doing the low comparison.
2871 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Calin Juravleddb7df22014-11-25 20:56:51 +00002872 break;
2873 }
2874 case Primitive::kPrimFloat:
2875 case Primitive::kPrimDouble: {
2876 locations->SetInAt(0, Location::RequiresFpuRegister());
2877 locations->SetInAt(1, Location::RequiresFpuRegister());
2878 locations->SetOut(Location::RequiresRegister());
2879 break;
2880 }
2881 default:
2882 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2883 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002884}
2885
2886void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002887 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002888 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002889 Location left = locations->InAt(0);
2890 Location right = locations->InAt(1);
2891
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002892 NearLabel less, greater, done;
Calin Juravleddb7df22014-11-25 20:56:51 +00002893 Primitive::Type type = compare->InputAt(0)->GetType();
2894 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002895 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002896 __ cmp(left.AsRegisterPairHigh<Register>(),
2897 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002898 __ b(&less, LT);
2899 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002900 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2901 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002902 __ cmp(left.AsRegisterPairLow<Register>(),
2903 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002904 break;
2905 }
2906 case Primitive::kPrimFloat:
2907 case Primitive::kPrimDouble: {
2908 __ LoadImmediate(out, 0);
2909 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002910 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002911 } else {
2912 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2913 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2914 }
2915 __ vmstat(); // transfer FP status register to ARM APSR.
2916 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002917 break;
2918 }
2919 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002920 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002921 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002922 __ b(&done, EQ);
2923 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2924
2925 __ Bind(&greater);
2926 __ LoadImmediate(out, 1);
2927 __ b(&done);
2928
2929 __ Bind(&less);
2930 __ LoadImmediate(out, -1);
2931
2932 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002933}
2934
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002935void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002936 LocationSummary* locations =
2937 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002938 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2939 locations->SetInAt(i, Location::Any());
2940 }
2941 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002942}
2943
2944void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002945 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002946 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002947}
2948
Calin Juravle52c48962014-12-16 17:02:57 +00002949void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2950 // TODO (ported from quick): revisit Arm barrier kinds
2951 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2952 switch (kind) {
2953 case MemBarrierKind::kAnyStore:
2954 case MemBarrierKind::kLoadAny:
2955 case MemBarrierKind::kAnyAny: {
2956 flavour = DmbOptions::ISH;
2957 break;
2958 }
2959 case MemBarrierKind::kStoreStore: {
2960 flavour = DmbOptions::ISHST;
2961 break;
2962 }
2963 default:
2964 LOG(FATAL) << "Unexpected memory barrier " << kind;
2965 }
2966 __ dmb(flavour);
2967}
2968
2969void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2970 uint32_t offset,
2971 Register out_lo,
2972 Register out_hi) {
2973 if (offset != 0) {
2974 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002975 __ add(IP, addr, ShifterOperand(out_lo));
2976 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002977 }
2978 __ ldrexd(out_lo, out_hi, addr);
2979}
2980
2981void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2982 uint32_t offset,
2983 Register value_lo,
2984 Register value_hi,
2985 Register temp1,
Calin Juravle77520bc2015-01-12 18:45:46 +00002986 Register temp2,
2987 HInstruction* instruction) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00002988 NearLabel fail;
Calin Juravle52c48962014-12-16 17:02:57 +00002989 if (offset != 0) {
2990 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002991 __ add(IP, addr, ShifterOperand(temp1));
2992 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002993 }
2994 __ Bind(&fail);
2995 // We need a load followed by store. (The address used in a STREX instruction must
2996 // be the same as the address in the most recently executed LDREX instruction.)
2997 __ ldrexd(temp1, temp2, addr);
Calin Juravle77520bc2015-01-12 18:45:46 +00002998 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00002999 __ strexd(temp1, value_lo, value_hi, addr);
3000 __ cmp(temp1, ShifterOperand(0));
3001 __ b(&fail, NE);
3002}
3003
3004void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
3005 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3006
Nicolas Geoffray39468442014-09-02 15:17:15 +01003007 LocationSummary* locations =
3008 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003009 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003010
Calin Juravle52c48962014-12-16 17:02:57 +00003011 Primitive::Type field_type = field_info.GetFieldType();
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003012 if (Primitive::IsFloatingPointType(field_type)) {
3013 locations->SetInAt(1, Location::RequiresFpuRegister());
3014 } else {
3015 locations->SetInAt(1, Location::RequiresRegister());
3016 }
3017
Calin Juravle52c48962014-12-16 17:02:57 +00003018 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00003019 bool generate_volatile = field_info.IsVolatile()
3020 && is_wide
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003021 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003022 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00003023 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
3024 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003025 locations->AddTemp(Location::RequiresRegister());
3026 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00003027 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00003028 // Arm encoding have some additional constraints for ldrexd/strexd:
3029 // - registers need to be consecutive
3030 // - the first register should be even but not R14.
3031 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3032 // enable Arm encoding.
3033 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3034
3035 locations->AddTemp(Location::RequiresRegister());
3036 locations->AddTemp(Location::RequiresRegister());
3037 if (field_type == Primitive::kPrimDouble) {
3038 // For doubles we need two more registers to copy the value.
3039 locations->AddTemp(Location::RegisterLocation(R2));
3040 locations->AddTemp(Location::RegisterLocation(R3));
3041 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01003042 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003043}
3044
Calin Juravle52c48962014-12-16 17:02:57 +00003045void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003046 const FieldInfo& field_info,
3047 bool value_can_be_null) {
Calin Juravle52c48962014-12-16 17:02:57 +00003048 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
3049
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003050 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00003051 Register base = locations->InAt(0).AsRegister<Register>();
3052 Location value = locations->InAt(1);
3053
3054 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003055 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003056 Primitive::Type field_type = field_info.GetFieldType();
3057 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3058
3059 if (is_volatile) {
3060 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
3061 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003062
3063 switch (field_type) {
3064 case Primitive::kPrimBoolean:
3065 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003066 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003067 break;
3068 }
3069
3070 case Primitive::kPrimShort:
3071 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003072 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003073 break;
3074 }
3075
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003076 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003077 case Primitive::kPrimNot: {
Calin Juravle77520bc2015-01-12 18:45:46 +00003078 __ StoreToOffset(kStoreWord, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003079 break;
3080 }
3081
3082 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003083 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003084 GenerateWideAtomicStore(base, offset,
3085 value.AsRegisterPairLow<Register>(),
3086 value.AsRegisterPairHigh<Register>(),
3087 locations->GetTemp(0).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003088 locations->GetTemp(1).AsRegister<Register>(),
3089 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003090 } else {
3091 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003092 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003093 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003094 break;
3095 }
3096
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003097 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003098 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003099 break;
3100 }
3101
3102 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003103 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003104 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003105 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
3106 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
3107
3108 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
3109
3110 GenerateWideAtomicStore(base, offset,
3111 value_reg_lo,
3112 value_reg_hi,
3113 locations->GetTemp(2).AsRegister<Register>(),
Calin Juravle77520bc2015-01-12 18:45:46 +00003114 locations->GetTemp(3).AsRegister<Register>(),
3115 instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003116 } else {
3117 __ StoreDToOffset(value_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003118 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003119 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003120 break;
3121 }
3122
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003123 case Primitive::kPrimVoid:
3124 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003125 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003126 }
Calin Juravle52c48962014-12-16 17:02:57 +00003127
Calin Juravle77520bc2015-01-12 18:45:46 +00003128 // Longs and doubles are handled in the switch.
3129 if (field_type != Primitive::kPrimLong && field_type != Primitive::kPrimDouble) {
3130 codegen_->MaybeRecordImplicitNullCheck(instruction);
3131 }
3132
3133 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
3134 Register temp = locations->GetTemp(0).AsRegister<Register>();
3135 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003136 codegen_->MarkGCCard(
3137 temp, card, base, value.AsRegister<Register>(), value_can_be_null);
Calin Juravle77520bc2015-01-12 18:45:46 +00003138 }
3139
Calin Juravle52c48962014-12-16 17:02:57 +00003140 if (is_volatile) {
3141 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
3142 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003143}
3144
Calin Juravle52c48962014-12-16 17:02:57 +00003145void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3146 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01003147 LocationSummary* locations =
3148 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003149 locations->SetInAt(0, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00003150
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003151 bool volatile_for_double = field_info.IsVolatile()
Calin Juravle34166012014-12-19 17:22:29 +00003152 && (field_info.GetFieldType() == Primitive::kPrimDouble)
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003153 && !codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003154 bool overlap = field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong);
Nicolas Geoffrayacc0b8e2015-04-20 12:39:57 +01003155
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003156 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3157 locations->SetOut(Location::RequiresFpuRegister());
3158 } else {
3159 locations->SetOut(Location::RequiresRegister(),
3160 (overlap ? Location::kOutputOverlap : Location::kNoOutputOverlap));
3161 }
Nicolas Geoffray829280c2015-01-28 10:20:37 +00003162 if (volatile_for_double) {
Calin Juravle52c48962014-12-16 17:02:57 +00003163 // Arm encoding have some additional constraints for ldrexd/strexd:
3164 // - registers need to be consecutive
3165 // - the first register should be even but not R14.
3166 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
3167 // enable Arm encoding.
3168 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
3169 locations->AddTemp(Location::RequiresRegister());
3170 locations->AddTemp(Location::RequiresRegister());
3171 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003172}
3173
Calin Juravle52c48962014-12-16 17:02:57 +00003174void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
3175 const FieldInfo& field_info) {
3176 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003177
Calin Juravle52c48962014-12-16 17:02:57 +00003178 LocationSummary* locations = instruction->GetLocations();
3179 Register base = locations->InAt(0).AsRegister<Register>();
3180 Location out = locations->Out();
3181 bool is_volatile = field_info.IsVolatile();
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003182 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures().HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00003183 Primitive::Type field_type = field_info.GetFieldType();
3184 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
3185
3186 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003187 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00003188 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003189 break;
3190 }
3191
3192 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00003193 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003194 break;
3195 }
3196
3197 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00003198 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003199 break;
3200 }
3201
3202 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00003203 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003204 break;
3205 }
3206
3207 case Primitive::kPrimInt:
3208 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00003209 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003210 break;
3211 }
3212
3213 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00003214 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003215 GenerateWideAtomicLoad(base, offset,
3216 out.AsRegisterPairLow<Register>(),
3217 out.AsRegisterPairHigh<Register>());
3218 } else {
3219 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
3220 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003221 break;
3222 }
3223
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003224 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00003225 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003226 break;
3227 }
3228
3229 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00003230 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00003231 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00003232 Register lo = locations->GetTemp(0).AsRegister<Register>();
3233 Register hi = locations->GetTemp(1).AsRegister<Register>();
3234 GenerateWideAtomicLoad(base, offset, lo, hi);
Calin Juravle77520bc2015-01-12 18:45:46 +00003235 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003236 __ vmovdrr(out_reg, lo, hi);
3237 } else {
3238 __ LoadDFromOffset(out_reg, base, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003239 codegen_->MaybeRecordImplicitNullCheck(instruction);
Calin Juravle52c48962014-12-16 17:02:57 +00003240 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003241 break;
3242 }
3243
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003244 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00003245 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003246 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003247 }
Calin Juravle52c48962014-12-16 17:02:57 +00003248
Calin Juravle77520bc2015-01-12 18:45:46 +00003249 // Doubles are handled in the switch.
3250 if (field_type != Primitive::kPrimDouble) {
3251 codegen_->MaybeRecordImplicitNullCheck(instruction);
3252 }
3253
Calin Juravle52c48962014-12-16 17:02:57 +00003254 if (is_volatile) {
3255 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
3256 }
3257}
3258
3259void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
3260 HandleFieldSet(instruction, instruction->GetFieldInfo());
3261}
3262
3263void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003264 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Calin Juravle52c48962014-12-16 17:02:57 +00003265}
3266
3267void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3268 HandleFieldGet(instruction, instruction->GetFieldInfo());
3269}
3270
3271void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
3272 HandleFieldGet(instruction, instruction->GetFieldInfo());
3273}
3274
3275void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3276 HandleFieldGet(instruction, instruction->GetFieldInfo());
3277}
3278
3279void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3280 HandleFieldGet(instruction, instruction->GetFieldInfo());
3281}
3282
3283void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3284 HandleFieldSet(instruction, instruction->GetFieldInfo());
3285}
3286
3287void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003288 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003289}
3290
3291void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003292 LocationSummary* locations =
3293 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravle77520bc2015-01-12 18:45:46 +00003294 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003295 if (instruction->HasUses()) {
3296 locations->SetOut(Location::SameAsFirstInput());
3297 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003298}
3299
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003300void InstructionCodeGeneratorARM::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00003301 if (codegen_->CanMoveNullCheckToUser(instruction)) {
3302 return;
3303 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003304 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00003305
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003306 __ LoadFromOffset(kLoadWord, IP, obj.AsRegister<Register>(), 0);
3307 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3308}
3309
3310void InstructionCodeGeneratorARM::GenerateExplicitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003311 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003312 codegen_->AddSlowPath(slow_path);
3313
3314 LocationSummary* locations = instruction->GetLocations();
3315 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003316
Calin Juravle77520bc2015-01-12 18:45:46 +00003317 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
3318 __ b(slow_path->GetEntryLabel(), EQ);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003319}
3320
Calin Juravlecd6dffe2015-01-08 17:35:35 +00003321void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
3322 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
3323 GenerateImplicitNullCheck(instruction);
3324 } else {
3325 GenerateExplicitNullCheck(instruction);
3326 }
3327}
3328
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003329void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003330 LocationSummary* locations =
3331 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003332 locations->SetInAt(0, Location::RequiresRegister());
3333 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003334 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3335 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
3336 } else {
3337 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3338 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003339}
3340
3341void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
3342 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003343 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003344 Location index = locations->InAt(1);
3345
3346 switch (instruction->GetType()) {
3347 case Primitive::kPrimBoolean: {
3348 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003349 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003350 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003351 size_t offset =
3352 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003353 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
3354 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003355 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003356 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
3357 }
3358 break;
3359 }
3360
3361 case Primitive::kPrimByte: {
3362 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003363 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003364 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003365 size_t offset =
3366 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003367 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
3368 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003369 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003370 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
3371 }
3372 break;
3373 }
3374
3375 case Primitive::kPrimShort: {
3376 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003377 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003378 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003379 size_t offset =
3380 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003381 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
3382 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003383 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003384 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
3385 }
3386 break;
3387 }
3388
3389 case Primitive::kPrimChar: {
3390 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003391 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003392 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003393 size_t offset =
3394 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003395 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
3396 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003397 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003398 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
3399 }
3400 break;
3401 }
3402
3403 case Primitive::kPrimInt:
3404 case Primitive::kPrimNot: {
3405 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
3406 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003407 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003408 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003409 size_t offset =
3410 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003411 __ LoadFromOffset(kLoadWord, out, obj, offset);
3412 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003413 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003414 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
3415 }
3416 break;
3417 }
3418
3419 case Primitive::kPrimLong: {
3420 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003421 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003422 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003423 size_t offset =
3424 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003425 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003426 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003427 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003428 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003429 }
3430 break;
3431 }
3432
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003433 case Primitive::kPrimFloat: {
3434 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3435 Location out = locations->Out();
3436 DCHECK(out.IsFpuRegister());
3437 if (index.IsConstant()) {
3438 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3439 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
3440 } else {
3441 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3442 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
3443 }
3444 break;
3445 }
3446
3447 case Primitive::kPrimDouble: {
3448 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3449 Location out = locations->Out();
3450 DCHECK(out.IsFpuRegisterPair());
3451 if (index.IsConstant()) {
3452 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3453 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3454 } else {
3455 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3456 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3457 }
3458 break;
3459 }
3460
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003461 case Primitive::kPrimVoid:
3462 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003463 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003464 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003465 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003466}
3467
3468void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003469 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003470
3471 bool needs_write_barrier =
3472 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3473 bool needs_runtime_call = instruction->NeedsTypeCheck();
3474
Nicolas Geoffray39468442014-09-02 15:17:15 +01003475 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003476 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3477 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003478 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003479 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3480 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3481 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003482 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003483 locations->SetInAt(0, Location::RequiresRegister());
3484 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01003485 if (Primitive::IsFloatingPointType(value_type)) {
3486 locations->SetInAt(2, Location::RequiresFpuRegister());
3487 } else {
3488 locations->SetInAt(2, Location::RequiresRegister());
3489 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003490
3491 if (needs_write_barrier) {
3492 // Temporary registers for the write barrier.
3493 locations->AddTemp(Location::RequiresRegister());
3494 locations->AddTemp(Location::RequiresRegister());
3495 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003496 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003497}
3498
3499void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3500 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003501 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003502 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003503 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003504 bool needs_runtime_call = locations->WillCall();
3505 bool needs_write_barrier =
3506 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003507
3508 switch (value_type) {
3509 case Primitive::kPrimBoolean:
3510 case Primitive::kPrimByte: {
3511 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003512 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003513 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003514 size_t offset =
3515 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003516 __ StoreToOffset(kStoreByte, value, obj, offset);
3517 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003518 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003519 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3520 }
3521 break;
3522 }
3523
3524 case Primitive::kPrimShort:
3525 case Primitive::kPrimChar: {
3526 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003527 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003528 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003529 size_t offset =
3530 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003531 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3532 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003533 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003534 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3535 }
3536 break;
3537 }
3538
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003539 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003540 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003541 if (!needs_runtime_call) {
3542 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003543 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003544 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003545 size_t offset =
3546 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003547 __ StoreToOffset(kStoreWord, value, obj, offset);
3548 } else {
3549 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003550 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003551 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3552 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003553 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003554 if (needs_write_barrier) {
3555 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003556 Register temp = locations->GetTemp(0).AsRegister<Register>();
3557 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003558 codegen_->MarkGCCard(temp, card, obj, value, instruction->GetValueCanBeNull());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003559 }
3560 } else {
3561 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003562 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3563 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00003564 instruction->GetDexPc(),
3565 nullptr);
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003566 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003567 break;
3568 }
3569
3570 case Primitive::kPrimLong: {
3571 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003572 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003573 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003574 size_t offset =
3575 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003576 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003577 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003578 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003579 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003580 }
3581 break;
3582 }
3583
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003584 case Primitive::kPrimFloat: {
3585 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3586 Location value = locations->InAt(2);
3587 DCHECK(value.IsFpuRegister());
3588 if (index.IsConstant()) {
3589 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3590 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3591 } else {
3592 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3593 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3594 }
3595 break;
3596 }
3597
3598 case Primitive::kPrimDouble: {
3599 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3600 Location value = locations->InAt(2);
3601 DCHECK(value.IsFpuRegisterPair());
3602 if (index.IsConstant()) {
3603 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3604 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3605 } else {
3606 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3607 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3608 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003609
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003610 break;
3611 }
3612
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003613 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003614 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003615 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003616 }
Calin Juravle77520bc2015-01-12 18:45:46 +00003617
3618 // Ints and objects are handled in the switch.
3619 if (value_type != Primitive::kPrimInt && value_type != Primitive::kPrimNot) {
3620 codegen_->MaybeRecordImplicitNullCheck(instruction);
3621 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003622}
3623
3624void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003625 LocationSummary* locations =
3626 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003627 locations->SetInAt(0, Location::RequiresRegister());
3628 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003629}
3630
3631void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3632 LocationSummary* locations = instruction->GetLocations();
3633 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003634 Register obj = locations->InAt(0).AsRegister<Register>();
3635 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003636 __ LoadFromOffset(kLoadWord, out, obj, offset);
Calin Juravle77520bc2015-01-12 18:45:46 +00003637 codegen_->MaybeRecordImplicitNullCheck(instruction);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003638}
3639
3640void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003641 LocationSummary* locations =
3642 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003643 locations->SetInAt(0, Location::RequiresRegister());
3644 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003645 if (instruction->HasUses()) {
3646 locations->SetOut(Location::SameAsFirstInput());
3647 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003648}
3649
3650void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3651 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003652 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003653 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003654 codegen_->AddSlowPath(slow_path);
3655
Roland Levillain271ab9c2014-11-27 15:23:57 +00003656 Register index = locations->InAt(0).AsRegister<Register>();
3657 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003658
3659 __ cmp(index, ShifterOperand(length));
3660 __ b(slow_path->GetEntryLabel(), CS);
3661}
3662
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003663void CodeGeneratorARM::MarkGCCard(Register temp,
3664 Register card,
3665 Register object,
3666 Register value,
3667 bool can_be_null) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00003668 NearLabel is_null;
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003669 if (can_be_null) {
3670 __ CompareAndBranchIfZero(value, &is_null);
3671 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003672 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3673 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3674 __ strb(card, Address(card, temp));
Nicolas Geoffray07276db2015-05-18 14:22:09 +01003675 if (can_be_null) {
3676 __ Bind(&is_null);
3677 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003678}
3679
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003680void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3681 temp->SetLocations(nullptr);
3682}
3683
3684void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3685 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003686 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003687}
3688
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003689void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003690 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003691 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003692}
3693
3694void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003695 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3696}
3697
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003698void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3699 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3700}
3701
3702void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003703 HBasicBlock* block = instruction->GetBlock();
3704 if (block->GetLoopInformation() != nullptr) {
3705 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3706 // The back edge will generate the suspend check.
3707 return;
3708 }
3709 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3710 // The goto will generate the suspend check.
3711 return;
3712 }
3713 GenerateSuspendCheck(instruction, nullptr);
3714}
3715
3716void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3717 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003718 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffraydb216f42015-05-05 17:02:20 +01003719 down_cast<SuspendCheckSlowPathARM*>(instruction->GetSlowPath());
3720 if (slow_path == nullptr) {
3721 slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
3722 instruction->SetSlowPath(slow_path);
3723 codegen_->AddSlowPath(slow_path);
3724 if (successor != nullptr) {
3725 DCHECK(successor->IsLoopHeader());
3726 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction);
3727 }
3728 } else {
3729 DCHECK_EQ(slow_path->GetSuccessor(), successor);
3730 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003731
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003732 __ LoadFromOffset(
3733 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3734 __ cmp(IP, ShifterOperand(0));
3735 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003736 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003737 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003738 __ Bind(slow_path->GetReturnLabel());
3739 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003740 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003741 __ b(slow_path->GetEntryLabel());
3742 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003743}
3744
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003745ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3746 return codegen_->GetAssembler();
3747}
3748
3749void ParallelMoveResolverARM::EmitMove(size_t index) {
3750 MoveOperands* move = moves_.Get(index);
3751 Location source = move->GetSource();
3752 Location destination = move->GetDestination();
3753
3754 if (source.IsRegister()) {
3755 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003756 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003757 } else {
3758 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003759 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003760 SP, destination.GetStackIndex());
3761 }
3762 } else if (source.IsStackSlot()) {
3763 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003764 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003765 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003766 } else if (destination.IsFpuRegister()) {
3767 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003768 } else {
3769 DCHECK(destination.IsStackSlot());
3770 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3771 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3772 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003773 } else if (source.IsFpuRegister()) {
3774 if (destination.IsFpuRegister()) {
3775 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003776 } else {
3777 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003778 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3779 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003780 } else if (source.IsDoubleStackSlot()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003781 if (destination.IsDoubleStackSlot()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003782 __ LoadDFromOffset(DTMP, SP, source.GetStackIndex());
3783 __ StoreDToOffset(DTMP, SP, destination.GetStackIndex());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003784 } else if (destination.IsRegisterPair()) {
3785 DCHECK(ExpectedPairLayout(destination));
3786 __ LoadFromOffset(
3787 kLoadWordPair, destination.AsRegisterPairLow<Register>(), SP, source.GetStackIndex());
3788 } else {
3789 DCHECK(destination.IsFpuRegisterPair()) << destination;
3790 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3791 SP,
3792 source.GetStackIndex());
3793 }
3794 } else if (source.IsRegisterPair()) {
3795 if (destination.IsRegisterPair()) {
3796 __ Mov(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
3797 __ Mov(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
3798 } else {
3799 DCHECK(destination.IsDoubleStackSlot()) << destination;
3800 DCHECK(ExpectedPairLayout(source));
3801 __ StoreToOffset(
3802 kStoreWordPair, source.AsRegisterPairLow<Register>(), SP, destination.GetStackIndex());
3803 }
3804 } else if (source.IsFpuRegisterPair()) {
3805 if (destination.IsFpuRegisterPair()) {
3806 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3807 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3808 } else {
3809 DCHECK(destination.IsDoubleStackSlot()) << destination;
3810 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3811 SP,
3812 destination.GetStackIndex());
3813 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003814 } else {
3815 DCHECK(source.IsConstant()) << source;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00003816 HConstant* constant = source.GetConstant();
3817 if (constant->IsIntConstant() || constant->IsNullConstant()) {
3818 int32_t value = CodeGenerator::GetInt32ValueOf(constant);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003819 if (destination.IsRegister()) {
3820 __ LoadImmediate(destination.AsRegister<Register>(), value);
3821 } else {
3822 DCHECK(destination.IsStackSlot());
3823 __ LoadImmediate(IP, value);
3824 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3825 }
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003826 } else if (constant->IsLongConstant()) {
3827 int64_t value = constant->AsLongConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003828 if (destination.IsRegisterPair()) {
3829 __ LoadImmediate(destination.AsRegisterPairLow<Register>(), Low32Bits(value));
3830 __ LoadImmediate(destination.AsRegisterPairHigh<Register>(), High32Bits(value));
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003831 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003832 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003833 __ LoadImmediate(IP, Low32Bits(value));
3834 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3835 __ LoadImmediate(IP, High32Bits(value));
3836 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3837 }
3838 } else if (constant->IsDoubleConstant()) {
3839 double value = constant->AsDoubleConstant()->GetValue();
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003840 if (destination.IsFpuRegisterPair()) {
3841 __ LoadDImmediate(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()), value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003842 } else {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003843 DCHECK(destination.IsDoubleStackSlot()) << destination;
3844 uint64_t int_value = bit_cast<uint64_t, double>(value);
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003845 __ LoadImmediate(IP, Low32Bits(int_value));
3846 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3847 __ LoadImmediate(IP, High32Bits(int_value));
3848 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3849 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003850 } else {
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00003851 DCHECK(constant->IsFloatConstant()) << constant->DebugName();
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003852 float value = constant->AsFloatConstant()->GetValue();
3853 if (destination.IsFpuRegister()) {
3854 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3855 } else {
3856 DCHECK(destination.IsStackSlot());
3857 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3858 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3859 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003860 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003861 }
3862}
3863
3864void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3865 __ Mov(IP, reg);
3866 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3867 __ StoreToOffset(kStoreWord, IP, SP, mem);
3868}
3869
3870void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3871 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3872 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3873 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3874 SP, mem1 + stack_offset);
3875 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3876 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3877 SP, mem2 + stack_offset);
3878 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3879}
3880
3881void ParallelMoveResolverARM::EmitSwap(size_t index) {
3882 MoveOperands* move = moves_.Get(index);
3883 Location source = move->GetSource();
3884 Location destination = move->GetDestination();
3885
3886 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003887 DCHECK_NE(source.AsRegister<Register>(), IP);
3888 DCHECK_NE(destination.AsRegister<Register>(), IP);
3889 __ Mov(IP, source.AsRegister<Register>());
3890 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3891 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003892 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003893 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003894 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003895 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003896 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3897 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003898 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003899 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003900 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003901 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003902 } else if (source.IsRegisterPair() && destination.IsRegisterPair()) {
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003903 __ vmovdrr(DTMP, source.AsRegisterPairLow<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003904 __ Mov(source.AsRegisterPairLow<Register>(), destination.AsRegisterPairLow<Register>());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003905 __ Mov(source.AsRegisterPairHigh<Register>(), destination.AsRegisterPairHigh<Register>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003906 __ vmovrrd(destination.AsRegisterPairLow<Register>(),
3907 destination.AsRegisterPairHigh<Register>(),
3908 DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003909 } else if (source.IsRegisterPair() || destination.IsRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003910 Register low_reg = source.IsRegisterPair()
3911 ? source.AsRegisterPairLow<Register>()
3912 : destination.AsRegisterPairLow<Register>();
3913 int mem = source.IsRegisterPair()
3914 ? destination.GetStackIndex()
3915 : source.GetStackIndex();
3916 DCHECK(ExpectedPairLayout(source.IsRegisterPair() ? source : destination));
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003917 __ vmovdrr(DTMP, low_reg, static_cast<Register>(low_reg + 1));
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003918 __ LoadFromOffset(kLoadWordPair, low_reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003919 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003920 } else if (source.IsFpuRegisterPair() && destination.IsFpuRegisterPair()) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003921 DRegister first = FromLowSToD(source.AsFpuRegisterPairLow<SRegister>());
3922 DRegister second = FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003923 __ vmovd(DTMP, first);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003924 __ vmovd(first, second);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003925 __ vmovd(second, DTMP);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003926 } else if (source.IsFpuRegisterPair() || destination.IsFpuRegisterPair()) {
3927 DRegister reg = source.IsFpuRegisterPair()
3928 ? FromLowSToD(source.AsFpuRegisterPairLow<SRegister>())
3929 : FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>());
3930 int mem = source.IsFpuRegisterPair()
3931 ? destination.GetStackIndex()
3932 : source.GetStackIndex();
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003933 __ vmovd(DTMP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003934 __ LoadDFromOffset(reg, SP, mem);
Nicolas Geoffrayffe8a572015-02-11 01:10:39 +00003935 __ StoreDToOffset(DTMP, SP, mem);
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003936 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3937 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3938 : destination.AsFpuRegister<SRegister>();
3939 int mem = source.IsFpuRegister()
3940 ? destination.GetStackIndex()
3941 : source.GetStackIndex();
3942
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003943 __ vmovrs(IP, reg);
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003944 __ LoadSFromOffset(reg, SP, mem);
Nicolas Geoffraya8eef822015-01-16 11:14:27 +00003945 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003946 } else if (source.IsDoubleStackSlot() && destination.IsDoubleStackSlot()) {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003947 Exchange(source.GetStackIndex(), destination.GetStackIndex());
3948 Exchange(source.GetHighStackIndex(kArmWordSize), destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003949 } else {
Nicolas Geoffray53f12622015-01-13 18:04:41 +00003950 LOG(FATAL) << "Unimplemented" << source << " <-> " << destination;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003951 }
3952}
3953
3954void ParallelMoveResolverARM::SpillScratch(int reg) {
3955 __ Push(static_cast<Register>(reg));
3956}
3957
3958void ParallelMoveResolverARM::RestoreScratch(int reg) {
3959 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003960}
3961
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003962void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003963 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3964 ? LocationSummary::kCallOnSlowPath
3965 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003966 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003967 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003968 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003969 locations->SetOut(Location::RequiresRegister());
3970}
3971
3972void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003973 LocationSummary* locations = cls->GetLocations();
3974 Register out = locations->Out().AsRegister<Register>();
3975 Register current_method = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003976 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003977 DCHECK(!cls->CanCallRuntime());
3978 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003979 __ LoadFromOffset(
3980 kLoadWord, out, current_method, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003981 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003982 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray76b1e172015-05-27 17:18:33 +01003983 __ LoadFromOffset(kLoadWord,
3984 out,
3985 current_method,
3986 mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003987 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003988
3989 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3990 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3991 codegen_->AddSlowPath(slow_path);
3992 __ cmp(out, ShifterOperand(0));
3993 __ b(slow_path->GetEntryLabel(), EQ);
3994 if (cls->MustGenerateClinitCheck()) {
3995 GenerateClassInitializationCheck(slow_path, out);
3996 } else {
3997 __ Bind(slow_path->GetExitLabel());
3998 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003999 }
4000}
4001
4002void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
4003 LocationSummary* locations =
4004 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
4005 locations->SetInAt(0, Location::RequiresRegister());
4006 if (check->HasUses()) {
4007 locations->SetOut(Location::SameAsFirstInput());
4008 }
4009}
4010
4011void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004012 // We assume the class is not null.
4013 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
4014 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004015 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00004016 GenerateClassInitializationCheck(slow_path,
4017 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004018}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004019
Nicolas Geoffray424f6762014-11-03 14:51:25 +00004020void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
4021 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01004022 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
4023 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
4024 __ b(slow_path->GetEntryLabel(), LT);
4025 // Even if the initialized flag is set, we may be in a situation where caches are not synced
4026 // properly. Therefore, we do a memory fence.
4027 __ dmb(ISH);
4028 __ Bind(slow_path->GetExitLabel());
4029}
4030
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004031void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
4032 LocationSummary* locations =
4033 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
4034 locations->SetOut(Location::RequiresRegister());
4035}
4036
4037void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
4038 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
4039 codegen_->AddSlowPath(slow_path);
4040
Roland Levillain271ab9c2014-11-27 15:23:57 +00004041 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004042 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08004043 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
4044 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00004045 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
4046 __ cmp(out, ShifterOperand(0));
4047 __ b(slow_path->GetEntryLabel(), EQ);
4048 __ Bind(slow_path->GetExitLabel());
4049}
4050
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004051void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
4052 LocationSummary* locations =
4053 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4054 locations->SetOut(Location::RequiresRegister());
4055}
4056
4057void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004058 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004059 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
4060 __ LoadFromOffset(kLoadWord, out, TR, offset);
4061 __ LoadImmediate(IP, 0);
4062 __ StoreToOffset(kStoreWord, IP, TR, offset);
4063}
4064
4065void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
4066 LocationSummary* locations =
4067 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4068 InvokeRuntimeCallingConvention calling_convention;
4069 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4070}
4071
4072void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
4073 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004074 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00004075}
4076
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004077void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004078 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
4079 ? LocationSummary::kNoCall
4080 : LocationSummary::kCallOnSlowPath;
4081 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4082 locations->SetInAt(0, Location::RequiresRegister());
4083 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004084 // The out register is used as a temporary, so it overlaps with the inputs.
4085 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004086}
4087
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004088void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004089 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004090 Register obj = locations->InAt(0).AsRegister<Register>();
4091 Register cls = locations->InAt(1).AsRegister<Register>();
4092 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004093 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004094 NearLabel done, zero;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004095 SlowPathCodeARM* slow_path = nullptr;
4096
4097 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004098 // avoid null check if we know obj is not null.
4099 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004100 __ CompareAndBranchIfZero(obj, &zero);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004101 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004102 // Compare the class of `obj` with `cls`.
4103 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
4104 __ cmp(out, ShifterOperand(cls));
4105 if (instruction->IsClassFinal()) {
4106 // Classes must be equal for the instanceof to succeed.
4107 __ b(&zero, NE);
4108 __ LoadImmediate(out, 1);
4109 __ b(&done);
4110 } else {
4111 // If the classes are not equal, we go into a slow path.
4112 DCHECK(locations->OnlyCallsOnSlowPath());
4113 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004114 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004115 codegen_->AddSlowPath(slow_path);
4116 __ b(slow_path->GetEntryLabel(), NE);
4117 __ LoadImmediate(out, 1);
4118 __ b(&done);
4119 }
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004120
4121 if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) {
4122 __ Bind(&zero);
4123 __ LoadImmediate(out, 0);
4124 }
4125
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00004126 if (slow_path != nullptr) {
4127 __ Bind(slow_path->GetExitLabel());
4128 }
4129 __ Bind(&done);
4130}
4131
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004132void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
4133 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
4134 instruction, LocationSummary::kCallOnSlowPath);
4135 locations->SetInAt(0, Location::RequiresRegister());
4136 locations->SetInAt(1, Location::RequiresRegister());
4137 locations->AddTemp(Location::RequiresRegister());
4138}
4139
4140void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
4141 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00004142 Register obj = locations->InAt(0).AsRegister<Register>();
4143 Register cls = locations->InAt(1).AsRegister<Register>();
4144 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004145 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
4146
4147 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
4148 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
4149 codegen_->AddSlowPath(slow_path);
4150
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004151 NearLabel done;
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004152 // avoid null check if we know obj is not null.
4153 if (instruction->MustDoNullCheck()) {
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004154 __ CompareAndBranchIfZero(obj, &done);
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01004155 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004156 // Compare the class of `obj` with `cls`.
4157 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
4158 __ cmp(temp, ShifterOperand(cls));
4159 __ b(slow_path->GetEntryLabel(), NE);
4160 __ Bind(slow_path->GetExitLabel());
Nicolas Geoffrayd56376c2015-05-21 12:32:34 +00004161 if (instruction->MustDoNullCheck()) {
4162 __ Bind(&done);
4163 }
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00004164}
4165
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004166void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4167 LocationSummary* locations =
4168 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
4169 InvokeRuntimeCallingConvention calling_convention;
4170 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4171}
4172
4173void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
4174 codegen_->InvokeRuntime(instruction->IsEnter()
4175 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
4176 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00004177 instruction->GetDexPc(),
4178 nullptr);
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00004179}
4180
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004181void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
4182void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
4183void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
4184
4185void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4186 LocationSummary* locations =
4187 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
4188 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
4189 || instruction->GetResultType() == Primitive::kPrimLong);
4190 locations->SetInAt(0, Location::RequiresRegister());
4191 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray829280c2015-01-28 10:20:37 +00004192 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004193}
4194
4195void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
4196 HandleBitwiseOperation(instruction);
4197}
4198
4199void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
4200 HandleBitwiseOperation(instruction);
4201}
4202
4203void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
4204 HandleBitwiseOperation(instruction);
4205}
4206
4207void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
4208 LocationSummary* locations = instruction->GetLocations();
4209
4210 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00004211 Register first = locations->InAt(0).AsRegister<Register>();
4212 Register second = locations->InAt(1).AsRegister<Register>();
4213 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00004214 if (instruction->IsAnd()) {
4215 __ and_(out, first, ShifterOperand(second));
4216 } else if (instruction->IsOr()) {
4217 __ orr(out, first, ShifterOperand(second));
4218 } else {
4219 DCHECK(instruction->IsXor());
4220 __ eor(out, first, ShifterOperand(second));
4221 }
4222 } else {
4223 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
4224 Location first = locations->InAt(0);
4225 Location second = locations->InAt(1);
4226 Location out = locations->Out();
4227 if (instruction->IsAnd()) {
4228 __ and_(out.AsRegisterPairLow<Register>(),
4229 first.AsRegisterPairLow<Register>(),
4230 ShifterOperand(second.AsRegisterPairLow<Register>()));
4231 __ and_(out.AsRegisterPairHigh<Register>(),
4232 first.AsRegisterPairHigh<Register>(),
4233 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4234 } else if (instruction->IsOr()) {
4235 __ orr(out.AsRegisterPairLow<Register>(),
4236 first.AsRegisterPairLow<Register>(),
4237 ShifterOperand(second.AsRegisterPairLow<Register>()));
4238 __ orr(out.AsRegisterPairHigh<Register>(),
4239 first.AsRegisterPairHigh<Register>(),
4240 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4241 } else {
4242 DCHECK(instruction->IsXor());
4243 __ eor(out.AsRegisterPairLow<Register>(),
4244 first.AsRegisterPairLow<Register>(),
4245 ShifterOperand(second.AsRegisterPairLow<Register>()));
4246 __ eor(out.AsRegisterPairHigh<Register>(),
4247 first.AsRegisterPairHigh<Register>(),
4248 ShifterOperand(second.AsRegisterPairHigh<Register>()));
4249 }
4250 }
4251}
4252
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004253void CodeGeneratorARM::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
4254 DCHECK_EQ(temp, kArtMethodRegister);
4255
4256 // TODO: Implement all kinds of calls:
4257 // 1) boot -> boot
4258 // 2) app -> boot
4259 // 3) app -> app
4260 //
4261 // Currently we implement the app -> app logic, which looks up in the resolve cache.
4262
Jeff Hao848f70a2014-01-15 13:49:50 -08004263 if (invoke->IsStringInit()) {
4264 // temp = thread->string_init_entrypoint
4265 __ LoadFromOffset(kLoadWord, temp, TR, invoke->GetStringInitOffset());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004266 // LR = temp[offset_of_quick_compiled_code]
4267 __ LoadFromOffset(kLoadWord, LR, temp,
4268 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4269 kArmWordSize).Int32Value());
4270 // LR()
4271 __ blx(LR);
4272 } else {
Jeff Hao848f70a2014-01-15 13:49:50 -08004273 // temp = method;
4274 LoadCurrentMethod(temp);
4275 if (!invoke->IsRecursive()) {
4276 // temp = temp->dex_cache_resolved_methods_;
4277 __ LoadFromOffset(
4278 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
4279 // temp = temp[index_in_cache]
4280 __ LoadFromOffset(
4281 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetDexMethodIndex()));
4282 // LR = temp[offset_of_quick_compiled_code]
4283 __ LoadFromOffset(kLoadWord, LR, temp,
4284 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
4285 kArmWordSize).Int32Value());
4286 // LR()
4287 __ blx(LR);
4288 } else {
4289 __ bl(GetFrameEntryLabel());
4290 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004291 }
4292
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08004293 DCHECK(!IsLeafMethod());
4294}
4295
Calin Juravleb1498f62015-02-16 13:13:29 +00004296void LocationsBuilderARM::VisitBoundType(HBoundType* instruction) {
4297 // Nothing to do, this should be removed during prepare for register allocator.
4298 UNUSED(instruction);
4299 LOG(FATAL) << "Unreachable";
4300}
4301
4302void InstructionCodeGeneratorARM::VisitBoundType(HBoundType* instruction) {
4303 // Nothing to do, this should be removed during prepare for register allocator.
4304 UNUSED(instruction);
4305 LOG(FATAL) << "Unreachable";
4306}
4307
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00004308} // namespace arm
4309} // namespace art