xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===-- AArch64TargetMachine.cpp - Define TargetMachine for AArch64 -------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric //
100b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include "AArch64TargetMachine.h"
130b57cec5SDimitry Andric #include "AArch64.h"
145ffd83dbSDimitry Andric #include "AArch64MachineFunctionInfo.h"
1581ad6265SDimitry Andric #include "AArch64MachineScheduler.h"
160b57cec5SDimitry Andric #include "AArch64MacroFusion.h"
170b57cec5SDimitry Andric #include "AArch64Subtarget.h"
180b57cec5SDimitry Andric #include "AArch64TargetObjectFile.h"
190b57cec5SDimitry Andric #include "AArch64TargetTransformInfo.h"
200b57cec5SDimitry Andric #include "MCTargetDesc/AArch64MCTargetDesc.h"
210b57cec5SDimitry Andric #include "TargetInfo/AArch64TargetInfo.h"
220b57cec5SDimitry Andric #include "llvm/ADT/STLExtras.h"
230b57cec5SDimitry Andric #include "llvm/Analysis/TargetTransformInfo.h"
245f757f3fSDimitry Andric #include "llvm/Analysis/ValueTracking.h"
2581ad6265SDimitry Andric #include "llvm/CodeGen/CFIFixup.h"
260b57cec5SDimitry Andric #include "llvm/CodeGen/CSEConfigBase.h"
2781ad6265SDimitry Andric #include "llvm/CodeGen/GlobalISel/CSEInfo.h"
280b57cec5SDimitry Andric #include "llvm/CodeGen/GlobalISel/IRTranslator.h"
290b57cec5SDimitry Andric #include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
300b57cec5SDimitry Andric #include "llvm/CodeGen/GlobalISel/Legalizer.h"
31349cc55cSDimitry Andric #include "llvm/CodeGen/GlobalISel/LoadStoreOpt.h"
320b57cec5SDimitry Andric #include "llvm/CodeGen/GlobalISel/Localizer.h"
330b57cec5SDimitry Andric #include "llvm/CodeGen/GlobalISel/RegBankSelect.h"
345ffd83dbSDimitry Andric #include "llvm/CodeGen/MIRParser/MIParser.h"
350b57cec5SDimitry Andric #include "llvm/CodeGen/MachineScheduler.h"
360b57cec5SDimitry Andric #include "llvm/CodeGen/Passes.h"
3781ad6265SDimitry Andric #include "llvm/CodeGen/TargetInstrInfo.h"
380b57cec5SDimitry Andric #include "llvm/CodeGen/TargetPassConfig.h"
390b57cec5SDimitry Andric #include "llvm/IR/Attributes.h"
400b57cec5SDimitry Andric #include "llvm/IR/Function.h"
41480093f4SDimitry Andric #include "llvm/InitializePasses.h"
420b57cec5SDimitry Andric #include "llvm/MC/MCAsmInfo.h"
430b57cec5SDimitry Andric #include "llvm/MC/MCTargetOptions.h"
44349cc55cSDimitry Andric #include "llvm/MC/TargetRegistry.h"
450b57cec5SDimitry Andric #include "llvm/Pass.h"
461db9f3b2SDimitry Andric #include "llvm/Passes/PassBuilder.h"
470b57cec5SDimitry Andric #include "llvm/Support/CodeGen.h"
480b57cec5SDimitry Andric #include "llvm/Support/CommandLine.h"
490b57cec5SDimitry Andric #include "llvm/Target/TargetLoweringObjectFile.h"
500b57cec5SDimitry Andric #include "llvm/Target/TargetOptions.h"
5106c3fb27SDimitry Andric #include "llvm/TargetParser/Triple.h"
52480093f4SDimitry Andric #include "llvm/Transforms/CFGuard.h"
530b57cec5SDimitry Andric #include "llvm/Transforms/Scalar.h"
54*0fca6ea1SDimitry Andric #include "llvm/Transforms/Vectorize/LoopIdiomVectorize.h"
550b57cec5SDimitry Andric #include <memory>
56bdd1243dSDimitry Andric #include <optional>
570b57cec5SDimitry Andric #include <string>
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric using namespace llvm;
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric static cl::opt<bool> EnableCCMP("aarch64-enable-ccmp",
620b57cec5SDimitry Andric                                 cl::desc("Enable the CCMP formation pass"),
630b57cec5SDimitry Andric                                 cl::init(true), cl::Hidden);
640b57cec5SDimitry Andric 
650b57cec5SDimitry Andric static cl::opt<bool>
660b57cec5SDimitry Andric     EnableCondBrTuning("aarch64-enable-cond-br-tune",
670b57cec5SDimitry Andric                        cl::desc("Enable the conditional branch tuning pass"),
680b57cec5SDimitry Andric                        cl::init(true), cl::Hidden);
690b57cec5SDimitry Andric 
7081ad6265SDimitry Andric static cl::opt<bool> EnableAArch64CopyPropagation(
7181ad6265SDimitry Andric     "aarch64-enable-copy-propagation",
7281ad6265SDimitry Andric     cl::desc("Enable the copy propagation with AArch64 copy instr"),
7381ad6265SDimitry Andric     cl::init(true), cl::Hidden);
7481ad6265SDimitry Andric 
750b57cec5SDimitry Andric static cl::opt<bool> EnableMCR("aarch64-enable-mcr",
760b57cec5SDimitry Andric                                cl::desc("Enable the machine combiner pass"),
770b57cec5SDimitry Andric                                cl::init(true), cl::Hidden);
780b57cec5SDimitry Andric 
790b57cec5SDimitry Andric static cl::opt<bool> EnableStPairSuppress("aarch64-enable-stp-suppress",
800b57cec5SDimitry Andric                                           cl::desc("Suppress STP for AArch64"),
810b57cec5SDimitry Andric                                           cl::init(true), cl::Hidden);
820b57cec5SDimitry Andric 
830b57cec5SDimitry Andric static cl::opt<bool> EnableAdvSIMDScalar(
840b57cec5SDimitry Andric     "aarch64-enable-simd-scalar",
850b57cec5SDimitry Andric     cl::desc("Enable use of AdvSIMD scalar integer instructions"),
860b57cec5SDimitry Andric     cl::init(false), cl::Hidden);
870b57cec5SDimitry Andric 
880b57cec5SDimitry Andric static cl::opt<bool>
890b57cec5SDimitry Andric     EnablePromoteConstant("aarch64-enable-promote-const",
900b57cec5SDimitry Andric                           cl::desc("Enable the promote constant pass"),
910b57cec5SDimitry Andric                           cl::init(true), cl::Hidden);
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric static cl::opt<bool> EnableCollectLOH(
940b57cec5SDimitry Andric     "aarch64-enable-collect-loh",
950b57cec5SDimitry Andric     cl::desc("Enable the pass that emits the linker optimization hints (LOH)"),
960b57cec5SDimitry Andric     cl::init(true), cl::Hidden);
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric static cl::opt<bool>
990b57cec5SDimitry Andric     EnableDeadRegisterElimination("aarch64-enable-dead-defs", cl::Hidden,
1000b57cec5SDimitry Andric                                   cl::desc("Enable the pass that removes dead"
1010b57cec5SDimitry Andric                                            " definitons and replaces stores to"
1020b57cec5SDimitry Andric                                            " them with stores to the zero"
1030b57cec5SDimitry Andric                                            " register"),
1040b57cec5SDimitry Andric                                   cl::init(true));
1050b57cec5SDimitry Andric 
1060b57cec5SDimitry Andric static cl::opt<bool> EnableRedundantCopyElimination(
1070b57cec5SDimitry Andric     "aarch64-enable-copyelim",
1080b57cec5SDimitry Andric     cl::desc("Enable the redundant copy elimination pass"), cl::init(true),
1090b57cec5SDimitry Andric     cl::Hidden);
1100b57cec5SDimitry Andric 
1110b57cec5SDimitry Andric static cl::opt<bool> EnableLoadStoreOpt("aarch64-enable-ldst-opt",
1120b57cec5SDimitry Andric                                         cl::desc("Enable the load/store pair"
1130b57cec5SDimitry Andric                                                  " optimization pass"),
1140b57cec5SDimitry Andric                                         cl::init(true), cl::Hidden);
1150b57cec5SDimitry Andric 
1160b57cec5SDimitry Andric static cl::opt<bool> EnableAtomicTidy(
1170b57cec5SDimitry Andric     "aarch64-enable-atomic-cfg-tidy", cl::Hidden,
1180b57cec5SDimitry Andric     cl::desc("Run SimplifyCFG after expanding atomic operations"
1190b57cec5SDimitry Andric              " to make use of cmpxchg flow-based information"),
1200b57cec5SDimitry Andric     cl::init(true));
1210b57cec5SDimitry Andric 
1220b57cec5SDimitry Andric static cl::opt<bool>
1230b57cec5SDimitry Andric EnableEarlyIfConversion("aarch64-enable-early-ifcvt", cl::Hidden,
1240b57cec5SDimitry Andric                         cl::desc("Run early if-conversion"),
1250b57cec5SDimitry Andric                         cl::init(true));
1260b57cec5SDimitry Andric 
1270b57cec5SDimitry Andric static cl::opt<bool>
1280b57cec5SDimitry Andric     EnableCondOpt("aarch64-enable-condopt",
1290b57cec5SDimitry Andric                   cl::desc("Enable the condition optimizer pass"),
1300b57cec5SDimitry Andric                   cl::init(true), cl::Hidden);
1310b57cec5SDimitry Andric 
1320b57cec5SDimitry Andric static cl::opt<bool>
1330b57cec5SDimitry Andric     EnableGEPOpt("aarch64-enable-gep-opt", cl::Hidden,
1340b57cec5SDimitry Andric                  cl::desc("Enable optimizations on complex GEPs"),
135bdd1243dSDimitry Andric                  cl::init(false));
136bdd1243dSDimitry Andric 
137bdd1243dSDimitry Andric static cl::opt<bool>
138bdd1243dSDimitry Andric     EnableSelectOpt("aarch64-select-opt", cl::Hidden,
139bdd1243dSDimitry Andric                     cl::desc("Enable select to branch optimizations"),
140fcaf7f86SDimitry Andric                     cl::init(true));
1410b57cec5SDimitry Andric 
1420b57cec5SDimitry Andric static cl::opt<bool>
1430b57cec5SDimitry Andric     BranchRelaxation("aarch64-enable-branch-relax", cl::Hidden, cl::init(true),
1440b57cec5SDimitry Andric                      cl::desc("Relax out of range conditional branches"));
1450b57cec5SDimitry Andric 
1460b57cec5SDimitry Andric static cl::opt<bool> EnableCompressJumpTables(
1470b57cec5SDimitry Andric     "aarch64-enable-compress-jump-tables", cl::Hidden, cl::init(true),
1480b57cec5SDimitry Andric     cl::desc("Use smallest entry possible for jump tables"));
1490b57cec5SDimitry Andric 
1500b57cec5SDimitry Andric // FIXME: Unify control over GlobalMerge.
1510b57cec5SDimitry Andric static cl::opt<cl::boolOrDefault>
1520b57cec5SDimitry Andric     EnableGlobalMerge("aarch64-enable-global-merge", cl::Hidden,
1530b57cec5SDimitry Andric                       cl::desc("Enable the global merge pass"));
1540b57cec5SDimitry Andric 
1550b57cec5SDimitry Andric static cl::opt<bool>
1560b57cec5SDimitry Andric     EnableLoopDataPrefetch("aarch64-enable-loop-data-prefetch", cl::Hidden,
1570b57cec5SDimitry Andric                            cl::desc("Enable the loop data prefetch pass"),
1580b57cec5SDimitry Andric                            cl::init(true));
1590b57cec5SDimitry Andric 
1600b57cec5SDimitry Andric static cl::opt<int> EnableGlobalISelAtO(
1610b57cec5SDimitry Andric     "aarch64-enable-global-isel-at-O", cl::Hidden,
1620b57cec5SDimitry Andric     cl::desc("Enable GlobalISel at or below an opt level (-1 to disable)"),
1630b57cec5SDimitry Andric     cl::init(0));
1640b57cec5SDimitry Andric 
165e8d8bef9SDimitry Andric static cl::opt<bool>
166e8d8bef9SDimitry Andric     EnableSVEIntrinsicOpts("aarch64-enable-sve-intrinsic-opts", cl::Hidden,
1675ffd83dbSDimitry Andric                            cl::desc("Enable SVE intrinsic opts"),
1685ffd83dbSDimitry Andric                            cl::init(true));
1695ffd83dbSDimitry Andric 
1700b57cec5SDimitry Andric static cl::opt<bool> EnableFalkorHWPFFix("aarch64-enable-falkor-hwpf-fix",
1710b57cec5SDimitry Andric                                          cl::init(true), cl::Hidden);
1720b57cec5SDimitry Andric 
1730b57cec5SDimitry Andric static cl::opt<bool>
1740b57cec5SDimitry Andric     EnableBranchTargets("aarch64-enable-branch-targets", cl::Hidden,
175fe6060f1SDimitry Andric                         cl::desc("Enable the AArch64 branch target pass"),
1760b57cec5SDimitry Andric                         cl::init(true));
1770b57cec5SDimitry Andric 
178fe6060f1SDimitry Andric static cl::opt<unsigned> SVEVectorBitsMaxOpt(
179fe6060f1SDimitry Andric     "aarch64-sve-vector-bits-max",
180fe6060f1SDimitry Andric     cl::desc("Assume SVE vector registers are at most this big, "
181fe6060f1SDimitry Andric              "with zero meaning no maximum size is assumed."),
182fe6060f1SDimitry Andric     cl::init(0), cl::Hidden);
183fe6060f1SDimitry Andric 
184fe6060f1SDimitry Andric static cl::opt<unsigned> SVEVectorBitsMinOpt(
185fe6060f1SDimitry Andric     "aarch64-sve-vector-bits-min",
186fe6060f1SDimitry Andric     cl::desc("Assume SVE vector registers are at least this big, "
187fe6060f1SDimitry Andric              "with zero meaning no minimum size is assumed."),
188fe6060f1SDimitry Andric     cl::init(0), cl::Hidden);
189fe6060f1SDimitry Andric 
190*0fca6ea1SDimitry Andric static cl::opt<bool> ForceStreaming(
191*0fca6ea1SDimitry Andric     "force-streaming",
192*0fca6ea1SDimitry Andric     cl::desc("Force the use of streaming code for all functions"),
193*0fca6ea1SDimitry Andric     cl::init(false), cl::Hidden);
194*0fca6ea1SDimitry Andric 
195*0fca6ea1SDimitry Andric static cl::opt<bool> ForceStreamingCompatible(
196*0fca6ea1SDimitry Andric     "force-streaming-compatible",
197*0fca6ea1SDimitry Andric     cl::desc("Force the use of streaming-compatible code for all functions"),
198*0fca6ea1SDimitry Andric     cl::init(false), cl::Hidden);
199*0fca6ea1SDimitry Andric 
200fe6060f1SDimitry Andric extern cl::opt<bool> EnableHomogeneousPrologEpilog;
201fe6060f1SDimitry Andric 
202349cc55cSDimitry Andric static cl::opt<bool> EnableGISelLoadStoreOptPreLegal(
203349cc55cSDimitry Andric     "aarch64-enable-gisel-ldst-prelegal",
204349cc55cSDimitry Andric     cl::desc("Enable GlobalISel's pre-legalizer load/store optimization pass"),
205349cc55cSDimitry Andric     cl::init(true), cl::Hidden);
206349cc55cSDimitry Andric 
207349cc55cSDimitry Andric static cl::opt<bool> EnableGISelLoadStoreOptPostLegal(
208349cc55cSDimitry Andric     "aarch64-enable-gisel-ldst-postlegal",
209349cc55cSDimitry Andric     cl::desc("Enable GlobalISel's post-legalizer load/store optimization pass"),
210349cc55cSDimitry Andric     cl::init(false), cl::Hidden);
211349cc55cSDimitry Andric 
2125f757f3fSDimitry Andric static cl::opt<bool>
2135f757f3fSDimitry Andric     EnableSinkFold("aarch64-enable-sink-fold",
2145f757f3fSDimitry Andric                    cl::desc("Enable sinking and folding of instruction copies"),
2155f757f3fSDimitry Andric                    cl::init(true), cl::Hidden);
2165f757f3fSDimitry Andric 
217*0fca6ea1SDimitry Andric static cl::opt<bool>
218*0fca6ea1SDimitry Andric     EnableMachinePipeliner("aarch64-enable-pipeliner",
219*0fca6ea1SDimitry Andric                            cl::desc("Enable Machine Pipeliner for AArch64"),
220*0fca6ea1SDimitry Andric                            cl::init(false), cl::Hidden);
221*0fca6ea1SDimitry Andric 
LLVMInitializeAArch64Target()222480093f4SDimitry Andric extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64Target() {
2230b57cec5SDimitry Andric   // Register the target.
2240b57cec5SDimitry Andric   RegisterTargetMachine<AArch64leTargetMachine> X(getTheAArch64leTarget());
2250b57cec5SDimitry Andric   RegisterTargetMachine<AArch64beTargetMachine> Y(getTheAArch64beTarget());
2260b57cec5SDimitry Andric   RegisterTargetMachine<AArch64leTargetMachine> Z(getTheARM64Target());
2278bcb0991SDimitry Andric   RegisterTargetMachine<AArch64leTargetMachine> W(getTheARM64_32Target());
2288bcb0991SDimitry Andric   RegisterTargetMachine<AArch64leTargetMachine> V(getTheAArch64_32Target());
2290b57cec5SDimitry Andric   auto PR = PassRegistry::getPassRegistry();
2300b57cec5SDimitry Andric   initializeGlobalISel(*PR);
2310b57cec5SDimitry Andric   initializeAArch64A53Fix835769Pass(*PR);
2320b57cec5SDimitry Andric   initializeAArch64A57FPLoadBalancingPass(*PR);
2330b57cec5SDimitry Andric   initializeAArch64AdvSIMDScalarPass(*PR);
2340b57cec5SDimitry Andric   initializeAArch64BranchTargetsPass(*PR);
2350b57cec5SDimitry Andric   initializeAArch64CollectLOHPass(*PR);
2360b57cec5SDimitry Andric   initializeAArch64CompressJumpTablesPass(*PR);
2370b57cec5SDimitry Andric   initializeAArch64ConditionalComparesPass(*PR);
2380b57cec5SDimitry Andric   initializeAArch64ConditionOptimizerPass(*PR);
2390b57cec5SDimitry Andric   initializeAArch64DeadRegisterDefinitionsPass(*PR);
2400b57cec5SDimitry Andric   initializeAArch64ExpandPseudoPass(*PR);
2410b57cec5SDimitry Andric   initializeAArch64LoadStoreOptPass(*PR);
242349cc55cSDimitry Andric   initializeAArch64MIPeepholeOptPass(*PR);
2430b57cec5SDimitry Andric   initializeAArch64SIMDInstrOptPass(*PR);
244fe6060f1SDimitry Andric   initializeAArch64O0PreLegalizerCombinerPass(*PR);
2450b57cec5SDimitry Andric   initializeAArch64PreLegalizerCombinerPass(*PR);
2465f757f3fSDimitry Andric   initializeAArch64PointerAuthPass(*PR);
247*0fca6ea1SDimitry Andric   initializeAArch64PostCoalescerPass(*PR);
2485ffd83dbSDimitry Andric   initializeAArch64PostLegalizerCombinerPass(*PR);
249e8d8bef9SDimitry Andric   initializeAArch64PostLegalizerLoweringPass(*PR);
250e8d8bef9SDimitry Andric   initializeAArch64PostSelectOptimizePass(*PR);
2510b57cec5SDimitry Andric   initializeAArch64PromoteConstantPass(*PR);
2520b57cec5SDimitry Andric   initializeAArch64RedundantCopyEliminationPass(*PR);
2530b57cec5SDimitry Andric   initializeAArch64StorePairSuppressPass(*PR);
2540b57cec5SDimitry Andric   initializeFalkorHWPFFixPass(*PR);
2550b57cec5SDimitry Andric   initializeFalkorMarkStridedAccessesLegacyPass(*PR);
2560b57cec5SDimitry Andric   initializeLDTLSCleanupPass(*PR);
25706c3fb27SDimitry Andric   initializeKCFIPass(*PR);
258bdd1243dSDimitry Andric   initializeSMEABIPass(*PR);
2595ffd83dbSDimitry Andric   initializeSVEIntrinsicOptsPass(*PR);
2600b57cec5SDimitry Andric   initializeAArch64SpeculationHardeningPass(*PR);
2615ffd83dbSDimitry Andric   initializeAArch64SLSHardeningPass(*PR);
2620b57cec5SDimitry Andric   initializeAArch64StackTaggingPass(*PR);
2638bcb0991SDimitry Andric   initializeAArch64StackTaggingPreRAPass(*PR);
264fe6060f1SDimitry Andric   initializeAArch64LowerHomogeneousPrologEpilogPass(*PR);
265*0fca6ea1SDimitry Andric   initializeAArch64DAGToDAGISelLegacyPass(*PR);
26606c3fb27SDimitry Andric   initializeAArch64GlobalsTaggingPass(*PR);
2670b57cec5SDimitry Andric }
2680b57cec5SDimitry Andric 
2690b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
2700b57cec5SDimitry Andric // AArch64 Lowering public interface.
2710b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
createTLOF(const Triple & TT)2720b57cec5SDimitry Andric static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
2730b57cec5SDimitry Andric   if (TT.isOSBinFormatMachO())
2748bcb0991SDimitry Andric     return std::make_unique<AArch64_MachoTargetObjectFile>();
2750b57cec5SDimitry Andric   if (TT.isOSBinFormatCOFF())
2768bcb0991SDimitry Andric     return std::make_unique<AArch64_COFFTargetObjectFile>();
2770b57cec5SDimitry Andric 
2788bcb0991SDimitry Andric   return std::make_unique<AArch64_ELFTargetObjectFile>();
2790b57cec5SDimitry Andric }
2800b57cec5SDimitry Andric 
2810b57cec5SDimitry Andric // Helper function to build a DataLayout string
computeDataLayout(const Triple & TT,const MCTargetOptions & Options,bool LittleEndian)2820b57cec5SDimitry Andric static std::string computeDataLayout(const Triple &TT,
2830b57cec5SDimitry Andric                                      const MCTargetOptions &Options,
2840b57cec5SDimitry Andric                                      bool LittleEndian) {
2858bcb0991SDimitry Andric   if (TT.isOSBinFormatMachO()) {
2868bcb0991SDimitry Andric     if (TT.getArch() == Triple::aarch64_32)
287*0fca6ea1SDimitry Andric       return "e-m:o-p:32:32-i64:64-i128:128-n32:64-S128-Fn32";
288*0fca6ea1SDimitry Andric     return "e-m:o-i64:64-i128:128-n32:64-S128-Fn32";
2898bcb0991SDimitry Andric   }
2900b57cec5SDimitry Andric   if (TT.isOSBinFormatCOFF())
291*0fca6ea1SDimitry Andric     return "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128-Fn32";
292e8d8bef9SDimitry Andric   std::string Endian = LittleEndian ? "e" : "E";
293e8d8bef9SDimitry Andric   std::string Ptr32 = TT.getEnvironment() == Triple::GNUILP32 ? "-p:32:32" : "";
294e8d8bef9SDimitry Andric   return Endian + "-m:e" + Ptr32 +
295*0fca6ea1SDimitry Andric          "-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32";
296e8d8bef9SDimitry Andric }
297e8d8bef9SDimitry Andric 
computeDefaultCPU(const Triple & TT,StringRef CPU)298e8d8bef9SDimitry Andric static StringRef computeDefaultCPU(const Triple &TT, StringRef CPU) {
299e8d8bef9SDimitry Andric   if (CPU.empty() && TT.isArm64e())
300e8d8bef9SDimitry Andric     return "apple-a12";
301e8d8bef9SDimitry Andric   return CPU;
3020b57cec5SDimitry Andric }
3030b57cec5SDimitry Andric 
getEffectiveRelocModel(const Triple & TT,std::optional<Reloc::Model> RM)3040b57cec5SDimitry Andric static Reloc::Model getEffectiveRelocModel(const Triple &TT,
305bdd1243dSDimitry Andric                                            std::optional<Reloc::Model> RM) {
3060b57cec5SDimitry Andric   // AArch64 Darwin and Windows are always PIC.
3070b57cec5SDimitry Andric   if (TT.isOSDarwin() || TT.isOSWindows())
3080b57cec5SDimitry Andric     return Reloc::PIC_;
3090b57cec5SDimitry Andric   // On ELF platforms the default static relocation model has a smart enough
3100b57cec5SDimitry Andric   // linker to cope with referencing external symbols defined in a shared
3110b57cec5SDimitry Andric   // library. Hence DynamicNoPIC doesn't need to be promoted to PIC.
31281ad6265SDimitry Andric   if (!RM || *RM == Reloc::DynamicNoPIC)
3130b57cec5SDimitry Andric     return Reloc::Static;
3140b57cec5SDimitry Andric   return *RM;
3150b57cec5SDimitry Andric }
3160b57cec5SDimitry Andric 
3170b57cec5SDimitry Andric static CodeModel::Model
getEffectiveAArch64CodeModel(const Triple & TT,std::optional<CodeModel::Model> CM,bool JIT)318bdd1243dSDimitry Andric getEffectiveAArch64CodeModel(const Triple &TT,
319bdd1243dSDimitry Andric                              std::optional<CodeModel::Model> CM, bool JIT) {
3200b57cec5SDimitry Andric   if (CM) {
3210b57cec5SDimitry Andric     if (*CM != CodeModel::Small && *CM != CodeModel::Tiny &&
3220b57cec5SDimitry Andric         *CM != CodeModel::Large) {
3230b57cec5SDimitry Andric       report_fatal_error(
3240b57cec5SDimitry Andric           "Only small, tiny and large code models are allowed on AArch64");
3250b57cec5SDimitry Andric     } else if (*CM == CodeModel::Tiny && !TT.isOSBinFormatELF())
3260b57cec5SDimitry Andric       report_fatal_error("tiny code model is only supported on ELF");
3270b57cec5SDimitry Andric     return *CM;
3280b57cec5SDimitry Andric   }
3290b57cec5SDimitry Andric   // The default MCJIT memory managers make no guarantees about where they can
3300b57cec5SDimitry Andric   // find an executable page; JITed code needs to be able to refer to globals
3310b57cec5SDimitry Andric   // no matter how far away they are.
332480093f4SDimitry Andric   // We should set the CodeModel::Small for Windows ARM64 in JIT mode,
333480093f4SDimitry Andric   // since with large code model LLVM generating 4 MOV instructions, and
334480093f4SDimitry Andric   // Windows doesn't support relocating these long branch (4 MOVs).
335480093f4SDimitry Andric   if (JIT && !TT.isOSWindows())
3360b57cec5SDimitry Andric     return CodeModel::Large;
3370b57cec5SDimitry Andric   return CodeModel::Small;
3380b57cec5SDimitry Andric }
3390b57cec5SDimitry Andric 
3400b57cec5SDimitry Andric /// Create an AArch64 architecture model.
3410b57cec5SDimitry Andric ///
AArch64TargetMachine(const Target & T,const Triple & TT,StringRef CPU,StringRef FS,const TargetOptions & Options,std::optional<Reloc::Model> RM,std::optional<CodeModel::Model> CM,CodeGenOptLevel OL,bool JIT,bool LittleEndian)3420b57cec5SDimitry Andric AArch64TargetMachine::AArch64TargetMachine(const Target &T, const Triple &TT,
3430b57cec5SDimitry Andric                                            StringRef CPU, StringRef FS,
3440b57cec5SDimitry Andric                                            const TargetOptions &Options,
345bdd1243dSDimitry Andric                                            std::optional<Reloc::Model> RM,
346bdd1243dSDimitry Andric                                            std::optional<CodeModel::Model> CM,
3475f757f3fSDimitry Andric                                            CodeGenOptLevel OL, bool JIT,
3480b57cec5SDimitry Andric                                            bool LittleEndian)
3490b57cec5SDimitry Andric     : LLVMTargetMachine(T,
3500b57cec5SDimitry Andric                         computeDataLayout(TT, Options.MCOptions, LittleEndian),
351e8d8bef9SDimitry Andric                         TT, computeDefaultCPU(TT, CPU), FS, Options,
352e8d8bef9SDimitry Andric                         getEffectiveRelocModel(TT, RM),
3530b57cec5SDimitry Andric                         getEffectiveAArch64CodeModel(TT, CM, JIT), OL),
3540b57cec5SDimitry Andric       TLOF(createTLOF(getTargetTriple())), isLittle(LittleEndian) {
3550b57cec5SDimitry Andric   initAsmInfo();
3560b57cec5SDimitry Andric 
3570b57cec5SDimitry Andric   if (TT.isOSBinFormatMachO()) {
3580b57cec5SDimitry Andric     this->Options.TrapUnreachable = true;
3590b57cec5SDimitry Andric     this->Options.NoTrapAfterNoreturn = true;
3600b57cec5SDimitry Andric   }
3610b57cec5SDimitry Andric 
3620b57cec5SDimitry Andric   if (getMCAsmInfo()->usesWindowsCFI()) {
3630b57cec5SDimitry Andric     // Unwinding can get confused if the last instruction in an
3640b57cec5SDimitry Andric     // exception-handling region (function, funclet, try block, etc.)
3650b57cec5SDimitry Andric     // is a call.
3660b57cec5SDimitry Andric     //
3670b57cec5SDimitry Andric     // FIXME: We could elide the trap if the next instruction would be in
3680b57cec5SDimitry Andric     // the same region anyway.
3690b57cec5SDimitry Andric     this->Options.TrapUnreachable = true;
3700b57cec5SDimitry Andric   }
3710b57cec5SDimitry Andric 
372480093f4SDimitry Andric   if (this->Options.TLSSize == 0) // default
373480093f4SDimitry Andric     this->Options.TLSSize = 24;
374480093f4SDimitry Andric   if ((getCodeModel() == CodeModel::Small ||
375480093f4SDimitry Andric        getCodeModel() == CodeModel::Kernel) &&
376480093f4SDimitry Andric       this->Options.TLSSize > 32)
377480093f4SDimitry Andric     // for the small (and kernel) code model, the maximum TLS size is 4GiB
378480093f4SDimitry Andric     this->Options.TLSSize = 32;
379480093f4SDimitry Andric   else if (getCodeModel() == CodeModel::Tiny && this->Options.TLSSize > 24)
380480093f4SDimitry Andric     // for the tiny code model, the maximum TLS size is 1MiB (< 16MiB)
381480093f4SDimitry Andric     this->Options.TLSSize = 24;
382480093f4SDimitry Andric 
3838bcb0991SDimitry Andric   // Enable GlobalISel at or below EnableGlobalISelAt0, unless this is
3848bcb0991SDimitry Andric   // MachO/CodeModel::Large, which GlobalISel does not support.
3855f757f3fSDimitry Andric   if (static_cast<int>(getOptLevel()) <= EnableGlobalISelAtO &&
3868bcb0991SDimitry Andric       TT.getArch() != Triple::aarch64_32 &&
387e8d8bef9SDimitry Andric       TT.getEnvironment() != Triple::GNUILP32 &&
3888bcb0991SDimitry Andric       !(getCodeModel() == CodeModel::Large && TT.isOSBinFormatMachO())) {
3890b57cec5SDimitry Andric     setGlobalISel(true);
3900b57cec5SDimitry Andric     setGlobalISelAbort(GlobalISelAbortMode::Disable);
3910b57cec5SDimitry Andric   }
3920b57cec5SDimitry Andric 
3930b57cec5SDimitry Andric   // AArch64 supports the MachineOutliner.
3940b57cec5SDimitry Andric   setMachineOutliner(true);
3950b57cec5SDimitry Andric 
3960b57cec5SDimitry Andric   // AArch64 supports default outlining behaviour.
3970b57cec5SDimitry Andric   setSupportsDefaultOutlining(true);
3985ffd83dbSDimitry Andric 
3995ffd83dbSDimitry Andric   // AArch64 supports the debug entry values.
4005ffd83dbSDimitry Andric   setSupportsDebugEntryValues(true);
40181ad6265SDimitry Andric 
40281ad6265SDimitry Andric   // AArch64 supports fixing up the DWARF unwind information.
40381ad6265SDimitry Andric   if (!getMCAsmInfo()->usesWindowsCFI())
40481ad6265SDimitry Andric     setCFIFixup(true);
4050b57cec5SDimitry Andric }
4060b57cec5SDimitry Andric 
4070b57cec5SDimitry Andric AArch64TargetMachine::~AArch64TargetMachine() = default;
4080b57cec5SDimitry Andric 
4090b57cec5SDimitry Andric const AArch64Subtarget *
getSubtargetImpl(const Function & F) const4100b57cec5SDimitry Andric AArch64TargetMachine::getSubtargetImpl(const Function &F) const {
4110b57cec5SDimitry Andric   Attribute CPUAttr = F.getFnAttribute("target-cpu");
412349cc55cSDimitry Andric   Attribute TuneAttr = F.getFnAttribute("tune-cpu");
4130b57cec5SDimitry Andric   Attribute FSAttr = F.getFnAttribute("target-features");
4140b57cec5SDimitry Andric 
415bdd1243dSDimitry Andric   StringRef CPU = CPUAttr.isValid() ? CPUAttr.getValueAsString() : TargetCPU;
416bdd1243dSDimitry Andric   StringRef TuneCPU = TuneAttr.isValid() ? TuneAttr.getValueAsString() : CPU;
417bdd1243dSDimitry Andric   StringRef FS = FSAttr.isValid() ? FSAttr.getValueAsString() : TargetFS;
4185f757f3fSDimitry Andric   bool HasMinSize = F.hasMinSize();
4190b57cec5SDimitry Andric 
420*0fca6ea1SDimitry Andric   bool IsStreaming = ForceStreaming ||
421*0fca6ea1SDimitry Andric                      F.hasFnAttribute("aarch64_pstate_sm_enabled") ||
42206c3fb27SDimitry Andric                      F.hasFnAttribute("aarch64_pstate_sm_body");
423*0fca6ea1SDimitry Andric   bool IsStreamingCompatible = ForceStreamingCompatible ||
42406c3fb27SDimitry Andric                                F.hasFnAttribute("aarch64_pstate_sm_compatible");
425fe6060f1SDimitry Andric 
426fe6060f1SDimitry Andric   unsigned MinSVEVectorSize = 0;
427fe6060f1SDimitry Andric   unsigned MaxSVEVectorSize = 0;
4285f757f3fSDimitry Andric   if (F.hasFnAttribute(Attribute::VScaleRange)) {
4295f757f3fSDimitry Andric     ConstantRange CR = getVScaleRange(&F, 64);
4305f757f3fSDimitry Andric     MinSVEVectorSize = CR.getUnsignedMin().getZExtValue() * 128;
4315f757f3fSDimitry Andric     MaxSVEVectorSize = CR.getUnsignedMax().getZExtValue() * 128;
432fe6060f1SDimitry Andric   } else {
433fe6060f1SDimitry Andric     MinSVEVectorSize = SVEVectorBitsMinOpt;
434fe6060f1SDimitry Andric     MaxSVEVectorSize = SVEVectorBitsMaxOpt;
435fe6060f1SDimitry Andric   }
436fe6060f1SDimitry Andric 
437fe6060f1SDimitry Andric   assert(MinSVEVectorSize % 128 == 0 &&
438fe6060f1SDimitry Andric          "SVE requires vector length in multiples of 128!");
439fe6060f1SDimitry Andric   assert(MaxSVEVectorSize % 128 == 0 &&
440fe6060f1SDimitry Andric          "SVE requires vector length in multiples of 128!");
441fe6060f1SDimitry Andric   assert((MaxSVEVectorSize >= MinSVEVectorSize || MaxSVEVectorSize == 0) &&
442fe6060f1SDimitry Andric          "Minimum SVE vector size should not be larger than its maximum!");
443fe6060f1SDimitry Andric 
444fe6060f1SDimitry Andric   // Sanitize user input in case of no asserts
4455f757f3fSDimitry Andric   if (MaxSVEVectorSize != 0) {
4465f757f3fSDimitry Andric     MinSVEVectorSize = std::min(MinSVEVectorSize, MaxSVEVectorSize);
4475f757f3fSDimitry Andric     MaxSVEVectorSize = std::max(MinSVEVectorSize, MaxSVEVectorSize);
448fe6060f1SDimitry Andric   }
449fe6060f1SDimitry Andric 
450bdd1243dSDimitry Andric   SmallString<512> Key;
451bdd1243dSDimitry Andric   raw_svector_ostream(Key) << "SVEMin" << MinSVEVectorSize << "SVEMax"
452*0fca6ea1SDimitry Andric                            << MaxSVEVectorSize << "IsStreaming=" << IsStreaming
453*0fca6ea1SDimitry Andric                            << "IsStreamingCompatible=" << IsStreamingCompatible
454*0fca6ea1SDimitry Andric                            << CPU << TuneCPU << FS
4555f757f3fSDimitry Andric                            << "HasMinSize=" << HasMinSize;
456fe6060f1SDimitry Andric 
457fe6060f1SDimitry Andric   auto &I = SubtargetMap[Key];
4580b57cec5SDimitry Andric   if (!I) {
4590b57cec5SDimitry Andric     // This needs to be done before we create a new subtarget since any
4600b57cec5SDimitry Andric     // creation will depend on the TM and the code generation flags on the
4610b57cec5SDimitry Andric     // function that reside in TargetOptions.
4620b57cec5SDimitry Andric     resetTargetOptions(F);
463bdd1243dSDimitry Andric     I = std::make_unique<AArch64Subtarget>(
464bdd1243dSDimitry Andric         TargetTriple, CPU, TuneCPU, FS, *this, isLittle, MinSVEVectorSize,
465*0fca6ea1SDimitry Andric         MaxSVEVectorSize, IsStreaming, IsStreamingCompatible, HasMinSize);
4660b57cec5SDimitry Andric   }
46706c3fb27SDimitry Andric 
468*0fca6ea1SDimitry Andric   assert((!IsStreaming || I->hasSME()) && "Expected SME to be available");
46906c3fb27SDimitry Andric 
4700b57cec5SDimitry Andric   return I.get();
4710b57cec5SDimitry Andric }
4720b57cec5SDimitry Andric 
anchor()4730b57cec5SDimitry Andric void AArch64leTargetMachine::anchor() { }
4740b57cec5SDimitry Andric 
AArch64leTargetMachine(const Target & T,const Triple & TT,StringRef CPU,StringRef FS,const TargetOptions & Options,std::optional<Reloc::Model> RM,std::optional<CodeModel::Model> CM,CodeGenOptLevel OL,bool JIT)4750b57cec5SDimitry Andric AArch64leTargetMachine::AArch64leTargetMachine(
4760b57cec5SDimitry Andric     const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
477bdd1243dSDimitry Andric     const TargetOptions &Options, std::optional<Reloc::Model> RM,
4785f757f3fSDimitry Andric     std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT)
4790b57cec5SDimitry Andric     : AArch64TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT, true) {}
4800b57cec5SDimitry Andric 
anchor()4810b57cec5SDimitry Andric void AArch64beTargetMachine::anchor() { }
4820b57cec5SDimitry Andric 
AArch64beTargetMachine(const Target & T,const Triple & TT,StringRef CPU,StringRef FS,const TargetOptions & Options,std::optional<Reloc::Model> RM,std::optional<CodeModel::Model> CM,CodeGenOptLevel OL,bool JIT)4830b57cec5SDimitry Andric AArch64beTargetMachine::AArch64beTargetMachine(
4840b57cec5SDimitry Andric     const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
485bdd1243dSDimitry Andric     const TargetOptions &Options, std::optional<Reloc::Model> RM,
4865f757f3fSDimitry Andric     std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT)
4870b57cec5SDimitry Andric     : AArch64TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT, false) {}
4880b57cec5SDimitry Andric 
4890b57cec5SDimitry Andric namespace {
4900b57cec5SDimitry Andric 
4910b57cec5SDimitry Andric /// AArch64 Code Generator Pass Configuration Options.
4920b57cec5SDimitry Andric class AArch64PassConfig : public TargetPassConfig {
4930b57cec5SDimitry Andric public:
AArch64PassConfig(AArch64TargetMachine & TM,PassManagerBase & PM)4940b57cec5SDimitry Andric   AArch64PassConfig(AArch64TargetMachine &TM, PassManagerBase &PM)
4950b57cec5SDimitry Andric       : TargetPassConfig(TM, PM) {
4965f757f3fSDimitry Andric     if (TM.getOptLevel() != CodeGenOptLevel::None)
4970b57cec5SDimitry Andric       substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
4985f757f3fSDimitry Andric     setEnableSinkAndFold(EnableSinkFold);
4990b57cec5SDimitry Andric   }
5000b57cec5SDimitry Andric 
getAArch64TargetMachine() const5010b57cec5SDimitry Andric   AArch64TargetMachine &getAArch64TargetMachine() const {
5020b57cec5SDimitry Andric     return getTM<AArch64TargetMachine>();
5030b57cec5SDimitry Andric   }
5040b57cec5SDimitry Andric 
5050b57cec5SDimitry Andric   ScheduleDAGInstrs *
createMachineScheduler(MachineSchedContext * C) const5060b57cec5SDimitry Andric   createMachineScheduler(MachineSchedContext *C) const override {
5070b57cec5SDimitry Andric     const AArch64Subtarget &ST = C->MF->getSubtarget<AArch64Subtarget>();
5080b57cec5SDimitry Andric     ScheduleDAGMILive *DAG = createGenericSchedLive(C);
5090b57cec5SDimitry Andric     DAG->addMutation(createLoadClusterDAGMutation(DAG->TII, DAG->TRI));
5100b57cec5SDimitry Andric     DAG->addMutation(createStoreClusterDAGMutation(DAG->TII, DAG->TRI));
5110b57cec5SDimitry Andric     if (ST.hasFusion())
5120b57cec5SDimitry Andric       DAG->addMutation(createAArch64MacroFusionDAGMutation());
5130b57cec5SDimitry Andric     return DAG;
5140b57cec5SDimitry Andric   }
5150b57cec5SDimitry Andric 
5160b57cec5SDimitry Andric   ScheduleDAGInstrs *
createPostMachineScheduler(MachineSchedContext * C) const5170b57cec5SDimitry Andric   createPostMachineScheduler(MachineSchedContext *C) const override {
5180b57cec5SDimitry Andric     const AArch64Subtarget &ST = C->MF->getSubtarget<AArch64Subtarget>();
51981ad6265SDimitry Andric     ScheduleDAGMI *DAG =
52081ad6265SDimitry Andric         new ScheduleDAGMI(C, std::make_unique<AArch64PostRASchedStrategy>(C),
52181ad6265SDimitry Andric                           /* RemoveKillFlags=*/true);
5220b57cec5SDimitry Andric     if (ST.hasFusion()) {
5230b57cec5SDimitry Andric       // Run the Macro Fusion after RA again since literals are expanded from
5240b57cec5SDimitry Andric       // pseudos then (v. addPreSched2()).
5250b57cec5SDimitry Andric       DAG->addMutation(createAArch64MacroFusionDAGMutation());
5260b57cec5SDimitry Andric       return DAG;
5270b57cec5SDimitry Andric     }
5280b57cec5SDimitry Andric 
52981ad6265SDimitry Andric     return DAG;
5300b57cec5SDimitry Andric   }
5310b57cec5SDimitry Andric 
5320b57cec5SDimitry Andric   void addIRPasses()  override;
5330b57cec5SDimitry Andric   bool addPreISel() override;
534349cc55cSDimitry Andric   void addCodeGenPrepare() override;
5350b57cec5SDimitry Andric   bool addInstSelector() override;
5360b57cec5SDimitry Andric   bool addIRTranslator() override;
5370b57cec5SDimitry Andric   void addPreLegalizeMachineIR() override;
5380b57cec5SDimitry Andric   bool addLegalizeMachineIR() override;
5395ffd83dbSDimitry Andric   void addPreRegBankSelect() override;
5400b57cec5SDimitry Andric   bool addRegBankSelect() override;
5410b57cec5SDimitry Andric   bool addGlobalInstructionSelect() override;
542349cc55cSDimitry Andric   void addMachineSSAOptimization() override;
5430b57cec5SDimitry Andric   bool addILPOpts() override;
5440b57cec5SDimitry Andric   void addPreRegAlloc() override;
5450b57cec5SDimitry Andric   void addPostRegAlloc() override;
5460b57cec5SDimitry Andric   void addPreSched2() override;
5470b57cec5SDimitry Andric   void addPreEmitPass() override;
54806c3fb27SDimitry Andric   void addPostBBSections() override;
549fe6060f1SDimitry Andric   void addPreEmitPass2() override;
550*0fca6ea1SDimitry Andric   bool addRegAssignAndRewriteOptimized() override;
5510b57cec5SDimitry Andric 
5520b57cec5SDimitry Andric   std::unique_ptr<CSEConfigBase> getCSEConfig() const override;
5530b57cec5SDimitry Andric };
5540b57cec5SDimitry Andric 
5550b57cec5SDimitry Andric } // end anonymous namespace
5560b57cec5SDimitry Andric 
registerPassBuilderCallbacks(PassBuilder & PB)557*0fca6ea1SDimitry Andric void AArch64TargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
558*0fca6ea1SDimitry Andric 
5591db9f3b2SDimitry Andric   PB.registerLateLoopOptimizationsEPCallback(
5601db9f3b2SDimitry Andric       [=](LoopPassManager &LPM, OptimizationLevel Level) {
561*0fca6ea1SDimitry Andric         LPM.addPass(LoopIdiomVectorizePass());
5621db9f3b2SDimitry Andric       });
5631db9f3b2SDimitry Andric }
5641db9f3b2SDimitry Andric 
5650b57cec5SDimitry Andric TargetTransformInfo
getTargetTransformInfo(const Function & F) const56681ad6265SDimitry Andric AArch64TargetMachine::getTargetTransformInfo(const Function &F) const {
5670b57cec5SDimitry Andric   return TargetTransformInfo(AArch64TTIImpl(this, F));
5680b57cec5SDimitry Andric }
5690b57cec5SDimitry Andric 
createPassConfig(PassManagerBase & PM)5700b57cec5SDimitry Andric TargetPassConfig *AArch64TargetMachine::createPassConfig(PassManagerBase &PM) {
5710b57cec5SDimitry Andric   return new AArch64PassConfig(*this, PM);
5720b57cec5SDimitry Andric }
5730b57cec5SDimitry Andric 
getCSEConfig() const5740b57cec5SDimitry Andric std::unique_ptr<CSEConfigBase> AArch64PassConfig::getCSEConfig() const {
5750b57cec5SDimitry Andric   return getStandardCSEConfigForOpt(TM->getOptLevel());
5760b57cec5SDimitry Andric }
5770b57cec5SDimitry Andric 
addIRPasses()5780b57cec5SDimitry Andric void AArch64PassConfig::addIRPasses() {
5790b57cec5SDimitry Andric   // Always expand atomic operations, we don't deal with atomicrmw or cmpxchg
5800b57cec5SDimitry Andric   // ourselves.
581*0fca6ea1SDimitry Andric   addPass(createAtomicExpandLegacyPass());
5820b57cec5SDimitry Andric 
5835ffd83dbSDimitry Andric   // Expand any SVE vector library calls that we can't code generate directly.
5845f757f3fSDimitry Andric   if (EnableSVEIntrinsicOpts &&
5855f757f3fSDimitry Andric       TM->getOptLevel() == CodeGenOptLevel::Aggressive)
5865ffd83dbSDimitry Andric     addPass(createSVEIntrinsicOptsPass());
5875ffd83dbSDimitry Andric 
5880b57cec5SDimitry Andric   // Cmpxchg instructions are often used with a subsequent comparison to
5890b57cec5SDimitry Andric   // determine whether it succeeded. We can exploit existing control-flow in
5900b57cec5SDimitry Andric   // ldrex/strex loops to simplify this, but it needs tidying up.
5915f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None && EnableAtomicTidy)
592e8d8bef9SDimitry Andric     addPass(createCFGSimplificationPass(SimplifyCFGOptions()
593e8d8bef9SDimitry Andric                                             .forwardSwitchCondToPhi(true)
594fb03ea46SDimitry Andric                                             .convertSwitchRangeToICmp(true)
595e8d8bef9SDimitry Andric                                             .convertSwitchToLookupTable(true)
596e8d8bef9SDimitry Andric                                             .needCanonicalLoops(false)
597e8d8bef9SDimitry Andric                                             .hoistCommonInsts(true)
598e8d8bef9SDimitry Andric                                             .sinkCommonInsts(true)));
5990b57cec5SDimitry Andric 
6000b57cec5SDimitry Andric   // Run LoopDataPrefetch
6010b57cec5SDimitry Andric   //
6020b57cec5SDimitry Andric   // Run this before LSR to remove the multiplies involved in computing the
6030b57cec5SDimitry Andric   // pointer values N iterations ahead.
6045f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None) {
6050b57cec5SDimitry Andric     if (EnableLoopDataPrefetch)
6060b57cec5SDimitry Andric       addPass(createLoopDataPrefetchPass());
6070b57cec5SDimitry Andric     if (EnableFalkorHWPFFix)
6080b57cec5SDimitry Andric       addPass(createFalkorMarkStridedAccessesPass());
6090b57cec5SDimitry Andric   }
6100b57cec5SDimitry Andric 
611*0fca6ea1SDimitry Andric   if (EnableGEPOpt) {
6120b57cec5SDimitry Andric     // Call SeparateConstOffsetFromGEP pass to extract constants within indices
6130b57cec5SDimitry Andric     // and lower a GEP with multiple indices to either arithmetic operations or
6140b57cec5SDimitry Andric     // multiple GEPs with single index.
6150b57cec5SDimitry Andric     addPass(createSeparateConstOffsetFromGEPPass(true));
6160b57cec5SDimitry Andric     // Call EarlyCSE pass to find and remove subexpressions in the lowered
6170b57cec5SDimitry Andric     // result.
6180b57cec5SDimitry Andric     addPass(createEarlyCSEPass());
6190b57cec5SDimitry Andric     // Do loop invariant code motion in case part of the lowered result is
6200b57cec5SDimitry Andric     // invariant.
6210b57cec5SDimitry Andric     addPass(createLICMPass());
6220b57cec5SDimitry Andric   }
6230b57cec5SDimitry Andric 
624fcaf7f86SDimitry Andric   TargetPassConfig::addIRPasses();
625fcaf7f86SDimitry Andric 
6265f757f3fSDimitry Andric   if (getOptLevel() == CodeGenOptLevel::Aggressive && EnableSelectOpt)
627bdd1243dSDimitry Andric     addPass(createSelectOptimizePass());
628bdd1243dSDimitry Andric 
62906c3fb27SDimitry Andric   addPass(createAArch64GlobalsTaggingPass());
630fcaf7f86SDimitry Andric   addPass(createAArch64StackTaggingPass(
6315f757f3fSDimitry Andric       /*IsOptNone=*/TM->getOptLevel() == CodeGenOptLevel::None));
632fcaf7f86SDimitry Andric 
633bdd1243dSDimitry Andric   // Match complex arithmetic patterns
6345f757f3fSDimitry Andric   if (TM->getOptLevel() >= CodeGenOptLevel::Default)
635bdd1243dSDimitry Andric     addPass(createComplexDeinterleavingPass(TM));
636bdd1243dSDimitry Andric 
637fcaf7f86SDimitry Andric   // Match interleaved memory accesses to ldN/stN intrinsics.
6385f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None) {
639fcaf7f86SDimitry Andric     addPass(createInterleavedLoadCombinePass());
640fcaf7f86SDimitry Andric     addPass(createInterleavedAccessPass());
641fcaf7f86SDimitry Andric   }
642fcaf7f86SDimitry Andric 
643bdd1243dSDimitry Andric   // Expand any functions marked with SME attributes which require special
644bdd1243dSDimitry Andric   // changes for the calling convention or that require the lazy-saving
645bdd1243dSDimitry Andric   // mechanism specified in the SME ABI.
646bdd1243dSDimitry Andric   addPass(createSMEABIPass());
647bdd1243dSDimitry Andric 
648480093f4SDimitry Andric   // Add Control Flow Guard checks.
6497a6dacacSDimitry Andric   if (TM->getTargetTriple().isOSWindows()) {
6507a6dacacSDimitry Andric     if (TM->getTargetTriple().isWindowsArm64EC())
6517a6dacacSDimitry Andric       addPass(createAArch64Arm64ECCallLoweringPass());
6527a6dacacSDimitry Andric     else
653480093f4SDimitry Andric       addPass(createCFGuardCheckPass());
6547a6dacacSDimitry Andric   }
65581ad6265SDimitry Andric 
65681ad6265SDimitry Andric   if (TM->Options.JMCInstrument)
65781ad6265SDimitry Andric     addPass(createJMCInstrumenterPass());
6580b57cec5SDimitry Andric }
6590b57cec5SDimitry Andric 
6600b57cec5SDimitry Andric // Pass Pipeline Configuration
addPreISel()6610b57cec5SDimitry Andric bool AArch64PassConfig::addPreISel() {
6620b57cec5SDimitry Andric   // Run promote constant before global merge, so that the promoted constants
6630b57cec5SDimitry Andric   // get a chance to be merged
6645f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None && EnablePromoteConstant)
6650b57cec5SDimitry Andric     addPass(createAArch64PromoteConstantPass());
6660b57cec5SDimitry Andric   // FIXME: On AArch64, this depends on the type.
6670b57cec5SDimitry Andric   // Basically, the addressable offsets are up to 4095 * Ty.getSizeInBytes().
6680b57cec5SDimitry Andric   // and the offset has to be a multiple of the related size in bytes.
6695f757f3fSDimitry Andric   if ((TM->getOptLevel() != CodeGenOptLevel::None &&
6700b57cec5SDimitry Andric        EnableGlobalMerge == cl::BOU_UNSET) ||
6710b57cec5SDimitry Andric       EnableGlobalMerge == cl::BOU_TRUE) {
6725f757f3fSDimitry Andric     bool OnlyOptimizeForSize =
6735f757f3fSDimitry Andric         (TM->getOptLevel() < CodeGenOptLevel::Aggressive) &&
6740b57cec5SDimitry Andric         (EnableGlobalMerge == cl::BOU_UNSET);
6750b57cec5SDimitry Andric 
6760b57cec5SDimitry Andric     // Merging of extern globals is enabled by default on non-Mach-O as we
6770b57cec5SDimitry Andric     // expect it to be generally either beneficial or harmless. On Mach-O it
6780b57cec5SDimitry Andric     // is disabled as we emit the .subsections_via_symbols directive which
6790b57cec5SDimitry Andric     // means that merging extern globals is not safe.
6800b57cec5SDimitry Andric     bool MergeExternalByDefault = !TM->getTargetTriple().isOSBinFormatMachO();
6810b57cec5SDimitry Andric 
6820b57cec5SDimitry Andric     // FIXME: extern global merging is only enabled when we optimise for size
6830b57cec5SDimitry Andric     // because there are some regressions with it also enabled for performance.
6840b57cec5SDimitry Andric     if (!OnlyOptimizeForSize)
6850b57cec5SDimitry Andric       MergeExternalByDefault = false;
6860b57cec5SDimitry Andric 
6870b57cec5SDimitry Andric     addPass(createGlobalMergePass(TM, 4095, OnlyOptimizeForSize,
6880b57cec5SDimitry Andric                                   MergeExternalByDefault));
6890b57cec5SDimitry Andric   }
6900b57cec5SDimitry Andric 
6910b57cec5SDimitry Andric   return false;
6920b57cec5SDimitry Andric }
6930b57cec5SDimitry Andric 
addCodeGenPrepare()694349cc55cSDimitry Andric void AArch64PassConfig::addCodeGenPrepare() {
6955f757f3fSDimitry Andric   if (getOptLevel() != CodeGenOptLevel::None)
696bdd1243dSDimitry Andric     addPass(createTypePromotionLegacyPass());
697349cc55cSDimitry Andric   TargetPassConfig::addCodeGenPrepare();
698349cc55cSDimitry Andric }
699349cc55cSDimitry Andric 
addInstSelector()7000b57cec5SDimitry Andric bool AArch64PassConfig::addInstSelector() {
7010b57cec5SDimitry Andric   addPass(createAArch64ISelDag(getAArch64TargetMachine(), getOptLevel()));
7020b57cec5SDimitry Andric 
7030b57cec5SDimitry Andric   // For ELF, cleanup any local-dynamic TLS accesses (i.e. combine as many
7040b57cec5SDimitry Andric   // references to _TLS_MODULE_BASE_ as possible.
7050b57cec5SDimitry Andric   if (TM->getTargetTriple().isOSBinFormatELF() &&
7065f757f3fSDimitry Andric       getOptLevel() != CodeGenOptLevel::None)
7070b57cec5SDimitry Andric     addPass(createAArch64CleanupLocalDynamicTLSPass());
7080b57cec5SDimitry Andric 
7090b57cec5SDimitry Andric   return false;
7100b57cec5SDimitry Andric }
7110b57cec5SDimitry Andric 
addIRTranslator()7120b57cec5SDimitry Andric bool AArch64PassConfig::addIRTranslator() {
713e8d8bef9SDimitry Andric   addPass(new IRTranslator(getOptLevel()));
7140b57cec5SDimitry Andric   return false;
7150b57cec5SDimitry Andric }
7160b57cec5SDimitry Andric 
addPreLegalizeMachineIR()7170b57cec5SDimitry Andric void AArch64PassConfig::addPreLegalizeMachineIR() {
7185f757f3fSDimitry Andric   if (getOptLevel() == CodeGenOptLevel::None) {
719fe6060f1SDimitry Andric     addPass(createAArch64O0PreLegalizerCombiner());
72006c3fb27SDimitry Andric     addPass(new Localizer());
72106c3fb27SDimitry Andric   } else {
722fe6060f1SDimitry Andric     addPass(createAArch64PreLegalizerCombiner());
72306c3fb27SDimitry Andric     addPass(new Localizer());
724349cc55cSDimitry Andric     if (EnableGISelLoadStoreOptPreLegal)
725349cc55cSDimitry Andric       addPass(new LoadStoreOpt());
726349cc55cSDimitry Andric   }
7270b57cec5SDimitry Andric }
7280b57cec5SDimitry Andric 
addLegalizeMachineIR()7290b57cec5SDimitry Andric bool AArch64PassConfig::addLegalizeMachineIR() {
7300b57cec5SDimitry Andric   addPass(new Legalizer());
7310b57cec5SDimitry Andric   return false;
7320b57cec5SDimitry Andric }
7330b57cec5SDimitry Andric 
addPreRegBankSelect()7345ffd83dbSDimitry Andric void AArch64PassConfig::addPreRegBankSelect() {
7355f757f3fSDimitry Andric   bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
736349cc55cSDimitry Andric   if (!IsOptNone) {
737e8d8bef9SDimitry Andric     addPass(createAArch64PostLegalizerCombiner(IsOptNone));
738349cc55cSDimitry Andric     if (EnableGISelLoadStoreOptPostLegal)
739349cc55cSDimitry Andric       addPass(new LoadStoreOpt());
740349cc55cSDimitry Andric   }
741e8d8bef9SDimitry Andric   addPass(createAArch64PostLegalizerLowering());
7425ffd83dbSDimitry Andric }
7435ffd83dbSDimitry Andric 
addRegBankSelect()7440b57cec5SDimitry Andric bool AArch64PassConfig::addRegBankSelect() {
7450b57cec5SDimitry Andric   addPass(new RegBankSelect());
7460b57cec5SDimitry Andric   return false;
7470b57cec5SDimitry Andric }
7480b57cec5SDimitry Andric 
addGlobalInstructionSelect()7490b57cec5SDimitry Andric bool AArch64PassConfig::addGlobalInstructionSelect() {
750fe6060f1SDimitry Andric   addPass(new InstructionSelect(getOptLevel()));
7515f757f3fSDimitry Andric   if (getOptLevel() != CodeGenOptLevel::None)
752e8d8bef9SDimitry Andric     addPass(createAArch64PostSelectOptimize());
7530b57cec5SDimitry Andric   return false;
7540b57cec5SDimitry Andric }
7550b57cec5SDimitry Andric 
addMachineSSAOptimization()756349cc55cSDimitry Andric void AArch64PassConfig::addMachineSSAOptimization() {
757349cc55cSDimitry Andric   // Run default MachineSSAOptimization first.
758349cc55cSDimitry Andric   TargetPassConfig::addMachineSSAOptimization();
759349cc55cSDimitry Andric 
7605f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None)
761349cc55cSDimitry Andric     addPass(createAArch64MIPeepholeOptPass());
762349cc55cSDimitry Andric }
763349cc55cSDimitry Andric 
addILPOpts()7640b57cec5SDimitry Andric bool AArch64PassConfig::addILPOpts() {
7650b57cec5SDimitry Andric   if (EnableCondOpt)
7660b57cec5SDimitry Andric     addPass(createAArch64ConditionOptimizerPass());
7670b57cec5SDimitry Andric   if (EnableCCMP)
7680b57cec5SDimitry Andric     addPass(createAArch64ConditionalCompares());
7690b57cec5SDimitry Andric   if (EnableMCR)
7700b57cec5SDimitry Andric     addPass(&MachineCombinerID);
7710b57cec5SDimitry Andric   if (EnableCondBrTuning)
7720b57cec5SDimitry Andric     addPass(createAArch64CondBrTuning());
7730b57cec5SDimitry Andric   if (EnableEarlyIfConversion)
7740b57cec5SDimitry Andric     addPass(&EarlyIfConverterID);
7750b57cec5SDimitry Andric   if (EnableStPairSuppress)
7760b57cec5SDimitry Andric     addPass(createAArch64StorePairSuppressPass());
7770b57cec5SDimitry Andric   addPass(createAArch64SIMDInstrOptPass());
7785f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None)
7798bcb0991SDimitry Andric     addPass(createAArch64StackTaggingPreRAPass());
7800b57cec5SDimitry Andric   return true;
7810b57cec5SDimitry Andric }
7820b57cec5SDimitry Andric 
addPreRegAlloc()7830b57cec5SDimitry Andric void AArch64PassConfig::addPreRegAlloc() {
7840b57cec5SDimitry Andric   // Change dead register definitions to refer to the zero register.
7855f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None &&
7865f757f3fSDimitry Andric       EnableDeadRegisterElimination)
7870b57cec5SDimitry Andric     addPass(createAArch64DeadRegisterDefinitions());
7880b57cec5SDimitry Andric 
7890b57cec5SDimitry Andric   // Use AdvSIMD scalar instructions whenever profitable.
7905f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None && EnableAdvSIMDScalar) {
7910b57cec5SDimitry Andric     addPass(createAArch64AdvSIMDScalar());
7920b57cec5SDimitry Andric     // The AdvSIMD pass may produce copies that can be rewritten to
793480093f4SDimitry Andric     // be register coalescer friendly.
7940b57cec5SDimitry Andric     addPass(&PeepholeOptimizerID);
7950b57cec5SDimitry Andric   }
796*0fca6ea1SDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None && EnableMachinePipeliner)
797*0fca6ea1SDimitry Andric     addPass(&MachinePipelinerID);
7980b57cec5SDimitry Andric }
7990b57cec5SDimitry Andric 
addPostRegAlloc()8000b57cec5SDimitry Andric void AArch64PassConfig::addPostRegAlloc() {
8010b57cec5SDimitry Andric   // Remove redundant copy instructions.
8025f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None &&
8035f757f3fSDimitry Andric       EnableRedundantCopyElimination)
8040b57cec5SDimitry Andric     addPass(createAArch64RedundantCopyEliminationPass());
8050b57cec5SDimitry Andric 
8065f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None && usingDefaultRegAlloc())
8070b57cec5SDimitry Andric     // Improve performance for some FP/SIMD code for A57.
8080b57cec5SDimitry Andric     addPass(createAArch64A57FPLoadBalancing());
8090b57cec5SDimitry Andric }
8100b57cec5SDimitry Andric 
addPreSched2()8110b57cec5SDimitry Andric void AArch64PassConfig::addPreSched2() {
812fe6060f1SDimitry Andric   // Lower homogeneous frame instructions
813fe6060f1SDimitry Andric   if (EnableHomogeneousPrologEpilog)
814fe6060f1SDimitry Andric     addPass(createAArch64LowerHomogeneousPrologEpilogPass());
8150b57cec5SDimitry Andric   // Expand some pseudo instructions to allow proper scheduling.
8160b57cec5SDimitry Andric   addPass(createAArch64ExpandPseudoPass());
8170b57cec5SDimitry Andric   // Use load/store pair instructions when possible.
8185f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None) {
8190b57cec5SDimitry Andric     if (EnableLoadStoreOpt)
8200b57cec5SDimitry Andric       addPass(createAArch64LoadStoreOptimizationPass());
8210b57cec5SDimitry Andric   }
822bdd1243dSDimitry Andric   // Emit KCFI checks for indirect calls.
82306c3fb27SDimitry Andric   addPass(createKCFIPass());
8240b57cec5SDimitry Andric 
8250b57cec5SDimitry Andric   // The AArch64SpeculationHardeningPass destroys dominator tree and natural
8260b57cec5SDimitry Andric   // loop info, which is needed for the FalkorHWPFFixPass and also later on.
8270b57cec5SDimitry Andric   // Therefore, run the AArch64SpeculationHardeningPass before the
8280b57cec5SDimitry Andric   // FalkorHWPFFixPass to avoid recomputing dominator tree and natural loop
8290b57cec5SDimitry Andric   // info.
8300b57cec5SDimitry Andric   addPass(createAArch64SpeculationHardeningPass());
8310b57cec5SDimitry Andric 
8325f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None) {
8330b57cec5SDimitry Andric     if (EnableFalkorHWPFFix)
8340b57cec5SDimitry Andric       addPass(createFalkorHWPFFixPass());
8350b57cec5SDimitry Andric   }
8360b57cec5SDimitry Andric }
8370b57cec5SDimitry Andric 
addPreEmitPass()8380b57cec5SDimitry Andric void AArch64PassConfig::addPreEmitPass() {
8390b57cec5SDimitry Andric   // Machine Block Placement might have created new opportunities when run
8400b57cec5SDimitry Andric   // at O3, where the Tail Duplication Threshold is set to 4 instructions.
8410b57cec5SDimitry Andric   // Run the load/store optimizer once more.
8425f757f3fSDimitry Andric   if (TM->getOptLevel() >= CodeGenOptLevel::Aggressive && EnableLoadStoreOpt)
8430b57cec5SDimitry Andric     addPass(createAArch64LoadStoreOptimizationPass());
8440b57cec5SDimitry Andric 
8455f757f3fSDimitry Andric   if (TM->getOptLevel() >= CodeGenOptLevel::Aggressive &&
84681ad6265SDimitry Andric       EnableAArch64CopyPropagation)
84781ad6265SDimitry Andric     addPass(createMachineCopyPropagationPass(true));
84881ad6265SDimitry Andric 
8490b57cec5SDimitry Andric   addPass(createAArch64A53Fix835769());
850480093f4SDimitry Andric 
851fe6060f1SDimitry Andric   if (TM->getTargetTriple().isOSWindows()) {
852480093f4SDimitry Andric     // Identify valid longjmp targets for Windows Control Flow Guard.
853480093f4SDimitry Andric     addPass(createCFGuardLongjmpPass());
854fe6060f1SDimitry Andric     // Identify valid eh continuation targets for Windows EHCont Guard.
855fe6060f1SDimitry Andric     addPass(createEHContGuardCatchretPass());
856fe6060f1SDimitry Andric   }
8570b57cec5SDimitry Andric 
8585f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None && EnableCollectLOH &&
8590b57cec5SDimitry Andric       TM->getTargetTriple().isOSBinFormatMachO())
8600b57cec5SDimitry Andric     addPass(createAArch64CollectLOHPass());
861fe6060f1SDimitry Andric }
8625ffd83dbSDimitry Andric 
addPostBBSections()86306c3fb27SDimitry Andric void AArch64PassConfig::addPostBBSections() {
864*0fca6ea1SDimitry Andric   addPass(createAArch64SLSHardeningPass());
8655f757f3fSDimitry Andric   addPass(createAArch64PointerAuthPass());
8665f757f3fSDimitry Andric   if (EnableBranchTargets)
8675f757f3fSDimitry Andric     addPass(createAArch64BranchTargetsPass());
86806c3fb27SDimitry Andric   // Relax conditional branch instructions if they're otherwise out of
86906c3fb27SDimitry Andric   // range of their destination.
87006c3fb27SDimitry Andric   if (BranchRelaxation)
87106c3fb27SDimitry Andric     addPass(&BranchRelaxationPassID);
87206c3fb27SDimitry Andric 
8735f757f3fSDimitry Andric   if (TM->getOptLevel() != CodeGenOptLevel::None && EnableCompressJumpTables)
87406c3fb27SDimitry Andric     addPass(createAArch64CompressJumpTablesPass());
87506c3fb27SDimitry Andric }
87606c3fb27SDimitry Andric 
addPreEmitPass2()877fe6060f1SDimitry Andric void AArch64PassConfig::addPreEmitPass2() {
878fe6060f1SDimitry Andric   // SVE bundles move prefixes with destructive operations. BLR_RVMARKER pseudo
879fe6060f1SDimitry Andric   // instructions are lowered to bundles as well.
8805ffd83dbSDimitry Andric   addPass(createUnpackMachineBundles(nullptr));
8815ffd83dbSDimitry Andric }
8825ffd83dbSDimitry Andric 
addRegAssignAndRewriteOptimized()883*0fca6ea1SDimitry Andric bool AArch64PassConfig::addRegAssignAndRewriteOptimized() {
884*0fca6ea1SDimitry Andric   addPass(createAArch64PostCoalescerPass());
885*0fca6ea1SDimitry Andric   return TargetPassConfig::addRegAssignAndRewriteOptimized();
886*0fca6ea1SDimitry Andric }
887*0fca6ea1SDimitry Andric 
createMachineFunctionInfo(BumpPtrAllocator & Allocator,const Function & F,const TargetSubtargetInfo * STI) const888bdd1243dSDimitry Andric MachineFunctionInfo *AArch64TargetMachine::createMachineFunctionInfo(
889bdd1243dSDimitry Andric     BumpPtrAllocator &Allocator, const Function &F,
890bdd1243dSDimitry Andric     const TargetSubtargetInfo *STI) const {
891bdd1243dSDimitry Andric   return AArch64FunctionInfo::create<AArch64FunctionInfo>(
892bdd1243dSDimitry Andric       Allocator, F, static_cast<const AArch64Subtarget *>(STI));
893bdd1243dSDimitry Andric }
894bdd1243dSDimitry Andric 
8955ffd83dbSDimitry Andric yaml::MachineFunctionInfo *
createDefaultFuncInfoYAML() const8965ffd83dbSDimitry Andric AArch64TargetMachine::createDefaultFuncInfoYAML() const {
8975ffd83dbSDimitry Andric   return new yaml::AArch64FunctionInfo();
8985ffd83dbSDimitry Andric }
8995ffd83dbSDimitry Andric 
9005ffd83dbSDimitry Andric yaml::MachineFunctionInfo *
convertFuncInfoToYAML(const MachineFunction & MF) const9015ffd83dbSDimitry Andric AArch64TargetMachine::convertFuncInfoToYAML(const MachineFunction &MF) const {
9025ffd83dbSDimitry Andric   const auto *MFI = MF.getInfo<AArch64FunctionInfo>();
9035ffd83dbSDimitry Andric   return new yaml::AArch64FunctionInfo(*MFI);
9045ffd83dbSDimitry Andric }
9055ffd83dbSDimitry Andric 
parseMachineFunctionInfo(const yaml::MachineFunctionInfo & MFI,PerFunctionMIParsingState & PFS,SMDiagnostic & Error,SMRange & SourceRange) const9065ffd83dbSDimitry Andric bool AArch64TargetMachine::parseMachineFunctionInfo(
9075ffd83dbSDimitry Andric     const yaml::MachineFunctionInfo &MFI, PerFunctionMIParsingState &PFS,
9085ffd83dbSDimitry Andric     SMDiagnostic &Error, SMRange &SourceRange) const {
90981ad6265SDimitry Andric   const auto &YamlMFI = static_cast<const yaml::AArch64FunctionInfo &>(MFI);
9105ffd83dbSDimitry Andric   MachineFunction &MF = PFS.MF;
9115ffd83dbSDimitry Andric   MF.getInfo<AArch64FunctionInfo>()->initializeBaseYamlFields(YamlMFI);
9125ffd83dbSDimitry Andric   return false;
9130b57cec5SDimitry Andric }
914