Cameron Zwarich | 6b0c4c9 | 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 | 4181ea3 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 11 | #include "llvm/Analysis/DominanceFrontierImpl.h" |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 12 | #include "llvm/IR/PassManager.h" |
Matt Arsenault | 4181ea3 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 13 | |
Cameron Zwarich | 6b0c4c9 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 14 | using namespace llvm; |
| 15 | |
Matt Arsenault | 4181ea3 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 16 | namespace llvm { |
| 17 | template class DominanceFrontierBase<BasicBlock>; |
| 18 | template class ForwardDominanceFrontierBase<BasicBlock>; |
| 19 | } |
| 20 | |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 21 | char DominanceFrontierWrapperPass::ID = 0; |
Matt Arsenault | 4181ea3 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 22 | |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 23 | INITIALIZE_PASS_BEGIN(DominanceFrontierWrapperPass, "domfrontier", |
Cameron Zwarich | 6b0c4c9 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 24 | "Dominance Frontier Construction", true, true) |
Chandler Carruth | 7352302 | 2014-01-13 13:07:17 +0000 | [diff] [blame] | 25 | INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 26 | INITIALIZE_PASS_END(DominanceFrontierWrapperPass, "domfrontier", |
Cameron Zwarich | 6b0c4c9 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 27 | "Dominance Frontier Construction", true, true) |
| 28 | |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 29 | DominanceFrontierWrapperPass::DominanceFrontierWrapperPass() |
| 30 | : FunctionPass(ID), DF() { |
| 31 | initializeDominanceFrontierWrapperPassPass(*PassRegistry::getPassRegistry()); |
Cameron Zwarich | 6b0c4c9 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 34 | void DominanceFrontierWrapperPass::releaseMemory() { |
| 35 | DF.releaseMemory(); |
Cameron Zwarich | 6b0c4c9 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 38 | bool DominanceFrontierWrapperPass::runOnFunction(Function &) { |
Matt Arsenault | 4181ea3 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 39 | releaseMemory(); |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 40 | DF.analyze(getAnalysis<DominatorTreeWrapperPass>().getDomTree()); |
Matt Arsenault | 4181ea3 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 41 | return false; |
| 42 | } |
| 43 | |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 44 | void DominanceFrontierWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { |
Matt Arsenault | 4181ea3 | 2014-07-12 21:59:52 +0000 | [diff] [blame] | 45 | AU.setPreservesAll(); |
| 46 | AU.addRequired<DominatorTreeWrapperPass>(); |
| 47 | } |
| 48 | |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 49 | void DominanceFrontierWrapperPass::print(raw_ostream &OS, const Module *) const { |
| 50 | DF.print(OS); |
Cameron Zwarich | 6b0c4c9 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Manman Ren | 49d684e | 2012-09-12 05:06:18 +0000 | [diff] [blame] | 53 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 54 | LLVM_DUMP_METHOD void DominanceFrontierWrapperPass::dump() const { |
Cameron Zwarich | 6b0c4c9 | 2011-01-18 06:06:27 +0000 | [diff] [blame] | 55 | print(dbgs()); |
| 56 | } |
Manman Ren | c3366cc | 2012-09-06 19:55:56 +0000 | [diff] [blame] | 57 | #endif |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 58 | |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 59 | char DominanceFrontierAnalysis::PassID; |
NAKAMURA Takumi | df0cd72 | 2016-02-28 17:17:00 +0000 | [diff] [blame] | 60 | |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 61 | DominanceFrontier DominanceFrontierAnalysis::run(Function &F, |
Chandler Carruth | b47f801 | 2016-03-11 11:05:24 +0000 | [diff] [blame^] | 62 | FunctionAnalysisManager &AM) { |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 63 | DominanceFrontier DF; |
Chandler Carruth | b47f801 | 2016-03-11 11:05:24 +0000 | [diff] [blame^] | 64 | DF.analyze(AM.getResult<DominatorTreeAnalysis>(F)); |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 65 | return DF; |
| 66 | } |
| 67 | |
| 68 | DominanceFrontierPrinterPass::DominanceFrontierPrinterPass(raw_ostream &OS) |
| 69 | : OS(OS) {} |
| 70 | |
| 71 | PreservedAnalyses |
Chandler Carruth | b47f801 | 2016-03-11 11:05:24 +0000 | [diff] [blame^] | 72 | DominanceFrontierPrinterPass::run(Function &F, FunctionAnalysisManager &AM) { |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 73 | OS << "DominanceFrontier for function: " << F.getName() << "\n"; |
Chandler Carruth | b47f801 | 2016-03-11 11:05:24 +0000 | [diff] [blame^] | 74 | AM.getResult<DominanceFrontierAnalysis>(F).print(OS); |
Hongbin Zheng | 751337f | 2016-02-25 17:54:15 +0000 | [diff] [blame] | 75 | |
| 76 | return PreservedAnalyses::all(); |
| 77 | } |