diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-26 23:33:07 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-26 23:33:07 +0800 |
| commit | 27c303ff00234e5ab9379878858f7ae3d0bdc2dc (patch) | |
| tree | 49639bc910abe9999f07d044ec235ce17dec3ca4 | |
| parent | a72a7a4323fb6eef8e15cc2f1229bcca14879e94 (diff) | |
| download | rcc-project-27c303ff00234e5ab9379878858f7ae3d0bdc2dc.tar.gz rcc-project-27c303ff00234e5ab9379878858f7ae3d0bdc2dc.tar.xz | |
[GlobalISel] Run machine transformations once
| -rw-r--r-- | backend/include/rcc/CodeGen/GlobalISel/Combiner.h | 3 | ||||
| -rw-r--r-- | backend/include/rcc/CodeGen/GlobalISel/InstructionSelect.h | 3 | ||||
| -rw-r--r-- | backend/include/rcc/CodeGen/GlobalISel/Legalizer.h | 3 | ||||
| -rw-r--r-- | backend/lib/CodeGen/GlobalISel/Combiner.cpp | 27 | ||||
| -rw-r--r-- | backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp | 30 | ||||
| -rw-r--r-- | backend/lib/CodeGen/GlobalISel/Legalizer.cpp | 32 |
6 files changed, 20 insertions, 78 deletions
diff --git a/backend/include/rcc/CodeGen/GlobalISel/Combiner.h b/backend/include/rcc/CodeGen/GlobalISel/Combiner.h index efb6bbf..85b68d1 100644 --- a/backend/include/rcc/CodeGen/GlobalISel/Combiner.h +++ b/backend/include/rcc/CodeGen/GlobalISel/Combiner.h @@ -35,7 +35,8 @@ public: private: [[nodiscard]] Expected<MachinePassResult> runImplementation(MachineFunction &Function, const TargetDescription &Target, - MachineActionReplay &Actions) const; + MachineFunctionAnalysisManager + &Analyses) const; const GIMatchTable *Table; const GIMatchTableExecutor *Executor; diff --git a/backend/include/rcc/CodeGen/GlobalISel/InstructionSelect.h b/backend/include/rcc/CodeGen/GlobalISel/InstructionSelect.h index f342cdc..174a943 100644 --- a/backend/include/rcc/CodeGen/GlobalISel/InstructionSelect.h +++ b/backend/include/rcc/CodeGen/GlobalISel/InstructionSelect.h @@ -21,7 +21,8 @@ public: private: [[nodiscard]] Expected<MachinePassResult> runImplementation(MachineFunction &Function, const TargetDescription &Target, - MachineActionReplay &Actions); + MachineFunctionAnalysisManager + &Analyses); const InstructionSelector *Info; }; diff --git a/backend/include/rcc/CodeGen/GlobalISel/Legalizer.h b/backend/include/rcc/CodeGen/GlobalISel/Legalizer.h index e90d09c..e75d71e 100644 --- a/backend/include/rcc/CodeGen/GlobalISel/Legalizer.h +++ b/backend/include/rcc/CodeGen/GlobalISel/Legalizer.h @@ -36,7 +36,8 @@ public: private: [[nodiscard]] Expected<MachinePassResult> runImplementation(MachineFunction &Function, const TargetDescription &Target, - MachineActionReplay &Actions); + MachineFunctionAnalysisManager + &Analyses); std::unique_ptr<LegalizerInfo> OwnedInfo; const LegalizerInfo *Info = nullptr; diff --git a/backend/lib/CodeGen/GlobalISel/Combiner.cpp b/backend/lib/CodeGen/GlobalISel/Combiner.cpp index 08b471a..c0a92cc 100644 --- a/backend/lib/CodeGen/GlobalISel/Combiner.cpp +++ b/backend/lib/CodeGen/GlobalISel/Combiner.cpp @@ -6,10 +6,8 @@ #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 <optional> #include <string> namespace rcc { @@ -21,31 +19,13 @@ const MachinePassContract &GlobalISelCombinerPass::contract() const noexcept { Expected<MachinePassResult> GlobalISelCombinerPass::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(), "GlobalISel combiner clone 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(), "GlobalISel combiner replay diverged: ")); - auto Replayed = Actions.finishReplay(); - if (!Replayed) - return std::unexpected(Replayed.error()); - return Result; + return runImplementation(Function, Target, Analyses); } Expected<MachinePassResult> GlobalISelCombinerPass::runImplementation(MachineFunction &Function, const TargetDescription &Target, - MachineActionReplay &Actions) const { + MachineFunctionAnalysisManager &Analyses) const { if (MaximumRewrites == 0 || MaximumIterations == 0) return makeUnexpected(ErrorCode::InvalidArgument, "GlobalISel combiner iteration limits must be nonzero"); @@ -61,7 +41,8 @@ GlobalISelCombinerPass::runImplementation(MachineFunction &Function, if (!Matches) return std::unexpected(Matches.error()); if (*Matches && Rewrites < MaximumRewrites) { - auto Accepted = Actions.request("gisel-combiner", Function, Instruction->stableID()); + auto Accepted = + Analyses.requestAction("gisel-combiner", Function, Instruction->stableID()); if (!Accepted) return std::unexpected(Accepted.error()); if (*Accepted) { diff --git a/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp b/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp index 66bbff2..6aab43d 100644 --- a/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp +++ b/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp @@ -6,14 +6,12 @@ #include "rcc/CodeGen/GlobalISel/Utils.h" #include "rcc/CodeGen/MachineBasicBlock.h" #include "rcc/CodeGen/MachineFunction.h" -#include "rcc/CodeGen/MachineFunctionCloner.h" #include "rcc/CodeGen/MachineInstr.h" #include "rcc/CodeGen/MachineRegisterInfo.h" #include "rcc/CodeGen/TargetDescription.h" #include <algorithm> #include <cstdint> -#include <optional> #include <string> #include <unordered_set> #include <utility> @@ -214,33 +212,13 @@ Expected<MachinePassResult> InstructionSelect::run(MachineFunction &Function, if (Info == nullptr) return std::unexpected(passFailure("instruction select has no target behavior interface", ErrorCode::InvalidArgument)); - auto Trial = cloneMachineFunction( - Function, Target, - MachineFunctionCloneOptions{.NewStableID = Function.stableID(), .NewName = std::nullopt}); - if (!Trial) { - return std::unexpected( - withErrorContext(Trial.error(), "instruction-selection transaction 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(), - "instruction selection 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> InstructionSelect::runImplementation(MachineFunction &Function, const TargetDescription &Target, - MachineActionReplay &Actions) { + MachineFunctionAnalysisManager + &Analyses) { MachinePassResult Result; std::vector<MachineInstr *> Worklist; @@ -304,7 +282,7 @@ Expected<MachinePassResult> InstructionSelect::runImplementation(MachineFunction return std::unexpected(Match.error()); std::string Rule = "select."; Rule.append(CurrentDescriptor->Name); - auto Accepted = Actions.request(Rule, Function, Instruction->stableID()); + auto Accepted = Analyses.requestAction(Rule, Function, Instruction->stableID()); if (!Accepted) return std::unexpected(Accepted.error()); if (!*Accepted) { diff --git a/backend/lib/CodeGen/GlobalISel/Legalizer.cpp b/backend/lib/CodeGen/GlobalISel/Legalizer.cpp index ca31d56..0601040 100644 --- a/backend/lib/CodeGen/GlobalISel/Legalizer.cpp +++ b/backend/lib/CodeGen/GlobalISel/Legalizer.cpp @@ -14,7 +14,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/MachineRegisterInfo.h" #include "rcc/CodeGen/TargetDescription.h" @@ -23,7 +22,6 @@ #include <array> #include <cstddef> #include <memory> -#include <optional> #include <ranges> #include <string> #include <unordered_set> @@ -262,8 +260,7 @@ Expected<MachinePassResult> Legalizer::run(MachineFunction &Function, return std::unexpected(passFailure("legalizer has an unknown GlobalISel abort mode", ErrorCode::InvalidArgument)); } - MachineActionReplay Actions(Analyses); - auto Result = runImplementation(Function, Target, Actions); + auto Result = runImplementation(Function, Target, Analyses); if (Result || Result.error().code() != ErrorCode::Unsupported) return Result; Function.properties().set(MachineFunctionProperty::FailedISel); @@ -274,30 +271,12 @@ Expected<MachinePassResult> Legalizer::run(MachineFunction &Function, }; } - auto Trial = cloneMachineFunction( - Function, Target, - MachineFunctionCloneOptions{.NewStableID = Function.stableID(), .NewName = std::nullopt}); - if (!Trial) - return std::unexpected(withErrorContext(Trial.error(), "legalizer transaction 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(), "legalizer 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> Legalizer::runImplementation(MachineFunction &Function, const TargetDescription &Target, - MachineActionReplay &Actions) { + MachineFunctionAnalysisManager &Analyses) { MachinePassResult Result; InstList InstructionWorklist; ArtifactList ArtifactWorklist; @@ -365,7 +344,8 @@ Expected<MachinePassResult> Legalizer::runImplementation(MachineFunction &Functi } if (isIntrinsicOpcode(Instruction->opcode())) { - auto Accepted = Actions.request("legalize.intrinsic", Function, Instruction->stableID()); + auto Accepted = + Analyses.requestAction("legalize.intrinsic", Function, Instruction->stableID()); if (!Accepted) return std::unexpected(Accepted.error()); if (!*Accepted) @@ -409,7 +389,7 @@ Expected<MachinePassResult> Legalizer::runImplementation(MachineFunction &Functi Rule.append(legalizationActionName(Decision->Action)); Rule.push_back('.'); Rule.append(Descriptor->Name); - auto Accepted = Actions.request(Rule, Function, Instruction->stableID()); + auto Accepted = Analyses.requestAction(Rule, Function, Instruction->stableID()); if (!Accepted) return std::unexpected(Accepted.error()); if (!*Accepted) { |
