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