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