1 //===- PostDominators.cpp - Post-Dominator 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 // This file implements the post-dominator construction algorithms.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/Analysis/PostDominators.h"
15 #include "llvm/ADT/DepthFirstIterator.h"
16 #include "llvm/ADT/SetOperations.h"
17 #include "llvm/IR/CFG.h"
18 #include "llvm/IR/Instructions.h"
19 #include "llvm/IR/PassManager.h"
20 #include "llvm/Support/Debug.h"
21 #include "llvm/Support/GenericDomTreeConstruction.h"
22 using namespace llvm;
23 
24 #define DEBUG_TYPE "postdomtree"
25 
26 //===----------------------------------------------------------------------===//
27 //  PostDominatorTree Implementation
28 //===----------------------------------------------------------------------===//
29 
30 char PostDominatorTreeWrapperPass::ID = 0;
31 INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree",
32                 "Post-Dominator Tree Construction", true, true)
33 
34 bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
35   DT.recalculate(F);
36   return false;
37 }
38 
39 void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
40   DT.print(OS);
41 }
42 
43 FunctionPass* llvm::createPostDomTree() {
44   return new PostDominatorTreeWrapperPass();
45 }
46 
47 template class llvm::AnalysisBase<PostDominatorTreeAnalysis>;
48 
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 }
65