1 //===- DominanceFrontier.cpp - Dominance Frontier 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 #include "llvm/Analysis/DominanceFrontier.h" 11 #include "llvm/Analysis/DominanceFrontierImpl.h" 12 #include "llvm/IR/PassManager.h" 13 14 using namespace llvm; 15 16 namespace llvm { 17 template class DominanceFrontierBase<BasicBlock>; 18 template class ForwardDominanceFrontierBase<BasicBlock>; 19 } 20 21 char DominanceFrontierWrapperPass::ID = 0; 22 23 INITIALIZE_PASS_BEGIN(DominanceFrontierWrapperPass, "domfrontier", 24 "Dominance Frontier Construction", true, true) 25 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) 26 INITIALIZE_PASS_END(DominanceFrontierWrapperPass, "domfrontier", 27 "Dominance Frontier Construction", true, true) 28 29 DominanceFrontierWrapperPass::DominanceFrontierWrapperPass() 30 : FunctionPass(ID), DF() { 31 initializeDominanceFrontierWrapperPassPass(*PassRegistry::getPassRegistry()); 32 } 33 34 void DominanceFrontierWrapperPass::releaseMemory() { 35 DF.releaseMemory(); 36 } 37 38 bool DominanceFrontierWrapperPass::runOnFunction(Function &) { 39 releaseMemory(); 40 DF.analyze(getAnalysis<DominatorTreeWrapperPass>().getDomTree()); 41 return false; 42 } 43 44 void DominanceFrontierWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { 45 AU.setPreservesAll(); 46 AU.addRequired<DominatorTreeWrapperPass>(); 47 } 48 49 void DominanceFrontierWrapperPass::print(raw_ostream &OS, const Module *) const { 50 DF.print(OS); 51 } 52 53 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 54 LLVM_DUMP_METHOD void DominanceFrontierWrapperPass::dump() const { 55 print(dbgs()); 56 } 57 #endif 58 59 /// Handle invalidation explicitly. 60 bool DominanceFrontier::invalidate(Function &F, const PreservedAnalyses &PA, 61 FunctionAnalysisManager::Invalidator &) { 62 // Check whether the analysis, all analyses on functions, or the function's 63 // CFG have been preserved. 64 auto PAC = PA.getChecker<DominanceFrontierAnalysis>(); 65 return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() || 66 PAC.preservedSet<CFGAnalyses>()); 67 } 68 69 AnalysisKey DominanceFrontierAnalysis::Key; 70 71 DominanceFrontier DominanceFrontierAnalysis::run(Function &F, 72 FunctionAnalysisManager &AM) { 73 DominanceFrontier DF; 74 DF.analyze(AM.getResult<DominatorTreeAnalysis>(F)); 75 return DF; 76 } 77 78 DominanceFrontierPrinterPass::DominanceFrontierPrinterPass(raw_ostream &OS) 79 : OS(OS) {} 80 81 PreservedAnalyses 82 DominanceFrontierPrinterPass::run(Function &F, FunctionAnalysisManager &AM) { 83 OS << "DominanceFrontier for function: " << F.getName() << "\n"; 84 AM.getResult<DominanceFrontierAnalysis>(F).print(OS); 85 86 return PreservedAnalyses::all(); 87 } 88