blob: 7390005ab016615276f82c776b5cd8e9692cc226 [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
Zheng Xuad4450e2015-04-17 18:48:56 +0800428void ParallelMoveResolverARM64::PrepareForEmitNativeCode() {
429 // Note: There are 6 kinds of moves:
430 // 1. constant -> GPR/FPR (non-cycle)
431 // 2. constant -> stack (non-cycle)
432 // 3. GPR/FPR -> GPR/FPR
433 // 4. GPR/FPR -> stack
434 // 5. stack -> GPR/FPR
435 // 6. stack -> stack (non-cycle)
436 // Case 1, 2 and 6 should never be included in a dependency cycle on ARM64. For case 3, 4, and 5
437 // VIXL uses at most 1 GPR. VIXL has 2 GPR and 1 FPR temps, and there should be no intersecting
438 // cycles on ARM64, so we always have 1 GPR and 1 FPR available VIXL temps to resolve the
439 // dependency.
440 vixl_temps_.Open(GetVIXLAssembler());
441}
442
443void ParallelMoveResolverARM64::FinishEmitNativeCode() {
444 vixl_temps_.Close();
445}
446
447Location ParallelMoveResolverARM64::AllocateScratchLocationFor(Location::Kind kind) {
448 DCHECK(kind == Location::kRegister || kind == Location::kFpuRegister ||
449 kind == Location::kStackSlot || kind == Location::kDoubleStackSlot);
450 kind = (kind == Location::kFpuRegister) ? Location::kFpuRegister : Location::kRegister;
451 Location scratch = GetScratchLocation(kind);
452 if (!scratch.Equals(Location::NoLocation())) {
453 return scratch;
454 }
455 // Allocate from VIXL temp registers.
456 if (kind == Location::kRegister) {
457 scratch = LocationFrom(vixl_temps_.AcquireX());
458 } else {
459 DCHECK(kind == Location::kFpuRegister);
460 scratch = LocationFrom(vixl_temps_.AcquireD());
461 }
462 AddScratchLocation(scratch);
463 return scratch;
464}
465
466void ParallelMoveResolverARM64::FreeScratchLocation(Location loc) {
467 if (loc.IsRegister()) {
468 vixl_temps_.Release(XRegisterFrom(loc));
469 } else {
470 DCHECK(loc.IsFpuRegister());
471 vixl_temps_.Release(DRegisterFrom(loc));
472 }
473 RemoveScratchLocation(loc);
474}
475
Alexandre Rames3e69f162014-12-10 10:36:50 +0000476void ParallelMoveResolverARM64::EmitMove(size_t index) {
477 MoveOperands* move = moves_.Get(index);
478 codegen_->MoveLocation(move->GetDestination(), move->GetSource());
479}
480
Alexandre Rames5319def2014-10-23 10:03:10 +0100481void CodeGeneratorARM64::GenerateFrameEntry() {
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000482 __ Bind(&frame_entry_label_);
483
Serban Constantinescu02164b32014-11-13 14:05:07 +0000484 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod();
485 if (do_overflow_check) {
486 UseScratchRegisterScope temps(GetVIXLAssembler());
487 Register temp = temps.AcquireX();
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000488 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000489 __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64)));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000490 __ Ldr(wzr, MemOperand(temp, 0));
491 RecordPcInfo(nullptr, 0);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000492 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100493
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000494 if (!HasEmptyFrame()) {
495 int frame_size = GetFrameSize();
496 // Stack layout:
497 // sp[frame_size - 8] : lr.
498 // ... : other preserved core registers.
499 // ... : other preserved fp registers.
500 // ... : reserved frame space.
501 // sp[0] : current method.
502 __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100503 GetAssembler()->cfi().AdjustCFAOffset(frame_size);
Zheng Xu69a50302015-04-14 20:04:41 +0800504 GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(),
505 frame_size - GetCoreSpillSize());
506 GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(),
507 frame_size - FrameEntrySpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000508 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100509}
510
511void CodeGeneratorARM64::GenerateFrameExit() {
David Srbeckyc34dc932015-04-12 09:27:43 +0100512 GetAssembler()->cfi().RememberState();
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000513 if (!HasEmptyFrame()) {
514 int frame_size = GetFrameSize();
Zheng Xu69a50302015-04-14 20:04:41 +0800515 GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(),
516 frame_size - FrameEntrySpillSize());
517 GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(),
518 frame_size - GetCoreSpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000519 __ Drop(frame_size);
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100520 GetAssembler()->cfi().AdjustCFAOffset(-frame_size);
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000521 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100522 __ Ret();
523 GetAssembler()->cfi().RestoreState();
524 GetAssembler()->cfi().DefCFAOffset(GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +0100525}
526
527void CodeGeneratorARM64::Bind(HBasicBlock* block) {
528 __ Bind(GetLabelOf(block));
529}
530
Alexandre Rames5319def2014-10-23 10:03:10 +0100531void CodeGeneratorARM64::Move(HInstruction* instruction,
532 Location location,
533 HInstruction* move_for) {
534 LocationSummary* locations = instruction->GetLocations();
535 if (locations != nullptr && locations->Out().Equals(location)) {
536 return;
537 }
538
539 Primitive::Type type = instruction->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000540 DCHECK_NE(type, Primitive::kPrimVoid);
Alexandre Rames5319def2014-10-23 10:03:10 +0100541
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000542 if (instruction->IsIntConstant()
543 || instruction->IsLongConstant()
544 || instruction->IsNullConstant()) {
545 int64_t value = GetInt64ValueOf(instruction->AsConstant());
Alexandre Rames5319def2014-10-23 10:03:10 +0100546 if (location.IsRegister()) {
547 Register dst = RegisterFrom(location, type);
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000548 DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) ||
Alexandre Rames5319def2014-10-23 10:03:10 +0100549 (instruction->IsLongConstant() && dst.Is64Bits()));
550 __ Mov(dst, value);
551 } else {
552 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000553 UseScratchRegisterScope temps(GetVIXLAssembler());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000554 Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant())
555 ? temps.AcquireW()
556 : temps.AcquireX();
Alexandre Rames5319def2014-10-23 10:03:10 +0100557 __ Mov(temp, value);
558 __ Str(temp, StackOperandFrom(location));
559 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000560 } else if (instruction->IsTemporary()) {
561 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000562 MoveLocation(location, temp_location, type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100563 } else if (instruction->IsLoadLocal()) {
564 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
Alexandre Rames542361f2015-01-29 16:57:31 +0000565 if (Primitive::Is64BitType(type)) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000566 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000567 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000568 MoveLocation(location, Location::StackSlot(stack_slot), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100569 }
570
571 } else {
572 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000573 MoveLocation(location, locations->Out(), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100574 }
575}
576
Alexandre Rames5319def2014-10-23 10:03:10 +0100577Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const {
578 Primitive::Type type = load->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000579
Alexandre Rames5319def2014-10-23 10:03:10 +0100580 switch (type) {
581 case Primitive::kPrimNot:
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000582 case Primitive::kPrimInt:
583 case Primitive::kPrimFloat:
584 return Location::StackSlot(GetStackSlot(load->GetLocal()));
585
586 case Primitive::kPrimLong:
587 case Primitive::kPrimDouble:
588 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
589
Alexandre Rames5319def2014-10-23 10:03:10 +0100590 case Primitive::kPrimBoolean:
591 case Primitive::kPrimByte:
592 case Primitive::kPrimChar:
593 case Primitive::kPrimShort:
Alexandre Rames5319def2014-10-23 10:03:10 +0100594 case Primitive::kPrimVoid:
Alexandre Rames5319def2014-10-23 10:03:10 +0100595 LOG(FATAL) << "Unexpected type " << type;
596 }
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000597
Alexandre Rames5319def2014-10-23 10:03:10 +0100598 LOG(FATAL) << "Unreachable";
599 return Location::NoLocation();
600}
601
602void CodeGeneratorARM64::MarkGCCard(Register object, Register value) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000603 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +0100604 Register card = temps.AcquireX();
Serban Constantinescu02164b32014-11-13 14:05:07 +0000605 Register temp = temps.AcquireW(); // Index within the CardTable - 32bit.
Alexandre Rames5319def2014-10-23 10:03:10 +0100606 vixl::Label done;
607 __ Cbz(value, &done);
608 __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value()));
609 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000610 __ Strb(card, MemOperand(card, temp.X()));
Alexandre Rames5319def2014-10-23 10:03:10 +0100611 __ Bind(&done);
612}
613
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000614void CodeGeneratorARM64::SetupBlockedRegisters(bool is_baseline) const {
615 // Blocked core registers:
616 // lr : Runtime reserved.
617 // tr : Runtime reserved.
618 // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it.
619 // ip1 : VIXL core temp.
620 // ip0 : VIXL core temp.
621 //
622 // Blocked fp registers:
623 // d31 : VIXL fp temp.
Alexandre Rames5319def2014-10-23 10:03:10 +0100624 CPURegList reserved_core_registers = vixl_reserved_core_registers;
625 reserved_core_registers.Combine(runtime_reserved_core_registers);
Alexandre Rames5319def2014-10-23 10:03:10 +0100626 while (!reserved_core_registers.IsEmpty()) {
627 blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true;
628 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000629
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000630 CPURegList reserved_fp_registers = vixl_reserved_fp_registers;
Zheng Xua3ec3942015-02-15 18:39:46 +0800631 while (!reserved_fp_registers.IsEmpty()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000632 blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true;
633 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000634
635 if (is_baseline) {
636 CPURegList reserved_core_baseline_registers = callee_saved_core_registers;
637 while (!reserved_core_baseline_registers.IsEmpty()) {
638 blocked_core_registers_[reserved_core_baseline_registers.PopLowestIndex().code()] = true;
639 }
640
641 CPURegList reserved_fp_baseline_registers = callee_saved_fp_registers;
642 while (!reserved_fp_baseline_registers.IsEmpty()) {
643 blocked_fpu_registers_[reserved_fp_baseline_registers.PopLowestIndex().code()] = true;
644 }
645 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100646}
647
648Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const {
649 if (type == Primitive::kPrimVoid) {
650 LOG(FATAL) << "Unreachable type " << type;
651 }
652
Alexandre Rames542361f2015-01-29 16:57:31 +0000653 if (Primitive::IsFloatingPointType(type)) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000654 ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters);
655 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100656 return Location::FpuRegisterLocation(reg);
657 } else {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000658 ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters);
659 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100660 return Location::RegisterLocation(reg);
661 }
662}
663
Alexandre Rames3e69f162014-12-10 10:36:50 +0000664size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
665 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
666 __ Str(reg, MemOperand(sp, stack_index));
667 return kArm64WordSize;
668}
669
670size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
671 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
672 __ Ldr(reg, MemOperand(sp, stack_index));
673 return kArm64WordSize;
674}
675
676size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
677 FPRegister reg = FPRegister(reg_id, kDRegSize);
678 __ Str(reg, MemOperand(sp, stack_index));
679 return kArm64WordSize;
680}
681
682size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
683 FPRegister reg = FPRegister(reg_id, kDRegSize);
684 __ Ldr(reg, MemOperand(sp, stack_index));
685 return kArm64WordSize;
686}
687
Alexandre Rames5319def2014-10-23 10:03:10 +0100688void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const {
689 stream << Arm64ManagedRegister::FromXRegister(XRegister(reg));
690}
691
692void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
693 stream << Arm64ManagedRegister::FromDRegister(DRegister(reg));
694}
695
Alexandre Rames67555f72014-11-18 10:55:16 +0000696void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000697 if (constant->IsIntConstant()) {
698 __ Mov(Register(destination), constant->AsIntConstant()->GetValue());
699 } else if (constant->IsLongConstant()) {
700 __ Mov(Register(destination), constant->AsLongConstant()->GetValue());
701 } else if (constant->IsNullConstant()) {
702 __ Mov(Register(destination), 0);
Alexandre Rames67555f72014-11-18 10:55:16 +0000703 } else if (constant->IsFloatConstant()) {
704 __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue());
705 } else {
706 DCHECK(constant->IsDoubleConstant());
707 __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue());
708 }
709}
710
Alexandre Rames3e69f162014-12-10 10:36:50 +0000711
712static bool CoherentConstantAndType(Location constant, Primitive::Type type) {
713 DCHECK(constant.IsConstant());
714 HConstant* cst = constant.GetConstant();
715 return (cst->IsIntConstant() && type == Primitive::kPrimInt) ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000716 // Null is mapped to a core W register, which we associate with kPrimInt.
717 (cst->IsNullConstant() && type == Primitive::kPrimInt) ||
Alexandre Rames3e69f162014-12-10 10:36:50 +0000718 (cst->IsLongConstant() && type == Primitive::kPrimLong) ||
719 (cst->IsFloatConstant() && type == Primitive::kPrimFloat) ||
720 (cst->IsDoubleConstant() && type == Primitive::kPrimDouble);
721}
722
723void CodeGeneratorARM64::MoveLocation(Location destination, Location source, Primitive::Type type) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000724 if (source.Equals(destination)) {
725 return;
726 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000727
728 // A valid move can always be inferred from the destination and source
729 // locations. When moving from and to a register, the argument type can be
730 // used to generate 32bit instead of 64bit moves. In debug mode we also
731 // checks the coherency of the locations and the type.
732 bool unspecified_type = (type == Primitive::kPrimVoid);
733
734 if (destination.IsRegister() || destination.IsFpuRegister()) {
735 if (unspecified_type) {
736 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
737 if (source.IsStackSlot() ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000738 (src_cst != nullptr && (src_cst->IsIntConstant()
739 || src_cst->IsFloatConstant()
740 || src_cst->IsNullConstant()))) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000741 // For stack slots and 32bit constants, a 64bit type is appropriate.
742 type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexandre Rames67555f72014-11-18 10:55:16 +0000743 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000744 // If the source is a double stack slot or a 64bit constant, a 64bit
745 // type is appropriate. Else the source is a register, and since the
746 // type has not been specified, we chose a 64bit type to force a 64bit
747 // move.
748 type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexandre Rames67555f72014-11-18 10:55:16 +0000749 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000750 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000751 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) ||
752 (destination.IsRegister() && !Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000753 CPURegister dst = CPURegisterFrom(destination, type);
754 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
755 DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot());
756 __ Ldr(dst, StackOperandFrom(source));
757 } else if (source.IsConstant()) {
758 DCHECK(CoherentConstantAndType(source, type));
759 MoveConstant(dst, source.GetConstant());
760 } else {
761 if (destination.IsRegister()) {
762 __ Mov(Register(dst), RegisterFrom(source, type));
763 } else {
Zheng Xuad4450e2015-04-17 18:48:56 +0800764 DCHECK(destination.IsFpuRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000765 __ Fmov(FPRegister(dst), FPRegisterFrom(source, type));
766 }
767 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000768 } else { // The destination is not a register. It must be a stack slot.
769 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
770 if (source.IsRegister() || source.IsFpuRegister()) {
771 if (unspecified_type) {
772 if (source.IsRegister()) {
773 type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
774 } else {
775 type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
776 }
777 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000778 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) &&
779 (source.IsFpuRegister() == Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000780 __ Str(CPURegisterFrom(source, type), StackOperandFrom(destination));
781 } else if (source.IsConstant()) {
782 DCHECK(unspecified_type || CoherentConstantAndType(source, type));
783 UseScratchRegisterScope temps(GetVIXLAssembler());
784 HConstant* src_cst = source.GetConstant();
785 CPURegister temp;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000786 if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000787 temp = temps.AcquireW();
788 } else if (src_cst->IsLongConstant()) {
789 temp = temps.AcquireX();
790 } else if (src_cst->IsFloatConstant()) {
791 temp = temps.AcquireS();
792 } else {
793 DCHECK(src_cst->IsDoubleConstant());
794 temp = temps.AcquireD();
795 }
796 MoveConstant(temp, src_cst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000797 __ Str(temp, StackOperandFrom(destination));
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000798 } else {
Alexandre Rames67555f72014-11-18 10:55:16 +0000799 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000800 DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000801 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000802 // There is generally less pressure on FP registers.
803 FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS();
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000804 __ Ldr(temp, StackOperandFrom(source));
805 __ Str(temp, StackOperandFrom(destination));
806 }
807 }
808}
809
810void CodeGeneratorARM64::Load(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000811 CPURegister dst,
812 const MemOperand& src) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000813 switch (type) {
814 case Primitive::kPrimBoolean:
Alexandre Rames67555f72014-11-18 10:55:16 +0000815 __ Ldrb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000816 break;
817 case Primitive::kPrimByte:
Alexandre Rames67555f72014-11-18 10:55:16 +0000818 __ Ldrsb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000819 break;
820 case Primitive::kPrimShort:
Alexandre Rames67555f72014-11-18 10:55:16 +0000821 __ Ldrsh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000822 break;
823 case Primitive::kPrimChar:
Alexandre Rames67555f72014-11-18 10:55:16 +0000824 __ Ldrh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000825 break;
826 case Primitive::kPrimInt:
827 case Primitive::kPrimNot:
828 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000829 case Primitive::kPrimFloat:
830 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000831 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Alexandre Rames67555f72014-11-18 10:55:16 +0000832 __ Ldr(dst, src);
833 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000834 case Primitive::kPrimVoid:
835 LOG(FATAL) << "Unreachable type " << type;
836 }
837}
838
Calin Juravle77520bc2015-01-12 18:45:46 +0000839void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000840 CPURegister dst,
841 const MemOperand& src) {
842 UseScratchRegisterScope temps(GetVIXLAssembler());
843 Register temp_base = temps.AcquireX();
Calin Juravle77520bc2015-01-12 18:45:46 +0000844 Primitive::Type type = instruction->GetType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000845
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000846 DCHECK(!src.IsPreIndex());
847 DCHECK(!src.IsPostIndex());
848
849 // TODO(vixl): Let the MacroAssembler handle MemOperand.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800850 __ Add(temp_base, src.base(), OperandFromMemOperand(src));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000851 MemOperand base = MemOperand(temp_base);
852 switch (type) {
853 case Primitive::kPrimBoolean:
854 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000855 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000856 break;
857 case Primitive::kPrimByte:
858 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000859 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000860 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
861 break;
862 case Primitive::kPrimChar:
863 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000864 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000865 break;
866 case Primitive::kPrimShort:
867 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000868 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000869 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
870 break;
871 case Primitive::kPrimInt:
872 case Primitive::kPrimNot:
873 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000874 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000875 __ Ldar(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000876 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000877 break;
878 case Primitive::kPrimFloat:
879 case Primitive::kPrimDouble: {
880 DCHECK(dst.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000881 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000882
883 Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
884 __ Ldar(temp, base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000885 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000886 __ Fmov(FPRegister(dst), temp);
887 break;
888 }
889 case Primitive::kPrimVoid:
890 LOG(FATAL) << "Unreachable type " << type;
891 }
892}
893
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000894void CodeGeneratorARM64::Store(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000895 CPURegister src,
896 const MemOperand& dst) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000897 switch (type) {
898 case Primitive::kPrimBoolean:
899 case Primitive::kPrimByte:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000900 __ Strb(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000901 break;
902 case Primitive::kPrimChar:
903 case Primitive::kPrimShort:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000904 __ Strh(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000905 break;
906 case Primitive::kPrimInt:
907 case Primitive::kPrimNot:
908 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000909 case Primitive::kPrimFloat:
910 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000911 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000912 __ Str(src, dst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000913 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000914 case Primitive::kPrimVoid:
915 LOG(FATAL) << "Unreachable type " << type;
916 }
917}
918
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000919void CodeGeneratorARM64::StoreRelease(Primitive::Type type,
920 CPURegister src,
921 const MemOperand& dst) {
922 UseScratchRegisterScope temps(GetVIXLAssembler());
923 Register temp_base = temps.AcquireX();
924
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000925 DCHECK(!dst.IsPreIndex());
926 DCHECK(!dst.IsPostIndex());
927
928 // TODO(vixl): Let the MacroAssembler handle this.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800929 Operand op = OperandFromMemOperand(dst);
930 __ Add(temp_base, dst.base(), op);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000931 MemOperand base = MemOperand(temp_base);
932 switch (type) {
933 case Primitive::kPrimBoolean:
934 case Primitive::kPrimByte:
935 __ Stlrb(Register(src), base);
936 break;
937 case Primitive::kPrimChar:
938 case Primitive::kPrimShort:
939 __ Stlrh(Register(src), base);
940 break;
941 case Primitive::kPrimInt:
942 case Primitive::kPrimNot:
943 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000944 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000945 __ Stlr(Register(src), base);
946 break;
947 case Primitive::kPrimFloat:
948 case Primitive::kPrimDouble: {
949 DCHECK(src.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000950 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000951
952 Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
953 __ Fmov(temp, FPRegister(src));
954 __ Stlr(temp, base);
955 break;
956 }
957 case Primitive::kPrimVoid:
958 LOG(FATAL) << "Unreachable type " << type;
959 }
960}
961
Alexandre Rames67555f72014-11-18 10:55:16 +0000962void CodeGeneratorARM64::LoadCurrentMethod(vixl::Register current_method) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000963 DCHECK(RequiresCurrentMethod());
Alexandre Rames67555f72014-11-18 10:55:16 +0000964 DCHECK(current_method.IsW());
965 __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset));
966}
967
968void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset,
969 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000970 uint32_t dex_pc,
971 SlowPathCode* slow_path) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000972 __ Ldr(lr, MemOperand(tr, entry_point_offset));
973 __ Blr(lr);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000974 if (instruction != nullptr) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000975 RecordPcInfo(instruction, dex_pc, slow_path);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000976 DCHECK(instruction->IsSuspendCheck()
977 || instruction->IsBoundsCheck()
978 || instruction->IsNullCheck()
979 || instruction->IsDivZeroCheck()
980 || !IsLeafMethod());
981 }
Alexandre Rames67555f72014-11-18 10:55:16 +0000982}
983
984void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path,
985 vixl::Register class_reg) {
986 UseScratchRegisterScope temps(GetVIXLAssembler());
987 Register temp = temps.AcquireW();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000988 size_t status_offset = mirror::Class::StatusOffset().SizeValue();
Serban Constantinescu579885a2015-02-22 20:51:33 +0000989 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000990
Serban Constantinescu02164b32014-11-13 14:05:07 +0000991 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
Serban Constantinescu579885a2015-02-22 20:51:33 +0000992 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000993 // TODO(vixl): Let the MacroAssembler handle MemOperand.
994 __ Add(temp, class_reg, status_offset);
995 __ Ldar(temp, HeapOperand(temp));
996 __ Cmp(temp, mirror::Class::kStatusInitialized);
997 __ B(lt, slow_path->GetEntryLabel());
998 } else {
999 __ Ldr(temp, HeapOperand(class_reg, status_offset));
1000 __ Cmp(temp, mirror::Class::kStatusInitialized);
1001 __ B(lt, slow_path->GetEntryLabel());
1002 __ Dmb(InnerShareable, BarrierReads);
1003 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001004 __ Bind(slow_path->GetExitLabel());
1005}
Alexandre Rames5319def2014-10-23 10:03:10 +01001006
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001007void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) {
1008 BarrierType type = BarrierAll;
1009
1010 switch (kind) {
1011 case MemBarrierKind::kAnyAny:
1012 case MemBarrierKind::kAnyStore: {
1013 type = BarrierAll;
1014 break;
1015 }
1016 case MemBarrierKind::kLoadAny: {
1017 type = BarrierReads;
1018 break;
1019 }
1020 case MemBarrierKind::kStoreStore: {
1021 type = BarrierWrites;
1022 break;
1023 }
1024 default:
1025 LOG(FATAL) << "Unexpected memory barrier " << kind;
1026 }
1027 __ Dmb(InnerShareable, type);
1028}
1029
Serban Constantinescu02164b32014-11-13 14:05:07 +00001030void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction,
1031 HBasicBlock* successor) {
1032 SuspendCheckSlowPathARM64* slow_path =
1033 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor);
1034 codegen_->AddSlowPath(slow_path);
1035 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
1036 Register temp = temps.AcquireW();
1037
1038 __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue()));
1039 if (successor == nullptr) {
1040 __ Cbnz(temp, slow_path->GetEntryLabel());
1041 __ Bind(slow_path->GetReturnLabel());
1042 } else {
1043 __ Cbz(temp, codegen_->GetLabelOf(successor));
1044 __ B(slow_path->GetEntryLabel());
1045 // slow_path will return to GetLabelOf(successor).
1046 }
1047}
1048
Alexandre Rames5319def2014-10-23 10:03:10 +01001049InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph,
1050 CodeGeneratorARM64* codegen)
1051 : HGraphVisitor(graph),
1052 assembler_(codegen->GetAssembler()),
1053 codegen_(codegen) {}
1054
1055#define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \
Alexandre Rames3e69f162014-12-10 10:36:50 +00001056 /* No unimplemented IR. */
Alexandre Rames5319def2014-10-23 10:03:10 +01001057
1058#define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode
1059
1060enum UnimplementedInstructionBreakCode {
Alexandre Rames67555f72014-11-18 10:55:16 +00001061 // Using a base helps identify when we hit such breakpoints.
1062 UnimplementedInstructionBreakCodeBaseCode = 0x900,
Alexandre Rames5319def2014-10-23 10:03:10 +01001063#define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name),
1064 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION)
1065#undef ENUM_UNIMPLEMENTED_INSTRUCTION
1066};
1067
1068#define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \
1069 void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001070 UNUSED(instr); \
Alexandre Rames5319def2014-10-23 10:03:10 +01001071 __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \
1072 } \
1073 void LocationsBuilderARM64::Visit##name(H##name* instr) { \
1074 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \
1075 locations->SetOut(Location::Any()); \
1076 }
1077 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS)
1078#undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS
1079
1080#undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE
Alexandre Rames67555f72014-11-18 10:55:16 +00001081#undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION
Alexandre Rames5319def2014-10-23 10:03:10 +01001082
Alexandre Rames67555f72014-11-18 10:55:16 +00001083void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001084 DCHECK_EQ(instr->InputCount(), 2U);
1085 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1086 Primitive::Type type = instr->GetResultType();
1087 switch (type) {
1088 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001089 case Primitive::kPrimLong:
Alexandre Rames5319def2014-10-23 10:03:10 +01001090 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001091 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr));
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001092 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001093 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001094
1095 case Primitive::kPrimFloat:
1096 case Primitive::kPrimDouble:
1097 locations->SetInAt(0, Location::RequiresFpuRegister());
1098 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001099 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001100 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001101
Alexandre Rames5319def2014-10-23 10:03:10 +01001102 default:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001103 LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001104 }
1105}
1106
Alexandre Rames67555f72014-11-18 10:55:16 +00001107void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001108 Primitive::Type type = instr->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001109
1110 switch (type) {
1111 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001112 case Primitive::kPrimLong: {
1113 Register dst = OutputRegister(instr);
1114 Register lhs = InputRegisterAt(instr, 0);
1115 Operand rhs = InputOperandAt(instr, 1);
Alexandre Rames5319def2014-10-23 10:03:10 +01001116 if (instr->IsAdd()) {
1117 __ Add(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001118 } else if (instr->IsAnd()) {
1119 __ And(dst, lhs, rhs);
1120 } else if (instr->IsOr()) {
1121 __ Orr(dst, lhs, rhs);
1122 } else if (instr->IsSub()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001123 __ Sub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001124 } else {
1125 DCHECK(instr->IsXor());
1126 __ Eor(dst, lhs, rhs);
Alexandre Rames5319def2014-10-23 10:03:10 +01001127 }
1128 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001129 }
1130 case Primitive::kPrimFloat:
1131 case Primitive::kPrimDouble: {
1132 FPRegister dst = OutputFPRegister(instr);
1133 FPRegister lhs = InputFPRegisterAt(instr, 0);
1134 FPRegister rhs = InputFPRegisterAt(instr, 1);
1135 if (instr->IsAdd()) {
1136 __ Fadd(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001137 } else if (instr->IsSub()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001138 __ Fsub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001139 } else {
1140 LOG(FATAL) << "Unexpected floating-point binary operation";
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001141 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001142 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001143 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001144 default:
Alexandre Rames67555f72014-11-18 10:55:16 +00001145 LOG(FATAL) << "Unexpected binary operation type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001146 }
1147}
1148
Serban Constantinescu02164b32014-11-13 14:05:07 +00001149void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) {
1150 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1151
1152 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1153 Primitive::Type type = instr->GetResultType();
1154 switch (type) {
1155 case Primitive::kPrimInt:
1156 case Primitive::kPrimLong: {
1157 locations->SetInAt(0, Location::RequiresRegister());
1158 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1159 locations->SetOut(Location::RequiresRegister());
1160 break;
1161 }
1162 default:
1163 LOG(FATAL) << "Unexpected shift type " << type;
1164 }
1165}
1166
1167void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) {
1168 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1169
1170 Primitive::Type type = instr->GetType();
1171 switch (type) {
1172 case Primitive::kPrimInt:
1173 case Primitive::kPrimLong: {
1174 Register dst = OutputRegister(instr);
1175 Register lhs = InputRegisterAt(instr, 0);
1176 Operand rhs = InputOperandAt(instr, 1);
1177 if (rhs.IsImmediate()) {
1178 uint32_t shift_value = (type == Primitive::kPrimInt)
1179 ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue)
1180 : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue);
1181 if (instr->IsShl()) {
1182 __ Lsl(dst, lhs, shift_value);
1183 } else if (instr->IsShr()) {
1184 __ Asr(dst, lhs, shift_value);
1185 } else {
1186 __ Lsr(dst, lhs, shift_value);
1187 }
1188 } else {
1189 Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W();
1190
1191 if (instr->IsShl()) {
1192 __ Lsl(dst, lhs, rhs_reg);
1193 } else if (instr->IsShr()) {
1194 __ Asr(dst, lhs, rhs_reg);
1195 } else {
1196 __ Lsr(dst, lhs, rhs_reg);
1197 }
1198 }
1199 break;
1200 }
1201 default:
1202 LOG(FATAL) << "Unexpected shift operation type " << type;
1203 }
1204}
1205
Alexandre Rames5319def2014-10-23 10:03:10 +01001206void LocationsBuilderARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001207 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001208}
1209
1210void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001211 HandleBinaryOp(instruction);
1212}
1213
1214void LocationsBuilderARM64::VisitAnd(HAnd* instruction) {
1215 HandleBinaryOp(instruction);
1216}
1217
1218void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) {
1219 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001220}
1221
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001222void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) {
1223 LocationSummary* locations =
1224 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1225 locations->SetInAt(0, Location::RequiresRegister());
1226 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1227 locations->SetOut(Location::RequiresRegister());
1228}
1229
1230void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) {
1231 LocationSummary* locations = instruction->GetLocations();
1232 Primitive::Type type = instruction->GetType();
1233 Register obj = InputRegisterAt(instruction, 0);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001234 Location index = locations->InAt(1);
1235 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001236 MemOperand source = HeapOperand(obj);
Alexandre Rames67555f72014-11-18 10:55:16 +00001237 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001238
1239 if (index.IsConstant()) {
1240 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001241 source = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001242 } else {
1243 Register temp = temps.AcquireSameSizeAs(obj);
1244 Register index_reg = RegisterFrom(index, Primitive::kPrimInt);
1245 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001246 source = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001247 }
1248
Alexandre Rames67555f72014-11-18 10:55:16 +00001249 codegen_->Load(type, OutputCPURegister(instruction), source);
Calin Juravle77520bc2015-01-12 18:45:46 +00001250 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001251}
1252
Alexandre Rames5319def2014-10-23 10:03:10 +01001253void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) {
1254 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1255 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001256 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001257}
1258
1259void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) {
1260 __ Ldr(OutputRegister(instruction),
1261 HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset()));
Calin Juravle77520bc2015-01-12 18:45:46 +00001262 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001263}
1264
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001265void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) {
1266 Primitive::Type value_type = instruction->GetComponentType();
1267 bool is_object = value_type == Primitive::kPrimNot;
1268 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1269 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1270 if (is_object) {
1271 InvokeRuntimeCallingConvention calling_convention;
1272 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1273 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1274 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1275 } else {
1276 locations->SetInAt(0, Location::RequiresRegister());
1277 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1278 locations->SetInAt(2, Location::RequiresRegister());
1279 }
1280}
1281
1282void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) {
1283 Primitive::Type value_type = instruction->GetComponentType();
1284 if (value_type == Primitive::kPrimNot) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001285 codegen_->InvokeRuntime(
1286 QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001287 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001288 } else {
1289 LocationSummary* locations = instruction->GetLocations();
1290 Register obj = InputRegisterAt(instruction, 0);
Alexandre Rames67555f72014-11-18 10:55:16 +00001291 CPURegister value = InputCPURegisterAt(instruction, 2);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001292 Location index = locations->InAt(1);
1293 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001294 MemOperand destination = HeapOperand(obj);
Alexandre Rames67555f72014-11-18 10:55:16 +00001295 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001296
1297 if (index.IsConstant()) {
1298 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001299 destination = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001300 } else {
1301 Register temp = temps.AcquireSameSizeAs(obj);
1302 Register index_reg = InputRegisterAt(instruction, 1);
1303 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(value_type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001304 destination = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001305 }
1306
1307 codegen_->Store(value_type, value, destination);
Calin Juravle77520bc2015-01-12 18:45:46 +00001308 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001309 }
1310}
1311
Alexandre Rames67555f72014-11-18 10:55:16 +00001312void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
1313 LocationSummary* locations =
1314 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1315 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu760d8ef2015-03-28 18:09:56 +00001316 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames67555f72014-11-18 10:55:16 +00001317 if (instruction->HasUses()) {
1318 locations->SetOut(Location::SameAsFirstInput());
1319 }
1320}
1321
1322void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001323 LocationSummary* locations = instruction->GetLocations();
1324 BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(
1325 instruction, locations->InAt(0), locations->InAt(1));
Alexandre Rames67555f72014-11-18 10:55:16 +00001326 codegen_->AddSlowPath(slow_path);
1327
1328 __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1));
1329 __ B(slow_path->GetEntryLabel(), hs);
1330}
1331
1332void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) {
1333 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1334 instruction, LocationSummary::kCallOnSlowPath);
1335 locations->SetInAt(0, Location::RequiresRegister());
1336 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +00001337 locations->AddTemp(Location::RequiresRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001338}
1339
1340void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001341 LocationSummary* locations = instruction->GetLocations();
Alexandre Rames67555f72014-11-18 10:55:16 +00001342 Register obj = InputRegisterAt(instruction, 0);;
1343 Register cls = InputRegisterAt(instruction, 1);;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001344 Register obj_cls = WRegisterFrom(instruction->GetLocations()->GetTemp(0));
Alexandre Rames67555f72014-11-18 10:55:16 +00001345
Alexandre Rames3e69f162014-12-10 10:36:50 +00001346 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1347 instruction, locations->InAt(1), LocationFrom(obj_cls), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001348 codegen_->AddSlowPath(slow_path);
1349
1350 // TODO: avoid this check if we know obj is not null.
1351 __ Cbz(obj, slow_path->GetExitLabel());
1352 // Compare the class of `obj` with `cls`.
Alexandre Rames3e69f162014-12-10 10:36:50 +00001353 __ Ldr(obj_cls, HeapOperand(obj, mirror::Object::ClassOffset()));
1354 __ Cmp(obj_cls, cls);
Alexandre Rames67555f72014-11-18 10:55:16 +00001355 __ B(ne, slow_path->GetEntryLabel());
1356 __ Bind(slow_path->GetExitLabel());
1357}
1358
1359void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) {
1360 LocationSummary* locations =
1361 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1362 locations->SetInAt(0, Location::RequiresRegister());
1363 if (check->HasUses()) {
1364 locations->SetOut(Location::SameAsFirstInput());
1365 }
1366}
1367
1368void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) {
1369 // We assume the class is not null.
1370 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
1371 check->GetLoadClass(), check, check->GetDexPc(), true);
1372 codegen_->AddSlowPath(slow_path);
1373 GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0));
1374}
1375
Serban Constantinescu02164b32014-11-13 14:05:07 +00001376void LocationsBuilderARM64::VisitCompare(HCompare* compare) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001377 LocationSummary* locations =
Serban Constantinescu02164b32014-11-13 14:05:07 +00001378 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
1379 Primitive::Type in_type = compare->InputAt(0)->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001380 switch (in_type) {
1381 case Primitive::kPrimLong: {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001382 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001383 locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001384 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1385 break;
1386 }
1387 case Primitive::kPrimFloat:
1388 case Primitive::kPrimDouble: {
1389 locations->SetInAt(0, Location::RequiresFpuRegister());
Alexandre Rames93415462015-02-17 15:08:20 +00001390 HInstruction* right = compare->InputAt(1);
1391 if ((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1392 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0))) {
1393 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1394 } else {
1395 locations->SetInAt(1, Location::RequiresFpuRegister());
1396 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001397 locations->SetOut(Location::RequiresRegister());
1398 break;
1399 }
1400 default:
1401 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1402 }
1403}
1404
1405void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) {
1406 Primitive::Type in_type = compare->InputAt(0)->GetType();
1407
1408 // 0 if: left == right
1409 // 1 if: left > right
1410 // -1 if: left < right
1411 switch (in_type) {
1412 case Primitive::kPrimLong: {
1413 Register result = OutputRegister(compare);
1414 Register left = InputRegisterAt(compare, 0);
1415 Operand right = InputOperandAt(compare, 1);
1416
1417 __ Cmp(left, right);
1418 __ Cset(result, ne);
1419 __ Cneg(result, result, lt);
1420 break;
1421 }
1422 case Primitive::kPrimFloat:
1423 case Primitive::kPrimDouble: {
1424 Register result = OutputRegister(compare);
1425 FPRegister left = InputFPRegisterAt(compare, 0);
Alexandre Rames93415462015-02-17 15:08:20 +00001426 if (compare->GetLocations()->InAt(1).IsConstant()) {
1427 if (kIsDebugBuild) {
1428 HInstruction* right = compare->GetLocations()->InAt(1).GetConstant();
1429 DCHECK((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1430 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0)));
1431 }
1432 // 0.0 is the only immediate that can be encoded directly in a FCMP instruction.
1433 __ Fcmp(left, 0.0);
1434 } else {
1435 __ Fcmp(left, InputFPRegisterAt(compare, 1));
1436 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001437 if (compare->IsGtBias()) {
1438 __ Cset(result, ne);
1439 } else {
1440 __ Csetm(result, ne);
1441 }
1442 __ Cneg(result, result, compare->IsGtBias() ? mi : gt);
Alexandre Rames5319def2014-10-23 10:03:10 +01001443 break;
1444 }
1445 default:
1446 LOG(FATAL) << "Unimplemented compare type " << in_type;
1447 }
1448}
1449
1450void LocationsBuilderARM64::VisitCondition(HCondition* instruction) {
1451 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1452 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001453 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames5319def2014-10-23 10:03:10 +01001454 if (instruction->NeedsMaterialization()) {
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001455 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001456 }
1457}
1458
1459void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) {
1460 if (!instruction->NeedsMaterialization()) {
1461 return;
1462 }
1463
1464 LocationSummary* locations = instruction->GetLocations();
1465 Register lhs = InputRegisterAt(instruction, 0);
1466 Operand rhs = InputOperandAt(instruction, 1);
1467 Register res = RegisterFrom(locations->Out(), instruction->GetType());
1468 Condition cond = ARM64Condition(instruction->GetCondition());
1469
1470 __ Cmp(lhs, rhs);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001471 __ Cset(res, cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001472}
1473
1474#define FOR_EACH_CONDITION_INSTRUCTION(M) \
1475 M(Equal) \
1476 M(NotEqual) \
1477 M(LessThan) \
1478 M(LessThanOrEqual) \
1479 M(GreaterThan) \
1480 M(GreaterThanOrEqual)
1481#define DEFINE_CONDITION_VISITORS(Name) \
1482void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \
1483void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); }
1484FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS)
Alexandre Rames67555f72014-11-18 10:55:16 +00001485#undef DEFINE_CONDITION_VISITORS
Alexandre Rames5319def2014-10-23 10:03:10 +01001486#undef FOR_EACH_CONDITION_INSTRUCTION
1487
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001488void LocationsBuilderARM64::VisitDiv(HDiv* div) {
1489 LocationSummary* locations =
1490 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1491 switch (div->GetResultType()) {
1492 case Primitive::kPrimInt:
1493 case Primitive::kPrimLong:
1494 locations->SetInAt(0, Location::RequiresRegister());
1495 locations->SetInAt(1, Location::RequiresRegister());
1496 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1497 break;
1498
1499 case Primitive::kPrimFloat:
1500 case Primitive::kPrimDouble:
1501 locations->SetInAt(0, Location::RequiresFpuRegister());
1502 locations->SetInAt(1, Location::RequiresFpuRegister());
1503 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1504 break;
1505
1506 default:
1507 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1508 }
1509}
1510
1511void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) {
1512 Primitive::Type type = div->GetResultType();
1513 switch (type) {
1514 case Primitive::kPrimInt:
1515 case Primitive::kPrimLong:
1516 __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1));
1517 break;
1518
1519 case Primitive::kPrimFloat:
1520 case Primitive::kPrimDouble:
1521 __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1));
1522 break;
1523
1524 default:
1525 LOG(FATAL) << "Unexpected div type " << type;
1526 }
1527}
1528
Alexandre Rames67555f72014-11-18 10:55:16 +00001529void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1530 LocationSummary* locations =
1531 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1532 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1533 if (instruction->HasUses()) {
1534 locations->SetOut(Location::SameAsFirstInput());
1535 }
1536}
1537
1538void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1539 SlowPathCodeARM64* slow_path =
1540 new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction);
1541 codegen_->AddSlowPath(slow_path);
1542 Location value = instruction->GetLocations()->InAt(0);
1543
Alexandre Rames3e69f162014-12-10 10:36:50 +00001544 Primitive::Type type = instruction->GetType();
1545
1546 if ((type != Primitive::kPrimInt) && (type != Primitive::kPrimLong)) {
1547 LOG(FATAL) << "Unexpected type " << type << "for DivZeroCheck.";
1548 return;
1549 }
1550
Alexandre Rames67555f72014-11-18 10:55:16 +00001551 if (value.IsConstant()) {
1552 int64_t divisor = Int64ConstantFrom(value);
1553 if (divisor == 0) {
1554 __ B(slow_path->GetEntryLabel());
1555 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001556 // A division by a non-null constant is valid. We don't need to perform
1557 // any check, so simply fall through.
Alexandre Rames67555f72014-11-18 10:55:16 +00001558 }
1559 } else {
1560 __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel());
1561 }
1562}
1563
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001564void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1565 LocationSummary* locations =
1566 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1567 locations->SetOut(Location::ConstantLocation(constant));
1568}
1569
1570void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1571 UNUSED(constant);
1572 // Will be generated at use site.
1573}
1574
Alexandre Rames5319def2014-10-23 10:03:10 +01001575void LocationsBuilderARM64::VisitExit(HExit* exit) {
1576 exit->SetLocations(nullptr);
1577}
1578
1579void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001580 UNUSED(exit);
Alexandre Rames5319def2014-10-23 10:03:10 +01001581}
1582
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001583void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) {
1584 LocationSummary* locations =
1585 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1586 locations->SetOut(Location::ConstantLocation(constant));
1587}
1588
1589void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) {
1590 UNUSED(constant);
1591 // Will be generated at use site.
1592}
1593
Alexandre Rames5319def2014-10-23 10:03:10 +01001594void LocationsBuilderARM64::VisitGoto(HGoto* got) {
1595 got->SetLocations(nullptr);
1596}
1597
1598void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) {
1599 HBasicBlock* successor = got->GetSuccessor();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001600 DCHECK(!successor->IsExitBlock());
1601 HBasicBlock* block = got->GetBlock();
1602 HInstruction* previous = got->GetPrevious();
1603 HLoopInformation* info = block->GetLoopInformation();
1604
David Brazdil46e2a392015-03-16 17:31:52 +00001605 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001606 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1607 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1608 return;
1609 }
1610 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1611 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1612 }
1613 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001614 __ B(codegen_->GetLabelOf(successor));
1615 }
1616}
1617
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001618void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction,
1619 vixl::Label* true_target,
1620 vixl::Label* false_target,
1621 vixl::Label* always_true_target) {
1622 HInstruction* cond = instruction->InputAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001623 HCondition* condition = cond->AsCondition();
Alexandre Rames5319def2014-10-23 10:03:10 +01001624
Serban Constantinescu02164b32014-11-13 14:05:07 +00001625 if (cond->IsIntConstant()) {
1626 int32_t cond_value = cond->AsIntConstant()->GetValue();
1627 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001628 if (always_true_target != nullptr) {
1629 __ B(always_true_target);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001630 }
1631 return;
1632 } else {
1633 DCHECK_EQ(cond_value, 0);
1634 }
1635 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001636 // The condition instruction has been materialized, compare the output to 0.
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001637 Location cond_val = instruction->GetLocations()->InAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001638 DCHECK(cond_val.IsRegister());
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001639 __ Cbnz(InputRegisterAt(instruction, 0), true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001640 } else {
1641 // The condition instruction has not been materialized, use its inputs as
1642 // the comparison and its condition as the branch condition.
1643 Register lhs = InputRegisterAt(condition, 0);
1644 Operand rhs = InputOperandAt(condition, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001645 Condition arm64_cond = ARM64Condition(condition->GetCondition());
Alexandre Rames4388dcc2015-02-03 10:28:33 +00001646 if ((arm64_cond != gt && arm64_cond != le) && rhs.IsImmediate() && (rhs.immediate() == 0)) {
1647 switch (arm64_cond) {
1648 case eq:
1649 __ Cbz(lhs, true_target);
1650 break;
1651 case ne:
1652 __ Cbnz(lhs, true_target);
1653 break;
1654 case lt:
1655 // Test the sign bit and branch accordingly.
1656 __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1657 break;
1658 case ge:
1659 // Test the sign bit and branch accordingly.
1660 __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1661 break;
1662 default:
1663 // Without the `static_cast` the compiler throws an error for
1664 // `-Werror=sign-promo`.
1665 LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001666 }
1667 } else {
1668 __ Cmp(lhs, rhs);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001669 __ B(arm64_cond, true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001670 }
1671 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001672 if (false_target != nullptr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001673 __ B(false_target);
1674 }
1675}
1676
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001677void LocationsBuilderARM64::VisitIf(HIf* if_instr) {
1678 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1679 HInstruction* cond = if_instr->InputAt(0);
1680 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1681 locations->SetInAt(0, Location::RequiresRegister());
1682 }
1683}
1684
1685void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) {
1686 vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1687 vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1688 vixl::Label* always_true_target = true_target;
1689 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1690 if_instr->IfTrueSuccessor())) {
1691 always_true_target = nullptr;
1692 }
1693 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1694 if_instr->IfFalseSuccessor())) {
1695 false_target = nullptr;
1696 }
1697 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1698}
1699
1700void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1701 LocationSummary* locations = new (GetGraph()->GetArena())
1702 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1703 HInstruction* cond = deoptimize->InputAt(0);
1704 DCHECK(cond->IsCondition());
1705 if (cond->AsCondition()->NeedsMaterialization()) {
1706 locations->SetInAt(0, Location::RequiresRegister());
1707 }
1708}
1709
1710void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1711 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena())
1712 DeoptimizationSlowPathARM64(deoptimize);
1713 codegen_->AddSlowPath(slow_path);
1714 vixl::Label* slow_path_entry = slow_path->GetEntryLabel();
1715 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1716}
1717
Alexandre Rames5319def2014-10-23 10:03:10 +01001718void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001719 LocationSummary* locations =
1720 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Rames5319def2014-10-23 10:03:10 +01001721 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001722 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001723}
1724
1725void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001726 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), instruction->GetFieldOffset());
Serban Constantinescu579885a2015-02-22 20:51:33 +00001727 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001728
1729 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00001730 if (use_acquire_release) {
Calin Juravle77520bc2015-01-12 18:45:46 +00001731 // NB: LoadAcquire will record the pc info if needed.
1732 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001733 } else {
1734 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
Calin Juravle77520bc2015-01-12 18:45:46 +00001735 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001736 // For IRIW sequential consistency kLoadAny is not sufficient.
1737 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1738 }
1739 } else {
1740 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
Calin Juravle77520bc2015-01-12 18:45:46 +00001741 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001742 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001743}
1744
1745void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001746 LocationSummary* locations =
1747 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Rames5319def2014-10-23 10:03:10 +01001748 locations->SetInAt(0, Location::RequiresRegister());
1749 locations->SetInAt(1, Location::RequiresRegister());
1750}
1751
1752void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001753 Register obj = InputRegisterAt(instruction, 0);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001754 CPURegister value = InputCPURegisterAt(instruction, 1);
1755 Offset offset = instruction->GetFieldOffset();
1756 Primitive::Type field_type = instruction->GetFieldType();
Serban Constantinescu579885a2015-02-22 20:51:33 +00001757 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001758
1759 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00001760 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001761 codegen_->StoreRelease(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001762 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001763 } else {
1764 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
1765 codegen_->Store(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001766 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001767 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1768 }
1769 } else {
1770 codegen_->Store(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001771 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001772 }
1773
1774 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001775 codegen_->MarkGCCard(obj, Register(value));
Alexandre Rames5319def2014-10-23 10:03:10 +01001776 }
1777}
1778
Alexandre Rames67555f72014-11-18 10:55:16 +00001779void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) {
1780 LocationSummary::CallKind call_kind =
1781 instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
1782 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
1783 locations->SetInAt(0, Location::RequiresRegister());
1784 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001785 // The output does overlap inputs.
1786 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexandre Rames67555f72014-11-18 10:55:16 +00001787}
1788
1789void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) {
1790 LocationSummary* locations = instruction->GetLocations();
1791 Register obj = InputRegisterAt(instruction, 0);;
1792 Register cls = InputRegisterAt(instruction, 1);;
1793 Register out = OutputRegister(instruction);
1794
1795 vixl::Label done;
1796
1797 // Return 0 if `obj` is null.
1798 // TODO: Avoid this check if we know `obj` is not null.
1799 __ Mov(out, 0);
1800 __ Cbz(obj, &done);
1801
1802 // Compare the class of `obj` with `cls`.
Serban Constantinescu02164b32014-11-13 14:05:07 +00001803 __ Ldr(out, HeapOperand(obj, mirror::Object::ClassOffset()));
Alexandre Rames67555f72014-11-18 10:55:16 +00001804 __ Cmp(out, cls);
1805 if (instruction->IsClassFinal()) {
1806 // Classes must be equal for the instanceof to succeed.
1807 __ Cset(out, eq);
1808 } else {
1809 // If the classes are not equal, we go into a slow path.
1810 DCHECK(locations->OnlyCallsOnSlowPath());
1811 SlowPathCodeARM64* slow_path =
Alexandre Rames3e69f162014-12-10 10:36:50 +00001812 new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1813 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001814 codegen_->AddSlowPath(slow_path);
1815 __ B(ne, slow_path->GetEntryLabel());
1816 __ Mov(out, 1);
1817 __ Bind(slow_path->GetExitLabel());
1818 }
1819
1820 __ Bind(&done);
1821}
1822
Alexandre Rames5319def2014-10-23 10:03:10 +01001823void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) {
1824 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1825 locations->SetOut(Location::ConstantLocation(constant));
1826}
1827
1828void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) {
1829 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001830 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01001831}
1832
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001833void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) {
1834 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1835 locations->SetOut(Location::ConstantLocation(constant));
1836}
1837
1838void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant) {
1839 // Will be generated at use site.
1840 UNUSED(constant);
1841}
1842
Alexandre Rames5319def2014-10-23 10:03:10 +01001843void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) {
1844 LocationSummary* locations =
1845 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
1846 locations->AddTemp(LocationFrom(x0));
1847
1848 InvokeDexCallingConventionVisitor calling_convention_visitor;
1849 for (size_t i = 0; i < invoke->InputCount(); i++) {
1850 HInstruction* input = invoke->InputAt(i);
1851 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1852 }
1853
1854 Primitive::Type return_type = invoke->GetType();
1855 if (return_type != Primitive::kPrimVoid) {
1856 locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type));
1857 }
1858}
1859
Alexandre Rames67555f72014-11-18 10:55:16 +00001860void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1861 HandleInvoke(invoke);
1862}
1863
1864void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1865 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1866 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
1867 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1868 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1869 Location receiver = invoke->GetLocations()->InAt(0);
1870 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001871 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames67555f72014-11-18 10:55:16 +00001872
1873 // The register ip1 is required to be used for the hidden argument in
1874 // art_quick_imt_conflict_trampoline, so prevent VIXL from using it.
1875 UseScratchRegisterScope scratch_scope(GetVIXLAssembler());
1876 scratch_scope.Exclude(ip1);
1877 __ Mov(ip1, invoke->GetDexMethodIndex());
1878
1879 // temp = object->GetClass();
1880 if (receiver.IsStackSlot()) {
1881 __ Ldr(temp, StackOperandFrom(receiver));
1882 __ Ldr(temp, HeapOperand(temp, class_offset));
1883 } else {
1884 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
1885 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001886 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames67555f72014-11-18 10:55:16 +00001887 // temp = temp->GetImtEntryAt(method_offset);
1888 __ Ldr(temp, HeapOperand(temp, method_offset));
1889 // lr = temp->GetEntryPoint();
1890 __ Ldr(lr, HeapOperand(temp, entry_point));
1891 // lr();
1892 __ Blr(lr);
1893 DCHECK(!codegen_->IsLeafMethod());
1894 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1895}
1896
1897void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001898 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1899 if (intrinsic.TryDispatch(invoke)) {
1900 return;
1901 }
1902
Alexandre Rames67555f72014-11-18 10:55:16 +00001903 HandleInvoke(invoke);
1904}
1905
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001906void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001907 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1908 if (intrinsic.TryDispatch(invoke)) {
1909 return;
1910 }
1911
Alexandre Rames67555f72014-11-18 10:55:16 +00001912 HandleInvoke(invoke);
1913}
1914
Andreas Gampe878d58c2015-01-15 23:24:00 -08001915static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) {
1916 if (invoke->GetLocations()->Intrinsified()) {
1917 IntrinsicCodeGeneratorARM64 intrinsic(codegen);
1918 intrinsic.Dispatch(invoke);
1919 return true;
1920 }
1921 return false;
1922}
1923
1924void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
1925 // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention.
1926 DCHECK(temp.Is(kArtMethodRegister));
Alexandre Rames5319def2014-10-23 10:03:10 +01001927 size_t index_in_cache = mirror::Array::DataOffset(kHeapRefSize).SizeValue() +
Andreas Gampe878d58c2015-01-15 23:24:00 -08001928 invoke->GetDexMethodIndex() * kHeapRefSize;
Alexandre Rames5319def2014-10-23 10:03:10 +01001929
1930 // TODO: Implement all kinds of calls:
1931 // 1) boot -> boot
1932 // 2) app -> boot
1933 // 3) app -> app
1934 //
1935 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1936
Nicolas Geoffray0a299b92015-01-29 11:39:44 +00001937 // temp = method;
1938 LoadCurrentMethod(temp);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001939 if (!invoke->IsRecursive()) {
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001940 // temp = temp->dex_cache_resolved_methods_;
1941 __ Ldr(temp, HeapOperand(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset()));
1942 // temp = temp[index_in_cache];
1943 __ Ldr(temp, HeapOperand(temp, index_in_cache));
1944 // lr = temp->entry_point_from_quick_compiled_code_;
1945 __ Ldr(lr, HeapOperand(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1946 kArm64WordSize)));
1947 // lr();
1948 __ Blr(lr);
1949 } else {
1950 __ Bl(&frame_entry_label_);
1951 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001952
Andreas Gampe878d58c2015-01-15 23:24:00 -08001953 DCHECK(!IsLeafMethod());
1954}
1955
1956void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
1957 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1958 return;
1959 }
1960
1961 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
1962 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001963 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Alexandre Rames5319def2014-10-23 10:03:10 +01001964}
1965
1966void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001967 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1968 return;
1969 }
1970
Alexandre Rames5319def2014-10-23 10:03:10 +01001971 LocationSummary* locations = invoke->GetLocations();
1972 Location receiver = locations->InAt(0);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001973 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
Alexandre Rames5319def2014-10-23 10:03:10 +01001974 size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() +
1975 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1976 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001977 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames5319def2014-10-23 10:03:10 +01001978
1979 // temp = object->GetClass();
1980 if (receiver.IsStackSlot()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001981 __ Ldr(temp, MemOperand(sp, receiver.GetStackIndex()));
1982 __ Ldr(temp, HeapOperand(temp, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01001983 } else {
1984 DCHECK(receiver.IsRegister());
Serban Constantinescu02164b32014-11-13 14:05:07 +00001985 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01001986 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001987 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames5319def2014-10-23 10:03:10 +01001988 // temp = temp->GetMethodAt(method_offset);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001989 __ Ldr(temp, HeapOperand(temp, method_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01001990 // lr = temp->GetEntryPoint();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001991 __ Ldr(lr, HeapOperand(temp, entry_point.SizeValue()));
Alexandre Rames5319def2014-10-23 10:03:10 +01001992 // lr();
1993 __ Blr(lr);
1994 DCHECK(!codegen_->IsLeafMethod());
1995 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1996}
1997
Alexandre Rames67555f72014-11-18 10:55:16 +00001998void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) {
1999 LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath
2000 : LocationSummary::kNoCall;
2001 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
2002 locations->SetOut(Location::RequiresRegister());
2003}
2004
2005void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) {
2006 Register out = OutputRegister(cls);
2007 if (cls->IsReferrersClass()) {
2008 DCHECK(!cls->CanCallRuntime());
2009 DCHECK(!cls->MustGenerateClinitCheck());
2010 codegen_->LoadCurrentMethod(out);
2011 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2012 } else {
2013 DCHECK(cls->CanCallRuntime());
2014 codegen_->LoadCurrentMethod(out);
2015 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DexCacheResolvedTypesOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002016 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002017
2018 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
2019 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2020 codegen_->AddSlowPath(slow_path);
2021 __ Cbz(out, slow_path->GetEntryLabel());
2022 if (cls->MustGenerateClinitCheck()) {
2023 GenerateClassInitializationCheck(slow_path, out);
2024 } else {
2025 __ Bind(slow_path->GetExitLabel());
2026 }
2027 }
2028}
2029
2030void LocationsBuilderARM64::VisitLoadException(HLoadException* load) {
2031 LocationSummary* locations =
2032 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2033 locations->SetOut(Location::RequiresRegister());
2034}
2035
2036void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) {
2037 MemOperand exception = MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value());
2038 __ Ldr(OutputRegister(instruction), exception);
2039 __ Str(wzr, exception);
2040}
2041
Alexandre Rames5319def2014-10-23 10:03:10 +01002042void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) {
2043 load->SetLocations(nullptr);
2044}
2045
2046void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) {
2047 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002048 UNUSED(load);
Alexandre Rames5319def2014-10-23 10:03:10 +01002049}
2050
Alexandre Rames67555f72014-11-18 10:55:16 +00002051void LocationsBuilderARM64::VisitLoadString(HLoadString* load) {
2052 LocationSummary* locations =
2053 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2054 locations->SetOut(Location::RequiresRegister());
2055}
2056
2057void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) {
2058 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load);
2059 codegen_->AddSlowPath(slow_path);
2060
2061 Register out = OutputRegister(load);
2062 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08002063 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2064 __ Ldr(out, HeapOperand(out, mirror::Class::DexCacheStringsOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002065 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002066 __ Cbz(out, slow_path->GetEntryLabel());
2067 __ Bind(slow_path->GetExitLabel());
2068}
2069
Alexandre Rames5319def2014-10-23 10:03:10 +01002070void LocationsBuilderARM64::VisitLocal(HLocal* local) {
2071 local->SetLocations(nullptr);
2072}
2073
2074void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) {
2075 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2076}
2077
2078void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) {
2079 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2080 locations->SetOut(Location::ConstantLocation(constant));
2081}
2082
2083void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) {
2084 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002085 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01002086}
2087
Alexandre Rames67555f72014-11-18 10:55:16 +00002088void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2089 LocationSummary* locations =
2090 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2091 InvokeRuntimeCallingConvention calling_convention;
2092 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2093}
2094
2095void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2096 codegen_->InvokeRuntime(instruction->IsEnter()
2097 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2098 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002099 instruction->GetDexPc(),
2100 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002101 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002102}
2103
Alexandre Rames42d641b2014-10-27 14:00:51 +00002104void LocationsBuilderARM64::VisitMul(HMul* mul) {
2105 LocationSummary* locations =
2106 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2107 switch (mul->GetResultType()) {
2108 case Primitive::kPrimInt:
2109 case Primitive::kPrimLong:
2110 locations->SetInAt(0, Location::RequiresRegister());
2111 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002112 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002113 break;
2114
2115 case Primitive::kPrimFloat:
2116 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002117 locations->SetInAt(0, Location::RequiresFpuRegister());
2118 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00002119 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002120 break;
2121
2122 default:
2123 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2124 }
2125}
2126
2127void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) {
2128 switch (mul->GetResultType()) {
2129 case Primitive::kPrimInt:
2130 case Primitive::kPrimLong:
2131 __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1));
2132 break;
2133
2134 case Primitive::kPrimFloat:
2135 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002136 __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1));
Alexandre Rames42d641b2014-10-27 14:00:51 +00002137 break;
2138
2139 default:
2140 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2141 }
2142}
2143
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002144void LocationsBuilderARM64::VisitNeg(HNeg* neg) {
2145 LocationSummary* locations =
2146 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2147 switch (neg->GetResultType()) {
2148 case Primitive::kPrimInt:
Alexandre Rames67555f72014-11-18 10:55:16 +00002149 case Primitive::kPrimLong:
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00002150 locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg));
Alexandre Rames67555f72014-11-18 10:55:16 +00002151 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002152 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002153
2154 case Primitive::kPrimFloat:
2155 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002156 locations->SetInAt(0, Location::RequiresFpuRegister());
2157 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002158 break;
2159
2160 default:
2161 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2162 }
2163}
2164
2165void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) {
2166 switch (neg->GetResultType()) {
2167 case Primitive::kPrimInt:
2168 case Primitive::kPrimLong:
2169 __ Neg(OutputRegister(neg), InputOperandAt(neg, 0));
2170 break;
2171
2172 case Primitive::kPrimFloat:
2173 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002174 __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002175 break;
2176
2177 default:
2178 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2179 }
2180}
2181
2182void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) {
2183 LocationSummary* locations =
2184 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2185 InvokeRuntimeCallingConvention calling_convention;
2186 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002187 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002188 locations->SetOut(LocationFrom(x0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002189 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1)));
2190 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2191 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002192}
2193
2194void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) {
2195 LocationSummary* locations = instruction->GetLocations();
2196 InvokeRuntimeCallingConvention calling_convention;
2197 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2198 DCHECK(type_index.Is(w0));
2199 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002200 DCHECK(current_method.Is(w2));
Alexandre Rames67555f72014-11-18 10:55:16 +00002201 codegen_->LoadCurrentMethod(current_method);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002202 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002203 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002204 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2205 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002206 instruction->GetDexPc(),
2207 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002208 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2209 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002210}
2211
Alexandre Rames5319def2014-10-23 10:03:10 +01002212void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) {
2213 LocationSummary* locations =
2214 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2215 InvokeRuntimeCallingConvention calling_convention;
2216 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
2217 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1)));
2218 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002219 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002220}
2221
2222void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
2223 LocationSummary* locations = instruction->GetLocations();
2224 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2225 DCHECK(type_index.Is(w0));
2226 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
2227 DCHECK(current_method.Is(w1));
Alexandre Rames67555f72014-11-18 10:55:16 +00002228 codegen_->LoadCurrentMethod(current_method);
Alexandre Rames5319def2014-10-23 10:03:10 +01002229 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002230 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002231 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2232 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002233 instruction->GetDexPc(),
2234 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002235 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002236}
2237
2238void LocationsBuilderARM64::VisitNot(HNot* instruction) {
2239 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexandre Rames4e596512014-11-07 15:56:50 +00002240 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002241 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01002242}
2243
2244void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) {
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002245 switch (instruction->GetResultType()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002246 case Primitive::kPrimInt:
Alexandre Rames5319def2014-10-23 10:03:10 +01002247 case Primitive::kPrimLong:
Roland Levillain55dcfb52014-10-24 18:09:09 +01002248 __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002249 break;
2250
2251 default:
2252 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2253 }
2254}
2255
David Brazdil66d126e2015-04-03 16:02:44 +01002256void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) {
2257 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2258 locations->SetInAt(0, Location::RequiresRegister());
2259 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2260}
2261
2262void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) {
David Brazdil66d126e2015-04-03 16:02:44 +01002263 __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1));
2264}
2265
Alexandre Rames5319def2014-10-23 10:03:10 +01002266void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) {
2267 LocationSummary* locations =
2268 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2269 locations->SetInAt(0, Location::RequiresRegister());
2270 if (instruction->HasUses()) {
2271 locations->SetOut(Location::SameAsFirstInput());
2272 }
2273}
2274
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002275void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002276 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2277 return;
2278 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002279 Location obj = instruction->GetLocations()->InAt(0);
2280
2281 __ Ldr(wzr, HeapOperandFrom(obj, Offset(0)));
2282 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2283}
2284
2285void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002286 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction);
2287 codegen_->AddSlowPath(slow_path);
2288
2289 LocationSummary* locations = instruction->GetLocations();
2290 Location obj = locations->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002291
2292 __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel());
Alexandre Rames5319def2014-10-23 10:03:10 +01002293}
2294
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002295void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) {
2296 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2297 GenerateImplicitNullCheck(instruction);
2298 } else {
2299 GenerateExplicitNullCheck(instruction);
2300 }
2301}
2302
Alexandre Rames67555f72014-11-18 10:55:16 +00002303void LocationsBuilderARM64::VisitOr(HOr* instruction) {
2304 HandleBinaryOp(instruction);
2305}
2306
2307void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) {
2308 HandleBinaryOp(instruction);
2309}
2310
Alexandre Rames3e69f162014-12-10 10:36:50 +00002311void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2312 LOG(FATAL) << "Unreachable";
2313}
2314
2315void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) {
2316 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2317}
2318
Alexandre Rames5319def2014-10-23 10:03:10 +01002319void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) {
2320 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2321 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2322 if (location.IsStackSlot()) {
2323 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2324 } else if (location.IsDoubleStackSlot()) {
2325 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2326 }
2327 locations->SetOut(location);
2328}
2329
2330void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) {
2331 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002332 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002333}
2334
2335void LocationsBuilderARM64::VisitPhi(HPhi* instruction) {
2336 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2337 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2338 locations->SetInAt(i, Location::Any());
2339 }
2340 locations->SetOut(Location::Any());
2341}
2342
2343void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002344 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002345 LOG(FATAL) << "Unreachable";
2346}
2347
Serban Constantinescu02164b32014-11-13 14:05:07 +00002348void LocationsBuilderARM64::VisitRem(HRem* rem) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002349 Primitive::Type type = rem->GetResultType();
Alexandre Rames542361f2015-01-29 16:57:31 +00002350 LocationSummary::CallKind call_kind =
2351 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002352 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2353
2354 switch (type) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002355 case Primitive::kPrimInt:
2356 case Primitive::kPrimLong:
2357 locations->SetInAt(0, Location::RequiresRegister());
2358 locations->SetInAt(1, Location::RequiresRegister());
2359 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2360 break;
2361
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002362 case Primitive::kPrimFloat:
2363 case Primitive::kPrimDouble: {
2364 InvokeRuntimeCallingConvention calling_convention;
2365 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
2366 locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1)));
2367 locations->SetOut(calling_convention.GetReturnLocation(type));
2368
2369 break;
2370 }
2371
Serban Constantinescu02164b32014-11-13 14:05:07 +00002372 default:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002373 LOG(FATAL) << "Unexpected rem type " << type;
Serban Constantinescu02164b32014-11-13 14:05:07 +00002374 }
2375}
2376
2377void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) {
2378 Primitive::Type type = rem->GetResultType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002379
Serban Constantinescu02164b32014-11-13 14:05:07 +00002380 switch (type) {
2381 case Primitive::kPrimInt:
2382 case Primitive::kPrimLong: {
2383 UseScratchRegisterScope temps(GetVIXLAssembler());
2384 Register dividend = InputRegisterAt(rem, 0);
2385 Register divisor = InputRegisterAt(rem, 1);
2386 Register output = OutputRegister(rem);
2387 Register temp = temps.AcquireSameSizeAs(output);
2388
2389 __ Sdiv(temp, dividend, divisor);
2390 __ Msub(output, temp, divisor, dividend);
2391 break;
2392 }
2393
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002394 case Primitive::kPrimFloat:
2395 case Primitive::kPrimDouble: {
2396 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
2397 : QUICK_ENTRY_POINT(pFmod);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002398 codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002399 break;
2400 }
2401
Serban Constantinescu02164b32014-11-13 14:05:07 +00002402 default:
2403 LOG(FATAL) << "Unexpected rem type " << type;
2404 }
2405}
2406
Alexandre Rames5319def2014-10-23 10:03:10 +01002407void LocationsBuilderARM64::VisitReturn(HReturn* instruction) {
2408 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2409 Primitive::Type return_type = instruction->InputAt(0)->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002410 locations->SetInAt(0, ARM64ReturnLocation(return_type));
Alexandre Rames5319def2014-10-23 10:03:10 +01002411}
2412
2413void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002414 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002415 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002416}
2417
2418void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) {
2419 instruction->SetLocations(nullptr);
2420}
2421
2422void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002423 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002424 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002425}
2426
Serban Constantinescu02164b32014-11-13 14:05:07 +00002427void LocationsBuilderARM64::VisitShl(HShl* shl) {
2428 HandleShift(shl);
2429}
2430
2431void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) {
2432 HandleShift(shl);
2433}
2434
2435void LocationsBuilderARM64::VisitShr(HShr* shr) {
2436 HandleShift(shr);
2437}
2438
2439void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) {
2440 HandleShift(shr);
2441}
2442
Alexandre Rames5319def2014-10-23 10:03:10 +01002443void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) {
2444 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
2445 Primitive::Type field_type = store->InputAt(1)->GetType();
2446 switch (field_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002447 case Primitive::kPrimNot:
Alexandre Rames5319def2014-10-23 10:03:10 +01002448 case Primitive::kPrimBoolean:
2449 case Primitive::kPrimByte:
2450 case Primitive::kPrimChar:
2451 case Primitive::kPrimShort:
2452 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002453 case Primitive::kPrimFloat:
Alexandre Rames5319def2014-10-23 10:03:10 +01002454 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
2455 break;
2456
2457 case Primitive::kPrimLong:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002458 case Primitive::kPrimDouble:
Alexandre Rames5319def2014-10-23 10:03:10 +01002459 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
2460 break;
2461
2462 default:
2463 LOG(FATAL) << "Unimplemented local type " << field_type;
2464 }
2465}
2466
2467void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002468 UNUSED(store);
Alexandre Rames5319def2014-10-23 10:03:10 +01002469}
2470
2471void LocationsBuilderARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002472 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002473}
2474
2475void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002476 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002477}
2478
Alexandre Rames67555f72014-11-18 10:55:16 +00002479void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2480 LocationSummary* locations =
2481 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2482 locations->SetInAt(0, Location::RequiresRegister());
2483 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2484}
2485
2486void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002487 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), instruction->GetFieldOffset());
Serban Constantinescu579885a2015-02-22 20:51:33 +00002488 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002489
2490 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00002491 if (use_acquire_release) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002492 // NB: LoadAcquire will record the pc info if needed.
2493 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002494 } else {
2495 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
2496 // For IRIW sequential consistency kLoadAny is not sufficient.
2497 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2498 }
2499 } else {
2500 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
2501 }
Alexandre Rames67555f72014-11-18 10:55:16 +00002502}
2503
2504void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002505 LocationSummary* locations =
2506 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2507 locations->SetInAt(0, Location::RequiresRegister());
2508 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames5319def2014-10-23 10:03:10 +01002509}
2510
Alexandre Rames67555f72014-11-18 10:55:16 +00002511void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002512 Register cls = InputRegisterAt(instruction, 0);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002513 CPURegister value = InputCPURegisterAt(instruction, 1);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002514 Offset offset = instruction->GetFieldOffset();
Alexandre Rames67555f72014-11-18 10:55:16 +00002515 Primitive::Type field_type = instruction->GetFieldType();
Serban Constantinescu579885a2015-02-22 20:51:33 +00002516 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Alexandre Rames5319def2014-10-23 10:03:10 +01002517
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002518 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00002519 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002520 codegen_->StoreRelease(field_type, value, HeapOperand(cls, offset));
2521 } else {
2522 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2523 codegen_->Store(field_type, value, HeapOperand(cls, offset));
2524 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2525 }
2526 } else {
2527 codegen_->Store(field_type, value, HeapOperand(cls, offset));
2528 }
2529
2530 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002531 codegen_->MarkGCCard(cls, Register(value));
2532 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002533}
2534
2535void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
2536 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2537}
2538
2539void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002540 HBasicBlock* block = instruction->GetBlock();
2541 if (block->GetLoopInformation() != nullptr) {
2542 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2543 // The back edge will generate the suspend check.
2544 return;
2545 }
2546 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2547 // The goto will generate the suspend check.
2548 return;
2549 }
2550 GenerateSuspendCheck(instruction, nullptr);
Alexandre Rames5319def2014-10-23 10:03:10 +01002551}
2552
2553void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) {
2554 temp->SetLocations(nullptr);
2555}
2556
2557void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) {
2558 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002559 UNUSED(temp);
Alexandre Rames5319def2014-10-23 10:03:10 +01002560}
2561
Alexandre Rames67555f72014-11-18 10:55:16 +00002562void LocationsBuilderARM64::VisitThrow(HThrow* instruction) {
2563 LocationSummary* locations =
2564 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2565 InvokeRuntimeCallingConvention calling_convention;
2566 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2567}
2568
2569void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) {
2570 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002571 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002572 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002573}
2574
2575void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) {
2576 LocationSummary* locations =
2577 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
2578 Primitive::Type input_type = conversion->GetInputType();
2579 Primitive::Type result_type = conversion->GetResultType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002580 DCHECK_NE(input_type, result_type);
Alexandre Rames67555f72014-11-18 10:55:16 +00002581 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
2582 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
2583 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
2584 }
2585
Alexandre Rames542361f2015-01-29 16:57:31 +00002586 if (Primitive::IsFloatingPointType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002587 locations->SetInAt(0, Location::RequiresFpuRegister());
2588 } else {
2589 locations->SetInAt(0, Location::RequiresRegister());
2590 }
2591
Alexandre Rames542361f2015-01-29 16:57:31 +00002592 if (Primitive::IsFloatingPointType(result_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002593 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2594 } else {
2595 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2596 }
2597}
2598
2599void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) {
2600 Primitive::Type result_type = conversion->GetResultType();
2601 Primitive::Type input_type = conversion->GetInputType();
2602
2603 DCHECK_NE(input_type, result_type);
2604
Alexandre Rames542361f2015-01-29 16:57:31 +00002605 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002606 int result_size = Primitive::ComponentSize(result_type);
2607 int input_size = Primitive::ComponentSize(input_type);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002608 int min_size = std::min(result_size, input_size);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002609 Register output = OutputRegister(conversion);
2610 Register source = InputRegisterAt(conversion, 0);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002611 if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) {
2612 __ Ubfx(output, source, 0, result_size * kBitsPerByte);
2613 } else if ((result_type == Primitive::kPrimChar) ||
2614 ((input_type == Primitive::kPrimChar) && (result_size > input_size))) {
2615 __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002616 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00002617 __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002618 }
Alexandre Rames542361f2015-01-29 16:57:31 +00002619 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002620 __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002621 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002622 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
2623 __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002624 } else if (Primitive::IsFloatingPointType(result_type) &&
2625 Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002626 __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0));
2627 } else {
2628 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
2629 << " to " << result_type;
Alexandre Rames67555f72014-11-18 10:55:16 +00002630 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00002631}
Alexandre Rames67555f72014-11-18 10:55:16 +00002632
Serban Constantinescu02164b32014-11-13 14:05:07 +00002633void LocationsBuilderARM64::VisitUShr(HUShr* ushr) {
2634 HandleShift(ushr);
2635}
2636
2637void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) {
2638 HandleShift(ushr);
Alexandre Rames67555f72014-11-18 10:55:16 +00002639}
2640
2641void LocationsBuilderARM64::VisitXor(HXor* instruction) {
2642 HandleBinaryOp(instruction);
2643}
2644
2645void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) {
2646 HandleBinaryOp(instruction);
2647}
2648
Calin Juravleb1498f62015-02-16 13:13:29 +00002649void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction) {
2650 // Nothing to do, this should be removed during prepare for register allocator.
2651 UNUSED(instruction);
2652 LOG(FATAL) << "Unreachable";
2653}
2654
2655void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction) {
2656 // Nothing to do, this should be removed during prepare for register allocator.
2657 UNUSED(instruction);
2658 LOG(FATAL) << "Unreachable";
2659}
2660
Alexandre Rames67555f72014-11-18 10:55:16 +00002661#undef __
2662#undef QUICK_ENTRY_POINT
2663
Alexandre Rames5319def2014-10-23 10:03:10 +01002664} // namespace arm64
2665} // namespace art