diff options
author | paperchalice <liujunchang97@outlook.com> | 2024-12-11 11:31:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-11 11:31:42 +0800 |
commit | 79047fac65b95a5a98bde0de473da858e805576c (patch) | |
tree | 6c2d968379f8da20c1c7af86b522876bab80f91e /llvm/lib/CodeGen/PHIElimination.cpp | |
parent | 30ea0f0ce476bf4c12684a9a514af2ca660bbe44 (diff) | |
download | llvm-79047fac65b95a5a98bde0de473da858e805576c.zip llvm-79047fac65b95a5a98bde0de473da858e805576c.tar.gz llvm-79047fac65b95a5a98bde0de473da858e805576c.tar.bz2 |
[DomTreeUpdater] Move critical edge splitting code to updater (#115111)
Support critical edge splitting in dominator tree updater. Continue the
work in #100856.
Compile time check:
https://llvm-compile-time-tracker.com/compare.php?from=87c35d782795b54911b3e3a91a5b738d4d870e55&to=42b3e5623a9ab4c3648564dc0926b36f3b438a3a&stat=instructions%3Au
Diffstat (limited to 'llvm/lib/CodeGen/PHIElimination.cpp')
-rw-r--r-- | llvm/lib/CodeGen/PHIElimination.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/PHIElimination.cpp b/llvm/lib/CodeGen/PHIElimination.cpp index e5f4077..b71e5b8 100644 --- a/llvm/lib/CodeGen/PHIElimination.cpp +++ b/llvm/lib/CodeGen/PHIElimination.cpp @@ -22,6 +22,7 @@ #include "llvm/CodeGen/LiveIntervals.h" #include "llvm/CodeGen/LiveVariables.h" #include "llvm/CodeGen/MachineBasicBlock.h" +#include "llvm/CodeGen/MachineDomTreeUpdater.h" #include "llvm/CodeGen/MachineDominators.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" @@ -90,7 +91,8 @@ class PHIEliminationImpl { /// Split critical edges where necessary for good coalescer performance. bool SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB, MachineLoopInfo *MLI, - std::vector<SparseBitVector<>> *LiveInSets); + std::vector<SparseBitVector<>> *LiveInSets, + MachineDomTreeUpdater &MDTU); // These functions are temporary abstractions around LiveVariables and // LiveIntervals, so they can go away when LiveVariables does. @@ -203,6 +205,16 @@ void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const { bool PHIEliminationImpl::run(MachineFunction &MF) { MRI = &MF.getRegInfo(); + MachineDominatorTree *MDT = nullptr; + if (P) { + auto *MDTWrapper = + P->getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>(); + MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr; + } else { + MDT = MFAM->getCachedResult<MachineDominatorTreeAnalysis>(MF); + } + MachineDomTreeUpdater MDTU(MDT, MachineDomTreeUpdater::UpdateStrategy::Lazy); + bool Changed = false; // Split critical edges to help the coalescer. @@ -237,7 +249,8 @@ bool PHIEliminationImpl::run(MachineFunction &MF) { } for (auto &MBB : MF) - Changed |= SplitPHIEdges(MF, MBB, MLI, (LV ? &LiveInSets : nullptr)); + Changed |= + SplitPHIEdges(MF, MBB, MLI, (LV ? &LiveInSets : nullptr), MDTU); } // This pass takes the function out of SSA form. @@ -268,10 +281,6 @@ bool PHIEliminationImpl::run(MachineFunction &MF) { MF.deleteMachineInstr(I.first); } - // TODO: we should use the incremental DomTree updater here. - if (Changed && MDT) - MDT->getBase().recalculate(MF); - LoweredPHIs.clear(); ImpDefs.clear(); VRegPHIUseCount.clear(); @@ -752,7 +761,7 @@ void PHIEliminationImpl::analyzePHINodes(const MachineFunction &MF) { bool PHIEliminationImpl::SplitPHIEdges( MachineFunction &MF, MachineBasicBlock &MBB, MachineLoopInfo *MLI, - std::vector<SparseBitVector<>> *LiveInSets) { + std::vector<SparseBitVector<>> *LiveInSets, MachineDomTreeUpdater &MDTU) { if (MBB.empty() || !MBB.front().isPHI() || MBB.isEHPad()) return false; // Quick exit for basic blocks without PHIs. @@ -819,8 +828,8 @@ bool PHIEliminationImpl::SplitPHIEdges( } if (!ShouldSplit && !SplitAllCriticalEdges) continue; - if (!(P ? PreMBB->SplitCriticalEdge(&MBB, *P, LiveInSets) - : PreMBB->SplitCriticalEdge(&MBB, *MFAM, LiveInSets))) { + if (!(P ? PreMBB->SplitCriticalEdge(&MBB, *P, LiveInSets, &MDTU) + : PreMBB->SplitCriticalEdge(&MBB, *MFAM, LiveInSets, &MDTU))) { LLVM_DEBUG(dbgs() << "Failed to split critical edge.\n"); continue; } |