blob: 3218002cf80b5ef065bf46805d44a1be96c73a84 [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#ifndef ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM64_H_
18#define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM64_H_
19
20#include "code_generator.h"
Calin Juravle23a8e352015-09-08 19:56:31 +010021#include "common_arm64.h"
Serban Constantinescu02d81cc2015-01-05 16:08:49 +000022#include "dex/compiler_enums.h"
Calin Juravlecd6dffe2015-01-08 17:35:35 +000023#include "driver/compiler_options.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010024#include "nodes.h"
25#include "parallel_move_resolver.h"
26#include "utils/arm64/assembler_arm64.h"
Serban Constantinescu82e52ce2015-03-26 16:50:57 +000027#include "vixl/a64/disasm-a64.h"
28#include "vixl/a64/macro-assembler-a64.h"
Alexandre Rames5319def2014-10-23 10:03:10 +010029#include "arch/arm64/quick_method_frame_info_arm64.h"
30
31namespace art {
32namespace arm64 {
33
34class CodeGeneratorARM64;
Andreas Gampe878d58c2015-01-15 23:24:00 -080035
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +000036// Use a local definition to prevent copying mistakes.
37static constexpr size_t kArm64WordSize = kArm64PointerSize;
38
Alexandre Rames5319def2014-10-23 10:03:10 +010039static const vixl::Register kParameterCoreRegisters[] = {
40 vixl::x1, vixl::x2, vixl::x3, vixl::x4, vixl::x5, vixl::x6, vixl::x7
41};
42static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters);
43static const vixl::FPRegister kParameterFPRegisters[] = {
44 vixl::d0, vixl::d1, vixl::d2, vixl::d3, vixl::d4, vixl::d5, vixl::d6, vixl::d7
45};
46static constexpr size_t kParameterFPRegistersLength = arraysize(kParameterFPRegisters);
47
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010048const vixl::Register tr = vixl::x19; // Thread Register
Mathieu Chartiere401d142015-04-22 13:56:20 -070049static const vixl::Register kArtMethodRegister = vixl::x0; // Method register on invoke.
Alexandre Rames5319def2014-10-23 10:03:10 +010050
51const vixl::CPURegList vixl_reserved_core_registers(vixl::ip0, vixl::ip1);
Alexandre Ramesa89086e2014-11-07 17:13:25 +000052const vixl::CPURegList vixl_reserved_fp_registers(vixl::d31);
Alexandre Rames5319def2014-10-23 10:03:10 +010053
Zheng Xu69a50302015-04-14 20:04:41 +080054const vixl::CPURegList runtime_reserved_core_registers(tr, vixl::lr);
Serban Constantinescu3d087de2015-01-28 11:57:05 +000055
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010056// Callee-saved registers AAPCS64 (without x19 - Thread Register)
Serban Constantinescu3d087de2015-01-28 11:57:05 +000057const vixl::CPURegList callee_saved_core_registers(vixl::CPURegister::kRegister,
58 vixl::kXRegSize,
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010059 vixl::x20.code(),
Serban Constantinescu3d087de2015-01-28 11:57:05 +000060 vixl::x30.code());
61const vixl::CPURegList callee_saved_fp_registers(vixl::CPURegister::kFPRegister,
62 vixl::kDRegSize,
63 vixl::d8.code(),
64 vixl::d15.code());
Alexandre Ramesa89086e2014-11-07 17:13:25 +000065Location ARM64ReturnLocation(Primitive::Type return_type);
66
Andreas Gampe878d58c2015-01-15 23:24:00 -080067class SlowPathCodeARM64 : public SlowPathCode {
68 public:
69 SlowPathCodeARM64() : entry_label_(), exit_label_() {}
70
71 vixl::Label* GetEntryLabel() { return &entry_label_; }
72 vixl::Label* GetExitLabel() { return &exit_label_; }
73
Zheng Xuda403092015-04-24 17:35:39 +080074 void SaveLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) OVERRIDE;
75 void RestoreLiveRegisters(CodeGenerator* codegen, LocationSummary* locations) OVERRIDE;
76
Andreas Gampe878d58c2015-01-15 23:24:00 -080077 private:
78 vixl::Label entry_label_;
79 vixl::Label exit_label_;
80
81 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM64);
82};
83
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +000084static const vixl::Register kRuntimeParameterCoreRegisters[] =
85 { vixl::x0, vixl::x1, vixl::x2, vixl::x3, vixl::x4, vixl::x5, vixl::x6, vixl::x7 };
86static constexpr size_t kRuntimeParameterCoreRegistersLength =
87 arraysize(kRuntimeParameterCoreRegisters);
88static const vixl::FPRegister kRuntimeParameterFpuRegisters[] =
89 { vixl::d0, vixl::d1, vixl::d2, vixl::d3, vixl::d4, vixl::d5, vixl::d6, vixl::d7 };
90static constexpr size_t kRuntimeParameterFpuRegistersLength =
91 arraysize(kRuntimeParameterCoreRegisters);
92
93class InvokeRuntimeCallingConvention : public CallingConvention<vixl::Register, vixl::FPRegister> {
94 public:
95 static constexpr size_t kParameterCoreRegistersLength = arraysize(kParameterCoreRegisters);
96
97 InvokeRuntimeCallingConvention()
98 : CallingConvention(kRuntimeParameterCoreRegisters,
99 kRuntimeParameterCoreRegistersLength,
100 kRuntimeParameterFpuRegisters,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700101 kRuntimeParameterFpuRegistersLength,
102 kArm64PointerSize) {}
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +0000103
104 Location GetReturnLocation(Primitive::Type return_type);
105
106 private:
107 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
108};
109
Alexandre Rames5319def2014-10-23 10:03:10 +0100110class InvokeDexCallingConvention : public CallingConvention<vixl::Register, vixl::FPRegister> {
111 public:
112 InvokeDexCallingConvention()
113 : CallingConvention(kParameterCoreRegisters,
114 kParameterCoreRegistersLength,
115 kParameterFPRegisters,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700116 kParameterFPRegistersLength,
117 kArm64PointerSize) {}
Alexandre Rames5319def2014-10-23 10:03:10 +0100118
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100119 Location GetReturnLocation(Primitive::Type return_type) const {
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000120 return ARM64ReturnLocation(return_type);
Alexandre Rames5319def2014-10-23 10:03:10 +0100121 }
122
123
124 private:
125 DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConvention);
126};
127
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100128class InvokeDexCallingConventionVisitorARM64 : public InvokeDexCallingConventionVisitor {
Alexandre Rames5319def2014-10-23 10:03:10 +0100129 public:
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100130 InvokeDexCallingConventionVisitorARM64() {}
131 virtual ~InvokeDexCallingConventionVisitorARM64() {}
Alexandre Rames5319def2014-10-23 10:03:10 +0100132
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100133 Location GetNextLocation(Primitive::Type type) OVERRIDE;
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100134 Location GetReturnLocation(Primitive::Type return_type) const OVERRIDE {
Alexandre Rames5319def2014-10-23 10:03:10 +0100135 return calling_convention.GetReturnLocation(return_type);
136 }
Nicolas Geoffrayfd88f162015-06-03 11:23:52 +0100137 Location GetMethodLocation() const OVERRIDE;
Alexandre Rames5319def2014-10-23 10:03:10 +0100138
139 private:
140 InvokeDexCallingConvention calling_convention;
Alexandre Rames5319def2014-10-23 10:03:10 +0100141
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100142 DISALLOW_COPY_AND_ASSIGN(InvokeDexCallingConventionVisitorARM64);
Alexandre Rames5319def2014-10-23 10:03:10 +0100143};
144
Calin Juravle23a8e352015-09-08 19:56:31 +0100145class FieldAccessCallingConvetionARM64 : public FieldAccessCallingConvetion {
146 public:
147 FieldAccessCallingConvetionARM64() {}
148
149 Location GetObjectLocation() const OVERRIDE {
150 return helpers::LocationFrom(vixl::x1);
151 }
152 Location GetFieldIndexLocation() const OVERRIDE {
153 return helpers::LocationFrom(vixl::x0);
154 }
155 Location GetReturnLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE {
156 return helpers::LocationFrom(vixl::x0);
157 }
158 Location GetSetValueLocation(
159 Primitive::Type type ATTRIBUTE_UNUSED, bool is_instance) const OVERRIDE {
160 return is_instance ? helpers::LocationFrom(vixl::x2) : helpers::LocationFrom(vixl::x1);
161 }
162 Location GetFpuLocation(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE {
163 return helpers::LocationFrom(vixl::d0);
164 }
165
166 private:
167 DISALLOW_COPY_AND_ASSIGN(FieldAccessCallingConvetionARM64);
168};
169
Alexandre Rames5319def2014-10-23 10:03:10 +0100170class InstructionCodeGeneratorARM64 : public HGraphVisitor {
171 public:
172 InstructionCodeGeneratorARM64(HGraph* graph, CodeGeneratorARM64* codegen);
173
174#define DECLARE_VISIT_INSTRUCTION(name, super) \
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000175 void Visit##name(H##name* instr) OVERRIDE;
Alexandre Ramesef20f712015-06-09 10:29:30 +0100176
177 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
178 FOR_EACH_CONCRETE_INSTRUCTION_ARM64(DECLARE_VISIT_INSTRUCTION)
179
Alexandre Rames5319def2014-10-23 10:03:10 +0100180#undef DECLARE_VISIT_INSTRUCTION
181
Alexandre Ramesef20f712015-06-09 10:29:30 +0100182 void VisitInstruction(HInstruction* instruction) OVERRIDE {
183 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
184 << " (id " << instruction->GetId() << ")";
185 }
186
Alexandre Rames5319def2014-10-23 10:03:10 +0100187 Arm64Assembler* GetAssembler() const { return assembler_; }
Alexandre Rames67555f72014-11-18 10:55:16 +0000188 vixl::MacroAssembler* GetVIXLAssembler() { return GetAssembler()->vixl_masm_; }
Alexandre Rames5319def2014-10-23 10:03:10 +0100189
190 private:
Alexandre Rames67555f72014-11-18 10:55:16 +0000191 void GenerateClassInitializationCheck(SlowPathCodeARM64* slow_path, vixl::Register class_reg);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000192 void GenerateMemoryBarrier(MemBarrierKind kind);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000193 void GenerateSuspendCheck(HSuspendCheck* instruction, HBasicBlock* successor);
Alexandre Rames67555f72014-11-18 10:55:16 +0000194 void HandleBinaryOp(HBinaryOperation* instr);
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100195 void HandleFieldSet(HInstruction* instruction,
196 const FieldInfo& field_info,
197 bool value_can_be_null);
Alexandre Rames09a99962015-04-15 11:47:56 +0100198 void HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info);
Serban Constantinescu02164b32014-11-13 14:05:07 +0000199 void HandleShift(HBinaryOperation* instr);
Calin Juravlecd6dffe2015-01-08 17:35:35 +0000200 void GenerateImplicitNullCheck(HNullCheck* instruction);
201 void GenerateExplicitNullCheck(HNullCheck* instruction);
Mingyao Yangd43b3ac2015-04-01 14:03:04 -0700202 void GenerateTestAndBranch(HInstruction* instruction,
203 vixl::Label* true_target,
204 vixl::Label* false_target,
205 vixl::Label* always_true_target);
Zheng Xuc6667102015-05-15 16:08:45 +0800206 void DivRemOneOrMinusOne(HBinaryOperation* instruction);
207 void DivRemByPowerOfTwo(HBinaryOperation* instruction);
208 void GenerateDivRemWithAnyConstant(HBinaryOperation* instruction);
209 void GenerateDivRemIntegral(HBinaryOperation* instruction);
David Brazdilfc6a86a2015-06-26 10:33:45 +0000210 void HandleGoto(HInstruction* got, HBasicBlock* successor);
Alexandre Rames5319def2014-10-23 10:03:10 +0100211
212 Arm64Assembler* const assembler_;
213 CodeGeneratorARM64* const codegen_;
214
215 DISALLOW_COPY_AND_ASSIGN(InstructionCodeGeneratorARM64);
216};
217
218class LocationsBuilderARM64 : public HGraphVisitor {
219 public:
Roland Levillain3887c462015-08-12 18:15:42 +0100220 LocationsBuilderARM64(HGraph* graph, CodeGeneratorARM64* codegen)
Alexandre Rames5319def2014-10-23 10:03:10 +0100221 : HGraphVisitor(graph), codegen_(codegen) {}
222
223#define DECLARE_VISIT_INSTRUCTION(name, super) \
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000224 void Visit##name(H##name* instr) OVERRIDE;
Alexandre Ramesef20f712015-06-09 10:29:30 +0100225
226 FOR_EACH_CONCRETE_INSTRUCTION_COMMON(DECLARE_VISIT_INSTRUCTION)
227 FOR_EACH_CONCRETE_INSTRUCTION_ARM64(DECLARE_VISIT_INSTRUCTION)
228
Alexandre Rames5319def2014-10-23 10:03:10 +0100229#undef DECLARE_VISIT_INSTRUCTION
230
Alexandre Ramesef20f712015-06-09 10:29:30 +0100231 void VisitInstruction(HInstruction* instruction) OVERRIDE {
232 LOG(FATAL) << "Unreachable instruction " << instruction->DebugName()
233 << " (id " << instruction->GetId() << ")";
234 }
235
Alexandre Rames5319def2014-10-23 10:03:10 +0100236 private:
Alexandre Rames67555f72014-11-18 10:55:16 +0000237 void HandleBinaryOp(HBinaryOperation* instr);
Alexandre Rames09a99962015-04-15 11:47:56 +0100238 void HandleFieldSet(HInstruction* instruction);
239 void HandleFieldGet(HInstruction* instruction);
Alexandre Rames5319def2014-10-23 10:03:10 +0100240 void HandleInvoke(HInvoke* instr);
Alexandre Rames09a99962015-04-15 11:47:56 +0100241 void HandleShift(HBinaryOperation* instr);
Alexandre Rames5319def2014-10-23 10:03:10 +0100242
243 CodeGeneratorARM64* const codegen_;
Roland Levillain2d27c8e2015-04-28 15:48:45 +0100244 InvokeDexCallingConventionVisitorARM64 parameter_visitor_;
Alexandre Rames5319def2014-10-23 10:03:10 +0100245
246 DISALLOW_COPY_AND_ASSIGN(LocationsBuilderARM64);
247};
248
Zheng Xuad4450e2015-04-17 18:48:56 +0800249class ParallelMoveResolverARM64 : public ParallelMoveResolverNoSwap {
Alexandre Rames3e69f162014-12-10 10:36:50 +0000250 public:
251 ParallelMoveResolverARM64(ArenaAllocator* allocator, CodeGeneratorARM64* codegen)
Zheng Xuad4450e2015-04-17 18:48:56 +0800252 : ParallelMoveResolverNoSwap(allocator), codegen_(codegen), vixl_temps_() {}
Alexandre Rames3e69f162014-12-10 10:36:50 +0000253
Zheng Xuad4450e2015-04-17 18:48:56 +0800254 protected:
255 void PrepareForEmitNativeCode() OVERRIDE;
256 void FinishEmitNativeCode() OVERRIDE;
257 Location AllocateScratchLocationFor(Location::Kind kind) OVERRIDE;
258 void FreeScratchLocation(Location loc) OVERRIDE;
Alexandre Rames3e69f162014-12-10 10:36:50 +0000259 void EmitMove(size_t index) OVERRIDE;
Alexandre Rames3e69f162014-12-10 10:36:50 +0000260
261 private:
262 Arm64Assembler* GetAssembler() const;
263 vixl::MacroAssembler* GetVIXLAssembler() const {
264 return GetAssembler()->vixl_masm_;
265 }
266
267 CodeGeneratorARM64* const codegen_;
Zheng Xuad4450e2015-04-17 18:48:56 +0800268 vixl::UseScratchRegisterScope vixl_temps_;
Alexandre Rames3e69f162014-12-10 10:36:50 +0000269
270 DISALLOW_COPY_AND_ASSIGN(ParallelMoveResolverARM64);
271};
272
Alexandre Rames5319def2014-10-23 10:03:10 +0100273class CodeGeneratorARM64 : public CodeGenerator {
274 public:
Serban Constantinescu579885a2015-02-22 20:51:33 +0000275 CodeGeneratorARM64(HGraph* graph,
276 const Arm64InstructionSetFeatures& isa_features,
Serban Constantinescuecc43662015-08-13 13:33:12 +0100277 const CompilerOptions& compiler_options,
278 OptimizingCompilerStats* stats = nullptr);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000279 virtual ~CodeGeneratorARM64() {}
Alexandre Rames5319def2014-10-23 10:03:10 +0100280
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000281 void GenerateFrameEntry() OVERRIDE;
282 void GenerateFrameExit() OVERRIDE;
Alexandre Rames5319def2014-10-23 10:03:10 +0100283
Zheng Xuda403092015-04-24 17:35:39 +0800284 vixl::CPURegList GetFramePreservedCoreRegisters() const;
285 vixl::CPURegList GetFramePreservedFPRegisters() const;
Alexandre Rames5319def2014-10-23 10:03:10 +0100286
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000287 void Bind(HBasicBlock* block) OVERRIDE;
Alexandre Rames5319def2014-10-23 10:03:10 +0100288
289 vixl::Label* GetLabelOf(HBasicBlock* block) const {
Nicolas Geoffraydc23d832015-02-16 11:15:43 +0000290 return CommonGetLabelOf<vixl::Label>(block_labels_, block);
Alexandre Rames5319def2014-10-23 10:03:10 +0100291 }
292
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000293 void Move(HInstruction* instruction, Location location, HInstruction* move_for) OVERRIDE;
Alexandre Rames5319def2014-10-23 10:03:10 +0100294
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000295 size_t GetWordSize() const OVERRIDE {
Alexandre Rames5319def2014-10-23 10:03:10 +0100296 return kArm64WordSize;
297 }
298
Mark Mendellf85a9ca2015-01-13 09:20:58 -0500299 size_t GetFloatingPointSpillSlotSize() const OVERRIDE {
300 // Allocated in D registers, which are word sized.
301 return kArm64WordSize;
302 }
303
Alexandre Rames67555f72014-11-18 10:55:16 +0000304 uintptr_t GetAddressOf(HBasicBlock* block) const OVERRIDE {
305 vixl::Label* block_entry_label = GetLabelOf(block);
306 DCHECK(block_entry_label->IsBound());
307 return block_entry_label->location();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000308 }
Alexandre Rames5319def2014-10-23 10:03:10 +0100309
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000310 HGraphVisitor* GetLocationBuilder() OVERRIDE { return &location_builder_; }
311 HGraphVisitor* GetInstructionVisitor() OVERRIDE { return &instruction_visitor_; }
312 Arm64Assembler* GetAssembler() OVERRIDE { return &assembler_; }
Alexandre Rameseb7b7392015-06-19 14:47:01 +0100313 const Arm64Assembler& GetAssembler() const OVERRIDE { return assembler_; }
Alexandre Rames67555f72014-11-18 10:55:16 +0000314 vixl::MacroAssembler* GetVIXLAssembler() { return GetAssembler()->vixl_masm_; }
Alexandre Rames5319def2014-10-23 10:03:10 +0100315
316 // Emit a write barrier.
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100317 void MarkGCCard(vixl::Register object, vixl::Register value, bool value_can_be_null);
Alexandre Rames5319def2014-10-23 10:03:10 +0100318
319 // Register allocation.
320
Nicolas Geoffray98893962015-01-21 12:32:32 +0000321 void SetupBlockedRegisters(bool is_baseline) const OVERRIDE;
Alexandre Rames5319def2014-10-23 10:03:10 +0100322 // AllocateFreeRegister() is only used when allocating registers locally
323 // during CompileBaseline().
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000324 Location AllocateFreeRegister(Primitive::Type type) const OVERRIDE;
Alexandre Rames5319def2014-10-23 10:03:10 +0100325
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000326 Location GetStackLocation(HLoadLocal* load) const OVERRIDE;
Alexandre Rames5319def2014-10-23 10:03:10 +0100327
Zheng Xuda403092015-04-24 17:35:39 +0800328 size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
329 size_t RestoreCoreRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
330 size_t SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
331 size_t RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) OVERRIDE;
Alexandre Rames5319def2014-10-23 10:03:10 +0100332
333 // The number of registers that can be allocated. The register allocator may
334 // decide to reserve and not use a few of them.
335 // We do not consider registers sp, xzr, wzr. They are either not allocatable
336 // (xzr, wzr), or make for poor allocatable registers (sp alignment
337 // requirements, etc.). This also facilitates our task as all other registers
338 // can easily be mapped via to or from their type and index or code.
Alexandre Ramesa89086e2014-11-07 17:13:25 +0000339 static const int kNumberOfAllocatableRegisters = vixl::kNumberOfRegisters - 1;
340 static const int kNumberOfAllocatableFPRegisters = vixl::kNumberOfFPRegisters;
Alexandre Rames5319def2014-10-23 10:03:10 +0100341 static constexpr int kNumberOfAllocatableRegisterPairs = 0;
342
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000343 void DumpCoreRegister(std::ostream& stream, int reg) const OVERRIDE;
344 void DumpFloatingPointRegister(std::ostream& stream, int reg) const OVERRIDE;
Alexandre Rames5319def2014-10-23 10:03:10 +0100345
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000346 InstructionSet GetInstructionSet() const OVERRIDE {
Alexandre Rames5319def2014-10-23 10:03:10 +0100347 return InstructionSet::kArm64;
348 }
349
Serban Constantinescu579885a2015-02-22 20:51:33 +0000350 const Arm64InstructionSetFeatures& GetInstructionSetFeatures() const {
351 return isa_features_;
352 }
353
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000354 void Initialize() OVERRIDE {
Alexandre Rames5319def2014-10-23 10:03:10 +0100355 HGraph* graph = GetGraph();
Vladimir Markofa6b93c2015-09-15 10:15:55 +0100356 int length = graph->GetBlocks().size();
Alexandre Rames5319def2014-10-23 10:03:10 +0100357 block_labels_ = graph->GetArena()->AllocArray<vixl::Label>(length);
358 for (int i = 0; i < length; ++i) {
359 new(block_labels_ + i) vixl::Label();
360 }
361 }
362
Serban Constantinescu32f5b4d2014-11-25 20:05:46 +0000363 void Finalize(CodeAllocator* allocator) OVERRIDE;
364
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000365 // Code generation helpers.
Alexandre Rames67555f72014-11-18 10:55:16 +0000366 void MoveConstant(vixl::CPURegister destination, HConstant* constant);
Calin Juravle175dc732015-08-25 15:42:32 +0100367 void MoveConstant(Location destination, int32_t value) OVERRIDE;
Alexandre Rames3e69f162014-12-10 10:36:50 +0000368 // The type is optional. When specified it must be coherent with the
369 // locations, and is used for optimisation and debugging.
370 void MoveLocation(Location destination, Location source,
371 Primitive::Type type = Primitive::kPrimVoid);
Calin Juravle23a8e352015-09-08 19:56:31 +0100372
373 void AddLocationAsTemp(Location location, LocationSummary* locations) OVERRIDE;
374 void MoveLocationToTemp(Location source,
375 const LocationSummary& locations,
376 int temp_index,
377 Primitive::Type type) OVERRIDE;
378 void MoveTempToLocation(const LocationSummary& locations,
379 int temp_index,
380 Location destination,
381 Primitive::Type type) OVERRIDE;
382
Alexandre Rames67555f72014-11-18 10:55:16 +0000383 void Load(Primitive::Type type, vixl::CPURegister dst, const vixl::MemOperand& src);
384 void Store(Primitive::Type type, vixl::CPURegister rt, const vixl::MemOperand& dst);
Calin Juravle77520bc2015-01-12 18:45:46 +0000385 void LoadAcquire(HInstruction* instruction, vixl::CPURegister dst, const vixl::MemOperand& src);
Serban Constantinescu02d81cc2015-01-05 16:08:49 +0000386 void StoreRelease(Primitive::Type type, vixl::CPURegister rt, const vixl::MemOperand& dst);
Alexandre Rames67555f72014-11-18 10:55:16 +0000387
388 // Generate code to invoke a runtime entry point.
Calin Juravle175dc732015-08-25 15:42:32 +0100389 void InvokeRuntime(QuickEntrypointEnum entrypoint,
390 HInstruction* instruction,
391 uint32_t dex_pc,
392 SlowPathCode* slow_path) OVERRIDE;
393
Nicolas Geoffrayeeefa122015-03-13 18:52:59 +0000394 void InvokeRuntime(int32_t offset,
395 HInstruction* instruction,
396 uint32_t dex_pc,
397 SlowPathCode* slow_path);
Alexandre Ramesfc19de82014-11-07 17:13:31 +0000398
Alexandre Rames3e69f162014-12-10 10:36:50 +0000399 ParallelMoveResolverARM64* GetMoveResolver() { return &move_resolver_; }
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000400
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000401 bool NeedsTwoRegisters(Primitive::Type type ATTRIBUTE_UNUSED) const OVERRIDE {
402 return false;
403 }
404
Nicolas Geoffray38207af2015-06-01 15:46:22 +0100405 void GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp);
Andreas Gampebfb5ba92015-09-01 15:45:02 +0000406 void GenerateVirtualCall(HInvokeVirtual* invoke, Location temp);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800407
Vladimir Marko58155012015-08-19 12:49:41 +0000408 void EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) OVERRIDE;
409
Alexandre Rames5319def2014-10-23 10:03:10 +0100410 private:
Vladimir Marko58155012015-08-19 12:49:41 +0000411 using Uint64ToLiteralMap = ArenaSafeMap<uint64_t, vixl::Literal<uint64_t>*>;
412 using MethodToLiteralMap = ArenaSafeMap<MethodReference,
413 vixl::Literal<uint64_t>*,
414 MethodReferenceComparator>;
415
416 vixl::Literal<uint64_t>* DeduplicateUint64Literal(uint64_t value);
417 vixl::Literal<uint64_t>* DeduplicateMethodLiteral(MethodReference target_method,
418 MethodToLiteralMap* map);
419 vixl::Literal<uint64_t>* DeduplicateMethodAddressLiteral(MethodReference target_method);
420 vixl::Literal<uint64_t>* DeduplicateMethodCodeLiteral(MethodReference target_method);
421
422 struct PcRelativeDexCacheAccessInfo {
423 PcRelativeDexCacheAccessInfo(const DexFile& dex_file, uint32_t element_off)
424 : target_dex_file(dex_file), element_offset(element_off), label(), pc_insn_label() { }
425
426 const DexFile& target_dex_file;
427 uint32_t element_offset;
428 // NOTE: Labels are bound to the end of the patched instruction because
429 // we don't know if there will be a veneer or how big it will be.
430 vixl::Label label;
431 vixl::Label* pc_insn_label;
432 };
433
Alexandre Rames5319def2014-10-23 10:03:10 +0100434 // Labels for each block that will be compiled.
435 vixl::Label* block_labels_;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +0000436 vixl::Label frame_entry_label_;
Alexandre Rames5319def2014-10-23 10:03:10 +0100437
438 LocationsBuilderARM64 location_builder_;
439 InstructionCodeGeneratorARM64 instruction_visitor_;
Alexandre Rames3e69f162014-12-10 10:36:50 +0000440 ParallelMoveResolverARM64 move_resolver_;
Alexandre Rames5319def2014-10-23 10:03:10 +0100441 Arm64Assembler assembler_;
Serban Constantinescu579885a2015-02-22 20:51:33 +0000442 const Arm64InstructionSetFeatures& isa_features_;
Alexandre Rames5319def2014-10-23 10:03:10 +0100443
Vladimir Marko58155012015-08-19 12:49:41 +0000444 // Deduplication map for 64-bit literals, used for non-patchable method address and method code.
445 Uint64ToLiteralMap uint64_literals_;
446 // Method patch info, map MethodReference to a literal for method address and method code.
447 MethodToLiteralMap method_patches_;
448 MethodToLiteralMap call_patches_;
449 // Relative call patch info.
450 // Using ArenaDeque<> which retains element addresses on push/emplace_back().
451 ArenaDeque<MethodPatchInfo<vixl::Label>> relative_call_patches_;
452 // PC-relative DexCache access info.
453 ArenaDeque<PcRelativeDexCacheAccessInfo> pc_rel_dex_cache_patches_;
454
Alexandre Rames5319def2014-10-23 10:03:10 +0100455 DISALLOW_COPY_AND_ASSIGN(CodeGeneratorARM64);
456};
457
Alexandre Rames3e69f162014-12-10 10:36:50 +0000458inline Arm64Assembler* ParallelMoveResolverARM64::GetAssembler() const {
459 return codegen_->GetAssembler();
460}
461
Alexandre Rames5319def2014-10-23 10:03:10 +0100462} // namespace arm64
463} // namespace art
464
465#endif // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_ARM64_H_