blob: 38a463e3e8f533f727188cafaa5aa7e24d2bef0a [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());
176 arm64_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1).W());
177 int32_t entry_point_offset = do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
178 : QUICK_ENTRY_POINT(pInitializeType);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000179 arm64_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800180 if (do_clinit_) {
181 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t, mirror::ArtMethod*>();
182 } else {
183 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t, mirror::ArtMethod*>();
184 }
Alexandre Rames67555f72014-11-18 10:55:16 +0000185
186 // Move the class to the desired location.
187 Location out = locations->Out();
188 if (out.IsValid()) {
189 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
190 Primitive::Type type = at_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000191 arm64_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000192 }
193
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000194 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000195 __ B(GetExitLabel());
196 }
197
198 private:
199 // The class this slow path will load.
200 HLoadClass* const cls_;
201
202 // The instruction where this slow path is happening.
203 // (Might be the load class or an initialization check).
204 HInstruction* const at_;
205
206 // The dex PC of `at_`.
207 const uint32_t dex_pc_;
208
209 // Whether to initialize the class.
210 const bool do_clinit_;
211
212 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM64);
213};
214
215class LoadStringSlowPathARM64 : public SlowPathCodeARM64 {
216 public:
217 explicit LoadStringSlowPathARM64(HLoadString* instruction) : instruction_(instruction) {}
218
219 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
220 LocationSummary* locations = instruction_->GetLocations();
221 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
222 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
223
224 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000225 SaveLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000226
227 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800228 arm64_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1).W());
229 __ Mov(calling_convention.GetRegisterAt(0).W(), instruction_->GetStringIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +0000230 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000231 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800232 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames67555f72014-11-18 10:55:16 +0000233 Primitive::Type type = instruction_->GetType();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000234 arm64_codegen->MoveLocation(locations->Out(), calling_convention.GetReturnLocation(type), type);
Alexandre Rames67555f72014-11-18 10:55:16 +0000235
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000236 RestoreLiveRegisters(codegen, locations);
Alexandre Rames67555f72014-11-18 10:55:16 +0000237 __ B(GetExitLabel());
238 }
239
240 private:
241 HLoadString* const instruction_;
242
243 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM64);
244};
245
Alexandre Rames5319def2014-10-23 10:03:10 +0100246class NullCheckSlowPathARM64 : public SlowPathCodeARM64 {
247 public:
248 explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {}
249
Alexandre Rames67555f72014-11-18 10:55:16 +0000250 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
251 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100252 __ Bind(GetEntryLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000253 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000254 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800255 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
Alexandre Rames5319def2014-10-23 10:03:10 +0100256 }
257
258 private:
259 HNullCheck* const instruction_;
260
261 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64);
262};
263
264class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 {
265 public:
266 explicit SuspendCheckSlowPathARM64(HSuspendCheck* instruction,
267 HBasicBlock* successor)
268 : instruction_(instruction), successor_(successor) {}
269
Alexandre Rames67555f72014-11-18 10:55:16 +0000270 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
271 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
Alexandre Rames5319def2014-10-23 10:03:10 +0100272 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000273 SaveLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000274 arm64_codegen->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000275 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc(), this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800276 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000277 RestoreLiveRegisters(codegen, instruction_->GetLocations());
Alexandre Rames67555f72014-11-18 10:55:16 +0000278 if (successor_ == nullptr) {
279 __ B(GetReturnLabel());
280 } else {
281 __ B(arm64_codegen->GetLabelOf(successor_));
282 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100283 }
284
285 vixl::Label* GetReturnLabel() {
286 DCHECK(successor_ == nullptr);
287 return &return_label_;
288 }
289
Alexandre Rames5319def2014-10-23 10:03:10 +0100290 private:
291 HSuspendCheck* const instruction_;
292 // If not null, the block to branch to after the suspend check.
293 HBasicBlock* const successor_;
294
295 // If `successor_` is null, the label to branch to after the suspend check.
296 vixl::Label return_label_;
297
298 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64);
299};
300
Alexandre Rames67555f72014-11-18 10:55:16 +0000301class TypeCheckSlowPathARM64 : public SlowPathCodeARM64 {
302 public:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000303 TypeCheckSlowPathARM64(HInstruction* instruction,
304 Location class_to_check,
305 Location object_class,
306 uint32_t dex_pc)
307 : instruction_(instruction),
308 class_to_check_(class_to_check),
309 object_class_(object_class),
310 dex_pc_(dex_pc) {}
Alexandre Rames67555f72014-11-18 10:55:16 +0000311
312 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000313 LocationSummary* locations = instruction_->GetLocations();
314 DCHECK(instruction_->IsCheckCast()
315 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
316 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
317
Alexandre Rames67555f72014-11-18 10:55:16 +0000318 __ Bind(GetEntryLabel());
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000319 SaveLiveRegisters(codegen, locations);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000320
321 // We're moving two locations to locations that could overlap, so we need a parallel
322 // move resolver.
323 InvokeRuntimeCallingConvention calling_convention;
324 codegen->EmitParallelMoves(
Nicolas Geoffray90218252015-04-15 11:56:51 +0100325 class_to_check_, LocationFrom(calling_convention.GetRegisterAt(0)), Primitive::kPrimNot,
326 object_class_, LocationFrom(calling_convention.GetRegisterAt(1)), Primitive::kPrimNot);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000327
328 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000329 arm64_codegen->InvokeRuntime(
330 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000331 Primitive::Type ret_type = instruction_->GetType();
332 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
333 arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800334 CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t,
335 const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000336 } else {
337 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000338 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800339 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000340 }
341
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000342 RestoreLiveRegisters(codegen, locations);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000343 __ B(GetExitLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000344 }
345
346 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000347 HInstruction* const instruction_;
348 const Location class_to_check_;
349 const Location object_class_;
350 uint32_t dex_pc_;
351
Alexandre Rames67555f72014-11-18 10:55:16 +0000352 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64);
353};
354
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700355class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 {
356 public:
357 explicit DeoptimizationSlowPathARM64(HInstruction* instruction)
358 : instruction_(instruction) {}
359
360 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
361 __ Bind(GetEntryLabel());
362 SaveLiveRegisters(codegen, instruction_->GetLocations());
363 DCHECK(instruction_->IsDeoptimize());
364 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
365 uint32_t dex_pc = deoptimize->GetDexPc();
366 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
367 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
368 }
369
370 private:
371 HInstruction* const instruction_;
372 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64);
373};
374
Alexandre Rames5319def2014-10-23 10:03:10 +0100375#undef __
376
377Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
378 Location next_location;
379 if (type == Primitive::kPrimVoid) {
380 LOG(FATAL) << "Unreachable type " << type;
381 }
382
Alexandre Rames542361f2015-01-29 16:57:31 +0000383 if (Primitive::IsFloatingPointType(type) &&
384 (fp_index_ < calling_convention.GetNumberOfFpuRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000385 next_location = LocationFrom(calling_convention.GetFpuRegisterAt(fp_index_++));
Alexandre Rames542361f2015-01-29 16:57:31 +0000386 } else if (!Primitive::IsFloatingPointType(type) &&
387 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000388 next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++));
389 } else {
390 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Alexandre Rames542361f2015-01-29 16:57:31 +0000391 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
392 : Location::StackSlot(stack_offset);
Alexandre Rames5319def2014-10-23 10:03:10 +0100393 }
394
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000395 // Space on the stack is reserved for all arguments.
Alexandre Rames542361f2015-01-29 16:57:31 +0000396 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
Alexandre Rames5319def2014-10-23 10:03:10 +0100397 return next_location;
398}
399
Serban Constantinescu579885a2015-02-22 20:51:33 +0000400CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph,
401 const Arm64InstructionSetFeatures& isa_features,
402 const CompilerOptions& compiler_options)
Alexandre Rames5319def2014-10-23 10:03:10 +0100403 : CodeGenerator(graph,
404 kNumberOfAllocatableRegisters,
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000405 kNumberOfAllocatableFPRegisters,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000406 kNumberOfAllocatableRegisterPairs,
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000407 callee_saved_core_registers.list(),
408 callee_saved_fp_registers.list(),
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000409 compiler_options),
Alexandre Rames5319def2014-10-23 10:03:10 +0100410 block_labels_(nullptr),
411 location_builder_(graph, this),
Alexandre Rames3e69f162014-12-10 10:36:50 +0000412 instruction_visitor_(graph, this),
Serban Constantinescu579885a2015-02-22 20:51:33 +0000413 move_resolver_(graph->GetArena(), this),
414 isa_features_(isa_features) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000415 // Save the link register (containing the return address) to mimic Quick.
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000416 AddAllocatedRegister(LocationFrom(lr));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000417}
Alexandre Rames5319def2014-10-23 10:03:10 +0100418
Alexandre Rames67555f72014-11-18 10:55:16 +0000419#undef __
420#define __ GetVIXLAssembler()->
Alexandre Rames5319def2014-10-23 10:03:10 +0100421
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000422void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) {
423 // Ensure we emit the literal pool.
424 __ FinalizeCode();
425 CodeGenerator::Finalize(allocator);
426}
427
Alexandre Rames3e69f162014-12-10 10:36:50 +0000428void ParallelMoveResolverARM64::EmitMove(size_t index) {
429 MoveOperands* move = moves_.Get(index);
430 codegen_->MoveLocation(move->GetDestination(), move->GetSource());
431}
432
433void ParallelMoveResolverARM64::EmitSwap(size_t index) {
434 MoveOperands* move = moves_.Get(index);
435 codegen_->SwapLocations(move->GetDestination(), move->GetSource());
436}
437
438void ParallelMoveResolverARM64::RestoreScratch(int reg) {
439 __ Pop(Register(VIXLRegCodeFromART(reg), kXRegSize));
440}
441
442void ParallelMoveResolverARM64::SpillScratch(int reg) {
443 __ Push(Register(VIXLRegCodeFromART(reg), kXRegSize));
444}
445
Alexandre Rames5319def2014-10-23 10:03:10 +0100446void CodeGeneratorARM64::GenerateFrameEntry() {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100447 MacroAssembler* masm = GetVIXLAssembler();
448 BlockPoolsScope block_pools(masm);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000449 __ Bind(&frame_entry_label_);
450
Serban Constantinescu02164b32014-11-13 14:05:07 +0000451 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod();
452 if (do_overflow_check) {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100453 UseScratchRegisterScope temps(masm);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000454 Register temp = temps.AcquireX();
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000455 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000456 __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64)));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000457 __ Ldr(wzr, MemOperand(temp, 0));
458 RecordPcInfo(nullptr, 0);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000459 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100460
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000461 if (!HasEmptyFrame()) {
462 int frame_size = GetFrameSize();
463 // Stack layout:
464 // sp[frame_size - 8] : lr.
465 // ... : other preserved core registers.
466 // ... : other preserved fp registers.
467 // ... : reserved frame space.
468 // sp[0] : current method.
469 __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100470 GetAssembler()->cfi().AdjustCFAOffset(frame_size);
Zheng Xu69a50302015-04-14 20:04:41 +0800471 GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(),
472 frame_size - GetCoreSpillSize());
473 GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(),
474 frame_size - FrameEntrySpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000475 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100476}
477
478void CodeGeneratorARM64::GenerateFrameExit() {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100479 BlockPoolsScope block_pools(GetVIXLAssembler());
David Srbeckyc34dc932015-04-12 09:27:43 +0100480 GetAssembler()->cfi().RememberState();
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000481 if (!HasEmptyFrame()) {
482 int frame_size = GetFrameSize();
Zheng Xu69a50302015-04-14 20:04:41 +0800483 GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(),
484 frame_size - FrameEntrySpillSize());
485 GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(),
486 frame_size - GetCoreSpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000487 __ Drop(frame_size);
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100488 GetAssembler()->cfi().AdjustCFAOffset(-frame_size);
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000489 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100490 __ Ret();
491 GetAssembler()->cfi().RestoreState();
492 GetAssembler()->cfi().DefCFAOffset(GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +0100493}
494
495void CodeGeneratorARM64::Bind(HBasicBlock* block) {
496 __ Bind(GetLabelOf(block));
497}
498
Alexandre Rames5319def2014-10-23 10:03:10 +0100499void CodeGeneratorARM64::Move(HInstruction* instruction,
500 Location location,
501 HInstruction* move_for) {
502 LocationSummary* locations = instruction->GetLocations();
503 if (locations != nullptr && locations->Out().Equals(location)) {
504 return;
505 }
506
507 Primitive::Type type = instruction->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000508 DCHECK_NE(type, Primitive::kPrimVoid);
Alexandre Rames5319def2014-10-23 10:03:10 +0100509
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000510 if (instruction->IsIntConstant()
511 || instruction->IsLongConstant()
512 || instruction->IsNullConstant()) {
513 int64_t value = GetInt64ValueOf(instruction->AsConstant());
Alexandre Rames5319def2014-10-23 10:03:10 +0100514 if (location.IsRegister()) {
515 Register dst = RegisterFrom(location, type);
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000516 DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) ||
Alexandre Rames5319def2014-10-23 10:03:10 +0100517 (instruction->IsLongConstant() && dst.Is64Bits()));
518 __ Mov(dst, value);
519 } else {
520 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000521 UseScratchRegisterScope temps(GetVIXLAssembler());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000522 Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant())
523 ? temps.AcquireW()
524 : temps.AcquireX();
Alexandre Rames5319def2014-10-23 10:03:10 +0100525 __ Mov(temp, value);
526 __ Str(temp, StackOperandFrom(location));
527 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000528 } else if (instruction->IsTemporary()) {
529 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000530 MoveLocation(location, temp_location, type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100531 } else if (instruction->IsLoadLocal()) {
532 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
Alexandre Rames542361f2015-01-29 16:57:31 +0000533 if (Primitive::Is64BitType(type)) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000534 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000535 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000536 MoveLocation(location, Location::StackSlot(stack_slot), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100537 }
538
539 } else {
540 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000541 MoveLocation(location, locations->Out(), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100542 }
543}
544
Alexandre Rames5319def2014-10-23 10:03:10 +0100545Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const {
546 Primitive::Type type = load->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000547
Alexandre Rames5319def2014-10-23 10:03:10 +0100548 switch (type) {
549 case Primitive::kPrimNot:
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000550 case Primitive::kPrimInt:
551 case Primitive::kPrimFloat:
552 return Location::StackSlot(GetStackSlot(load->GetLocal()));
553
554 case Primitive::kPrimLong:
555 case Primitive::kPrimDouble:
556 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
557
Alexandre Rames5319def2014-10-23 10:03:10 +0100558 case Primitive::kPrimBoolean:
559 case Primitive::kPrimByte:
560 case Primitive::kPrimChar:
561 case Primitive::kPrimShort:
Alexandre Rames5319def2014-10-23 10:03:10 +0100562 case Primitive::kPrimVoid:
Alexandre Rames5319def2014-10-23 10:03:10 +0100563 LOG(FATAL) << "Unexpected type " << type;
564 }
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000565
Alexandre Rames5319def2014-10-23 10:03:10 +0100566 LOG(FATAL) << "Unreachable";
567 return Location::NoLocation();
568}
569
570void CodeGeneratorARM64::MarkGCCard(Register object, Register value) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000571 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +0100572 Register card = temps.AcquireX();
Serban Constantinescu02164b32014-11-13 14:05:07 +0000573 Register temp = temps.AcquireW(); // Index within the CardTable - 32bit.
Alexandre Rames5319def2014-10-23 10:03:10 +0100574 vixl::Label done;
575 __ Cbz(value, &done);
576 __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value()));
577 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000578 __ Strb(card, MemOperand(card, temp.X()));
Alexandre Rames5319def2014-10-23 10:03:10 +0100579 __ Bind(&done);
580}
581
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000582void CodeGeneratorARM64::SetupBlockedRegisters(bool is_baseline) const {
583 // Blocked core registers:
584 // lr : Runtime reserved.
585 // tr : Runtime reserved.
586 // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it.
587 // ip1 : VIXL core temp.
588 // ip0 : VIXL core temp.
589 //
590 // Blocked fp registers:
591 // d31 : VIXL fp temp.
Alexandre Rames5319def2014-10-23 10:03:10 +0100592 CPURegList reserved_core_registers = vixl_reserved_core_registers;
593 reserved_core_registers.Combine(runtime_reserved_core_registers);
Alexandre Rames5319def2014-10-23 10:03:10 +0100594 while (!reserved_core_registers.IsEmpty()) {
595 blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true;
596 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000597
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000598 CPURegList reserved_fp_registers = vixl_reserved_fp_registers;
Zheng Xua3ec3942015-02-15 18:39:46 +0800599 while (!reserved_fp_registers.IsEmpty()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000600 blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true;
601 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000602
603 if (is_baseline) {
604 CPURegList reserved_core_baseline_registers = callee_saved_core_registers;
605 while (!reserved_core_baseline_registers.IsEmpty()) {
606 blocked_core_registers_[reserved_core_baseline_registers.PopLowestIndex().code()] = true;
607 }
608
609 CPURegList reserved_fp_baseline_registers = callee_saved_fp_registers;
610 while (!reserved_fp_baseline_registers.IsEmpty()) {
611 blocked_fpu_registers_[reserved_fp_baseline_registers.PopLowestIndex().code()] = true;
612 }
613 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100614}
615
616Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const {
617 if (type == Primitive::kPrimVoid) {
618 LOG(FATAL) << "Unreachable type " << type;
619 }
620
Alexandre Rames542361f2015-01-29 16:57:31 +0000621 if (Primitive::IsFloatingPointType(type)) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000622 ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters);
623 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100624 return Location::FpuRegisterLocation(reg);
625 } else {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000626 ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters);
627 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100628 return Location::RegisterLocation(reg);
629 }
630}
631
Alexandre Rames3e69f162014-12-10 10:36:50 +0000632size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
633 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
634 __ Str(reg, MemOperand(sp, stack_index));
635 return kArm64WordSize;
636}
637
638size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
639 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
640 __ Ldr(reg, MemOperand(sp, stack_index));
641 return kArm64WordSize;
642}
643
644size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
645 FPRegister reg = FPRegister(reg_id, kDRegSize);
646 __ Str(reg, MemOperand(sp, stack_index));
647 return kArm64WordSize;
648}
649
650size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
651 FPRegister reg = FPRegister(reg_id, kDRegSize);
652 __ Ldr(reg, MemOperand(sp, stack_index));
653 return kArm64WordSize;
654}
655
Alexandre Rames5319def2014-10-23 10:03:10 +0100656void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const {
657 stream << Arm64ManagedRegister::FromXRegister(XRegister(reg));
658}
659
660void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
661 stream << Arm64ManagedRegister::FromDRegister(DRegister(reg));
662}
663
Alexandre Rames67555f72014-11-18 10:55:16 +0000664void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000665 if (constant->IsIntConstant()) {
666 __ Mov(Register(destination), constant->AsIntConstant()->GetValue());
667 } else if (constant->IsLongConstant()) {
668 __ Mov(Register(destination), constant->AsLongConstant()->GetValue());
669 } else if (constant->IsNullConstant()) {
670 __ Mov(Register(destination), 0);
Alexandre Rames67555f72014-11-18 10:55:16 +0000671 } else if (constant->IsFloatConstant()) {
672 __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue());
673 } else {
674 DCHECK(constant->IsDoubleConstant());
675 __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue());
676 }
677}
678
Alexandre Rames3e69f162014-12-10 10:36:50 +0000679
680static bool CoherentConstantAndType(Location constant, Primitive::Type type) {
681 DCHECK(constant.IsConstant());
682 HConstant* cst = constant.GetConstant();
683 return (cst->IsIntConstant() && type == Primitive::kPrimInt) ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000684 // Null is mapped to a core W register, which we associate with kPrimInt.
685 (cst->IsNullConstant() && type == Primitive::kPrimInt) ||
Alexandre Rames3e69f162014-12-10 10:36:50 +0000686 (cst->IsLongConstant() && type == Primitive::kPrimLong) ||
687 (cst->IsFloatConstant() && type == Primitive::kPrimFloat) ||
688 (cst->IsDoubleConstant() && type == Primitive::kPrimDouble);
689}
690
691void CodeGeneratorARM64::MoveLocation(Location destination, Location source, Primitive::Type type) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000692 if (source.Equals(destination)) {
693 return;
694 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000695
696 // A valid move can always be inferred from the destination and source
697 // locations. When moving from and to a register, the argument type can be
698 // used to generate 32bit instead of 64bit moves. In debug mode we also
699 // checks the coherency of the locations and the type.
700 bool unspecified_type = (type == Primitive::kPrimVoid);
701
702 if (destination.IsRegister() || destination.IsFpuRegister()) {
703 if (unspecified_type) {
704 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
705 if (source.IsStackSlot() ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000706 (src_cst != nullptr && (src_cst->IsIntConstant()
707 || src_cst->IsFloatConstant()
708 || src_cst->IsNullConstant()))) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000709 // For stack slots and 32bit constants, a 64bit type is appropriate.
710 type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexandre Rames67555f72014-11-18 10:55:16 +0000711 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000712 // If the source is a double stack slot or a 64bit constant, a 64bit
713 // type is appropriate. Else the source is a register, and since the
714 // type has not been specified, we chose a 64bit type to force a 64bit
715 // move.
716 type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexandre Rames67555f72014-11-18 10:55:16 +0000717 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000718 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000719 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) ||
720 (destination.IsRegister() && !Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000721 CPURegister dst = CPURegisterFrom(destination, type);
722 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
723 DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot());
724 __ Ldr(dst, StackOperandFrom(source));
725 } else if (source.IsConstant()) {
726 DCHECK(CoherentConstantAndType(source, type));
727 MoveConstant(dst, source.GetConstant());
728 } else {
729 if (destination.IsRegister()) {
730 __ Mov(Register(dst), RegisterFrom(source, type));
731 } else {
732 __ Fmov(FPRegister(dst), FPRegisterFrom(source, type));
733 }
734 }
735
736 } else { // The destination is not a register. It must be a stack slot.
737 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
738 if (source.IsRegister() || source.IsFpuRegister()) {
739 if (unspecified_type) {
740 if (source.IsRegister()) {
741 type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
742 } else {
743 type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
744 }
745 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000746 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) &&
747 (source.IsFpuRegister() == Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000748 __ Str(CPURegisterFrom(source, type), StackOperandFrom(destination));
749 } else if (source.IsConstant()) {
750 DCHECK(unspecified_type || CoherentConstantAndType(source, type));
751 UseScratchRegisterScope temps(GetVIXLAssembler());
752 HConstant* src_cst = source.GetConstant();
753 CPURegister temp;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000754 if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000755 temp = temps.AcquireW();
756 } else if (src_cst->IsLongConstant()) {
757 temp = temps.AcquireX();
758 } else if (src_cst->IsFloatConstant()) {
759 temp = temps.AcquireS();
760 } else {
761 DCHECK(src_cst->IsDoubleConstant());
762 temp = temps.AcquireD();
763 }
764 MoveConstant(temp, src_cst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000765 __ Str(temp, StackOperandFrom(destination));
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000766 } else {
Alexandre Rames67555f72014-11-18 10:55:16 +0000767 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000768 DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000769 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000770 // There is generally less pressure on FP registers.
771 FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS();
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000772 __ Ldr(temp, StackOperandFrom(source));
773 __ Str(temp, StackOperandFrom(destination));
774 }
775 }
776}
777
Alexandre Rames3e69f162014-12-10 10:36:50 +0000778void CodeGeneratorARM64::SwapLocations(Location loc1, Location loc2) {
779 DCHECK(!loc1.IsConstant());
780 DCHECK(!loc2.IsConstant());
781
782 if (loc1.Equals(loc2)) {
783 return;
784 }
785
786 UseScratchRegisterScope temps(GetAssembler()->vixl_masm_);
787
788 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
789 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
790 bool is_fp_reg1 = loc1.IsFpuRegister();
791 bool is_fp_reg2 = loc2.IsFpuRegister();
792
793 if (loc2.IsRegister() && loc1.IsRegister()) {
794 Register r1 = XRegisterFrom(loc1);
795 Register r2 = XRegisterFrom(loc2);
796 Register tmp = temps.AcquireSameSizeAs(r1);
797 __ Mov(tmp, r2);
798 __ Mov(r2, r1);
799 __ Mov(r1, tmp);
800 } else if (is_fp_reg2 && is_fp_reg1) {
801 FPRegister r1 = DRegisterFrom(loc1);
802 FPRegister r2 = DRegisterFrom(loc2);
803 FPRegister tmp = temps.AcquireSameSizeAs(r1);
804 __ Fmov(tmp, r2);
805 __ Fmov(r2, r1);
806 __ Fmov(r1, tmp);
807 } else if (is_slot1 != is_slot2) {
808 MemOperand mem = StackOperandFrom(is_slot1 ? loc1 : loc2);
809 Location reg_loc = is_slot1 ? loc2 : loc1;
810 CPURegister reg, tmp;
811 if (reg_loc.IsFpuRegister()) {
812 reg = DRegisterFrom(reg_loc);
813 tmp = temps.AcquireD();
814 } else {
815 reg = XRegisterFrom(reg_loc);
816 tmp = temps.AcquireX();
817 }
818 __ Ldr(tmp, mem);
819 __ Str(reg, mem);
820 if (reg_loc.IsFpuRegister()) {
821 __ Fmov(FPRegister(reg), FPRegister(tmp));
822 } else {
823 __ Mov(Register(reg), Register(tmp));
824 }
825 } else if (is_slot1 && is_slot2) {
826 MemOperand mem1 = StackOperandFrom(loc1);
827 MemOperand mem2 = StackOperandFrom(loc2);
828 Register tmp1 = loc1.IsStackSlot() ? temps.AcquireW() : temps.AcquireX();
829 Register tmp2 = temps.AcquireSameSizeAs(tmp1);
830 __ Ldr(tmp1, mem1);
831 __ Ldr(tmp2, mem2);
832 __ Str(tmp1, mem2);
833 __ Str(tmp2, mem1);
834 } else {
835 LOG(FATAL) << "Unimplemented";
836 }
837}
838
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000839void CodeGeneratorARM64::Load(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000840 CPURegister dst,
841 const MemOperand& src) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000842 switch (type) {
843 case Primitive::kPrimBoolean:
Alexandre Rames67555f72014-11-18 10:55:16 +0000844 __ Ldrb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000845 break;
846 case Primitive::kPrimByte:
Alexandre Rames67555f72014-11-18 10:55:16 +0000847 __ Ldrsb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000848 break;
849 case Primitive::kPrimShort:
Alexandre Rames67555f72014-11-18 10:55:16 +0000850 __ Ldrsh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000851 break;
852 case Primitive::kPrimChar:
Alexandre Rames67555f72014-11-18 10:55:16 +0000853 __ Ldrh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000854 break;
855 case Primitive::kPrimInt:
856 case Primitive::kPrimNot:
857 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000858 case Primitive::kPrimFloat:
859 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000860 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Alexandre Rames67555f72014-11-18 10:55:16 +0000861 __ Ldr(dst, src);
862 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000863 case Primitive::kPrimVoid:
864 LOG(FATAL) << "Unreachable type " << type;
865 }
866}
867
Calin Juravle77520bc2015-01-12 18:45:46 +0000868void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000869 CPURegister dst,
870 const MemOperand& src) {
Alexandre Ramesd921d642015-04-16 15:07:16 +0100871 MacroAssembler* masm = GetVIXLAssembler();
872 BlockPoolsScope block_pools(masm);
873 UseScratchRegisterScope temps(masm);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000874 Register temp_base = temps.AcquireX();
Calin Juravle77520bc2015-01-12 18:45:46 +0000875 Primitive::Type type = instruction->GetType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000876
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000877 DCHECK(!src.IsPreIndex());
878 DCHECK(!src.IsPostIndex());
879
880 // TODO(vixl): Let the MacroAssembler handle MemOperand.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800881 __ Add(temp_base, src.base(), OperandFromMemOperand(src));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000882 MemOperand base = MemOperand(temp_base);
883 switch (type) {
884 case Primitive::kPrimBoolean:
885 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000886 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000887 break;
888 case Primitive::kPrimByte:
889 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000890 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000891 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
892 break;
893 case Primitive::kPrimChar:
894 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000895 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000896 break;
897 case Primitive::kPrimShort:
898 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000899 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000900 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
901 break;
902 case Primitive::kPrimInt:
903 case Primitive::kPrimNot:
904 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000905 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000906 __ Ldar(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000907 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000908 break;
909 case Primitive::kPrimFloat:
910 case Primitive::kPrimDouble: {
911 DCHECK(dst.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000912 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000913
914 Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
915 __ Ldar(temp, base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000916 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000917 __ Fmov(FPRegister(dst), temp);
918 break;
919 }
920 case Primitive::kPrimVoid:
921 LOG(FATAL) << "Unreachable type " << type;
922 }
923}
924
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000925void CodeGeneratorARM64::Store(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000926 CPURegister src,
927 const MemOperand& dst) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000928 switch (type) {
929 case Primitive::kPrimBoolean:
930 case Primitive::kPrimByte:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000931 __ Strb(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000932 break;
933 case Primitive::kPrimChar:
934 case Primitive::kPrimShort:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000935 __ Strh(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000936 break;
937 case Primitive::kPrimInt:
938 case Primitive::kPrimNot:
939 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000940 case Primitive::kPrimFloat:
941 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000942 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000943 __ Str(src, dst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000944 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000945 case Primitive::kPrimVoid:
946 LOG(FATAL) << "Unreachable type " << type;
947 }
948}
949
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000950void CodeGeneratorARM64::StoreRelease(Primitive::Type type,
951 CPURegister src,
952 const MemOperand& dst) {
953 UseScratchRegisterScope temps(GetVIXLAssembler());
954 Register temp_base = temps.AcquireX();
955
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000956 DCHECK(!dst.IsPreIndex());
957 DCHECK(!dst.IsPostIndex());
958
959 // TODO(vixl): Let the MacroAssembler handle this.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800960 Operand op = OperandFromMemOperand(dst);
961 __ Add(temp_base, dst.base(), op);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000962 MemOperand base = MemOperand(temp_base);
963 switch (type) {
964 case Primitive::kPrimBoolean:
965 case Primitive::kPrimByte:
966 __ Stlrb(Register(src), base);
967 break;
968 case Primitive::kPrimChar:
969 case Primitive::kPrimShort:
970 __ Stlrh(Register(src), base);
971 break;
972 case Primitive::kPrimInt:
973 case Primitive::kPrimNot:
974 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000975 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000976 __ Stlr(Register(src), base);
977 break;
978 case Primitive::kPrimFloat:
979 case Primitive::kPrimDouble: {
980 DCHECK(src.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000981 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000982
983 Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
984 __ Fmov(temp, FPRegister(src));
985 __ Stlr(temp, base);
986 break;
987 }
988 case Primitive::kPrimVoid:
989 LOG(FATAL) << "Unreachable type " << type;
990 }
991}
992
Alexandre Rames67555f72014-11-18 10:55:16 +0000993void CodeGeneratorARM64::LoadCurrentMethod(vixl::Register current_method) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000994 DCHECK(RequiresCurrentMethod());
Alexandre Rames67555f72014-11-18 10:55:16 +0000995 DCHECK(current_method.IsW());
996 __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset));
997}
998
999void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset,
1000 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001001 uint32_t dex_pc,
1002 SlowPathCode* slow_path) {
Alexandre Ramesd921d642015-04-16 15:07:16 +01001003 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames67555f72014-11-18 10:55:16 +00001004 __ Ldr(lr, MemOperand(tr, entry_point_offset));
1005 __ Blr(lr);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001006 if (instruction != nullptr) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001007 RecordPcInfo(instruction, dex_pc, slow_path);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001008 DCHECK(instruction->IsSuspendCheck()
1009 || instruction->IsBoundsCheck()
1010 || instruction->IsNullCheck()
1011 || instruction->IsDivZeroCheck()
1012 || !IsLeafMethod());
1013 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001014}
1015
1016void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path,
1017 vixl::Register class_reg) {
1018 UseScratchRegisterScope temps(GetVIXLAssembler());
1019 Register temp = temps.AcquireW();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001020 size_t status_offset = mirror::Class::StatusOffset().SizeValue();
Serban Constantinescu579885a2015-02-22 20:51:33 +00001021 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001022
Serban Constantinescu02164b32014-11-13 14:05:07 +00001023 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
Serban Constantinescu579885a2015-02-22 20:51:33 +00001024 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001025 // TODO(vixl): Let the MacroAssembler handle MemOperand.
1026 __ Add(temp, class_reg, status_offset);
1027 __ Ldar(temp, HeapOperand(temp));
1028 __ Cmp(temp, mirror::Class::kStatusInitialized);
1029 __ B(lt, slow_path->GetEntryLabel());
1030 } else {
1031 __ Ldr(temp, HeapOperand(class_reg, status_offset));
1032 __ Cmp(temp, mirror::Class::kStatusInitialized);
1033 __ B(lt, slow_path->GetEntryLabel());
1034 __ Dmb(InnerShareable, BarrierReads);
1035 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001036 __ Bind(slow_path->GetExitLabel());
1037}
Alexandre Rames5319def2014-10-23 10:03:10 +01001038
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001039void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) {
1040 BarrierType type = BarrierAll;
1041
1042 switch (kind) {
1043 case MemBarrierKind::kAnyAny:
1044 case MemBarrierKind::kAnyStore: {
1045 type = BarrierAll;
1046 break;
1047 }
1048 case MemBarrierKind::kLoadAny: {
1049 type = BarrierReads;
1050 break;
1051 }
1052 case MemBarrierKind::kStoreStore: {
1053 type = BarrierWrites;
1054 break;
1055 }
1056 default:
1057 LOG(FATAL) << "Unexpected memory barrier " << kind;
1058 }
1059 __ Dmb(InnerShareable, type);
1060}
1061
Serban Constantinescu02164b32014-11-13 14:05:07 +00001062void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction,
1063 HBasicBlock* successor) {
1064 SuspendCheckSlowPathARM64* slow_path =
1065 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor);
1066 codegen_->AddSlowPath(slow_path);
1067 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
1068 Register temp = temps.AcquireW();
1069
1070 __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue()));
1071 if (successor == nullptr) {
1072 __ Cbnz(temp, slow_path->GetEntryLabel());
1073 __ Bind(slow_path->GetReturnLabel());
1074 } else {
1075 __ Cbz(temp, codegen_->GetLabelOf(successor));
1076 __ B(slow_path->GetEntryLabel());
1077 // slow_path will return to GetLabelOf(successor).
1078 }
1079}
1080
Alexandre Rames5319def2014-10-23 10:03:10 +01001081InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph,
1082 CodeGeneratorARM64* codegen)
1083 : HGraphVisitor(graph),
1084 assembler_(codegen->GetAssembler()),
1085 codegen_(codegen) {}
1086
1087#define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \
Alexandre Rames3e69f162014-12-10 10:36:50 +00001088 /* No unimplemented IR. */
Alexandre Rames5319def2014-10-23 10:03:10 +01001089
1090#define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode
1091
1092enum UnimplementedInstructionBreakCode {
Alexandre Rames67555f72014-11-18 10:55:16 +00001093 // Using a base helps identify when we hit such breakpoints.
1094 UnimplementedInstructionBreakCodeBaseCode = 0x900,
Alexandre Rames5319def2014-10-23 10:03:10 +01001095#define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name),
1096 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION)
1097#undef ENUM_UNIMPLEMENTED_INSTRUCTION
1098};
1099
1100#define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \
1101 void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001102 UNUSED(instr); \
Alexandre Rames5319def2014-10-23 10:03:10 +01001103 __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \
1104 } \
1105 void LocationsBuilderARM64::Visit##name(H##name* instr) { \
1106 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \
1107 locations->SetOut(Location::Any()); \
1108 }
1109 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS)
1110#undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS
1111
1112#undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE
Alexandre Rames67555f72014-11-18 10:55:16 +00001113#undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION
Alexandre Rames5319def2014-10-23 10:03:10 +01001114
Alexandre Rames67555f72014-11-18 10:55:16 +00001115void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001116 DCHECK_EQ(instr->InputCount(), 2U);
1117 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1118 Primitive::Type type = instr->GetResultType();
1119 switch (type) {
1120 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001121 case Primitive::kPrimLong:
Alexandre Rames5319def2014-10-23 10:03:10 +01001122 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001123 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr));
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001124 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001125 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001126
1127 case Primitive::kPrimFloat:
1128 case Primitive::kPrimDouble:
1129 locations->SetInAt(0, Location::RequiresFpuRegister());
1130 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001131 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001132 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001133
Alexandre Rames5319def2014-10-23 10:03:10 +01001134 default:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001135 LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001136 }
1137}
1138
Alexandre Rames09a99962015-04-15 11:47:56 +01001139void LocationsBuilderARM64::HandleFieldGet(HInstruction* instruction) {
1140 LocationSummary* locations =
1141 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1142 locations->SetInAt(0, Location::RequiresRegister());
1143 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1144 locations->SetOut(Location::RequiresFpuRegister());
1145 } else {
1146 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1147 }
1148}
1149
1150void InstructionCodeGeneratorARM64::HandleFieldGet(HInstruction* instruction,
1151 const FieldInfo& field_info) {
1152 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Alexandre Ramesd921d642015-04-16 15:07:16 +01001153 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames09a99962015-04-15 11:47:56 +01001154
1155 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), field_info.GetFieldOffset());
1156 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
1157
1158 if (field_info.IsVolatile()) {
1159 if (use_acquire_release) {
1160 // NB: LoadAcquire will record the pc info if needed.
1161 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
1162 } else {
1163 codegen_->Load(field_info.GetFieldType(), OutputCPURegister(instruction), field);
1164 codegen_->MaybeRecordImplicitNullCheck(instruction);
1165 // For IRIW sequential consistency kLoadAny is not sufficient.
1166 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1167 }
1168 } else {
1169 codegen_->Load(field_info.GetFieldType(), OutputCPURegister(instruction), field);
1170 codegen_->MaybeRecordImplicitNullCheck(instruction);
1171 }
1172}
1173
1174void LocationsBuilderARM64::HandleFieldSet(HInstruction* instruction) {
1175 LocationSummary* locations =
1176 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1177 locations->SetInAt(0, Location::RequiresRegister());
1178 if (Primitive::IsFloatingPointType(instruction->InputAt(1)->GetType())) {
1179 locations->SetInAt(1, Location::RequiresFpuRegister());
1180 } else {
1181 locations->SetInAt(1, Location::RequiresRegister());
1182 }
1183}
1184
1185void InstructionCodeGeneratorARM64::HandleFieldSet(HInstruction* instruction,
1186 const FieldInfo& field_info) {
1187 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
Alexandre Ramesd921d642015-04-16 15:07:16 +01001188 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames09a99962015-04-15 11:47:56 +01001189
1190 Register obj = InputRegisterAt(instruction, 0);
1191 CPURegister value = InputCPURegisterAt(instruction, 1);
1192 Offset offset = field_info.GetFieldOffset();
1193 Primitive::Type field_type = field_info.GetFieldType();
1194 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
1195
1196 if (field_info.IsVolatile()) {
1197 if (use_acquire_release) {
1198 codegen_->StoreRelease(field_type, value, HeapOperand(obj, offset));
1199 codegen_->MaybeRecordImplicitNullCheck(instruction);
1200 } else {
1201 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
1202 codegen_->Store(field_type, value, HeapOperand(obj, offset));
1203 codegen_->MaybeRecordImplicitNullCheck(instruction);
1204 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1205 }
1206 } else {
1207 codegen_->Store(field_type, value, HeapOperand(obj, offset));
1208 codegen_->MaybeRecordImplicitNullCheck(instruction);
1209 }
1210
1211 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
1212 codegen_->MarkGCCard(obj, Register(value));
1213 }
1214}
1215
Alexandre Rames67555f72014-11-18 10:55:16 +00001216void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001217 Primitive::Type type = instr->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001218
1219 switch (type) {
1220 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001221 case Primitive::kPrimLong: {
1222 Register dst = OutputRegister(instr);
1223 Register lhs = InputRegisterAt(instr, 0);
1224 Operand rhs = InputOperandAt(instr, 1);
Alexandre Rames5319def2014-10-23 10:03:10 +01001225 if (instr->IsAdd()) {
1226 __ Add(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001227 } else if (instr->IsAnd()) {
1228 __ And(dst, lhs, rhs);
1229 } else if (instr->IsOr()) {
1230 __ Orr(dst, lhs, rhs);
1231 } else if (instr->IsSub()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001232 __ Sub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001233 } else {
1234 DCHECK(instr->IsXor());
1235 __ Eor(dst, lhs, rhs);
Alexandre Rames5319def2014-10-23 10:03:10 +01001236 }
1237 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001238 }
1239 case Primitive::kPrimFloat:
1240 case Primitive::kPrimDouble: {
1241 FPRegister dst = OutputFPRegister(instr);
1242 FPRegister lhs = InputFPRegisterAt(instr, 0);
1243 FPRegister rhs = InputFPRegisterAt(instr, 1);
1244 if (instr->IsAdd()) {
1245 __ Fadd(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001246 } else if (instr->IsSub()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001247 __ Fsub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001248 } else {
1249 LOG(FATAL) << "Unexpected floating-point binary operation";
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001250 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001251 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001252 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001253 default:
Alexandre Rames67555f72014-11-18 10:55:16 +00001254 LOG(FATAL) << "Unexpected binary operation type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001255 }
1256}
1257
Serban Constantinescu02164b32014-11-13 14:05:07 +00001258void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) {
1259 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1260
1261 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1262 Primitive::Type type = instr->GetResultType();
1263 switch (type) {
1264 case Primitive::kPrimInt:
1265 case Primitive::kPrimLong: {
1266 locations->SetInAt(0, Location::RequiresRegister());
1267 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1268 locations->SetOut(Location::RequiresRegister());
1269 break;
1270 }
1271 default:
1272 LOG(FATAL) << "Unexpected shift type " << type;
1273 }
1274}
1275
1276void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) {
1277 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1278
1279 Primitive::Type type = instr->GetType();
1280 switch (type) {
1281 case Primitive::kPrimInt:
1282 case Primitive::kPrimLong: {
1283 Register dst = OutputRegister(instr);
1284 Register lhs = InputRegisterAt(instr, 0);
1285 Operand rhs = InputOperandAt(instr, 1);
1286 if (rhs.IsImmediate()) {
1287 uint32_t shift_value = (type == Primitive::kPrimInt)
1288 ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue)
1289 : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue);
1290 if (instr->IsShl()) {
1291 __ Lsl(dst, lhs, shift_value);
1292 } else if (instr->IsShr()) {
1293 __ Asr(dst, lhs, shift_value);
1294 } else {
1295 __ Lsr(dst, lhs, shift_value);
1296 }
1297 } else {
1298 Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W();
1299
1300 if (instr->IsShl()) {
1301 __ Lsl(dst, lhs, rhs_reg);
1302 } else if (instr->IsShr()) {
1303 __ Asr(dst, lhs, rhs_reg);
1304 } else {
1305 __ Lsr(dst, lhs, rhs_reg);
1306 }
1307 }
1308 break;
1309 }
1310 default:
1311 LOG(FATAL) << "Unexpected shift operation type " << type;
1312 }
1313}
1314
Alexandre Rames5319def2014-10-23 10:03:10 +01001315void LocationsBuilderARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001316 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001317}
1318
1319void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001320 HandleBinaryOp(instruction);
1321}
1322
1323void LocationsBuilderARM64::VisitAnd(HAnd* instruction) {
1324 HandleBinaryOp(instruction);
1325}
1326
1327void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) {
1328 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001329}
1330
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001331void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) {
1332 LocationSummary* locations =
1333 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1334 locations->SetInAt(0, Location::RequiresRegister());
1335 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01001336 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1337 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1338 } else {
1339 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1340 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001341}
1342
1343void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) {
1344 LocationSummary* locations = instruction->GetLocations();
1345 Primitive::Type type = instruction->GetType();
1346 Register obj = InputRegisterAt(instruction, 0);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001347 Location index = locations->InAt(1);
1348 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001349 MemOperand source = HeapOperand(obj);
Alexandre Ramesd921d642015-04-16 15:07:16 +01001350 MacroAssembler* masm = GetVIXLAssembler();
1351 UseScratchRegisterScope temps(masm);
1352 BlockPoolsScope block_pools(masm);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001353
1354 if (index.IsConstant()) {
1355 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001356 source = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001357 } else {
1358 Register temp = temps.AcquireSameSizeAs(obj);
1359 Register index_reg = RegisterFrom(index, Primitive::kPrimInt);
1360 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001361 source = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001362 }
1363
Alexandre Rames67555f72014-11-18 10:55:16 +00001364 codegen_->Load(type, OutputCPURegister(instruction), source);
Calin Juravle77520bc2015-01-12 18:45:46 +00001365 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001366}
1367
Alexandre Rames5319def2014-10-23 10:03:10 +01001368void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) {
1369 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1370 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001371 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001372}
1373
1374void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) {
Alexandre Ramesd921d642015-04-16 15:07:16 +01001375 BlockPoolsScope block_pools(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +01001376 __ Ldr(OutputRegister(instruction),
1377 HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset()));
Calin Juravle77520bc2015-01-12 18:45:46 +00001378 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001379}
1380
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001381void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) {
Alexandre Rames97833a02015-04-16 15:07:12 +01001382 if (instruction->NeedsTypeCheck()) {
1383 LocationSummary* locations =
1384 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001385 InvokeRuntimeCallingConvention calling_convention;
1386 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1387 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1388 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1389 } else {
Alexandre Rames97833a02015-04-16 15:07:12 +01001390 LocationSummary* locations =
1391 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001392 locations->SetInAt(0, Location::RequiresRegister());
1393 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Alexandre Rames88c13cd2015-04-14 17:35:39 +01001394 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
1395 locations->SetInAt(2, Location::RequiresFpuRegister());
1396 } else {
1397 locations->SetInAt(2, Location::RequiresRegister());
1398 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001399 }
1400}
1401
1402void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) {
1403 Primitive::Type value_type = instruction->GetComponentType();
Alexandre Rames97833a02015-04-16 15:07:12 +01001404 LocationSummary* locations = instruction->GetLocations();
1405 bool needs_runtime_call = locations->WillCall();
1406
1407 if (needs_runtime_call) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001408 codegen_->InvokeRuntime(
1409 QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001410 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001411 } else {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001412 Register obj = InputRegisterAt(instruction, 0);
Alexandre Rames67555f72014-11-18 10:55:16 +00001413 CPURegister value = InputCPURegisterAt(instruction, 2);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001414 Location index = locations->InAt(1);
1415 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001416 MemOperand destination = HeapOperand(obj);
Alexandre Ramesd921d642015-04-16 15:07:16 +01001417 MacroAssembler* masm = GetVIXLAssembler();
Alexandre Ramesd921d642015-04-16 15:07:16 +01001418 BlockPoolsScope block_pools(masm);
Alexandre Rames97833a02015-04-16 15:07:12 +01001419 {
1420 // We use a block to end the scratch scope before the write barrier, thus
1421 // freeing the temporary registers so they can be used in `MarkGCCard`.
1422 UseScratchRegisterScope temps(masm);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001423
Alexandre Rames97833a02015-04-16 15:07:12 +01001424 if (index.IsConstant()) {
1425 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type);
1426 destination = HeapOperand(obj, offset);
1427 } else {
1428 Register temp = temps.AcquireSameSizeAs(obj);
1429 Register index_reg = InputRegisterAt(instruction, 1);
1430 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(value_type)));
1431 destination = HeapOperand(temp, offset);
1432 }
1433
1434 codegen_->Store(value_type, value, destination);
1435 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001436 }
Alexandre Rames97833a02015-04-16 15:07:12 +01001437 if (CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue())) {
1438 codegen_->MarkGCCard(obj, value.W());
1439 }
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001440 }
1441}
1442
Alexandre Rames67555f72014-11-18 10:55:16 +00001443void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
1444 LocationSummary* locations =
1445 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1446 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu760d8ef2015-03-28 18:09:56 +00001447 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames67555f72014-11-18 10:55:16 +00001448 if (instruction->HasUses()) {
1449 locations->SetOut(Location::SameAsFirstInput());
1450 }
1451}
1452
1453void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001454 LocationSummary* locations = instruction->GetLocations();
1455 BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(
1456 instruction, locations->InAt(0), locations->InAt(1));
Alexandre Rames67555f72014-11-18 10:55:16 +00001457 codegen_->AddSlowPath(slow_path);
1458
1459 __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1));
1460 __ B(slow_path->GetEntryLabel(), hs);
1461}
1462
1463void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) {
1464 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1465 instruction, LocationSummary::kCallOnSlowPath);
1466 locations->SetInAt(0, Location::RequiresRegister());
1467 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +00001468 locations->AddTemp(Location::RequiresRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001469}
1470
1471void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001472 LocationSummary* locations = instruction->GetLocations();
Alexandre Rames67555f72014-11-18 10:55:16 +00001473 Register obj = InputRegisterAt(instruction, 0);;
1474 Register cls = InputRegisterAt(instruction, 1);;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001475 Register obj_cls = WRegisterFrom(instruction->GetLocations()->GetTemp(0));
Alexandre Rames67555f72014-11-18 10:55:16 +00001476
Alexandre Rames3e69f162014-12-10 10:36:50 +00001477 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1478 instruction, locations->InAt(1), LocationFrom(obj_cls), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001479 codegen_->AddSlowPath(slow_path);
1480
1481 // TODO: avoid this check if we know obj is not null.
1482 __ Cbz(obj, slow_path->GetExitLabel());
1483 // Compare the class of `obj` with `cls`.
Alexandre Rames3e69f162014-12-10 10:36:50 +00001484 __ Ldr(obj_cls, HeapOperand(obj, mirror::Object::ClassOffset()));
1485 __ Cmp(obj_cls, cls);
Alexandre Rames67555f72014-11-18 10:55:16 +00001486 __ B(ne, slow_path->GetEntryLabel());
1487 __ Bind(slow_path->GetExitLabel());
1488}
1489
1490void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) {
1491 LocationSummary* locations =
1492 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1493 locations->SetInAt(0, Location::RequiresRegister());
1494 if (check->HasUses()) {
1495 locations->SetOut(Location::SameAsFirstInput());
1496 }
1497}
1498
1499void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) {
1500 // We assume the class is not null.
1501 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
1502 check->GetLoadClass(), check, check->GetDexPc(), true);
1503 codegen_->AddSlowPath(slow_path);
1504 GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0));
1505}
1506
Serban Constantinescu02164b32014-11-13 14:05:07 +00001507void LocationsBuilderARM64::VisitCompare(HCompare* compare) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001508 LocationSummary* locations =
Serban Constantinescu02164b32014-11-13 14:05:07 +00001509 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
1510 Primitive::Type in_type = compare->InputAt(0)->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001511 switch (in_type) {
1512 case Primitive::kPrimLong: {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001513 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001514 locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001515 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1516 break;
1517 }
1518 case Primitive::kPrimFloat:
1519 case Primitive::kPrimDouble: {
1520 locations->SetInAt(0, Location::RequiresFpuRegister());
Alexandre Rames93415462015-02-17 15:08:20 +00001521 HInstruction* right = compare->InputAt(1);
1522 if ((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1523 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0))) {
1524 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1525 } else {
1526 locations->SetInAt(1, Location::RequiresFpuRegister());
1527 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001528 locations->SetOut(Location::RequiresRegister());
1529 break;
1530 }
1531 default:
1532 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1533 }
1534}
1535
1536void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) {
1537 Primitive::Type in_type = compare->InputAt(0)->GetType();
1538
1539 // 0 if: left == right
1540 // 1 if: left > right
1541 // -1 if: left < right
1542 switch (in_type) {
1543 case Primitive::kPrimLong: {
1544 Register result = OutputRegister(compare);
1545 Register left = InputRegisterAt(compare, 0);
1546 Operand right = InputOperandAt(compare, 1);
1547
1548 __ Cmp(left, right);
1549 __ Cset(result, ne);
1550 __ Cneg(result, result, lt);
1551 break;
1552 }
1553 case Primitive::kPrimFloat:
1554 case Primitive::kPrimDouble: {
1555 Register result = OutputRegister(compare);
1556 FPRegister left = InputFPRegisterAt(compare, 0);
Alexandre Rames93415462015-02-17 15:08:20 +00001557 if (compare->GetLocations()->InAt(1).IsConstant()) {
1558 if (kIsDebugBuild) {
1559 HInstruction* right = compare->GetLocations()->InAt(1).GetConstant();
1560 DCHECK((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1561 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0)));
1562 }
1563 // 0.0 is the only immediate that can be encoded directly in a FCMP instruction.
1564 __ Fcmp(left, 0.0);
1565 } else {
1566 __ Fcmp(left, InputFPRegisterAt(compare, 1));
1567 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001568 if (compare->IsGtBias()) {
1569 __ Cset(result, ne);
1570 } else {
1571 __ Csetm(result, ne);
1572 }
1573 __ Cneg(result, result, compare->IsGtBias() ? mi : gt);
Alexandre Rames5319def2014-10-23 10:03:10 +01001574 break;
1575 }
1576 default:
1577 LOG(FATAL) << "Unimplemented compare type " << in_type;
1578 }
1579}
1580
1581void LocationsBuilderARM64::VisitCondition(HCondition* instruction) {
1582 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1583 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001584 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames5319def2014-10-23 10:03:10 +01001585 if (instruction->NeedsMaterialization()) {
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001586 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001587 }
1588}
1589
1590void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) {
1591 if (!instruction->NeedsMaterialization()) {
1592 return;
1593 }
1594
1595 LocationSummary* locations = instruction->GetLocations();
1596 Register lhs = InputRegisterAt(instruction, 0);
1597 Operand rhs = InputOperandAt(instruction, 1);
1598 Register res = RegisterFrom(locations->Out(), instruction->GetType());
1599 Condition cond = ARM64Condition(instruction->GetCondition());
1600
1601 __ Cmp(lhs, rhs);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001602 __ Cset(res, cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001603}
1604
1605#define FOR_EACH_CONDITION_INSTRUCTION(M) \
1606 M(Equal) \
1607 M(NotEqual) \
1608 M(LessThan) \
1609 M(LessThanOrEqual) \
1610 M(GreaterThan) \
1611 M(GreaterThanOrEqual)
1612#define DEFINE_CONDITION_VISITORS(Name) \
1613void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \
1614void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); }
1615FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS)
Alexandre Rames67555f72014-11-18 10:55:16 +00001616#undef DEFINE_CONDITION_VISITORS
Alexandre Rames5319def2014-10-23 10:03:10 +01001617#undef FOR_EACH_CONDITION_INSTRUCTION
1618
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001619void LocationsBuilderARM64::VisitDiv(HDiv* div) {
1620 LocationSummary* locations =
1621 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1622 switch (div->GetResultType()) {
1623 case Primitive::kPrimInt:
1624 case Primitive::kPrimLong:
1625 locations->SetInAt(0, Location::RequiresRegister());
1626 locations->SetInAt(1, Location::RequiresRegister());
1627 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1628 break;
1629
1630 case Primitive::kPrimFloat:
1631 case Primitive::kPrimDouble:
1632 locations->SetInAt(0, Location::RequiresFpuRegister());
1633 locations->SetInAt(1, Location::RequiresFpuRegister());
1634 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1635 break;
1636
1637 default:
1638 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1639 }
1640}
1641
1642void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) {
1643 Primitive::Type type = div->GetResultType();
1644 switch (type) {
1645 case Primitive::kPrimInt:
1646 case Primitive::kPrimLong:
1647 __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1));
1648 break;
1649
1650 case Primitive::kPrimFloat:
1651 case Primitive::kPrimDouble:
1652 __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1));
1653 break;
1654
1655 default:
1656 LOG(FATAL) << "Unexpected div type " << type;
1657 }
1658}
1659
Alexandre Rames67555f72014-11-18 10:55:16 +00001660void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1661 LocationSummary* locations =
1662 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1663 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1664 if (instruction->HasUses()) {
1665 locations->SetOut(Location::SameAsFirstInput());
1666 }
1667}
1668
1669void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1670 SlowPathCodeARM64* slow_path =
1671 new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction);
1672 codegen_->AddSlowPath(slow_path);
1673 Location value = instruction->GetLocations()->InAt(0);
1674
Alexandre Rames3e69f162014-12-10 10:36:50 +00001675 Primitive::Type type = instruction->GetType();
1676
1677 if ((type != Primitive::kPrimInt) && (type != Primitive::kPrimLong)) {
1678 LOG(FATAL) << "Unexpected type " << type << "for DivZeroCheck.";
1679 return;
1680 }
1681
Alexandre Rames67555f72014-11-18 10:55:16 +00001682 if (value.IsConstant()) {
1683 int64_t divisor = Int64ConstantFrom(value);
1684 if (divisor == 0) {
1685 __ B(slow_path->GetEntryLabel());
1686 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001687 // A division by a non-null constant is valid. We don't need to perform
1688 // any check, so simply fall through.
Alexandre Rames67555f72014-11-18 10:55:16 +00001689 }
1690 } else {
1691 __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel());
1692 }
1693}
1694
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001695void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1696 LocationSummary* locations =
1697 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1698 locations->SetOut(Location::ConstantLocation(constant));
1699}
1700
1701void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1702 UNUSED(constant);
1703 // Will be generated at use site.
1704}
1705
Alexandre Rames5319def2014-10-23 10:03:10 +01001706void LocationsBuilderARM64::VisitExit(HExit* exit) {
1707 exit->SetLocations(nullptr);
1708}
1709
1710void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001711 UNUSED(exit);
Alexandre Rames5319def2014-10-23 10:03:10 +01001712}
1713
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001714void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) {
1715 LocationSummary* locations =
1716 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1717 locations->SetOut(Location::ConstantLocation(constant));
1718}
1719
1720void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) {
1721 UNUSED(constant);
1722 // Will be generated at use site.
1723}
1724
Alexandre Rames5319def2014-10-23 10:03:10 +01001725void LocationsBuilderARM64::VisitGoto(HGoto* got) {
1726 got->SetLocations(nullptr);
1727}
1728
1729void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) {
1730 HBasicBlock* successor = got->GetSuccessor();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001731 DCHECK(!successor->IsExitBlock());
1732 HBasicBlock* block = got->GetBlock();
1733 HInstruction* previous = got->GetPrevious();
1734 HLoopInformation* info = block->GetLoopInformation();
1735
David Brazdil46e2a392015-03-16 17:31:52 +00001736 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001737 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1738 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1739 return;
1740 }
1741 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1742 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1743 }
1744 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001745 __ B(codegen_->GetLabelOf(successor));
1746 }
1747}
1748
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001749void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction,
1750 vixl::Label* true_target,
1751 vixl::Label* false_target,
1752 vixl::Label* always_true_target) {
1753 HInstruction* cond = instruction->InputAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001754 HCondition* condition = cond->AsCondition();
Alexandre Rames5319def2014-10-23 10:03:10 +01001755
Serban Constantinescu02164b32014-11-13 14:05:07 +00001756 if (cond->IsIntConstant()) {
1757 int32_t cond_value = cond->AsIntConstant()->GetValue();
1758 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001759 if (always_true_target != nullptr) {
1760 __ B(always_true_target);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001761 }
1762 return;
1763 } else {
1764 DCHECK_EQ(cond_value, 0);
1765 }
1766 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001767 // The condition instruction has been materialized, compare the output to 0.
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001768 Location cond_val = instruction->GetLocations()->InAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001769 DCHECK(cond_val.IsRegister());
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001770 __ Cbnz(InputRegisterAt(instruction, 0), true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001771 } else {
1772 // The condition instruction has not been materialized, use its inputs as
1773 // the comparison and its condition as the branch condition.
1774 Register lhs = InputRegisterAt(condition, 0);
1775 Operand rhs = InputOperandAt(condition, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001776 Condition arm64_cond = ARM64Condition(condition->GetCondition());
Alexandre Rames4388dcc2015-02-03 10:28:33 +00001777 if ((arm64_cond != gt && arm64_cond != le) && rhs.IsImmediate() && (rhs.immediate() == 0)) {
1778 switch (arm64_cond) {
1779 case eq:
1780 __ Cbz(lhs, true_target);
1781 break;
1782 case ne:
1783 __ Cbnz(lhs, true_target);
1784 break;
1785 case lt:
1786 // Test the sign bit and branch accordingly.
1787 __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1788 break;
1789 case ge:
1790 // Test the sign bit and branch accordingly.
1791 __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1792 break;
1793 default:
1794 // Without the `static_cast` the compiler throws an error for
1795 // `-Werror=sign-promo`.
1796 LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001797 }
1798 } else {
1799 __ Cmp(lhs, rhs);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001800 __ B(arm64_cond, true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001801 }
1802 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001803 if (false_target != nullptr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001804 __ B(false_target);
1805 }
1806}
1807
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001808void LocationsBuilderARM64::VisitIf(HIf* if_instr) {
1809 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1810 HInstruction* cond = if_instr->InputAt(0);
1811 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1812 locations->SetInAt(0, Location::RequiresRegister());
1813 }
1814}
1815
1816void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) {
1817 vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1818 vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1819 vixl::Label* always_true_target = true_target;
1820 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1821 if_instr->IfTrueSuccessor())) {
1822 always_true_target = nullptr;
1823 }
1824 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1825 if_instr->IfFalseSuccessor())) {
1826 false_target = nullptr;
1827 }
1828 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1829}
1830
1831void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1832 LocationSummary* locations = new (GetGraph()->GetArena())
1833 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1834 HInstruction* cond = deoptimize->InputAt(0);
1835 DCHECK(cond->IsCondition());
1836 if (cond->AsCondition()->NeedsMaterialization()) {
1837 locations->SetInAt(0, Location::RequiresRegister());
1838 }
1839}
1840
1841void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1842 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena())
1843 DeoptimizationSlowPathARM64(deoptimize);
1844 codegen_->AddSlowPath(slow_path);
1845 vixl::Label* slow_path_entry = slow_path->GetEntryLabel();
1846 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1847}
1848
Alexandre Rames5319def2014-10-23 10:03:10 +01001849void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001850 HandleFieldGet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001851}
1852
1853void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001854 HandleFieldGet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01001855}
1856
1857void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001858 HandleFieldSet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001859}
1860
1861void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01001862 HandleFieldSet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01001863}
1864
Alexandre Rames67555f72014-11-18 10:55:16 +00001865void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) {
1866 LocationSummary::CallKind call_kind =
1867 instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
1868 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
1869 locations->SetInAt(0, Location::RequiresRegister());
1870 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001871 // The output does overlap inputs.
1872 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexandre Rames67555f72014-11-18 10:55:16 +00001873}
1874
1875void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) {
1876 LocationSummary* locations = instruction->GetLocations();
1877 Register obj = InputRegisterAt(instruction, 0);;
1878 Register cls = InputRegisterAt(instruction, 1);;
1879 Register out = OutputRegister(instruction);
1880
1881 vixl::Label done;
1882
1883 // Return 0 if `obj` is null.
1884 // TODO: Avoid this check if we know `obj` is not null.
1885 __ Mov(out, 0);
1886 __ Cbz(obj, &done);
1887
1888 // Compare the class of `obj` with `cls`.
Serban Constantinescu02164b32014-11-13 14:05:07 +00001889 __ Ldr(out, HeapOperand(obj, mirror::Object::ClassOffset()));
Alexandre Rames67555f72014-11-18 10:55:16 +00001890 __ Cmp(out, cls);
1891 if (instruction->IsClassFinal()) {
1892 // Classes must be equal for the instanceof to succeed.
1893 __ Cset(out, eq);
1894 } else {
1895 // If the classes are not equal, we go into a slow path.
1896 DCHECK(locations->OnlyCallsOnSlowPath());
1897 SlowPathCodeARM64* slow_path =
Alexandre Rames3e69f162014-12-10 10:36:50 +00001898 new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1899 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001900 codegen_->AddSlowPath(slow_path);
1901 __ B(ne, slow_path->GetEntryLabel());
1902 __ Mov(out, 1);
1903 __ Bind(slow_path->GetExitLabel());
1904 }
1905
1906 __ Bind(&done);
1907}
1908
Alexandre Rames5319def2014-10-23 10:03:10 +01001909void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) {
1910 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1911 locations->SetOut(Location::ConstantLocation(constant));
1912}
1913
1914void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) {
1915 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001916 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01001917}
1918
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001919void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) {
1920 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1921 locations->SetOut(Location::ConstantLocation(constant));
1922}
1923
1924void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant) {
1925 // Will be generated at use site.
1926 UNUSED(constant);
1927}
1928
Alexandre Rames5319def2014-10-23 10:03:10 +01001929void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) {
1930 LocationSummary* locations =
1931 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
1932 locations->AddTemp(LocationFrom(x0));
1933
1934 InvokeDexCallingConventionVisitor calling_convention_visitor;
1935 for (size_t i = 0; i < invoke->InputCount(); i++) {
1936 HInstruction* input = invoke->InputAt(i);
1937 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1938 }
1939
1940 Primitive::Type return_type = invoke->GetType();
1941 if (return_type != Primitive::kPrimVoid) {
1942 locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type));
1943 }
1944}
1945
Alexandre Rames67555f72014-11-18 10:55:16 +00001946void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1947 HandleInvoke(invoke);
1948}
1949
1950void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1951 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1952 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
1953 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1954 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1955 Location receiver = invoke->GetLocations()->InAt(0);
1956 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001957 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames67555f72014-11-18 10:55:16 +00001958
1959 // The register ip1 is required to be used for the hidden argument in
1960 // art_quick_imt_conflict_trampoline, so prevent VIXL from using it.
Alexandre Ramesd921d642015-04-16 15:07:16 +01001961 MacroAssembler* masm = GetVIXLAssembler();
1962 UseScratchRegisterScope scratch_scope(masm);
1963 BlockPoolsScope block_pools(masm);
Alexandre Rames67555f72014-11-18 10:55:16 +00001964 scratch_scope.Exclude(ip1);
1965 __ Mov(ip1, invoke->GetDexMethodIndex());
1966
1967 // temp = object->GetClass();
1968 if (receiver.IsStackSlot()) {
1969 __ Ldr(temp, StackOperandFrom(receiver));
1970 __ Ldr(temp, HeapOperand(temp, class_offset));
1971 } else {
1972 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
1973 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001974 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames67555f72014-11-18 10:55:16 +00001975 // temp = temp->GetImtEntryAt(method_offset);
1976 __ Ldr(temp, HeapOperand(temp, method_offset));
1977 // lr = temp->GetEntryPoint();
1978 __ Ldr(lr, HeapOperand(temp, entry_point));
1979 // lr();
1980 __ Blr(lr);
1981 DCHECK(!codegen_->IsLeafMethod());
1982 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1983}
1984
1985void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001986 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1987 if (intrinsic.TryDispatch(invoke)) {
1988 return;
1989 }
1990
Alexandre Rames67555f72014-11-18 10:55:16 +00001991 HandleInvoke(invoke);
1992}
1993
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001994void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001995 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1996 if (intrinsic.TryDispatch(invoke)) {
1997 return;
1998 }
1999
Alexandre Rames67555f72014-11-18 10:55:16 +00002000 HandleInvoke(invoke);
2001}
2002
Andreas Gampe878d58c2015-01-15 23:24:00 -08002003static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) {
2004 if (invoke->GetLocations()->Intrinsified()) {
2005 IntrinsicCodeGeneratorARM64 intrinsic(codegen);
2006 intrinsic.Dispatch(invoke);
2007 return true;
2008 }
2009 return false;
2010}
2011
2012void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
2013 // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention.
2014 DCHECK(temp.Is(kArtMethodRegister));
Alexandre Rames5319def2014-10-23 10:03:10 +01002015 size_t index_in_cache = mirror::Array::DataOffset(kHeapRefSize).SizeValue() +
Andreas Gampe878d58c2015-01-15 23:24:00 -08002016 invoke->GetDexMethodIndex() * kHeapRefSize;
Alexandre Rames5319def2014-10-23 10:03:10 +01002017
2018 // TODO: Implement all kinds of calls:
2019 // 1) boot -> boot
2020 // 2) app -> boot
2021 // 3) app -> app
2022 //
2023 // Currently we implement the app -> app logic, which looks up in the resolve cache.
2024
Nicolas Geoffray0a299b92015-01-29 11:39:44 +00002025 // temp = method;
2026 LoadCurrentMethod(temp);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002027 if (!invoke->IsRecursive()) {
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00002028 // temp = temp->dex_cache_resolved_methods_;
2029 __ Ldr(temp, HeapOperand(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset()));
2030 // temp = temp[index_in_cache];
2031 __ Ldr(temp, HeapOperand(temp, index_in_cache));
2032 // lr = temp->entry_point_from_quick_compiled_code_;
2033 __ Ldr(lr, HeapOperand(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
2034 kArm64WordSize)));
2035 // lr();
2036 __ Blr(lr);
2037 } else {
2038 __ Bl(&frame_entry_label_);
2039 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002040
Andreas Gampe878d58c2015-01-15 23:24:00 -08002041 DCHECK(!IsLeafMethod());
2042}
2043
2044void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
2045 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2046 return;
2047 }
2048
Alexandre Ramesd921d642015-04-16 15:07:16 +01002049 BlockPoolsScope block_pools(GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -08002050 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
2051 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00002052 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Alexandre Rames5319def2014-10-23 10:03:10 +01002053}
2054
2055void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08002056 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
2057 return;
2058 }
2059
Alexandre Rames5319def2014-10-23 10:03:10 +01002060 LocationSummary* locations = invoke->GetLocations();
2061 Location receiver = locations->InAt(0);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002062 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002063 size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() +
2064 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
2065 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00002066 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames5319def2014-10-23 10:03:10 +01002067
Alexandre Ramesd921d642015-04-16 15:07:16 +01002068 BlockPoolsScope block_pools(GetVIXLAssembler());
2069
Alexandre Rames5319def2014-10-23 10:03:10 +01002070 // temp = object->GetClass();
2071 if (receiver.IsStackSlot()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002072 __ Ldr(temp, MemOperand(sp, receiver.GetStackIndex()));
2073 __ Ldr(temp, HeapOperand(temp, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002074 } else {
2075 DCHECK(receiver.IsRegister());
Serban Constantinescu02164b32014-11-13 14:05:07 +00002076 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002077 }
Calin Juravle77520bc2015-01-12 18:45:46 +00002078 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames5319def2014-10-23 10:03:10 +01002079 // temp = temp->GetMethodAt(method_offset);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002080 __ Ldr(temp, HeapOperand(temp, method_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002081 // lr = temp->GetEntryPoint();
Serban Constantinescu02164b32014-11-13 14:05:07 +00002082 __ Ldr(lr, HeapOperand(temp, entry_point.SizeValue()));
Alexandre Rames5319def2014-10-23 10:03:10 +01002083 // lr();
2084 __ Blr(lr);
2085 DCHECK(!codegen_->IsLeafMethod());
2086 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2087}
2088
Alexandre Rames67555f72014-11-18 10:55:16 +00002089void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) {
2090 LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath
2091 : LocationSummary::kNoCall;
2092 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
2093 locations->SetOut(Location::RequiresRegister());
2094}
2095
2096void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) {
2097 Register out = OutputRegister(cls);
2098 if (cls->IsReferrersClass()) {
2099 DCHECK(!cls->CanCallRuntime());
2100 DCHECK(!cls->MustGenerateClinitCheck());
2101 codegen_->LoadCurrentMethod(out);
2102 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2103 } else {
2104 DCHECK(cls->CanCallRuntime());
2105 codegen_->LoadCurrentMethod(out);
2106 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DexCacheResolvedTypesOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002107 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002108
2109 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
2110 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2111 codegen_->AddSlowPath(slow_path);
2112 __ Cbz(out, slow_path->GetEntryLabel());
2113 if (cls->MustGenerateClinitCheck()) {
2114 GenerateClassInitializationCheck(slow_path, out);
2115 } else {
2116 __ Bind(slow_path->GetExitLabel());
2117 }
2118 }
2119}
2120
2121void LocationsBuilderARM64::VisitLoadException(HLoadException* load) {
2122 LocationSummary* locations =
2123 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2124 locations->SetOut(Location::RequiresRegister());
2125}
2126
2127void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) {
2128 MemOperand exception = MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value());
2129 __ Ldr(OutputRegister(instruction), exception);
2130 __ Str(wzr, exception);
2131}
2132
Alexandre Rames5319def2014-10-23 10:03:10 +01002133void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) {
2134 load->SetLocations(nullptr);
2135}
2136
2137void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) {
2138 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002139 UNUSED(load);
Alexandre Rames5319def2014-10-23 10:03:10 +01002140}
2141
Alexandre Rames67555f72014-11-18 10:55:16 +00002142void LocationsBuilderARM64::VisitLoadString(HLoadString* load) {
2143 LocationSummary* locations =
2144 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2145 locations->SetOut(Location::RequiresRegister());
2146}
2147
2148void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) {
2149 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load);
2150 codegen_->AddSlowPath(slow_path);
2151
2152 Register out = OutputRegister(load);
2153 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08002154 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2155 __ Ldr(out, HeapOperand(out, mirror::Class::DexCacheStringsOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002156 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002157 __ Cbz(out, slow_path->GetEntryLabel());
2158 __ Bind(slow_path->GetExitLabel());
2159}
2160
Alexandre Rames5319def2014-10-23 10:03:10 +01002161void LocationsBuilderARM64::VisitLocal(HLocal* local) {
2162 local->SetLocations(nullptr);
2163}
2164
2165void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) {
2166 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2167}
2168
2169void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) {
2170 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2171 locations->SetOut(Location::ConstantLocation(constant));
2172}
2173
2174void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) {
2175 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002176 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01002177}
2178
Alexandre Rames67555f72014-11-18 10:55:16 +00002179void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2180 LocationSummary* locations =
2181 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2182 InvokeRuntimeCallingConvention calling_convention;
2183 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2184}
2185
2186void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2187 codegen_->InvokeRuntime(instruction->IsEnter()
2188 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2189 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002190 instruction->GetDexPc(),
2191 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002192 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002193}
2194
Alexandre Rames42d641b2014-10-27 14:00:51 +00002195void LocationsBuilderARM64::VisitMul(HMul* mul) {
2196 LocationSummary* locations =
2197 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2198 switch (mul->GetResultType()) {
2199 case Primitive::kPrimInt:
2200 case Primitive::kPrimLong:
2201 locations->SetInAt(0, Location::RequiresRegister());
2202 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002203 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002204 break;
2205
2206 case Primitive::kPrimFloat:
2207 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002208 locations->SetInAt(0, Location::RequiresFpuRegister());
2209 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00002210 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002211 break;
2212
2213 default:
2214 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2215 }
2216}
2217
2218void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) {
2219 switch (mul->GetResultType()) {
2220 case Primitive::kPrimInt:
2221 case Primitive::kPrimLong:
2222 __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1));
2223 break;
2224
2225 case Primitive::kPrimFloat:
2226 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002227 __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1));
Alexandre Rames42d641b2014-10-27 14:00:51 +00002228 break;
2229
2230 default:
2231 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2232 }
2233}
2234
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002235void LocationsBuilderARM64::VisitNeg(HNeg* neg) {
2236 LocationSummary* locations =
2237 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2238 switch (neg->GetResultType()) {
2239 case Primitive::kPrimInt:
Alexandre Rames67555f72014-11-18 10:55:16 +00002240 case Primitive::kPrimLong:
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00002241 locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg));
Alexandre Rames67555f72014-11-18 10:55:16 +00002242 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002243 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002244
2245 case Primitive::kPrimFloat:
2246 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002247 locations->SetInAt(0, Location::RequiresFpuRegister());
2248 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002249 break;
2250
2251 default:
2252 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2253 }
2254}
2255
2256void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) {
2257 switch (neg->GetResultType()) {
2258 case Primitive::kPrimInt:
2259 case Primitive::kPrimLong:
2260 __ Neg(OutputRegister(neg), InputOperandAt(neg, 0));
2261 break;
2262
2263 case Primitive::kPrimFloat:
2264 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002265 __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002266 break;
2267
2268 default:
2269 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2270 }
2271}
2272
2273void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) {
2274 LocationSummary* locations =
2275 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2276 InvokeRuntimeCallingConvention calling_convention;
2277 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002278 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002279 locations->SetOut(LocationFrom(x0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002280 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1)));
2281 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2282 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002283}
2284
2285void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) {
2286 LocationSummary* locations = instruction->GetLocations();
2287 InvokeRuntimeCallingConvention calling_convention;
2288 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2289 DCHECK(type_index.Is(w0));
2290 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002291 DCHECK(current_method.Is(w2));
Alexandre Rames67555f72014-11-18 10:55:16 +00002292 codegen_->LoadCurrentMethod(current_method);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002293 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002294 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002295 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2296 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002297 instruction->GetDexPc(),
2298 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002299 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2300 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002301}
2302
Alexandre Rames5319def2014-10-23 10:03:10 +01002303void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) {
2304 LocationSummary* locations =
2305 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2306 InvokeRuntimeCallingConvention calling_convention;
2307 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
2308 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1)));
2309 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002310 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002311}
2312
2313void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
2314 LocationSummary* locations = instruction->GetLocations();
2315 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2316 DCHECK(type_index.Is(w0));
2317 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
2318 DCHECK(current_method.Is(w1));
Alexandre Rames67555f72014-11-18 10:55:16 +00002319 codegen_->LoadCurrentMethod(current_method);
Alexandre Rames5319def2014-10-23 10:03:10 +01002320 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002321 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002322 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2323 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002324 instruction->GetDexPc(),
2325 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002326 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002327}
2328
2329void LocationsBuilderARM64::VisitNot(HNot* instruction) {
2330 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexandre Rames4e596512014-11-07 15:56:50 +00002331 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002332 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01002333}
2334
2335void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) {
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002336 switch (instruction->GetResultType()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002337 case Primitive::kPrimInt:
Alexandre Rames5319def2014-10-23 10:03:10 +01002338 case Primitive::kPrimLong:
Roland Levillain55dcfb52014-10-24 18:09:09 +01002339 __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002340 break;
2341
2342 default:
2343 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2344 }
2345}
2346
David Brazdil66d126e2015-04-03 16:02:44 +01002347void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) {
2348 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2349 locations->SetInAt(0, Location::RequiresRegister());
2350 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2351}
2352
2353void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) {
David Brazdil66d126e2015-04-03 16:02:44 +01002354 __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1));
2355}
2356
Alexandre Rames5319def2014-10-23 10:03:10 +01002357void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) {
2358 LocationSummary* locations =
2359 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2360 locations->SetInAt(0, Location::RequiresRegister());
2361 if (instruction->HasUses()) {
2362 locations->SetOut(Location::SameAsFirstInput());
2363 }
2364}
2365
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002366void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002367 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2368 return;
2369 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002370
Alexandre Ramesd921d642015-04-16 15:07:16 +01002371 BlockPoolsScope block_pools(GetVIXLAssembler());
2372 Location obj = instruction->GetLocations()->InAt(0);
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002373 __ Ldr(wzr, HeapOperandFrom(obj, Offset(0)));
2374 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2375}
2376
2377void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002378 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction);
2379 codegen_->AddSlowPath(slow_path);
2380
2381 LocationSummary* locations = instruction->GetLocations();
2382 Location obj = locations->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002383
2384 __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel());
Alexandre Rames5319def2014-10-23 10:03:10 +01002385}
2386
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002387void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) {
2388 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2389 GenerateImplicitNullCheck(instruction);
2390 } else {
2391 GenerateExplicitNullCheck(instruction);
2392 }
2393}
2394
Alexandre Rames67555f72014-11-18 10:55:16 +00002395void LocationsBuilderARM64::VisitOr(HOr* instruction) {
2396 HandleBinaryOp(instruction);
2397}
2398
2399void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) {
2400 HandleBinaryOp(instruction);
2401}
2402
Alexandre Rames3e69f162014-12-10 10:36:50 +00002403void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2404 LOG(FATAL) << "Unreachable";
2405}
2406
2407void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) {
2408 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2409}
2410
Alexandre Rames5319def2014-10-23 10:03:10 +01002411void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) {
2412 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2413 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2414 if (location.IsStackSlot()) {
2415 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2416 } else if (location.IsDoubleStackSlot()) {
2417 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2418 }
2419 locations->SetOut(location);
2420}
2421
2422void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) {
2423 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002424 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002425}
2426
2427void LocationsBuilderARM64::VisitPhi(HPhi* instruction) {
2428 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2429 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2430 locations->SetInAt(i, Location::Any());
2431 }
2432 locations->SetOut(Location::Any());
2433}
2434
2435void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002436 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002437 LOG(FATAL) << "Unreachable";
2438}
2439
Serban Constantinescu02164b32014-11-13 14:05:07 +00002440void LocationsBuilderARM64::VisitRem(HRem* rem) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002441 Primitive::Type type = rem->GetResultType();
Alexandre Rames542361f2015-01-29 16:57:31 +00002442 LocationSummary::CallKind call_kind =
2443 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002444 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2445
2446 switch (type) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002447 case Primitive::kPrimInt:
2448 case Primitive::kPrimLong:
2449 locations->SetInAt(0, Location::RequiresRegister());
2450 locations->SetInAt(1, Location::RequiresRegister());
2451 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2452 break;
2453
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002454 case Primitive::kPrimFloat:
2455 case Primitive::kPrimDouble: {
2456 InvokeRuntimeCallingConvention calling_convention;
2457 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
2458 locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1)));
2459 locations->SetOut(calling_convention.GetReturnLocation(type));
2460
2461 break;
2462 }
2463
Serban Constantinescu02164b32014-11-13 14:05:07 +00002464 default:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002465 LOG(FATAL) << "Unexpected rem type " << type;
Serban Constantinescu02164b32014-11-13 14:05:07 +00002466 }
2467}
2468
2469void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) {
2470 Primitive::Type type = rem->GetResultType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002471
Serban Constantinescu02164b32014-11-13 14:05:07 +00002472 switch (type) {
2473 case Primitive::kPrimInt:
2474 case Primitive::kPrimLong: {
2475 UseScratchRegisterScope temps(GetVIXLAssembler());
2476 Register dividend = InputRegisterAt(rem, 0);
2477 Register divisor = InputRegisterAt(rem, 1);
2478 Register output = OutputRegister(rem);
2479 Register temp = temps.AcquireSameSizeAs(output);
2480
2481 __ Sdiv(temp, dividend, divisor);
2482 __ Msub(output, temp, divisor, dividend);
2483 break;
2484 }
2485
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002486 case Primitive::kPrimFloat:
2487 case Primitive::kPrimDouble: {
2488 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
2489 : QUICK_ENTRY_POINT(pFmod);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002490 codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002491 break;
2492 }
2493
Serban Constantinescu02164b32014-11-13 14:05:07 +00002494 default:
2495 LOG(FATAL) << "Unexpected rem type " << type;
2496 }
2497}
2498
Alexandre Rames5319def2014-10-23 10:03:10 +01002499void LocationsBuilderARM64::VisitReturn(HReturn* instruction) {
2500 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2501 Primitive::Type return_type = instruction->InputAt(0)->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002502 locations->SetInAt(0, ARM64ReturnLocation(return_type));
Alexandre Rames5319def2014-10-23 10:03:10 +01002503}
2504
2505void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002506 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002507 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002508}
2509
2510void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) {
2511 instruction->SetLocations(nullptr);
2512}
2513
2514void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002515 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002516 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002517}
2518
Serban Constantinescu02164b32014-11-13 14:05:07 +00002519void LocationsBuilderARM64::VisitShl(HShl* shl) {
2520 HandleShift(shl);
2521}
2522
2523void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) {
2524 HandleShift(shl);
2525}
2526
2527void LocationsBuilderARM64::VisitShr(HShr* shr) {
2528 HandleShift(shr);
2529}
2530
2531void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) {
2532 HandleShift(shr);
2533}
2534
Alexandre Rames5319def2014-10-23 10:03:10 +01002535void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) {
2536 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
2537 Primitive::Type field_type = store->InputAt(1)->GetType();
2538 switch (field_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002539 case Primitive::kPrimNot:
Alexandre Rames5319def2014-10-23 10:03:10 +01002540 case Primitive::kPrimBoolean:
2541 case Primitive::kPrimByte:
2542 case Primitive::kPrimChar:
2543 case Primitive::kPrimShort:
2544 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002545 case Primitive::kPrimFloat:
Alexandre Rames5319def2014-10-23 10:03:10 +01002546 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
2547 break;
2548
2549 case Primitive::kPrimLong:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002550 case Primitive::kPrimDouble:
Alexandre Rames5319def2014-10-23 10:03:10 +01002551 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
2552 break;
2553
2554 default:
2555 LOG(FATAL) << "Unimplemented local type " << field_type;
2556 }
2557}
2558
2559void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002560 UNUSED(store);
Alexandre Rames5319def2014-10-23 10:03:10 +01002561}
2562
2563void LocationsBuilderARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002564 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002565}
2566
2567void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002568 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002569}
2570
Alexandre Rames67555f72014-11-18 10:55:16 +00002571void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002572 HandleFieldGet(instruction);
Alexandre Rames67555f72014-11-18 10:55:16 +00002573}
2574
2575void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002576 HandleFieldGet(instruction, instruction->GetFieldInfo());
Alexandre Rames67555f72014-11-18 10:55:16 +00002577}
2578
2579void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002580 HandleFieldSet(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002581}
2582
Alexandre Rames67555f72014-11-18 10:55:16 +00002583void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames09a99962015-04-15 11:47:56 +01002584 HandleFieldSet(instruction, instruction->GetFieldInfo());
Alexandre Rames5319def2014-10-23 10:03:10 +01002585}
2586
2587void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
2588 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2589}
2590
2591void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002592 HBasicBlock* block = instruction->GetBlock();
2593 if (block->GetLoopInformation() != nullptr) {
2594 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2595 // The back edge will generate the suspend check.
2596 return;
2597 }
2598 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2599 // The goto will generate the suspend check.
2600 return;
2601 }
2602 GenerateSuspendCheck(instruction, nullptr);
Alexandre Rames5319def2014-10-23 10:03:10 +01002603}
2604
2605void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) {
2606 temp->SetLocations(nullptr);
2607}
2608
2609void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) {
2610 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002611 UNUSED(temp);
Alexandre Rames5319def2014-10-23 10:03:10 +01002612}
2613
Alexandre Rames67555f72014-11-18 10:55:16 +00002614void LocationsBuilderARM64::VisitThrow(HThrow* instruction) {
2615 LocationSummary* locations =
2616 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2617 InvokeRuntimeCallingConvention calling_convention;
2618 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2619}
2620
2621void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) {
2622 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002623 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002624 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002625}
2626
2627void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) {
2628 LocationSummary* locations =
2629 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
2630 Primitive::Type input_type = conversion->GetInputType();
2631 Primitive::Type result_type = conversion->GetResultType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002632 DCHECK_NE(input_type, result_type);
Alexandre Rames67555f72014-11-18 10:55:16 +00002633 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
2634 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
2635 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
2636 }
2637
Alexandre Rames542361f2015-01-29 16:57:31 +00002638 if (Primitive::IsFloatingPointType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002639 locations->SetInAt(0, Location::RequiresFpuRegister());
2640 } else {
2641 locations->SetInAt(0, Location::RequiresRegister());
2642 }
2643
Alexandre Rames542361f2015-01-29 16:57:31 +00002644 if (Primitive::IsFloatingPointType(result_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002645 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2646 } else {
2647 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2648 }
2649}
2650
2651void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) {
2652 Primitive::Type result_type = conversion->GetResultType();
2653 Primitive::Type input_type = conversion->GetInputType();
2654
2655 DCHECK_NE(input_type, result_type);
2656
Alexandre Rames542361f2015-01-29 16:57:31 +00002657 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002658 int result_size = Primitive::ComponentSize(result_type);
2659 int input_size = Primitive::ComponentSize(input_type);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002660 int min_size = std::min(result_size, input_size);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002661 Register output = OutputRegister(conversion);
2662 Register source = InputRegisterAt(conversion, 0);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002663 if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) {
2664 __ Ubfx(output, source, 0, result_size * kBitsPerByte);
2665 } else if ((result_type == Primitive::kPrimChar) ||
2666 ((input_type == Primitive::kPrimChar) && (result_size > input_size))) {
2667 __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002668 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00002669 __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002670 }
Alexandre Rames542361f2015-01-29 16:57:31 +00002671 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002672 __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002673 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002674 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
2675 __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002676 } else if (Primitive::IsFloatingPointType(result_type) &&
2677 Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002678 __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0));
2679 } else {
2680 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
2681 << " to " << result_type;
Alexandre Rames67555f72014-11-18 10:55:16 +00002682 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00002683}
Alexandre Rames67555f72014-11-18 10:55:16 +00002684
Serban Constantinescu02164b32014-11-13 14:05:07 +00002685void LocationsBuilderARM64::VisitUShr(HUShr* ushr) {
2686 HandleShift(ushr);
2687}
2688
2689void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) {
2690 HandleShift(ushr);
Alexandre Rames67555f72014-11-18 10:55:16 +00002691}
2692
2693void LocationsBuilderARM64::VisitXor(HXor* instruction) {
2694 HandleBinaryOp(instruction);
2695}
2696
2697void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) {
2698 HandleBinaryOp(instruction);
2699}
2700
Calin Juravleb1498f62015-02-16 13:13:29 +00002701void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction) {
2702 // Nothing to do, this should be removed during prepare for register allocator.
2703 UNUSED(instruction);
2704 LOG(FATAL) << "Unreachable";
2705}
2706
2707void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction) {
2708 // Nothing to do, this should be removed during prepare for register allocator.
2709 UNUSED(instruction);
2710 LOG(FATAL) << "Unreachable";
2711}
2712
Alexandre Rames67555f72014-11-18 10:55:16 +00002713#undef __
2714#undef QUICK_ENTRY_POINT
2715
Alexandre Rames5319def2014-10-23 10:03:10 +01002716} // namespace arm64
2717} // namespace art