From 175fdbf4b30eae5e5344cd7fca7e953ca0b2463e Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Thu, 13 Aug 2026 13:29:50 +0800 Subject: [Tooling] Remove the duplicate output kind --- backend/lib/Tooling/PipelineDriver.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'backend/lib/Tooling/PipelineDriver.cpp') diff --git a/backend/lib/Tooling/PipelineDriver.cpp b/backend/lib/Tooling/PipelineDriver.cpp index 68cbb57..1a584f7 100644 --- a/backend/lib/Tooling/PipelineDriver.cpp +++ b/backend/lib/Tooling/PipelineDriver.cpp @@ -34,8 +34,24 @@ struct FunctionRunResult final { std::optional Failure; }; -[[nodiscard]] unsigned stageOrdinal(BackendStage Stage) noexcept { - return static_cast(Stage); +[[nodiscard]] std::uint8_t stageRank(BackendStage Stage) noexcept { + switch (Stage) { + case BackendStage::PreLegalizerMIR: + return 0; + case BackendStage::LegalizedMIR: + return 1; + case BackendStage::RegisterBankMIR: + return 2; + case BackendStage::SelectedMIR: + return 3; + case BackendStage::PostSSAMIR: + return 4; + case BackendStage::PostRegisterAllocationMIR: + return 5; + case BackendStage::FinalMIR: + return 6; + } + return 0; } [[nodiscard]] bool selectorMatches(std::string_view Selector, std::string_view Pass, @@ -224,7 +240,7 @@ runFunction(MachineFunction &Function, mir::MIRDocument &Document, const TargetD if (!Captured) return std::unexpected(Captured.error()); } - if (Controls.StopAtStage && stageOrdinal(CurrentStage) >= stageOrdinal(*Controls.StopAtStage)) { + if (Controls.StopAtStage && !isEarlierStage(CurrentStage, *Controls.StopAtStage)) { return Result; } @@ -289,7 +305,7 @@ runFunction(MachineFunction &Function, mir::MIRDocument &Document, const TargetD StopMatched = true; break; } - if (Controls.StopAtStage && stageOrdinal(CurrentStage) >= stageOrdinal(*Controls.StopAtStage)) { + if (Controls.StopAtStage && !isEarlierStage(CurrentStage, *Controls.StopAtStage)) { break; } } @@ -314,6 +330,10 @@ runFunction(MachineFunction &Function, mir::MIRDocument &Document, const TargetD } // namespace +bool isEarlierStage(BackendStage Left, BackendStage Right) noexcept { + return stageRank(Left) < stageRank(Right); +} + BackendStage stageForFunction(const MachineFunction &Function) noexcept { const MachineFunctionProperties &Properties = Function.properties(); if (Properties.has(MachineFunctionProperty::Selected) && -- cgit v1.2.3