diff options
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r-- | llvm/lib/IR/Core.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/IR/Dominators.cpp | 76 | ||||
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 6 |
3 files changed, 47 insertions, 37 deletions
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 31e445ecaa1..ff4976bcbf9 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -40,7 +40,7 @@ using namespace llvm; void llvm::initializeCore(PassRegistry &Registry) { - initializeDominatorTreePass(Registry); + initializeDominatorTreeWrapperPassPass(Registry); initializePrintModulePassWrapperPass(Registry); initializePrintFunctionPassWrapperPass(Registry); initializePrintBasicBlockPassPass(Registry); diff --git a/llvm/lib/IR/Dominators.cpp b/llvm/lib/IR/Dominators.cpp index c831c19517f..8fa742f745a 100644 --- a/llvm/lib/IR/Dominators.cpp +++ b/llvm/lib/IR/Dominators.cpp @@ -64,35 +64,6 @@ bool BasicBlockEdge::isSingleEdge() const { TEMPLATE_INSTANTIATION(class llvm::DomTreeNodeBase<BasicBlock>); TEMPLATE_INSTANTIATION(class llvm::DominatorTreeBase<BasicBlock>); -char DominatorTree::ID = 0; -INITIALIZE_PASS(DominatorTree, "domtree", - "Dominator Tree Construction", true, true) - -bool DominatorTree::runOnFunction(Function &F) { - DT->recalculate(F); - return false; -} - -void DominatorTree::verifyAnalysis() const { - if (!VerifyDomInfo) return; - - Function &F = *getRoot()->getParent(); - - DominatorTree OtherDT; - OtherDT.getBase().recalculate(F); - if (compare(OtherDT)) { - errs() << "DominatorTree is not up to date!\nComputed:\n"; - print(errs()); - errs() << "\nActual:\n"; - OtherDT.print(errs()); - abort(); - } -} - -void DominatorTree::print(raw_ostream &OS, const Module *) const { - DT->print(OS); -} - // dominates - Return true if Def dominates a use in User. This performs // the special checks necessary if Def and User are in the same basic block. // Note that Def doesn't dominate a use in Def itself! @@ -210,8 +181,7 @@ bool DominatorTree::dominates(const BasicBlockEdge &BBE, return true; } -bool DominatorTree::dominates(const BasicBlockEdge &BBE, - const Use &U) const { +bool DominatorTree::dominates(const BasicBlockEdge &BBE, const Use &U) const { // Assert that we have a single edge. We could handle them by simply // returning false, but since isSingleEdge is linear on the number of // edges, the callers can normally handle them more efficiently. @@ -234,8 +204,7 @@ bool DominatorTree::dominates(const BasicBlockEdge &BBE, return dominates(BBE, UseBB); } -bool DominatorTree::dominates(const Instruction *Def, - const Use &U) const { +bool DominatorTree::dominates(const Instruction *Def, const Use &U) const { Instruction *UserInst = cast<Instruction>(U.getUser()); const BasicBlock *DefBB = Def->getParent(); @@ -300,3 +269,44 @@ bool DominatorTree::isReachableFromEntry(const Use &U) const { // Everything else uses their operands in their own block. return isReachableFromEntry(I->getParent()); } + +void DominatorTree::verifyDomTree() const { + if (!VerifyDomInfo) + return; + + Function &F = *getRoot()->getParent(); + + DominatorTree OtherDT; + OtherDT.recalculate(F); + if (compare(OtherDT)) { + errs() << "DominatorTree is not up to date!\nComputed:\n"; + print(errs()); + errs() << "\nActual:\n"; + OtherDT.print(errs()); + abort(); + } +} + +//===----------------------------------------------------------------------===// +// DominatorTreeWrapperPass Implementation +//===----------------------------------------------------------------------===// +// +// The implementation details of the wrapper pass that holds a DominatorTree. +// +//===----------------------------------------------------------------------===// + +char DominatorTreeWrapperPass::ID = 0; +INITIALIZE_PASS(DominatorTreeWrapperPass, "domtree", + "Dominator Tree Construction", true, true) + +bool DominatorTreeWrapperPass::runOnFunction(Function &F) { + DT.recalculate(F); + return false; +} + +void DominatorTreeWrapperPass::verifyAnalysis() const { DT.verifyDomTree(); } + +void DominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const { + DT.print(OS); +} + diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 635157b09ed..9e150e85756 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -176,7 +176,7 @@ namespace { bool runOnFunction(Function &F) { // Get dominator information if we are being run by PassManager - DT = &getAnalysis<DominatorTree>(); + DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); Mod = F.getParent(); if (!Context) Context = &F.getContext(); @@ -233,7 +233,7 @@ namespace { virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); AU.addRequiredID(PreVerifyID); - AU.addRequired<DominatorTree>(); + AU.addRequired<DominatorTreeWrapperPass>(); } /// abortIfBroken - If the module is broken and we are supposed to abort on @@ -395,7 +395,7 @@ namespace { char Verifier::ID = 0; INITIALIZE_PASS_BEGIN(Verifier, "verify", "Module Verifier", false, false) INITIALIZE_PASS_DEPENDENCY(PreVerifier) -INITIALIZE_PASS_DEPENDENCY(DominatorTree) +INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) INITIALIZE_PASS_END(Verifier, "verify", "Module Verifier", false, false) // Assert - We know that cond should be true, if not print an error message. |