44 "riscv-enable-copyelim",
51 cl::desc(
"Enable the global merge pass"));
55 cl::desc(
"Enable the machine combiner pass"),
59 "riscv-v-vector-bits-max",
60 cl::desc(
"Assume V extension vector registers are at most this big, "
61 "with zero meaning no maximum size is assumed."),
65 "riscv-v-vector-bits-min",
66 cl::desc(
"Assume V extension vector registers are at least this big, "
67 "with zero meaning no minimum size is assumed. A value of -1 "
68 "means use Zvl*b extension. This is primarily used to enable "
69 "autovectorization with fixed width vectors."),
73 "riscv-enable-copy-propagation",
74 cl::desc(
"Enable the copy propagation with RISC-V copy instr"),
79 cl::desc(
"Enable the pass that removes dead"
80 " definitons and replaces stores to"
81 " them with stores to x0"),
86 cl::desc(
"Enable sinking and folding of instruction copies"),
91 cl::desc(
"Enable the loop data prefetch pass"),
96 cl::desc(
"Enable load clustering in the machine scheduler"),
130 if (TT.isArch64Bit()) {
131 if (ABIName ==
"lp64e")
132 return "e-m:e-p:64:64-i64:64-i128:128-n32:64-S64";
134 return "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128";
136 assert(TT.isArch32Bit() &&
"only RV32 and RV64 are currently supported");
138 if (ABIName ==
"ilp32e")
139 return "e-m:e-p:32:32-i64:64-n32-S32";
141 return "e-m:e-p:32:32-i64:64-n32-S128";
145 std::optional<Reloc::Model> RM) {
152 std::optional<Reloc::Model> RM,
153 std::optional<CodeModel::Model> CM,
165 if (TT.isOSFuchsia() && !TT.isArch64Bit())
171 Attribute CPUAttr =
F.getFnAttribute(
"target-cpu");
172 Attribute TuneAttr =
F.getFnAttribute(
"tune-cpu");
173 Attribute FSAttr =
F.getFnAttribute(
"target-features");
177 std::string TuneCPU =
185 Attribute VScaleRangeAttr =
F.getFnAttribute(Attribute::VScaleRange);
186 if (VScaleRangeAttr.
isValid()) {
194 if (RVVBitsMin != -1U) {
196 assert((RVVBitsMin == 0 || (RVVBitsMin >= 64 && RVVBitsMin <= 65536 &&
198 "V or Zve* extension requires vector length to be in the range of "
199 "64 to 65536 and a power 2!");
200 assert((RVVBitsMax >= RVVBitsMin || RVVBitsMax == 0) &&
201 "Minimum V extension vector length should not be larger than its "
204 assert((RVVBitsMax == 0 || (RVVBitsMax >= 64 && RVVBitsMax <= 65536 &&
206 "V or Zve* extension requires vector length to be in the range of "
207 "64 to 65536 and a power 2!");
209 if (RVVBitsMin != -1U) {
210 if (RVVBitsMax != 0) {
211 RVVBitsMin = std::min(RVVBitsMin, RVVBitsMax);
212 RVVBitsMax = std::max(RVVBitsMin, RVVBitsMax);
216 (RVVBitsMin < 64 || RVVBitsMin > 65536) ? 0 : RVVBitsMin);
219 llvm::bit_floor((RVVBitsMax < 64 || RVVBitsMax > 65536) ? 0 : RVVBitsMax);
223 << CPU << TuneCPU << FS;
224 auto &
I = SubtargetMap[Key];
231 if (
const MDString *ModuleTargetABI = dyn_cast_or_null<MDString>(
232 F.getParent()->getModuleFlag(
"target-abi"))) {
235 ModuleTargetABI->getString() != ABIName) {
238 ABIName = ModuleTargetABI->getString();
240 I = std::make_unique<RISCVSubtarget>(
241 TargetTriple, CPU, TuneCPU, FS, ABIName, RVVBitsMin, RVVBitsMax, *
this);
249 return RISCVMachineFunctionInfo::create<RISCVMachineFunctionInfo>(
Allocator,
263 unsigned DstAS)
const {
287static cl::opt<RVVRegisterRegAlloc::FunctionPassCtor,
false,
291 cl::desc(
"Register allocator to use for RVV register."));
293static void initializeDefaultRVVRegisterAllocatorOnce() {
298 RVVRegisterRegAlloc::setDefault(RVVRegAlloc);
306static FunctionPass *createGreedyRVVRegisterAllocator() {
314static RVVRegisterRegAlloc basicRegAllocRVVReg(
"basic",
315 "basic register allocator",
316 createBasicRVVRegisterAllocator);
317static RVVRegisterRegAlloc
318 greedyRegAllocRVVReg(
"greedy",
"greedy register allocator",
319 createGreedyRVVRegisterAllocator);
321static RVVRegisterRegAlloc fastRegAllocRVVReg(
"fast",
"fast register allocator",
322 createFastRVVRegisterAllocator);
328 if (
TM.getOptLevel() != CodeGenOptLevel::None)
334 return getTM<RISCVTargetMachine>();
343 DAG->
TII, DAG->
TRI,
true));
348 void addIRPasses()
override;
349 bool addPreISel()
override;
350 void addCodeGenPrepare()
override;
351 bool addInstSelector()
override;
352 bool addIRTranslator()
override;
353 void addPreLegalizeMachineIR()
override;
354 bool addLegalizeMachineIR()
override;
355 void addPreRegBankSelect()
override;
356 bool addRegBankSelect()
override;
357 bool addGlobalInstructionSelect()
override;
358 void addPreEmitPass()
override;
359 void addPreEmitPass2()
override;
360 void addPreSched2()
override;
361 void addMachineSSAOptimization()
override;
363 bool addRegAssignAndRewriteFast()
override;
364 bool addRegAssignAndRewriteOptimized()
override;
365 void addPreRegAlloc()
override;
366 void addPostRegAlloc()
override;
367 void addFastRegAlloc()
override;
372 return new RISCVPassConfig(*
this, PM);
375FunctionPass *RISCVPassConfig::createRVVRegAllocPass(
bool Optimized) {
378 initializeDefaultRVVRegisterAllocatorOnce);
385 return createGreedyRVVRegisterAllocator();
387 return createFastRVVRegisterAllocator();
390bool RISCVPassConfig::addRegAssignAndRewriteFast() {
391 addPass(createRVVRegAllocPass(
false));
399bool RISCVPassConfig::addRegAssignAndRewriteOptimized() {
400 addPass(createRVVRegAllocPass(
true));
409void RISCVPassConfig::addIRPasses() {
424bool RISCVPassConfig::addPreISel() {
441void RISCVPassConfig::addCodeGenPrepare() {
447bool RISCVPassConfig::addInstSelector() {
453bool RISCVPassConfig::addIRTranslator() {
458void RISCVPassConfig::addPreLegalizeMachineIR() {
466bool RISCVPassConfig::addLegalizeMachineIR() {
471void RISCVPassConfig::addPreRegBankSelect() {
476bool RISCVPassConfig::addRegBankSelect() {
481bool RISCVPassConfig::addGlobalInstructionSelect() {
486void RISCVPassConfig::addPreSched2() {
493void RISCVPassConfig::addPreEmitPass() {
507void RISCVPassConfig::addPreEmitPass2() {
527void RISCVPassConfig::addMachineSSAOptimization() {
535 if (
TM->getTargetTriple().isRISCV64()) {
540void RISCVPassConfig::addPreRegAlloc() {
549void RISCVPassConfig::addFastRegAlloc() {
555void RISCVPassConfig::addPostRegAlloc() {
575 const auto &YamlMFI =
static cl::opt< bool > EnableSinkFold("aarch64-enable-sink-fold", cl::desc("Enable sinking and folding of instruction copies"), cl::init(true), cl::Hidden)
static cl::opt< bool > EnableRedundantCopyElimination("aarch64-enable-copyelim", cl::desc("Enable the redundant copy elimination pass"), cl::init(true), cl::Hidden)
static cl::opt< bool > EnableLoopDataPrefetch("aarch64-enable-loop-data-prefetch", cl::Hidden, cl::desc("Enable the loop data prefetch pass"), cl::init(true))
static const Function * getParent(const Value *V)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_EXTERNAL_VISIBILITY
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static cl::opt< bool > EnableGlobalMerge("enable-global-merge", cl::Hidden, cl::desc("Enable the global merge pass"), cl::init(true))
This file declares the IRTranslator pass.
static std::string computeDataLayout()
unsigned const TargetRegisterInfo * TRI
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
const char LLVMTargetMachineRef TM
static cl::opt< bool > EnableRedundantCopyElimination("riscv-enable-copyelim", cl::desc("Enable the redundant copy elimination pass"), cl::init(true), cl::Hidden)
static cl::opt< bool > EnableSinkFold("riscv-enable-sink-fold", cl::desc("Enable sinking and folding of instruction copies"), cl::init(true), cl::Hidden)
static cl::opt< bool > EnableLoopDataPrefetch("riscv-enable-loop-data-prefetch", cl::Hidden, cl::desc("Enable the loop data prefetch pass"), cl::init(true))
static cl::opt< unsigned > RVVVectorBitsMaxOpt("riscv-v-vector-bits-max", cl::desc("Assume V extension vector registers are at most this big, " "with zero meaning no maximum size is assumed."), cl::init(0), cl::Hidden)
static cl::opt< cl::boolOrDefault > EnableGlobalMerge("riscv-enable-global-merge", cl::Hidden, cl::desc("Enable the global merge pass"))
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTarget()
static cl::opt< bool > EnableRISCVCopyPropagation("riscv-enable-copy-propagation", cl::desc("Enable the copy propagation with RISC-V copy instr"), cl::init(true), cl::Hidden)
static cl::opt< int > RVVVectorBitsMinOpt("riscv-v-vector-bits-min", cl::desc("Assume V extension vector registers are at least this big, " "with zero meaning no minimum size is assumed. A value of -1 " "means use Zvl*b extension. This is primarily used to enable " "autovectorization with fixed width vectors."), cl::init(-1), cl::Hidden)
static Reloc::Model getEffectiveRelocModel(const Triple &TT, std::optional< Reloc::Model > RM)
static cl::opt< bool > EnableRISCVDeadRegisterElimination("riscv-enable-dead-defs", cl::Hidden, cl::desc("Enable the pass that removes dead" " definitons and replaces stores to" " them with stores to x0"), cl::init(true))
static cl::opt< bool > EnableMachineCombiner("riscv-enable-machine-combiner", cl::desc("Enable the machine combiner pass"), cl::init(true), cl::Hidden)
static cl::opt< bool > EnableMISchedLoadClustering("riscv-misched-load-clustering", cl::Hidden, cl::desc("Enable load clustering in the machine scheduler"), cl::init(false))
This file describes the interface of the MachineFunctionPass responsible for assigning the generic vi...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static FunctionPass * useDefaultRegisterAllocator()
-regalloc=... command line option.
Target-Independent Code Generator Pass Configuration Options pass.
std::optional< unsigned > getVScaleRangeMax() const
Returns the maximum value for the vscale_range attribute or std::nullopt when unknown.
unsigned getVScaleRangeMin() const
Returns the minimum value for the vscale_range attribute.
StringRef getValueAsString() const
Return the attribute's value as a string.
bool isValid() const
Return true if the attribute is any kind of attribute.
Allocate memory in an ever growing pool, as if by bump-pointer.
Lightweight error class with error context and mandatory checking.
FunctionPass class - This class is used to implement most global optimizations.
This pass is responsible for selecting generic machine instructions to target-specific instructions.
This class describes a target machine that is implemented with the LLVM target-independent code gener...
StringRef getABIName() const
getABIName - If this returns a non-empty string this represents the textual name of the ABI that we w...
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This implementation is used for RISC-V ELF targets.
RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo and contains private RISCV-...
yaml::MachineFunctionInfo * createDefaultFuncInfoYAML() const override
Allocate and return a default initialized instance of the YAML representation for the MachineFunction...
RISCVTargetMachine(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)
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DstAS) const override
Returns true if a cast between SrcAS and DestAS is a noop.
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
yaml::MachineFunctionInfo * convertFuncInfoToYAML(const MachineFunction &MF) const override
Allocate and initialize an instance of the YAML representation of the MachineFunctionInfo.
bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange) const override
Parse out the target's MachineFunctionInfo from the YAML reprsentation.
const RISCVSubtarget * getSubtargetImpl() const =delete
This pass implements the reg bank selector pass used in the GlobalISel pipeline.
RegisterPassParser class - Handle the addition of new machine passes.
RegisterRegAllocBase class - Track the registration of register allocators.
FunctionPass *(*)() FunctionPassCtor
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Represents a range in source code.
A ScheduleDAG for scheduling lists of MachineInstr.
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
void addMutation(std::unique_ptr< ScheduleDAGMutation > Mutation)
Add a postprocessing step to the DAG builder.
const TargetInstrInfo * TII
Target instruction information.
const TargetRegisterInfo * TRI
Target processor register info.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
void setMachineOutliner(bool Enable)
void setSupportsDefaultOutlining(bool Enable)
std::unique_ptr< const MCSubtargetInfo > STI
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
MCTargetOptions MCOptions
Machine level options.
Target-Independent Code Generator Pass Configuration Options.
virtual void addCodeGenPrepare()
Add pass to prepare the LLVM IR for code generation.
virtual bool addRegAssignAndRewriteFast()
Add core register allocator passes which do the actual register assignment and rewriting.
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
virtual void addFastRegAlloc()
addFastRegAlloc - Add the minimum set of target-independent passes that are required for fast registe...
virtual void addMachineSSAOptimization()
addMachineSSAOptimization - Add standard passes that optimize machine instructions in SSA form.
virtual bool addRegAssignAndRewriteOptimized()
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
A raw_ostream that writes to an SmallVector or SmallString.
@ C
The default llvm calling convention, compatible with C.
ABI getTargetABI(StringRef ABIName)
static constexpr unsigned RVVBitsPerBlock
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createFastRegisterAllocator()
FastRegisterAllocation Pass - This pass register allocates as fast as possible.
FunctionPass * createRISCVPostLegalizerCombiner()
void initializeRISCVPushPopOptPass(PassRegistry &)
void initializeRISCVExpandPseudoPass(PassRegistry &)
void initializeRISCVFoldMasksPass(PassRegistry &)
FunctionPass * createRISCVMoveMergePass()
createRISCVMoveMergePass - returns an instance of the move merge pass.
FunctionPass * createTypePromotionLegacyPass()
Create IR Type Promotion pass.
void initializeRISCVDeadRegisterDefinitionsPass(PassRegistry &)
FunctionPass * createGreedyRegisterAllocator()
Greedy register allocation pass - This pass implements a global register allocator for optimized buil...
void initializeRISCVPreLegalizerCombinerPass(PassRegistry &)
FunctionPass * createRISCVExpandAtomicPseudoPass()
FunctionPass * createRISCVPostRAExpandPseudoPass()
FunctionPass * createRISCVInsertReadWriteCSRPass()
Target & getTheRISCV32Target()
void initializeRISCVInsertVSETVLIPass(PassRegistry &)
char & PostRASchedulerID
PostRAScheduler - This pass performs post register allocation scheduling.
FunctionPass * createRISCVDeadRegisterDefinitionsPass()
char & PostMachineSchedulerID
PostMachineScheduler - This pass schedules machine instructions postRA.
ScheduleDAGMILive * createGenericSchedLive(MachineSchedContext *C)
Create the standard converging machine scheduler.
FunctionPass * createRISCVGatherScatterLoweringPass()
FunctionPass * createRISCVMergeBaseOffsetOptPass()
Returns an instance of the Merge Base Offset Optimization pass.
void initializeRISCVDAGToDAGISelPass(PassRegistry &)
char & MachineCombinerID
This pass performs instruction combining using trace metrics to estimate critical-path and resource d...
void initializeRISCVPostRAExpandPseudoPass(PassRegistry &)
CodeModel::Model getEffectiveCodeModel(std::optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
FunctionPass * createRISCVPreLegalizerCombiner()
char & BranchRelaxationPassID
BranchRelaxation - This pass replaces branches that need to jump further than is supported by a branc...
FunctionPass * createRISCVO0PreLegalizerCombiner()
FunctionPass * createRISCVPushPopOptimizationPass()
createRISCVPushPopOptimizationPass - returns an instance of the Push/Pop optimization pass.
FunctionPass * createRISCVMakeCompressibleOptPass()
Returns an instance of the Make Compressible Optimization pass.
FunctionPass * createRISCVRedundantCopyEliminationPass()
FunctionPass * createKCFIPass()
Lowers KCFI operand bundles for indirect calls.
Pass * createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset, bool OnlyOptimizeForSize=false, bool MergeExternalByDefault=false)
GlobalMerge - This pass merges internal (by default) globals into structs to enable reuse of a base p...
void initializeRISCVInsertWriteVXRMPass(PassRegistry &)
FunctionPass * createRISCVFoldMasksPass()
FunctionPass * createLoopDataPrefetchPass()
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
void initializeRISCVInsertReadWriteCSRPass(PassRegistry &)
FunctionPass * createRISCVInsertVSETVLIPass()
Returns an instance of the Insert VSETVLI pass.
CodeGenOptLevel
Code generation optimization level.
void initializeRISCVCoalesceVSETVLIPass(PassRegistry &)
FunctionPass * createRISCVOptWInstrsPass()
FunctionPass * createInterleavedAccessPass()
InterleavedAccess Pass - This pass identifies and matches interleaved memory accesses to target speci...
FunctionPass * createBasicRegisterAllocator()
BasicRegisterAllocation Pass - This pass implements a degenerate global register allocator using the ...
void initializeGlobalISel(PassRegistry &)
Initialize all passes linked into the GlobalISel library.
void initializeRISCVMakeCompressibleOptPass(PassRegistry &)
FunctionPass * createRISCVCodeGenPreparePass()
ModulePass * createBarrierNoopPass()
createBarrierNoopPass - This pass is purely a module pass barrier in a pass manager.
std::unique_ptr< ScheduleDAGMutation > createLoadClusterDAGMutation(const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
void initializeRISCVOptWInstrsPass(PassRegistry &)
FunctionPass * createUnpackMachineBundles(std::function< bool(const MachineFunction &)> Ftor)
void initializeRISCVCodeGenPreparePass(PassRegistry &)
Target & getTheRISCV64Target()
void call_once(once_flag &flag, Function &&F, Args &&... ArgList)
Execute the function specified as a parameter once.
void initializeRISCVO0PreLegalizerCombinerPass(PassRegistry &)
void initializeKCFIPass(PassRegistry &)
void initializeRISCVMergeBaseOffsetOptPass(PassRegistry &)
FunctionPass * createRISCVISelDag(RISCVTargetMachine &TM, CodeGenOptLevel OptLevel)
FunctionPass * createVirtRegRewriter(bool ClearVirtRegs=true)
void initializeRISCVGatherScatterLoweringPass(PassRegistry &)
FunctionPass * createRISCVExpandPseudoPass()
FunctionPass * createRISCVPreRAExpandPseudoPass()
FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
FunctionPass * createRISCVCoalesceVSETVLIPass()
FunctionPass * createRISCVInsertWriteVXRMPass()
MachineFunctionPass * createMachineCopyPropagationPass(bool UseCopyInstr)
void initializeRISCVPreRAExpandPseudoPass(PassRegistry &)
void initializeRISCVPostLegalizerCombinerPass(PassRegistry &)
void initializeRISCVMoveMergePass(PassRegistry &)
Implement std::hash so that hash_code can be used in STL containers.
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
static bool isRVVRegClass(const TargetRegisterClass *RC)
RegisterTargetMachine - Helper template for registering a target machine implementation,...
The llvm::once_flag structure.
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.