diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-26 23:36:30 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-26 23:36:30 +0800 |
| commit | 35f4e0a3aa03dfae06b5c9f226e38e609de2eef5 (patch) | |
| tree | 81aed53d2b4cbd08590798ea8eb1c0941bed4c92 | |
| parent | 27c303ff00234e5ab9379878858f7ae3d0bdc2dc (diff) | |
| download | rcc-project-35f4e0a3aa03dfae06b5c9f226e38e609de2eef5.tar.gz rcc-project-35f4e0a3aa03dfae06b5c9f226e38e609de2eef5.tar.xz | |
[CodeGen] Run SSA exit transformations once
| -rw-r--r-- | backend/include/rcc/CodeGen/PHIElimination.h | 3 | ||||
| -rw-r--r-- | backend/include/rcc/CodeGen/TwoAddressInstructionPass.h | 3 | ||||
| -rw-r--r-- | backend/lib/CodeGen/PHIElimination.cpp | 30 | ||||
| -rw-r--r-- | backend/lib/CodeGen/TwoAddressInstructionPass.cpp | 43 |
4 files changed, 22 insertions, 57 deletions
diff --git a/backend/include/rcc/CodeGen/PHIElimination.h b/backend/include/rcc/CodeGen/PHIElimination.h index 1443303..fc95037 100644 --- a/backend/include/rcc/CodeGen/PHIElimination.h +++ b/backend/include/rcc/CodeGen/PHIElimination.h @@ -21,7 +21,8 @@ public: private: [[nodiscard]] Expected<MachinePassResult> runImplementation(MachineFunction &Function, const TargetDescription &Target, - MachineActionReplay &Actions); + MachineFunctionAnalysisManager + &Analyses); const TargetInstrInfo &Info; }; diff --git a/backend/include/rcc/CodeGen/TwoAddressInstructionPass.h b/backend/include/rcc/CodeGen/TwoAddressInstructionPass.h index 3c9e9dc..9016bd5 100644 --- a/backend/include/rcc/CodeGen/TwoAddressInstructionPass.h +++ b/backend/include/rcc/CodeGen/TwoAddressInstructionPass.h @@ -21,7 +21,8 @@ public: private: [[nodiscard]] Expected<MachinePassResult> runImplementation(MachineFunction &Function, const TargetDescription &Target, - MachineActionReplay &Actions); + MachineFunctionAnalysisManager + &Analyses); const TargetInstrInfo &Info; }; diff --git a/backend/lib/CodeGen/PHIElimination.cpp b/backend/lib/CodeGen/PHIElimination.cpp index 2c536f5..677a04c 100644 --- a/backend/lib/CodeGen/PHIElimination.cpp +++ b/backend/lib/CodeGen/PHIElimination.cpp @@ -7,7 +7,6 @@ #include "rcc/CodeGen/MachineBasicBlock.h" #include "rcc/CodeGen/MachineCFGUpdater.h" #include "rcc/CodeGen/MachineFunction.h" -#include "rcc/CodeGen/MachineFunctionCloner.h" #include "rcc/CodeGen/MachineIRBuilder.h" #include "rcc/CodeGen/MachineInstr.h" #include "rcc/CodeGen/MachineOperand.h" @@ -477,33 +476,13 @@ const MachinePassContract &PHIEliminationPass::contract() const noexcept { Expected<MachinePassResult> PHIEliminationPass::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(), "PHI-elimination 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(), "PHI elimination 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> PHIEliminationPass::runImplementation(MachineFunction &Function, const TargetDescription &Target, - MachineActionReplay &Actions) { + MachineFunctionAnalysisManager + &Analyses) { MachinePassResult Result; std::unordered_map<EdgeKey, MachineBasicBlock *, EdgeKeyHash> SplitEdges; const std::vector<MachineBasicBlock *> Blocks(Function.allBlocks().begin(), @@ -517,7 +496,8 @@ Expected<MachinePassResult> PHIEliminationPass::runImplementation(MachineFunctio continue; for (PhiPlan &Plan : *Plans) { - auto Accepted = Actions.request("eliminate-phi", Function, Plan.Instruction->stableID()); + auto Accepted = + Analyses.requestAction("eliminate-phi", Function, Plan.Instruction->stableID()); if (!Accepted) return std::unexpected(Accepted.error()); if (!*Accepted) { diff --git a/backend/lib/CodeGen/TwoAddressInstructionPass.cpp b/backend/lib/CodeGen/TwoAddressInstructionPass.cpp index b0b7e5b..80da2e8 100644 --- a/backend/lib/CodeGen/TwoAddressInstructionPass.cpp +++ b/backend/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -6,7 +6,6 @@ #include "rcc/CodeGen/LiveVariables.h" #include "rcc/CodeGen/MachineBasicBlock.h" #include "rcc/CodeGen/MachineFunction.h" -#include "rcc/CodeGen/MachineFunctionCloner.h" #include "rcc/CodeGen/MachineIRBuilder.h" #include "rcc/CodeGen/MachineInstr.h" #include "rcc/CodeGen/MachineOperand.h" @@ -448,32 +447,12 @@ const MachinePassContract &TwoAddressInstructionPass::contract() const noexcept Expected<MachinePassResult> TwoAddressInstructionPass::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(), "two-address 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(), "two-address rewrite 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> TwoAddressInstructionPass::runImplementation( - MachineFunction &Function, const TargetDescription &Target, MachineActionReplay &Actions) { + MachineFunction &Function, const TargetDescription &Target, + MachineFunctionAnalysisManager &Analyses) { MachinePassResult Result; const std::vector<MachineInstr *> Instructions(Function.allInstructions().begin(), Function.allInstructions().end()); @@ -481,7 +460,8 @@ Expected<MachinePassResult> TwoAddressInstructionPass::runImplementation( if (Instruction->parent() == nullptr) continue; if (Instruction->opcode() == opcode(GenericOpcode::REG_SEQUENCE)) { - auto Accepted = Actions.request("expand-reg-sequence", Function, Instruction->stableID()); + auto Accepted = + Analyses.requestAction("expand-reg-sequence", Function, Instruction->stableID()); if (!Accepted) return std::unexpected(Accepted.error()); if (!*Accepted) @@ -495,7 +475,8 @@ Expected<MachinePassResult> TwoAddressInstructionPass::runImplementation( continue; } if (Instruction->opcode() == opcode(GenericOpcode::INSERT_SUBREG)) { - auto Accepted = Actions.request("expand-insert-subreg", Function, Instruction->stableID()); + auto Accepted = + Analyses.requestAction("expand-insert-subreg", Function, Instruction->stableID()); if (!Accepted) return std::unexpected(Accepted.error()); if (!*Accepted) @@ -546,7 +527,8 @@ Expected<MachinePassResult> TwoAddressInstructionPass::runImplementation( continue; if (isImplicitlyUndef(Function, *Use)) { - auto Accepted = Actions.request("rewrite-undef-tie", Function, Instruction->stableID()); + auto Accepted = + Analyses.requestAction("rewrite-undef-tie", Function, Instruction->stableID()); if (!Accepted) return std::unexpected(Accepted.error()); if (!*Accepted) @@ -561,7 +543,7 @@ Expected<MachinePassResult> TwoAddressInstructionPass::runImplementation( } auto AllowCommute = - Actions.request("commute-tied-operands", Function, Instruction->stableID()); + Analyses.requestAction("commute-tied-operands", Function, Instruction->stableID()); if (!AllowCommute) return std::unexpected(AllowCommute.error()); if (*AllowCommute) { @@ -576,7 +558,7 @@ Expected<MachinePassResult> TwoAddressInstructionPass::runImplementation( } auto AllowConversion = - Actions.request("convert-three-address", Function, Instruction->stableID()); + Analyses.requestAction("convert-three-address", Function, Instruction->stableID()); if (!AllowConversion) return std::unexpected(AllowConversion.error()); if (*AllowConversion) { @@ -594,7 +576,8 @@ Expected<MachinePassResult> TwoAddressInstructionPass::runImplementation( } } - auto AllowCopy = Actions.request("insert-tied-copy", Function, Instruction->stableID()); + auto AllowCopy = + Analyses.requestAction("insert-tied-copy", Function, Instruction->stableID()); if (!AllowCopy) return std::unexpected(AllowCopy.error()); if (!*AllowCopy) |
