diff options
| -rw-r--r-- | backend/include/rcc/CodeGen/MachineBlockPlacement.h | 2 | ||||
| -rw-r--r-- | backend/include/rcc/CodeGen/MachineBranchRelaxation.h | 3 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineBlockPlacement.cpp | 26 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineBranchRelaxation.cpp | 26 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineScheduler.cpp | 63 | ||||
| -rw-r--r-- | backend/lib/CodeGen/MachineSchedulerInternal.h | 4 | ||||
| -rw-r--r-- | backend/lib/CodeGen/PostRAScheduler.cpp | 44 |
7 files changed, 30 insertions, 138 deletions
diff --git a/backend/include/rcc/CodeGen/MachineBlockPlacement.h b/backend/include/rcc/CodeGen/MachineBlockPlacement.h index 41d5f2d..557855a 100644 --- a/backend/include/rcc/CodeGen/MachineBlockPlacement.h +++ b/backend/include/rcc/CodeGen/MachineBlockPlacement.h @@ -17,7 +17,7 @@ public: private: [[nodiscard]] Expected<MachinePassResult> runImplementation(MachineFunction &Function, const TargetDescription &Target, - MachineFunctionAnalysisManager &Analyses, MachineActionReplay &Actions) const; + MachineFunctionAnalysisManager &Analyses) const; }; } // namespace rcc diff --git a/backend/include/rcc/CodeGen/MachineBranchRelaxation.h b/backend/include/rcc/CodeGen/MachineBranchRelaxation.h index 5b359b4..db3d03f 100644 --- a/backend/include/rcc/CodeGen/MachineBranchRelaxation.h +++ b/backend/include/rcc/CodeGen/MachineBranchRelaxation.h @@ -29,7 +29,8 @@ public: private: [[nodiscard]] Expected<MachinePassResult> runImplementation(MachineFunction &Function, const TargetDescription &Target, - MachineActionReplay &Actions) const; + MachineFunctionAnalysisManager + &Analyses) const; const TargetInstrInfo *Info; MachineBranchRelaxationOptions Options; diff --git a/backend/lib/CodeGen/MachineBlockPlacement.cpp b/backend/lib/CodeGen/MachineBlockPlacement.cpp index 0dbcd37..76e44d0 100644 --- a/backend/lib/CodeGen/MachineBlockPlacement.cpp +++ b/backend/lib/CodeGen/MachineBlockPlacement.cpp @@ -6,7 +6,6 @@ #include "rcc/CodeGen/MachineBasicBlock.h" #include "rcc/CodeGen/MachineBasicBlockAttributes.h" #include "rcc/CodeGen/MachineFunction.h" -#include "rcc/CodeGen/MachineFunctionCloner.h" #include <algorithm> #include <cstddef> @@ -99,31 +98,12 @@ const MachinePassContract &MachineBlockPlacementPass::contract() const noexcept Expected<MachinePassResult> MachineBlockPlacementPass::run(MachineFunction &Function, const TargetDescription &Target, MachineFunctionAnalysisManager &Analyses) { - auto Trial = cloneMachineFunction( - Function, Target, - MachineFunctionCloneOptions{.NewStableID = Function.stableID(), .NewName = std::nullopt}); - if (!Trial) - return std::unexpected(withErrorContext(Trial.error(), "block placement setup failed: ")); - MachineFunctionAnalysisManager TrialAnalyses; - MachineActionReplay Actions(Analyses, Trial->InstructionStableIDs); - auto TrialResult = runImplementation(*Trial->ClonedFunction, Target, TrialAnalyses, Actions); - if (!TrialResult) - return std::unexpected(TrialResult.error()); - Actions.beginReplay(); - auto Result = runImplementation(Function, Target, Analyses, Actions); - if (!Result) { - return std::unexpected(withErrorContext( - Result.error(), "block placement diverged after a successful transaction preflight: ")); - } - auto Replayed = Actions.finishReplay(); - if (!Replayed) - return std::unexpected(Replayed.error()); - return Result; + return runImplementation(Function, Target, Analyses); } Expected<MachinePassResult> MachineBlockPlacementPass::runImplementation( MachineFunction &Function, const TargetDescription &Target, - MachineFunctionAnalysisManager &Analyses, MachineActionReplay &Actions) const { + MachineFunctionAnalysisManager &Analyses) const { auto Probabilities = Analyses.getResult<MachineBranchProbabilityAnalysis>(Function, Target); if (!Probabilities) return std::unexpected(Probabilities.error()); @@ -224,7 +204,7 @@ Expected<MachinePassResult> MachineBlockPlacementPass::runImplementation( } } if (Changed) { - auto Accepted = Actions.request("apply-block-layout", Function); + auto Accepted = Analyses.requestAction("apply-block-layout", Function); if (!Accepted) return std::unexpected(Accepted.error()); if (!*Accepted) { diff --git a/backend/lib/CodeGen/MachineBranchRelaxation.cpp b/backend/lib/CodeGen/MachineBranchRelaxation.cpp index 83ad38c..2abc1a1 100644 --- a/backend/lib/CodeGen/MachineBranchRelaxation.cpp +++ b/backend/lib/CodeGen/MachineBranchRelaxation.cpp @@ -4,7 +4,6 @@ #include "rcc/CodeGen/MachineBasicBlock.h" #include "rcc/CodeGen/MachineFunction.h" -#include "rcc/CodeGen/MachineFunctionCloner.h" #include "rcc/CodeGen/MachineInstr.h" #include "rcc/CodeGen/TargetDescription.h" #include "rcc/CodeGen/TargetInstrInfo.h" @@ -100,31 +99,13 @@ const MachinePassContract &MachineBranchRelaxationPass::contract() const noexcep Expected<MachinePassResult> MachineBranchRelaxationPass::run(MachineFunction &Function, const TargetDescription &Target, MachineFunctionAnalysisManager &Analyses) { - auto Trial = cloneMachineFunction( - Function, Target, - MachineFunctionCloneOptions{.NewStableID = Function.stableID(), .NewName = std::nullopt}); - if (!Trial) - return std::unexpected(withErrorContext(Trial.error(), "branch relaxation setup failed: ")); - MachineActionReplay Actions(Analyses, Trial->InstructionStableIDs); - auto TrialResult = runImplementation(*Trial->ClonedFunction, Target, Actions); - if (!TrialResult) - return std::unexpected(TrialResult.error()); - Actions.beginReplay(); - auto Result = runImplementation(Function, Target, Actions); - if (!Result) { - return std::unexpected(withErrorContext( - Result.error(), "branch relaxation diverged after a successful transaction preflight: ")); - } - auto Replayed = Actions.finishReplay(); - if (!Replayed) - return std::unexpected(Replayed.error()); - return Result; + return runImplementation(Function, Target, Analyses); } Expected<MachinePassResult> MachineBranchRelaxationPass::runImplementation(MachineFunction &Function, const TargetDescription &Target, - MachineActionReplay &Actions) const { + MachineFunctionAnalysisManager &Analyses) const { if (Options.ConvergenceWatchdog == 0) return makeUnexpected(ErrorCode::InvalidArgument, "branch relaxation watchdog must be nonzero"); MachinePassResult Result; @@ -154,7 +135,8 @@ MachineBranchRelaxationPass::runImplementation(MachineFunction &Function, return std::unexpected(Offset.error()); if (Info->isBranchOffsetInRange(*Instruction, *Offset)) continue; - auto Accepted = Actions.request("relax-branch", Function, Instruction->stableID()); + auto Accepted = + Analyses.requestAction("relax-branch", Function, Instruction->stableID()); if (!Accepted) return std::unexpected(Accepted.error()); if (!*Accepted) { diff --git a/backend/lib/CodeGen/MachineScheduler.cpp b/backend/lib/CodeGen/MachineScheduler.cpp index 302173f..dfc7b24 100644 --- a/backend/lib/CodeGen/MachineScheduler.cpp +++ b/backend/lib/CodeGen/MachineScheduler.cpp @@ -7,7 +7,6 @@ #include "rcc/CodeGen/LiveVariables.h" #include "rcc/CodeGen/MachineBasicBlock.h" #include "rcc/CodeGen/MachineFunction.h" -#include "rcc/CodeGen/MachineFunctionCloner.h" #include "rcc/CodeGen/MachineInstr.h" #include "rcc/CodeGen/RegisterPressure.h" #include "rcc/CodeGen/ScheduleDAG.h" @@ -129,7 +128,7 @@ scheduleDAG(const ScheduleDAG &DAG, const MachineFunction &Function, const TargetDescription &Target, const TargetSchedulingModel &Model, ScheduleDAGMode Mode, const MachineBlockLiveness &Liveness, std::uint64_t BlockFrequency, bool EnableBidirectionalScheduling, - MachineActionReplay *Actions) { + MachineFunctionAnalysisManager &Analyses) { auto TopPressure = RegisterPressureTracker::create(DAG, Function, Target, Model, Mode, Liveness, RegisterPressureDirection::TopDown); if (!TopPressure) @@ -216,14 +215,12 @@ scheduleDAG(const ScheduleDAG &DAG, const MachineFunction &Function, } const ScheduleUnit &Selected = DAG.units()[Best->Unit]; - if (Actions != nullptr) { - auto Accepted = Actions->request(Best->Bottom ? "schedule-bottom" : "schedule-top", Function, - Selected.StableID); - if (!Accepted) - return std::unexpected(Accepted.error()); - if (!*Accepted) - return std::vector<std::size_t>{}; - } + auto Accepted = Analyses.requestAction(Best->Bottom ? "schedule-bottom" : "schedule-top", + Function, Selected.StableID); + if (!Accepted) + return std::unexpected(Accepted.error()); + if (!*Accepted) + return std::vector<std::size_t>{}; Scheduled[Best->Unit] = true; if (Best->Bottom) { auto Issued = BottomHazards->issue(Selected, Best->Cycle); @@ -273,7 +270,7 @@ scheduleRegion(MachineBasicBlock &Block, std::span<MachineInstr *const> Instruct MachineFunction &Function, const TargetDescription &Target, const TargetSchedulingModel &Model, ScheduleDAGMode Mode, const MachineBlockLiveness &Liveness, std::uint64_t BlockFrequency, - MachineSchedulerOptions Options, MachineActionReplay *Actions) { + MachineSchedulerOptions Options, MachineFunctionAnalysisManager &Analyses) { if (Instructions.size() < 2 || Instructions.size() > Options.MaximumRegionSize) return false; if (Options.EmitDebugOutput) { @@ -286,7 +283,7 @@ scheduleRegion(MachineBasicBlock &Block, std::span<MachineInstr *const> Instruct if (DAG->units().size() < 2) return false; auto UnitOrder = scheduleDAG(*DAG, Function, Target, Model, Mode, Liveness, BlockFrequency, - Options.EnableBidirectionalScheduling, Actions); + Options.EnableBidirectionalScheduling, Analyses); if (!UnitOrder) return std::unexpected(UnitOrder.error()); if (UnitOrder->empty()) @@ -326,7 +323,8 @@ runMachineScheduler(MachineFunction &Function, const TargetDescription &Target, const TargetSchedulingModel &Model, ScheduleDAGMode Mode, const LiveVariablesAnalysis::Result &Liveness, const MachineBlockFrequencyAnalysis::Result &Frequencies, - MachineSchedulerOptions Options, MachineActionReplay *Actions) { + MachineSchedulerOptions Options, + MachineFunctionAnalysisManager &Analyses) { if (Options.MaximumRegionSize == 0) { return makeUnexpected(ErrorCode::InvalidArgument, "machine scheduler region budget must be nonzero"); @@ -342,7 +340,7 @@ runMachineScheduler(MachineFunction &Function, const TargetDescription &Target, std::vector<MachineInstr *> Region; auto FlushRegion = [&]() -> Expected<void> { auto Changed = scheduleRegion(*Block, Region, Function, Target, Model, Mode, *BlockLiveness, - Frequencies.frequency(*Block), Options, Actions); + Frequencies.frequency(*Block), Options, Analyses); if (!Changed) return std::unexpected(Changed.error()); BlockChanged |= *Changed; @@ -401,47 +399,16 @@ const MachinePassContract &MachineSchedulerPass::contract() const noexcept { Expected<MachinePassResult> MachineSchedulerPass::run(MachineFunction &Function, const TargetDescription &Target, MachineFunctionAnalysisManager &Analyses) { - auto Trial = cloneMachineFunction( - Function, Target, - MachineFunctionCloneOptions{.NewStableID = Function.stableID(), .NewName = std::nullopt}); - if (!Trial) { - return std::unexpected( - withErrorContext(Trial.error(), "machine scheduler transaction setup failed: ")); - } - MachineFunctionAnalysisManager TrialAnalyses; - auto TrialLiveness = - TrialAnalyses.getResult<LiveVariablesAnalysis>(*Trial->ClonedFunction, Target); - if (!TrialLiveness) - return std::unexpected(TrialLiveness.error()); - auto TrialFrequencies = - TrialAnalyses.getResult<MachineBlockFrequencyAnalysis>(*Trial->ClonedFunction, Target); - if (!TrialFrequencies) - return std::unexpected(TrialFrequencies.error()); - MachineActionReplay Actions(Analyses, Trial->InstructionStableIDs); - MachineSchedulerOptions TrialOptions = Options; - TrialOptions.EmitDebugOutput = false; - auto TrialResult = runMachineScheduler(*Trial->ClonedFunction, Target, *Model, - ScheduleDAGMode::PreRegisterAllocation, **TrialLiveness, - **TrialFrequencies, TrialOptions, &Actions); - if (!TrialResult) - return std::unexpected(TrialResult.error()); - auto Liveness = Analyses.getResult<LiveVariablesAnalysis>(Function, Target); if (!Liveness) return std::unexpected(Liveness.error()); auto Frequencies = Analyses.getResult<MachineBlockFrequencyAnalysis>(Function, Target); if (!Frequencies) return std::unexpected(Frequencies.error()); - Actions.beginReplay(); auto Run = runMachineScheduler(Function, Target, *Model, ScheduleDAGMode::PreRegisterAllocation, - **Liveness, **Frequencies, Options, &Actions); - if (!Run) { - return std::unexpected(withErrorContext( - Run.error(), "machine scheduler diverged after a successful transaction preflight: ")); - } - auto Replayed = Actions.finishReplay(); - if (!Replayed) - return std::unexpected(Replayed.error()); + **Liveness, **Frequencies, Options, Analyses); + if (!Run) + return std::unexpected(Run.error()); MachinePassResult Result; Result.Changed = Run->Changed; diff --git a/backend/lib/CodeGen/MachineSchedulerInternal.h b/backend/lib/CodeGen/MachineSchedulerInternal.h index 1815eaa..999937c 100644 --- a/backend/lib/CodeGen/MachineSchedulerInternal.h +++ b/backend/lib/CodeGen/MachineSchedulerInternal.h @@ -16,7 +16,6 @@ namespace rcc { class MachineBasicBlock; -class MachineActionReplay; class MachineFunction; class TargetDescription; class TargetSchedulingModel; @@ -30,7 +29,8 @@ runMachineScheduler(MachineFunction &Function, const TargetDescription &Target, const TargetSchedulingModel &Model, ScheduleDAGMode Mode, const LiveVariablesAnalysis::Result &Liveness, const MachineBlockFrequencyAnalysis::Result &Frequencies, - MachineSchedulerOptions Options, MachineActionReplay *Actions = nullptr); + MachineSchedulerOptions Options, + MachineFunctionAnalysisManager &Analyses); } // namespace rcc diff --git a/backend/lib/CodeGen/PostRAScheduler.cpp b/backend/lib/CodeGen/PostRAScheduler.cpp index 7f5c697..d8c6a36 100644 --- a/backend/lib/CodeGen/PostRAScheduler.cpp +++ b/backend/lib/CodeGen/PostRAScheduler.cpp @@ -7,7 +7,6 @@ #include "rcc/CodeGen/LiveVariables.h" #include "rcc/CodeGen/MachineBasicBlock.h" #include "rcc/CodeGen/MachineFunction.h" -#include "rcc/CodeGen/MachineFunctionCloner.h" #include "rcc/CodeGen/MachineInstr.h" #include "rcc/CodeGen/MachineOperand.h" #include "rcc/CodeGen/RegisterMask.h" @@ -19,9 +18,7 @@ #include <bit> #include <cstddef> #include <cstdint> -#include <optional> #include <ranges> -#include <string> #include <utility> #include <vector> @@ -56,51 +53,16 @@ const MachinePassContract &PostRASchedulerPass::contract() const noexcept { Expected<MachinePassResult> PostRASchedulerPass::run(MachineFunction &Function, const TargetDescription &Target, MachineFunctionAnalysisManager &Analyses) { - auto Trial = cloneMachineFunction( - Function, Target, - MachineFunctionCloneOptions{.NewStableID = Function.stableID(), .NewName = std::nullopt}); - if (!Trial) { - return std::unexpected( - withErrorContext(Trial.error(), "post-RA scheduler transaction setup failed: ")); - } - MachineFunctionAnalysisManager TrialAnalyses; - auto TrialLiveness = - TrialAnalyses.getResult<LiveVariablesAnalysis>(*Trial->ClonedFunction, Target); - if (!TrialLiveness) - return std::unexpected(TrialLiveness.error()); - auto TrialFrequencies = - TrialAnalyses.getResult<MachineBlockFrequencyAnalysis>(*Trial->ClonedFunction, Target); - if (!TrialFrequencies) - return std::unexpected(TrialFrequencies.error()); - MachineActionReplay Actions(Analyses, Trial->InstructionStableIDs); - MachineSchedulerOptions TrialOptions = Options; - TrialOptions.EmitDebugOutput = false; - auto TrialRun = runMachineScheduler(*Trial->ClonedFunction, Target, *Model, - ScheduleDAGMode::PostRegisterAllocation, **TrialLiveness, - **TrialFrequencies, TrialOptions, &Actions); - if (!TrialRun) - return std::unexpected(TrialRun.error()); - auto TrialRepair = - repairPostRAMachineBlockLiveness(TrialRun->ChangedBlocks, Target, **TrialLiveness); - if (!TrialRepair) - return std::unexpected(TrialRepair.error()); - auto Liveness = Analyses.getResult<LiveVariablesAnalysis>(Function, Target); if (!Liveness) return std::unexpected(Liveness.error()); auto Frequencies = Analyses.getResult<MachineBlockFrequencyAnalysis>(Function, Target); if (!Frequencies) return std::unexpected(Frequencies.error()); - Actions.beginReplay(); auto Run = runMachineScheduler(Function, Target, *Model, ScheduleDAGMode::PostRegisterAllocation, - **Liveness, **Frequencies, Options, &Actions); - if (!Run) { - return std::unexpected(withErrorContext( - Run.error(), "post-RA scheduler diverged after a successful transaction preflight: ")); - } - auto Replayed = Actions.finishReplay(); - if (!Replayed) - return std::unexpected(Replayed.error()); + **Liveness, **Frequencies, Options, Analyses); + if (!Run) + return std::unexpected(Run.error()); auto Repaired = repairPostRAMachineBlockLiveness(Run->ChangedBlocks, Target, **Liveness); if (!Repaired) return std::unexpected(Repaired.error()); |
