1 //===- PostDominators.cpp - Post-Dominator Calculation --------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements the post-dominator construction algorithms. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm/Analysis/PostDominators.h" 15 #include "llvm/ADT/DepthFirstIterator.h" 16 #include "llvm/ADT/SetOperations.h" 17 #include "llvm/IR/CFG.h" 18 #include "llvm/IR/Instructions.h" 19 #include "llvm/IR/PassManager.h" 20 #include "llvm/Support/Debug.h" 21 #include "llvm/Support/GenericDomTreeConstruction.h" 22 using namespace llvm; 23 24 #define DEBUG_TYPE "postdomtree" 25 26 template class llvm::DominatorTreeBase<BasicBlock, true>; // PostDomTreeBase 27 28 //===----------------------------------------------------------------------===// 29 // PostDominatorTree Implementation 30 //===----------------------------------------------------------------------===// 31 32 char PostDominatorTreeWrapperPass::ID = 0; 33 INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree", 34 "Post-Dominator Tree Construction", true, true) 35 36 bool PostDominatorTree::invalidate(Function &F, const PreservedAnalyses &PA, 37 FunctionAnalysisManager::Invalidator &) { 38 // Check whether the analysis, all analyses on functions, or the function's 39 // CFG have been preserved. 40 auto PAC = PA.getChecker<PostDominatorTreeAnalysis>(); 41 return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() || 42 PAC.preservedSet<CFGAnalyses>()); 43 } 44 45 bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) { 46 DT.recalculate(F); 47 return false; 48 } 49 50 void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const { 51 DT.print(OS); 52 } 53 54 FunctionPass* llvm::createPostDomTree() { 55 return new PostDominatorTreeWrapperPass(); 56 } 57 58 AnalysisKey PostDominatorTreeAnalysis::Key; 59 60 PostDominatorTree PostDominatorTreeAnalysis::run(Function &F, 61 FunctionAnalysisManager &) { 62 PostDominatorTree PDT; 63 PDT.recalculate(F); 64 return PDT; 65 } 66 67 PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS) 68 : OS(OS) {} 69 70 PreservedAnalyses 71 PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager &AM) { 72 OS << "PostDominatorTree for function: " << F.getName() << "\n"; 73 AM.getResult<PostDominatorTreeAnalysis>(F).print(OS); 74 75 return PreservedAnalyses::all(); 76 } 77