Cameron Zwarich | 4676599 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 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" |
Matt Arsenault | 661ca49 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 11 | #include "llvm/Analysis/DominanceFrontierImpl.h" |
Nico Weber | 0f38c60 | 2018-04-30 14:59:11 +0000 | [diff] [blame] | 12 | #include "llvm/Config/llvm-config.h" |
Eugene Zelenko | 4114bcf | 2017-07-24 23:16:33 +0000 | [diff] [blame] | 13 | #include "llvm/IR/Dominators.h" |
| 14 | #include "llvm/IR/Function.h" |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 15 | #include "llvm/IR/PassManager.h" |
Eugene Zelenko | 4114bcf | 2017-07-24 23:16:33 +0000 | [diff] [blame] | 16 | #include "llvm/Pass.h" |
| 17 | #include "llvm/Support/Compiler.h" |
| 18 | #include "llvm/Support/Debug.h" |
| 19 | #include "llvm/Support/raw_ostream.h" |
Matt Arsenault | 661ca49 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 20 | |
Cameron Zwarich | 4676599 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 21 | using namespace llvm; |
| 22 | |
Matt Arsenault | 661ca49 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 23 | namespace llvm { |
Eugene Zelenko | 4114bcf | 2017-07-24 23:16:33 +0000 | [diff] [blame] | 24 | |
Jakub Kuderski | cb10552 | 2017-07-14 18:26:09 +0000 | [diff] [blame] | 25 | template class DominanceFrontierBase<BasicBlock, false>; |
| 26 | template class DominanceFrontierBase<BasicBlock, true>; |
Matt Arsenault | 661ca49 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 27 | template class ForwardDominanceFrontierBase<BasicBlock>; |
Eugene Zelenko | 4114bcf | 2017-07-24 23:16:33 +0000 | [diff] [blame] | 28 | |
| 29 | } // end namespace llvm |
Matt Arsenault | 661ca49 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 30 | |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 31 | char DominanceFrontierWrapperPass::ID = 0; |
Matt Arsenault | 661ca49 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 32 | |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 33 | INITIALIZE_PASS_BEGIN(DominanceFrontierWrapperPass, "domfrontier", |
Cameron Zwarich | 4676599 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 34 | "Dominance Frontier Construction", true, true) |
Chandler Carruth | 7f2eff7 | 2014-01-13 13:07:17 +0000 | [diff] [blame] | 35 | INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 36 | INITIALIZE_PASS_END(DominanceFrontierWrapperPass, "domfrontier", |
Cameron Zwarich | 4676599 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 37 | "Dominance Frontier Construction", true, true) |
| 38 | |
Eugene Zelenko | 4114bcf | 2017-07-24 23:16:33 +0000 | [diff] [blame] | 39 | DominanceFrontierWrapperPass::DominanceFrontierWrapperPass() |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 40 | : FunctionPass(ID), DF() { |
| 41 | initializeDominanceFrontierWrapperPassPass(*PassRegistry::getPassRegistry()); |
Cameron Zwarich | 4676599 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 44 | void DominanceFrontierWrapperPass::releaseMemory() { |
| 45 | DF.releaseMemory(); |
Cameron Zwarich | 4676599 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 48 | bool DominanceFrontierWrapperPass::runOnFunction(Function &) { |
Matt Arsenault | 661ca49 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 49 | releaseMemory(); |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 50 | DF.analyze(getAnalysis<DominatorTreeWrapperPass>().getDomTree()); |
Matt Arsenault | 661ca49 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 51 | return false; |
| 52 | } |
| 53 | |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 54 | void DominanceFrontierWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { |
Matt Arsenault | 661ca49 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 55 | AU.setPreservesAll(); |
| 56 | AU.addRequired<DominatorTreeWrapperPass>(); |
| 57 | } |
| 58 | |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 59 | void DominanceFrontierWrapperPass::print(raw_ostream &OS, const Module *) const { |
| 60 | DF.print(OS); |
Cameron Zwarich | 4676599 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Aaron Ballman | 1d03d38 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 63 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 64 | LLVM_DUMP_METHOD void DominanceFrontierWrapperPass::dump() const { |
Cameron Zwarich | 4676599 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 65 | print(dbgs()); |
| 66 | } |
Manman Ren | cc77eec | 2012-09-06 19:55:56 +0000 | [diff] [blame] | 67 | #endif |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 68 | |
Chandler Carruth | 10dd00c | 2017-01-15 06:32:49 +0000 | [diff] [blame] | 69 | /// Handle invalidation explicitly. |
| 70 | bool DominanceFrontier::invalidate(Function &F, const PreservedAnalyses &PA, |
| 71 | FunctionAnalysisManager::Invalidator &) { |
| 72 | // Check whether the analysis, all analyses on functions, or the function's |
| 73 | // CFG have been preserved. |
| 74 | auto PAC = PA.getChecker<DominanceFrontierAnalysis>(); |
| 75 | return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() || |
| 76 | PAC.preservedSet<CFGAnalyses>()); |
| 77 | } |
| 78 | |
Chandler Carruth | 33d5681 | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 79 | AnalysisKey DominanceFrontierAnalysis::Key; |
NAKAMURA Takumi | d9b6afb | 2016-02-28 17:17:00 +0000 | [diff] [blame] | 80 | |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 81 | DominanceFrontier DominanceFrontierAnalysis::run(Function &F, |
Chandler Carruth | 8e27cb2 | 2016-03-11 11:05:24 +0000 | [diff] [blame] | 82 | FunctionAnalysisManager &AM) { |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 83 | DominanceFrontier DF; |
Chandler Carruth | 8e27cb2 | 2016-03-11 11:05:24 +0000 | [diff] [blame] | 84 | DF.analyze(AM.getResult<DominatorTreeAnalysis>(F)); |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 85 | return DF; |
| 86 | } |
| 87 | |
| 88 | DominanceFrontierPrinterPass::DominanceFrontierPrinterPass(raw_ostream &OS) |
| 89 | : OS(OS) {} |
| 90 | |
| 91 | PreservedAnalyses |
Chandler Carruth | 8e27cb2 | 2016-03-11 11:05:24 +0000 | [diff] [blame] | 92 | DominanceFrontierPrinterPass::run(Function &F, FunctionAnalysisManager &AM) { |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 93 | OS << "DominanceFrontier for function: " << F.getName() << "\n"; |
Chandler Carruth | 8e27cb2 | 2016-03-11 11:05:24 +0000 | [diff] [blame] | 94 | AM.getResult<DominanceFrontierAnalysis>(F).print(OS); |
Hongbin Zheng | 1596922 | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 95 | |
| 96 | return PreservedAnalyses::all(); |
| 97 | } |