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"
15#include "RISCV.h"
32#include "llvm/CodeGen/Passes.h"
40#include "llvm/Transforms/IPO.h"
42#include <optional>
43using namespace llvm;
44
46 "riscv-enable-copyelim",
47 cl::desc("Enable the redundant copy elimination pass"), cl::init(true),
49
50// FIXME: Unify control over GlobalMerge.
52 EnableGlobalMerge("riscv-enable-global-merge", cl::Hidden,
53 cl::desc("Enable the global merge pass"));
54
55static cl::opt<bool>
56 EnableMachineCombiner("riscv-enable-machine-combiner",
57 cl::desc("Enable the machine combiner pass"),
58 cl::init(true), cl::Hidden);
59
61 "riscv-v-vector-bits-max",
62 cl::desc("Assume V extension vector registers are at most this big, "
63 "with zero meaning no maximum size is assumed."),
65
67 "riscv-v-vector-bits-min",
68 cl::desc("Assume V extension vector registers are at least this big, "
69 "with zero meaning no minimum size is assumed. A value of -1 "
70 "means use Zvl*b extension. This is primarily used to enable "
71 "autovectorization with fixed width vectors."),
72 cl::init(-1), cl::Hidden);
73
75 "riscv-enable-copy-propagation",
76 cl::desc("Enable the copy propagation with RISC-V copy instr"),
77 cl::init(true), cl::Hidden);
78
80 "riscv-enable-dead-defs", cl::Hidden,
81 cl::desc("Enable the pass that removes dead"
82 " definitions and replaces stores to"
83 " them with stores to x0"),
84 cl::init(true));
85
86static cl::opt<bool>
87 EnableSinkFold("riscv-enable-sink-fold",
88 cl::desc("Enable sinking and folding of instruction copies"),
89 cl::init(true), cl::Hidden);
90
91static cl::opt<bool>
92 EnableLoopDataPrefetch("riscv-enable-loop-data-prefetch", cl::Hidden,
93 cl::desc("Enable the loop data prefetch pass"),
94 cl::init(true));
95
97 "riscv-disable-vector-mask-mutation",
98 cl::desc("Disable the vector mask scheduling mutation"), cl::init(false),
100
101static cl::opt<bool>
102 EnableMachinePipeliner("riscv-enable-pipeliner",
103 cl::desc("Enable Machine Pipeliner for RISC-V"),
104 cl::init(false), cl::Hidden);
105
107 "riscv-enable-cfi-instr-inserter",
108 cl::desc("Enable CFI Instruction Inserter for RISC-V"), cl::init(false),
109 cl::Hidden);
110
111static cl::opt<bool>
112 EnableSelectOpt("riscv-select-opt", cl::Hidden,
113 cl::desc("Enable select to branch optimizations"),
114 cl::init(true));
115
156}
157
159 std::optional<Reloc::Model> RM) {
160 if (TT.isOSBinFormatMachO())
161 return RM.value_or(Reloc::PIC_);
162
163 return RM.value_or(Reloc::Static);
164}
165
166static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
167 if (TT.isOSBinFormatMachO())
168 return std::make_unique<RISCVMachOTargetObjectFile>();
169 return std::make_unique<RISCVELFTargetObjectFile>();
170}
171
173 StringRef CPU, StringRef FS,
174 const TargetOptions &Options,
175 std::optional<Reloc::Model> RM,
176 std::optional<CodeModel::Model> CM,
177 CodeGenOptLevel OL, bool JIT)
179 T, TT.computeDataLayout(Options.MCOptions.getABIName()), TT, CPU, FS,
181 getEffectiveCodeModel(CM, CodeModel::Small), OL),
182 TLOF(createTLOF(TT)) {
183 initAsmInfo();
184
185 // RISC-V supports the MachineOutliner.
186 setMachineOutliner(true);
188
189 // RISC-V supports the debug entry values.
191
192 if (TT.isOSFuchsia() && !TT.isArch64Bit())
193 report_fatal_error("Fuchsia is only supported for 64-bit");
194
196}
197
198const RISCVSubtarget *
200 Attribute CPUAttr = F.getFnAttribute("target-cpu");
201 Attribute TuneAttr = F.getFnAttribute("tune-cpu");
202 Attribute FSAttr = F.getFnAttribute("target-features");
203
204 std::string CPU =
205 CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
206 std::string TuneCPU =
207 TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU;
208 std::string FS =
209 FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
210
211 unsigned RVVBitsMin = RVVVectorBitsMinOpt;
212 unsigned RVVBitsMax = RVVVectorBitsMaxOpt;
213
214 Attribute VScaleRangeAttr = F.getFnAttribute(Attribute::VScaleRange);
215 if (VScaleRangeAttr.isValid()) {
216 if (!RVVVectorBitsMinOpt.getNumOccurrences())
217 RVVBitsMin = VScaleRangeAttr.getVScaleRangeMin() * RISCV::RVVBitsPerBlock;
218 std::optional<unsigned> VScaleMax = VScaleRangeAttr.getVScaleRangeMax();
219 if (VScaleMax.has_value() && !RVVVectorBitsMaxOpt.getNumOccurrences())
220 RVVBitsMax = *VScaleMax * RISCV::RVVBitsPerBlock;
221 }
222
223 if (RVVBitsMin != -1U) {
224 // FIXME: Change to >= 32 when VLEN = 32 is supported.
225 assert((RVVBitsMin == 0 || (RVVBitsMin >= 64 && RVVBitsMin <= 65536 &&
226 isPowerOf2_32(RVVBitsMin))) &&
227 "V or Zve* extension requires vector length to be in the range of "
228 "64 to 65536 and a power 2!");
229 assert((RVVBitsMax >= RVVBitsMin || RVVBitsMax == 0) &&
230 "Minimum V extension vector length should not be larger than its "
231 "maximum!");
232 }
233 assert((RVVBitsMax == 0 || (RVVBitsMax >= 64 && RVVBitsMax <= 65536 &&
234 isPowerOf2_32(RVVBitsMax))) &&
235 "V or Zve* extension requires vector length to be in the range of "
236 "64 to 65536 and a power 2!");
237
238 if (RVVBitsMin != -1U) {
239 if (RVVBitsMax != 0) {
240 RVVBitsMin = std::min(RVVBitsMin, RVVBitsMax);
241 RVVBitsMax = std::max(RVVBitsMin, RVVBitsMax);
242 }
243
244 RVVBitsMin = llvm::bit_floor(
245 (RVVBitsMin < 64 || RVVBitsMin > 65536) ? 0 : RVVBitsMin);
246 }
247 RVVBitsMax =
248 llvm::bit_floor((RVVBitsMax < 64 || RVVBitsMax > 65536) ? 0 : RVVBitsMax);
249
251 raw_svector_ostream(Key) << "RVVMin" << RVVBitsMin << "RVVMax" << RVVBitsMax
252 << CPU << TuneCPU << FS;
253 auto &I = SubtargetMap[Key];
254 if (!I) {
255 StringRef ABIName = getTargetABIName(*F.getParent());
256 I = std::make_unique<RISCVSubtarget>(
257 TargetTriple, CPU, TuneCPU, FS, ABIName, RVVBitsMin, RVVBitsMax, *this);
258 }
259 return I.get();
260}
261
268
271 return TargetTransformInfo(std::make_unique<RISCVTTIImpl>(this, F));
272}
273
274// A RISC-V hart has a single byte-addressable address space of 2^XLEN bytes
275// for all memory accesses, so it is reasonable to assume that an
276// implementation has no-op address space casts. If an implementation makes a
277// change to this, they can override it here.
279 unsigned DstAS) const {
280 return true;
281}
282
285 const RISCVSubtarget &ST = C->MF->getSubtarget<RISCVSubtarget>();
287
288 // Add MacroFusion mutation first with a higher priority than later clustering
289 const auto &MacroFusions = ST.getMacroFusions();
290 if (!MacroFusions.empty())
291 DAG->addMutation(createMacroFusionDAGMutation(MacroFusions));
292
293 if (ST.enableMISchedLoadClustering())
294 DAG->addMutation(createLoadClusterDAGMutation(
295 DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
296
297 if (ST.enableMISchedStoreClustering())
298 DAG->addMutation(createStoreClusterDAGMutation(
299 DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
300
301 if (!DisableVectorMaskMutation && ST.hasVInstructions())
302 DAG->addMutation(createRISCVVectorMaskDAGMutation(DAG->TRI));
303
304 return DAG;
305}
306
309 const RISCVSubtarget &ST = C->MF->getSubtarget<RISCVSubtarget>();
311
312 // Add MacroFusion mutation first with a higher priority than later clustering
313 const auto &MacroFusions = ST.getMacroFusions();
314 if (!MacroFusions.empty())
315 DAG->addMutation(createMacroFusionDAGMutation(MacroFusions));
316
317 if (ST.enablePostMISchedLoadClustering())
318 DAG->addMutation(createLoadClusterDAGMutation(
319 DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
320
321 if (ST.enablePostMISchedStoreClustering())
322 DAG->addMutation(createStoreClusterDAGMutation(
323 DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
324
325 return DAG;
326}
327
328namespace {
329
330class RVVRegisterRegAlloc : public RegisterRegAllocBase<RVVRegisterRegAlloc> {
331public:
332 RVVRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
333 : RegisterRegAllocBase(N, D, C) {}
334};
335
336static bool onlyAllocateRVVReg(const TargetRegisterInfo &TRI,
337 const MachineRegisterInfo &MRI,
338 const Register Reg) {
339 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
341}
342
343static FunctionPass *useDefaultRegisterAllocator() { return nullptr; }
344
345static llvm::once_flag InitializeDefaultRVVRegisterAllocatorFlag;
346
347/// -riscv-rvv-regalloc=<fast|basic|greedy> command line option.
348/// This option could designate the rvv register allocator only.
349/// For example: -riscv-rvv-regalloc=basic
350static cl::opt<RVVRegisterRegAlloc::FunctionPassCtor, false,
352 RVVRegAlloc("riscv-rvv-regalloc", cl::Hidden,
354 cl::desc("Register allocator to use for RVV register."));
355
356static void initializeDefaultRVVRegisterAllocatorOnce() {
357 RegisterRegAlloc::FunctionPassCtor Ctor = RVVRegisterRegAlloc::getDefault();
358
359 if (!Ctor) {
360 Ctor = RVVRegAlloc;
361 RVVRegisterRegAlloc::setDefault(RVVRegAlloc);
362 }
363}
364
365static FunctionPass *createBasicRVVRegisterAllocator() {
366 return createBasicRegisterAllocator(onlyAllocateRVVReg);
367}
368
369static FunctionPass *createGreedyRVVRegisterAllocator() {
370 return createGreedyRegisterAllocator(onlyAllocateRVVReg);
371}
372
373static FunctionPass *createFastRVVRegisterAllocator() {
374 return createFastRegisterAllocator(onlyAllocateRVVReg, false);
375}
376
377static RVVRegisterRegAlloc basicRegAllocRVVReg("basic",
378 "basic register allocator",
379 createBasicRVVRegisterAllocator);
380static RVVRegisterRegAlloc
381 greedyRegAllocRVVReg("greedy", "greedy register allocator",
382 createGreedyRVVRegisterAllocator);
383
384static RVVRegisterRegAlloc fastRegAllocRVVReg("fast", "fast register allocator",
385 createFastRVVRegisterAllocator);
386
387class RISCVPassConfig : public TargetPassConfig {
388public:
389 RISCVPassConfig(RISCVTargetMachine &TM, PassManagerBase &PM)
390 : TargetPassConfig(TM, PM) {
391 if (TM.getOptLevel() != CodeGenOptLevel::None)
392 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
393 setEnableSinkAndFold(EnableSinkFold);
394 EnableLoopTermFold = true;
395 }
396
397 RISCVTargetMachine &getRISCVTargetMachine() const {
399 }
400
401 void addIRPasses() override;
402 bool addPreISel() override;
403 void addCodeGenPrepare() override;
404 bool addInstSelector() override;
405 bool addIRTranslator() override;
406 void addPreLegalizeMachineIR() override;
407 bool addLegalizeMachineIR() override;
408 void addPreRegBankSelect() override;
409 bool addRegBankSelect() override;
410 bool addGlobalInstructionSelect() override;
411 void addPreEmitPass() override;
412 void addPreEmitPass2() override;
413 void addPreSched2() override;
414 void addMachineSSAOptimization() override;
415 FunctionPass *createRVVRegAllocPass(bool Optimized);
416 bool addRegAssignAndRewriteFast() override;
417 bool addRegAssignAndRewriteOptimized() override;
418 void addPreRegAlloc() override;
419 void addPostRegAlloc() override;
420 void addFastRegAlloc() override;
421 bool addILPOpts() override;
422
423 std::unique_ptr<CSEConfigBase> getCSEConfig() const override;
424};
425} // namespace
426
428 return new RISCVPassConfig(*this, PM);
429}
430
431std::unique_ptr<CSEConfigBase> RISCVPassConfig::getCSEConfig() const {
432 return getStandardCSEConfigForOpt(TM->getOptLevel());
433}
434
435FunctionPass *RISCVPassConfig::createRVVRegAllocPass(bool Optimized) {
436 // Initialize the global default.
437 llvm::call_once(InitializeDefaultRVVRegisterAllocatorFlag,
438 initializeDefaultRVVRegisterAllocatorOnce);
439
440 RegisterRegAlloc::FunctionPassCtor Ctor = RVVRegisterRegAlloc::getDefault();
441 if (Ctor != useDefaultRegisterAllocator)
442 return Ctor();
443
444 if (Optimized)
445 return createGreedyRVVRegisterAllocator();
446
447 return createFastRVVRegisterAllocator();
448}
449
450bool RISCVPassConfig::addRegAssignAndRewriteFast() {
451 addPass(createRVVRegAllocPass(false));
453 if (TM->getOptLevel() != CodeGenOptLevel::None &&
457}
458
459bool RISCVPassConfig::addRegAssignAndRewriteOptimized() {
460 addPass(createRVVRegAllocPass(true));
461 addPass(createVirtRegRewriter(false));
463 if (TM->getOptLevel() != CodeGenOptLevel::None &&
467}
468
469void RISCVPassConfig::addIRPasses() {
472
473 if (getOptLevel() != CodeGenOptLevel::None) {
476
480 }
481
483
484 if (getOptLevel() == CodeGenOptLevel::Aggressive && EnableSelectOpt)
485 addPass(createSelectOptimizePass());
486}
487
488bool RISCVPassConfig::addPreISel() {
489 if (TM->getOptLevel() != CodeGenOptLevel::None)
491 if (TM->getOptLevel() != CodeGenOptLevel::None) {
492 // Add a barrier before instruction selection so that we will not get
493 // deleted block address after enabling default outlining. See D99707 for
494 // more details.
495 addPass(createBarrierNoopPass());
496 }
497
498 if ((TM->getOptLevel() != CodeGenOptLevel::None &&
501 // FIXME: Like AArch64, we disable extern global merging by default due to
502 // concerns it might regress some workloads. Unlike AArch64, we don't
503 // currently support enabling the pass in an "OnlyOptimizeForSize" mode.
504 // Investigating and addressing both items are TODO.
505 addPass(createGlobalMergePass(TM, /* MaxOffset */ 2047,
506 /* OnlyOptimizeForSize */ false,
507 /* MergeExternalByDefault */ true));
508 }
509
510 return false;
511}
512
513void RISCVPassConfig::addCodeGenPrepare() {
514 if (getOptLevel() != CodeGenOptLevel::None)
517}
518
519bool RISCVPassConfig::addInstSelector() {
520 addPass(createRISCVISelDag(getRISCVTargetMachine(), getOptLevel()));
521
522 return false;
523}
524
525bool RISCVPassConfig::addIRTranslator() {
526 addPass(new IRTranslatorLegacy(getOptLevel()));
527 return false;
528}
529
530void RISCVPassConfig::addPreLegalizeMachineIR() {
531 if (getOptLevel() == CodeGenOptLevel::None) {
533 } else {
535 }
536}
537
538bool RISCVPassConfig::addLegalizeMachineIR() {
539 addPass(new LegalizerLegacy());
540 return false;
541}
542
543void RISCVPassConfig::addPreRegBankSelect() {
544 if (getOptLevel() != CodeGenOptLevel::None)
546}
547
548bool RISCVPassConfig::addRegBankSelect() {
549 addPass(new RegBankSelect());
550 return false;
551}
552
553bool RISCVPassConfig::addGlobalInstructionSelect() {
554 addPass(new InstructionSelect(getOptLevel()));
555 return false;
556}
557
558void RISCVPassConfig::addPreSched2() {
560
561 // Emit KCFI checks for indirect calls.
562 addPass(createKCFIPass());
563 if (TM->getOptLevel() != CodeGenOptLevel::None)
565}
566
567void RISCVPassConfig::addPreEmitPass() {
568 // TODO: It would potentially be better to schedule copy propagation after
569 // expanding pseudos (in addPreEmitPass2). However, performing copy
570 // propagation after the machine outliner (which runs after addPreEmitPass)
571 // currently leads to incorrect code-gen, where copies to registers within
572 // outlined functions are removed erroneously.
573 if (TM->getOptLevel() >= CodeGenOptLevel::Default &&
576 if (TM->getOptLevel() >= CodeGenOptLevel::Default)
578 // The IndirectBranchTrackingPass inserts lpad and could have changed the
579 // basic block alignment. It must be done before Branch Relaxation to
580 // prevent the adjusted offset exceeding the branch range.
582 addPass(&BranchRelaxationPassID);
584}
585
586void RISCVPassConfig::addPreEmitPass2() {
587 if (TM->getOptLevel() != CodeGenOptLevel::None) {
588 addPass(createRISCVMoveMergePass());
589 // Schedule PushPop Optimization before expansion of Pseudo instruction,
590 // ensuring return instruction is detected correctly.
592 }
594
595 // Add QC Relaxation Markers as late as possible, and only for RV32
596 if (TM->getOptLevel() != CodeGenOptLevel::None &&
597 TM->getTargetTriple().isRISCV32())
599
600 // Schedule the expansion of AMOs at the last possible moment, avoiding the
601 // possibility for other passes to break the requirements for forward
602 // progress in the LR/SC block.
604
605 // KCFI indirect call checks are lowered to a bundle.
607 return MF.getFunction().getParent()->getModuleFlag("kcfi");
608 }));
609
611 addPass(createCFIInstrInserter());
612}
613
614void RISCVPassConfig::addMachineSSAOptimization() {
615 // It's beneficial to reduce the VL to enable more
616 // Machine SSA optimizations.
617 if (TM->getOptLevel() != CodeGenOptLevel::None) {
618 // RISCVVLOptimizer can make loop invariant instructions like vmv.v.i
619 // loop variant by propagating a VL defined inside the loop. Run LICM and
620 // hoist them early. Don't do this at -O0 to avoid the compile-time
621 // overhead. Not reducing the VL of loop invariant pseudos results in more
622 // vsetvli toggles, and still requires the MachineLoopInfo analysis to be
623 // run.
624 addPass(&EarlyMachineLICMID);
626 }
627
630
632
633 if (TM->getTargetTriple().isRISCV64()) {
634 addPass(createRISCVOptWInstrsPass());
635 }
636}
637
638void RISCVPassConfig::addPreRegAlloc() {
640 if (TM->getOptLevel() != CodeGenOptLevel::None) {
642 // Add Zilsd pre-allocation load/store optimization
644 }
645
649
650 if (TM->getOptLevel() != CodeGenOptLevel::None && EnableMachinePipeliner)
651 addPass(&MachinePipelinerID);
652
654}
655
656void RISCVPassConfig::addFastRegAlloc() {
657 addPass(&InitUndefID);
659}
660
661
662void RISCVPassConfig::addPostRegAlloc() {
663 if (TM->getOptLevel() != CodeGenOptLevel::None &&
666}
667
668bool RISCVPassConfig::addILPOpts() {
670 addPass(&MachineCombinerID);
671
672 return true;
673}
674
679
685
688 SMDiagnostic &Error, SMRange &SourceRange) const {
689 const auto &YamlMFI =
690 static_cast<const yaml::RISCVMachineFunctionInfo &>(MFI);
691 PFS.MF.getInfo<RISCVMachineFunctionInfo>()->initializeBaseYamlFields(YamlMFI);
692 return false;
693}
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:856
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
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
This file declares the RISC-V gather/scatter lowering passes.
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.
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 ...
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:308
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.
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 ...
A raw_ostream that writes to an SmallVector or SmallString.
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.
LLVM_ABI char & EarlyMachineLICMID
This pass performs loop invariant code motion on machine instructions.
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 * 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)
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:280
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 * createRISCVGatherScatterLoweringPass()
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:75
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:149
@ Default
-O2, -Os, -Oz
Definition CodeGen.h:152
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 initializeRISCVQCRelaxMarkingPass(PassRegistry &)
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 &)
void initializeRISCVGatherScatterLoweringLegacyPass(PassRegistry &)
FunctionPass * createRISCVISelDag(RISCVTargetMachine &TM, CodeGenOptLevel OptLevel)
void initializeRISCVZacasABIFixLegacyPass(PassRegistry &)
LLVM_ABI FunctionPass * createVirtRegRewriter(bool ClearVirtRegs=true)
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:390
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 &)
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.