LLVM 24.0.0git
RISCVTargetMachine.cpp
Go to the documentation of this file.
1//===-- RISCVTargetMachine.cpp - Define TargetMachine for RISC-V ----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Implements the info about RISC-V target spec.
10//
11//===----------------------------------------------------------------------===//
12
13#include "RISCVTargetMachine.h"
14#include "RISCV.h"
30#include "llvm/CodeGen/Passes.h"
39#include "llvm/Transforms/IPO.h"
41#include <optional>
42using namespace llvm;
43
85}
86
88 std::optional<Reloc::Model> RM) {
89 if (TT.isOSBinFormatMachO())
90 return RM.value_or(Reloc::PIC_);
91
92 return RM.value_or(Reloc::Static);
93}
94
95static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
96 if (TT.isOSBinFormatMachO())
97 return std::make_unique<RISCVMachOTargetObjectFile>();
98 return std::make_unique<RISCVELFTargetObjectFile>();
99}
100
102 StringRef CPU, StringRef FS,
103 const TargetOptions &Options,
104 std::optional<Reloc::Model> RM,
105 std::optional<CodeModel::Model> CM,
106 CodeGenOptLevel OL, bool JIT)
107 : CodeGenTargetMachineImpl(T, TT, CPU, FS, Options,
109 getEffectiveCodeModel(CM, CodeModel::Small), OL),
110 CLOpts(cl::LibraryOptionsContext::get<RISCVOptions>(
111 Options.MCOptions.LibraryOptions)),
112 TLOF(createTLOF(TT)) {
113 initAsmInfo();
114
115 // RISC-V supports the MachineOutliner.
116 setMachineOutliner(true);
118
119 // RISC-V supports the debug entry values.
121
122 if (TT.isOSFuchsia() && !TT.isArch64Bit())
123 report_fatal_error("Fuchsia is only supported for 64-bit");
124
125 setCFIFixup(!CLOpts.enable_cfi_instr_inserter);
126}
127
128const RISCVSubtarget *
130 Attribute CPUAttr = F.getFnAttribute("target-cpu");
131 Attribute TuneAttr = F.getFnAttribute("tune-cpu");
132 Attribute FSAttr = F.getFnAttribute("target-features");
133
134 std::string CPU =
135 CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
136 std::string TuneCPU =
137 TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU;
138 std::string FS =
139 FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
140
141 unsigned RVVBitsMin = CLOpts.v_vector_bits_min.value_or(-1);
142 unsigned RVVBitsMax = CLOpts.v_vector_bits_max.value_or(0);
143
144 Attribute VScaleRangeAttr = F.getFnAttribute(Attribute::VScaleRange);
145 if (VScaleRangeAttr.isValid()) {
146 if (!CLOpts.v_vector_bits_min)
147 RVVBitsMin = VScaleRangeAttr.getVScaleRangeMin() * RISCV::RVVBitsPerBlock;
148 std::optional<unsigned> VScaleMax = VScaleRangeAttr.getVScaleRangeMax();
149 if (VScaleMax.has_value() && !CLOpts.v_vector_bits_max)
150 RVVBitsMax = *VScaleMax * RISCV::RVVBitsPerBlock;
151 }
152
153 if (RVVBitsMin != -1U) {
154 // FIXME: Change to >= 32 when VLEN = 32 is supported.
155 assert((RVVBitsMin == 0 || (RVVBitsMin >= 64 && RVVBitsMin <= 65536 &&
156 isPowerOf2_32(RVVBitsMin))) &&
157 "V or Zve* extension requires vector length to be in the range of "
158 "64 to 65536 and a power 2!");
159 assert((RVVBitsMax >= RVVBitsMin || RVVBitsMax == 0) &&
160 "Minimum V extension vector length should not be larger than its "
161 "maximum!");
162 }
163 assert((RVVBitsMax == 0 || (RVVBitsMax >= 64 && RVVBitsMax <= 65536 &&
164 isPowerOf2_32(RVVBitsMax))) &&
165 "V or Zve* extension requires vector length to be in the range of "
166 "64 to 65536 and a power 2!");
167
168 if (RVVBitsMin != -1U) {
169 if (RVVBitsMax != 0) {
170 RVVBitsMin = std::min(RVVBitsMin, RVVBitsMax);
171 RVVBitsMax = std::max(RVVBitsMin, RVVBitsMax);
172 }
173
174 RVVBitsMin = llvm::bit_floor(
175 (RVVBitsMin < 64 || RVVBitsMin > 65536) ? 0 : RVVBitsMin);
176 }
177 RVVBitsMax =
178 llvm::bit_floor((RVVBitsMax < 64 || RVVBitsMax > 65536) ? 0 : RVVBitsMax);
179
181 raw_svector_ostream(Key) << "RVVMin" << RVVBitsMin << "RVVMax" << RVVBitsMax
182 << CPU << TuneCPU << FS;
183 auto &I = SubtargetMap[Key];
184 if (!I) {
185 StringRef ABIName = getTargetABIName(*F.getParent());
186 I = std::make_unique<RISCVSubtarget>(
187 TargetTriple, CPU, TuneCPU, FS, ABIName, RVVBitsMin, RVVBitsMax, *this);
188 }
189 return I.get();
190}
191
198
201 return TargetTransformInfo(std::make_unique<RISCVTTIImpl>(this, F));
202}
203
204// A RISC-V hart has a single byte-addressable address space of 2^XLEN bytes
205// for all memory accesses, so it is reasonable to assume that an
206// implementation has no-op address space casts. If an implementation makes a
207// change to this, they can override it here.
209 unsigned SrcAS,
210 unsigned DstAS) const {
211 return true;
212}
213
216 const RISCVSubtarget &ST = C->MF->getSubtarget<RISCVSubtarget>();
218
219 // Add MacroFusion mutation first with a higher priority than later clustering
220 const auto &MacroFusions = ST.getMacroFusions();
221 if (!MacroFusions.empty())
222 DAG->addMutation(createMacroFusionDAGMutation(MacroFusions));
223
224 if (ST.enableMISchedLoadClustering())
225 DAG->addMutation(createLoadClusterDAGMutation(
226 DAG->TII, /*ReorderWhileClustering=*/true));
227
228 if (ST.enableMISchedStoreClustering())
229 DAG->addMutation(createStoreClusterDAGMutation(
230 DAG->TII, /*ReorderWhileClustering=*/true));
231
232 if (CLOpts.vector_mask_mutation && ST.hasVInstructions())
233 DAG->addMutation(createRISCVVectorMaskDAGMutation(DAG->TRI));
234
235 return DAG;
236}
237
240 const RISCVSubtarget &ST = C->MF->getSubtarget<RISCVSubtarget>();
242
243 // Add MacroFusion mutation first with a higher priority than later clustering
244 const auto &MacroFusions = ST.getMacroFusions();
245 if (!MacroFusions.empty())
246 DAG->addMutation(createMacroFusionDAGMutation(MacroFusions));
247
248 if (ST.enablePostMISchedLoadClustering())
249 DAG->addMutation(createLoadClusterDAGMutation(
250 DAG->TII, /*ReorderWhileClustering=*/true));
251
252 if (ST.enablePostMISchedStoreClustering())
253 DAG->addMutation(createStoreClusterDAGMutation(
254 DAG->TII, /*ReorderWhileClustering=*/true));
255
256 return DAG;
257}
258
259namespace {
260
261class RVVRegisterRegAlloc : public RegisterRegAllocBase<RVVRegisterRegAlloc> {
262public:
263 RVVRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
264 : RegisterRegAllocBase(N, D, C) {}
265};
266
267static bool onlyAllocateRVVReg(const TargetRegisterInfo &TRI,
268 const MachineRegisterInfo &MRI,
269 const Register Reg) {
270 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
272}
273
274static FunctionPass *useDefaultRegisterAllocator() { return nullptr; }
275
276static llvm::once_flag InitializeDefaultRVVRegisterAllocatorFlag;
277
278/// -riscv-rvv-regalloc=<fast|basic|greedy> command line option.
279/// This option could designate the rvv register allocator only.
280/// For example: -riscv-rvv-regalloc=basic
281static cl::opt<RVVRegisterRegAlloc::FunctionPassCtor, false,
283 RVVRegAlloc("riscv-rvv-regalloc", cl::Hidden,
285 cl::desc("Register allocator to use for RVV register."));
286
287static void initializeDefaultRVVRegisterAllocatorOnce() {
288 RegisterRegAlloc::FunctionPassCtor Ctor = RVVRegisterRegAlloc::getDefault();
289
290 if (!Ctor) {
291 Ctor = RVVRegAlloc;
292 RVVRegisterRegAlloc::setDefault(RVVRegAlloc);
293 }
294}
295
296static FunctionPass *createBasicRVVRegisterAllocator() {
297 return createBasicRegisterAllocator(onlyAllocateRVVReg);
298}
299
300static FunctionPass *createGreedyRVVRegisterAllocator() {
301 return createGreedyRegisterAllocator(onlyAllocateRVVReg);
302}
303
304static FunctionPass *createFastRVVRegisterAllocator() {
305 return createFastRegisterAllocator(onlyAllocateRVVReg, false);
306}
307
308static RVVRegisterRegAlloc basicRegAllocRVVReg("basic",
309 "basic register allocator",
310 createBasicRVVRegisterAllocator);
311static RVVRegisterRegAlloc
312 greedyRegAllocRVVReg("greedy", "greedy register allocator",
313 createGreedyRVVRegisterAllocator);
314
315static RVVRegisterRegAlloc fastRegAllocRVVReg("fast", "fast register allocator",
316 createFastRVVRegisterAllocator);
317
318class RISCVPassConfig : public TargetPassConfig {
319 const RISCVOptions &CLOpts;
320
321public:
322 RISCVPassConfig(RISCVTargetMachine &TM, PassManagerBase &PM)
323 : TargetPassConfig(TM, PM), CLOpts(TM.getCLOpts()) {
324 if (TM.getOptLevel() != CodeGenOptLevel::None)
325 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
326 setEnableSinkAndFold(CLOpts.enable_sink_fold);
327 EnableLoopTermFold = true;
328 }
329
330 RISCVTargetMachine &getRISCVTargetMachine() const {
332 }
333
334 void addIRPasses() override;
335 bool addPreISel() override;
336 void addCodeGenPrepare() override;
337 bool addInstSelector() override;
338 bool addIRTranslator() override;
339 void addPreLegalizeMachineIR() override;
340 bool addLegalizeMachineIR() override;
341 void addPreRegBankSelect() override;
342 bool addRegBankSelect() override;
343 bool addGlobalInstructionSelect() override;
344 void addPreEmitPass() override;
345 void addPreEmitPass2() override;
346 void addPreSched2() override;
347 void addMachineSSAOptimization() override;
348 FunctionPass *createRVVRegAllocPass(bool Optimized);
349 bool addRegAssignAndRewriteFast() override;
350 bool addRegAssignAndRewriteOptimized() override;
351 void addPreRegAlloc() override;
352 void addPostRegAlloc() override;
353 void addFastRegAlloc() override;
354 bool addILPOpts() override;
355
356 std::unique_ptr<CSEConfigBase> getCSEConfig() const override;
357};
358} // namespace
359
361 return new RISCVPassConfig(*this, PM);
362}
363
364std::unique_ptr<CSEConfigBase> RISCVPassConfig::getCSEConfig() const {
365 return getStandardCSEConfigForOpt(TM->getOptLevel());
366}
367
368FunctionPass *RISCVPassConfig::createRVVRegAllocPass(bool Optimized) {
369 // Initialize the global default.
370 llvm::call_once(InitializeDefaultRVVRegisterAllocatorFlag,
371 initializeDefaultRVVRegisterAllocatorOnce);
372
373 RegisterRegAlloc::FunctionPassCtor Ctor = RVVRegisterRegAlloc::getDefault();
374 if (Ctor != useDefaultRegisterAllocator)
375 return Ctor();
376
377 if (Optimized)
378 return createGreedyRVVRegisterAllocator();
379
380 return createFastRVVRegisterAllocator();
381}
382
383bool RISCVPassConfig::addRegAssignAndRewriteFast() {
384 addPass(createRVVRegAllocPass(false));
386 if (TM->getOptLevel() != CodeGenOptLevel::None && CLOpts.enable_dead_defs)
389}
390
391bool RISCVPassConfig::addRegAssignAndRewriteOptimized() {
392 addPass(createRVVRegAllocPass(true));
393 addPass(createVirtRegRewriter(false));
395 if (TM->getOptLevel() != CodeGenOptLevel::None && CLOpts.enable_dead_defs)
398}
399
400void RISCVPassConfig::addIRPasses() {
403
404 if (getOptLevel() != CodeGenOptLevel::None) {
405 if (CLOpts.enable_loop_data_prefetch)
407
411 }
412
414
415 if (getOptLevel() == CodeGenOptLevel::Aggressive && CLOpts.select_opt)
416 addPass(createSelectOptimizePass());
417}
418
419bool RISCVPassConfig::addPreISel() {
420 if (TM->getOptLevel() != CodeGenOptLevel::None)
422 if (TM->getOptLevel() != CodeGenOptLevel::None) {
423 // Add a barrier before instruction selection so that we will not get
424 // deleted block address after enabling default outlining. See D99707 for
425 // more details.
426 addPass(createBarrierNoopPass());
427 }
428
429 if (valueOr(CLOpts.enable_global_merge,
430 TM->getOptLevel() != CodeGenOptLevel::None)) {
431 // FIXME: Like AArch64, we disable extern global merging by default due to
432 // concerns it might regress some workloads. Unlike AArch64, we don't
433 // currently support enabling the pass in an "OnlyOptimizeForSize" mode.
434 // Investigating and addressing both items are TODO.
435 addPass(createGlobalMergePass(TM, /* MaxOffset */ 2047,
436 /* OnlyOptimizeForSize */ false,
437 /* MergeExternalByDefault */ true));
438 }
439
440 return false;
441}
442
443void RISCVPassConfig::addCodeGenPrepare() {
444 if (getOptLevel() != CodeGenOptLevel::None)
447}
448
449bool RISCVPassConfig::addInstSelector() {
450 addPass(createRISCVISelDagLegacyPass(getRISCVTargetMachine(), getOptLevel()));
451
452 return false;
453}
454
455bool RISCVPassConfig::addIRTranslator() {
456 addPass(new IRTranslatorLegacy(getOptLevel()));
457 return false;
458}
459
460void RISCVPassConfig::addPreLegalizeMachineIR() {
461 if (getOptLevel() == CodeGenOptLevel::None) {
463 } else {
465 }
466}
467
468bool RISCVPassConfig::addLegalizeMachineIR() {
469 addPass(new LegalizerLegacy());
470 return false;
471}
472
473void RISCVPassConfig::addPreRegBankSelect() {
474 if (getOptLevel() != CodeGenOptLevel::None)
476}
477
478bool RISCVPassConfig::addRegBankSelect() {
479 addPass(new RegBankSelectLegacy());
480 return false;
481}
482
483bool RISCVPassConfig::addGlobalInstructionSelect() {
484 addPass(new InstructionSelectLegacy(getOptLevel()));
485 return false;
486}
487
488void RISCVPassConfig::addPreSched2() {
490
491 // Emit KCFI checks for indirect calls.
492 addPass(createKCFIPass());
493 if (TM->getOptLevel() != CodeGenOptLevel::None)
495}
496
497void RISCVPassConfig::addPreEmitPass() {
498 // TODO: It would potentially be better to schedule copy propagation after
499 // expanding pseudos (in addPreEmitPass2). However, performing copy
500 // propagation after the machine outliner (which runs after addPreEmitPass)
501 // currently leads to incorrect code-gen, where copies to registers within
502 // outlined functions are removed erroneously.
503 if (TM->getOptLevel() >= CodeGenOptLevel::Default &&
504 CLOpts.enable_copy_propagation)
506 if (TM->getOptLevel() >= CodeGenOptLevel::Default)
508 // The IndirectBranchTrackingPass inserts lpad and could have changed the
509 // basic block alignment. It must be done before Branch Relaxation to
510 // prevent the adjusted offset exceeding the branch range.
512 addPass(&BranchRelaxationPassID);
514}
515
516void RISCVPassConfig::addPreEmitPass2() {
517 if (TM->getOptLevel() != CodeGenOptLevel::None) {
518 addPass(createRISCVMoveMergePass());
519 // Schedule PushPop Optimization before expansion of Pseudo instruction,
520 // ensuring return instruction is detected correctly.
522 }
524
525 // Add QC Relaxation Markers as late as possible, and only for RV32
526 if (TM->getOptLevel() != CodeGenOptLevel::None &&
527 TM->getTargetTriple().isRISCV32())
529
530 // Schedule the expansion of AMOs at the last possible moment, avoiding the
531 // possibility for other passes to break the requirements for forward
532 // progress in the LR/SC block.
534
535 // KCFI indirect call checks are lowered to a bundle.
537 return MF.getFunction().getParent()->getModuleFlag("kcfi");
538 }));
539
540 if (CLOpts.enable_cfi_instr_inserter)
542}
543
544void RISCVPassConfig::addMachineSSAOptimization() {
545 // It's beneficial to reduce the VL to enable more
546 // Machine SSA optimizations.
547 if (TM->getOptLevel() != CodeGenOptLevel::None) {
548 // RISCVVLOptimizer can make loop invariant instructions like vmv.v.i
549 // loop variant by propagating a VL defined inside the loop. Run LICM and
550 // hoist them early. Don't do this at -O0 to avoid the compile-time
551 // overhead. Not reducing the VL of loop invariant pseudos results in more
552 // vsetvli toggles, and still requires the MachineLoopInfo analysis to be
553 // run.
554 addPass(&EarlyMachineLICMID);
556 }
557
560
562
563 if (TM->getTargetTriple().isRISCV64()) {
565 }
566}
567
568void RISCVPassConfig::addPreRegAlloc() {
570 if (TM->getOptLevel() != CodeGenOptLevel::None) {
572 // Add Zilsd pre-allocation load/store optimization
574 }
575
579
580 if (TM->getOptLevel() != CodeGenOptLevel::None && CLOpts.enable_pipeliner)
581 addPass(&MachinePipelinerID);
582
584}
585
586void RISCVPassConfig::addFastRegAlloc() {
587 addPass(&InitUndefID);
589}
590
591
592void RISCVPassConfig::addPostRegAlloc() {
593 if (TM->getOptLevel() != CodeGenOptLevel::None && CLOpts.enable_copyelim)
595}
596
597bool RISCVPassConfig::addILPOpts() {
598 if (CLOpts.enable_machine_combiner)
599 addPass(&MachineCombinerID);
600
601 return true;
602}
603
608
614
617 SMDiagnostic &Error, SMRange &SourceRange) const {
618 const auto &YamlMFI =
619 static_cast<const yaml::RISCVMachineFunctionInfo &>(MFI);
620 PFS.MF.getInfo<RISCVMachineFunctionInfo>()->initializeBaseYamlFields(YamlMFI);
621 return false;
622}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static std::unique_ptr< TargetLoweringObjectFile > createTLOF(const Triple &TT)
static Reloc::Model getEffectiveRelocModel()
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Provides analysis for continuously CSEing during GISel passes.
#define LLVM_ABI
Definition Compiler.h:215
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
This file declares the IRTranslator pass.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
#define T
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTarget()
This file defines a TargetTransformInfoImplBase conforming object specific to the RISC-V target machi...
This file describes the interface of the MachineFunctionPass responsible for assigning the generic vi...
const GCNTargetMachine & getTM(const GCNSubtarget *STI)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static FunctionPass * useDefaultRegisterAllocator()
-regalloc=... command line option.
Target-Independent Code Generator Pass Configuration Options pass.
This pass exposes codegen information to IR-level passes.
static std::unique_ptr< TargetLoweringObjectFile > createTLOF()
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:106
LLVM_ABI std::optional< unsigned > getVScaleRangeMax() const
Returns the maximum value for the vscale_range attribute or std::nullopt when unknown.
LLVM_ABI unsigned getVScaleRangeMin() const
Returns the minimum value for the vscale_range attribute.
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition Attributes.h:266
CodeGenTargetMachineImpl(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOptLevel OL)
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
Module * getParent()
Get the module that this global value is contained inside of...
This pass is responsible for selecting generic machine instructions to target-specific instructions.
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...
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition Module.cpp:358
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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 ...
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
bool isNoopAddrSpaceCast(const DataLayout &DL, unsigned SrcAS, unsigned DstAS) const override
Returns true if a cast between SrcAS and DestAS is a noop.
ScheduleDAGInstrs * createMachineScheduler(MachineSchedContext *C) const override
Create an instance of ScheduleDAGInstrs to be run within the standard MachineScheduler pass for this ...
ScheduleDAGInstrs * createPostMachineScheduler(MachineSchedContext *C) const override
Similar to createMachineScheduler but used when postRA machine scheduling is enabled.
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.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition SourceMgr.h:305
Represents a range in source code.
Definition SMLoc.h:47
A ScheduleDAG for scheduling lists of MachineInstr.
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
void setSupportsDebugEntryValues(bool Enable)
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
void setMachineOutliner(bool Enable)
void setCFIFixup(bool Enable)
void setSupportsDefaultOutlining(bool Enable)
StringRef getTargetABIName(const Module &M) const
Returns the effective target ABI name: the "target-abi" module flag if present, otherwise the -target...
const DataLayout DL
DataLayout for the target: keep ABI type size and alignment.
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions 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.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
Registers T::Global with cl::ParseCommandLineOptions.
A raw_ostream that writes to an SmallVector or SmallString.
const MipsMCOptions & getCLOpts(const MCTargetOptions &Options)
static constexpr unsigned RVVBitsPerBlock
This namespace contains all of the command line option processing machinery.
Definition LLVMContext.h:35
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
ScheduleDAGMILive * createSchedLive(MachineSchedContext *C)
Create the standard converging machine scheduler.
FunctionPass * createRISCVLandingPadSetupPass()
FunctionPass * createRISCVVectorPeepholeLegacyPass()
FunctionPass * createRISCVLoadStoreOptPass()
LLVM_ABI FunctionPass * createFastRegisterAllocator()
FastRegisterAllocation Pass - This pass register allocates as fast as possible.
void initializeRISCVFoldMemOffsetLegacyPass(PassRegistry &)
LLVM_ABI char & EarlyMachineLICMID
This pass performs loop invariant code motion on machine instructions.
void initializeRISCVPushPopOptPass(PassRegistry &)
FunctionPass * createRISCVMoveMergePass()
createRISCVMoveMergePass - returns an instance of the move merge pass.
LLVM_ABI char & InitUndefID
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createMacroFusionDAGMutation(ArrayRef< MacroFusionPredTy > Predicates, bool BranchOnly=false)
Create a DAG scheduling mutation to pair instructions back to back for instructions that benefit acco...
LLVM_ABI FunctionPass * createTypePromotionLegacyPass()
Create IR Type Promotion pass.
void initializeRISCVDeadRegisterDefinitionsPass(PassRegistry &)
LLVM_ABI FunctionPass * createGreedyRegisterAllocator()
Greedy register allocation pass - This pass implements a global register allocator for optimized buil...
void initializeRISCVPreLegalizerCombinerPass(PassRegistry &)
FunctionPass * createRISCVCodeGenPrepareLegacyPass()
FunctionPass * createRISCVISelDagLegacyPass(RISCVTargetMachine &TM, CodeGenOptLevel OptLevel)
FunctionPass * createRISCVOptWInstrsLegacyPass()
LLVM_ABI FunctionPass * createSelectOptimizePass()
This pass converts conditional moves to conditional jumps when profitable.
LLVM_ABI Pass * createGlobalMergePass(const TargetMachine *TM, unsigned MaximalOffset, bool OnlyOptimizeForSize=false, bool MergeExternalByDefault=false, bool MergeConstantByDefault=false, bool MergeConstAggressiveByDefault=false)
GlobalMerge - This pass merges internal (by default) globals into structs to enable reuse of a base p...
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createLoadClusterDAGMutation(const TargetInstrInfo *TII, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
FunctionPass * createRISCVInsertReadWriteCSRPass()
Target & getTheRISCV32Target()
void initializeRISCVInsertVSETVLIPass(PassRegistry &)
FunctionPass * createRISCVGatherScatterLoweringLegacyPass()
LLVM_ABI char & PostRASchedulerID
PostRAScheduler - This pass performs post register allocation scheduling.
void initializeRISCVExpandPseudoPreEmitLegacyPass(PassRegistry &)
void initializeRISCVLateBranchOptPass(PassRegistry &)
FunctionPass * createRISCVExpandPseudoPostRALegacyPass()
FunctionPass * createRISCVExpandPseudoAtomicsLegacyPass()
void initializeRISCVRedundantCopyEliminationPass(PassRegistry &)
Target & getTheRISCV64beTarget()
FunctionPass * createRISCVZacasABIFixLegacyPass()
LLVM_ABI std::unique_ptr< CSEConfigBase > getStandardCSEConfigForOpt(CodeGenOptLevel Level)
Definition CSEInfo.cpp:85
FunctionPass * createRISCVDeadRegisterDefinitionsPass()
LLVM_ABI char & PostMachineSchedulerID
PostMachineScheduler - This pass schedules machine instructions postRA.
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createStoreClusterDAGMutation(const TargetInstrInfo *TII, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
void initializeRISCVCodeGenPrepareLegacyPass(PassRegistry &)
LLVM_ABI FunctionPass * createCFIInstrInserterLegacy()
Creates CFI Instruction Inserter pass.
FunctionPass * createRISCVMergeBaseOffsetOptPass()
Returns an instance of the Merge Base Offset Optimization pass.
FunctionPass * createRISCVPostLegalizerCombiner()
LLVM_ABI void initializeMachineKCFILegacyPass(PassRegistry &)
LLVM_ABI char & MachineCombinerID
This pass performs instruction combining using trace metrics to estimate critical-path and resource d...
LLVM_ABI FunctionPass * createUnpackMachineBundlesLegacy(std::function< bool(const MachineFunction &)> Ftor)
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM)
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.
Definition MathExtras.h:280
void initializeRISCVExpandPseudoAtomicsLegacyPass(PassRegistry &)
ScheduleDAGMI * createSchedPostRA(MachineSchedContext *C)
Create a generic scheduler with no vreg liveness or DAG mutation passes.
LLVM_ABI char & BranchRelaxationPassID
BranchRelaxation - This pass replaces branches that need to jump further than is supported by a branc...
FunctionPass * createRISCVExpandPseudoPreEmitLegacyPass()
void initializeRISCVDAGToDAGISelLegacyPass(PassRegistry &)
FunctionPass * createRISCVPreAllocZilsdOptPass()
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
FunctionPass * createRISCVPushPopOptimizationPass()
createRISCVPushPopOptimizationPass - returns an instance of the Push/Pop optimization pass.
FunctionPass * createRISCVFoldMemOffsetLegacyPass()
FunctionPass * createRISCVMakeCompressibleOptPass()
Returns an instance of the Make Compressible Optimization pass.
FunctionPass * createRISCVRedundantCopyEliminationPass()
LLVM_ABI FunctionPass * createKCFIPass()
Lowers KCFI operand bundles for indirect calls.
Definition KCFI.cpp:75
void initializeRISCVVMV0EliminationPass(PassRegistry &)
void initializeRISCVInsertWriteVXRMPass(PassRegistry &)
void initializeRISCVLoadStoreOptPass(PassRegistry &)
LLVM_ABI FunctionPass * createLoopDataPrefetchPass()
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
void initializeRISCVInsertReadWriteCSRPass(PassRegistry &)
FunctionPass * createRISCVPreLegalizerCombiner()
FunctionPass * createRISCVVMV0EliminationPass()
void initializeRISCVExpandPseudoPreRALegacyPass(PassRegistry &)
FunctionPass * createRISCVInsertVSETVLIPass()
Returns an instance of the Insert VSETVLI pass.
FunctionPass * createRISCVO0PreLegalizerCombiner()
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:227
@ Default
-O2, -Os, -Oz
Definition CodeGen.h:230
void initializeRISCVVLOptimizerLegacyPass(PassRegistry &)
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
FunctionPass * createRISCVIndirectBranchTrackingPass()
LLVM_ABI FunctionPass * createInterleavedAccessPass()
InterleavedAccess Pass - This pass identifies and matches interleaved memory accesses to target speci...
std::unique_ptr< ScheduleDAGMutation > createRISCVVectorMaskDAGMutation(const TargetRegisterInfo *TRI)
LLVM_ABI FunctionPass * createBasicRegisterAllocator()
BasicRegisterAllocation Pass - This pass implements a degenerate global register allocator using the ...
LLVM_ABI void initializeGlobalISel(PassRegistry &)
Initialize all passes linked into the GlobalISel library.
void initializeRISCVMakeCompressibleOptPass(PassRegistry &)
void initializeRISCVVectorPeepholeLegacyPass(PassRegistry &)
LLVM_ABI char & MachinePipelinerID
This pass performs software pipelining on machine instructions.
LLVM_ABI ModulePass * createBarrierNoopPass()
createBarrierNoopPass - This pass is purely a module pass barrier in a pass manager.
void initializeRISCVQCRelaxMarkingPass(PassRegistry &)
FunctionPass * createRISCVLateBranchOptPass()
Target & getTheRISCV64Target()
FunctionPass * createRISCVExpandPseudoPreRALegacyPass()
ModulePass * createRISCVPromoteConstantPass()
void call_once(once_flag &flag, Function &&F, Args &&... ArgList)
Execute the function specified as a parameter once.
Definition Threading.h:86
void initializeRISCVO0PreLegalizerCombinerPass(PassRegistry &)
void initializeRISCVMergeBaseOffsetOptPass(PassRegistry &)
void initializeRISCVIndirectBranchTrackingPass(PassRegistry &)
void initializeRISCVPromoteConstantPass(PassRegistry &)
void initializeRISCVAsmPrinterPass(PassRegistry &)
void initializeRISCVOptWInstrsLegacyPass(PassRegistry &)
void initializeRISCVGatherScatterLoweringLegacyPass(PassRegistry &)
void initializeRISCVZacasABIFixLegacyPass(PassRegistry &)
LLVM_ABI FunctionPass * createVirtRegRewriter(bool ClearVirtRegs=true)
constexpr bool valueOr(BoolOrDefault X, bool Default)
LLVM_ABI FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:391
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
Definition bit.h:347
FunctionPass * createRISCVInsertWriteVXRMPass()
LLVM_ABI MachineFunctionPass * createMachineCopyPropagationPass(bool UseCopyInstr)
FunctionPass * createRISCVVLOptimizerLegacyPass()
void initializeRISCVExpandPseudoPostRALegacyPass(PassRegistry &)
void initializeRISCVPreAllocZilsdOptPass(PassRegistry &)
Target & getTheRISCV32beTarget()
void initializeRISCVPostLegalizerCombinerPass(PassRegistry &)
void initializeRISCVMoveMergePass(PassRegistry &)
FunctionPass * createRISCVQCRelaxMarkingPass()
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
#define N
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
static FuncInfoTy * create(BumpPtrAllocator &Allocator, const Function &F, const SubtargetTy *STI)
Factory function: default behavior is to call new using the supplied allocator.
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.
Definition Threading.h:67
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.