Chris Lattner | d43023a | 2002-08-02 16:43:03 +0000 | [diff] [blame] | 1 | //===- PostDominators.cpp - Post-Dominator Calculation --------------------===// |
Misha Brukman | 01808ca | 2005-04-21 21:13:18 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 01808ca | 2005-04-21 21:13:18 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 081aabc | 2001-07-02 05:46:38 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | d43023a | 2002-08-02 16:43:03 +0000 | [diff] [blame] | 10 | // This file implements the post-dominator construction algorithms. |
Chris Lattner | 081aabc | 2001-07-02 05:46:38 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | c86203a | 2002-08-21 23:43:50 +0000 | [diff] [blame] | 14 | #include "llvm/Analysis/PostDominators.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/DepthFirstIterator.h" |
| 16 | #include "llvm/ADT/SetOperations.h" |
Chandler Carruth | 1305dc3 | 2014-03-04 11:45:46 +0000 | [diff] [blame] | 17 | #include "llvm/IR/CFG.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Instructions.h" |
Hongbin Zheng | 3f97840 | 2016-02-25 17:54:07 +0000 | [diff] [blame] | 19 | #include "llvm/IR/PassManager.h" |
Owen Anderson | 57236b5 | 2008-04-16 04:21:16 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Debug.h" |
Chandler Carruth | 442f784 | 2014-03-04 10:07:28 +0000 | [diff] [blame] | 21 | #include "llvm/Support/GenericDomTreeConstruction.h" |
Chris Lattner | f9f7c2d | 2003-12-07 00:35:42 +0000 | [diff] [blame] | 22 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 23 | |
Chandler Carruth | f1221bd | 2014-04-22 02:48:03 +0000 | [diff] [blame] | 24 | #define DEBUG_TYPE "postdomtree" |
| 25 | |
Chris Lattner | c385beb | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 26 | //===----------------------------------------------------------------------===// |
Owen Anderson | f35a1db | 2007-04-15 08:47:27 +0000 | [diff] [blame] | 27 | // PostDominatorTree Implementation |
Nate Begeman | d5811b9 | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 28 | //===----------------------------------------------------------------------===// |
| 29 | |
Hongbin Zheng | 3f97840 | 2016-02-25 17:54:07 +0000 | [diff] [blame] | 30 | char PostDominatorTreeWrapperPass::ID = 0; |
| 31 | INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree", |
Owen Anderson | df7a4f2 | 2010-10-07 22:25:06 +0000 | [diff] [blame] | 32 | "Post-Dominator Tree Construction", true, true) |
Nate Begeman | d5811b9 | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 33 | |
Hongbin Zheng | 3f97840 | 2016-02-25 17:54:07 +0000 | [diff] [blame] | 34 | bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) { |
| 35 | DT.recalculate(F); |
Owen Anderson | b60f254 | 2007-10-03 03:20:17 +0000 | [diff] [blame] | 36 | return false; |
| 37 | } |
| 38 | |
Hongbin Zheng | 3f97840 | 2016-02-25 17:54:07 +0000 | [diff] [blame] | 39 | void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const { |
| 40 | DT.print(OS); |
Torok Edwin | 2a45575 | 2008-05-03 20:25:26 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Owen Anderson | b1ba352 | 2008-05-29 17:00:13 +0000 | [diff] [blame] | 43 | FunctionPass* llvm::createPostDomTree() { |
Hongbin Zheng | 3f97840 | 2016-02-25 17:54:07 +0000 | [diff] [blame] | 44 | return new PostDominatorTreeWrapperPass(); |
Owen Anderson | b1ba352 | 2008-05-29 17:00:13 +0000 | [diff] [blame] | 45 | } |
| 46 | |
NAKAMURA Takumi | df0cd72 | 2016-02-28 17:17:00 +0000 | [diff] [blame^] | 47 | template class llvm::AnalysisBase<PostDominatorTreeAnalysis>; |
| 48 | |
Hongbin Zheng | 3f97840 | 2016-02-25 17:54:07 +0000 | [diff] [blame] | 49 | PostDominatorTree PostDominatorTreeAnalysis::run(Function &F) { |
| 50 | PostDominatorTree PDT; |
| 51 | PDT.recalculate(F); |
| 52 | return PDT; |
| 53 | } |
| 54 | |
| 55 | PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS) |
| 56 | : OS(OS) {} |
| 57 | |
| 58 | PreservedAnalyses |
| 59 | PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager *AM) { |
| 60 | OS << "PostDominatorTree for function: " << F.getName() << "\n"; |
| 61 | AM->getResult<PostDominatorTreeAnalysis>(F).print(OS); |
| 62 | |
| 63 | return PreservedAnalyses::all(); |
| 64 | } |