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