diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2024-07-27 23:34:35 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2024-10-23 18:26:01 +0000 |
commit | 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583 (patch) | |
tree | 6cf5ab1f05330c6773b1f3f64799d56a9c7a1faa /contrib/llvm-project/llvm/lib/CodeGen/MachineDominators.cpp | |
parent | 6b9f7133aba44189d9625c352bc2c2a59baf18ef (diff) | |
parent | ac9a064cb179f3425b310fa2847f8764ac970a4d (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/MachineDominators.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/CodeGen/MachineDominators.cpp | 99 |
1 files changed, 69 insertions, 30 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/MachineDominators.cpp b/contrib/llvm-project/llvm/lib/CodeGen/MachineDominators.cpp index 0632cde9c6f4..a2cc8fdfa7c9 100644 --- a/contrib/llvm-project/llvm/lib/CodeGen/MachineDominators.cpp +++ b/contrib/llvm-project/llvm/lib/CodeGen/MachineDominators.cpp @@ -18,6 +18,7 @@ #include "llvm/Pass.h" #include "llvm/PassRegistry.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/GenericDomTreeConstruction.h" using namespace llvm; @@ -37,51 +38,86 @@ static cl::opt<bool, true> VerifyMachineDomInfoX( namespace llvm { template class DomTreeNodeBase<MachineBasicBlock>; template class DominatorTreeBase<MachineBasicBlock, false>; // DomTreeBase + +namespace DomTreeBuilder { +template void Calculate<MBBDomTree>(MBBDomTree &DT); +template void CalculateWithUpdates<MBBDomTree>(MBBDomTree &DT, MBBUpdates U); + +template void InsertEdge<MBBDomTree>(MBBDomTree &DT, MachineBasicBlock *From, + MachineBasicBlock *To); + +template void DeleteEdge<MBBDomTree>(MBBDomTree &DT, MachineBasicBlock *From, + MachineBasicBlock *To); + +template void ApplyUpdates<MBBDomTree>(MBBDomTree &DT, MBBDomTreeGraphDiff &, + MBBDomTreeGraphDiff *); + +template bool Verify<MBBDomTree>(const MBBDomTree &DT, + MBBDomTree::VerificationLevel VL); +} // namespace DomTreeBuilder } -char MachineDominatorTree::ID = 0; +bool MachineDominatorTree::invalidate( + MachineFunction &, const PreservedAnalyses &PA, + MachineFunctionAnalysisManager::Invalidator &) { + // Check whether the analysis, all analyses on machine functions, or the + // machine function's CFG have been preserved. + auto PAC = PA.getChecker<MachineDominatorTreeAnalysis>(); + return !PAC.preserved() && + !PAC.preservedSet<AllAnalysesOn<MachineFunction>>() && + !PAC.preservedSet<CFGAnalyses>(); +} -INITIALIZE_PASS(MachineDominatorTree, "machinedomtree", - "MachineDominator Tree Construction", true, true) +AnalysisKey MachineDominatorTreeAnalysis::Key; -char &llvm::MachineDominatorsID = MachineDominatorTree::ID; +MachineDominatorTreeAnalysis::Result +MachineDominatorTreeAnalysis::run(MachineFunction &MF, + MachineFunctionAnalysisManager &) { + return MachineDominatorTree(MF); +} -void MachineDominatorTree::getAnalysisUsage(AnalysisUsage &AU) const { - AU.setPreservesAll(); - MachineFunctionPass::getAnalysisUsage(AU); +PreservedAnalyses +MachineDominatorTreePrinterPass::run(MachineFunction &MF, + MachineFunctionAnalysisManager &MFAM) { + OS << "MachineDominatorTree for machine function: " << MF.getName() << '\n'; + MFAM.getResult<MachineDominatorTreeAnalysis>(MF).print(OS); + return PreservedAnalyses::all(); } -bool MachineDominatorTree::runOnMachineFunction(MachineFunction &F) { - calculate(F); - return false; +char MachineDominatorTreeWrapperPass::ID = 0; + +INITIALIZE_PASS(MachineDominatorTreeWrapperPass, "machinedomtree", + "MachineDominator Tree Construction", true, true) + +MachineDominatorTreeWrapperPass::MachineDominatorTreeWrapperPass() + : MachineFunctionPass(ID) { + initializeMachineDominatorTreeWrapperPassPass( + *PassRegistry::getPassRegistry()); } void MachineDominatorTree::calculate(MachineFunction &F) { CriticalEdgesToSplit.clear(); NewBBs.clear(); - DT.reset(new DomTreeBase<MachineBasicBlock>()); - DT->recalculate(F); + recalculate(F); } -MachineDominatorTree::MachineDominatorTree() - : MachineFunctionPass(ID) { - initializeMachineDominatorTreePass(*PassRegistry::getPassRegistry()); -} +char &llvm::MachineDominatorsID = MachineDominatorTreeWrapperPass::ID; -void MachineDominatorTree::releaseMemory() { - CriticalEdgesToSplit.clear(); - DT.reset(nullptr); +bool MachineDominatorTreeWrapperPass::runOnMachineFunction(MachineFunction &F) { + DT = MachineDominatorTree(F); + return false; } -void MachineDominatorTree::verifyAnalysis() const { - if (DT && VerifyMachineDomInfo) - if (!DT->verify(MachineDomTree::VerificationLevel::Basic)) { - errs() << "MachineDominatorTree verification failed\n"; - abort(); - } +void MachineDominatorTreeWrapperPass::releaseMemory() { DT.reset(); } + +void MachineDominatorTreeWrapperPass::verifyAnalysis() const { + if (VerifyMachineDomInfo && DT) + if (!DT->verify(MachineDominatorTree::VerificationLevel::Basic)) + report_fatal_error("MachineDominatorTree verification failed!"); } -void MachineDominatorTree::print(raw_ostream &OS, const Module*) const { +void MachineDominatorTreeWrapperPass::print(raw_ostream &OS, + const Module *) const { if (DT) DT->print(OS); } @@ -103,7 +139,7 @@ void MachineDominatorTree::applySplitCriticalEdges() const { for (CriticalEdge &Edge : CriticalEdgesToSplit) { // Update dominator information. MachineBasicBlock *Succ = Edge.ToBB; - MachineDomTreeNode *SuccDTNode = DT->getNode(Succ); + MachineDomTreeNode *SuccDTNode = Base::getNode(Succ); for (MachineBasicBlock *PredBB : Succ->predecessors()) { if (PredBB == Edge.NewBB) @@ -126,7 +162,7 @@ void MachineDominatorTree::applySplitCriticalEdges() const { "than one predecessor!"); PredBB = *PredBB->pred_begin(); } - if (!DT->dominates(SuccDTNode, DT->getNode(PredBB))) { + if (!Base::dominates(SuccDTNode, Base::getNode(PredBB))) { IsNewIDom[Idx] = false; break; } @@ -138,13 +174,16 @@ void MachineDominatorTree::applySplitCriticalEdges() const { Idx = 0; for (CriticalEdge &Edge : CriticalEdgesToSplit) { // We know FromBB dominates NewBB. - MachineDomTreeNode *NewDTNode = DT->addNewBlock(Edge.NewBB, Edge.FromBB); + MachineDomTreeNode *NewDTNode = + const_cast<MachineDominatorTree *>(this)->Base::addNewBlock( + Edge.NewBB, Edge.FromBB); // If all the other predecessors of "Succ" are dominated by "Succ" itself // then the new block is the new immediate dominator of "Succ". Otherwise, // the new block doesn't dominate anything. if (IsNewIDom[Idx]) - DT->changeImmediateDominator(DT->getNode(Edge.ToBB), NewDTNode); + const_cast<MachineDominatorTree *>(this)->Base::changeImmediateDominator( + Base::getNode(Edge.ToBB), NewDTNode); ++Idx; } NewBBs.clear(); |