blob: 7dfb5952eb08948873e1d3e24128a34bc3ef9821 [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(
125 index_location_, LocationFrom(calling_convention.GetRegisterAt(0)),
126 length_location_, LocationFrom(calling_convention.GetRegisterAt(1)));
127 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(
325 class_to_check_, LocationFrom(calling_convention.GetRegisterAt(0)),
326 object_class_, LocationFrom(calling_convention.GetRegisterAt(1)));
327
328 if (instruction_->IsInstanceOf()) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000329 arm64_codegen->InvokeRuntime(
330 QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_, this);
Alexandre Rames3e69f162014-12-10 10:36:50 +0000331 Primitive::Type ret_type = instruction_->GetType();
332 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
333 arm64_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800334 CheckEntrypointTypes<kQuickInstanceofNonTrivial, uint32_t,
335 const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000336 } else {
337 DCHECK(instruction_->IsCheckCast());
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000338 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_, this);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800339 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
Alexandre Rames3e69f162014-12-10 10:36:50 +0000340 }
341
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000342 RestoreLiveRegisters(codegen, locations);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000343 __ B(GetExitLabel());
Alexandre Rames67555f72014-11-18 10:55:16 +0000344 }
345
346 private:
Alexandre Rames3e69f162014-12-10 10:36:50 +0000347 HInstruction* const instruction_;
348 const Location class_to_check_;
349 const Location object_class_;
350 uint32_t dex_pc_;
351
Alexandre Rames67555f72014-11-18 10:55:16 +0000352 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM64);
353};
354
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700355class DeoptimizationSlowPathARM64 : public SlowPathCodeARM64 {
356 public:
357 explicit DeoptimizationSlowPathARM64(HInstruction* instruction)
358 : instruction_(instruction) {}
359
360 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
361 __ Bind(GetEntryLabel());
362 SaveLiveRegisters(codegen, instruction_->GetLocations());
363 DCHECK(instruction_->IsDeoptimize());
364 HDeoptimize* deoptimize = instruction_->AsDeoptimize();
365 uint32_t dex_pc = deoptimize->GetDexPc();
366 CodeGeneratorARM64* arm64_codegen = down_cast<CodeGeneratorARM64*>(codegen);
367 arm64_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), instruction_, dex_pc, this);
368 }
369
370 private:
371 HInstruction* const instruction_;
372 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathARM64);
373};
374
Alexandre Rames5319def2014-10-23 10:03:10 +0100375#undef __
376
377Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
378 Location next_location;
379 if (type == Primitive::kPrimVoid) {
380 LOG(FATAL) << "Unreachable type " << type;
381 }
382
Alexandre Rames542361f2015-01-29 16:57:31 +0000383 if (Primitive::IsFloatingPointType(type) &&
384 (fp_index_ < calling_convention.GetNumberOfFpuRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000385 next_location = LocationFrom(calling_convention.GetFpuRegisterAt(fp_index_++));
Alexandre Rames542361f2015-01-29 16:57:31 +0000386 } else if (!Primitive::IsFloatingPointType(type) &&
387 (gp_index_ < calling_convention.GetNumberOfRegisters())) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000388 next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_++));
389 } else {
390 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
Alexandre Rames542361f2015-01-29 16:57:31 +0000391 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
392 : Location::StackSlot(stack_offset);
Alexandre Rames5319def2014-10-23 10:03:10 +0100393 }
394
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000395 // Space on the stack is reserved for all arguments.
Alexandre Rames542361f2015-01-29 16:57:31 +0000396 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
Alexandre Rames5319def2014-10-23 10:03:10 +0100397 return next_location;
398}
399
Serban Constantinescu579885a2015-02-22 20:51:33 +0000400CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph,
401 const Arm64InstructionSetFeatures& isa_features,
402 const CompilerOptions& compiler_options)
Alexandre Rames5319def2014-10-23 10:03:10 +0100403 : CodeGenerator(graph,
404 kNumberOfAllocatableRegisters,
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000405 kNumberOfAllocatableFPRegisters,
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000406 kNumberOfAllocatableRegisterPairs,
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000407 callee_saved_core_registers.list(),
408 callee_saved_fp_registers.list(),
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000409 compiler_options),
Alexandre Rames5319def2014-10-23 10:03:10 +0100410 block_labels_(nullptr),
411 location_builder_(graph, this),
Alexandre Rames3e69f162014-12-10 10:36:50 +0000412 instruction_visitor_(graph, this),
Serban Constantinescu579885a2015-02-22 20:51:33 +0000413 move_resolver_(graph->GetArena(), this),
414 isa_features_(isa_features) {
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000415 // Save the link register (containing the return address) to mimic Quick.
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000416 AddAllocatedRegister(LocationFrom(lr));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000417}
Alexandre Rames5319def2014-10-23 10:03:10 +0100418
Alexandre Rames67555f72014-11-18 10:55:16 +0000419#undef __
420#define __ GetVIXLAssembler()->
Alexandre Rames5319def2014-10-23 10:03:10 +0100421
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000422void CodeGeneratorARM64::Finalize(CodeAllocator* allocator) {
423 // Ensure we emit the literal pool.
424 __ FinalizeCode();
425 CodeGenerator::Finalize(allocator);
426}
427
Alexandre Rames3e69f162014-12-10 10:36:50 +0000428void ParallelMoveResolverARM64::EmitMove(size_t index) {
429 MoveOperands* move = moves_.Get(index);
430 codegen_->MoveLocation(move->GetDestination(), move->GetSource());
431}
432
433void ParallelMoveResolverARM64::EmitSwap(size_t index) {
434 MoveOperands* move = moves_.Get(index);
435 codegen_->SwapLocations(move->GetDestination(), move->GetSource());
436}
437
438void ParallelMoveResolverARM64::RestoreScratch(int reg) {
439 __ Pop(Register(VIXLRegCodeFromART(reg), kXRegSize));
440}
441
442void ParallelMoveResolverARM64::SpillScratch(int reg) {
443 __ Push(Register(VIXLRegCodeFromART(reg), kXRegSize));
444}
445
Alexandre Rames5319def2014-10-23 10:03:10 +0100446void CodeGeneratorARM64::GenerateFrameEntry() {
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000447 __ Bind(&frame_entry_label_);
448
Serban Constantinescu02164b32014-11-13 14:05:07 +0000449 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kArm64) || !IsLeafMethod();
450 if (do_overflow_check) {
451 UseScratchRegisterScope temps(GetVIXLAssembler());
452 Register temp = temps.AcquireX();
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000453 DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks());
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000454 __ Sub(temp, sp, static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64)));
Nicolas Geoffrayd97dc402015-01-22 13:50:01 +0000455 __ Ldr(wzr, MemOperand(temp, 0));
456 RecordPcInfo(nullptr, 0);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000457 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100458
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000459 if (!HasEmptyFrame()) {
460 int frame_size = GetFrameSize();
461 // Stack layout:
462 // sp[frame_size - 8] : lr.
463 // ... : other preserved core registers.
464 // ... : other preserved fp registers.
465 // ... : reserved frame space.
466 // sp[0] : current method.
467 __ Str(kArtMethodRegister, MemOperand(sp, -frame_size, PreIndex));
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100468 GetAssembler()->cfi().AdjustCFAOffset(frame_size);
Zheng Xu69a50302015-04-14 20:04:41 +0800469 GetAssembler()->SpillRegisters(GetFramePreservedCoreRegisters(),
470 frame_size - GetCoreSpillSize());
471 GetAssembler()->SpillRegisters(GetFramePreservedFPRegisters(),
472 frame_size - FrameEntrySpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000473 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100474}
475
476void CodeGeneratorARM64::GenerateFrameExit() {
David Srbeckyc34dc932015-04-12 09:27:43 +0100477 GetAssembler()->cfi().RememberState();
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000478 if (!HasEmptyFrame()) {
479 int frame_size = GetFrameSize();
Zheng Xu69a50302015-04-14 20:04:41 +0800480 GetAssembler()->UnspillRegisters(GetFramePreservedFPRegisters(),
481 frame_size - FrameEntrySpillSize());
482 GetAssembler()->UnspillRegisters(GetFramePreservedCoreRegisters(),
483 frame_size - GetCoreSpillSize());
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000484 __ Drop(frame_size);
David Srbeckyc6b4dd82015-04-07 20:32:43 +0100485 GetAssembler()->cfi().AdjustCFAOffset(-frame_size);
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000486 }
David Srbeckyc34dc932015-04-12 09:27:43 +0100487 __ Ret();
488 GetAssembler()->cfi().RestoreState();
489 GetAssembler()->cfi().DefCFAOffset(GetFrameSize());
Alexandre Rames5319def2014-10-23 10:03:10 +0100490}
491
492void CodeGeneratorARM64::Bind(HBasicBlock* block) {
493 __ Bind(GetLabelOf(block));
494}
495
Alexandre Rames5319def2014-10-23 10:03:10 +0100496void CodeGeneratorARM64::Move(HInstruction* instruction,
497 Location location,
498 HInstruction* move_for) {
499 LocationSummary* locations = instruction->GetLocations();
500 if (locations != nullptr && locations->Out().Equals(location)) {
501 return;
502 }
503
504 Primitive::Type type = instruction->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000505 DCHECK_NE(type, Primitive::kPrimVoid);
Alexandre Rames5319def2014-10-23 10:03:10 +0100506
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000507 if (instruction->IsIntConstant()
508 || instruction->IsLongConstant()
509 || instruction->IsNullConstant()) {
510 int64_t value = GetInt64ValueOf(instruction->AsConstant());
Alexandre Rames5319def2014-10-23 10:03:10 +0100511 if (location.IsRegister()) {
512 Register dst = RegisterFrom(location, type);
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000513 DCHECK(((instruction->IsIntConstant() || instruction->IsNullConstant()) && dst.Is32Bits()) ||
Alexandre Rames5319def2014-10-23 10:03:10 +0100514 (instruction->IsLongConstant() && dst.Is64Bits()));
515 __ Mov(dst, value);
516 } else {
517 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000518 UseScratchRegisterScope temps(GetVIXLAssembler());
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000519 Register temp = (instruction->IsIntConstant() || instruction->IsNullConstant())
520 ? temps.AcquireW()
521 : temps.AcquireX();
Alexandre Rames5319def2014-10-23 10:03:10 +0100522 __ Mov(temp, value);
523 __ Str(temp, StackOperandFrom(location));
524 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000525 } else if (instruction->IsTemporary()) {
526 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000527 MoveLocation(location, temp_location, type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100528 } else if (instruction->IsLoadLocal()) {
529 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
Alexandre Rames542361f2015-01-29 16:57:31 +0000530 if (Primitive::Is64BitType(type)) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000531 MoveLocation(location, Location::DoubleStackSlot(stack_slot), type);
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000532 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000533 MoveLocation(location, Location::StackSlot(stack_slot), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100534 }
535
536 } else {
537 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000538 MoveLocation(location, locations->Out(), type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100539 }
540}
541
Alexandre Rames5319def2014-10-23 10:03:10 +0100542Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const {
543 Primitive::Type type = load->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000544
Alexandre Rames5319def2014-10-23 10:03:10 +0100545 switch (type) {
546 case Primitive::kPrimNot:
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000547 case Primitive::kPrimInt:
548 case Primitive::kPrimFloat:
549 return Location::StackSlot(GetStackSlot(load->GetLocal()));
550
551 case Primitive::kPrimLong:
552 case Primitive::kPrimDouble:
553 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
554
Alexandre Rames5319def2014-10-23 10:03:10 +0100555 case Primitive::kPrimBoolean:
556 case Primitive::kPrimByte:
557 case Primitive::kPrimChar:
558 case Primitive::kPrimShort:
Alexandre Rames5319def2014-10-23 10:03:10 +0100559 case Primitive::kPrimVoid:
Alexandre Rames5319def2014-10-23 10:03:10 +0100560 LOG(FATAL) << "Unexpected type " << type;
561 }
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000562
Alexandre Rames5319def2014-10-23 10:03:10 +0100563 LOG(FATAL) << "Unreachable";
564 return Location::NoLocation();
565}
566
567void CodeGeneratorARM64::MarkGCCard(Register object, Register value) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000568 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames5319def2014-10-23 10:03:10 +0100569 Register card = temps.AcquireX();
Serban Constantinescu02164b32014-11-13 14:05:07 +0000570 Register temp = temps.AcquireW(); // Index within the CardTable - 32bit.
Alexandre Rames5319def2014-10-23 10:03:10 +0100571 vixl::Label done;
572 __ Cbz(value, &done);
573 __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value()));
574 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000575 __ Strb(card, MemOperand(card, temp.X()));
Alexandre Rames5319def2014-10-23 10:03:10 +0100576 __ Bind(&done);
577}
578
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000579void CodeGeneratorARM64::SetupBlockedRegisters(bool is_baseline) const {
580 // Blocked core registers:
581 // lr : Runtime reserved.
582 // tr : Runtime reserved.
583 // xSuspend : Runtime reserved. TODO: Unblock this when the runtime stops using it.
584 // ip1 : VIXL core temp.
585 // ip0 : VIXL core temp.
586 //
587 // Blocked fp registers:
588 // d31 : VIXL fp temp.
Alexandre Rames5319def2014-10-23 10:03:10 +0100589 CPURegList reserved_core_registers = vixl_reserved_core_registers;
590 reserved_core_registers.Combine(runtime_reserved_core_registers);
Alexandre Rames5319def2014-10-23 10:03:10 +0100591 while (!reserved_core_registers.IsEmpty()) {
592 blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true;
593 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000594
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000595 CPURegList reserved_fp_registers = vixl_reserved_fp_registers;
Zheng Xua3ec3942015-02-15 18:39:46 +0800596 while (!reserved_fp_registers.IsEmpty()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000597 blocked_fpu_registers_[reserved_fp_registers.PopLowestIndex().code()] = true;
598 }
Serban Constantinescu3d087de2015-01-28 11:57:05 +0000599
600 if (is_baseline) {
601 CPURegList reserved_core_baseline_registers = callee_saved_core_registers;
602 while (!reserved_core_baseline_registers.IsEmpty()) {
603 blocked_core_registers_[reserved_core_baseline_registers.PopLowestIndex().code()] = true;
604 }
605
606 CPURegList reserved_fp_baseline_registers = callee_saved_fp_registers;
607 while (!reserved_fp_baseline_registers.IsEmpty()) {
608 blocked_fpu_registers_[reserved_fp_baseline_registers.PopLowestIndex().code()] = true;
609 }
610 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100611}
612
613Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const {
614 if (type == Primitive::kPrimVoid) {
615 LOG(FATAL) << "Unreachable type " << type;
616 }
617
Alexandre Rames542361f2015-01-29 16:57:31 +0000618 if (Primitive::IsFloatingPointType(type)) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000619 ssize_t reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfAllocatableFPRegisters);
620 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100621 return Location::FpuRegisterLocation(reg);
622 } else {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000623 ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfAllocatableRegisters);
624 DCHECK_NE(reg, -1);
Alexandre Rames5319def2014-10-23 10:03:10 +0100625 return Location::RegisterLocation(reg);
626 }
627}
628
Alexandre Rames3e69f162014-12-10 10:36:50 +0000629size_t CodeGeneratorARM64::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
630 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
631 __ Str(reg, MemOperand(sp, stack_index));
632 return kArm64WordSize;
633}
634
635size_t CodeGeneratorARM64::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
636 Register reg = Register(VIXLRegCodeFromART(reg_id), kXRegSize);
637 __ Ldr(reg, MemOperand(sp, stack_index));
638 return kArm64WordSize;
639}
640
641size_t CodeGeneratorARM64::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
642 FPRegister reg = FPRegister(reg_id, kDRegSize);
643 __ Str(reg, MemOperand(sp, stack_index));
644 return kArm64WordSize;
645}
646
647size_t CodeGeneratorARM64::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
648 FPRegister reg = FPRegister(reg_id, kDRegSize);
649 __ Ldr(reg, MemOperand(sp, stack_index));
650 return kArm64WordSize;
651}
652
Alexandre Rames5319def2014-10-23 10:03:10 +0100653void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const {
654 stream << Arm64ManagedRegister::FromXRegister(XRegister(reg));
655}
656
657void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
658 stream << Arm64ManagedRegister::FromDRegister(DRegister(reg));
659}
660
Alexandre Rames67555f72014-11-18 10:55:16 +0000661void CodeGeneratorARM64::MoveConstant(CPURegister destination, HConstant* constant) {
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000662 if (constant->IsIntConstant()) {
663 __ Mov(Register(destination), constant->AsIntConstant()->GetValue());
664 } else if (constant->IsLongConstant()) {
665 __ Mov(Register(destination), constant->AsLongConstant()->GetValue());
666 } else if (constant->IsNullConstant()) {
667 __ Mov(Register(destination), 0);
Alexandre Rames67555f72014-11-18 10:55:16 +0000668 } else if (constant->IsFloatConstant()) {
669 __ Fmov(FPRegister(destination), constant->AsFloatConstant()->GetValue());
670 } else {
671 DCHECK(constant->IsDoubleConstant());
672 __ Fmov(FPRegister(destination), constant->AsDoubleConstant()->GetValue());
673 }
674}
675
Alexandre Rames3e69f162014-12-10 10:36:50 +0000676
677static bool CoherentConstantAndType(Location constant, Primitive::Type type) {
678 DCHECK(constant.IsConstant());
679 HConstant* cst = constant.GetConstant();
680 return (cst->IsIntConstant() && type == Primitive::kPrimInt) ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000681 // Null is mapped to a core W register, which we associate with kPrimInt.
682 (cst->IsNullConstant() && type == Primitive::kPrimInt) ||
Alexandre Rames3e69f162014-12-10 10:36:50 +0000683 (cst->IsLongConstant() && type == Primitive::kPrimLong) ||
684 (cst->IsFloatConstant() && type == Primitive::kPrimFloat) ||
685 (cst->IsDoubleConstant() && type == Primitive::kPrimDouble);
686}
687
688void CodeGeneratorARM64::MoveLocation(Location destination, Location source, Primitive::Type type) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000689 if (source.Equals(destination)) {
690 return;
691 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000692
693 // A valid move can always be inferred from the destination and source
694 // locations. When moving from and to a register, the argument type can be
695 // used to generate 32bit instead of 64bit moves. In debug mode we also
696 // checks the coherency of the locations and the type.
697 bool unspecified_type = (type == Primitive::kPrimVoid);
698
699 if (destination.IsRegister() || destination.IsFpuRegister()) {
700 if (unspecified_type) {
701 HConstant* src_cst = source.IsConstant() ? source.GetConstant() : nullptr;
702 if (source.IsStackSlot() ||
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000703 (src_cst != nullptr && (src_cst->IsIntConstant()
704 || src_cst->IsFloatConstant()
705 || src_cst->IsNullConstant()))) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000706 // For stack slots and 32bit constants, a 64bit type is appropriate.
707 type = destination.IsRegister() ? Primitive::kPrimInt : Primitive::kPrimFloat;
Alexandre Rames67555f72014-11-18 10:55:16 +0000708 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000709 // If the source is a double stack slot or a 64bit constant, a 64bit
710 // type is appropriate. Else the source is a register, and since the
711 // type has not been specified, we chose a 64bit type to force a 64bit
712 // move.
713 type = destination.IsRegister() ? Primitive::kPrimLong : Primitive::kPrimDouble;
Alexandre Rames67555f72014-11-18 10:55:16 +0000714 }
Alexandre Rames3e69f162014-12-10 10:36:50 +0000715 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000716 DCHECK((destination.IsFpuRegister() && Primitive::IsFloatingPointType(type)) ||
717 (destination.IsRegister() && !Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000718 CPURegister dst = CPURegisterFrom(destination, type);
719 if (source.IsStackSlot() || source.IsDoubleStackSlot()) {
720 DCHECK(dst.Is64Bits() == source.IsDoubleStackSlot());
721 __ Ldr(dst, StackOperandFrom(source));
722 } else if (source.IsConstant()) {
723 DCHECK(CoherentConstantAndType(source, type));
724 MoveConstant(dst, source.GetConstant());
725 } else {
726 if (destination.IsRegister()) {
727 __ Mov(Register(dst), RegisterFrom(source, type));
728 } else {
729 __ Fmov(FPRegister(dst), FPRegisterFrom(source, type));
730 }
731 }
732
733 } else { // The destination is not a register. It must be a stack slot.
734 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
735 if (source.IsRegister() || source.IsFpuRegister()) {
736 if (unspecified_type) {
737 if (source.IsRegister()) {
738 type = destination.IsStackSlot() ? Primitive::kPrimInt : Primitive::kPrimLong;
739 } else {
740 type = destination.IsStackSlot() ? Primitive::kPrimFloat : Primitive::kPrimDouble;
741 }
742 }
Alexandre Rames542361f2015-01-29 16:57:31 +0000743 DCHECK((destination.IsDoubleStackSlot() == Primitive::Is64BitType(type)) &&
744 (source.IsFpuRegister() == Primitive::IsFloatingPointType(type)));
Alexandre Rames3e69f162014-12-10 10:36:50 +0000745 __ Str(CPURegisterFrom(source, type), StackOperandFrom(destination));
746 } else if (source.IsConstant()) {
747 DCHECK(unspecified_type || CoherentConstantAndType(source, type));
748 UseScratchRegisterScope temps(GetVIXLAssembler());
749 HConstant* src_cst = source.GetConstant();
750 CPURegister temp;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000751 if (src_cst->IsIntConstant() || src_cst->IsNullConstant()) {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000752 temp = temps.AcquireW();
753 } else if (src_cst->IsLongConstant()) {
754 temp = temps.AcquireX();
755 } else if (src_cst->IsFloatConstant()) {
756 temp = temps.AcquireS();
757 } else {
758 DCHECK(src_cst->IsDoubleConstant());
759 temp = temps.AcquireD();
760 }
761 MoveConstant(temp, src_cst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000762 __ Str(temp, StackOperandFrom(destination));
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000763 } else {
Alexandre Rames67555f72014-11-18 10:55:16 +0000764 DCHECK(source.IsStackSlot() || source.IsDoubleStackSlot());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000765 DCHECK(source.IsDoubleStackSlot() == destination.IsDoubleStackSlot());
Alexandre Rames67555f72014-11-18 10:55:16 +0000766 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Rames3e69f162014-12-10 10:36:50 +0000767 // There is generally less pressure on FP registers.
768 FPRegister temp = destination.IsDoubleStackSlot() ? temps.AcquireD() : temps.AcquireS();
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000769 __ Ldr(temp, StackOperandFrom(source));
770 __ Str(temp, StackOperandFrom(destination));
771 }
772 }
773}
774
Alexandre Rames3e69f162014-12-10 10:36:50 +0000775void CodeGeneratorARM64::SwapLocations(Location loc1, Location loc2) {
776 DCHECK(!loc1.IsConstant());
777 DCHECK(!loc2.IsConstant());
778
779 if (loc1.Equals(loc2)) {
780 return;
781 }
782
783 UseScratchRegisterScope temps(GetAssembler()->vixl_masm_);
784
785 bool is_slot1 = loc1.IsStackSlot() || loc1.IsDoubleStackSlot();
786 bool is_slot2 = loc2.IsStackSlot() || loc2.IsDoubleStackSlot();
787 bool is_fp_reg1 = loc1.IsFpuRegister();
788 bool is_fp_reg2 = loc2.IsFpuRegister();
789
790 if (loc2.IsRegister() && loc1.IsRegister()) {
791 Register r1 = XRegisterFrom(loc1);
792 Register r2 = XRegisterFrom(loc2);
793 Register tmp = temps.AcquireSameSizeAs(r1);
794 __ Mov(tmp, r2);
795 __ Mov(r2, r1);
796 __ Mov(r1, tmp);
797 } else if (is_fp_reg2 && is_fp_reg1) {
798 FPRegister r1 = DRegisterFrom(loc1);
799 FPRegister r2 = DRegisterFrom(loc2);
800 FPRegister tmp = temps.AcquireSameSizeAs(r1);
801 __ Fmov(tmp, r2);
802 __ Fmov(r2, r1);
803 __ Fmov(r1, tmp);
804 } else if (is_slot1 != is_slot2) {
805 MemOperand mem = StackOperandFrom(is_slot1 ? loc1 : loc2);
806 Location reg_loc = is_slot1 ? loc2 : loc1;
807 CPURegister reg, tmp;
808 if (reg_loc.IsFpuRegister()) {
809 reg = DRegisterFrom(reg_loc);
810 tmp = temps.AcquireD();
811 } else {
812 reg = XRegisterFrom(reg_loc);
813 tmp = temps.AcquireX();
814 }
815 __ Ldr(tmp, mem);
816 __ Str(reg, mem);
817 if (reg_loc.IsFpuRegister()) {
818 __ Fmov(FPRegister(reg), FPRegister(tmp));
819 } else {
820 __ Mov(Register(reg), Register(tmp));
821 }
822 } else if (is_slot1 && is_slot2) {
823 MemOperand mem1 = StackOperandFrom(loc1);
824 MemOperand mem2 = StackOperandFrom(loc2);
825 Register tmp1 = loc1.IsStackSlot() ? temps.AcquireW() : temps.AcquireX();
826 Register tmp2 = temps.AcquireSameSizeAs(tmp1);
827 __ Ldr(tmp1, mem1);
828 __ Ldr(tmp2, mem2);
829 __ Str(tmp1, mem2);
830 __ Str(tmp2, mem1);
831 } else {
832 LOG(FATAL) << "Unimplemented";
833 }
834}
835
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000836void CodeGeneratorARM64::Load(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000837 CPURegister dst,
838 const MemOperand& src) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000839 switch (type) {
840 case Primitive::kPrimBoolean:
Alexandre Rames67555f72014-11-18 10:55:16 +0000841 __ Ldrb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000842 break;
843 case Primitive::kPrimByte:
Alexandre Rames67555f72014-11-18 10:55:16 +0000844 __ Ldrsb(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000845 break;
846 case Primitive::kPrimShort:
Alexandre Rames67555f72014-11-18 10:55:16 +0000847 __ Ldrsh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000848 break;
849 case Primitive::kPrimChar:
Alexandre Rames67555f72014-11-18 10:55:16 +0000850 __ Ldrh(Register(dst), src);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000851 break;
852 case Primitive::kPrimInt:
853 case Primitive::kPrimNot:
854 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000855 case Primitive::kPrimFloat:
856 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000857 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Alexandre Rames67555f72014-11-18 10:55:16 +0000858 __ Ldr(dst, src);
859 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000860 case Primitive::kPrimVoid:
861 LOG(FATAL) << "Unreachable type " << type;
862 }
863}
864
Calin Juravle77520bc2015-01-12 18:45:46 +0000865void CodeGeneratorARM64::LoadAcquire(HInstruction* instruction,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000866 CPURegister dst,
867 const MemOperand& src) {
868 UseScratchRegisterScope temps(GetVIXLAssembler());
869 Register temp_base = temps.AcquireX();
Calin Juravle77520bc2015-01-12 18:45:46 +0000870 Primitive::Type type = instruction->GetType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000871
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000872 DCHECK(!src.IsPreIndex());
873 DCHECK(!src.IsPostIndex());
874
875 // TODO(vixl): Let the MacroAssembler handle MemOperand.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800876 __ Add(temp_base, src.base(), OperandFromMemOperand(src));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000877 MemOperand base = MemOperand(temp_base);
878 switch (type) {
879 case Primitive::kPrimBoolean:
880 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000881 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000882 break;
883 case Primitive::kPrimByte:
884 __ Ldarb(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000885 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000886 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
887 break;
888 case Primitive::kPrimChar:
889 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000890 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000891 break;
892 case Primitive::kPrimShort:
893 __ Ldarh(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000894 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000895 __ Sbfx(Register(dst), Register(dst), 0, Primitive::ComponentSize(type) * kBitsPerByte);
896 break;
897 case Primitive::kPrimInt:
898 case Primitive::kPrimNot:
899 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000900 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000901 __ Ldar(Register(dst), base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000902 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000903 break;
904 case Primitive::kPrimFloat:
905 case Primitive::kPrimDouble: {
906 DCHECK(dst.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000907 DCHECK_EQ(dst.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000908
909 Register temp = dst.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
910 __ Ldar(temp, base);
Calin Juravle77520bc2015-01-12 18:45:46 +0000911 MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000912 __ Fmov(FPRegister(dst), temp);
913 break;
914 }
915 case Primitive::kPrimVoid:
916 LOG(FATAL) << "Unreachable type " << type;
917 }
918}
919
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000920void CodeGeneratorARM64::Store(Primitive::Type type,
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000921 CPURegister src,
922 const MemOperand& dst) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000923 switch (type) {
924 case Primitive::kPrimBoolean:
925 case Primitive::kPrimByte:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000926 __ Strb(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000927 break;
928 case Primitive::kPrimChar:
929 case Primitive::kPrimShort:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000930 __ Strh(Register(src), dst);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000931 break;
932 case Primitive::kPrimInt:
933 case Primitive::kPrimNot:
934 case Primitive::kPrimLong:
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000935 case Primitive::kPrimFloat:
936 case Primitive::kPrimDouble:
Alexandre Rames542361f2015-01-29 16:57:31 +0000937 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000938 __ Str(src, dst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000939 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000940 case Primitive::kPrimVoid:
941 LOG(FATAL) << "Unreachable type " << type;
942 }
943}
944
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000945void CodeGeneratorARM64::StoreRelease(Primitive::Type type,
946 CPURegister src,
947 const MemOperand& dst) {
948 UseScratchRegisterScope temps(GetVIXLAssembler());
949 Register temp_base = temps.AcquireX();
950
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000951 DCHECK(!dst.IsPreIndex());
952 DCHECK(!dst.IsPostIndex());
953
954 // TODO(vixl): Let the MacroAssembler handle this.
Andreas Gampe878d58c2015-01-15 23:24:00 -0800955 Operand op = OperandFromMemOperand(dst);
956 __ Add(temp_base, dst.base(), op);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000957 MemOperand base = MemOperand(temp_base);
958 switch (type) {
959 case Primitive::kPrimBoolean:
960 case Primitive::kPrimByte:
961 __ Stlrb(Register(src), base);
962 break;
963 case Primitive::kPrimChar:
964 case Primitive::kPrimShort:
965 __ Stlrh(Register(src), base);
966 break;
967 case Primitive::kPrimInt:
968 case Primitive::kPrimNot:
969 case Primitive::kPrimLong:
Alexandre Rames542361f2015-01-29 16:57:31 +0000970 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000971 __ Stlr(Register(src), base);
972 break;
973 case Primitive::kPrimFloat:
974 case Primitive::kPrimDouble: {
975 DCHECK(src.IsFPRegister());
Alexandre Rames542361f2015-01-29 16:57:31 +0000976 DCHECK_EQ(src.Is64Bits(), Primitive::Is64BitType(type));
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000977
978 Register temp = src.Is64Bits() ? temps.AcquireX() : temps.AcquireW();
979 __ Fmov(temp, FPRegister(src));
980 __ Stlr(temp, base);
981 break;
982 }
983 case Primitive::kPrimVoid:
984 LOG(FATAL) << "Unreachable type " << type;
985 }
986}
987
Alexandre Rames67555f72014-11-18 10:55:16 +0000988void CodeGeneratorARM64::LoadCurrentMethod(vixl::Register current_method) {
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +0000989 DCHECK(RequiresCurrentMethod());
Alexandre Rames67555f72014-11-18 10:55:16 +0000990 DCHECK(current_method.IsW());
991 __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset));
992}
993
994void CodeGeneratorARM64::InvokeRuntime(int32_t entry_point_offset,
995 HInstruction* instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000996 uint32_t dex_pc,
997 SlowPathCode* slow_path) {
Alexandre Rames67555f72014-11-18 10:55:16 +0000998 __ Ldr(lr, MemOperand(tr, entry_point_offset));
999 __ Blr(lr);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001000 if (instruction != nullptr) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001001 RecordPcInfo(instruction, dex_pc, slow_path);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001002 DCHECK(instruction->IsSuspendCheck()
1003 || instruction->IsBoundsCheck()
1004 || instruction->IsNullCheck()
1005 || instruction->IsDivZeroCheck()
1006 || !IsLeafMethod());
1007 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001008}
1009
1010void InstructionCodeGeneratorARM64::GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path,
1011 vixl::Register class_reg) {
1012 UseScratchRegisterScope temps(GetVIXLAssembler());
1013 Register temp = temps.AcquireW();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001014 size_t status_offset = mirror::Class::StatusOffset().SizeValue();
Serban Constantinescu579885a2015-02-22 20:51:33 +00001015 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001016
Serban Constantinescu02164b32014-11-13 14:05:07 +00001017 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
Serban Constantinescu579885a2015-02-22 20:51:33 +00001018 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001019 // TODO(vixl): Let the MacroAssembler handle MemOperand.
1020 __ Add(temp, class_reg, status_offset);
1021 __ Ldar(temp, HeapOperand(temp));
1022 __ Cmp(temp, mirror::Class::kStatusInitialized);
1023 __ B(lt, slow_path->GetEntryLabel());
1024 } else {
1025 __ Ldr(temp, HeapOperand(class_reg, status_offset));
1026 __ Cmp(temp, mirror::Class::kStatusInitialized);
1027 __ B(lt, slow_path->GetEntryLabel());
1028 __ Dmb(InnerShareable, BarrierReads);
1029 }
Alexandre Rames67555f72014-11-18 10:55:16 +00001030 __ Bind(slow_path->GetExitLabel());
1031}
Alexandre Rames5319def2014-10-23 10:03:10 +01001032
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001033void InstructionCodeGeneratorARM64::GenerateMemoryBarrier(MemBarrierKind kind) {
1034 BarrierType type = BarrierAll;
1035
1036 switch (kind) {
1037 case MemBarrierKind::kAnyAny:
1038 case MemBarrierKind::kAnyStore: {
1039 type = BarrierAll;
1040 break;
1041 }
1042 case MemBarrierKind::kLoadAny: {
1043 type = BarrierReads;
1044 break;
1045 }
1046 case MemBarrierKind::kStoreStore: {
1047 type = BarrierWrites;
1048 break;
1049 }
1050 default:
1051 LOG(FATAL) << "Unexpected memory barrier " << kind;
1052 }
1053 __ Dmb(InnerShareable, type);
1054}
1055
Serban Constantinescu02164b32014-11-13 14:05:07 +00001056void InstructionCodeGeneratorARM64::GenerateSuspendCheck(HSuspendCheck* instruction,
1057 HBasicBlock* successor) {
1058 SuspendCheckSlowPathARM64* slow_path =
1059 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, successor);
1060 codegen_->AddSlowPath(slow_path);
1061 UseScratchRegisterScope temps(codegen_->GetVIXLAssembler());
1062 Register temp = temps.AcquireW();
1063
1064 __ Ldrh(temp, MemOperand(tr, Thread::ThreadFlagsOffset<kArm64WordSize>().SizeValue()));
1065 if (successor == nullptr) {
1066 __ Cbnz(temp, slow_path->GetEntryLabel());
1067 __ Bind(slow_path->GetReturnLabel());
1068 } else {
1069 __ Cbz(temp, codegen_->GetLabelOf(successor));
1070 __ B(slow_path->GetEntryLabel());
1071 // slow_path will return to GetLabelOf(successor).
1072 }
1073}
1074
Alexandre Rames5319def2014-10-23 10:03:10 +01001075InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph,
1076 CodeGeneratorARM64* codegen)
1077 : HGraphVisitor(graph),
1078 assembler_(codegen->GetAssembler()),
1079 codegen_(codegen) {}
1080
1081#define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \
Alexandre Rames3e69f162014-12-10 10:36:50 +00001082 /* No unimplemented IR. */
Alexandre Rames5319def2014-10-23 10:03:10 +01001083
1084#define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode
1085
1086enum UnimplementedInstructionBreakCode {
Alexandre Rames67555f72014-11-18 10:55:16 +00001087 // Using a base helps identify when we hit such breakpoints.
1088 UnimplementedInstructionBreakCodeBaseCode = 0x900,
Alexandre Rames5319def2014-10-23 10:03:10 +01001089#define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name),
1090 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION)
1091#undef ENUM_UNIMPLEMENTED_INSTRUCTION
1092};
1093
1094#define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \
1095 void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001096 UNUSED(instr); \
Alexandre Rames5319def2014-10-23 10:03:10 +01001097 __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \
1098 } \
1099 void LocationsBuilderARM64::Visit##name(H##name* instr) { \
1100 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \
1101 locations->SetOut(Location::Any()); \
1102 }
1103 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS)
1104#undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS
1105
1106#undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE
Alexandre Rames67555f72014-11-18 10:55:16 +00001107#undef FOR_EACH_UNIMPLEMENTED_INSTRUCTION
Alexandre Rames5319def2014-10-23 10:03:10 +01001108
Alexandre Rames67555f72014-11-18 10:55:16 +00001109void LocationsBuilderARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001110 DCHECK_EQ(instr->InputCount(), 2U);
1111 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1112 Primitive::Type type = instr->GetResultType();
1113 switch (type) {
1114 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001115 case Primitive::kPrimLong:
Alexandre Rames5319def2014-10-23 10:03:10 +01001116 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001117 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instr->InputAt(1), instr));
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001118 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001119 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001120
1121 case Primitive::kPrimFloat:
1122 case Primitive::kPrimDouble:
1123 locations->SetInAt(0, Location::RequiresFpuRegister());
1124 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001125 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001126 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001127
Alexandre Rames5319def2014-10-23 10:03:10 +01001128 default:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001129 LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001130 }
1131}
1132
Alexandre Rames67555f72014-11-18 10:55:16 +00001133void InstructionCodeGeneratorARM64::HandleBinaryOp(HBinaryOperation* instr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001134 Primitive::Type type = instr->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001135
1136 switch (type) {
1137 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001138 case Primitive::kPrimLong: {
1139 Register dst = OutputRegister(instr);
1140 Register lhs = InputRegisterAt(instr, 0);
1141 Operand rhs = InputOperandAt(instr, 1);
Alexandre Rames5319def2014-10-23 10:03:10 +01001142 if (instr->IsAdd()) {
1143 __ Add(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001144 } else if (instr->IsAnd()) {
1145 __ And(dst, lhs, rhs);
1146 } else if (instr->IsOr()) {
1147 __ Orr(dst, lhs, rhs);
1148 } else if (instr->IsSub()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001149 __ Sub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001150 } else {
1151 DCHECK(instr->IsXor());
1152 __ Eor(dst, lhs, rhs);
Alexandre Rames5319def2014-10-23 10:03:10 +01001153 }
1154 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001155 }
1156 case Primitive::kPrimFloat:
1157 case Primitive::kPrimDouble: {
1158 FPRegister dst = OutputFPRegister(instr);
1159 FPRegister lhs = InputFPRegisterAt(instr, 0);
1160 FPRegister rhs = InputFPRegisterAt(instr, 1);
1161 if (instr->IsAdd()) {
1162 __ Fadd(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001163 } else if (instr->IsSub()) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001164 __ Fsub(dst, lhs, rhs);
Alexandre Rames67555f72014-11-18 10:55:16 +00001165 } else {
1166 LOG(FATAL) << "Unexpected floating-point binary operation";
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001167 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001168 break;
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001169 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001170 default:
Alexandre Rames67555f72014-11-18 10:55:16 +00001171 LOG(FATAL) << "Unexpected binary operation type " << type;
Alexandre Rames5319def2014-10-23 10:03:10 +01001172 }
1173}
1174
Serban Constantinescu02164b32014-11-13 14:05:07 +00001175void LocationsBuilderARM64::HandleShift(HBinaryOperation* instr) {
1176 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1177
1178 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1179 Primitive::Type type = instr->GetResultType();
1180 switch (type) {
1181 case Primitive::kPrimInt:
1182 case Primitive::kPrimLong: {
1183 locations->SetInAt(0, Location::RequiresRegister());
1184 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1185 locations->SetOut(Location::RequiresRegister());
1186 break;
1187 }
1188 default:
1189 LOG(FATAL) << "Unexpected shift type " << type;
1190 }
1191}
1192
1193void InstructionCodeGeneratorARM64::HandleShift(HBinaryOperation* instr) {
1194 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr());
1195
1196 Primitive::Type type = instr->GetType();
1197 switch (type) {
1198 case Primitive::kPrimInt:
1199 case Primitive::kPrimLong: {
1200 Register dst = OutputRegister(instr);
1201 Register lhs = InputRegisterAt(instr, 0);
1202 Operand rhs = InputOperandAt(instr, 1);
1203 if (rhs.IsImmediate()) {
1204 uint32_t shift_value = (type == Primitive::kPrimInt)
1205 ? static_cast<uint32_t>(rhs.immediate() & kMaxIntShiftValue)
1206 : static_cast<uint32_t>(rhs.immediate() & kMaxLongShiftValue);
1207 if (instr->IsShl()) {
1208 __ Lsl(dst, lhs, shift_value);
1209 } else if (instr->IsShr()) {
1210 __ Asr(dst, lhs, shift_value);
1211 } else {
1212 __ Lsr(dst, lhs, shift_value);
1213 }
1214 } else {
1215 Register rhs_reg = dst.IsX() ? rhs.reg().X() : rhs.reg().W();
1216
1217 if (instr->IsShl()) {
1218 __ Lsl(dst, lhs, rhs_reg);
1219 } else if (instr->IsShr()) {
1220 __ Asr(dst, lhs, rhs_reg);
1221 } else {
1222 __ Lsr(dst, lhs, rhs_reg);
1223 }
1224 }
1225 break;
1226 }
1227 default:
1228 LOG(FATAL) << "Unexpected shift operation type " << type;
1229 }
1230}
1231
Alexandre Rames5319def2014-10-23 10:03:10 +01001232void LocationsBuilderARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001233 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001234}
1235
1236void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001237 HandleBinaryOp(instruction);
1238}
1239
1240void LocationsBuilderARM64::VisitAnd(HAnd* instruction) {
1241 HandleBinaryOp(instruction);
1242}
1243
1244void InstructionCodeGeneratorARM64::VisitAnd(HAnd* instruction) {
1245 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001246}
1247
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001248void LocationsBuilderARM64::VisitArrayGet(HArrayGet* instruction) {
1249 LocationSummary* locations =
1250 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1251 locations->SetInAt(0, Location::RequiresRegister());
1252 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1253 locations->SetOut(Location::RequiresRegister());
1254}
1255
1256void InstructionCodeGeneratorARM64::VisitArrayGet(HArrayGet* instruction) {
1257 LocationSummary* locations = instruction->GetLocations();
1258 Primitive::Type type = instruction->GetType();
1259 Register obj = InputRegisterAt(instruction, 0);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001260 Location index = locations->InAt(1);
1261 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001262 MemOperand source = HeapOperand(obj);
Alexandre Rames67555f72014-11-18 10:55:16 +00001263 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001264
1265 if (index.IsConstant()) {
1266 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001267 source = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001268 } else {
1269 Register temp = temps.AcquireSameSizeAs(obj);
1270 Register index_reg = RegisterFrom(index, Primitive::kPrimInt);
1271 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001272 source = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001273 }
1274
Alexandre Rames67555f72014-11-18 10:55:16 +00001275 codegen_->Load(type, OutputCPURegister(instruction), source);
Calin Juravle77520bc2015-01-12 18:45:46 +00001276 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001277}
1278
Alexandre Rames5319def2014-10-23 10:03:10 +01001279void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) {
1280 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1281 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001282 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001283}
1284
1285void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) {
1286 __ Ldr(OutputRegister(instruction),
1287 HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset()));
Calin Juravle77520bc2015-01-12 18:45:46 +00001288 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01001289}
1290
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001291void LocationsBuilderARM64::VisitArraySet(HArraySet* instruction) {
1292 Primitive::Type value_type = instruction->GetComponentType();
1293 bool is_object = value_type == Primitive::kPrimNot;
1294 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1295 instruction, is_object ? LocationSummary::kCall : LocationSummary::kNoCall);
1296 if (is_object) {
1297 InvokeRuntimeCallingConvention calling_convention;
1298 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1299 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1300 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1301 } else {
1302 locations->SetInAt(0, Location::RequiresRegister());
1303 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1304 locations->SetInAt(2, Location::RequiresRegister());
1305 }
1306}
1307
1308void InstructionCodeGeneratorARM64::VisitArraySet(HArraySet* instruction) {
1309 Primitive::Type value_type = instruction->GetComponentType();
1310 if (value_type == Primitive::kPrimNot) {
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00001311 codegen_->InvokeRuntime(
1312 QUICK_ENTRY_POINT(pAputObject), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001313 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001314 } else {
1315 LocationSummary* locations = instruction->GetLocations();
1316 Register obj = InputRegisterAt(instruction, 0);
Alexandre Rames67555f72014-11-18 10:55:16 +00001317 CPURegister value = InputCPURegisterAt(instruction, 2);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001318 Location index = locations->InAt(1);
1319 size_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(value_type)).Uint32Value();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001320 MemOperand destination = HeapOperand(obj);
Alexandre Rames67555f72014-11-18 10:55:16 +00001321 UseScratchRegisterScope temps(GetVIXLAssembler());
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001322
1323 if (index.IsConstant()) {
1324 offset += Int64ConstantFrom(index) << Primitive::ComponentSizeShift(value_type);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001325 destination = HeapOperand(obj, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001326 } else {
1327 Register temp = temps.AcquireSameSizeAs(obj);
1328 Register index_reg = InputRegisterAt(instruction, 1);
1329 __ Add(temp, obj, Operand(index_reg, LSL, Primitive::ComponentSizeShift(value_type)));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001330 destination = HeapOperand(temp, offset);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001331 }
1332
1333 codegen_->Store(value_type, value, destination);
Calin Juravle77520bc2015-01-12 18:45:46 +00001334 codegen_->MaybeRecordImplicitNullCheck(instruction);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001335 }
1336}
1337
Alexandre Rames67555f72014-11-18 10:55:16 +00001338void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
1339 LocationSummary* locations =
1340 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1341 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu760d8ef2015-03-28 18:09:56 +00001342 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames67555f72014-11-18 10:55:16 +00001343 if (instruction->HasUses()) {
1344 locations->SetOut(Location::SameAsFirstInput());
1345 }
1346}
1347
1348void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001349 LocationSummary* locations = instruction->GetLocations();
1350 BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(
1351 instruction, locations->InAt(0), locations->InAt(1));
Alexandre Rames67555f72014-11-18 10:55:16 +00001352 codegen_->AddSlowPath(slow_path);
1353
1354 __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1));
1355 __ B(slow_path->GetEntryLabel(), hs);
1356}
1357
1358void LocationsBuilderARM64::VisitCheckCast(HCheckCast* instruction) {
1359 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1360 instruction, LocationSummary::kCallOnSlowPath);
1361 locations->SetInAt(0, Location::RequiresRegister());
1362 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames3e69f162014-12-10 10:36:50 +00001363 locations->AddTemp(Location::RequiresRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00001364}
1365
1366void InstructionCodeGeneratorARM64::VisitCheckCast(HCheckCast* instruction) {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001367 LocationSummary* locations = instruction->GetLocations();
Alexandre Rames67555f72014-11-18 10:55:16 +00001368 Register obj = InputRegisterAt(instruction, 0);;
1369 Register cls = InputRegisterAt(instruction, 1);;
Alexandre Rames3e69f162014-12-10 10:36:50 +00001370 Register obj_cls = WRegisterFrom(instruction->GetLocations()->GetTemp(0));
Alexandre Rames67555f72014-11-18 10:55:16 +00001371
Alexandre Rames3e69f162014-12-10 10:36:50 +00001372 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1373 instruction, locations->InAt(1), LocationFrom(obj_cls), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001374 codegen_->AddSlowPath(slow_path);
1375
1376 // TODO: avoid this check if we know obj is not null.
1377 __ Cbz(obj, slow_path->GetExitLabel());
1378 // Compare the class of `obj` with `cls`.
Alexandre Rames3e69f162014-12-10 10:36:50 +00001379 __ Ldr(obj_cls, HeapOperand(obj, mirror::Object::ClassOffset()));
1380 __ Cmp(obj_cls, cls);
Alexandre Rames67555f72014-11-18 10:55:16 +00001381 __ B(ne, slow_path->GetEntryLabel());
1382 __ Bind(slow_path->GetExitLabel());
1383}
1384
1385void LocationsBuilderARM64::VisitClinitCheck(HClinitCheck* check) {
1386 LocationSummary* locations =
1387 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
1388 locations->SetInAt(0, Location::RequiresRegister());
1389 if (check->HasUses()) {
1390 locations->SetOut(Location::SameAsFirstInput());
1391 }
1392}
1393
1394void InstructionCodeGeneratorARM64::VisitClinitCheck(HClinitCheck* check) {
1395 // We assume the class is not null.
1396 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
1397 check->GetLoadClass(), check, check->GetDexPc(), true);
1398 codegen_->AddSlowPath(slow_path);
1399 GenerateClassInitializationCheck(slow_path, InputRegisterAt(check, 0));
1400}
1401
Serban Constantinescu02164b32014-11-13 14:05:07 +00001402void LocationsBuilderARM64::VisitCompare(HCompare* compare) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001403 LocationSummary* locations =
Serban Constantinescu02164b32014-11-13 14:05:07 +00001404 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
1405 Primitive::Type in_type = compare->InputAt(0)->GetType();
Alexandre Rames5319def2014-10-23 10:03:10 +01001406 switch (in_type) {
1407 case Primitive::kPrimLong: {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001408 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001409 locations->SetInAt(1, ARM64EncodableConstantOrRegister(compare->InputAt(1), compare));
Serban Constantinescu02164b32014-11-13 14:05:07 +00001410 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1411 break;
1412 }
1413 case Primitive::kPrimFloat:
1414 case Primitive::kPrimDouble: {
1415 locations->SetInAt(0, Location::RequiresFpuRegister());
Alexandre Rames93415462015-02-17 15:08:20 +00001416 HInstruction* right = compare->InputAt(1);
1417 if ((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1418 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0))) {
1419 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1420 } else {
1421 locations->SetInAt(1, Location::RequiresFpuRegister());
1422 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001423 locations->SetOut(Location::RequiresRegister());
1424 break;
1425 }
1426 default:
1427 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
1428 }
1429}
1430
1431void InstructionCodeGeneratorARM64::VisitCompare(HCompare* compare) {
1432 Primitive::Type in_type = compare->InputAt(0)->GetType();
1433
1434 // 0 if: left == right
1435 // 1 if: left > right
1436 // -1 if: left < right
1437 switch (in_type) {
1438 case Primitive::kPrimLong: {
1439 Register result = OutputRegister(compare);
1440 Register left = InputRegisterAt(compare, 0);
1441 Operand right = InputOperandAt(compare, 1);
1442
1443 __ Cmp(left, right);
1444 __ Cset(result, ne);
1445 __ Cneg(result, result, lt);
1446 break;
1447 }
1448 case Primitive::kPrimFloat:
1449 case Primitive::kPrimDouble: {
1450 Register result = OutputRegister(compare);
1451 FPRegister left = InputFPRegisterAt(compare, 0);
Alexandre Rames93415462015-02-17 15:08:20 +00001452 if (compare->GetLocations()->InAt(1).IsConstant()) {
1453 if (kIsDebugBuild) {
1454 HInstruction* right = compare->GetLocations()->InAt(1).GetConstant();
1455 DCHECK((right->IsFloatConstant() && (right->AsFloatConstant()->GetValue() == 0.0f)) ||
1456 (right->IsDoubleConstant() && (right->AsDoubleConstant()->GetValue() == 0.0)));
1457 }
1458 // 0.0 is the only immediate that can be encoded directly in a FCMP instruction.
1459 __ Fcmp(left, 0.0);
1460 } else {
1461 __ Fcmp(left, InputFPRegisterAt(compare, 1));
1462 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00001463 if (compare->IsGtBias()) {
1464 __ Cset(result, ne);
1465 } else {
1466 __ Csetm(result, ne);
1467 }
1468 __ Cneg(result, result, compare->IsGtBias() ? mi : gt);
Alexandre Rames5319def2014-10-23 10:03:10 +01001469 break;
1470 }
1471 default:
1472 LOG(FATAL) << "Unimplemented compare type " << in_type;
1473 }
1474}
1475
1476void LocationsBuilderARM64::VisitCondition(HCondition* instruction) {
1477 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1478 locations->SetInAt(0, Location::RequiresRegister());
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00001479 locations->SetInAt(1, ARM64EncodableConstantOrRegister(instruction->InputAt(1), instruction));
Alexandre Rames5319def2014-10-23 10:03:10 +01001480 if (instruction->NeedsMaterialization()) {
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001481 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001482 }
1483}
1484
1485void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) {
1486 if (!instruction->NeedsMaterialization()) {
1487 return;
1488 }
1489
1490 LocationSummary* locations = instruction->GetLocations();
1491 Register lhs = InputRegisterAt(instruction, 0);
1492 Operand rhs = InputOperandAt(instruction, 1);
1493 Register res = RegisterFrom(locations->Out(), instruction->GetType());
1494 Condition cond = ARM64Condition(instruction->GetCondition());
1495
1496 __ Cmp(lhs, rhs);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001497 __ Cset(res, cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001498}
1499
1500#define FOR_EACH_CONDITION_INSTRUCTION(M) \
1501 M(Equal) \
1502 M(NotEqual) \
1503 M(LessThan) \
1504 M(LessThanOrEqual) \
1505 M(GreaterThan) \
1506 M(GreaterThanOrEqual)
1507#define DEFINE_CONDITION_VISITORS(Name) \
1508void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \
1509void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); }
1510FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS)
Alexandre Rames67555f72014-11-18 10:55:16 +00001511#undef DEFINE_CONDITION_VISITORS
Alexandre Rames5319def2014-10-23 10:03:10 +01001512#undef FOR_EACH_CONDITION_INSTRUCTION
1513
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001514void LocationsBuilderARM64::VisitDiv(HDiv* div) {
1515 LocationSummary* locations =
1516 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1517 switch (div->GetResultType()) {
1518 case Primitive::kPrimInt:
1519 case Primitive::kPrimLong:
1520 locations->SetInAt(0, Location::RequiresRegister());
1521 locations->SetInAt(1, Location::RequiresRegister());
1522 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1523 break;
1524
1525 case Primitive::kPrimFloat:
1526 case Primitive::kPrimDouble:
1527 locations->SetInAt(0, Location::RequiresFpuRegister());
1528 locations->SetInAt(1, Location::RequiresFpuRegister());
1529 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1530 break;
1531
1532 default:
1533 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1534 }
1535}
1536
1537void InstructionCodeGeneratorARM64::VisitDiv(HDiv* div) {
1538 Primitive::Type type = div->GetResultType();
1539 switch (type) {
1540 case Primitive::kPrimInt:
1541 case Primitive::kPrimLong:
1542 __ Sdiv(OutputRegister(div), InputRegisterAt(div, 0), InputRegisterAt(div, 1));
1543 break;
1544
1545 case Primitive::kPrimFloat:
1546 case Primitive::kPrimDouble:
1547 __ Fdiv(OutputFPRegister(div), InputFPRegisterAt(div, 0), InputFPRegisterAt(div, 1));
1548 break;
1549
1550 default:
1551 LOG(FATAL) << "Unexpected div type " << type;
1552 }
1553}
1554
Alexandre Rames67555f72014-11-18 10:55:16 +00001555void LocationsBuilderARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1556 LocationSummary* locations =
1557 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1558 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
1559 if (instruction->HasUses()) {
1560 locations->SetOut(Location::SameAsFirstInput());
1561 }
1562}
1563
1564void InstructionCodeGeneratorARM64::VisitDivZeroCheck(HDivZeroCheck* instruction) {
1565 SlowPathCodeARM64* slow_path =
1566 new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM64(instruction);
1567 codegen_->AddSlowPath(slow_path);
1568 Location value = instruction->GetLocations()->InAt(0);
1569
Alexandre Rames3e69f162014-12-10 10:36:50 +00001570 Primitive::Type type = instruction->GetType();
1571
1572 if ((type != Primitive::kPrimInt) && (type != Primitive::kPrimLong)) {
1573 LOG(FATAL) << "Unexpected type " << type << "for DivZeroCheck.";
1574 return;
1575 }
1576
Alexandre Rames67555f72014-11-18 10:55:16 +00001577 if (value.IsConstant()) {
1578 int64_t divisor = Int64ConstantFrom(value);
1579 if (divisor == 0) {
1580 __ B(slow_path->GetEntryLabel());
1581 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00001582 // A division by a non-null constant is valid. We don't need to perform
1583 // any check, so simply fall through.
Alexandre Rames67555f72014-11-18 10:55:16 +00001584 }
1585 } else {
1586 __ Cbz(InputRegisterAt(instruction, 0), slow_path->GetEntryLabel());
1587 }
1588}
1589
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001590void LocationsBuilderARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1591 LocationSummary* locations =
1592 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1593 locations->SetOut(Location::ConstantLocation(constant));
1594}
1595
1596void InstructionCodeGeneratorARM64::VisitDoubleConstant(HDoubleConstant* constant) {
1597 UNUSED(constant);
1598 // Will be generated at use site.
1599}
1600
Alexandre Rames5319def2014-10-23 10:03:10 +01001601void LocationsBuilderARM64::VisitExit(HExit* exit) {
1602 exit->SetLocations(nullptr);
1603}
1604
1605void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001606 UNUSED(exit);
Alexandre Rames5319def2014-10-23 10:03:10 +01001607}
1608
Alexandre Ramesa89086e2014-11-07 17:13:25 +00001609void LocationsBuilderARM64::VisitFloatConstant(HFloatConstant* constant) {
1610 LocationSummary* locations =
1611 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1612 locations->SetOut(Location::ConstantLocation(constant));
1613}
1614
1615void InstructionCodeGeneratorARM64::VisitFloatConstant(HFloatConstant* constant) {
1616 UNUSED(constant);
1617 // Will be generated at use site.
1618}
1619
Alexandre Rames5319def2014-10-23 10:03:10 +01001620void LocationsBuilderARM64::VisitGoto(HGoto* got) {
1621 got->SetLocations(nullptr);
1622}
1623
1624void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) {
1625 HBasicBlock* successor = got->GetSuccessor();
Serban Constantinescu02164b32014-11-13 14:05:07 +00001626 DCHECK(!successor->IsExitBlock());
1627 HBasicBlock* block = got->GetBlock();
1628 HInstruction* previous = got->GetPrevious();
1629 HLoopInformation* info = block->GetLoopInformation();
1630
David Brazdil46e2a392015-03-16 17:31:52 +00001631 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001632 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
1633 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
1634 return;
1635 }
1636 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
1637 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
1638 }
1639 if (!codegen_->GoesToNextBlock(block, successor)) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001640 __ B(codegen_->GetLabelOf(successor));
1641 }
1642}
1643
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001644void InstructionCodeGeneratorARM64::GenerateTestAndBranch(HInstruction* instruction,
1645 vixl::Label* true_target,
1646 vixl::Label* false_target,
1647 vixl::Label* always_true_target) {
1648 HInstruction* cond = instruction->InputAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001649 HCondition* condition = cond->AsCondition();
Alexandre Rames5319def2014-10-23 10:03:10 +01001650
Serban Constantinescu02164b32014-11-13 14:05:07 +00001651 if (cond->IsIntConstant()) {
1652 int32_t cond_value = cond->AsIntConstant()->GetValue();
1653 if (cond_value == 1) {
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001654 if (always_true_target != nullptr) {
1655 __ B(always_true_target);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001656 }
1657 return;
1658 } else {
1659 DCHECK_EQ(cond_value, 0);
1660 }
1661 } else if (!cond->IsCondition() || condition->NeedsMaterialization()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001662 // The condition instruction has been materialized, compare the output to 0.
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001663 Location cond_val = instruction->GetLocations()->InAt(0);
Alexandre Rames5319def2014-10-23 10:03:10 +01001664 DCHECK(cond_val.IsRegister());
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001665 __ Cbnz(InputRegisterAt(instruction, 0), true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001666 } else {
1667 // The condition instruction has not been materialized, use its inputs as
1668 // the comparison and its condition as the branch condition.
1669 Register lhs = InputRegisterAt(condition, 0);
1670 Operand rhs = InputOperandAt(condition, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001671 Condition arm64_cond = ARM64Condition(condition->GetCondition());
Alexandre Rames4388dcc2015-02-03 10:28:33 +00001672 if ((arm64_cond != gt && arm64_cond != le) && rhs.IsImmediate() && (rhs.immediate() == 0)) {
1673 switch (arm64_cond) {
1674 case eq:
1675 __ Cbz(lhs, true_target);
1676 break;
1677 case ne:
1678 __ Cbnz(lhs, true_target);
1679 break;
1680 case lt:
1681 // Test the sign bit and branch accordingly.
1682 __ Tbnz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1683 break;
1684 case ge:
1685 // Test the sign bit and branch accordingly.
1686 __ Tbz(lhs, (lhs.IsX() ? kXRegSize : kWRegSize) - 1, true_target);
1687 break;
1688 default:
1689 // Without the `static_cast` the compiler throws an error for
1690 // `-Werror=sign-promo`.
1691 LOG(FATAL) << "Unexpected condition: " << static_cast<int>(arm64_cond);
Alexandre Rames5319def2014-10-23 10:03:10 +01001692 }
1693 } else {
1694 __ Cmp(lhs, rhs);
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001695 __ B(arm64_cond, true_target);
Alexandre Rames5319def2014-10-23 10:03:10 +01001696 }
1697 }
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001698 if (false_target != nullptr) {
Alexandre Rames5319def2014-10-23 10:03:10 +01001699 __ B(false_target);
1700 }
1701}
1702
Mingyao Yangd43b3ac2015-04-01 14:03:04 -07001703void LocationsBuilderARM64::VisitIf(HIf* if_instr) {
1704 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
1705 HInstruction* cond = if_instr->InputAt(0);
1706 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
1707 locations->SetInAt(0, Location::RequiresRegister());
1708 }
1709}
1710
1711void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) {
1712 vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
1713 vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
1714 vixl::Label* always_true_target = true_target;
1715 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1716 if_instr->IfTrueSuccessor())) {
1717 always_true_target = nullptr;
1718 }
1719 if (codegen_->GoesToNextBlock(if_instr->GetBlock(),
1720 if_instr->IfFalseSuccessor())) {
1721 false_target = nullptr;
1722 }
1723 GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target);
1724}
1725
1726void LocationsBuilderARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1727 LocationSummary* locations = new (GetGraph()->GetArena())
1728 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
1729 HInstruction* cond = deoptimize->InputAt(0);
1730 DCHECK(cond->IsCondition());
1731 if (cond->AsCondition()->NeedsMaterialization()) {
1732 locations->SetInAt(0, Location::RequiresRegister());
1733 }
1734}
1735
1736void InstructionCodeGeneratorARM64::VisitDeoptimize(HDeoptimize* deoptimize) {
1737 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena())
1738 DeoptimizationSlowPathARM64(deoptimize);
1739 codegen_->AddSlowPath(slow_path);
1740 vixl::Label* slow_path_entry = slow_path->GetEntryLabel();
1741 GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry);
1742}
1743
Alexandre Rames5319def2014-10-23 10:03:10 +01001744void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001745 LocationSummary* locations =
1746 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Rames5319def2014-10-23 10:03:10 +01001747 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00001748 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01001749}
1750
1751void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00001752 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), instruction->GetFieldOffset());
Serban Constantinescu579885a2015-02-22 20:51:33 +00001753 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001754
1755 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00001756 if (use_acquire_release) {
Calin Juravle77520bc2015-01-12 18:45:46 +00001757 // NB: LoadAcquire will record the pc info if needed.
1758 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001759 } else {
1760 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
Calin Juravle77520bc2015-01-12 18:45:46 +00001761 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001762 // For IRIW sequential consistency kLoadAny is not sufficient.
1763 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1764 }
1765 } else {
1766 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
Calin Juravle77520bc2015-01-12 18:45:46 +00001767 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001768 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001769}
1770
1771void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001772 LocationSummary* locations =
1773 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Alexandre Rames5319def2014-10-23 10:03:10 +01001774 locations->SetInAt(0, Location::RequiresRegister());
1775 locations->SetInAt(1, Location::RequiresRegister());
1776}
1777
1778void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Alexandre Ramesfc19de82014-11-07 17:13:31 +00001779 Register obj = InputRegisterAt(instruction, 0);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001780 CPURegister value = InputCPURegisterAt(instruction, 1);
1781 Offset offset = instruction->GetFieldOffset();
1782 Primitive::Type field_type = instruction->GetFieldType();
Serban Constantinescu579885a2015-02-22 20:51:33 +00001783 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001784
1785 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00001786 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001787 codegen_->StoreRelease(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001788 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001789 } else {
1790 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
1791 codegen_->Store(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001792 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001793 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
1794 }
1795 } else {
1796 codegen_->Store(field_type, value, HeapOperand(obj, offset));
Calin Juravle77520bc2015-01-12 18:45:46 +00001797 codegen_->MaybeRecordImplicitNullCheck(instruction);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00001798 }
1799
1800 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Alexandre Rames67555f72014-11-18 10:55:16 +00001801 codegen_->MarkGCCard(obj, Register(value));
Alexandre Rames5319def2014-10-23 10:03:10 +01001802 }
1803}
1804
Alexandre Rames67555f72014-11-18 10:55:16 +00001805void LocationsBuilderARM64::VisitInstanceOf(HInstanceOf* instruction) {
1806 LocationSummary::CallKind call_kind =
1807 instruction->IsClassFinal() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
1808 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
1809 locations->SetInAt(0, Location::RequiresRegister());
1810 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray6c2dff82015-01-21 14:56:54 +00001811 // The output does overlap inputs.
1812 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Alexandre Rames67555f72014-11-18 10:55:16 +00001813}
1814
1815void InstructionCodeGeneratorARM64::VisitInstanceOf(HInstanceOf* instruction) {
1816 LocationSummary* locations = instruction->GetLocations();
1817 Register obj = InputRegisterAt(instruction, 0);;
1818 Register cls = InputRegisterAt(instruction, 1);;
1819 Register out = OutputRegister(instruction);
1820
1821 vixl::Label done;
1822
1823 // Return 0 if `obj` is null.
1824 // TODO: Avoid this check if we know `obj` is not null.
1825 __ Mov(out, 0);
1826 __ Cbz(obj, &done);
1827
1828 // Compare the class of `obj` with `cls`.
Serban Constantinescu02164b32014-11-13 14:05:07 +00001829 __ Ldr(out, HeapOperand(obj, mirror::Object::ClassOffset()));
Alexandre Rames67555f72014-11-18 10:55:16 +00001830 __ Cmp(out, cls);
1831 if (instruction->IsClassFinal()) {
1832 // Classes must be equal for the instanceof to succeed.
1833 __ Cset(out, eq);
1834 } else {
1835 // If the classes are not equal, we go into a slow path.
1836 DCHECK(locations->OnlyCallsOnSlowPath());
1837 SlowPathCodeARM64* slow_path =
Alexandre Rames3e69f162014-12-10 10:36:50 +00001838 new (GetGraph()->GetArena()) TypeCheckSlowPathARM64(
1839 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Alexandre Rames67555f72014-11-18 10:55:16 +00001840 codegen_->AddSlowPath(slow_path);
1841 __ B(ne, slow_path->GetEntryLabel());
1842 __ Mov(out, 1);
1843 __ Bind(slow_path->GetExitLabel());
1844 }
1845
1846 __ Bind(&done);
1847}
1848
Alexandre Rames5319def2014-10-23 10:03:10 +01001849void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) {
1850 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1851 locations->SetOut(Location::ConstantLocation(constant));
1852}
1853
1854void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) {
1855 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001856 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01001857}
1858
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001859void LocationsBuilderARM64::VisitNullConstant(HNullConstant* constant) {
1860 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
1861 locations->SetOut(Location::ConstantLocation(constant));
1862}
1863
1864void InstructionCodeGeneratorARM64::VisitNullConstant(HNullConstant* constant) {
1865 // Will be generated at use site.
1866 UNUSED(constant);
1867}
1868
Alexandre Rames5319def2014-10-23 10:03:10 +01001869void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) {
1870 LocationSummary* locations =
1871 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
1872 locations->AddTemp(LocationFrom(x0));
1873
1874 InvokeDexCallingConventionVisitor calling_convention_visitor;
1875 for (size_t i = 0; i < invoke->InputCount(); i++) {
1876 HInstruction* input = invoke->InputAt(i);
1877 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1878 }
1879
1880 Primitive::Type return_type = invoke->GetType();
1881 if (return_type != Primitive::kPrimVoid) {
1882 locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type));
1883 }
1884}
1885
Alexandre Rames67555f72014-11-18 10:55:16 +00001886void LocationsBuilderARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1887 HandleInvoke(invoke);
1888}
1889
1890void InstructionCodeGeneratorARM64::VisitInvokeInterface(HInvokeInterface* invoke) {
1891 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
1892 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
1893 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1894 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1895 Location receiver = invoke->GetLocations()->InAt(0);
1896 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001897 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames67555f72014-11-18 10:55:16 +00001898
1899 // The register ip1 is required to be used for the hidden argument in
1900 // art_quick_imt_conflict_trampoline, so prevent VIXL from using it.
1901 UseScratchRegisterScope scratch_scope(GetVIXLAssembler());
1902 scratch_scope.Exclude(ip1);
1903 __ Mov(ip1, invoke->GetDexMethodIndex());
1904
1905 // temp = object->GetClass();
1906 if (receiver.IsStackSlot()) {
1907 __ Ldr(temp, StackOperandFrom(receiver));
1908 __ Ldr(temp, HeapOperand(temp, class_offset));
1909 } else {
1910 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
1911 }
Calin Juravle77520bc2015-01-12 18:45:46 +00001912 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames67555f72014-11-18 10:55:16 +00001913 // temp = temp->GetImtEntryAt(method_offset);
1914 __ Ldr(temp, HeapOperand(temp, method_offset));
1915 // lr = temp->GetEntryPoint();
1916 __ Ldr(lr, HeapOperand(temp, entry_point));
1917 // lr();
1918 __ Blr(lr);
1919 DCHECK(!codegen_->IsLeafMethod());
1920 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1921}
1922
1923void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001924 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1925 if (intrinsic.TryDispatch(invoke)) {
1926 return;
1927 }
1928
Alexandre Rames67555f72014-11-18 10:55:16 +00001929 HandleInvoke(invoke);
1930}
1931
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001932void LocationsBuilderARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001933 IntrinsicLocationsBuilderARM64 intrinsic(GetGraph()->GetArena());
1934 if (intrinsic.TryDispatch(invoke)) {
1935 return;
1936 }
1937
Alexandre Rames67555f72014-11-18 10:55:16 +00001938 HandleInvoke(invoke);
1939}
1940
Andreas Gampe878d58c2015-01-15 23:24:00 -08001941static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorARM64* codegen) {
1942 if (invoke->GetLocations()->Intrinsified()) {
1943 IntrinsicCodeGeneratorARM64 intrinsic(codegen);
1944 intrinsic.Dispatch(invoke);
1945 return true;
1946 }
1947 return false;
1948}
1949
1950void CodeGeneratorARM64::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Register temp) {
1951 // Make sure that ArtMethod* is passed in kArtMethodRegister as per the calling convention.
1952 DCHECK(temp.Is(kArtMethodRegister));
Alexandre Rames5319def2014-10-23 10:03:10 +01001953 size_t index_in_cache = mirror::Array::DataOffset(kHeapRefSize).SizeValue() +
Andreas Gampe878d58c2015-01-15 23:24:00 -08001954 invoke->GetDexMethodIndex() * kHeapRefSize;
Alexandre Rames5319def2014-10-23 10:03:10 +01001955
1956 // TODO: Implement all kinds of calls:
1957 // 1) boot -> boot
1958 // 2) app -> boot
1959 // 3) app -> app
1960 //
1961 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1962
Nicolas Geoffray0a299b92015-01-29 11:39:44 +00001963 // temp = method;
1964 LoadCurrentMethod(temp);
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001965 if (!invoke->IsRecursive()) {
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001966 // temp = temp->dex_cache_resolved_methods_;
1967 __ Ldr(temp, HeapOperand(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset()));
1968 // temp = temp[index_in_cache];
1969 __ Ldr(temp, HeapOperand(temp, index_in_cache));
1970 // lr = temp->entry_point_from_quick_compiled_code_;
1971 __ Ldr(lr, HeapOperand(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1972 kArm64WordSize)));
1973 // lr();
1974 __ Blr(lr);
1975 } else {
1976 __ Bl(&frame_entry_label_);
1977 }
Alexandre Rames5319def2014-10-23 10:03:10 +01001978
Andreas Gampe878d58c2015-01-15 23:24:00 -08001979 DCHECK(!IsLeafMethod());
1980}
1981
1982void InstructionCodeGeneratorARM64::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
1983 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1984 return;
1985 }
1986
1987 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
1988 codegen_->GenerateStaticOrDirectCall(invoke, temp);
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +00001989 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Alexandre Rames5319def2014-10-23 10:03:10 +01001990}
1991
1992void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -08001993 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
1994 return;
1995 }
1996
Alexandre Rames5319def2014-10-23 10:03:10 +01001997 LocationSummary* locations = invoke->GetLocations();
1998 Location receiver = locations->InAt(0);
Serban Constantinescu02164b32014-11-13 14:05:07 +00001999 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002000 size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() +
2001 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
2002 Offset class_offset = mirror::Object::ClassOffset();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00002003 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kArm64WordSize);
Alexandre Rames5319def2014-10-23 10:03:10 +01002004
2005 // temp = object->GetClass();
2006 if (receiver.IsStackSlot()) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002007 __ Ldr(temp, MemOperand(sp, receiver.GetStackIndex()));
2008 __ Ldr(temp, HeapOperand(temp, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002009 } else {
2010 DCHECK(receiver.IsRegister());
Serban Constantinescu02164b32014-11-13 14:05:07 +00002011 __ Ldr(temp, HeapOperandFrom(receiver, class_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002012 }
Calin Juravle77520bc2015-01-12 18:45:46 +00002013 codegen_->MaybeRecordImplicitNullCheck(invoke);
Alexandre Rames5319def2014-10-23 10:03:10 +01002014 // temp = temp->GetMethodAt(method_offset);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002015 __ Ldr(temp, HeapOperand(temp, method_offset));
Alexandre Rames5319def2014-10-23 10:03:10 +01002016 // lr = temp->GetEntryPoint();
Serban Constantinescu02164b32014-11-13 14:05:07 +00002017 __ Ldr(lr, HeapOperand(temp, entry_point.SizeValue()));
Alexandre Rames5319def2014-10-23 10:03:10 +01002018 // lr();
2019 __ Blr(lr);
2020 DCHECK(!codegen_->IsLeafMethod());
2021 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
2022}
2023
Alexandre Rames67555f72014-11-18 10:55:16 +00002024void LocationsBuilderARM64::VisitLoadClass(HLoadClass* cls) {
2025 LocationSummary::CallKind call_kind = cls->CanCallRuntime() ? LocationSummary::kCallOnSlowPath
2026 : LocationSummary::kNoCall;
2027 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
2028 locations->SetOut(Location::RequiresRegister());
2029}
2030
2031void InstructionCodeGeneratorARM64::VisitLoadClass(HLoadClass* cls) {
2032 Register out = OutputRegister(cls);
2033 if (cls->IsReferrersClass()) {
2034 DCHECK(!cls->CanCallRuntime());
2035 DCHECK(!cls->MustGenerateClinitCheck());
2036 codegen_->LoadCurrentMethod(out);
2037 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2038 } else {
2039 DCHECK(cls->CanCallRuntime());
2040 codegen_->LoadCurrentMethod(out);
2041 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DexCacheResolvedTypesOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002042 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002043
2044 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM64(
2045 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2046 codegen_->AddSlowPath(slow_path);
2047 __ Cbz(out, slow_path->GetEntryLabel());
2048 if (cls->MustGenerateClinitCheck()) {
2049 GenerateClassInitializationCheck(slow_path, out);
2050 } else {
2051 __ Bind(slow_path->GetExitLabel());
2052 }
2053 }
2054}
2055
2056void LocationsBuilderARM64::VisitLoadException(HLoadException* load) {
2057 LocationSummary* locations =
2058 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
2059 locations->SetOut(Location::RequiresRegister());
2060}
2061
2062void InstructionCodeGeneratorARM64::VisitLoadException(HLoadException* instruction) {
2063 MemOperand exception = MemOperand(tr, Thread::ExceptionOffset<kArm64WordSize>().Int32Value());
2064 __ Ldr(OutputRegister(instruction), exception);
2065 __ Str(wzr, exception);
2066}
2067
Alexandre Rames5319def2014-10-23 10:03:10 +01002068void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) {
2069 load->SetLocations(nullptr);
2070}
2071
2072void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) {
2073 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002074 UNUSED(load);
Alexandre Rames5319def2014-10-23 10:03:10 +01002075}
2076
Alexandre Rames67555f72014-11-18 10:55:16 +00002077void LocationsBuilderARM64::VisitLoadString(HLoadString* load) {
2078 LocationSummary* locations =
2079 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2080 locations->SetOut(Location::RequiresRegister());
2081}
2082
2083void InstructionCodeGeneratorARM64::VisitLoadString(HLoadString* load) {
2084 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM64(load);
2085 codegen_->AddSlowPath(slow_path);
2086
2087 Register out = OutputRegister(load);
2088 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08002089 __ Ldr(out, HeapOperand(out, mirror::ArtMethod::DeclaringClassOffset()));
2090 __ Ldr(out, HeapOperand(out, mirror::Class::DexCacheStringsOffset()));
Serban Constantinescu02164b32014-11-13 14:05:07 +00002091 __ Ldr(out, HeapOperand(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
Alexandre Rames67555f72014-11-18 10:55:16 +00002092 __ Cbz(out, slow_path->GetEntryLabel());
2093 __ Bind(slow_path->GetExitLabel());
2094}
2095
Alexandre Rames5319def2014-10-23 10:03:10 +01002096void LocationsBuilderARM64::VisitLocal(HLocal* local) {
2097 local->SetLocations(nullptr);
2098}
2099
2100void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) {
2101 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
2102}
2103
2104void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) {
2105 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
2106 locations->SetOut(Location::ConstantLocation(constant));
2107}
2108
2109void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) {
2110 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002111 UNUSED(constant);
Alexandre Rames5319def2014-10-23 10:03:10 +01002112}
2113
Alexandre Rames67555f72014-11-18 10:55:16 +00002114void LocationsBuilderARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2115 LocationSummary* locations =
2116 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2117 InvokeRuntimeCallingConvention calling_convention;
2118 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2119}
2120
2121void InstructionCodeGeneratorARM64::VisitMonitorOperation(HMonitorOperation* instruction) {
2122 codegen_->InvokeRuntime(instruction->IsEnter()
2123 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
2124 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002125 instruction->GetDexPc(),
2126 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002127 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002128}
2129
Alexandre Rames42d641b2014-10-27 14:00:51 +00002130void LocationsBuilderARM64::VisitMul(HMul* mul) {
2131 LocationSummary* locations =
2132 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
2133 switch (mul->GetResultType()) {
2134 case Primitive::kPrimInt:
2135 case Primitive::kPrimLong:
2136 locations->SetInAt(0, Location::RequiresRegister());
2137 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002138 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002139 break;
2140
2141 case Primitive::kPrimFloat:
2142 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002143 locations->SetInAt(0, Location::RequiresFpuRegister());
2144 locations->SetInAt(1, Location::RequiresFpuRegister());
Alexandre Rames67555f72014-11-18 10:55:16 +00002145 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Rames42d641b2014-10-27 14:00:51 +00002146 break;
2147
2148 default:
2149 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2150 }
2151}
2152
2153void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) {
2154 switch (mul->GetResultType()) {
2155 case Primitive::kPrimInt:
2156 case Primitive::kPrimLong:
2157 __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1));
2158 break;
2159
2160 case Primitive::kPrimFloat:
2161 case Primitive::kPrimDouble:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002162 __ Fmul(OutputFPRegister(mul), InputFPRegisterAt(mul, 0), InputFPRegisterAt(mul, 1));
Alexandre Rames42d641b2014-10-27 14:00:51 +00002163 break;
2164
2165 default:
2166 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
2167 }
2168}
2169
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002170void LocationsBuilderARM64::VisitNeg(HNeg* neg) {
2171 LocationSummary* locations =
2172 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
2173 switch (neg->GetResultType()) {
2174 case Primitive::kPrimInt:
Alexandre Rames67555f72014-11-18 10:55:16 +00002175 case Primitive::kPrimLong:
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +00002176 locations->SetInAt(0, ARM64EncodableConstantOrRegister(neg->InputAt(0), neg));
Alexandre Rames67555f72014-11-18 10:55:16 +00002177 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002178 break;
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002179
2180 case Primitive::kPrimFloat:
2181 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002182 locations->SetInAt(0, Location::RequiresFpuRegister());
2183 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002184 break;
2185
2186 default:
2187 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2188 }
2189}
2190
2191void InstructionCodeGeneratorARM64::VisitNeg(HNeg* neg) {
2192 switch (neg->GetResultType()) {
2193 case Primitive::kPrimInt:
2194 case Primitive::kPrimLong:
2195 __ Neg(OutputRegister(neg), InputOperandAt(neg, 0));
2196 break;
2197
2198 case Primitive::kPrimFloat:
2199 case Primitive::kPrimDouble:
Alexandre Rames67555f72014-11-18 10:55:16 +00002200 __ Fneg(OutputFPRegister(neg), InputFPRegisterAt(neg, 0));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002201 break;
2202
2203 default:
2204 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
2205 }
2206}
2207
2208void LocationsBuilderARM64::VisitNewArray(HNewArray* instruction) {
2209 LocationSummary* locations =
2210 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2211 InvokeRuntimeCallingConvention calling_convention;
2212 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002213 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2)));
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002214 locations->SetOut(LocationFrom(x0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002215 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(1)));
2216 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2217 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002218}
2219
2220void InstructionCodeGeneratorARM64::VisitNewArray(HNewArray* instruction) {
2221 LocationSummary* locations = instruction->GetLocations();
2222 InvokeRuntimeCallingConvention calling_convention;
2223 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2224 DCHECK(type_index.Is(w0));
2225 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002226 DCHECK(current_method.Is(w2));
Alexandre Rames67555f72014-11-18 10:55:16 +00002227 codegen_->LoadCurrentMethod(current_method);
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002228 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002229 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002230 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2231 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002232 instruction->GetDexPc(),
2233 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002234 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
2235 void*, uint32_t, int32_t, mirror::ArtMethod*>();
Alexandre Ramesfc19de82014-11-07 17:13:31 +00002236}
2237
Alexandre Rames5319def2014-10-23 10:03:10 +01002238void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) {
2239 LocationSummary* locations =
2240 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2241 InvokeRuntimeCallingConvention calling_convention;
2242 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
2243 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1)));
2244 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002245 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002246}
2247
2248void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
2249 LocationSummary* locations = instruction->GetLocations();
2250 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
2251 DCHECK(type_index.Is(w0));
2252 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
2253 DCHECK(current_method.Is(w1));
Alexandre Rames67555f72014-11-18 10:55:16 +00002254 codegen_->LoadCurrentMethod(current_method);
Alexandre Rames5319def2014-10-23 10:03:10 +01002255 __ Mov(type_index, instruction->GetTypeIndex());
Alexandre Rames67555f72014-11-18 10:55:16 +00002256 codegen_->InvokeRuntime(
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002257 GetThreadOffset<kArm64WordSize>(instruction->GetEntrypoint()).Int32Value(),
2258 instruction,
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002259 instruction->GetDexPc(),
2260 nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002261 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, mirror::ArtMethod*>();
Alexandre Rames5319def2014-10-23 10:03:10 +01002262}
2263
2264void LocationsBuilderARM64::VisitNot(HNot* instruction) {
2265 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexandre Rames4e596512014-11-07 15:56:50 +00002266 locations->SetInAt(0, Location::RequiresRegister());
Alexandre Ramesfb4e5fa2014-11-06 12:41:16 +00002267 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Alexandre Rames5319def2014-10-23 10:03:10 +01002268}
2269
2270void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) {
Nicolas Geoffrayd8ef2e92015-02-24 16:02:06 +00002271 switch (instruction->GetResultType()) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002272 case Primitive::kPrimInt:
Alexandre Rames5319def2014-10-23 10:03:10 +01002273 case Primitive::kPrimLong:
Roland Levillain55dcfb52014-10-24 18:09:09 +01002274 __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0));
Alexandre Rames5319def2014-10-23 10:03:10 +01002275 break;
2276
2277 default:
2278 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
2279 }
2280}
2281
David Brazdil66d126e2015-04-03 16:02:44 +01002282void LocationsBuilderARM64::VisitBooleanNot(HBooleanNot* instruction) {
2283 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2284 locations->SetInAt(0, Location::RequiresRegister());
2285 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2286}
2287
2288void InstructionCodeGeneratorARM64::VisitBooleanNot(HBooleanNot* instruction) {
2289 DCHECK_EQ(instruction->InputAt(0)->GetType(), Primitive::kPrimBoolean);
2290 __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), vixl::Operand(1));
2291}
2292
Alexandre Rames5319def2014-10-23 10:03:10 +01002293void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) {
2294 LocationSummary* locations =
2295 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2296 locations->SetInAt(0, Location::RequiresRegister());
2297 if (instruction->HasUses()) {
2298 locations->SetOut(Location::SameAsFirstInput());
2299 }
2300}
2301
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002302void InstructionCodeGeneratorARM64::GenerateImplicitNullCheck(HNullCheck* instruction) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002303 if (codegen_->CanMoveNullCheckToUser(instruction)) {
2304 return;
2305 }
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002306 Location obj = instruction->GetLocations()->InAt(0);
2307
2308 __ Ldr(wzr, HeapOperandFrom(obj, Offset(0)));
2309 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2310}
2311
2312void InstructionCodeGeneratorARM64::GenerateExplicitNullCheck(HNullCheck* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002313 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction);
2314 codegen_->AddSlowPath(slow_path);
2315
2316 LocationSummary* locations = instruction->GetLocations();
2317 Location obj = locations->InAt(0);
Calin Juravle77520bc2015-01-12 18:45:46 +00002318
2319 __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel());
Alexandre Rames5319def2014-10-23 10:03:10 +01002320}
2321
Calin Juravlecd6dffe2015-01-08 17:35:35 +00002322void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) {
2323 if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) {
2324 GenerateImplicitNullCheck(instruction);
2325 } else {
2326 GenerateExplicitNullCheck(instruction);
2327 }
2328}
2329
Alexandre Rames67555f72014-11-18 10:55:16 +00002330void LocationsBuilderARM64::VisitOr(HOr* instruction) {
2331 HandleBinaryOp(instruction);
2332}
2333
2334void InstructionCodeGeneratorARM64::VisitOr(HOr* instruction) {
2335 HandleBinaryOp(instruction);
2336}
2337
Alexandre Rames3e69f162014-12-10 10:36:50 +00002338void LocationsBuilderARM64::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
2339 LOG(FATAL) << "Unreachable";
2340}
2341
2342void InstructionCodeGeneratorARM64::VisitParallelMove(HParallelMove* instruction) {
2343 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2344}
2345
Alexandre Rames5319def2014-10-23 10:03:10 +01002346void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) {
2347 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2348 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2349 if (location.IsStackSlot()) {
2350 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2351 } else if (location.IsDoubleStackSlot()) {
2352 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2353 }
2354 locations->SetOut(location);
2355}
2356
2357void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) {
2358 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002359 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002360}
2361
2362void LocationsBuilderARM64::VisitPhi(HPhi* instruction) {
2363 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2364 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2365 locations->SetInAt(i, Location::Any());
2366 }
2367 locations->SetOut(Location::Any());
2368}
2369
2370void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002371 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002372 LOG(FATAL) << "Unreachable";
2373}
2374
Serban Constantinescu02164b32014-11-13 14:05:07 +00002375void LocationsBuilderARM64::VisitRem(HRem* rem) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002376 Primitive::Type type = rem->GetResultType();
Alexandre Rames542361f2015-01-29 16:57:31 +00002377 LocationSummary::CallKind call_kind =
2378 Primitive::IsFloatingPointType(type) ? LocationSummary::kCall : LocationSummary::kNoCall;
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002379 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2380
2381 switch (type) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002382 case Primitive::kPrimInt:
2383 case Primitive::kPrimLong:
2384 locations->SetInAt(0, Location::RequiresRegister());
2385 locations->SetInAt(1, Location::RequiresRegister());
2386 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2387 break;
2388
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002389 case Primitive::kPrimFloat:
2390 case Primitive::kPrimDouble: {
2391 InvokeRuntimeCallingConvention calling_convention;
2392 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
2393 locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1)));
2394 locations->SetOut(calling_convention.GetReturnLocation(type));
2395
2396 break;
2397 }
2398
Serban Constantinescu02164b32014-11-13 14:05:07 +00002399 default:
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002400 LOG(FATAL) << "Unexpected rem type " << type;
Serban Constantinescu02164b32014-11-13 14:05:07 +00002401 }
2402}
2403
2404void InstructionCodeGeneratorARM64::VisitRem(HRem* rem) {
2405 Primitive::Type type = rem->GetResultType();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002406
Serban Constantinescu02164b32014-11-13 14:05:07 +00002407 switch (type) {
2408 case Primitive::kPrimInt:
2409 case Primitive::kPrimLong: {
2410 UseScratchRegisterScope temps(GetVIXLAssembler());
2411 Register dividend = InputRegisterAt(rem, 0);
2412 Register divisor = InputRegisterAt(rem, 1);
2413 Register output = OutputRegister(rem);
2414 Register temp = temps.AcquireSameSizeAs(output);
2415
2416 __ Sdiv(temp, dividend, divisor);
2417 __ Msub(output, temp, divisor, dividend);
2418 break;
2419 }
2420
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002421 case Primitive::kPrimFloat:
2422 case Primitive::kPrimDouble: {
2423 int32_t entry_offset = (type == Primitive::kPrimFloat) ? QUICK_ENTRY_POINT(pFmodf)
2424 : QUICK_ENTRY_POINT(pFmod);
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002425 codegen_->InvokeRuntime(entry_offset, rem, rem->GetDexPc(), nullptr);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002426 break;
2427 }
2428
Serban Constantinescu02164b32014-11-13 14:05:07 +00002429 default:
2430 LOG(FATAL) << "Unexpected rem type " << type;
2431 }
2432}
2433
Alexandre Rames5319def2014-10-23 10:03:10 +01002434void LocationsBuilderARM64::VisitReturn(HReturn* instruction) {
2435 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
2436 Primitive::Type return_type = instruction->InputAt(0)->GetType();
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002437 locations->SetInAt(0, ARM64ReturnLocation(return_type));
Alexandre Rames5319def2014-10-23 10:03:10 +01002438}
2439
2440void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002441 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002442 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002443}
2444
2445void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) {
2446 instruction->SetLocations(nullptr);
2447}
2448
2449void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002450 UNUSED(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002451 codegen_->GenerateFrameExit();
Alexandre Rames5319def2014-10-23 10:03:10 +01002452}
2453
Serban Constantinescu02164b32014-11-13 14:05:07 +00002454void LocationsBuilderARM64::VisitShl(HShl* shl) {
2455 HandleShift(shl);
2456}
2457
2458void InstructionCodeGeneratorARM64::VisitShl(HShl* shl) {
2459 HandleShift(shl);
2460}
2461
2462void LocationsBuilderARM64::VisitShr(HShr* shr) {
2463 HandleShift(shr);
2464}
2465
2466void InstructionCodeGeneratorARM64::VisitShr(HShr* shr) {
2467 HandleShift(shr);
2468}
2469
Alexandre Rames5319def2014-10-23 10:03:10 +01002470void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) {
2471 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
2472 Primitive::Type field_type = store->InputAt(1)->GetType();
2473 switch (field_type) {
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002474 case Primitive::kPrimNot:
Alexandre Rames5319def2014-10-23 10:03:10 +01002475 case Primitive::kPrimBoolean:
2476 case Primitive::kPrimByte:
2477 case Primitive::kPrimChar:
2478 case Primitive::kPrimShort:
2479 case Primitive::kPrimInt:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002480 case Primitive::kPrimFloat:
Alexandre Rames5319def2014-10-23 10:03:10 +01002481 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
2482 break;
2483
2484 case Primitive::kPrimLong:
Alexandre Ramesa89086e2014-11-07 17:13:25 +00002485 case Primitive::kPrimDouble:
Alexandre Rames5319def2014-10-23 10:03:10 +01002486 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
2487 break;
2488
2489 default:
2490 LOG(FATAL) << "Unimplemented local type " << field_type;
2491 }
2492}
2493
2494void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002495 UNUSED(store);
Alexandre Rames5319def2014-10-23 10:03:10 +01002496}
2497
2498void LocationsBuilderARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002499 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002500}
2501
2502void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002503 HandleBinaryOp(instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +01002504}
2505
Alexandre Rames67555f72014-11-18 10:55:16 +00002506void LocationsBuilderARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2507 LocationSummary* locations =
2508 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2509 locations->SetInAt(0, Location::RequiresRegister());
2510 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2511}
2512
2513void InstructionCodeGeneratorARM64::VisitStaticFieldGet(HStaticFieldGet* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002514 MemOperand field = HeapOperand(InputRegisterAt(instruction, 0), instruction->GetFieldOffset());
Serban Constantinescu579885a2015-02-22 20:51:33 +00002515 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002516
2517 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00002518 if (use_acquire_release) {
Calin Juravle77520bc2015-01-12 18:45:46 +00002519 // NB: LoadAcquire will record the pc info if needed.
2520 codegen_->LoadAcquire(instruction, OutputCPURegister(instruction), field);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002521 } else {
2522 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
2523 // For IRIW sequential consistency kLoadAny is not sufficient.
2524 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2525 }
2526 } else {
2527 codegen_->Load(instruction->GetType(), OutputCPURegister(instruction), field);
2528 }
Alexandre Rames67555f72014-11-18 10:55:16 +00002529}
2530
2531void LocationsBuilderARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames5319def2014-10-23 10:03:10 +01002532 LocationSummary* locations =
2533 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2534 locations->SetInAt(0, Location::RequiresRegister());
2535 locations->SetInAt(1, Location::RequiresRegister());
Alexandre Rames5319def2014-10-23 10:03:10 +01002536}
2537
Alexandre Rames67555f72014-11-18 10:55:16 +00002538void InstructionCodeGeneratorARM64::VisitStaticFieldSet(HStaticFieldSet* instruction) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002539 Register cls = InputRegisterAt(instruction, 0);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002540 CPURegister value = InputCPURegisterAt(instruction, 1);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002541 Offset offset = instruction->GetFieldOffset();
Alexandre Rames67555f72014-11-18 10:55:16 +00002542 Primitive::Type field_type = instruction->GetFieldType();
Serban Constantinescu579885a2015-02-22 20:51:33 +00002543 bool use_acquire_release = codegen_->GetInstructionSetFeatures().PreferAcquireRelease();
Alexandre Rames5319def2014-10-23 10:03:10 +01002544
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002545 if (instruction->IsVolatile()) {
Serban Constantinescu579885a2015-02-22 20:51:33 +00002546 if (use_acquire_release) {
Serban Constantinescu02d81cc2015-01-05 16:08:49 +00002547 codegen_->StoreRelease(field_type, value, HeapOperand(cls, offset));
2548 } else {
2549 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2550 codegen_->Store(field_type, value, HeapOperand(cls, offset));
2551 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2552 }
2553 } else {
2554 codegen_->Store(field_type, value, HeapOperand(cls, offset));
2555 }
2556
2557 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002558 codegen_->MarkGCCard(cls, Register(value));
2559 }
Alexandre Rames5319def2014-10-23 10:03:10 +01002560}
2561
2562void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
2563 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2564}
2565
2566void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002567 HBasicBlock* block = instruction->GetBlock();
2568 if (block->GetLoopInformation() != nullptr) {
2569 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2570 // The back edge will generate the suspend check.
2571 return;
2572 }
2573 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2574 // The goto will generate the suspend check.
2575 return;
2576 }
2577 GenerateSuspendCheck(instruction, nullptr);
Alexandre Rames5319def2014-10-23 10:03:10 +01002578}
2579
2580void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) {
2581 temp->SetLocations(nullptr);
2582}
2583
2584void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) {
2585 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002586 UNUSED(temp);
Alexandre Rames5319def2014-10-23 10:03:10 +01002587}
2588
Alexandre Rames67555f72014-11-18 10:55:16 +00002589void LocationsBuilderARM64::VisitThrow(HThrow* instruction) {
2590 LocationSummary* locations =
2591 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2592 InvokeRuntimeCallingConvention calling_convention;
2593 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2594}
2595
2596void InstructionCodeGeneratorARM64::VisitThrow(HThrow* instruction) {
2597 codegen_->InvokeRuntime(
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +00002598 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc(), nullptr);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002599 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
Alexandre Rames67555f72014-11-18 10:55:16 +00002600}
2601
2602void LocationsBuilderARM64::VisitTypeConversion(HTypeConversion* conversion) {
2603 LocationSummary* locations =
2604 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
2605 Primitive::Type input_type = conversion->GetInputType();
2606 Primitive::Type result_type = conversion->GetResultType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00002607 DCHECK_NE(input_type, result_type);
Alexandre Rames67555f72014-11-18 10:55:16 +00002608 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
2609 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
2610 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
2611 }
2612
Alexandre Rames542361f2015-01-29 16:57:31 +00002613 if (Primitive::IsFloatingPointType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002614 locations->SetInAt(0, Location::RequiresFpuRegister());
2615 } else {
2616 locations->SetInAt(0, Location::RequiresRegister());
2617 }
2618
Alexandre Rames542361f2015-01-29 16:57:31 +00002619 if (Primitive::IsFloatingPointType(result_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002620 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2621 } else {
2622 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2623 }
2624}
2625
2626void InstructionCodeGeneratorARM64::VisitTypeConversion(HTypeConversion* conversion) {
2627 Primitive::Type result_type = conversion->GetResultType();
2628 Primitive::Type input_type = conversion->GetInputType();
2629
2630 DCHECK_NE(input_type, result_type);
2631
Alexandre Rames542361f2015-01-29 16:57:31 +00002632 if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexandre Rames67555f72014-11-18 10:55:16 +00002633 int result_size = Primitive::ComponentSize(result_type);
2634 int input_size = Primitive::ComponentSize(input_type);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002635 int min_size = std::min(result_size, input_size);
Serban Constantinescu02164b32014-11-13 14:05:07 +00002636 Register output = OutputRegister(conversion);
2637 Register source = InputRegisterAt(conversion, 0);
Alexandre Rames3e69f162014-12-10 10:36:50 +00002638 if ((result_type == Primitive::kPrimChar) && (input_size < result_size)) {
2639 __ Ubfx(output, source, 0, result_size * kBitsPerByte);
2640 } else if ((result_type == Primitive::kPrimChar) ||
2641 ((input_type == Primitive::kPrimChar) && (result_size > input_size))) {
2642 __ Ubfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002643 } else {
Alexandre Rames3e69f162014-12-10 10:36:50 +00002644 __ Sbfx(output, output.IsX() ? source.X() : source.W(), 0, min_size * kBitsPerByte);
Alexandre Rames67555f72014-11-18 10:55:16 +00002645 }
Alexandre Rames542361f2015-01-29 16:57:31 +00002646 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002647 __ Scvtf(OutputFPRegister(conversion), InputRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002648 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002649 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
2650 __ Fcvtzs(OutputRegister(conversion), InputFPRegisterAt(conversion, 0));
Alexandre Rames542361f2015-01-29 16:57:31 +00002651 } else if (Primitive::IsFloatingPointType(result_type) &&
2652 Primitive::IsFloatingPointType(input_type)) {
Serban Constantinescu02164b32014-11-13 14:05:07 +00002653 __ Fcvt(OutputFPRegister(conversion), InputFPRegisterAt(conversion, 0));
2654 } else {
2655 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
2656 << " to " << result_type;
Alexandre Rames67555f72014-11-18 10:55:16 +00002657 }
Serban Constantinescu02164b32014-11-13 14:05:07 +00002658}
Alexandre Rames67555f72014-11-18 10:55:16 +00002659
Serban Constantinescu02164b32014-11-13 14:05:07 +00002660void LocationsBuilderARM64::VisitUShr(HUShr* ushr) {
2661 HandleShift(ushr);
2662}
2663
2664void InstructionCodeGeneratorARM64::VisitUShr(HUShr* ushr) {
2665 HandleShift(ushr);
Alexandre Rames67555f72014-11-18 10:55:16 +00002666}
2667
2668void LocationsBuilderARM64::VisitXor(HXor* instruction) {
2669 HandleBinaryOp(instruction);
2670}
2671
2672void InstructionCodeGeneratorARM64::VisitXor(HXor* instruction) {
2673 HandleBinaryOp(instruction);
2674}
2675
Calin Juravleb1498f62015-02-16 13:13:29 +00002676void LocationsBuilderARM64::VisitBoundType(HBoundType* instruction) {
2677 // Nothing to do, this should be removed during prepare for register allocator.
2678 UNUSED(instruction);
2679 LOG(FATAL) << "Unreachable";
2680}
2681
2682void InstructionCodeGeneratorARM64::VisitBoundType(HBoundType* instruction) {
2683 // Nothing to do, this should be removed during prepare for register allocator.
2684 UNUSED(instruction);
2685 LOG(FATAL) << "Unreachable";
2686}
2687
Alexandre Rames67555f72014-11-18 10:55:16 +00002688#undef __
2689#undef QUICK_ENTRY_POINT
2690
Alexandre Rames5319def2014-10-23 10:03:10 +01002691} // namespace arm64
2692} // namespace art