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/IR/Function.h" 16 #include "llvm/IR/PassManager.h" 17 #include "llvm/Pass.h" 18 #include "llvm/Support/raw_ostream.h" 19 20 using namespace llvm; 21 22 #define DEBUG_TYPE "postdomtree" 23 24 template class llvm::DominatorTreeBase<BasicBlock, true>; // PostDomTreeBase 25 26 //===----------------------------------------------------------------------===// 27 // PostDominatorTree Implementation 28 //===----------------------------------------------------------------------===// 29 30 char PostDominatorTreeWrapperPass::ID = 0; 31 32 INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree", 33 "Post-Dominator Tree Construction", true, true) 34 35 bool PostDominatorTree::invalidate(Function &F, const PreservedAnalyses &PA, 36 FunctionAnalysisManager::Invalidator &) { 37 // Check whether the analysis, all analyses on functions, or the function's 38 // CFG have been preserved. 39 auto PAC = PA.getChecker<PostDominatorTreeAnalysis>(); 40 return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() || 41 PAC.preservedSet<CFGAnalyses>()); 42 } 43 44 bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) { 45 DT.recalculate(F); 46 return false; 47 } 48 49 void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const { 50 DT.print(OS); 51 } 52 53 FunctionPass* llvm::createPostDomTree() { 54 return new PostDominatorTreeWrapperPass(); 55 } 56 57 AnalysisKey PostDominatorTreeAnalysis::Key; 58 59 PostDominatorTree PostDominatorTreeAnalysis::run(Function &F, 60 FunctionAnalysisManager &) { 61 PostDominatorTree PDT; 62 PDT.recalculate(F); 63 return PDT; 64 } 65 66 PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS) 67 : OS(OS) {} 68 69 PreservedAnalyses 70 PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager &AM) { 71 OS << "PostDominatorTree for function: " << F.getName() << "\n"; 72 AM.getResult<PostDominatorTreeAnalysis>(F).print(OS); 73 74 return PreservedAnalyses::all(); 75 } 76