Mercurial > hg > Members > tobaru > cbc > CbC_llvm
diff lib/IR/Dominators.cpp @ 77:54457678186b
LLVM 3.6
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Sep 2014 22:06:00 +0900 |
parents | 95c75e76d11b |
children | 60c9769439b8 |
line wrap: on
line diff
--- a/lib/IR/Dominators.cpp Thu Dec 12 15:22:36 2013 +0900 +++ b/lib/IR/Dominators.cpp Mon Sep 08 22:06:00 2014 +0900 @@ -14,17 +14,16 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Analysis/Dominators.h" +#include "llvm/IR/Dominators.h" #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/Analysis/DominatorInternals.h" -#include "llvm/Assembly/Writer.h" +#include "llvm/IR/CFG.h" #include "llvm/IR/Instructions.h" -#include "llvm/Support/CFG.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/GenericDomTreeConstruction.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> using namespace llvm; @@ -57,41 +56,23 @@ //===----------------------------------------------------------------------===// // // Provide public access to DominatorTree information. Implementation details -// can be found in DominatorInternals.h. +// can be found in Dominators.h, GenericDomTree.h, and +// GenericDomTreeConstruction.h. // //===----------------------------------------------------------------------===// 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); -} +#define LLVM_COMMA , +TEMPLATE_INSTANTIATION(void llvm::Calculate<Function LLVM_COMMA BasicBlock *>( + DominatorTreeBase<GraphTraits<BasicBlock *>::NodeType> &DT LLVM_COMMA + Function &F)); +TEMPLATE_INSTANTIATION( + void llvm::Calculate<Function LLVM_COMMA Inverse<BasicBlock *> >( + DominatorTreeBase<GraphTraits<Inverse<BasicBlock *> >::NodeType> &DT + LLVM_COMMA Function &F)); +#undef LLVM_COMMA // 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. @@ -210,8 +191,7 @@ 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 +214,7 @@ 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 +279,44 @@ // 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); +} +