blob: 9a8c4d7807d3c2e569931a6b236b30c950c9b842 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//=- llvm/Analysis/PostDominators.h - Post Dominator Calculation --*- C++ -*-=//
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 exposes interfaces to post dominance information.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ANALYSIS_POSTDOMINATORS_H
15#define LLVM_ANALYSIS_POSTDOMINATORS_H
16
17#include "llvm/ADT/DepthFirstIterator.h"
18#include "llvm/IR/Dominators.h"
19#include "llvm/IR/PassManager.h"
20#include "llvm/Pass.h"
21
22namespace llvm {
23
24class Function;
25class raw_ostream;
26
27/// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
28/// compute the post-dominator tree.
29class PostDominatorTree : public PostDomTreeBase<BasicBlock> {
30public:
31 using Base = PostDomTreeBase<BasicBlock>;
32
33 /// Handle invalidation explicitly.
34 bool invalidate(Function &F, const PreservedAnalyses &PA,
35 FunctionAnalysisManager::Invalidator &);
36};
37
38/// \brief Analysis pass which computes a \c PostDominatorTree.
39class PostDominatorTreeAnalysis
40 : public AnalysisInfoMixin<PostDominatorTreeAnalysis> {
41 friend AnalysisInfoMixin<PostDominatorTreeAnalysis>;
42
43 static AnalysisKey Key;
44
45public:
46 /// \brief Provide the result type for this analysis pass.
47 using Result = PostDominatorTree;
48
49 /// \brief Run the analysis pass over a function and produce a post dominator
50 /// tree.
51 PostDominatorTree run(Function &F, FunctionAnalysisManager &);
52};
53
54/// \brief Printer pass for the \c PostDominatorTree.
55class PostDominatorTreePrinterPass
56 : public PassInfoMixin<PostDominatorTreePrinterPass> {
57 raw_ostream &OS;
58
59public:
60 explicit PostDominatorTreePrinterPass(raw_ostream &OS);
61
62 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
63};
64
65struct PostDominatorTreeWrapperPass : public FunctionPass {
66 static char ID; // Pass identification, replacement for typeid
67
68 PostDominatorTree DT;
69
70 PostDominatorTreeWrapperPass() : FunctionPass(ID) {
71 initializePostDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
72 }
73
74 PostDominatorTree &getPostDomTree() { return DT; }
75 const PostDominatorTree &getPostDomTree() const { return DT; }
76
77 bool runOnFunction(Function &F) override;
78
79 void verifyAnalysis() const override;
80
81 void getAnalysisUsage(AnalysisUsage &AU) const override {
82 AU.setPreservesAll();
83 }
84
85 void releaseMemory() override {
86 DT.releaseMemory();
87 }
88
89 void print(raw_ostream &OS, const Module*) const override;
90};
91
92FunctionPass* createPostDomTree();
93
94template <> struct GraphTraits<PostDominatorTree*>
95 : public GraphTraits<DomTreeNode*> {
96 static NodeRef getEntryNode(PostDominatorTree *DT) {
97 return DT->getRootNode();
98 }
99
100 static nodes_iterator nodes_begin(PostDominatorTree *N) {
101 if (getEntryNode(N))
102 return df_begin(getEntryNode(N));
103 else
104 return df_end(getEntryNode(N));
105 }
106
107 static nodes_iterator nodes_end(PostDominatorTree *N) {
108 return df_end(getEntryNode(N));
109 }
110};
111
112} // end namespace llvm
113
114#endif // LLVM_ANALYSIS_POSTDOMINATORS_H