From 8a4bb6e3b0bffa0ed79b51347b12ee4293b622a7 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Sat, 22 Aug 2026 18:49:08 +0800 Subject: [CodeGen] Generate RISC-V macro fusion rules --- backend/lib/Tooling/PipelineDriver.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'backend/lib/Tooling/PipelineDriver.cpp') diff --git a/backend/lib/Tooling/PipelineDriver.cpp b/backend/lib/Tooling/PipelineDriver.cpp index 76951b6..0ba0c54 100644 --- a/backend/lib/Tooling/PipelineDriver.cpp +++ b/backend/lib/Tooling/PipelineDriver.cpp @@ -79,6 +79,24 @@ struct FunctionRunResult final { }); } +[[nodiscard]] bool hasDebugType(const BackendInvocation &Invocation, + std::string_view DebugType) noexcept { + const auto Option = std::ranges::find(Invocation.TargetOptions, std::string_view{"debug-only"}, + &BackendOption::Name); + if (Option == Invocation.TargetOptions.end()) + return false; + std::string_view Types = Option->Value; + while (!Types.empty()) { + const std::size_t Comma = Types.find(','); + if (Types.substr(0, Comma) == DebugType) + return true; + if (Comma == std::string_view::npos) + break; + Types.remove_prefix(Comma + 1U); + } + return false; +} + [[nodiscard]] std::optional stageAfterPass(std::string_view Pass) noexcept { if (Pass == "legalizer") return BackendStage::LegalizedMIR; @@ -108,12 +126,14 @@ createPasses(const MachineFunction &Function, const BackendInvocation &Invocatio GlobalISelAbort = *Parsed; } MachineFunctionPassManager Pipeline(Options); + const bool DebugMachineScheduler = hasDebugType(Invocation, "machine-scheduler"); if (Invocation.PassPipeline.size() == 1 && Invocation.PassPipeline.front() == "default") { auto Added = riscv::addCanonicalPipeline( Pipeline, Function, Subtarget, riscv::RISCVPipelineOptions{.Optimization = Invocation.Optimization, .UseTargetCopyInstructions = true, - .GlobalISelAbort = GlobalISelAbort}); + .GlobalISelAbort = GlobalISelAbort, + .DebugMachineScheduler = DebugMachineScheduler}); if (!Added) return std::unexpected(Added.error()); } else { @@ -130,7 +150,8 @@ createPasses(const MachineFunction &Function, const BackendInvocation &Invocatio Name, Subtarget, riscv::RISCVPipelineOptions{.Optimization = Invocation.Optimization, .UseTargetCopyInstructions = UseTargetCopyInstructions, - .GlobalISelAbort = GlobalISelAbort}); + .GlobalISelAbort = GlobalISelAbort, + .DebugMachineScheduler = DebugMachineScheduler}); if (!Pass) return std::unexpected(Pass.error()); auto Added = Pipeline.addPass(std::move(*Pass)); -- cgit v1.2.3