LLVM 23.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"
15#include "RISCV.h"
31#include "llvm/CodeGen/Passes.h"
40#include "llvm/Transforms/IPO.h"
43#include <optional>
44using namespace llvm;
45
47 "riscv-enable-copyelim",
48 cl::desc("Enable the redundant copy elimination pass"), cl::init(true),
50
51// FIXME: Unify control over GlobalMerge.
53 EnableGlobalMerge("riscv-enable-global-merge", cl::Hidden,
54 cl::desc("Enable the global merge pass"));
55
56static cl::opt<bool>
57 EnableMachineCombiner("riscv-enable-machine-combiner",
58 cl::desc("Enable the machine combiner pass"),
59 cl::init(true), cl::Hidden);
60
62 "riscv-v-vector-bits-max",
63 cl::desc("Assume V extension vector registers are at most this big, "
64 "with zero meaning no maximum size is assumed."),
66
68 "riscv-v-vector-bits-min",
69 cl::desc("Assume V extension vector registers are at least this big, "
70 "with zero meaning no minimum size is assumed. A value of -1 "
71 "means use Zvl*b extension. This is primarily used to enable "
72 "autovectorization with fixed width vectors."),
73 cl::init(-1), cl::Hidden);
74
76 "riscv-enable-copy-propagation",
77 cl::desc("Enable the copy propagation with RISC-V copy instr"),
78 cl::init(true), cl::Hidden);
79
81 "riscv-enable-dead-defs", cl::Hidden,
82 cl::desc("Enable the pass that removes dead"
83 " definitions and replaces stores to"
84 " them with stores to x0"),
85 cl::init(true));
86
87static cl::opt<bool>
88 EnableSinkFold("riscv-enable-sink-fold",
89 cl::desc("Enable sinking and folding of instruction copies"),
90 cl::init(true), cl::Hidden);
91
92static cl::opt<bool>
93 EnableLoopDataPrefetch("riscv-enable-loop-data-prefetch", cl::Hidden,
94 cl::desc("Enable the loop data prefetch pass"),
95 cl::init(true));
96
98 "riscv-disable-vector-mask-mutation",
99 cl::desc("Disable the vector mask scheduling mutation"), cl::init(false),
100 cl::Hidden);
101
102static cl::opt<bool>
103 EnableMachinePipeliner("riscv-enable-pipeliner",
104 cl::desc("Enable Machine Pipeliner for RISC-V"),
105 cl::init(false), cl::Hidden);
106
108 "riscv-enable-cfi-instr-inserter",
109 cl::desc("Enable CFI Instruction Inserter for RISC-V"), cl::init(false),
110 cl::Hidden);
111
112static cl::opt<bool>
113 EnableSelectOpt("riscv-select-opt", cl::Hidden,
114 cl::desc("Enable select to branch optimizations"),
115 cl::init(true));
116
155}
156
158 std::optional<Reloc::Model> RM) {
159 if (TT.isOSBinFormatMachO())
160 return RM.value_or(Reloc::PIC_);
161
162 return RM.value_or(Reloc::Static);
163}
164
165static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
166 if (TT.isOSBinFormatMachO())
167 return std::make_unique<RISCVMachOTargetObjectFile>();
168 return std::make_unique<RISCVELFTargetObjectFile>();
169}
170
172 StringRef CPU, StringRef FS,
173 const TargetOptions &Options,
174 std::optional<Reloc::Model> RM,
175 std::optional<CodeModel::Model> CM,
176 CodeGenOptLevel OL, bool JIT)
178 T, TT.computeDataLayout(Options.MCOptions.getABIName()), TT, CPU, FS,
180 getEffectiveCodeModel(CM, CodeModel::Small), OL),
181 TLOF(createTLOF(TT)) {
182 initAsmInfo();
183
184 // RISC-V supports the MachineOutliner.
185 setMachineOutliner(true);
187
188 // RISC-V supports the debug entry values.
190
191 if (TT.isOSFuchsia() && !TT.isArch64Bit())
192 report_fatal_error("Fuchsia is only supported for 64-bit");
193
195}
196
197const RISCVSubtarget *
199 Attribute CPUAttr = F.getFnAttribute("target-cpu");
200 Attribute TuneAttr = F.getFnAttribute("tune-cpu");
201 Attribute FSAttr = F.getFnAttribute("target-features");
202
203 std::string CPU =
204 CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
205 std::string TuneCPU =
206 TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU;
207 std::string FS =
208 FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
209
210 unsigned RVVBitsMin = RVVVectorBitsMinOpt;
211 unsigned RVVBitsMax = RVVVectorBitsMaxOpt;
212
213 Attribute VScaleRangeAttr = F.getFnAttribute(Attribute::VScaleRange);
214 if (VScaleRangeAttr.isValid()) {
215 if (!RVVVectorBitsMinOpt.getNumOccurrences())
216 RVVBitsMin = VScaleRangeAttr.getVScaleRangeMin() * RISCV::RVVBitsPerBlock;
217 std::optional<unsigned> VScaleMax = VScaleRangeAttr.getVScaleRangeMax();
218 if (VScaleMax.has_value() && !RVVVectorBitsMaxOpt.getNumOccurrences())
219 RVVBitsMax = *VScaleMax * RISCV::RVVBitsPerBlock;
220 }
221
222 if (RVVBitsMin != -1U) {
223 // FIXME: Change to >= 32 when VLEN = 32 is supported.
224 assert((RVVBitsMin == 0 || (RVVBitsMin >= 64 && RVVBitsMin <= 65536 &&
225 isPowerOf2_32(RVVBitsMin))) &&
226 "V or Zve* extension requires vector length to be in the range of "
227 "64 to 65536 and a power 2!");
228 assert((RVVBitsMax >= RVVBitsMin || RVVBitsMax == 0) &&
229 "Minimum V extension vector length should not be larger than its "
230 "maximum!");
231 }
232 assert((RVVBitsMax == 0 || (RVVBitsMax >= 64 && RVVBitsMax <= 65536 &&
233 isPowerOf2_32(RVVBitsMax))) &&
234 "V or Zve* extension requires vector length to be in the range of "
235 "64 to 65536 and a power 2!");
236
237 if (RVVBitsMin != -1U) {
238 if (RVVBitsMax != 0) {
239 RVVBitsMin = std::min(RVVBitsMin, RVVBitsMax);
240 RVVBitsMax = std::max(RVVBitsMin, RVVBitsMax);
241 }
242
243 RVVBitsMin = llvm::bit_floor(
244 (RVVBitsMin < 64 || RVVBitsMin > 65536) ? 0 : RVVBitsMin);
245 }
246 RVVBitsMax =
247 llvm::bit_floor((RVVBitsMax < 64 || RVVBitsMax > 65536) ? 0 : RVVBitsMax);
248
250 raw_svector_ostream(Key) << "RVVMin" << RVVBitsMin << "RVVMax" << RVVBitsMax
251 << CPU << TuneCPU << FS;
252 auto &I = SubtargetMap[Key];
253 if (!I) {
254 // This needs to be done before we create a new subtarget since any
255 // creation will depend on the TM and the code generation flags on the
256 // function that reside in TargetOptions.
258 auto ABIName = Options.MCOptions.getABIName();
259 if (const MDString *ModuleTargetABI = dyn_cast_or_null<MDString>(
260 F.getParent()->getModuleFlag("target-abi"))) {
261 auto TargetABI = RISCVABI::getTargetABI(ABIName);
262 if (TargetABI != RISCVABI::ABI_Unknown &&
263 ModuleTargetABI->getString() != ABIName) {
264 report_fatal_error("-target-abi option != target-abi module flag");
265 }
266 ABIName = ModuleTargetABI->getString();
267 }
268 I = std::make_unique<RISCVSubtarget>(
269 TargetTriple, CPU, TuneCPU, FS, ABIName, RVVBitsMin, RVVBitsMax, *this);
270 }
271 return I.get();
272}
273
280
283 return TargetTransformInfo(std::make_unique<RISCVTTIImpl>(this, F));
284}
285
286// A RISC-V hart has a single byte-addressable address space of 2^XLEN bytes
287// for all memory accesses, so it is reasonable to assume that an
288// implementation has no-op address space casts. If an implementation makes a
289// change to this, they can override it here.
291 unsigned DstAS) const {
292 return true;
293}
294
297 const RISCVSubtarget &ST = C->MF->getSubtarget<RISCVSubtarget>();
299
300 // Add MacroFusion mutation first with a higher priority than later clustering
301 const auto &MacroFusions = ST.getMacroFusions();
302 if (!MacroFusions.empty())
303 DAG->addMutation(createMacroFusionDAGMutation(MacroFusions));
304
305 if (ST.enableMISchedLoadClustering())
306 DAG->addMutation(createLoadClusterDAGMutation(
307 DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
308
309 if (ST.enableMISchedStoreClustering())
310 DAG->addMutation(createStoreClusterDAGMutation(
311 DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
312
313 if (!DisableVectorMaskMutation && ST.hasVInstructions())
314 DAG->addMutation(createRISCVVectorMaskDAGMutation(DAG->TRI));
315
316 return DAG;
317}
318
321 const RISCVSubtarget &ST = C->MF->getSubtarget<RISCVSubtarget>();
323
324 // Add MacroFusion mutation first with a higher priority than later clustering
325 const auto &MacroFusions = ST.getMacroFusions();
326 if (!MacroFusions.empty())
327 DAG->addMutation(createMacroFusionDAGMutation(MacroFusions));
328
329 if (ST.enablePostMISchedLoadClustering())
330 DAG->addMutation(createLoadClusterDAGMutation(
331 DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
332
333 if (ST.enablePostMISchedStoreClustering())
334 DAG->addMutation(createStoreClusterDAGMutation(
335 DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
336
337 return DAG;
338}
339
340namespace {
341
342class RVVRegisterRegAlloc : public RegisterRegAllocBase<RVVRegisterRegAlloc> {
343public:
344 RVVRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
345 : RegisterRegAllocBase(N, D, C) {}
346};
347
348static bool onlyAllocateRVVReg(const TargetRegisterInfo &TRI,
349 const MachineRegisterInfo &MRI,
350 const Register Reg) {
351 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
353}
354
355static FunctionPass *useDefaultRegisterAllocator() { return nullptr; }
356
357static llvm::once_flag InitializeDefaultRVVRegisterAllocatorFlag;
358
359/// -riscv-rvv-regalloc=<fast|basic|greedy> command line option.
360/// This option could designate the rvv register allocator only.
361/// For example: -riscv-rvv-regalloc=basic
362static cl::opt<RVVRegisterRegAlloc::FunctionPassCtor, false,
364 RVVRegAlloc("riscv-rvv-regalloc", cl::Hidden,
366 cl::desc("Register allocator to use for RVV register."));
367
368static void initializeDefaultRVVRegisterAllocatorOnce() {
369 RegisterRegAlloc::FunctionPassCtor Ctor = RVVRegisterRegAlloc::getDefault();
370
371 if (!Ctor) {
372 Ctor = RVVRegAlloc;
373 RVVRegisterRegAlloc::setDefault(RVVRegAlloc);
374 }
375}
376
377static FunctionPass *createBasicRVVRegisterAllocator() {
378 return createBasicRegisterAllocator(onlyAllocateRVVReg);
379}
380
381static FunctionPass *createGreedyRVVRegisterAllocator() {
382 return createGreedyRegisterAllocator(onlyAllocateRVVReg);
383}
384
385static FunctionPass *createFastRVVRegisterAllocator() {
386 return createFastRegisterAllocator(onlyAllocateRVVReg, false);
387}
388
389static RVVRegisterRegAlloc basicRegAllocRVVReg("basic",
390 "basic register allocator",
391 createBasicRVVRegisterAllocator);
392static RVVRegisterRegAlloc
393 greedyRegAllocRVVReg("greedy", "greedy register allocator",
394 createGreedyRVVRegisterAllocator);
395
396static RVVRegisterRegAlloc fastRegAllocRVVReg("fast", "fast register allocator",
397 createFastRVVRegisterAllocator);
398
399class RISCVPassConfig : public TargetPassConfig {
400public:
401 RISCVPassConfig(RISCVTargetMachine &TM, PassManagerBase &PM)
402 : TargetPassConfig(TM, PM) {
403 if (TM.getOptLevel() != CodeGenOptLevel::None)
404 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
405 setEnableSinkAndFold(EnableSinkFold);
406 EnableLoopTermFold = true;
407 }
408
409 RISCVTargetMachine &getRISCVTargetMachine() const {
411 }
412
413 void addIRPasses() override;
414 bool addPreISel() override;
415 void addCodeGenPrepare() override;
416 bool addInstSelector() override;
417 bool addIRTranslator() override;
418 void addPreLegalizeMachineIR() override;
419 bool addLegalizeMachineIR() override;
420 void addPreRegBankSelect() override;
421 bool addRegBankSelect() override;
422 bool addGlobalInstructionSelect() override;
423 void addPreEmitPass() override;
424 void addPreEmitPass2() override;
425 void addPreSched2() override;
426 void addMachineSSAOptimization() override;
427 FunctionPass *createRVVRegAllocPass(bool Optimized);
428 bool addRegAssignAndRewriteFast() override;
429 bool addRegAssignAndRewriteOptimized() override;
430 void addPreRegAlloc() override;
431 void addPostRegAlloc() override;
432 void addFastRegAlloc() override;
433 bool addILPOpts() override;
434
435 std::unique_ptr<CSEConfigBase> getCSEConfig() const override;
436};
437} // namespace
438
440 return new RISCVPassConfig(*this, PM);
441}
442
443std::unique_ptr<CSEConfigBase> RISCVPassConfig::getCSEConfig() const {
444 return getStandardCSEConfigForOpt(TM->getOptLevel());
445}
446
447FunctionPass *RISCVPassConfig::createRVVRegAllocPass(bool Optimized) {
448 // Initialize the global default.
449 llvm::call_once(InitializeDefaultRVVRegisterAllocatorFlag,
450 initializeDefaultRVVRegisterAllocatorOnce);
451
452 RegisterRegAlloc::FunctionPassCtor Ctor = RVVRegisterRegAlloc::getDefault();
453 if (Ctor != useDefaultRegisterAllocator)
454 return Ctor();
455
456 if (Optimized)
457 return createGreedyRVVRegisterAllocator();
458
459 return createFastRVVRegisterAllocator();
460}
461
462bool RISCVPassConfig::addRegAssignAndRewriteFast() {
463 addPass(createRVVRegAllocPass(false));
465 if (TM->getOptLevel() != CodeGenOptLevel::None &&
469}
470
471bool RISCVPassConfig::addRegAssignAndRewriteOptimized() {
472 addPass(createRVVRegAllocPass(true));
473 addPass(createVirtRegRewriter(false));
475 if (TM->getOptLevel() != CodeGenOptLevel::None &&
479}
480
481void RISCVPassConfig::addIRPasses() {
484
485 if (getOptLevel() != CodeGenOptLevel::None) {
488
492 }
493
495
496 if (getOptLevel() == CodeGenOptLevel::Aggressive && EnableSelectOpt)
497 addPass(createSelectOptimizePass());
498}
499
500bool RISCVPassConfig::addPreISel() {
501 if (TM->getOptLevel() != CodeGenOptLevel::None)
503 if (TM->getOptLevel() != CodeGenOptLevel::None) {
504 // Add a barrier before instruction selection so that we will not get
505 // deleted block address after enabling default outlining. See D99707 for
506 // more details.
507 addPass(createBarrierNoopPass());
508 }
509
510 if ((TM->getOptLevel() != CodeGenOptLevel::None &&
513 // FIXME: Like AArch64, we disable extern global merging by default due to
514 // concerns it might regress some workloads. Unlike AArch64, we don't
515 // currently support enabling the pass in an "OnlyOptimizeForSize" mode.
516 // Investigating and addressing both items are TODO.
517 addPass(createGlobalMergePass(TM, /* MaxOffset */ 2047,
518 /* OnlyOptimizeForSize */ false,
519 /* MergeExternalByDefault */ true));
520 }
521
522 return false;
523}
524
525void RISCVPassConfig::addCodeGenPrepare() {
526 if (getOptLevel() != CodeGenOptLevel::None)
529}
530
531bool RISCVPassConfig::addInstSelector() {
532 addPass(createRISCVISelDag(getRISCVTargetMachine(), getOptLevel()));
533
534 return false;
535}
536
537bool RISCVPassConfig::addIRTranslator() {
538 addPass(new IRTranslator(getOptLevel()));
539 return false;
540}
541
542void RISCVPassConfig::addPreLegalizeMachineIR() {
543 if (getOptLevel() == CodeGenOptLevel::None) {
545 } else {
547 }
548}
549
550bool RISCVPassConfig::addLegalizeMachineIR() {
551 addPass(new Legalizer());
552 return false;
553}
554
555void RISCVPassConfig::addPreRegBankSelect() {
556 if (getOptLevel() != CodeGenOptLevel::None)
558}
559
560bool RISCVPassConfig::addRegBankSelect() {
561 addPass(new RegBankSelect());
562 return false;
563}
564
565bool RISCVPassConfig::addGlobalInstructionSelect() {
566 addPass(new InstructionSelect(getOptLevel()));
567 return false;
568}
569
570void RISCVPassConfig::addPreSched2() {
572
573 // Emit KCFI checks for indirect calls.
574 addPass(createKCFIPass());
575 if (TM->getOptLevel() != CodeGenOptLevel::None)
577}
578
579void RISCVPassConfig::addPreEmitPass() {
580 // TODO: It would potentially be better to schedule copy propagation after
581 // expanding pseudos (in addPreEmitPass2). However, performing copy
582 // propagation after the machine outliner (which runs after addPreEmitPass)
583 // currently leads to incorrect code-gen, where copies to registers within
584 // outlined functions are removed erroneously.
585 if (TM->getOptLevel() >= CodeGenOptLevel::Default &&
588 if (TM->getOptLevel() >= CodeGenOptLevel::Default)
590 // The IndirectBranchTrackingPass inserts lpad and could have changed the
591 // basic block alignment. It must be done before Branch Relaxation to
592 // prevent the adjusted offset exceeding the branch range.
594 addPass(&BranchRelaxationPassID);
596}
597
598void RISCVPassConfig::addPreEmitPass2() {
599 if (TM->getOptLevel() != CodeGenOptLevel::None) {
600 addPass(createRISCVMoveMergePass());
601 // Schedule PushPop Optimization before expansion of Pseudo instruction,
602 // ensuring return instruction is detected correctly.
604 }
606
607 // Schedule the expansion of AMOs at the last possible moment, avoiding the
608 // possibility for other passes to break the requirements for forward
609 // progress in the LR/SC block.
611
612 // KCFI indirect call checks are lowered to a bundle.
614 return MF.getFunction().getParent()->getModuleFlag("kcfi");
615 }));
616
618 addPass(createCFIInstrInserter());
619}
620
621void RISCVPassConfig::addMachineSSAOptimization() {
622 // It's beneficial to reduce the VL to enable more
623 // Machine SSA optimizations.
624 if (TM->getOptLevel() != CodeGenOptLevel::None)
626
629
631
632 if (TM->getTargetTriple().isRISCV64()) {
633 addPass(createRISCVOptWInstrsPass());
634 }
635}
636
637void RISCVPassConfig::addPreRegAlloc() {
639 if (TM->getOptLevel() != CodeGenOptLevel::None) {
641 // Add Zilsd pre-allocation load/store optimization
643 }
644
648
649 if (TM->getOptLevel() != CodeGenOptLevel::None && EnableMachinePipeliner)
650 addPass(&MachinePipelinerID);
651
653}
654
655void RISCVPassConfig::addFastRegAlloc() {
656 addPass(&InitUndefID);
658}
659
660
661void RISCVPassConfig::addPostRegAlloc() {
662 if (TM->getOptLevel() != CodeGenOptLevel::None &&
665}
666
667bool RISCVPassConfig::addILPOpts() {
669 addPass(&MachineCombinerID);
670
671 return true;
672}
673
675#define GET_PASS_REGISTRY "RISCVPassRegistry.def"
677
678 PB.registerLateLoopOptimizationsEPCallback([=](LoopPassManager &LPM,
679 OptimizationLevel Level) {
680 if (Level != OptimizationLevel::O0)
682 });
683}
684
689
695
698 SMDiagnostic &Error, SMRange &SourceRange) const {
699 const auto &YamlMFI =
700 static_cast<const yaml::RISCVMachineFunctionInfo &>(MFI);
701 PFS.MF.getInfo<RISCVMachineFunctionInfo>()->initializeBaseYamlFields(YamlMFI);
702 return false;
703}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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 > EnableSelectOpt("aarch64-select-opt", cl::Hidden, cl::desc("Enable select to branch optimizations"), cl::init(true))
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 cl::opt< bool > EnableMachinePipeliner("aarch64-enable-pipeliner", cl::desc("Enable Machine Pipeliner for AArch64"), cl::init(false), cl::Hidden)
static std::unique_ptr< TargetLoweringObjectFile > createTLOF(const Triple &TT)
static Reloc::Model getEffectiveRelocModel()
#define X(NUM, ENUM, NAME)
Definition ELF.h:853
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:213
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
DXIL Legalizer
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.
#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
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
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 > EnableMachinePipeliner("riscv-enable-pipeliner", cl::desc("Enable Machine Pipeliner for RISC-V"), cl::init(false), 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"))
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 cl::opt< bool > DisableVectorMaskMutation("riscv-disable-vector-mask-mutation", cl::desc("Disable the vector mask scheduling mutation"), cl::init(false), cl::Hidden)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTarget()
static cl::opt< bool > EnableRISCVDeadRegisterElimination("riscv-enable-dead-defs", cl::Hidden, cl::desc("Enable the pass that removes dead" " definitions and replaces stores to" " them with stores to x0"), cl::init(true))
static cl::opt< bool > EnableCFIInstrInserter("riscv-enable-cfi-instr-inserter", cl::desc("Enable CFI Instruction Inserter for RISC-V"), cl::init(false), cl::Hidden)
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 > EnableSelectOpt("riscv-select-opt", cl::Hidden, cl::desc("Enable select to branch optimizations"), cl::init(true))
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:105
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:261
CodeGenTargetMachineImpl(const Target &T, StringRef DataLayoutString, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOptLevel OL)
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.
A single uniqued string.
Definition Metadata.h:722
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 const OptimizationLevel O0
Disable as many optimizations as possible.
This class provides access to building LLVM's passes.
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 ...
void registerPassBuilderCallbacks(PassBuilder &PB) override
Allow the target to modify the pass pipeline.
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.
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:303
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)
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions Options
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
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:47
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.
Interfaces for registering analysis passes, producing common pass manager configurations,...
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
ABI getTargetABI(StringRef ABIName)
static constexpr unsigned RVVBitsPerBlock
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 * createRISCVLoadStoreOptPass()
LLVM_ABI FunctionPass * createFastRegisterAllocator()
FastRegisterAllocation Pass - This pass register allocates as fast as possible.
void initializeRISCVPushPopOptPass(PassRegistry &)
void initializeRISCVExpandPseudoPass(PassRegistry &)
FunctionPass * createRISCVFoldMemOffsetPass()
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 * createRISCVExpandAtomicPseudoPass()
FunctionPass * createRISCVPostRAExpandPseudoPass()
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...
FunctionPass * createRISCVInsertReadWriteCSRPass()
Target & getTheRISCV32Target()
void initializeRISCVFoldMemOffsetPass(PassRegistry &)
void initializeRISCVInsertVSETVLIPass(PassRegistry &)
FunctionPass * createRISCVVLOptimizerPass()
LLVM_ABI char & PostRASchedulerID
PostRAScheduler - This pass performs post register allocation scheduling.
void initializeRISCVLateBranchOptPass(PassRegistry &)
void initializeRISCVRedundantCopyEliminationPass(PassRegistry &)
Target & getTheRISCV64beTarget()
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.
FunctionPass * createRISCVGatherScatterLoweringPass()
FunctionPass * createRISCVMergeBaseOffsetOptPass()
Returns an instance of the Merge Base Offset Optimization pass.
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
FunctionPass * createRISCVPostLegalizerCombiner()
LLVM_ABI void initializeMachineKCFILegacyPass(PassRegistry &)
PassManager< Loop, LoopAnalysisManager, LoopStandardAnalysisResults &, LPMUpdater & > LoopPassManager
The Loop pass manager.
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)
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.
Definition MathExtras.h:279
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...
void initializeRISCVDAGToDAGISelLegacyPass(PassRegistry &)
FunctionPass * createRISCVPreAllocZilsdOptPass()
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()
LLVM_ABI FunctionPass * createKCFIPass()
Lowers KCFI operand bundles for indirect calls.
Definition KCFI.cpp:69
void initializeRISCVVMV0EliminationPass(PassRegistry &)
void initializeRISCVInsertWriteVXRMPass(PassRegistry &)
void initializeRISCVLoadStoreOptPass(PassRegistry &)
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createStoreClusterDAGMutation(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...
LLVM_ABI FunctionPass * createLoopDataPrefetchPass()
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
void initializeRISCVInsertReadWriteCSRPass(PassRegistry &)
void initializeRISCVExpandAtomicPseudoPass(PassRegistry &)
FunctionPass * createRISCVPreLegalizerCombiner()
void initializeRISCVCodeGenPrepareLegacyPassPass(PassRegistry &)
FunctionPass * createRISCVVMV0EliminationPass()
FunctionPass * createRISCVInsertVSETVLIPass()
Returns an instance of the Insert VSETVLI pass.
FunctionPass * createRISCVO0PreLegalizerCombiner()
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
@ Default
-O2, -Os, -Oz
Definition CodeGen.h:85
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
FunctionPass * createRISCVIndirectBranchTrackingPass()
FunctionPass * createRISCVOptWInstrsPass()
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 &)
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 initializeRISCVVLOptimizerPass(PassRegistry &)
LLVM_ABI 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 * createRISCVLateBranchOptPass()
Target & getTheRISCV64Target()
ModulePass * createRISCVPromoteConstantPass()
FunctionPass * createRISCVVectorPeepholePass()
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 &)
FunctionPass * createRISCVISelDag(RISCVTargetMachine &TM, CodeGenOptLevel OptLevel)
LLVM_ABI FunctionPass * createVirtRegRewriter(bool ClearVirtRegs=true)
void initializeRISCVGatherScatterLoweringPass(PassRegistry &)
FunctionPass * createRISCVExpandPseudoPass()
FunctionPass * createRISCVPreRAExpandPseudoPass()
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:383
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)
void initializeRISCVVectorPeepholePass(PassRegistry &)
FunctionPass * createRISCVZacasABIFixPass()
LLVM_ABI FunctionPass * createCFIInstrInserter()
Creates CFI Instruction Inserter pass.
void initializeRISCVPreRAExpandPseudoPass(PassRegistry &)
void initializeRISCVPreAllocZilsdOptPass(PassRegistry &)
Target & getTheRISCV32beTarget()
void initializeRISCVPostLegalizerCombinerPass(PassRegistry &)
void initializeRISCVMoveMergePass(PassRegistry &)
#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.