LLVM 22.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"
30#include "llvm/CodeGen/Passes.h"
39#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
142}
143
144static std::string computeDataLayout(const Triple &TT,
145 const TargetOptions &Opts) {
146 std::string Ret;
147
148 if (TT.isLittleEndian())
149 Ret += "e";
150 else
151 Ret += "E";
152
153 Ret += "-m:e";
154
155 // Pointer and integer sizes.
156 if (TT.isArch64Bit()) {
157 Ret += "-p:64:64-i64:64-i128:128";
158 Ret += "-n32:64";
159 } else {
160 assert(TT.isArch32Bit() && "only RV32 and RV64 are currently supported");
161 Ret += "-p:32:32-i64:64";
162 Ret += "-n32";
163 }
164
165 // Stack alignment based on ABI.
166 StringRef ABI = Opts.MCOptions.getABIName();
167 if (ABI == "ilp32e")
168 Ret += "-S32";
169 else if (ABI == "lp64e")
170 Ret += "-S64";
171 else
172 Ret += "-S128";
173
174 return Ret;
175}
176
178 std::optional<Reloc::Model> RM) {
179 return RM.value_or(Reloc::Static);
180}
181
183 StringRef CPU, StringRef FS,
184 const TargetOptions &Options,
185 std::optional<Reloc::Model> RM,
186 std::optional<CodeModel::Model> CM,
187 CodeGenOptLevel OL, bool JIT)
190 getEffectiveCodeModel(CM, CodeModel::Small), OL),
191 TLOF(std::make_unique<RISCVELFTargetObjectFile>()) {
192 initAsmInfo();
193
194 // RISC-V supports the MachineOutliner.
195 setMachineOutliner(true);
197
198 if (TT.isOSFuchsia() && !TT.isArch64Bit())
199 report_fatal_error("Fuchsia is only supported for 64-bit");
200
201 setCFIFixup(true);
202}
203
204const RISCVSubtarget *
206 Attribute CPUAttr = F.getFnAttribute("target-cpu");
207 Attribute TuneAttr = F.getFnAttribute("tune-cpu");
208 Attribute FSAttr = F.getFnAttribute("target-features");
209
210 std::string CPU =
211 CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
212 std::string TuneCPU =
213 TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU;
214 std::string FS =
215 FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
216
217 unsigned RVVBitsMin = RVVVectorBitsMinOpt;
218 unsigned RVVBitsMax = RVVVectorBitsMaxOpt;
219
220 Attribute VScaleRangeAttr = F.getFnAttribute(Attribute::VScaleRange);
221 if (VScaleRangeAttr.isValid()) {
222 if (!RVVVectorBitsMinOpt.getNumOccurrences())
223 RVVBitsMin = VScaleRangeAttr.getVScaleRangeMin() * RISCV::RVVBitsPerBlock;
224 std::optional<unsigned> VScaleMax = VScaleRangeAttr.getVScaleRangeMax();
225 if (VScaleMax.has_value() && !RVVVectorBitsMaxOpt.getNumOccurrences())
226 RVVBitsMax = *VScaleMax * RISCV::RVVBitsPerBlock;
227 }
228
229 if (RVVBitsMin != -1U) {
230 // FIXME: Change to >= 32 when VLEN = 32 is supported.
231 assert((RVVBitsMin == 0 || (RVVBitsMin >= 64 && RVVBitsMin <= 65536 &&
232 isPowerOf2_32(RVVBitsMin))) &&
233 "V or Zve* extension requires vector length to be in the range of "
234 "64 to 65536 and a power 2!");
235 assert((RVVBitsMax >= RVVBitsMin || RVVBitsMax == 0) &&
236 "Minimum V extension vector length should not be larger than its "
237 "maximum!");
238 }
239 assert((RVVBitsMax == 0 || (RVVBitsMax >= 64 && RVVBitsMax <= 65536 &&
240 isPowerOf2_32(RVVBitsMax))) &&
241 "V or Zve* extension requires vector length to be in the range of "
242 "64 to 65536 and a power 2!");
243
244 if (RVVBitsMin != -1U) {
245 if (RVVBitsMax != 0) {
246 RVVBitsMin = std::min(RVVBitsMin, RVVBitsMax);
247 RVVBitsMax = std::max(RVVBitsMin, RVVBitsMax);
248 }
249
250 RVVBitsMin = llvm::bit_floor(
251 (RVVBitsMin < 64 || RVVBitsMin > 65536) ? 0 : RVVBitsMin);
252 }
253 RVVBitsMax =
254 llvm::bit_floor((RVVBitsMax < 64 || RVVBitsMax > 65536) ? 0 : RVVBitsMax);
255
257 raw_svector_ostream(Key) << "RVVMin" << RVVBitsMin << "RVVMax" << RVVBitsMax
258 << CPU << TuneCPU << FS;
259 auto &I = SubtargetMap[Key];
260 if (!I) {
261 // This needs to be done before we create a new subtarget since any
262 // creation will depend on the TM and the code generation flags on the
263 // function that reside in TargetOptions.
265 auto ABIName = Options.MCOptions.getABIName();
266 if (const MDString *ModuleTargetABI = dyn_cast_or_null<MDString>(
267 F.getParent()->getModuleFlag("target-abi"))) {
268 auto TargetABI = RISCVABI::getTargetABI(ABIName);
269 if (TargetABI != RISCVABI::ABI_Unknown &&
270 ModuleTargetABI->getString() != ABIName) {
271 report_fatal_error("-target-abi option != target-abi module flag");
272 }
273 ABIName = ModuleTargetABI->getString();
274 }
275 I = std::make_unique<RISCVSubtarget>(
276 TargetTriple, CPU, TuneCPU, FS, ABIName, RVVBitsMin, RVVBitsMax, *this);
277 }
278 return I.get();
279}
280
282 BumpPtrAllocator &Allocator, const Function &F,
283 const TargetSubtargetInfo *STI) const {
284 return RISCVMachineFunctionInfo::create<RISCVMachineFunctionInfo>(
285 Allocator, F, static_cast<const RISCVSubtarget *>(STI));
286}
287
290 return TargetTransformInfo(std::make_unique<RISCVTTIImpl>(this, F));
291}
292
293// A RISC-V hart has a single byte-addressable address space of 2^XLEN bytes
294// for all memory accesses, so it is reasonable to assume that an
295// implementation has no-op address space casts. If an implementation makes a
296// change to this, they can override it here.
298 unsigned DstAS) const {
299 return true;
300}
301
304 const RISCVSubtarget &ST = C->MF->getSubtarget<RISCVSubtarget>();
306
307 if (ST.enableMISchedLoadClustering())
308 DAG->addMutation(createLoadClusterDAGMutation(
309 DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
310
311 if (ST.enableMISchedStoreClustering())
312 DAG->addMutation(createStoreClusterDAGMutation(
313 DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
314
315 if (!DisableVectorMaskMutation && ST.hasVInstructions())
316 DAG->addMutation(createRISCVVectorMaskDAGMutation(DAG->TRI));
317
318 return DAG;
319}
320
323 const RISCVSubtarget &ST = C->MF->getSubtarget<RISCVSubtarget>();
325
326 if (ST.enablePostMISchedLoadClustering())
327 DAG->addMutation(createLoadClusterDAGMutation(
328 DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
329
330 if (ST.enablePostMISchedStoreClustering())
331 DAG->addMutation(createStoreClusterDAGMutation(
332 DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
333
334 return DAG;
335}
336
337namespace {
338
339class RVVRegisterRegAlloc : public RegisterRegAllocBase<RVVRegisterRegAlloc> {
340public:
341 RVVRegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
342 : RegisterRegAllocBase(N, D, C) {}
343};
344
345static bool onlyAllocateRVVReg(const TargetRegisterInfo &TRI,
347 const Register Reg) {
348 const TargetRegisterClass *RC = MRI.getRegClass(Reg);
350}
351
352static FunctionPass *useDefaultRegisterAllocator() { return nullptr; }
353
354static llvm::once_flag InitializeDefaultRVVRegisterAllocatorFlag;
355
356/// -riscv-rvv-regalloc=<fast|basic|greedy> command line option.
357/// This option could designate the rvv register allocator only.
358/// For example: -riscv-rvv-regalloc=basic
359static cl::opt<RVVRegisterRegAlloc::FunctionPassCtor, false,
361 RVVRegAlloc("riscv-rvv-regalloc", cl::Hidden,
363 cl::desc("Register allocator to use for RVV register."));
364
365static void initializeDefaultRVVRegisterAllocatorOnce() {
366 RegisterRegAlloc::FunctionPassCtor Ctor = RVVRegisterRegAlloc::getDefault();
367
368 if (!Ctor) {
369 Ctor = RVVRegAlloc;
370 RVVRegisterRegAlloc::setDefault(RVVRegAlloc);
371 }
372}
373
374static FunctionPass *createBasicRVVRegisterAllocator() {
375 return createBasicRegisterAllocator(onlyAllocateRVVReg);
376}
377
378static FunctionPass *createGreedyRVVRegisterAllocator() {
379 return createGreedyRegisterAllocator(onlyAllocateRVVReg);
380}
381
382static FunctionPass *createFastRVVRegisterAllocator() {
383 return createFastRegisterAllocator(onlyAllocateRVVReg, false);
384}
385
386static RVVRegisterRegAlloc basicRegAllocRVVReg("basic",
387 "basic register allocator",
388 createBasicRVVRegisterAllocator);
389static RVVRegisterRegAlloc
390 greedyRegAllocRVVReg("greedy", "greedy register allocator",
391 createGreedyRVVRegisterAllocator);
392
393static RVVRegisterRegAlloc fastRegAllocRVVReg("fast", "fast register allocator",
394 createFastRVVRegisterAllocator);
395
396class RISCVPassConfig : public TargetPassConfig {
397public:
398 RISCVPassConfig(RISCVTargetMachine &TM, PassManagerBase &PM)
399 : TargetPassConfig(TM, PM) {
400 if (TM.getOptLevel() != CodeGenOptLevel::None)
401 substitutePass(&PostRASchedulerID, &PostMachineSchedulerID);
402 setEnableSinkAndFold(EnableSinkFold);
403 EnableLoopTermFold = true;
404 }
405
406 RISCVTargetMachine &getRISCVTargetMachine() const {
407 return getTM<RISCVTargetMachine>();
408 }
409
410 void addIRPasses() override;
411 bool addPreISel() override;
412 void addCodeGenPrepare() override;
413 bool addInstSelector() override;
414 bool addIRTranslator() override;
415 void addPreLegalizeMachineIR() override;
416 bool addLegalizeMachineIR() override;
417 void addPreRegBankSelect() override;
418 bool addRegBankSelect() override;
419 bool addGlobalInstructionSelect() override;
420 void addPreEmitPass() override;
421 void addPreEmitPass2() override;
422 void addPreSched2() override;
423 void addMachineSSAOptimization() override;
424 FunctionPass *createRVVRegAllocPass(bool Optimized);
425 bool addRegAssignAndRewriteFast() override;
426 bool addRegAssignAndRewriteOptimized() override;
427 void addPreRegAlloc() override;
428 void addPostRegAlloc() override;
429 void addFastRegAlloc() override;
430
431 std::unique_ptr<CSEConfigBase> getCSEConfig() const override;
432};
433} // namespace
434
436 return new RISCVPassConfig(*this, PM);
437}
438
439std::unique_ptr<CSEConfigBase> RISCVPassConfig::getCSEConfig() const {
440 return getStandardCSEConfigForOpt(TM->getOptLevel());
441}
442
443FunctionPass *RISCVPassConfig::createRVVRegAllocPass(bool Optimized) {
444 // Initialize the global default.
445 llvm::call_once(InitializeDefaultRVVRegisterAllocatorFlag,
446 initializeDefaultRVVRegisterAllocatorOnce);
447
448 RegisterRegAlloc::FunctionPassCtor Ctor = RVVRegisterRegAlloc::getDefault();
449 if (Ctor != useDefaultRegisterAllocator)
450 return Ctor();
451
452 if (Optimized)
453 return createGreedyRVVRegisterAllocator();
454
455 return createFastRVVRegisterAllocator();
456}
457
458bool RISCVPassConfig::addRegAssignAndRewriteFast() {
459 addPass(createRVVRegAllocPass(false));
461 if (TM->getOptLevel() != CodeGenOptLevel::None &&
465}
466
467bool RISCVPassConfig::addRegAssignAndRewriteOptimized() {
468 addPass(createRVVRegAllocPass(true));
469 addPass(createVirtRegRewriter(false));
471 if (TM->getOptLevel() != CodeGenOptLevel::None &&
475}
476
477void RISCVPassConfig::addIRPasses() {
480
481 if (getOptLevel() != CodeGenOptLevel::None) {
484
488 }
489
491}
492
493bool RISCVPassConfig::addPreISel() {
494 if (TM->getOptLevel() != CodeGenOptLevel::None) {
495 // Add a barrier before instruction selection so that we will not get
496 // deleted block address after enabling default outlining. See D99707 for
497 // more details.
498 addPass(createBarrierNoopPass());
499 }
500
501 if ((TM->getOptLevel() != CodeGenOptLevel::None &&
504 // FIXME: Like AArch64, we disable extern global merging by default due to
505 // concerns it might regress some workloads. Unlike AArch64, we don't
506 // currently support enabling the pass in an "OnlyOptimizeForSize" mode.
507 // Investigating and addressing both items are TODO.
508 addPass(createGlobalMergePass(TM, /* MaxOffset */ 2047,
509 /* OnlyOptimizeForSize */ false,
510 /* MergeExternalByDefault */ true));
511 }
512
513 return false;
514}
515
516void RISCVPassConfig::addCodeGenPrepare() {
517 if (getOptLevel() != CodeGenOptLevel::None)
520}
521
522bool RISCVPassConfig::addInstSelector() {
523 addPass(createRISCVISelDag(getRISCVTargetMachine(), getOptLevel()));
524
525 return false;
526}
527
528bool RISCVPassConfig::addIRTranslator() {
529 addPass(new IRTranslator(getOptLevel()));
530 return false;
531}
532
533void RISCVPassConfig::addPreLegalizeMachineIR() {
534 if (getOptLevel() == CodeGenOptLevel::None) {
536 } else {
538 }
539}
540
541bool RISCVPassConfig::addLegalizeMachineIR() {
542 addPass(new Legalizer());
543 return false;
544}
545
546void RISCVPassConfig::addPreRegBankSelect() {
547 if (getOptLevel() != CodeGenOptLevel::None)
549}
550
551bool RISCVPassConfig::addRegBankSelect() {
552 addPass(new RegBankSelect());
553 return false;
554}
555
556bool RISCVPassConfig::addGlobalInstructionSelect() {
557 addPass(new InstructionSelect(getOptLevel()));
558 return false;
559}
560
561void RISCVPassConfig::addPreSched2() {
563
564 // Emit KCFI checks for indirect calls.
565 addPass(createKCFIPass());
566 if (TM->getOptLevel() != CodeGenOptLevel::None)
568}
569
570void RISCVPassConfig::addPreEmitPass() {
571 // TODO: It would potentially be better to schedule copy propagation after
572 // expanding pseudos (in addPreEmitPass2). However, performing copy
573 // propagation after the machine outliner (which runs after addPreEmitPass)
574 // currently leads to incorrect code-gen, where copies to registers within
575 // outlined functions are removed erroneously.
576 if (TM->getOptLevel() >= CodeGenOptLevel::Default &&
579 if (TM->getOptLevel() >= CodeGenOptLevel::Default)
581 // The IndirectBranchTrackingPass inserts lpad and could have changed the
582 // basic block alignment. It must be done before Branch Relaxation to
583 // prevent the adjusted offset exceeding the branch range.
585 addPass(&BranchRelaxationPassID);
587}
588
589void RISCVPassConfig::addPreEmitPass2() {
590 if (TM->getOptLevel() != CodeGenOptLevel::None) {
591 addPass(createRISCVMoveMergePass());
592 // Schedule PushPop Optimization before expansion of Pseudo instruction,
593 // ensuring return instruction is detected correctly.
595 }
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.
604 addPass(createUnpackMachineBundles([&](const MachineFunction &MF) {
605 return MF.getFunction().getParent()->getModuleFlag("kcfi");
606 }));
607}
608
609void RISCVPassConfig::addMachineSSAOptimization() {
612
614
616 addPass(&MachineCombinerID);
617
618 if (TM->getTargetTriple().isRISCV64()) {
619 addPass(createRISCVOptWInstrsPass());
620 }
621}
622
623void RISCVPassConfig::addPreRegAlloc() {
625 if (TM->getOptLevel() != CodeGenOptLevel::None) {
628 }
629
633
634 if (TM->getOptLevel() != CodeGenOptLevel::None && EnableMachinePipeliner)
635 addPass(&MachinePipelinerID);
636
638}
639
640void RISCVPassConfig::addFastRegAlloc() {
641 addPass(&InitUndefID);
643}
644
645
646void RISCVPassConfig::addPostRegAlloc() {
647 if (TM->getOptLevel() != CodeGenOptLevel::None &&
650}
651
654 OptimizationLevel Level) {
656 });
657}
658
662}
663
666 const auto *MFI = MF.getInfo<RISCVMachineFunctionInfo>();
667 return new yaml::RISCVMachineFunctionInfo(*MFI);
668}
669
672 SMDiagnostic &Error, SMRange &SourceRange) const {
673 const auto &YamlMFI =
674 static_cast<const yaml::RISCVMachineFunctionInfo &>(MFI);
675 PFS.MF.getInfo<RISCVMachineFunctionInfo>()->initializeBaseYamlFields(YamlMFI);
676 return false;
677}
unsigned const MachineRegisterInfo * MRI
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 > 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 const Function * getParent(const Value *V)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Provides analysis for continuously CSEing during GISel passes.
#define LLVM_ABI
Definition: Compiler.h:213
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:132
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static cl::opt< bool > EnableGlobalMerge("enable-global-merge", cl::Hidden, cl::desc("Enable the global merge pass"), cl::init(true))
This file declares the IRTranslator pass.
static LVOptions Options
Definition: LVOptions.cpp:25
static std::string computeDataLayout()
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Register const TargetRegisterInfo * TRI
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
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 Reloc::Model getEffectiveRelocModel(const Triple &TT, std::optional< Reloc::Model > RM)
static cl::opt< bool > EnableMachineCombiner("riscv-enable-machine-combiner", cl::desc("Enable the machine combiner pass"), cl::init(true), cl::Hidden)
This file defines a TargetTransformInfoImplBase conforming object specific to the RISC-V target machi...
Basic Register Allocator
This file describes the interface of the MachineFunctionPass responsible for assigning the generic vi...
static FunctionPass * useDefaultRegisterAllocator()
-regalloc=... command line option.
Target-Independent Code Generator Pass Configuration Options pass.
This pass exposes codegen information to IR-level passes.
LLVM_ABI std::optional< unsigned > getVScaleRangeMax() const
Returns the maximum value for the vscale_range attribute or std::nullopt when unknown.
Definition: Attributes.cpp:474
LLVM_ABI unsigned getVScaleRangeMin() const
Returns the minimum value for the vscale_range attribute.
Definition: Attributes.cpp:468
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:400
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition: Attributes.h:223
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
implements a set of functionality in the TargetMachine class for targets that make use of the indepen...
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
This pass is responsible for selecting generic machine instructions to target-specific instructions.
LLVM_ABI StringRef getABIName() const
getABIName - If this returns a non-empty string this represents the textual name of the ABI that we w...
A single uniqued string.
Definition: Metadata.h:720
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,...
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:110
void registerLateLoopOptimizationsEPCallback(const std::function< void(LoopPassManager &, OptimizationLevel)> &C)
Register a callback for a default optimizer pipeline extension point.
Definition: PassBuilder.h:431
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This implementation is used for RISC-V ELF targets.
RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo and contains private RISCV-...
yaml::MachineFunctionInfo * createDefaultFuncInfoYAML() const override
Allocate and return a default initialized instance of the YAML representation for the MachineFunction...
RISCVTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL, bool JIT)
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
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.
Definition: RegBankSelect.h:91
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:19
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:282
Represents a range in source code.
Definition: SMLoc.h:48
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
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:233
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::string TargetFS
std::string TargetCPU
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions Options
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
MCTargetOptions MCOptions
Machine level options.
Target-Independent Code Generator Pass Configuration Options.
virtual void addCodeGenPrepare()
Add pass to prepare the LLVM IR for code generation.
virtual bool addRegAssignAndRewriteFast()
Add core register allocator passes which do the actual register assignment and rewriting.
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
virtual void addFastRegAlloc()
addFastRegAlloc - Add the minimum set of target-independent passes that are required for fast registe...
virtual void addMachineSSAOptimization()
addMachineSSAOptimization - Add standard passes that optimize machine instructions in SSA form.
virtual bool addRegAssignAndRewriteOptimized()
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
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.
Definition: raw_ostream.h:692
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)
Definition: CommandLine.h:444
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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
Definition: InitUndef.cpp:105
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 * createRISCVExpandAtomicPseudoPass()
FunctionPass * createRISCVPostRAExpandPseudoPass()
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:89
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.
FunctionPass * createRISCVPostLegalizerCombiner()
LLVM_ABI char & MachineCombinerID
This pass performs instruction combining using trace metrics to estimate critical-path and resource d...
void initializeRISCVPostRAExpandPseudoPass(PassRegistry &)
CodeModel::Model getEffectiveCodeModel(std::optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:288
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 * 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:61
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:167
void initializeRISCVInsertReadWriteCSRPass(PassRegistry &)
void initializeRISCVExpandAtomicPseudoPass(PassRegistry &)
FunctionPass * createRISCVPreLegalizerCombiner()
FunctionPass * createRISCVVMV0EliminationPass()
FunctionPass * createRISCVInsertVSETVLIPass()
Returns an instance of the Insert VSETVLI pass.
FunctionPass * createRISCVO0PreLegalizerCombiner()
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:82
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.
Definition: GlobalISel.cpp:17
LLVM_ABI void initializeKCFIPass(PassRegistry &)
void initializeRISCVMakeCompressibleOptPass(PassRegistry &)
FunctionPass * createRISCVCodeGenPreparePass()
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 &)
LLVM_ABI FunctionPass * createUnpackMachineBundles(std::function< bool(const MachineFunction &)> Ftor)
void initializeRISCVCodeGenPreparePass(PassRegistry &)
FunctionPass * createRISCVLateBranchOptPass()
Target & getTheRISCV64Target()
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 initializeRISCVAsmPrinterPass(PassRegistry &)
FunctionPass * createRISCVISelDag(RISCVTargetMachine &TM, CodeGenOptLevel OptLevel)
LLVM_ABI FunctionPass * createVirtRegRewriter(bool ClearVirtRegs=true)
Definition: VirtRegMap.cpp:782
void initializeRISCVGatherScatterLoweringPass(PassRegistry &)
FunctionPass * createRISCVExpandPseudoPass()
FunctionPass * createRISCVPreRAExpandPseudoPass()
LLVM_ABI FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
Definition: bit.h:280
FunctionPass * createRISCVInsertWriteVXRMPass()
LLVM_ABI MachineFunctionPass * createMachineCopyPropagationPass(bool UseCopyInstr)
void initializeRISCVVectorPeepholePass(PassRegistry &)
FunctionPass * createRISCVZacasABIFixPass()
void initializeRISCVPreRAExpandPseudoPass(PassRegistry &)
Target & getTheRISCV32beTarget()
void initializeRISCVPostLegalizerCombinerPass(PassRegistry &)
void initializeRISCVMoveMergePass(PassRegistry &)
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
#define N
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
static bool isRVVRegClass(const TargetRegisterClass *RC)
RegisterTargetMachine - Helper template for registering a target machine implementation,...
The llvm::once_flag structure.
Definition: Threading.h:67
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.