blob: 5d504c697a1a2167607125502e937eec3df6d8fa [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
19#include "entrypoints/quick/quick_entrypoints.h"
20#include "gc/accounting/card_table.h"
21#include "mirror/array-inl.h"
22#include "mirror/art_method.h"
23#include "mirror/class.h"
24#include "thread.h"
25#include "utils/arm64/assembler_arm64.h"
26#include "utils/assembler.h"
27#include "utils/stack_checks.h"
28
29
30using namespace vixl; // NOLINT(build/namespaces)
31
32#ifdef __
33#error "ARM64 Codegen VIXL macro-assembler macro already defined."
34#endif
35
36
37namespace art {
38
39namespace arm64 {
40
41static bool IsFPType(Primitive::Type type) {
42 return type == Primitive::kPrimFloat || type == Primitive::kPrimDouble;
43}
44
45// TODO: clean-up some of the constant definitions.
46static constexpr size_t kHeapRefSize = sizeof(mirror::HeapReference<mirror::Object>);
47static constexpr int kCurrentMethodStackOffset = 0;
48
49namespace {
50// Convenience helpers to ease conversion to and from VIXL operands.
51
52int VIXLRegCodeFromART(int code) {
53 // TODO: static check?
54 DCHECK_EQ(SP, 31);
55 DCHECK_EQ(WSP, 31);
56 DCHECK_EQ(XZR, 32);
57 DCHECK_EQ(WZR, 32);
58 if (code == SP) {
59 return vixl::kSPRegInternalCode;
60 }
61 if (code == XZR) {
62 return vixl::kZeroRegCode;
63 }
64 return code;
65}
66
67int ARTRegCodeFromVIXL(int code) {
68 // TODO: static check?
69 DCHECK_EQ(SP, 31);
70 DCHECK_EQ(WSP, 31);
71 DCHECK_EQ(XZR, 32);
72 DCHECK_EQ(WZR, 32);
73 if (code == vixl::kSPRegInternalCode) {
74 return SP;
75 }
76 if (code == vixl::kZeroRegCode) {
77 return XZR;
78 }
79 return code;
80}
81
82Register XRegisterFrom(Location location) {
83 return Register::XRegFromCode(VIXLRegCodeFromART(location.reg()));
84}
85
86Register WRegisterFrom(Location location) {
87 return Register::WRegFromCode(VIXLRegCodeFromART(location.reg()));
88}
89
90Register RegisterFrom(Location location, Primitive::Type type) {
91 DCHECK(type != Primitive::kPrimVoid && !IsFPType(type));
92 return type == Primitive::kPrimLong ? XRegisterFrom(location) : WRegisterFrom(location);
93}
94
95Register OutputRegister(HInstruction* instr) {
96 return RegisterFrom(instr->GetLocations()->Out(), instr->GetType());
97}
98
99Register InputRegisterAt(HInstruction* instr, int input_index) {
100 return RegisterFrom(instr->GetLocations()->InAt(input_index),
101 instr->InputAt(input_index)->GetType());
102}
103
104int64_t Int64ConstantFrom(Location location) {
105 HConstant* instr = location.GetConstant();
106 return instr->IsIntConstant() ? instr->AsIntConstant()->GetValue()
107 : instr->AsLongConstant()->GetValue();
108}
109
110Operand OperandFrom(Location location, Primitive::Type type) {
111 if (location.IsRegister()) {
112 return Operand(RegisterFrom(location, type));
113 } else {
114 return Operand(Int64ConstantFrom(location));
115 }
116}
117
118Operand InputOperandAt(HInstruction* instr, int input_index) {
119 return OperandFrom(instr->GetLocations()->InAt(input_index),
120 instr->InputAt(input_index)->GetType());
121}
122
123MemOperand StackOperandFrom(Location location) {
124 return MemOperand(sp, location.GetStackIndex());
125}
126
127MemOperand HeapOperand(const Register& base, Offset offset) {
128 // A heap reference must be 32bit, so fit in a W register.
129 DCHECK(base.IsW());
130 return MemOperand(base.X(), offset.SizeValue());
131}
132
133MemOperand HeapOperandFrom(Location location, Primitive::Type type, Offset offset) {
134 return HeapOperand(RegisterFrom(location, type), offset);
135}
136
137Location LocationFrom(const Register& reg) {
138 return Location::RegisterLocation(ARTRegCodeFromVIXL(reg.code()));
139}
140
141} // namespace
142
143inline Condition ARM64Condition(IfCondition cond) {
144 switch (cond) {
145 case kCondEQ: return eq;
146 case kCondNE: return ne;
147 case kCondLT: return lt;
148 case kCondLE: return le;
149 case kCondGT: return gt;
150 case kCondGE: return ge;
151 default:
152 LOG(FATAL) << "Unknown if condition";
153 }
154 return nv; // Unreachable.
155}
156
157static const Register kRuntimeParameterCoreRegisters[] = { x0, x1, x2, x3, x4, x5, x6, x7 };
158static constexpr size_t kRuntimeParameterCoreRegistersLength =
159 arraysize(kRuntimeParameterCoreRegisters);
160static const FPRegister kRuntimeParameterFpuRegisters[] = { };
161static constexpr size_t kRuntimeParameterFpuRegistersLength = 0;
162
163class InvokeRuntimeCallingConvention : public CallingConvention<Register, FPRegister> {
164 public:
165 static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters);
166
167 InvokeRuntimeCallingConvention()
168 : CallingConvention(kRuntimeParameterCoreRegisters,
169 kRuntimeParameterCoreRegistersLength,
170 kRuntimeParameterFpuRegisters,
171 kRuntimeParameterFpuRegistersLength) {}
172
173 Location GetReturnLocation(Primitive::Type return_type);
174
175 private:
176 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
177};
178
179Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type return_type) {
180 DCHECK_NE(return_type, Primitive::kPrimVoid);
181 if (return_type == Primitive::kPrimFloat || return_type == Primitive::kPrimDouble) {
182 LOG(FATAL) << "Unimplemented return type " << return_type;
183 }
184 return LocationFrom(x0);
185}
186
187#define __ reinterpret_cast<Arm64Assembler*>(codegen->GetAssembler())->vixl_masm_->
188
189class SlowPathCodeARM64 : public SlowPathCode {
190 public:
191 SlowPathCodeARM64() : entry_label_(), exit_label_() {}
192
193 vixl::Label* GetEntryLabel() { return &entry_label_; }
194 vixl::Label* GetExitLabel() { return &exit_label_; }
195
196 private:
197 vixl::Label entry_label_;
198 vixl::Label exit_label_;
199
200 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM64);
201};
202
203class BoundsCheckSlowPathARM64 : public SlowPathCodeARM64 {
204 public:
205 explicit BoundsCheckSlowPathARM64(HBoundsCheck* instruction,
206 Location index_location,
207 Location length_location)
208 : instruction_(instruction),
209 index_location_(index_location),
210 length_location_(length_location) {}
211
212 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
213 CodeGeneratorARM64* arm64_codegen = reinterpret_cast<CodeGeneratorARM64*>(codegen);
214 __ Bind(GetEntryLabel());
215 InvokeRuntimeCallingConvention calling_convention;
216 arm64_codegen->MoveHelper(LocationFrom(calling_convention.GetRegisterAt(0)),
217 index_location_, Primitive::kPrimInt);
218 arm64_codegen->MoveHelper(LocationFrom(calling_convention.GetRegisterAt(1)),
219 length_location_, Primitive::kPrimInt);
220 size_t offset = QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pThrowArrayBounds).SizeValue();
221 __ Ldr(lr, MemOperand(tr, offset));
222 __ Blr(lr);
223 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
224 }
225
226 private:
227 HBoundsCheck* const instruction_;
228 const Location index_location_;
229 const Location length_location_;
230
231 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM64);
232};
233
234class NullCheckSlowPathARM64 : public SlowPathCodeARM64 {
235 public:
236 explicit NullCheckSlowPathARM64(HNullCheck* instr) : instruction_(instr) {}
237
238 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
239 __ Bind(GetEntryLabel());
240 int32_t offset = QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pThrowNullPointer).Int32Value();
241 __ Ldr(lr, MemOperand(tr, offset));
242 __ Blr(lr);
243 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
244 }
245
246 private:
247 HNullCheck* const instruction_;
248
249 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM64);
250};
251
252class SuspendCheckSlowPathARM64 : public SlowPathCodeARM64 {
253 public:
254 explicit SuspendCheckSlowPathARM64(HSuspendCheck* instruction,
255 HBasicBlock* successor)
256 : instruction_(instruction), successor_(successor) {}
257
258 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
259 size_t offset = QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pTestSuspend).SizeValue();
260 __ Bind(GetEntryLabel());
261 __ Ldr(lr, MemOperand(tr, offset));
262 __ Blr(lr);
263 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
264 __ B(GetReturnLabel());
265 }
266
267 vixl::Label* GetReturnLabel() {
268 DCHECK(successor_ == nullptr);
269 return &return_label_;
270 }
271
272
273 private:
274 HSuspendCheck* const instruction_;
275 // If not null, the block to branch to after the suspend check.
276 HBasicBlock* const successor_;
277
278 // If `successor_` is null, the label to branch to after the suspend check.
279 vixl::Label return_label_;
280
281 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM64);
282};
283
284#undef __
285
286Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
287 Location next_location;
288 if (type == Primitive::kPrimVoid) {
289 LOG(FATAL) << "Unreachable type " << type;
290 }
291
292 if (type == Primitive::kPrimFloat || type == Primitive::kPrimDouble) {
293 LOG(FATAL) << "Unimplemented type " << type;
294 }
295
296 if (gp_index_ < calling_convention.GetNumberOfRegisters()) {
297 next_location = LocationFrom(calling_convention.GetRegisterAt(gp_index_));
298 if (type == Primitive::kPrimLong) {
299 // Double stack slot reserved on the stack.
300 stack_index_++;
301 }
302 } else { // Stack.
303 if (type == Primitive::kPrimLong) {
304 next_location = Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_));
305 // Double stack slot reserved on the stack.
306 stack_index_++;
307 } else {
308 next_location = Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_));
309 }
310 }
311 // Move to the next register/stack slot.
312 gp_index_++;
313 stack_index_++;
314 return next_location;
315}
316
317CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph)
318 : CodeGenerator(graph,
319 kNumberOfAllocatableRegisters,
320 kNumberOfAllocatableFloatingPointRegisters,
321 kNumberOfAllocatableRegisterPairs),
322 block_labels_(nullptr),
323 location_builder_(graph, this),
324 instruction_visitor_(graph, this) {}
325
326#define __ reinterpret_cast<Arm64Assembler*>(GetAssembler())->vixl_masm_->
327
328void CodeGeneratorARM64::GenerateFrameEntry() {
329 // TODO: Add proper support for the stack overflow check.
330 UseScratchRegisterScope temps(assembler_.vixl_masm_);
331 Register temp = temps.AcquireX();
332 __ Add(temp, sp, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm64)));
333 __ Ldr(temp, MemOperand(temp, 0));
334 RecordPcInfo(nullptr, 0);
335
336 CPURegList preserved_regs = GetFramePreservedRegisters();
337 int frame_size = GetFrameSize();
338 core_spill_mask_ |= preserved_regs.list();
339
340 __ Str(w0, MemOperand(sp, -frame_size, PreIndex));
341 __ PokeCPURegList(preserved_regs, frame_size - preserved_regs.TotalSizeInBytes());
342
343 // Stack layout:
344 // sp[frame_size - 8] : lr.
345 // ... : other preserved registers.
346 // sp[frame_size - regs_size]: first preserved register.
347 // ... : reserved frame space.
348 // sp[0] : context pointer.
349}
350
351void CodeGeneratorARM64::GenerateFrameExit() {
352 int frame_size = GetFrameSize();
353 CPURegList preserved_regs = GetFramePreservedRegisters();
354 __ PeekCPURegList(preserved_regs, frame_size - preserved_regs.TotalSizeInBytes());
355 __ Drop(frame_size);
356}
357
358void CodeGeneratorARM64::Bind(HBasicBlock* block) {
359 __ Bind(GetLabelOf(block));
360}
361
362void CodeGeneratorARM64::MoveHelper(Location destination,
363 Location source,
364 Primitive::Type type) {
365 if (source.Equals(destination)) {
366 return;
367 }
368 if (destination.IsRegister()) {
369 Register dst = RegisterFrom(destination, type);
370 if (source.IsRegister()) {
371 Register src = RegisterFrom(source, type);
372 DCHECK(dst.IsSameSizeAndType(src));
373 __ Mov(dst, src);
374 } else {
375 DCHECK(dst.Is64Bits() || !source.IsDoubleStackSlot());
376 __ Ldr(dst, StackOperandFrom(source));
377 }
378 } else {
379 DCHECK(destination.IsStackSlot() || destination.IsDoubleStackSlot());
380 if (source.IsRegister()) {
381 __ Str(RegisterFrom(source, type), StackOperandFrom(destination));
382 } else {
383 UseScratchRegisterScope temps(assembler_.vixl_masm_);
384 Register temp = destination.IsDoubleStackSlot() ? temps.AcquireX() : temps.AcquireW();
385 __ Ldr(temp, StackOperandFrom(source));
386 __ Str(temp, StackOperandFrom(destination));
387 }
388 }
389}
390
391void CodeGeneratorARM64::Move(HInstruction* instruction,
392 Location location,
393 HInstruction* move_for) {
394 LocationSummary* locations = instruction->GetLocations();
395 if (locations != nullptr && locations->Out().Equals(location)) {
396 return;
397 }
398
399 Primitive::Type type = instruction->GetType();
400
401 if (instruction->IsIntConstant() || instruction->IsLongConstant()) {
402 int64_t value = instruction->IsIntConstant() ? instruction->AsIntConstant()->GetValue()
403 : instruction->AsLongConstant()->GetValue();
404 if (location.IsRegister()) {
405 Register dst = RegisterFrom(location, type);
406 DCHECK((instruction->IsIntConstant() && dst.Is32Bits()) ||
407 (instruction->IsLongConstant() && dst.Is64Bits()));
408 __ Mov(dst, value);
409 } else {
410 DCHECK(location.IsStackSlot() || location.IsDoubleStackSlot());
411 UseScratchRegisterScope temps(assembler_.vixl_masm_);
412 Register temp = instruction->IsIntConstant() ? temps.AcquireW() : temps.AcquireX();
413 __ Mov(temp, value);
414 __ Str(temp, StackOperandFrom(location));
415 }
416
417 } else if (instruction->IsLoadLocal()) {
418 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
419 switch (type) {
420 case Primitive::kPrimNot:
421 case Primitive::kPrimBoolean:
422 case Primitive::kPrimByte:
423 case Primitive::kPrimChar:
424 case Primitive::kPrimShort:
425 case Primitive::kPrimInt:
426 MoveHelper(location, Location::StackSlot(stack_slot), type);
427 break;
428 case Primitive::kPrimLong:
429 MoveHelper(location, Location::DoubleStackSlot(stack_slot), type);
430 break;
431 default:
432 LOG(FATAL) << "Unimplemented type" << type;
433 }
434
435 } else {
436 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
437 MoveHelper(location, locations->Out(), type);
438 }
439}
440
441size_t CodeGeneratorARM64::FrameEntrySpillSize() const {
442 return GetFramePreservedRegistersSize();
443}
444
445Location CodeGeneratorARM64::GetStackLocation(HLoadLocal* load) const {
446 Primitive::Type type = load->GetType();
447 switch (type) {
448 case Primitive::kPrimNot:
449 case Primitive::kPrimBoolean:
450 case Primitive::kPrimByte:
451 case Primitive::kPrimChar:
452 case Primitive::kPrimShort:
453 case Primitive::kPrimInt:
454 return Location::StackSlot(GetStackSlot(load->GetLocal()));
455 case Primitive::kPrimLong:
456 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
457 case Primitive::kPrimFloat:
458 case Primitive::kPrimDouble:
459 LOG(FATAL) << "Unimplemented type " << type;
460 break;
461 case Primitive::kPrimVoid:
462 default:
463 LOG(FATAL) << "Unexpected type " << type;
464 }
465 LOG(FATAL) << "Unreachable";
466 return Location::NoLocation();
467}
468
469void CodeGeneratorARM64::MarkGCCard(Register object, Register value) {
470 UseScratchRegisterScope temps(assembler_.vixl_masm_);
471 Register card = temps.AcquireX();
472 Register temp = temps.AcquireX();
473 vixl::Label done;
474 __ Cbz(value, &done);
475 __ Ldr(card, MemOperand(tr, Thread::CardTableOffset<kArm64WordSize>().Int32Value()));
476 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
477 __ Strb(card, MemOperand(card, temp));
478 __ Bind(&done);
479}
480
481void CodeGeneratorARM64::SetupBlockedRegisters() const {
482 // Block reserved registers:
483 // ip0 (VIXL temporary)
484 // ip1 (VIXL temporary)
485 // xSuspend (Suspend counter)
486 // lr
487 // sp is not part of the allocatable registers, so we don't need to block it.
488 CPURegList reserved_core_registers = vixl_reserved_core_registers;
489 reserved_core_registers.Combine(runtime_reserved_core_registers);
490 // TODO: See if we should instead allow allocating but preserve those if used.
491 reserved_core_registers.Combine(quick_callee_saved_registers);
492 while (!reserved_core_registers.IsEmpty()) {
493 blocked_core_registers_[reserved_core_registers.PopLowestIndex().code()] = true;
494 }
495}
496
497Location CodeGeneratorARM64::AllocateFreeRegister(Primitive::Type type) const {
498 if (type == Primitive::kPrimVoid) {
499 LOG(FATAL) << "Unreachable type " << type;
500 }
501
502 if (type == Primitive::kPrimFloat || type == Primitive::kPrimDouble) {
503 LOG(FATAL) << "Unimplemented support for floating-point";
504 }
505
506 ssize_t reg = FindFreeEntry(blocked_core_registers_, kNumberOfXRegisters);
507 DCHECK_NE(reg, -1);
508 blocked_core_registers_[reg] = true;
509
510 if (IsFPType(type)) {
511 return Location::FpuRegisterLocation(reg);
512 } else {
513 return Location::RegisterLocation(reg);
514 }
515}
516
517void CodeGeneratorARM64::DumpCoreRegister(std::ostream& stream, int reg) const {
518 stream << Arm64ManagedRegister::FromXRegister(XRegister(reg));
519}
520
521void CodeGeneratorARM64::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
522 stream << Arm64ManagedRegister::FromDRegister(DRegister(reg));
523}
524
525#undef __
526#define __ assembler_->vixl_masm_->
527
528InstructionCodeGeneratorARM64::InstructionCodeGeneratorARM64(HGraph* graph,
529 CodeGeneratorARM64* codegen)
530 : HGraphVisitor(graph),
531 assembler_(codegen->GetAssembler()),
532 codegen_(codegen) {}
533
534#define FOR_EACH_UNIMPLEMENTED_INSTRUCTION(M) \
535 M(ArrayGet) \
536 M(ArraySet) \
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100537 M(ClinitCheck) \
Alexandre Rames5319def2014-10-23 10:03:10 +0100538 M(DoubleConstant) \
Calin Juravle7c4954d2014-10-28 16:57:40 +0000539 M(Div) \
Alexandre Rames5319def2014-10-23 10:03:10 +0100540 M(FloatConstant) \
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100541 M(LoadClass) \
Alexandre Rames5319def2014-10-23 10:03:10 +0100542 M(Neg) \
543 M(NewArray) \
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100544 M(ParallelMove) \
545 M(StaticFieldGet) \
546 M(StaticFieldSet) \
Alexandre Rames5319def2014-10-23 10:03:10 +0100547
548#define UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name) name##UnimplementedInstructionBreakCode
549
550enum UnimplementedInstructionBreakCode {
551#define ENUM_UNIMPLEMENTED_INSTRUCTION(name) UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name),
552 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(ENUM_UNIMPLEMENTED_INSTRUCTION)
553#undef ENUM_UNIMPLEMENTED_INSTRUCTION
554};
555
556#define DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS(name) \
557 void InstructionCodeGeneratorARM64::Visit##name(H##name* instr) { \
558 __ Brk(UNIMPLEMENTED_INSTRUCTION_BREAK_CODE(name)); \
559 } \
560 void LocationsBuilderARM64::Visit##name(H##name* instr) { \
561 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr); \
562 locations->SetOut(Location::Any()); \
563 }
564 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS)
565#undef DEFINE_UNIMPLEMENTED_INSTRUCTION_VISITORS
566
567#undef UNIMPLEMENTED_INSTRUCTION_BREAK_CODE
568
569void LocationsBuilderARM64::HandleAddSub(HBinaryOperation* instr) {
570 DCHECK(instr->IsAdd() || instr->IsSub());
571 DCHECK_EQ(instr->InputCount(), 2U);
572 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
573 Primitive::Type type = instr->GetResultType();
574 switch (type) {
575 case Primitive::kPrimInt:
576 case Primitive::kPrimLong: {
577 locations->SetInAt(0, Location::RequiresRegister());
578 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
579 locations->SetOut(Location::RequiresRegister());
580 break;
581 }
582 case Primitive::kPrimBoolean:
583 case Primitive::kPrimByte:
584 case Primitive::kPrimChar:
585 case Primitive::kPrimShort:
586 LOG(FATAL) << "Unexpected " << instr->DebugName() << " type " << type;
587 break;
588 default:
589 LOG(FATAL) << "Unimplemented " << instr->DebugName() << " type " << type;
590 }
591}
592
593void InstructionCodeGeneratorARM64::HandleAddSub(HBinaryOperation* instr) {
594 DCHECK(instr->IsAdd() || instr->IsSub());
595
596 Primitive::Type type = instr->GetType();
597 Register dst = OutputRegister(instr);
598 Register lhs = InputRegisterAt(instr, 0);
599 Operand rhs = InputOperandAt(instr, 1);
600
601 switch (type) {
602 case Primitive::kPrimInt:
603 case Primitive::kPrimLong:
604 if (instr->IsAdd()) {
605 __ Add(dst, lhs, rhs);
606 } else {
607 __ Sub(dst, lhs, rhs);
608 }
609 break;
610
611 case Primitive::kPrimBoolean:
612 case Primitive::kPrimByte:
613 case Primitive::kPrimChar:
614 case Primitive::kPrimShort:
615 LOG(FATAL) << "Unexpected add/sub type " << type;
616 break;
617 default:
618 LOG(FATAL) << "Unimplemented add/sub type " << type;
619 }
620}
621
622void LocationsBuilderARM64::VisitAdd(HAdd* instruction) {
623 HandleAddSub(instruction);
624}
625
626void InstructionCodeGeneratorARM64::VisitAdd(HAdd* instruction) {
627 HandleAddSub(instruction);
628}
629
630void LocationsBuilderARM64::VisitArrayLength(HArrayLength* instruction) {
631 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
632 locations->SetInAt(0, Location::RequiresRegister());
633 locations->SetOut(Location::RequiresRegister());
634}
635
636void InstructionCodeGeneratorARM64::VisitArrayLength(HArrayLength* instruction) {
637 __ Ldr(OutputRegister(instruction),
638 HeapOperand(InputRegisterAt(instruction, 0), mirror::Array::LengthOffset()));
639}
640
641void LocationsBuilderARM64::VisitCompare(HCompare* instruction) {
642 LocationSummary* locations =
643 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
644 locations->SetInAt(0, Location::RequiresRegister());
645 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
646 locations->SetOut(Location::RequiresRegister());
647}
648
649void InstructionCodeGeneratorARM64::VisitCompare(HCompare* instruction) {
650 Primitive::Type in_type = instruction->InputAt(0)->GetType();
651
652 DCHECK_EQ(in_type, Primitive::kPrimLong);
653 switch (in_type) {
654 case Primitive::kPrimLong: {
655 vixl::Label done;
656 Register result = OutputRegister(instruction);
657 Register left = InputRegisterAt(instruction, 0);
658 Operand right = InputOperandAt(instruction, 1);
659 __ Subs(result, left, right);
660 __ B(eq, &done);
661 __ Mov(result, 1);
662 __ Cneg(result, result, le);
663 __ Bind(&done);
664 break;
665 }
666 default:
667 LOG(FATAL) << "Unimplemented compare type " << in_type;
668 }
669}
670
671void LocationsBuilderARM64::VisitCondition(HCondition* instruction) {
672 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
673 locations->SetInAt(0, Location::RequiresRegister());
674 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
675 if (instruction->NeedsMaterialization()) {
676 locations->SetOut(Location::RequiresRegister());
677 }
678}
679
680void InstructionCodeGeneratorARM64::VisitCondition(HCondition* instruction) {
681 if (!instruction->NeedsMaterialization()) {
682 return;
683 }
684
685 LocationSummary* locations = instruction->GetLocations();
686 Register lhs = InputRegisterAt(instruction, 0);
687 Operand rhs = InputOperandAt(instruction, 1);
688 Register res = RegisterFrom(locations->Out(), instruction->GetType());
689 Condition cond = ARM64Condition(instruction->GetCondition());
690
691 __ Cmp(lhs, rhs);
692 __ Csel(res, vixl::Assembler::AppropriateZeroRegFor(res), Operand(1), InvertCondition(cond));
693}
694
695#define FOR_EACH_CONDITION_INSTRUCTION(M) \
696 M(Equal) \
697 M(NotEqual) \
698 M(LessThan) \
699 M(LessThanOrEqual) \
700 M(GreaterThan) \
701 M(GreaterThanOrEqual)
702#define DEFINE_CONDITION_VISITORS(Name) \
703void LocationsBuilderARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); } \
704void InstructionCodeGeneratorARM64::Visit##Name(H##Name* comp) { VisitCondition(comp); }
705FOR_EACH_CONDITION_INSTRUCTION(DEFINE_CONDITION_VISITORS)
706#undef FOR_EACH_CONDITION_INSTRUCTION
707
708void LocationsBuilderARM64::VisitExit(HExit* exit) {
709 exit->SetLocations(nullptr);
710}
711
712void InstructionCodeGeneratorARM64::VisitExit(HExit* exit) {
713 if (kIsDebugBuild) {
714 down_cast<Arm64Assembler*>(GetAssembler())->Comment("Unreachable");
715 __ Brk(0); // TODO: Introduce special markers for such code locations.
716 }
717}
718
719void LocationsBuilderARM64::VisitGoto(HGoto* got) {
720 got->SetLocations(nullptr);
721}
722
723void InstructionCodeGeneratorARM64::VisitGoto(HGoto* got) {
724 HBasicBlock* successor = got->GetSuccessor();
725 // TODO: Support for suspend checks emission.
726 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
727 __ B(codegen_->GetLabelOf(successor));
728 }
729}
730
731void LocationsBuilderARM64::VisitIf(HIf* if_instr) {
732 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
733 HInstruction* cond = if_instr->InputAt(0);
734 DCHECK(cond->IsCondition());
735 if (cond->AsCondition()->NeedsMaterialization()) {
736 locations->SetInAt(0, Location::RequiresRegister());
737 }
738}
739
740void InstructionCodeGeneratorARM64::VisitIf(HIf* if_instr) {
741 HInstruction* cond = if_instr->InputAt(0);
742 DCHECK(cond->IsCondition());
743 HCondition* condition = cond->AsCondition();
744 vixl::Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor());
745 vixl::Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor());
746
747 // TODO: Support constant condition input in VisitIf.
748
749 if (condition->NeedsMaterialization()) {
750 // The condition instruction has been materialized, compare the output to 0.
751 Location cond_val = if_instr->GetLocations()->InAt(0);
752 DCHECK(cond_val.IsRegister());
753 __ Cbnz(InputRegisterAt(if_instr, 0), true_target);
754
755 } else {
756 // The condition instruction has not been materialized, use its inputs as
757 // the comparison and its condition as the branch condition.
758 Register lhs = InputRegisterAt(condition, 0);
759 Operand rhs = InputOperandAt(condition, 1);
760 Condition cond = ARM64Condition(condition->GetCondition());
761 if ((cond == eq || cond == ne) && rhs.IsImmediate() && (rhs.immediate() == 0)) {
762 if (cond == eq) {
763 __ Cbz(lhs, true_target);
764 } else {
765 __ Cbnz(lhs, true_target);
766 }
767 } else {
768 __ Cmp(lhs, rhs);
769 __ B(cond, true_target);
770 }
771 }
772
773 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(), if_instr->IfFalseSuccessor())) {
774 __ B(false_target);
775 }
776}
777
778void LocationsBuilderARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
779 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
780 locations->SetInAt(0, Location::RequiresRegister());
781 locations->SetOut(Location::RequiresRegister());
782}
783
784void InstructionCodeGeneratorARM64::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
785 Primitive::Type res_type = instruction->GetType();
786 Register res = OutputRegister(instruction);
787 Register obj = InputRegisterAt(instruction, 0);
788 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
789
790 switch (res_type) {
791 case Primitive::kPrimBoolean: {
792 __ Ldrb(res, MemOperand(obj, offset));
793 break;
794 }
795 case Primitive::kPrimByte: {
796 __ Ldrsb(res, MemOperand(obj, offset));
797 break;
798 }
799 case Primitive::kPrimShort: {
800 __ Ldrsh(res, MemOperand(obj, offset));
801 break;
802 }
803 case Primitive::kPrimChar: {
804 __ Ldrh(res, MemOperand(obj, offset));
805 break;
806 }
807 case Primitive::kPrimInt:
808 case Primitive::kPrimNot:
809 case Primitive::kPrimLong: { // TODO: support volatile.
810 DCHECK(res.IsX() == (res_type == Primitive::kPrimLong));
811 __ Ldr(res, MemOperand(obj, offset));
812 break;
813 }
814
815 case Primitive::kPrimFloat:
816 case Primitive::kPrimDouble:
817 LOG(FATAL) << "Unimplemented register res_type " << res_type;
818 break;
819
820 case Primitive::kPrimVoid:
821 LOG(FATAL) << "Unreachable res_type " << res_type;
822 }
823}
824
825void LocationsBuilderARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
826 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
827 locations->SetInAt(0, Location::RequiresRegister());
828 locations->SetInAt(1, Location::RequiresRegister());
829}
830
831void InstructionCodeGeneratorARM64::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
832 Register obj = InputRegisterAt(instruction, 0);
833 Register value = InputRegisterAt(instruction, 1);
834 Primitive::Type field_type = instruction->InputAt(1)->GetType();
835 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
836
837 switch (field_type) {
838 case Primitive::kPrimBoolean:
839 case Primitive::kPrimByte: {
840 __ Strb(value, MemOperand(obj, offset));
841 break;
842 }
843
844 case Primitive::kPrimShort:
845 case Primitive::kPrimChar: {
846 __ Strh(value, MemOperand(obj, offset));
847 break;
848 }
849
850 case Primitive::kPrimInt:
851 case Primitive::kPrimNot:
852 case Primitive::kPrimLong: {
853 DCHECK(value.IsX() == (field_type == Primitive::kPrimLong));
854 __ Str(value, MemOperand(obj, offset));
855
856 if (field_type == Primitive::kPrimNot) {
857 codegen_->MarkGCCard(obj, value);
858 }
859 break;
860 }
861
862 case Primitive::kPrimFloat:
863 case Primitive::kPrimDouble:
864 LOG(FATAL) << "Unimplemented register type " << field_type;
865 break;
866
867 case Primitive::kPrimVoid:
868 LOG(FATAL) << "Unreachable type " << field_type;
869 }
870}
871
872void LocationsBuilderARM64::VisitIntConstant(HIntConstant* constant) {
873 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
874 locations->SetOut(Location::ConstantLocation(constant));
875}
876
877void InstructionCodeGeneratorARM64::VisitIntConstant(HIntConstant* constant) {
878 // Will be generated at use site.
879}
880
881void LocationsBuilderARM64::VisitInvokeStatic(HInvokeStatic* invoke) {
882 HandleInvoke(invoke);
883}
884
885void LocationsBuilderARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
886 HandleInvoke(invoke);
887}
888
889void LocationsBuilderARM64::HandleInvoke(HInvoke* invoke) {
890 LocationSummary* locations =
891 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
892 locations->AddTemp(LocationFrom(x0));
893
894 InvokeDexCallingConventionVisitor calling_convention_visitor;
895 for (size_t i = 0; i < invoke->InputCount(); i++) {
896 HInstruction* input = invoke->InputAt(i);
897 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
898 }
899
900 Primitive::Type return_type = invoke->GetType();
901 if (return_type != Primitive::kPrimVoid) {
902 locations->SetOut(calling_convention_visitor.GetReturnLocation(return_type));
903 }
904}
905
906void InstructionCodeGeneratorARM64::VisitInvokeStatic(HInvokeStatic* invoke) {
907 Register temp = WRegisterFrom(invoke->GetLocations()->GetTemp(0));
908 // Make sure that ArtMethod* is passed in W0 as per the calling convention
909 DCHECK(temp.Is(w0));
910 size_t index_in_cache = mirror::Array::DataOffset(kHeapRefSize).SizeValue() +
911 invoke->GetIndexInDexCache() * kHeapRefSize;
912
913 // TODO: Implement all kinds of calls:
914 // 1) boot -> boot
915 // 2) app -> boot
916 // 3) app -> app
917 //
918 // Currently we implement the app -> app logic, which looks up in the resolve cache.
919
920 // temp = method;
921 __ Ldr(temp, MemOperand(sp, kCurrentMethodStackOffset));
922 // temp = temp->dex_cache_resolved_methods_;
923 __ Ldr(temp, MemOperand(temp.X(), mirror::ArtMethod::DexCacheResolvedMethodsOffset().SizeValue()));
924 // temp = temp[index_in_cache];
925 __ Ldr(temp, MemOperand(temp.X(), index_in_cache));
926 // lr = temp->entry_point_from_quick_compiled_code_;
927 __ Ldr(lr, MemOperand(temp.X(), mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().SizeValue()));
928 // lr();
929 __ Blr(lr);
930
931 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
932 DCHECK(!codegen_->IsLeafMethod());
933}
934
935void InstructionCodeGeneratorARM64::VisitInvokeVirtual(HInvokeVirtual* invoke) {
936 LocationSummary* locations = invoke->GetLocations();
937 Location receiver = locations->InAt(0);
938 Register temp = XRegisterFrom(invoke->GetLocations()->GetTemp(0));
939 size_t method_offset = mirror::Class::EmbeddedVTableOffset().SizeValue() +
940 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
941 Offset class_offset = mirror::Object::ClassOffset();
942 Offset entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset();
943
944 // temp = object->GetClass();
945 if (receiver.IsStackSlot()) {
946 __ Ldr(temp.W(), MemOperand(sp, receiver.GetStackIndex()));
947 __ Ldr(temp.W(), MemOperand(temp, class_offset.SizeValue()));
948 } else {
949 DCHECK(receiver.IsRegister());
950 __ Ldr(temp.W(), HeapOperandFrom(receiver, Primitive::kPrimNot,
951 class_offset));
952 }
953 // temp = temp->GetMethodAt(method_offset);
954 __ Ldr(temp.W(), MemOperand(temp, method_offset));
955 // lr = temp->GetEntryPoint();
956 __ Ldr(lr, MemOperand(temp, entry_point.SizeValue()));
957 // lr();
958 __ Blr(lr);
959 DCHECK(!codegen_->IsLeafMethod());
960 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
961}
962
963void LocationsBuilderARM64::VisitLoadLocal(HLoadLocal* load) {
964 load->SetLocations(nullptr);
965}
966
967void InstructionCodeGeneratorARM64::VisitLoadLocal(HLoadLocal* load) {
968 // Nothing to do, this is driven by the code generator.
969}
970
971void LocationsBuilderARM64::VisitLocal(HLocal* local) {
972 local->SetLocations(nullptr);
973}
974
975void InstructionCodeGeneratorARM64::VisitLocal(HLocal* local) {
976 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
977}
978
979void LocationsBuilderARM64::VisitLongConstant(HLongConstant* constant) {
980 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
981 locations->SetOut(Location::ConstantLocation(constant));
982}
983
984void InstructionCodeGeneratorARM64::VisitLongConstant(HLongConstant* constant) {
985 // Will be generated at use site.
986}
987
Alexandre Rames42d641b2014-10-27 14:00:51 +0000988void LocationsBuilderARM64::VisitMul(HMul* mul) {
989 LocationSummary* locations =
990 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
991 switch (mul->GetResultType()) {
992 case Primitive::kPrimInt:
993 case Primitive::kPrimLong:
994 locations->SetInAt(0, Location::RequiresRegister());
995 locations->SetInAt(1, Location::RequiresRegister());
996 locations->SetOut(Location::RequiresRegister());
997 break;
998
999 case Primitive::kPrimFloat:
1000 case Primitive::kPrimDouble:
1001 LOG(FATAL) << "Unimplemented mul type " << mul->GetResultType();
1002 break;
1003
1004 default:
1005 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
1006 }
1007}
1008
1009void InstructionCodeGeneratorARM64::VisitMul(HMul* mul) {
1010 switch (mul->GetResultType()) {
1011 case Primitive::kPrimInt:
1012 case Primitive::kPrimLong:
1013 __ Mul(OutputRegister(mul), InputRegisterAt(mul, 0), InputRegisterAt(mul, 1));
1014 break;
1015
1016 case Primitive::kPrimFloat:
1017 case Primitive::kPrimDouble:
1018 LOG(FATAL) << "Unimplemented mul type " << mul->GetResultType();
1019 break;
1020
1021 default:
1022 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
1023 }
1024}
1025
Alexandre Rames5319def2014-10-23 10:03:10 +01001026void LocationsBuilderARM64::VisitNewInstance(HNewInstance* instruction) {
1027 LocationSummary* locations =
1028 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1029 InvokeRuntimeCallingConvention calling_convention;
1030 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
1031 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1)));
1032 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
1033}
1034
1035void InstructionCodeGeneratorARM64::VisitNewInstance(HNewInstance* instruction) {
1036 LocationSummary* locations = instruction->GetLocations();
1037 Register type_index = RegisterFrom(locations->GetTemp(0), Primitive::kPrimInt);
1038 DCHECK(type_index.Is(w0));
1039 Register current_method = RegisterFrom(locations->GetTemp(1), Primitive::kPrimNot);
1040 DCHECK(current_method.Is(w1));
1041 __ Ldr(current_method, MemOperand(sp, kCurrentMethodStackOffset));
1042 __ Mov(type_index, instruction->GetTypeIndex());
1043 __ Ldr(lr, MemOperand(tr, QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pAllocObjectWithAccessCheck).Int32Value()));
1044 __ Blr(lr);
1045 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
1046 DCHECK(!codegen_->IsLeafMethod());
1047}
1048
1049void LocationsBuilderARM64::VisitNot(HNot* instruction) {
1050 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1051 locations->SetInAt(0, Location::RequiresRegister());
1052 locations->SetOut(Location::RequiresRegister());
1053}
1054
1055void InstructionCodeGeneratorARM64::VisitNot(HNot* instruction) {
1056 switch (instruction->InputAt(0)->GetType()) {
1057 case Primitive::kPrimBoolean:
1058 __ Eor(OutputRegister(instruction), InputRegisterAt(instruction, 0), Operand(1));
1059 break;
1060
1061 case Primitive::kPrimInt:
1062 __ Mvn(OutputRegister(instruction), InputOperandAt(instruction, 0));
1063 break;
1064
1065 case Primitive::kPrimLong:
1066 LOG(FATAL) << "Not yet implemented type for not operation " << instruction->GetResultType();
1067 break;
1068
1069 default:
1070 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
1071 }
1072}
1073
1074void LocationsBuilderARM64::VisitNullCheck(HNullCheck* instruction) {
1075 LocationSummary* locations =
1076 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1077 locations->SetInAt(0, Location::RequiresRegister());
1078 if (instruction->HasUses()) {
1079 locations->SetOut(Location::SameAsFirstInput());
1080 }
1081}
1082
1083void InstructionCodeGeneratorARM64::VisitNullCheck(HNullCheck* instruction) {
1084 SlowPathCodeARM64* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM64(instruction);
1085 codegen_->AddSlowPath(slow_path);
1086
1087 LocationSummary* locations = instruction->GetLocations();
1088 Location obj = locations->InAt(0);
1089 if (obj.IsRegister()) {
1090 __ Cbz(RegisterFrom(obj, instruction->InputAt(0)->GetType()), slow_path->GetEntryLabel());
1091 } else {
1092 DCHECK(obj.IsConstant()) << obj;
1093 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1094 __ B(slow_path->GetEntryLabel());
1095 }
1096}
1097
1098void LocationsBuilderARM64::VisitParameterValue(HParameterValue* instruction) {
1099 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1100 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1101 if (location.IsStackSlot()) {
1102 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1103 } else if (location.IsDoubleStackSlot()) {
1104 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1105 }
1106 locations->SetOut(location);
1107}
1108
1109void InstructionCodeGeneratorARM64::VisitParameterValue(HParameterValue* instruction) {
1110 // Nothing to do, the parameter is already at its location.
1111}
1112
1113void LocationsBuilderARM64::VisitPhi(HPhi* instruction) {
1114 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1115 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1116 locations->SetInAt(i, Location::Any());
1117 }
1118 locations->SetOut(Location::Any());
1119}
1120
1121void InstructionCodeGeneratorARM64::VisitPhi(HPhi* instruction) {
1122 LOG(FATAL) << "Unreachable";
1123}
1124
1125void LocationsBuilderARM64::VisitReturn(HReturn* instruction) {
1126 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1127 Primitive::Type return_type = instruction->InputAt(0)->GetType();
1128
1129 if (return_type == Primitive::kPrimFloat || return_type == Primitive::kPrimDouble) {
1130 LOG(FATAL) << "Unimplemented return type " << return_type;
1131 }
1132
1133 locations->SetInAt(0, LocationFrom(x0));
1134}
1135
1136void InstructionCodeGeneratorARM64::VisitReturn(HReturn* instruction) {
1137 if (kIsDebugBuild) {
1138 Primitive::Type type = instruction->InputAt(0)->GetType();
1139 switch (type) {
1140 case Primitive::kPrimBoolean:
1141 case Primitive::kPrimByte:
1142 case Primitive::kPrimChar:
1143 case Primitive::kPrimShort:
1144 case Primitive::kPrimInt:
1145 case Primitive::kPrimNot:
1146 DCHECK(InputRegisterAt(instruction, 0).Is(w0));
1147 break;
1148
1149 case Primitive::kPrimLong:
1150 DCHECK(InputRegisterAt(instruction, 0).Is(x0));
1151 break;
1152
1153 default:
1154 LOG(FATAL) << "Unimplemented return type " << type;
1155 }
1156 }
1157 codegen_->GenerateFrameExit();
1158 __ Br(lr);
1159}
1160
1161void LocationsBuilderARM64::VisitReturnVoid(HReturnVoid* instruction) {
1162 instruction->SetLocations(nullptr);
1163}
1164
1165void InstructionCodeGeneratorARM64::VisitReturnVoid(HReturnVoid* instruction) {
1166 codegen_->GenerateFrameExit();
1167 __ Br(lr);
1168}
1169
1170void LocationsBuilderARM64::VisitStoreLocal(HStoreLocal* store) {
1171 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(store);
1172 Primitive::Type field_type = store->InputAt(1)->GetType();
1173 switch (field_type) {
1174 case Primitive::kPrimBoolean:
1175 case Primitive::kPrimByte:
1176 case Primitive::kPrimChar:
1177 case Primitive::kPrimShort:
1178 case Primitive::kPrimInt:
1179 case Primitive::kPrimNot:
1180 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1181 break;
1182
1183 case Primitive::kPrimLong:
1184 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1185 break;
1186
1187 default:
1188 LOG(FATAL) << "Unimplemented local type " << field_type;
1189 }
1190}
1191
1192void InstructionCodeGeneratorARM64::VisitStoreLocal(HStoreLocal* store) {
1193}
1194
1195void LocationsBuilderARM64::VisitSub(HSub* instruction) {
1196 HandleAddSub(instruction);
1197}
1198
1199void InstructionCodeGeneratorARM64::VisitSub(HSub* instruction) {
1200 HandleAddSub(instruction);
1201}
1202
1203void LocationsBuilderARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
1204 LocationSummary* locations =
1205 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1206 locations->SetInAt(0, Location::RequiresRegister());
1207 locations->SetInAt(1, Location::RequiresRegister());
1208 if (instruction->HasUses()) {
1209 locations->SetOut(Location::SameAsFirstInput());
1210 }
1211}
1212
1213void InstructionCodeGeneratorARM64::VisitBoundsCheck(HBoundsCheck* instruction) {
1214 LocationSummary* locations = instruction->GetLocations();
1215 BoundsCheckSlowPathARM64* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM64(
1216 instruction, locations->InAt(0), locations->InAt(1));
1217 codegen_->AddSlowPath(slow_path);
1218
1219 __ Cmp(InputRegisterAt(instruction, 0), InputOperandAt(instruction, 1));
1220 __ B(slow_path->GetEntryLabel(), hs);
1221}
1222
1223void LocationsBuilderARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
1224 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
1225}
1226
1227void InstructionCodeGeneratorARM64::VisitSuspendCheck(HSuspendCheck* instruction) {
1228 // TODO: Improve support for suspend checks.
1229 SuspendCheckSlowPathARM64* slow_path =
1230 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM64(instruction, nullptr);
1231 codegen_->AddSlowPath(slow_path);
1232
1233 __ Subs(wSuspend, wSuspend, 1);
1234 __ B(slow_path->GetEntryLabel(), le);
1235 __ Bind(slow_path->GetReturnLabel());
1236}
1237
1238void LocationsBuilderARM64::VisitTemporary(HTemporary* temp) {
1239 temp->SetLocations(nullptr);
1240}
1241
1242void InstructionCodeGeneratorARM64::VisitTemporary(HTemporary* temp) {
1243 // Nothing to do, this is driven by the code generator.
1244}
1245
1246} // namespace arm64
1247} // namespace art