blob: 2a2f07f788230eaf3f3c9e95524b788d4925ef97 [file] [log] [blame]
Alexandre Rames5319def2014-10-23 10:03:10 +01001/*
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_arm64.h"
18
Serban Constantinescu579885a2015-02-22 20:51:33 +000019#include "arch/arm64/instruction_set_features_arm64.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080020#include "common_arm64.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010021#include "entrypoints/quick/quick_entrypoints.h"
Andreas Gampe1cc7dba2014-12-17 18:43:01 -080022#include "entrypoints/quick/quick_entrypoints_enum.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010023#include "gc/accounting/card_table.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080024#include "intrinsics.h"
25#include "intrinsics_arm64.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010026#include "mirror/array-inl.h"
27#include "mirror/art_method.h"
28#include "mirror/class.h"
Calin Juravlecd6dffe2015-01-08 17:35:35 +000029#include "offsets.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010030#include "thread.h"
31#include "utils/arm64/assembler_arm64.h"
32#include "utils/assembler.h"
33#include "utils/stack_checks.h"
34
35
36using namespace vixl; // NOLINT(build/namespaces)
37
38#ifdef __
39#error "ARM64 Codegen VIXL macro-assembler macro already defined."
40#endif
41
Alexandre Rames5319def2014-10-23 10:03:10 +010042namespace art {
43
44namespace arm64 {
45
Andreas Gampe878d58c2015-01-15 23:24:00 -080046using helpers::CPURegisterFrom;
47using helpers::DRegisterFrom;
48using helpers::FPRegisterFrom;
49using helpers::HeapOperand;
50using helpers::HeapOperandFrom;
51using helpers::InputCPURegisterAt;
52using helpers::InputFPRegisterAt;
53using helpers::InputRegisterAt;
54using helpers::InputOperandAt;
55using helpers::Int64ConstantFrom;
Andreas Gampe878d58c2015-01-15 23:24:00 -080056using helpers::LocationFrom;
57using helpers::OperandFromMemOperand;
58using helpers::OutputCPURegister;
59using helpers::OutputFPRegister;
60using helpers::OutputRegister;
61using helpers::RegisterFrom;
62using helpers::StackOperandFrom;
63using helpers::VIXLRegCodeFromART;
64using helpers::WRegisterFrom;
65using helpers::XRegisterFrom;
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +000066using helpers::ARM64EncodableConstantOrRegister;
Andreas Gampe878d58c2015-01-15 23:24:00 -080067
Alexandre Rames5319def2014-10-23 10:03:10 +010068static constexpr size_t kHeapRefSize = sizeof(mirror::HeapReference<mirror::Object>);
69static constexpr int kCurrentMethodStackOffset = 0;
70
Alexandre Rames5319def2014-10-23 10:03:10 +010071inline Condition ARM64Condition(IfCondition cond) {
72 switch (cond) {
73 case kCondEQ: return eq;
74 case kCondNE: return ne;
75 case kCondLT: return lt;
76 case kCondLE: return le;
77 case kCondGT: return gt;
78 case kCondGE: return ge;
79 default:
80 LOG(FATAL) << "Unknown if condition";
81 }
82 return nv; // Unreachable.
83}
84
Alexandre Ramesa89086e2014-11-07 17:13:25 +000085Location ARM64ReturnLocation(Primitive::Type return_type) {
86 DCHECK_NE(return_type, Primitive::kPrimVoid);
87 // Note that in practice, `LocationFrom(x0)` and `LocationFrom(w0)` create the
88 // same Location object, and so do `LocationFrom(d0)` and `LocationFrom(s0)`,
89 // but we use the exact registers for clarity.
90 if (return_type == Primitive::kPrimFloat) {
91 return LocationFrom(s0);
92 } else if (return_type == Primitive::kPrimDouble) {
93 return LocationFrom(d0);
94 } else if (return_type == Primitive::kPrimLong) {
95 return LocationFrom(x0);
96 } else {
97 return LocationFrom(w0);
98 }
99}
100
Alexandre Rames5319def2014-10-23 10:03:10 +0100101Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000102 return ARM64ReturnLocation(return_type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100103}
104
Alexandre Rames67555f72014-11-18 10:55:16 +0000105#define __ down_cast<CodeGeneratorARM64*>(codegen)->GetVIXLAssembler()->
106#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, x).Int32Value()
Alexandre Rames5319def2014-10-23 10:03:10 +0100107
Alexandre Rames5319def2014-10-23 10:03:10 +0100108class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 {
109 public:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000110 BoundsCheckSlowPathARM64(HBoundsCheck* instruction,
111 Location index_location,
112 Location length_location)
113 : instruction_(instruction),
114 index_location_(index_location),
115 length_location_(length_location) {}
116
Alexandre Rames5319def2014-10-23 10:03:10 +0100117
Alexandre Rames67555f72014-11-18 10:55:16 +0000118 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000119 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100120 __ Bind(GetEntryLabel());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000121 // We're moving two locations to locations that could overlap, so we need a parallel
122 // move resolver.
123 InvokeRuntimeCallingConvention calling_convention;
124 codegen->EmitParallelMoves(
Nicolas Geoffray90218252015-04-15 11:56:51 +0100125 index_location_, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimInt,
126 length_location_, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimInt);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000127 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000128 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800129 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100130 }
131
132 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000133 HBoundsCheck* const instruction_;
134 const Location index_location_;
135 const Location length_location_;
136
Alexandre Rames5319def2014-10-23 10:03:10 +0100137 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64);
138};
139
Alexandre Rames67555f72014-11-18 10:55:16 +0000140class DivZeroCheckSlowPathARM64 : public SlowPathCodeARM64 {
141 public:
142 explicit DivZeroCheckSlowPathARM64(HDivZeroCheck* instruction) : instruction_(instruction) {}
143
144 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
145 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
146 __ Bind(GetEntryLabel());
147 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000148 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800149 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000150 }
151
152 private:
153 HDivZeroCheck* const instruction_;
154 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM64);
155};
156
157class LoadClassSlowPathARM64 : public SlowPathCodeARM64 {
158 public:
159 LoadClassSlowPathARM64(HLoadClass* cls,
160 HInstruction* at,
161 uint32_t dex_pc,
162 bool do_clinit)
163 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
164 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
165 }
166
167 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
168 LocationSummary* locations = at_->GetLocations();
169 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
170
171 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000172 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000173
174 InvokeRuntimeCallingConvention calling_convention;
175 __ Mov(calling_convention.GetRegisterAt(0).W(), cls_->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +0000176 int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
177 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000178 arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800179 if (do_clinit_) {
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100180 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800181 } else {
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100182 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800183 }
Alexandre Rames67555f72014-11-18 10:55:16 +0000184
185 // Move the class to the desired location.
186 Location out = locations->Out();
187 if (out.IsValid()) {
188 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
189 Primitive::Type type = at_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000190 arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000191 }
192
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000193 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000194 __ B(GetExitLabel());
195 }
196
197 private:
198 // The class this slow path will load.
199 HLoadClass* const cls_;
200
201 // The instruction where this slow path is happening.
202 // (Might be the load class or an initialization check).
203 HInstruction* const at_;
204
205 // The dex PC of `at_`.
206 const uint32_t dex_pc_;
207
208 // Whether to initialize the class.
209 const bool do_clinit_;
210
211 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64);
212};
213
214class LoadStringSlowPathARM64 : public SlowPathCodeARM64 {
215 public:
216 explicit LoadStringSlowPathARM64(HLoadString* instruction) : instruction_(instruction) {}
217
218 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
219 LocationSummary* locations = instruction_->GetLocations();
220 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
221 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
222
223 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000224 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000225
226 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800227 __ Mov(calling_convention.GetRegisterAt(0).W(), instruction_->GetStringIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +0000228 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000229 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Vladimir Marko5ea536a2015-04-20 20:11:30 +0100230 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000231 Primitive::Type type = instruction_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000232 arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000233
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000234 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000235 __ B(GetExitLabel());
236 }
237
238 private:
239 HLoadString* const instruction_;
240
241 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64);
242};
243
Alexandre Rames5319def2014-10-23 10:03:10 +0100244class NullCheckSlowPathARM64 : public SlowPathCodeARM64 {
245 public:
246 explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {}
247
Alexandre Rames67555f72014-11-18 10:55:16 +0000248 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
249 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100250 __ Bind(GetEntryLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000251 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000252 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800253 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100254 }
255
256 private:
257 HNullCheck* const instruction_;
258
259 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64);
260};
261
262class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 {
263 public:
264 explicit SuspendCheckSlowPathARM64(HSuspendCheck* instruction,
265 HBasicBlock* successor)
266 : instruction_(instruction), successor_(successor) {}
267
Alexandre Rames67555f72014-11-18 10:55:16 +0000268 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
269 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100270 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000271 SaveLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000272 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000273 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800274 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000275 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000276 if (successor_ == nullptr) {
277 __ B(GetReturnLabel());
278 } else {
279 __ B(arm64_codegen->GetLabelOf(successor_));
280 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100281 }
282
283 vixl::Label* GetReturnLabel() {
284 DCHECK(successor_ == nullptr);
285 return &return_label_;
286 }
287
Alexandre Rames5319def2014-10-23 10:03:10 +0100288 private:
289 HSuspendCheck* const instruction_;
290 // If not null, the block to branch to after the suspend check.
291 HBasicBlock* const successor_;
292
293 // If `successor_` is null, the label to branch to after the suspend check.
294 vixl::Label return_label_;
295
296 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64);
297};
298
Alexandre Rames67555f72014-11-18 10:55:16 +0000299class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 {
300 public:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000301 TypeCheckSlowPathARM64(HInstruction* instruction,
302 Location class_to_check,
303 Location object_class,
304 uint32_t dex_pc)
305 : instruction_(instruction),
306 class_to_check_(class_to_check),
307 object_class_(object_class),
308 dex_pc_(dex_pc) {}
Alexandre Rames67555f72014-11-18 10:55:16 +0000309
310 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000311 LocationSummary* locations = instruction_->GetLocations();
312 DCHECK(instruction_->IsCheckCast()
313 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
314 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
315
Alexandre Rames67555f72014-11-18 10:55:16 +0000316 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000317 SaveLiveRegisters(codegen, locations);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000318
319 // We're moving two locations to locations that could overlap, so we need a parallel
320 // move resolver.
321 InvokeRuntimeCallingConvention calling_convention;
322 codegen->EmitParallelMoves(
Nicolas Geoffray90218252015-04-15 11:56:51 +0100323 class_to_check_, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot,
324 object_class_, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000325
326 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000327 arm64_codegen->InvokeRuntime(
328 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000329 Primitive::Type ret_type = instruction_->GetType();
330 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
331 arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800332 CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t,
333 const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000334 } else {
335 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000336 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800337 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000338 }
339
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000340 RestoreLiveRegisters(codegen, locations);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000341 __ B(GetExitLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000342 }
343
344 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000345 HInstruction* const instruction_;
346 const Location class_to_check_;
347 const Location object_class_;
348 uint32_t dex_pc_;
349
Alexandre Rames67555f72014-11-18 10:55:16 +0000350 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64);
351};
352
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700353class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 {
354 public:
355 explicit DeoptimizationSlowPathARM64(HInstruction* instruction)
356 : instruction_(instruction) {}
357
358 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
359 __ Bind(GetEntryLabel());
360 SaveLiveRegisters(codegen, instruction_->GetLocations());
361 DCHECK(instruction_->IsDeoptimize());
362 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
363 uint32_t dex_pc = deoptimize->GetDexPc();
364 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
365 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
366 }
367
368 private:
369 HInstruction* const instruction_;
370 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64);
371};
372
Alexandre Rames5319def2014-10-23 10:03:10 +0100373#undef __
374
375Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
376 Location next_location;
377 if (type == Primitive::kPrimVoid) {
378 LOG(FATAL) << "Unreachable type " << type;
379 }
380
Alexandre Rames542361f2015-01-29 16:57:31 +0000381 if (Primitive::IsFloatingPointType(type) &&
382 (fp_index_ < calling_convention.GetNumberOfFpuRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000383 next_location = LocationFrom(calling_convention.GetFpuRegisterAt(fp_index_++));
Alexandre Rames542361f2015-01-29 16:57:31 +0000384 } else if (!Primitive::IsFloatingPointType(type) &&
385 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000386 next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++));
387 } else {
388 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Alexandre Rames542361f2015-01-29 16:57:31 +0000389 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
390 : Location::StackSlot(stack_offset);
Alexandre Rames5319def2014-10-23 10:03:10 +0100391 }
392
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000393 // Space on the stack is reserved for all arguments.
Alexandre Rames542361f2015-01-29 16:57:31 +0000394 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
Alexandre Rames5319def2014-10-23 10:03:10 +0100395 return next_location;
396}
397
Serban Constantinescu579885a2015-02-22 20:51:33 +0000398CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph,
399 const Arm64InstructionSetFeatures& isa_features,
400 const CompilerOptions& compiler_options)
Alexandre Rames5319def2014-10-23 10:03:10 +0100401 : CodeGenerator(graph,
402 kNumberOfAllocatableRegisters,
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000403 kNumberOfAllocatableFPRegisters,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000404 kNumberOfAllocatableRegisterPairs,
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000405 callee_saved_core_registers.list(),
406 callee_saved_fp_registers.list(),
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000407 compiler_options),
Alexandre Rames5319def2014-10-23 10:03:10 +0100408 block_labels_(nullptr),
409 location_builder_(graph, this),
Alexandre Rames3e69f162014-12-10 10:36:50 +0000410 instruction_visitor_(graph, this),
Serban Constantinescu579885a2015-02-22 20:51:33 +0000411 move_resolver_(graph->GetArena(), this),
412 isa_features_(isa_features) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000413 // Save the link register (containing the return address) to mimic Quick.
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000414 AddAllocatedRegister(LocationFrom(lr));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000415}
Alexandre Rames5319def2014-10-23 10:03:10 +0100416
Alexandre Rames67555f72014-11-18 10:55:16 +0000417#undef __
418#define __ GetVIXLAssembler()->
Alexandre Rames5319def2014-10-23 10:03:10 +0100419
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000420void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) {
421 // Ensure we emit the literal pool.
422 __ FinalizeCode();
423 CodeGenerator::Finalize(allocator);
424}
425
Zheng Xuad4450e2015-04-17 18:48:56 +0800426void ParallelMoveResolverARM64::PrepareForEmitNativeCode() {
427 // Note: There are 6 kinds of moves:
428 // 1. constant -> GPR/FPR (non-cycle)
429 // 2. constant -> stack (non-cycle)
430 // 3. GPR/FPR -> GPR/FPR
431 // 4. GPR/FPR -> stack
432 // 5. stack -> GPR/FPR
433 // 6. stack -> stack (non-cycle)
434 // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5
435 // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting
436 // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the
437 // dependency.
438 vixl_temps_.Open(GetVIXLAssembler());
439}
440
441void ParallelMoveResolverARM64::FinishEmitNativeCode() {
442 vixl_temps_.Close();
443}
444
445Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) {
446 DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister ||
447 kind == Location::kStackSlot || kind == Location::kDoubleStackSlot);
448 kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister;
449 Location scratch = GetScratchLocation(kind);
450 if (!scratch.Equals(Location::NoLocation())) {
451 return scratch;
452 }
453 // Allocate from VIXL temp registers.
454 if (kind == Location::kRegister) {
455 scratch = LocationFrom(vixl_temps_.AcquireX());
456 } else {
457 DCHECK(kind == Location::kFpuRegister);
458 scratch = LocationFrom(vixl_temps_.AcquireD());
459 }
460 AddScratchLocation(scratch);
461 return scratch;
462}
463
464void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) {
465 if (loc.IsRegister()) {
466 vixl_temps_.Release(XRegisterFrom(loc));
467 } else {
468 DCHECK(loc.IsFpuRegister());
469 vixl_temps_.Release(DRegisterFrom(loc));
470 }
471 RemoveScratchLocation(loc);
472}
473
Alexandre Rames3e69f162014-12-10 10:36:50 +0000474void ParallelMoveResolverARM64::EmitMove(size_t index) {
475 MoveOperands* move = moves_.Get(index);
476 codegen_->MoveLocation(move->GetDestination(), move->GetSource());
477}
478
Alexandre Rames5319def2014-10-23 10:03:10 +0100479void CodeGeneratorARM64::GenerateFrameEntry() {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100480 MacroAssembler* masm = GetVIXLAssembler();
481 BlockPoolsScope block_pools(masm);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000482 __ Bind(&frame_entry_label_);
483
Serban Constantinescu02164b32014-11-13 14:05:07 +0000484 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod();
485 if (do_overflow_check) {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100486 UseScratchRegisterScope temps(masm);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000487 Register temp = temps.AcquireX();
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000488 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000489 __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64)));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000490 __ Ldr(wzr, MemOperand(temp, 0));
491 RecordPcInfo(nullptr, 0);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000492 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100493
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000494 if (!HasEmptyFrame()) {
495 int frame_size = GetFrameSize();
496 // Stack layout:
497 // sp[frame_size - 8] : lr.
498 // ... : other preserved core registers.
499 // ... : other preserved fp registers.
500 // ... : reserved frame space.
501 // sp[0] : current method.
502 __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100503 GetAssembler()->cfi().AdjustCFAOffset(frame_size);
Zheng Xu69a50302015-04-14 20:04:41 +0800504 GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(),
505 frame_size - GetCoreSpillSize());
506 GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(),
507 frame_size - FrameEntrySpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000508 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100509}
510
511void CodeGeneratorARM64::GenerateFrameExit() {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100512 BlockPoolsScope block_pools(GetVIXLAssembler());
David Srbeckyc34dc932015-04-12 09:27:43 +0100513 GetAssembler()->cfi().RememberState();
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000514 if (!HasEmptyFrame()) {
515 int frame_size = GetFrameSize();
Zheng Xu69a50302015-04-14 20:04:41 +0800516 GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(),
517 frame_size - FrameEntrySpillSize());
518 GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(),
519 frame_size - GetCoreSpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000520 __ Drop(frame_size);
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100521 GetAssembler()->cfi().AdjustCFAOffset(-frame_size);
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000522 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100523 __ Ret();
524 GetAssembler()->cfi().RestoreState();
525 GetAssembler()->cfi().DefCFAOffset(GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +0100526}
527
528void CodeGeneratorARM64::Bind(HBasicBlock* block) {
529 __ Bind(GetLabelOf(block));
530}
531
Alexandre Rames5319def2014-10-23 10:03:10 +0100532void CodeGeneratorARM64::Move(HInstruction* instruction,
533 Location location,
534 HInstruction* move_for) {
535 LocationSummary* locations = instruction->GetLocations();
536 if (locations != nullptr && locations->Out().Equals(location)) {
537 return;
538 }
539
540 Primitive::Type type = instruction->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000541 DCHECK_NE(type, Primitive::kPrimVoid);
Alexandre Rames5319def2014-10-23 10:03:10 +0100542
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000543 if (instruction->IsIntConstant()
544 || instruction->IsLongConstant()
545 || instruction->IsNullConstant()) {
546 int64_t value = GetInt64ValueOf(instruction->AsConstant());
Alexandre Rames5319def2014-10-23 10:03:10 +0100547 if (location.IsRegister()) {
548 Register dst = RegisterFrom(location, type);
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000549 DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) ||
Alexandre Rames5319def2014-10-23 10:03:10 +0100550 (instruction->IsLongConstant() && dst.Is64Bits()));
551 __ Mov(dst, value);
552 } else {
553 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000554 UseScratchRegisterScope temps(GetVIXLAssembler());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000555 Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant())
556 ? temps.AcquireW()
557 : temps.AcquireX();
Alexandre Rames5319def2014-10-23 10:03:10 +0100558 __ Mov(temp, value);
559 __ Str(temp, StackOperandFrom(location));
560 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000561 } else if (instruction->IsTemporary()) {
562 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000563 MoveLocation(location, temp_location, type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100564 } else if (instruction->IsLoadLocal()) {
565 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
Alexandre Rames542361f2015-01-29 16:57:31 +0000566 if (Primitive::Is64BitType(type)) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000567 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000568 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000569 MoveLocation(location, Location::StackSlot(stack_slot), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100570 }
571
572 } else {
573 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000574 MoveLocation(location, locations->Out(), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100575 }
576}
577
Alexandre Rames5319def2014-10-23 10:03:10 +0100578Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const {
579 Primitive::Type type = load->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000580
Alexandre Rames5319def2014-10-23 10:03:10 +0100581 switch (type) {
582 case Primitive::kPrimNot:
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000583 case Primitive::kPrimInt:
584 case Primitive::kPrimFloat:
585 return Location::StackSlot(GetStackSlot(load->GetLocal()));
586
587 case Primitive::kPrimLong:
588 case Primitive::kPrimDouble:
589 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
590
Alexandre Rames5319def2014-10-23 10:03:10 +0100591 case Primitive::kPrimBoolean:
592 case Primitive::kPrimByte:
593 case Primitive::kPrimChar:
594 case Primitive::kPrimShort:
Alexandre Rames5319def2014-10-23 10:03:10 +0100595 case Primitive::kPrimVoid:
Alexandre Rames5319def2014-10-23 10:03:10 +0100596 LOG(FATAL) << "Unexpected type " << type;
597 }
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000598
Alexandre Rames5319def2014-10-23 10:03:10 +0100599 LOG(FATAL) << "Unreachable";
600 return Location::NoLocation();
601}
602
603void CodeGeneratorARM64::MarkGCCard(Register object, Register value) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000604 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +0100605 Register card = temps.AcquireX();
Serban Constantinescu02164b32014-11-13 14:05:07 +0000606 Register temp = temps.AcquireW(); // Index within the CardTable - 32bit.
Alexandre Rames5319def2014-10-23 10:03:10 +0100607 vixl::Label done;
608 __ Cbz(value, &done);
609 __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value()));
610 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000611 __ Strb(card, MemOperand(card, temp.X()));
Alexandre Rames5319def2014-10-23 10:03:10 +0100612 __ Bind(&done);
613}
614
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000615void CodeGeneratorARM64::SetupBlockedRegisters(bool is_baseline) const {
616 // Blocked core registers:
617 // lr : Runtime reserved.
618 // tr : Runtime reserved.
619 // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it.
620 // ip1 : VIXL core temp.
621 // ip0 : VIXL core temp.
622 //
623 // Blocked fp registers:
624 // d31 : VIXL fp temp.
Alexandre Rames5319def2014-10-23 10:03:10 +0100625 CPURegList reserved_core_registers = vixl_reserved_core_registers;
626 reserved_core_registers.Combine(runtime_reserved_core_registers);
Alexandre Rames5319def2014-10-23 10:03:10 +0100627 while (!reserved_core_registers.IsEmpty()) {
628 blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true;
629 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000630
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000631 CPURegList reserved_fp_registers = vixl_reserved_fp_registers;
Zheng Xua3ec3942015-02-15 18:39:46 +0800632 while (!reserved_fp_registers.IsEmpty()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000633 blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true;
634 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000635
636 if (is_baseline) {
637 CPURegList reserved_core_baseline_registers = callee_saved_core_registers;
638 while (!reserved_core_baseline_registers.IsEmpty()) {
639 blocked_core_registers_[reserved_core_baseline_registers.PopLowestIndex().code()] = true;
640 }
641
642 CPURegList reserved_fp_baseline_registers = callee_saved_fp_registers;
643 while (!reserved_fp_baseline_registers.IsEmpty()) {
644 blocked_fpu_registers_[reserved_fp_baseline_registers.PopLowestIndex().code()] = true;
645 }
646 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100647}
648
649Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const {
650 if (type == Primitive::kPrimVoid) {
651 LOG(FATAL) << "Unreachable type " << type;
652 }
653
Alexandre Rames542361f2015-01-29 16:57:31 +0000654 if (Primitive::IsFloatingPointType(type)) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000655 ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters);
656 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100657 return Location::FpuRegisterLocation(reg);
658 } else {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000659 ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters);
660 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100661 return Location::RegisterLocation(reg);
662 }
663}
664
Alexandre Rames3e69f162014-12-10 10:36:50 +0000665size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
666 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
667 __ Str(reg, MemOperand(sp, stack_index));
668 return kArm64WordSize;
669}
670
671size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
672 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
673 __ Ldr(reg, MemOperand(sp, stack_index));
674 return kArm64WordSize;
675}
676
677size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
678 FPRegister reg = FPRegister(reg_id, kDRegSize);
679 __ Str(reg, MemOperand(sp, stack_index));
680 return kArm64WordSize;
681}
682
683size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
684 FPRegister reg = FPRegister(reg_id, kDRegSize);
685 __ Ldr(reg, MemOperand(sp, stack_index));
686 return kArm64WordSize;
687}
688
Alexandre Rames5319def2014-10-23 10:03:10 +0100689void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const {
690 stream << Arm64ManagedRegister::FromXRegister(XRegister(reg));
691}
692
693void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
694 stream << Arm64ManagedRegister::FromDRegister(DRegister(reg));
695}
696
Alexandre Rames67555f72014-11-18 10:55:16 +0000697void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000698 if (constant->IsIntConstant()) {
699 __ Mov(Register(destination), constant->AsIntConstant()->GetValue());
700 } else if (constant->IsLongConstant()) {
701 __ Mov(Register(destination), constant->AsLongConstant()->GetValue());
702 } else if (constant->IsNullConstant()) {
703 __ Mov(Register(destination), 0);
Alexandre Rames67555f72014-11-18 10:55:16 +0000704 } else if (constant->IsFloatConstant()) {
705 __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue());
706 } else {
707 DCHECK(constant->IsDoubleConstant());
708 __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue());
709 }
710}
711
Alexandre Rames3e69f162014-12-10 10:36:50 +0000712
713static bool CoherentConstantAndType(Location constant, Primitive::Type type) {
714 DCHECK(constant.IsConstant());
715 HConstant* cst = constant.GetConstant();
716 return (cst->IsIntConstant() && type == Primitive::kPrimInt) ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000717 // Null is mapped to a core W register, which we associate with kPrimInt.
718 (cst->IsNullConstant() && type == Primitive::kPrimInt) ||
Alexandre Rames3e69f162014-12-10 10:36:50 +0000719 (cst->IsLongConstant() && type == Primitive::kPrimLong) ||
720 (cst->IsFloatConstant() && type == Primitive::kPrimFloat) ||
721 (cst->IsDoubleConstant() && type == Primitive::kPrimDouble);
722}
723
724void CodeGeneratorARM64::MoveLocation(Location destination, Location source, Primitive::Type type) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000725 if (source.Equals(destination)) {
726 return;
727 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000728
729 // A valid move can always be inferred from the destination and source
730 // locations. When moving from and to a register, the argument type can be
731 // used to generate 32bit instead of 64bit moves. In debug mode we also
732 // checks the coherency of the locations and the type.
733 bool unspecified_type = (type == Primitive::kPrimVoid);
734
735 if (destination.IsRegister() || destination.IsFpuRegister()) {
736 if (unspecified_type) {
737 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
738 if (source.IsStackSlot() ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000739 (src_cst != nullptr && (src_cst->IsIntConstant()
740 || src_cst->IsFloatConstant()
741 || src_cst->IsNullConstant()))) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000742 // For stack slots and 32bit constants, a 64bit type is appropriate.
743 type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexandre Rames67555f72014-11-18 10:55:16 +0000744 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000745 // If the source is a double stack slot or a 64bit constant, a 64bit
746 // type is appropriate. Else the source is a register, and since the
747 // type has not been specified, we chose a 64bit type to force a 64bit
748 // move.
749 type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexandre Rames67555f72014-11-18 10:55:16 +0000750 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000751 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000752 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) ||
753 (destination.IsRegister() && !Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000754 CPURegister dst = CPURegisterFrom(destination, type);
755 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
756 DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot());
757 __ Ldr(dst, StackOperandFrom(source));
758 } else if (source.IsConstant()) {
759 DCHECK(CoherentConstantAndType(source, type));
760 MoveConstant(dst, source.GetConstant());
761 } else {
762 if (destination.IsRegister()) {
763 __ Mov(Register(dst), RegisterFrom(source, type));
764 } else {
Zheng Xuad4450e2015-04-17 18:48:56 +0800765 DCHECK(destination.IsFpuRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000766 __ Fmov(FPRegister(dst), FPRegisterFrom(source, type));
767 }
768 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000769 } else { // The destination is not a register. It must be a stack slot.
770 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
771 if (source.IsRegister() || source.IsFpuRegister()) {
772 if (unspecified_type) {
773 if (source.IsRegister()) {
774 type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
775 } else {
776 type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
777 }
778 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000779 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) &&
780 (source.IsFpuRegister() == Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000781 __ Str(CPURegisterFrom(source, type), StackOperandFrom(destination));
782 } else if (source.IsConstant()) {
783 DCHECK(unspecified_type || CoherentConstantAndType(source, type));
784 UseScratchRegisterScope temps(GetVIXLAssembler());
785 HConstant* src_cst = source.GetConstant();
786 CPURegister temp;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000787 if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000788 temp = temps.AcquireW();
789 } else if (src_cst->IsLongConstant()) {
790 temp = temps.AcquireX();
791 } else if (src_cst->IsFloatConstant()) {
792 temp = temps.AcquireS();
793 } else {
794 DCHECK(src_cst->IsDoubleConstant());
795 temp = temps.AcquireD();
796 }
797 MoveConstant(temp, src_cst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000798 __ Str(temp, StackOperandFrom(destination));
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000799 } else {
Alexandre Rames67555f72014-11-18 10:55:16 +0000800 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000801 DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000802 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000803 // There is generally less pressure on FP registers.
804 FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS();
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000805 __ Ldr(temp, StackOperandFrom(source));
806 __ Str(temp, StackOperandFrom(destination));
807 }
808 }
809}
810
811void CodeGeneratorARM64::Load(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000812 CPURegister dst,
813 const MemOperand& src) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000814 switch (type) {
815 case Primitive::kPrimBoolean:
Alexandre Rames67555f72014-11-18 10:55:16 +0000816 __ Ldrb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000817 break;
818 case Primitive::kPrimByte:
Alexandre Rames67555f72014-11-18 10:55:16 +0000819 __ Ldrsb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000820 break;
821 case Primitive::kPrimShort:
Alexandre Rames67555f72014-11-18 10:55:16 +0000822 __ Ldrsh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000823 break;
824 case Primitive::kPrimChar:
Alexandre Rames67555f72014-11-18 10:55:16 +0000825 __ Ldrh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000826 break;
827 case Primitive::kPrimInt:
828 case Primitive::kPrimNot:
829 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000830 case Primitive::kPrimFloat:
831 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000832 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Alexandre Rames67555f72014-11-18 10:55:16 +0000833 __ Ldr(dst, src);
834 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000835 case Primitive::kPrimVoid:
836 LOG(FATAL) << "Unreachable type " << type;
837 }
838}
839
Calin Juravle77520bc2015-01-12 18:45:46 +0000840void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000841 CPURegister dst,
842 const MemOperand& src) {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100843 MacroAssembler* masm = GetVIXLAssembler();
844 BlockPoolsScope block_pools(masm);
845 UseScratchRegisterScope temps(masm);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000846 Register temp_base = temps.AcquireX();
Calin Juravle77520bc2015-01-12 18:45:46 +0000847 Primitive::Type type = instruction->GetType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000848
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000849 DCHECK(!src.IsPreIndex());
850 DCHECK(!src.IsPostIndex());
851
852 // TODO(vixl): Let the MacroAssembler handle MemOperand.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800853 __ Add(temp_base, src.base(), OperandFromMemOperand(src));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000854 MemOperand base = MemOperand(temp_base);
855 switch (type) {
856 case Primitive::kPrimBoolean:
857 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000858 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000859 break;
860 case Primitive::kPrimByte:
861 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000862 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000863 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
864 break;
865 case Primitive::kPrimChar:
866 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000867 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000868 break;
869 case Primitive::kPrimShort:
870 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000871 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000872 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
873 break;
874 case Primitive::kPrimInt:
875 case Primitive::kPrimNot:
876 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000877 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000878 __ Ldar(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000879 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000880 break;
881 case Primitive::kPrimFloat:
882 case Primitive::kPrimDouble: {
883 DCHECK(dst.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000884 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000885
886 Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
887 __ Ldar(temp, base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000888 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000889 __ Fmov(FPRegister(dst), temp);
890 break;
891 }
892 case Primitive::kPrimVoid:
893 LOG(FATAL) << "Unreachable type " << type;
894 }
895}
896
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000897void CodeGeneratorARM64::Store(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000898 CPURegister src,
899 const MemOperand& dst) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000900 switch (type) {
901 case Primitive::kPrimBoolean:
902 case Primitive::kPrimByte:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000903 __ Strb(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000904 break;
905 case Primitive::kPrimChar:
906 case Primitive::kPrimShort:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000907 __ Strh(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000908 break;
909 case Primitive::kPrimInt:
910 case Primitive::kPrimNot:
911 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000912 case Primitive::kPrimFloat:
913 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000914 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000915 __ Str(src, dst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000916 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000917 case Primitive::kPrimVoid:
918 LOG(FATAL) << "Unreachable type " << type;
919 }
920}
921
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000922void CodeGeneratorARM64::StoreRelease(Primitive::Type type,
923 CPURegister src,
924 const MemOperand& dst) {
925 UseScratchRegisterScope temps(GetVIXLAssembler());
926 Register temp_base = temps.AcquireX();
927
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000928 DCHECK(!dst.IsPreIndex());
929 DCHECK(!dst.IsPostIndex());
930
931 // TODO(vixl): Let the MacroAssembler handle this.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800932 Operand op = OperandFromMemOperand(dst);
933 __ Add(temp_base, dst.base(), op);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000934 MemOperand base = MemOperand(temp_base);
935 switch (type) {
936 case Primitive::kPrimBoolean:
937 case Primitive::kPrimByte:
938 __ Stlrb(Register(src), base);
939 break;
940 case Primitive::kPrimChar:
941 case Primitive::kPrimShort:
942 __ Stlrh(Register(src), base);
943 break;
944 case Primitive::kPrimInt:
945 case Primitive::kPrimNot:
946 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000947 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000948 __ Stlr(Register(src), base);
949 break;
950 case Primitive::kPrimFloat:
951 case Primitive::kPrimDouble: {
952 DCHECK(src.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000953 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000954
955 Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
956 __ Fmov(temp, FPRegister(src));
957 __ Stlr(temp, base);
958 break;
959 }
960 case Primitive::kPrimVoid:
961 LOG(FATAL) << "Unreachable type " << type;
962 }
963}
964
Alexandre Rames67555f72014-11-18 10:55:16 +0000965void CodeGeneratorARM64::LoadCurrentMethod(vixl::Register current_method) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000966 DCHECK(RequiresCurrentMethod());
Alexandre Rames67555f72014-11-18 10:55:16 +0000967 DCHECK(current_method.IsW());
968 __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset));
969}
970
971void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset,
972 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000973 uint32_t dex_pc,
974 SlowPathCode* slow_path) {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100975 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames67555f72014-11-18 10:55:16 +0000976 __ Ldr(lr, MemOperand(tr, entry_point_offset));
977 __ Blr(lr);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000978 if (instruction != nullptr) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000979 RecordPcInfo(instruction, dex_pc, slow_path);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000980 DCHECK(instruction->IsSuspendCheck()
981 || instruction->IsBoundsCheck()
982 || instruction->IsNullCheck()
983 || instruction->IsDivZeroCheck()
984 || !IsLeafMethod());
985 }
Alexandre Rames67555f72014-11-18 10:55:16 +0000986}
987
988void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path,
989 vixl::Register class_reg) {
990 UseScratchRegisterScope temps(GetVIXLAssembler());
991 Register temp = temps.AcquireW();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000992 size_t status_offset = mirror::Class::StatusOffset().SizeValue();
Serban Constantinescu579885a2015-02-22 20:51:33 +0000993 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000994
Serban Constantinescu02164b32014-11-13 14:05:07 +0000995 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
Serban Constantinescu579885a2015-02-22 20:51:33 +0000996 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000997 // TODO(vixl): Let the MacroAssembler handle MemOperand.
998 __ Add(temp, class_reg, status_offset);
999 __ Ldar(temp, HeapOperand(temp));
1000 __ Cmp(temp, mirror::Class::kStatusInitialized);
1001 __ B(lt, slow_path->GetEntryLabel());
1002 } else {
1003 __ Ldr(temp, HeapOperand(class_reg, status_offset));
1004 __ Cmp(temp, mirror::Class::kStatusInitialized);
1005 __ B(lt, slow_path->GetEntryLabel());
1006 __ Dmb(InnerShareable, BarrierReads);
1007 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001008 __ Bind(slow_path->GetExitLabel());
1009}
Alexandre Rames5319def2014-10-23 10:03:10 +01001010
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001011void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) {
1012 BarrierType type = BarrierAll;
1013
1014 switch (kind) {
1015 case MemBarrierKind::kAnyAny:
1016 case MemBarrierKind::kAnyStore: {
1017 type = BarrierAll;
1018 break;
1019 }
1020 case MemBarrierKind::kLoadAny: {
1021 type = BarrierReads;
1022 break;
1023 }
1024 case MemBarrierKind::kStoreStore: {
1025 type = BarrierWrites;
1026 break;
1027 }
1028 default:
1029 LOG(FATAL) << "Unexpected memory barrier " << kind;
1030 }
1031 __ Dmb(InnerShareable, type);
1032}
1033
Serban Constantinescu02164b32014-11-13 14:05:07 +00001034void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction,
1035 HBasicBlock* successor) {
1036 SuspendCheckSlowPathARM64* slow_path =
1037 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor);
1038 codegen_->AddSlowPath(slow_path);
1039 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
1040 Register temp = temps.AcquireW();
1041
1042 __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue()));
1043 if (successor == nullptr) {
1044 __ Cbnz(temp, slow_path->GetEntryLabel());
1045 __ Bind(slow_path->GetReturnLabel());
1046 } else {
1047 __ Cbz(temp, codegen_->GetLabelOf(successor));
1048 __ B(slow_path->GetEntryLabel());
1049 // slow_path will return to GetLabelOf(successor).
1050 }
1051}
1052
Alexandre Rames5319def2014-10-23 10:03:10 +01001053InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph,
1054 CodeGeneratorARM64* codegen)
1055 : HGraphVisitor(graph),
1056 assembler_(codegen->GetAssembler()),
1057 codegen_(codegen) {}
1058
1059#define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \
Alexandre Rames3e69f162014-12-10 10:36:50 +00001060 /* No unimplemented IR. */
Alexandre Rames5319def2014-10-23 10:03:10 +01001061
1062#define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode
1063
1064enum UnimplementedInstructionBreakCode {
Alexandre Rames67555f72014-11-18 10:55:16 +00001065 // Using a base helps identify when we hit such breakpoints.
1066 UnimplementedInstructionBreakCodeBaseCode = 0x900,
Alexandre Rames5319def2014-10-23 10:03:10 +01001067#define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name),
1068 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION)
1069#undef ENUM_UNIMPLEMENTED_INSTRUCTION
1070};
1071
1072#define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \
1073 void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001074 UNUSED(instr); \
Alexandre Rames5319def2014-10-23 10:03:10 +01001075 __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \
1076 } \
1077 void LocationsBuilderARM64::Visit##name(H##name* instr) { \
1078 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \
1079 locations->SetOut(Location::Any()); \
1080 }
1081 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS)
1082#undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS
1083
1084#undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE
Alexandre Rames67555f72014-11-18 10:55:16 +00001085#undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION
Alexandre Rames5319def2014-10-23 10:03:10 +01001086
Alexandre Rames67555f72014-11-18 10:55:16 +00001087void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001088 DCHECK_EQ(instr->InputCount(), 2U);
1089 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1090 Primitive::Type type = instr->GetResultType();
1091 switch (type) {
1092 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001093 case Primitive::kPrimLong:
Alexandre Rames5319def2014-10-23 10:03:10 +01001094 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001095 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr));
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001096 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001097 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001098
1099 case Primitive::kPrimFloat:
1100 case Primitive::kPrimDouble:
1101 locations->SetInAt(0, Location::RequiresFpuRegister());
1102 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001103 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001104 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001105
Alexandre Rames5319def2014-10-23 10:03:10 +01001106 default:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001107 LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001108 }
1109}
1110
Alexandre Rames09a99962015-04-15 11:47:56 +01001111void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) {
1112 LocationSummary* locations =
1113 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1114 locations->SetInAt(0, Location::RequiresRegister());
1115 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1116 locations->SetOut(Location::RequiresFpuRegister());
1117 } else {
1118 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1119 }
1120}
1121
1122void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction,
1123 const FieldInfo& field_info) {
1124 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Alexandre Ramesd921d642015-04-16 15:07:16 +01001125 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames09a99962015-04-15 11:47:56 +01001126
1127 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset());
1128 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
1129
1130 if (field_info.IsVolatile()) {
1131 if (use_acquire_release) {
1132 // NB: LoadAcquire will record the pc info if needed.
1133 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
1134 } else {
1135 codegen_->Load(field_info.GetFieldType(), OutputCPURegister(instruction), field);
1136 codegen_->MaybeRecordImplicitNullCheck(instruction);
1137 // For IRIW sequential consistency kLoadAny is not sufficient.
1138 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1139 }
1140 } else {
1141 codegen_->Load(field_info.GetFieldType(), OutputCPURegister(instruction), field);
1142 codegen_->MaybeRecordImplicitNullCheck(instruction);
1143 }
1144}
1145
1146void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) {
1147 LocationSummary* locations =
1148 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1149 locations->SetInAt(0, Location::RequiresRegister());
1150 if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
1151 locations->SetInAt(1, Location::RequiresFpuRegister());
1152 } else {
1153 locations->SetInAt(1, Location::RequiresRegister());
1154 }
1155}
1156
1157void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction,
1158 const FieldInfo& field_info) {
1159 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
Alexandre Ramesd921d642015-04-16 15:07:16 +01001160 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames09a99962015-04-15 11:47:56 +01001161
1162 Register obj = InputRegisterAt(instruction, 0);
1163 CPURegister value = InputCPURegisterAt(instruction, 1);
1164 Offset offset = field_info.GetFieldOffset();
1165 Primitive::Type field_type = field_info.GetFieldType();
1166 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
1167
1168 if (field_info.IsVolatile()) {
1169 if (use_acquire_release) {
1170 codegen_->StoreRelease(field_type, value, HeapOperand(obj, offset));
1171 codegen_->MaybeRecordImplicitNullCheck(instruction);
1172 } else {
1173 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
1174 codegen_->Store(field_type, value, HeapOperand(obj, offset));
1175 codegen_->MaybeRecordImplicitNullCheck(instruction);
1176 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1177 }
1178 } else {
1179 codegen_->Store(field_type, value, HeapOperand(obj, offset));
1180 codegen_->MaybeRecordImplicitNullCheck(instruction);
1181 }
1182
1183 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
1184 codegen_->MarkGCCard(obj, Register(value));
1185 }
1186}
1187
Alexandre Rames67555f72014-11-18 10:55:16 +00001188void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001189 Primitive::Type type = instr->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001190
1191 switch (type) {
1192 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001193 case Primitive::kPrimLong: {
1194 Register dst = OutputRegister(instr);
1195 Register lhs = InputRegisterAt(instr, 0);
1196 Operand rhs = InputOperandAt(instr, 1);
Alexandre Rames5319def2014-10-23 10:03:10 +01001197 if (instr->IsAdd()) {
1198 __ Add(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001199 } else if (instr->IsAnd()) {
1200 __ And(dst, lhs, rhs);
1201 } else if (instr->IsOr()) {
1202 __ Orr(dst, lhs, rhs);
1203 } else if (instr->IsSub()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001204 __ Sub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001205 } else {
1206 DCHECK(instr->IsXor());
1207 __ Eor(dst, lhs, rhs);
Alexandre Rames5319def2014-10-23 10:03:10 +01001208 }
1209 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001210 }
1211 case Primitive::kPrimFloat:
1212 case Primitive::kPrimDouble: {
1213 FPRegister dst = OutputFPRegister(instr);
1214 FPRegister lhs = InputFPRegisterAt(instr, 0);
1215 FPRegister rhs = InputFPRegisterAt(instr, 1);
1216 if (instr->IsAdd()) {
1217 __ Fadd(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001218 } else if (instr->IsSub()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001219 __ Fsub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001220 } else {
1221 LOG(FATAL) << "Unexpected floating-point binary operation";
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001222 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001223 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001224 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001225 default:
Alexandre Rames67555f72014-11-18 10:55:16 +00001226 LOG(FATAL) << "Unexpected binary operation type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001227 }
1228}
1229
Serban Constantinescu02164b32014-11-13 14:05:07 +00001230void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) {
1231 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1232
1233 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1234 Primitive::Type type = instr->GetResultType();
1235 switch (type) {
1236 case Primitive::kPrimInt:
1237 case Primitive::kPrimLong: {
1238 locations->SetInAt(0, Location::RequiresRegister());
1239 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1240 locations->SetOut(Location::RequiresRegister());
1241 break;
1242 }
1243 default:
1244 LOG(FATAL) << "Unexpected shift type " << type;
1245 }
1246}
1247
1248void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) {
1249 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1250
1251 Primitive::Type type = instr->GetType();
1252 switch (type) {
1253 case Primitive::kPrimInt:
1254 case Primitive::kPrimLong: {
1255 Register dst = OutputRegister(instr);
1256 Register lhs = InputRegisterAt(instr, 0);
1257 Operand rhs = InputOperandAt(instr, 1);
1258 if (rhs.IsImmediate()) {
1259 uint32_t shift_value = (type == Primitive::kPrimInt)
1260 ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue)
1261 : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue);
1262 if (instr->IsShl()) {
1263 __ Lsl(dst, lhs, shift_value);
1264 } else if (instr->IsShr()) {
1265 __ Asr(dst, lhs, shift_value);
1266 } else {
1267 __ Lsr(dst, lhs, shift_value);
1268 }
1269 } else {
1270 Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W();
1271
1272 if (instr->IsShl()) {
1273 __ Lsl(dst, lhs, rhs_reg);
1274 } else if (instr->IsShr()) {
1275 __ Asr(dst, lhs, rhs_reg);
1276 } else {
1277 __ Lsr(dst, lhs, rhs_reg);
1278 }
1279 }
1280 break;
1281 }
1282 default:
1283 LOG(FATAL) << "Unexpected shift operation type " << type;
1284 }
1285}
1286
Alexandre Rames5319def2014-10-23 10:03:10 +01001287void LocationsBuilderARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001288 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001289}
1290
1291void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001292 HandleBinaryOp(instruction);
1293}
1294
1295void LocationsBuilderARM64::VisitAnd(HAnd* instruction) {
1296 HandleBinaryOp(instruction);
1297}
1298
1299void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) {
1300 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001301}
1302
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001303void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) {
1304 LocationSummary* locations =
1305 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1306 locations->SetInAt(0, Location::RequiresRegister());
1307 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01001308 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1309 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1310 } else {
1311 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1312 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001313}
1314
1315void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) {
1316 LocationSummary* locations = instruction->GetLocations();
1317 Primitive::Type type = instruction->GetType();
1318 Register obj = InputRegisterAt(instruction, 0);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001319 Location index = locations->InAt(1);
1320 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001321 MemOperand source = HeapOperand(obj);
Alexandre Ramesd921d642015-04-16 15:07:16 +01001322 MacroAssembler* masm = GetVIXLAssembler();
1323 UseScratchRegisterScope temps(masm);
1324 BlockPoolsScope block_pools(masm);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001325
1326 if (index.IsConstant()) {
1327 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001328 source = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001329 } else {
1330 Register temp = temps.AcquireSameSizeAs(obj);
1331 Register index_reg = RegisterFrom(index, Primitive::kPrimInt);
1332 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001333 source = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001334 }
1335
Alexandre Rames67555f72014-11-18 10:55:16 +00001336 codegen_->Load(type, OutputCPURegister(instruction), source);
Calin Juravle77520bc2015-01-12 18:45:46 +00001337 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001338}
1339
Alexandre Rames5319def2014-10-23 10:03:10 +01001340void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) {
1341 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1342 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001343 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001344}
1345
1346void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) {
Alexandre Ramesd921d642015-04-16 15:07:16 +01001347 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +01001348 __ Ldr(OutputRegister(instruction),
1349 HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset()));
Calin Juravle77520bc2015-01-12 18:45:46 +00001350 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001351}
1352
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001353void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) {
Alexandre Rames97833a02015-04-16 15:07:12 +01001354 if (instruction->NeedsTypeCheck()) {
1355 LocationSummary* locations =
1356 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001357 InvokeRuntimeCallingConvention calling_convention;
1358 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1359 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1360 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1361 } else {
Alexandre Rames97833a02015-04-16 15:07:12 +01001362 LocationSummary* locations =
1363 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001364 locations->SetInAt(0, Location::RequiresRegister());
1365 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01001366 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1367 locations->SetInAt(2, Location::RequiresFpuRegister());
1368 } else {
1369 locations->SetInAt(2, Location::RequiresRegister());
1370 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001371 }
1372}
1373
1374void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) {
1375 Primitive::Type value_type = instruction->GetComponentType();
Alexandre Rames97833a02015-04-16 15:07:12 +01001376 LocationSummary* locations = instruction->GetLocations();
1377 bool needs_runtime_call = locations->WillCall();
1378
1379 if (needs_runtime_call) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001380 codegen_->InvokeRuntime(
1381 QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001382 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001383 } else {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001384 Register obj = InputRegisterAt(instruction, 0);
Alexandre Rames67555f72014-11-18 10:55:16 +00001385 CPURegister value = InputCPURegisterAt(instruction, 2);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001386 Location index = locations->InAt(1);
1387 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001388 MemOperand destination = HeapOperand(obj);
Alexandre Ramesd921d642015-04-16 15:07:16 +01001389 MacroAssembler* masm = GetVIXLAssembler();
Alexandre Ramesd921d642015-04-16 15:07:16 +01001390 BlockPoolsScope block_pools(masm);
Alexandre Rames97833a02015-04-16 15:07:12 +01001391 {
1392 // We use a block to end the scratch scope before the write barrier, thus
1393 // freeing the temporary registers so they can be used in `MarkGCCard`.
1394 UseScratchRegisterScope temps(masm);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001395
Alexandre Rames97833a02015-04-16 15:07:12 +01001396 if (index.IsConstant()) {
1397 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type);
1398 destination = HeapOperand(obj, offset);
1399 } else {
1400 Register temp = temps.AcquireSameSizeAs(obj);
1401 Register index_reg = InputRegisterAt(instruction, 1);
1402 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(value_type)));
1403 destination = HeapOperand(temp, offset);
1404 }
1405
1406 codegen_->Store(value_type, value, destination);
1407 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001408 }
Alexandre Rames97833a02015-04-16 15:07:12 +01001409 if (CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue())) {
1410 codegen_->MarkGCCard(obj, value.W());
1411 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001412 }
1413}
1414
Alexandre Rames67555f72014-11-18 10:55:16 +00001415void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
1416 LocationSummary* locations =
1417 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1418 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu760d8ef2015-03-28 18:09:56 +00001419 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames67555f72014-11-18 10:55:16 +00001420 if (instruction->HasUses()) {
1421 locations->SetOut(Location::SameAsFirstInput());
1422 }
1423}
1424
1425void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001426 LocationSummary* locations = instruction->GetLocations();
1427 BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(
1428 instruction, locations->InAt(0), locations->InAt(1));
Alexandre Rames67555f72014-11-18 10:55:16 +00001429 codegen_->AddSlowPath(slow_path);
1430
1431 __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1));
1432 __ B(slow_path->GetEntryLabel(), hs);
1433}
1434
1435void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) {
1436 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1437 instruction, LocationSummary::kCallOnSlowPath);
1438 locations->SetInAt(0, Location::RequiresRegister());
1439 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +00001440 locations->AddTemp(Location::RequiresRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001441}
1442
1443void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001444 LocationSummary* locations = instruction->GetLocations();
Alexandre Rames67555f72014-11-18 10:55:16 +00001445 Register obj = InputRegisterAt(instruction, 0);;
1446 Register cls = InputRegisterAt(instruction, 1);;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001447 Register obj_cls = WRegisterFrom(instruction->GetLocations()->GetTemp(0));
Alexandre Rames67555f72014-11-18 10:55:16 +00001448
Alexandre Rames3e69f162014-12-10 10:36:50 +00001449 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1450 instruction, locations->InAt(1), LocationFrom(obj_cls), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001451 codegen_->AddSlowPath(slow_path);
1452
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01001453 // Avoid null check if we know obj is not null.
1454 if (instruction->MustDoNullCheck()) {
1455 __ Cbz(obj, slow_path->GetExitLabel());
1456 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001457 // Compare the class of `obj` with `cls`.
Alexandre Rames3e69f162014-12-10 10:36:50 +00001458 __ Ldr(obj_cls, HeapOperand(obj, mirror::Object::ClassOffset()));
1459 __ Cmp(obj_cls, cls);
Alexandre Rames67555f72014-11-18 10:55:16 +00001460 __ B(ne, slow_path->GetEntryLabel());
1461 __ Bind(slow_path->GetExitLabel());
1462}
1463
1464void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) {
1465 LocationSummary* locations =
1466 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1467 locations->SetInAt(0, Location::RequiresRegister());
1468 if (check->HasUses()) {
1469 locations->SetOut(Location::SameAsFirstInput());
1470 }
1471}
1472
1473void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) {
1474 // We assume the class is not null.
1475 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
1476 check->GetLoadClass(), check, check->GetDexPc(), true);
1477 codegen_->AddSlowPath(slow_path);
1478 GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0));
1479}
1480
Serban Constantinescu02164b32014-11-13 14:05:07 +00001481void LocationsBuilderARM64::VisitCompare(HCompare* compare) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001482 LocationSummary* locations =
Serban Constantinescu02164b32014-11-13 14:05:07 +00001483 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
1484 Primitive::Type in_type = compare->InputAt(0)->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001485 switch (in_type) {
1486 case Primitive::kPrimLong: {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001487 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001488 locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001489 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1490 break;
1491 }
1492 case Primitive::kPrimFloat:
1493 case Primitive::kPrimDouble: {
1494 locations->SetInAt(0, Location::RequiresFpuRegister());
Alexandre Rames93415462015-02-17 15:08:20 +00001495 HInstruction* right = compare->InputAt(1);
1496 if ((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1497 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0))) {
1498 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1499 } else {
1500 locations->SetInAt(1, Location::RequiresFpuRegister());
1501 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001502 locations->SetOut(Location::RequiresRegister());
1503 break;
1504 }
1505 default:
1506 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1507 }
1508}
1509
1510void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) {
1511 Primitive::Type in_type = compare->InputAt(0)->GetType();
1512
1513 // 0 if: left == right
1514 // 1 if: left > right
1515 // -1 if: left < right
1516 switch (in_type) {
1517 case Primitive::kPrimLong: {
1518 Register result = OutputRegister(compare);
1519 Register left = InputRegisterAt(compare, 0);
1520 Operand right = InputOperandAt(compare, 1);
1521
1522 __ Cmp(left, right);
1523 __ Cset(result, ne);
1524 __ Cneg(result, result, lt);
1525 break;
1526 }
1527 case Primitive::kPrimFloat:
1528 case Primitive::kPrimDouble: {
1529 Register result = OutputRegister(compare);
1530 FPRegister left = InputFPRegisterAt(compare, 0);
Alexandre Rames93415462015-02-17 15:08:20 +00001531 if (compare->GetLocations()->InAt(1).IsConstant()) {
1532 if (kIsDebugBuild) {
1533 HInstruction* right = compare->GetLocations()->InAt(1).GetConstant();
1534 DCHECK((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1535 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0)));
1536 }
1537 // 0.0 is the only immediate that can be encoded directly in a FCMP instruction.
1538 __ Fcmp(left, 0.0);
1539 } else {
1540 __ Fcmp(left, InputFPRegisterAt(compare, 1));
1541 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001542 if (compare->IsGtBias()) {
1543 __ Cset(result, ne);
1544 } else {
1545 __ Csetm(result, ne);
1546 }
1547 __ Cneg(result, result, compare->IsGtBias() ? mi : gt);
Alexandre Rames5319def2014-10-23 10:03:10 +01001548 break;
1549 }
1550 default:
1551 LOG(FATAL) << "Unimplemented compare type " << in_type;
1552 }
1553}
1554
1555void LocationsBuilderARM64::VisitCondition(HCondition* instruction) {
1556 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1557 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001558 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames5319def2014-10-23 10:03:10 +01001559 if (instruction->NeedsMaterialization()) {
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001560 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001561 }
1562}
1563
1564void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) {
1565 if (!instruction->NeedsMaterialization()) {
1566 return;
1567 }
1568
1569 LocationSummary* locations = instruction->GetLocations();
1570 Register lhs = InputRegisterAt(instruction, 0);
1571 Operand rhs = InputOperandAt(instruction, 1);
1572 Register res = RegisterFrom(locations->Out(), instruction->GetType());
1573 Condition cond = ARM64Condition(instruction->GetCondition());
1574
1575 __ Cmp(lhs, rhs);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001576 __ Cset(res, cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001577}
1578
1579#define FOR_EACH_CONDITION_INSTRUCTION(M) \
1580 M(Equal) \
1581 M(NotEqual) \
1582 M(LessThan) \
1583 M(LessThanOrEqual) \
1584 M(GreaterThan) \
1585 M(GreaterThanOrEqual)
1586#define DEFINE_CONDITION_VISITORS(Name) \
1587void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \
1588void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); }
1589FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS)
Alexandre Rames67555f72014-11-18 10:55:16 +00001590#undef DEFINE_CONDITION_VISITORS
Alexandre Rames5319def2014-10-23 10:03:10 +01001591#undef FOR_EACH_CONDITION_INSTRUCTION
1592
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001593void LocationsBuilderARM64::VisitDiv(HDiv* div) {
1594 LocationSummary* locations =
1595 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1596 switch (div->GetResultType()) {
1597 case Primitive::kPrimInt:
1598 case Primitive::kPrimLong:
1599 locations->SetInAt(0, Location::RequiresRegister());
1600 locations->SetInAt(1, Location::RequiresRegister());
1601 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1602 break;
1603
1604 case Primitive::kPrimFloat:
1605 case Primitive::kPrimDouble:
1606 locations->SetInAt(0, Location::RequiresFpuRegister());
1607 locations->SetInAt(1, Location::RequiresFpuRegister());
1608 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1609 break;
1610
1611 default:
1612 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1613 }
1614}
1615
1616void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) {
1617 Primitive::Type type = div->GetResultType();
1618 switch (type) {
1619 case Primitive::kPrimInt:
1620 case Primitive::kPrimLong:
1621 __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1));
1622 break;
1623
1624 case Primitive::kPrimFloat:
1625 case Primitive::kPrimDouble:
1626 __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1));
1627 break;
1628
1629 default:
1630 LOG(FATAL) << "Unexpected div type " << type;
1631 }
1632}
1633
Alexandre Rames67555f72014-11-18 10:55:16 +00001634void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1635 LocationSummary* locations =
1636 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1637 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1638 if (instruction->HasUses()) {
1639 locations->SetOut(Location::SameAsFirstInput());
1640 }
1641}
1642
1643void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1644 SlowPathCodeARM64* slow_path =
1645 new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction);
1646 codegen_->AddSlowPath(slow_path);
1647 Location value = instruction->GetLocations()->InAt(0);
1648
Alexandre Rames3e69f162014-12-10 10:36:50 +00001649 Primitive::Type type = instruction->GetType();
1650
1651 if ((type != Primitive::kPrimInt) && (type != Primitive::kPrimLong)) {
1652 LOG(FATAL) << "Unexpected type " << type << "for DivZeroCheck.";
1653 return;
1654 }
1655
Alexandre Rames67555f72014-11-18 10:55:16 +00001656 if (value.IsConstant()) {
1657 int64_t divisor = Int64ConstantFrom(value);
1658 if (divisor == 0) {
1659 __ B(slow_path->GetEntryLabel());
1660 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001661 // A division by a non-null constant is valid. We don't need to perform
1662 // any check, so simply fall through.
Alexandre Rames67555f72014-11-18 10:55:16 +00001663 }
1664 } else {
1665 __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel());
1666 }
1667}
1668
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001669void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1670 LocationSummary* locations =
1671 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1672 locations->SetOut(Location::ConstantLocation(constant));
1673}
1674
1675void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1676 UNUSED(constant);
1677 // Will be generated at use site.
1678}
1679
Alexandre Rames5319def2014-10-23 10:03:10 +01001680void LocationsBuilderARM64::VisitExit(HExit* exit) {
1681 exit->SetLocations(nullptr);
1682}
1683
1684void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001685 UNUSED(exit);
Alexandre Rames5319def2014-10-23 10:03:10 +01001686}
1687
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001688void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) {
1689 LocationSummary* locations =
1690 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1691 locations->SetOut(Location::ConstantLocation(constant));
1692}
1693
1694void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) {
1695 UNUSED(constant);
1696 // Will be generated at use site.
1697}
1698
Alexandre Rames5319def2014-10-23 10:03:10 +01001699void LocationsBuilderARM64::VisitGoto(HGoto* got) {
1700 got->SetLocations(nullptr);
1701}
1702
1703void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) {
1704 HBasicBlock* successor = got->GetSuccessor();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001705 DCHECK(!successor->IsExitBlock());
1706 HBasicBlock* block = got->GetBlock();
1707 HInstruction* previous = got->GetPrevious();
1708 HLoopInformation* info = block->GetLoopInformation();
1709
David Brazdil46e2a392015-03-16 17:31:52 +00001710 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001711 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1712 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1713 return;
1714 }
1715 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1716 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1717 }
1718 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001719 __ B(codegen_->GetLabelOf(successor));
1720 }
1721}
1722
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001723void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction,
1724 vixl::Label* true_target,
1725 vixl::Label* false_target,
1726 vixl::Label* always_true_target) {
1727 HInstruction* cond = instruction->InputAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001728 HCondition* condition = cond->AsCondition();
Alexandre Rames5319def2014-10-23 10:03:10 +01001729
Serban Constantinescu02164b32014-11-13 14:05:07 +00001730 if (cond->IsIntConstant()) {
1731 int32_t cond_value = cond->AsIntConstant()->GetValue();
1732 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001733 if (always_true_target != nullptr) {
1734 __ B(always_true_target);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001735 }
1736 return;
1737 } else {
1738 DCHECK_EQ(cond_value, 0);
1739 }
1740 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001741 // The condition instruction has been materialized, compare the output to 0.
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001742 Location cond_val = instruction->GetLocations()->InAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001743 DCHECK(cond_val.IsRegister());
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001744 __ Cbnz(InputRegisterAt(instruction, 0), true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001745 } else {
1746 // The condition instruction has not been materialized, use its inputs as
1747 // the comparison and its condition as the branch condition.
1748 Register lhs = InputRegisterAt(condition, 0);
1749 Operand rhs = InputOperandAt(condition, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001750 Condition arm64_cond = ARM64Condition(condition->GetCondition());
Alexandre Rames4388dcc2015-02-03 10:28:33 +00001751 if ((arm64_cond != gt && arm64_cond != le) && rhs.IsImmediate() && (rhs.immediate() == 0)) {
1752 switch (arm64_cond) {
1753 case eq:
1754 __ Cbz(lhs, true_target);
1755 break;
1756 case ne:
1757 __ Cbnz(lhs, true_target);
1758 break;
1759 case lt:
1760 // Test the sign bit and branch accordingly.
1761 __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1762 break;
1763 case ge:
1764 // Test the sign bit and branch accordingly.
1765 __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1766 break;
1767 default:
1768 // Without the `static_cast` the compiler throws an error for
1769 // `-Werror=sign-promo`.
1770 LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001771 }
1772 } else {
1773 __ Cmp(lhs, rhs);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001774 __ B(arm64_cond, true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001775 }
1776 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001777 if (false_target != nullptr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001778 __ B(false_target);
1779 }
1780}
1781
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001782void LocationsBuilderARM64::VisitIf(HIf* if_instr) {
1783 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1784 HInstruction* cond = if_instr->InputAt(0);
1785 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1786 locations->SetInAt(0, Location::RequiresRegister());
1787 }
1788}
1789
1790void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) {
1791 vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1792 vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1793 vixl::Label* always_true_target = true_target;
1794 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1795 if_instr->IfTrueSuccessor())) {
1796 always_true_target = nullptr;
1797 }
1798 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1799 if_instr->IfFalseSuccessor())) {
1800 false_target = nullptr;
1801 }
1802 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1803}
1804
1805void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1806 LocationSummary* locations = new (GetGraph()->GetArena())
1807 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1808 HInstruction* cond = deoptimize->InputAt(0);
1809 DCHECK(cond->IsCondition());
1810 if (cond->AsCondition()->NeedsMaterialization()) {
1811 locations->SetInAt(0, Location::RequiresRegister());
1812 }
1813}
1814
1815void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1816 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena())
1817 DeoptimizationSlowPathARM64(deoptimize);
1818 codegen_->AddSlowPath(slow_path);
1819 vixl::Label* slow_path_entry = slow_path->GetEntryLabel();
1820 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1821}
1822
Alexandre Rames5319def2014-10-23 10:03:10 +01001823void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001824 HandleFieldGet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001825}
1826
1827void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001828 HandleFieldGet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01001829}
1830
1831void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001832 HandleFieldSet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001833}
1834
1835void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001836 HandleFieldSet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01001837}
1838
Alexandre Rames67555f72014-11-18 10:55:16 +00001839void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) {
1840 LocationSummary::CallKind call_kind =
1841 instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
1842 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
1843 locations->SetInAt(0, Location::RequiresRegister());
1844 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001845 // The output does overlap inputs.
1846 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexandre Rames67555f72014-11-18 10:55:16 +00001847}
1848
1849void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) {
1850 LocationSummary* locations = instruction->GetLocations();
1851 Register obj = InputRegisterAt(instruction, 0);;
1852 Register cls = InputRegisterAt(instruction, 1);;
1853 Register out = OutputRegister(instruction);
1854
1855 vixl::Label done;
1856
1857 // Return 0 if `obj` is null.
Guillaume "Vermeille" Sanchezaf888352015-04-20 14:41:30 +01001858 // Avoid null check if we know `obj` is not null.
1859 if (instruction->MustDoNullCheck()) {
1860 __ Mov(out, 0);
1861 __ Cbz(obj, &done);
1862 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001863
1864 // Compare the class of `obj` with `cls`.
Serban Constantinescu02164b32014-11-13 14:05:07 +00001865 __ Ldr(out, HeapOperand(obj, mirror::Object::ClassOffset()));
Alexandre Rames67555f72014-11-18 10:55:16 +00001866 __ Cmp(out, cls);
1867 if (instruction->IsClassFinal()) {
1868 // Classes must be equal for the instanceof to succeed.
1869 __ Cset(out, eq);
1870 } else {
1871 // If the classes are not equal, we go into a slow path.
1872 DCHECK(locations->OnlyCallsOnSlowPath());
1873 SlowPathCodeARM64* slow_path =
Alexandre Rames3e69f162014-12-10 10:36:50 +00001874 new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1875 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001876 codegen_->AddSlowPath(slow_path);
1877 __ B(ne, slow_path->GetEntryLabel());
1878 __ Mov(out, 1);
1879 __ Bind(slow_path->GetExitLabel());
1880 }
1881
1882 __ Bind(&done);
1883}
1884
Alexandre Rames5319def2014-10-23 10:03:10 +01001885void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) {
1886 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1887 locations->SetOut(Location::ConstantLocation(constant));
1888}
1889
1890void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) {
1891 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001892 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01001893}
1894
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001895void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) {
1896 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1897 locations->SetOut(Location::ConstantLocation(constant));
1898}
1899
1900void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant) {
1901 // Will be generated at use site.
1902 UNUSED(constant);
1903}
1904
Alexandre Rames5319def2014-10-23 10:03:10 +01001905void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) {
1906 LocationSummary* locations =
1907 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
1908 locations->AddTemp(LocationFrom(x0));
1909
1910 InvokeDexCallingConventionVisitor calling_convention_visitor;
1911 for (size_t i = 0; i < invoke->InputCount(); i++) {
1912 HInstruction* input = invoke->InputAt(i);
1913 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1914 }
1915
1916 Primitive::Type return_type = invoke->GetType();
1917 if (return_type != Primitive::kPrimVoid) {
1918 locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type));
1919 }
1920}
1921
Alexandre Rames67555f72014-11-18 10:55:16 +00001922void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1923 HandleInvoke(invoke);
1924}
1925
1926void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1927 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1928 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
1929 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1930 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1931 Location receiver = invoke->GetLocations()->InAt(0);
1932 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001933 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames67555f72014-11-18 10:55:16 +00001934
1935 // The register ip1 is required to be used for the hidden argument in
1936 // art_quick_imt_conflict_trampoline, so prevent VIXL from using it.
Alexandre Ramesd921d642015-04-16 15:07:16 +01001937 MacroAssembler* masm = GetVIXLAssembler();
1938 UseScratchRegisterScope scratch_scope(masm);
1939 BlockPoolsScope block_pools(masm);
Alexandre Rames67555f72014-11-18 10:55:16 +00001940 scratch_scope.Exclude(ip1);
1941 __ Mov(ip1, invoke->GetDexMethodIndex());
1942
1943 // temp = object->GetClass();
1944 if (receiver.IsStackSlot()) {
1945 __ Ldr(temp, StackOperandFrom(receiver));
1946 __ Ldr(temp, HeapOperand(temp, class_offset));
1947 } else {
1948 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
1949 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001950 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames67555f72014-11-18 10:55:16 +00001951 // temp = temp->GetImtEntryAt(method_offset);
1952 __ Ldr(temp, HeapOperand(temp, method_offset));
1953 // lr = temp->GetEntryPoint();
1954 __ Ldr(lr, HeapOperand(temp, entry_point));
1955 // lr();
1956 __ Blr(lr);
1957 DCHECK(!codegen_->IsLeafMethod());
1958 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1959}
1960
1961void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001962 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1963 if (intrinsic.TryDispatch(invoke)) {
1964 return;
1965 }
1966
Alexandre Rames67555f72014-11-18 10:55:16 +00001967 HandleInvoke(invoke);
1968}
1969
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001970void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001971 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1972 if (intrinsic.TryDispatch(invoke)) {
1973 return;
1974 }
1975
Alexandre Rames67555f72014-11-18 10:55:16 +00001976 HandleInvoke(invoke);
1977}
1978
Andreas Gampe878d58c2015-01-15 23:24:00 -08001979static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) {
1980 if (invoke->GetLocations()->Intrinsified()) {
1981 IntrinsicCodeGeneratorARM64 intrinsic(codegen);
1982 intrinsic.Dispatch(invoke);
1983 return true;
1984 }
1985 return false;
1986}
1987
1988void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
1989 // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention.
1990 DCHECK(temp.Is(kArtMethodRegister));
Alexandre Rames5319def2014-10-23 10:03:10 +01001991 size_t index_in_cache = mirror::Array::DataOffset(kHeapRefSize).SizeValue() +
Andreas Gampe878d58c2015-01-15 23:24:00 -08001992 invoke->GetDexMethodIndex() * kHeapRefSize;
Alexandre Rames5319def2014-10-23 10:03:10 +01001993
1994 // TODO: Implement all kinds of calls:
1995 // 1) boot -> boot
1996 // 2) app -> boot
1997 // 3) app -> app
1998 //
1999 // Currently we implement the app -> app logic, which looks up in the resolve cache.
2000
Nicolas Geoffray0a299b92015-01-29 11:39:44 +00002001 // temp = method;
2002 LoadCurrentMethod(temp);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002003 if (!invoke->IsRecursive()) {
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002004 // temp = temp->dex_cache_resolved_methods_;
2005 __ Ldr(temp, HeapOperand(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset()));
2006 // temp = temp[index_in_cache];
2007 __ Ldr(temp, HeapOperand(temp, index_in_cache));
2008 // lr = temp->entry_point_from_quick_compiled_code_;
2009 __ Ldr(lr, HeapOperand(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
2010 kArm64WordSize)));
2011 // lr();
2012 __ Blr(lr);
2013 } else {
2014 __ Bl(&frame_entry_label_);
2015 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002016
Andreas Gampe878d58c2015-01-15 23:24:00 -08002017 DCHECK(!IsLeafMethod());
2018}
2019
2020void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2021 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2022 return;
2023 }
2024
Alexandre Ramesd921d642015-04-16 15:07:16 +01002025 BlockPoolsScope block_pools(GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -08002026 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
2027 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00002028 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Alexandre Rames5319def2014-10-23 10:03:10 +01002029}
2030
2031void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08002032 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2033 return;
2034 }
2035
Alexandre Rames5319def2014-10-23 10:03:10 +01002036 LocationSummary* locations = invoke->GetLocations();
2037 Location receiver = locations->InAt(0);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002038 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002039 size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() +
2040 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
2041 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00002042 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames5319def2014-10-23 10:03:10 +01002043
Alexandre Ramesd921d642015-04-16 15:07:16 +01002044 BlockPoolsScope block_pools(GetVIXLAssembler());
2045
Alexandre Rames5319def2014-10-23 10:03:10 +01002046 // temp = object->GetClass();
2047 if (receiver.IsStackSlot()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002048 __ Ldr(temp, MemOperand(sp, receiver.GetStackIndex()));
2049 __ Ldr(temp, HeapOperand(temp, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002050 } else {
2051 DCHECK(receiver.IsRegister());
Serban Constantinescu02164b32014-11-13 14:05:07 +00002052 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002053 }
Calin Juravle77520bc2015-01-12 18:45:46 +00002054 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames5319def2014-10-23 10:03:10 +01002055 // temp = temp->GetMethodAt(method_offset);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002056 __ Ldr(temp, HeapOperand(temp, method_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002057 // lr = temp->GetEntryPoint();
Serban Constantinescu02164b32014-11-13 14:05:07 +00002058 __ Ldr(lr, HeapOperand(temp, entry_point.SizeValue()));
Alexandre Rames5319def2014-10-23 10:03:10 +01002059 // lr();
2060 __ Blr(lr);
2061 DCHECK(!codegen_->IsLeafMethod());
2062 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2063}
2064
Alexandre Rames67555f72014-11-18 10:55:16 +00002065void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) {
2066 LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath
2067 : LocationSummary::kNoCall;
2068 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
2069 locations->SetOut(Location::RequiresRegister());
2070}
2071
2072void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) {
2073 Register out = OutputRegister(cls);
2074 if (cls->IsReferrersClass()) {
2075 DCHECK(!cls->CanCallRuntime());
2076 DCHECK(!cls->MustGenerateClinitCheck());
2077 codegen_->LoadCurrentMethod(out);
2078 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2079 } else {
2080 DCHECK(cls->CanCallRuntime());
2081 codegen_->LoadCurrentMethod(out);
2082 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DexCacheResolvedTypesOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002083 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002084
2085 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
2086 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2087 codegen_->AddSlowPath(slow_path);
2088 __ Cbz(out, slow_path->GetEntryLabel());
2089 if (cls->MustGenerateClinitCheck()) {
2090 GenerateClassInitializationCheck(slow_path, out);
2091 } else {
2092 __ Bind(slow_path->GetExitLabel());
2093 }
2094 }
2095}
2096
2097void LocationsBuilderARM64::VisitLoadException(HLoadException* load) {
2098 LocationSummary* locations =
2099 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2100 locations->SetOut(Location::RequiresRegister());
2101}
2102
2103void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) {
2104 MemOperand exception = MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value());
2105 __ Ldr(OutputRegister(instruction), exception);
2106 __ Str(wzr, exception);
2107}
2108
Alexandre Rames5319def2014-10-23 10:03:10 +01002109void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) {
2110 load->SetLocations(nullptr);
2111}
2112
2113void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) {
2114 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002115 UNUSED(load);
Alexandre Rames5319def2014-10-23 10:03:10 +01002116}
2117
Alexandre Rames67555f72014-11-18 10:55:16 +00002118void LocationsBuilderARM64::VisitLoadString(HLoadString* load) {
2119 LocationSummary* locations =
2120 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2121 locations->SetOut(Location::RequiresRegister());
2122}
2123
2124void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) {
2125 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load);
2126 codegen_->AddSlowPath(slow_path);
2127
2128 Register out = OutputRegister(load);
2129 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08002130 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2131 __ Ldr(out, HeapOperand(out, mirror::Class::DexCacheStringsOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002132 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002133 __ Cbz(out, slow_path->GetEntryLabel());
2134 __ Bind(slow_path->GetExitLabel());
2135}
2136
Alexandre Rames5319def2014-10-23 10:03:10 +01002137void LocationsBuilderARM64::VisitLocal(HLocal* local) {
2138 local->SetLocations(nullptr);
2139}
2140
2141void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) {
2142 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2143}
2144
2145void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) {
2146 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2147 locations->SetOut(Location::ConstantLocation(constant));
2148}
2149
2150void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) {
2151 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002152 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01002153}
2154
Alexandre Rames67555f72014-11-18 10:55:16 +00002155void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2156 LocationSummary* locations =
2157 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2158 InvokeRuntimeCallingConvention calling_convention;
2159 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2160}
2161
2162void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2163 codegen_->InvokeRuntime(instruction->IsEnter()
2164 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2165 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002166 instruction->GetDexPc(),
2167 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002168 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002169}
2170
Alexandre Rames42d641b2014-10-27 14:00:51 +00002171void LocationsBuilderARM64::VisitMul(HMul* mul) {
2172 LocationSummary* locations =
2173 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2174 switch (mul->GetResultType()) {
2175 case Primitive::kPrimInt:
2176 case Primitive::kPrimLong:
2177 locations->SetInAt(0, Location::RequiresRegister());
2178 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002179 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002180 break;
2181
2182 case Primitive::kPrimFloat:
2183 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002184 locations->SetInAt(0, Location::RequiresFpuRegister());
2185 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00002186 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002187 break;
2188
2189 default:
2190 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2191 }
2192}
2193
2194void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) {
2195 switch (mul->GetResultType()) {
2196 case Primitive::kPrimInt:
2197 case Primitive::kPrimLong:
2198 __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1));
2199 break;
2200
2201 case Primitive::kPrimFloat:
2202 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002203 __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1));
Alexandre Rames42d641b2014-10-27 14:00:51 +00002204 break;
2205
2206 default:
2207 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2208 }
2209}
2210
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002211void LocationsBuilderARM64::VisitNeg(HNeg* neg) {
2212 LocationSummary* locations =
2213 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2214 switch (neg->GetResultType()) {
2215 case Primitive::kPrimInt:
Alexandre Rames67555f72014-11-18 10:55:16 +00002216 case Primitive::kPrimLong:
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00002217 locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg));
Alexandre Rames67555f72014-11-18 10:55:16 +00002218 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002219 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002220
2221 case Primitive::kPrimFloat:
2222 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002223 locations->SetInAt(0, Location::RequiresFpuRegister());
2224 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002225 break;
2226
2227 default:
2228 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2229 }
2230}
2231
2232void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) {
2233 switch (neg->GetResultType()) {
2234 case Primitive::kPrimInt:
2235 case Primitive::kPrimLong:
2236 __ Neg(OutputRegister(neg), InputOperandAt(neg, 0));
2237 break;
2238
2239 case Primitive::kPrimFloat:
2240 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002241 __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002242 break;
2243
2244 default:
2245 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2246 }
2247}
2248
2249void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) {
2250 LocationSummary* locations =
2251 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2252 InvokeRuntimeCallingConvention calling_convention;
2253 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002254 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002255 locations->SetOut(LocationFrom(x0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002256 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1)));
2257 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2258 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002259}
2260
2261void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) {
2262 LocationSummary* locations = instruction->GetLocations();
2263 InvokeRuntimeCallingConvention calling_convention;
2264 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2265 DCHECK(type_index.Is(w0));
2266 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002267 DCHECK(current_method.Is(w2));
Alexandre Rames67555f72014-11-18 10:55:16 +00002268 codegen_->LoadCurrentMethod(current_method);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002269 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002270 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002271 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2272 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002273 instruction->GetDexPc(),
2274 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002275 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2276 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002277}
2278
Alexandre Rames5319def2014-10-23 10:03:10 +01002279void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) {
2280 LocationSummary* locations =
2281 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2282 InvokeRuntimeCallingConvention calling_convention;
2283 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
2284 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1)));
2285 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002286 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002287}
2288
2289void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
2290 LocationSummary* locations = instruction->GetLocations();
2291 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2292 DCHECK(type_index.Is(w0));
2293 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
2294 DCHECK(current_method.Is(w1));
Alexandre Rames67555f72014-11-18 10:55:16 +00002295 codegen_->LoadCurrentMethod(current_method);
Alexandre Rames5319def2014-10-23 10:03:10 +01002296 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002297 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002298 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2299 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002300 instruction->GetDexPc(),
2301 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002302 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002303}
2304
2305void LocationsBuilderARM64::VisitNot(HNot* instruction) {
2306 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexandre Rames4e596512014-11-07 15:56:50 +00002307 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002308 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01002309}
2310
2311void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) {
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002312 switch (instruction->GetResultType()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002313 case Primitive::kPrimInt:
Alexandre Rames5319def2014-10-23 10:03:10 +01002314 case Primitive::kPrimLong:
Roland Levillain55dcfb52014-10-24 18:09:09 +01002315 __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002316 break;
2317
2318 default:
2319 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2320 }
2321}
2322
David Brazdil66d126e2015-04-03 16:02:44 +01002323void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) {
2324 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2325 locations->SetInAt(0, Location::RequiresRegister());
2326 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2327}
2328
2329void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) {
David Brazdil66d126e2015-04-03 16:02:44 +01002330 __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1));
2331}
2332
Alexandre Rames5319def2014-10-23 10:03:10 +01002333void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) {
2334 LocationSummary* locations =
2335 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2336 locations->SetInAt(0, Location::RequiresRegister());
2337 if (instruction->HasUses()) {
2338 locations->SetOut(Location::SameAsFirstInput());
2339 }
2340}
2341
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002342void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002343 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2344 return;
2345 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002346
Alexandre Ramesd921d642015-04-16 15:07:16 +01002347 BlockPoolsScope block_pools(GetVIXLAssembler());
2348 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002349 __ Ldr(wzr, HeapOperandFrom(obj, Offset(0)));
2350 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2351}
2352
2353void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002354 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction);
2355 codegen_->AddSlowPath(slow_path);
2356
2357 LocationSummary* locations = instruction->GetLocations();
2358 Location obj = locations->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002359
2360 __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel());
Alexandre Rames5319def2014-10-23 10:03:10 +01002361}
2362
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002363void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) {
2364 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2365 GenerateImplicitNullCheck(instruction);
2366 } else {
2367 GenerateExplicitNullCheck(instruction);
2368 }
2369}
2370
Alexandre Rames67555f72014-11-18 10:55:16 +00002371void LocationsBuilderARM64::VisitOr(HOr* instruction) {
2372 HandleBinaryOp(instruction);
2373}
2374
2375void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) {
2376 HandleBinaryOp(instruction);
2377}
2378
Alexandre Rames3e69f162014-12-10 10:36:50 +00002379void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2380 LOG(FATAL) << "Unreachable";
2381}
2382
2383void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) {
2384 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2385}
2386
Alexandre Rames5319def2014-10-23 10:03:10 +01002387void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) {
2388 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2389 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2390 if (location.IsStackSlot()) {
2391 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2392 } else if (location.IsDoubleStackSlot()) {
2393 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2394 }
2395 locations->SetOut(location);
2396}
2397
2398void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) {
2399 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002400 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002401}
2402
2403void LocationsBuilderARM64::VisitPhi(HPhi* instruction) {
2404 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2405 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2406 locations->SetInAt(i, Location::Any());
2407 }
2408 locations->SetOut(Location::Any());
2409}
2410
2411void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002412 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002413 LOG(FATAL) << "Unreachable";
2414}
2415
Serban Constantinescu02164b32014-11-13 14:05:07 +00002416void LocationsBuilderARM64::VisitRem(HRem* rem) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002417 Primitive::Type type = rem->GetResultType();
Alexandre Rames542361f2015-01-29 16:57:31 +00002418 LocationSummary::CallKind call_kind =
2419 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002420 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2421
2422 switch (type) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002423 case Primitive::kPrimInt:
2424 case Primitive::kPrimLong:
2425 locations->SetInAt(0, Location::RequiresRegister());
2426 locations->SetInAt(1, Location::RequiresRegister());
2427 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2428 break;
2429
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002430 case Primitive::kPrimFloat:
2431 case Primitive::kPrimDouble: {
2432 InvokeRuntimeCallingConvention calling_convention;
2433 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
2434 locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1)));
2435 locations->SetOut(calling_convention.GetReturnLocation(type));
2436
2437 break;
2438 }
2439
Serban Constantinescu02164b32014-11-13 14:05:07 +00002440 default:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002441 LOG(FATAL) << "Unexpected rem type " << type;
Serban Constantinescu02164b32014-11-13 14:05:07 +00002442 }
2443}
2444
2445void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) {
2446 Primitive::Type type = rem->GetResultType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002447
Serban Constantinescu02164b32014-11-13 14:05:07 +00002448 switch (type) {
2449 case Primitive::kPrimInt:
2450 case Primitive::kPrimLong: {
2451 UseScratchRegisterScope temps(GetVIXLAssembler());
2452 Register dividend = InputRegisterAt(rem, 0);
2453 Register divisor = InputRegisterAt(rem, 1);
2454 Register output = OutputRegister(rem);
2455 Register temp = temps.AcquireSameSizeAs(output);
2456
2457 __ Sdiv(temp, dividend, divisor);
2458 __ Msub(output, temp, divisor, dividend);
2459 break;
2460 }
2461
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002462 case Primitive::kPrimFloat:
2463 case Primitive::kPrimDouble: {
2464 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
2465 : QUICK_ENTRY_POINT(pFmod);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002466 codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002467 break;
2468 }
2469
Serban Constantinescu02164b32014-11-13 14:05:07 +00002470 default:
2471 LOG(FATAL) << "Unexpected rem type " << type;
2472 }
2473}
2474
Calin Juravle27df7582015-04-17 19:12:31 +01002475void LocationsBuilderARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
2476 memory_barrier->SetLocations(nullptr);
2477}
2478
2479void InstructionCodeGeneratorARM64::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
2480 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
2481}
2482
Alexandre Rames5319def2014-10-23 10:03:10 +01002483void LocationsBuilderARM64::VisitReturn(HReturn* instruction) {
2484 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2485 Primitive::Type return_type = instruction->InputAt(0)->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002486 locations->SetInAt(0, ARM64ReturnLocation(return_type));
Alexandre Rames5319def2014-10-23 10:03:10 +01002487}
2488
2489void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002490 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002491 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002492}
2493
2494void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) {
2495 instruction->SetLocations(nullptr);
2496}
2497
2498void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002499 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002500 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002501}
2502
Serban Constantinescu02164b32014-11-13 14:05:07 +00002503void LocationsBuilderARM64::VisitShl(HShl* shl) {
2504 HandleShift(shl);
2505}
2506
2507void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) {
2508 HandleShift(shl);
2509}
2510
2511void LocationsBuilderARM64::VisitShr(HShr* shr) {
2512 HandleShift(shr);
2513}
2514
2515void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) {
2516 HandleShift(shr);
2517}
2518
Alexandre Rames5319def2014-10-23 10:03:10 +01002519void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) {
2520 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
2521 Primitive::Type field_type = store->InputAt(1)->GetType();
2522 switch (field_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002523 case Primitive::kPrimNot:
Alexandre Rames5319def2014-10-23 10:03:10 +01002524 case Primitive::kPrimBoolean:
2525 case Primitive::kPrimByte:
2526 case Primitive::kPrimChar:
2527 case Primitive::kPrimShort:
2528 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002529 case Primitive::kPrimFloat:
Alexandre Rames5319def2014-10-23 10:03:10 +01002530 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
2531 break;
2532
2533 case Primitive::kPrimLong:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002534 case Primitive::kPrimDouble:
Alexandre Rames5319def2014-10-23 10:03:10 +01002535 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
2536 break;
2537
2538 default:
2539 LOG(FATAL) << "Unimplemented local type " << field_type;
2540 }
2541}
2542
2543void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002544 UNUSED(store);
Alexandre Rames5319def2014-10-23 10:03:10 +01002545}
2546
2547void LocationsBuilderARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002548 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002549}
2550
2551void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002552 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002553}
2554
Alexandre Rames67555f72014-11-18 10:55:16 +00002555void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002556 HandleFieldGet(instruction);
Alexandre Rames67555f72014-11-18 10:55:16 +00002557}
2558
2559void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002560 HandleFieldGet(instruction, instruction->GetFieldInfo());
Alexandre Rames67555f72014-11-18 10:55:16 +00002561}
2562
2563void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002564 HandleFieldSet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002565}
2566
Alexandre Rames67555f72014-11-18 10:55:16 +00002567void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002568 HandleFieldSet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01002569}
2570
2571void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
2572 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2573}
2574
2575void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002576 HBasicBlock* block = instruction->GetBlock();
2577 if (block->GetLoopInformation() != nullptr) {
2578 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2579 // The back edge will generate the suspend check.
2580 return;
2581 }
2582 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2583 // The goto will generate the suspend check.
2584 return;
2585 }
2586 GenerateSuspendCheck(instruction, nullptr);
Alexandre Rames5319def2014-10-23 10:03:10 +01002587}
2588
2589void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) {
2590 temp->SetLocations(nullptr);
2591}
2592
2593void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) {
2594 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002595 UNUSED(temp);
Alexandre Rames5319def2014-10-23 10:03:10 +01002596}
2597
Alexandre Rames67555f72014-11-18 10:55:16 +00002598void LocationsBuilderARM64::VisitThrow(HThrow* instruction) {
2599 LocationSummary* locations =
2600 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2601 InvokeRuntimeCallingConvention calling_convention;
2602 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2603}
2604
2605void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) {
2606 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002607 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002608 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002609}
2610
2611void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) {
2612 LocationSummary* locations =
2613 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
2614 Primitive::Type input_type = conversion->GetInputType();
2615 Primitive::Type result_type = conversion->GetResultType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002616 DCHECK_NE(input_type, result_type);
Alexandre Rames67555f72014-11-18 10:55:16 +00002617 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
2618 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
2619 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
2620 }
2621
Alexandre Rames542361f2015-01-29 16:57:31 +00002622 if (Primitive::IsFloatingPointType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002623 locations->SetInAt(0, Location::RequiresFpuRegister());
2624 } else {
2625 locations->SetInAt(0, Location::RequiresRegister());
2626 }
2627
Alexandre Rames542361f2015-01-29 16:57:31 +00002628 if (Primitive::IsFloatingPointType(result_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002629 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2630 } else {
2631 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2632 }
2633}
2634
2635void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) {
2636 Primitive::Type result_type = conversion->GetResultType();
2637 Primitive::Type input_type = conversion->GetInputType();
2638
2639 DCHECK_NE(input_type, result_type);
2640
Alexandre Rames542361f2015-01-29 16:57:31 +00002641 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002642 int result_size = Primitive::ComponentSize(result_type);
2643 int input_size = Primitive::ComponentSize(input_type);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002644 int min_size = std::min(result_size, input_size);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002645 Register output = OutputRegister(conversion);
2646 Register source = InputRegisterAt(conversion, 0);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002647 if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) {
2648 __ Ubfx(output, source, 0, result_size * kBitsPerByte);
2649 } else if ((result_type == Primitive::kPrimChar) ||
2650 ((input_type == Primitive::kPrimChar) && (result_size > input_size))) {
2651 __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002652 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00002653 __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002654 }
Alexandre Rames542361f2015-01-29 16:57:31 +00002655 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002656 __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002657 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002658 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
2659 __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002660 } else if (Primitive::IsFloatingPointType(result_type) &&
2661 Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002662 __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0));
2663 } else {
2664 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
2665 << " to " << result_type;
Alexandre Rames67555f72014-11-18 10:55:16 +00002666 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00002667}
Alexandre Rames67555f72014-11-18 10:55:16 +00002668
Serban Constantinescu02164b32014-11-13 14:05:07 +00002669void LocationsBuilderARM64::VisitUShr(HUShr* ushr) {
2670 HandleShift(ushr);
2671}
2672
2673void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) {
2674 HandleShift(ushr);
Alexandre Rames67555f72014-11-18 10:55:16 +00002675}
2676
2677void LocationsBuilderARM64::VisitXor(HXor* instruction) {
2678 HandleBinaryOp(instruction);
2679}
2680
2681void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) {
2682 HandleBinaryOp(instruction);
2683}
2684
Calin Juravleb1498f62015-02-16 13:13:29 +00002685void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction) {
2686 // Nothing to do, this should be removed during prepare for register allocator.
2687 UNUSED(instruction);
2688 LOG(FATAL) << "Unreachable";
2689}
2690
2691void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction) {
2692 // Nothing to do, this should be removed during prepare for register allocator.
2693 UNUSED(instruction);
2694 LOG(FATAL) << "Unreachable";
2695}
2696
Alexandre Rames67555f72014-11-18 10:55:16 +00002697#undef __
2698#undef QUICK_ENTRY_POINT
2699
Alexandre Rames5319def2014-10-23 10:03:10 +01002700} // namespace arm64
2701} // namespace art