]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Analysis/PostDominators.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r308421, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / Analysis / PostDominators.h
1 //=- 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/IR/Dominators.h"
18 #include "llvm/IR/PassManager.h"
19
20 namespace llvm {
21
22 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
23 /// compute the post-dominator tree.
24 ///
25 struct PostDominatorTree : public PostDomTreeBase<BasicBlock> {
26   typedef PostDomTreeBase<BasicBlock> Base;
27
28   /// Handle invalidation explicitly.
29   bool invalidate(Function &F, const PreservedAnalyses &PA,
30                   FunctionAnalysisManager::Invalidator &);
31 };
32
33 /// \brief Analysis pass which computes a \c PostDominatorTree.
34 class PostDominatorTreeAnalysis
35     : public AnalysisInfoMixin<PostDominatorTreeAnalysis> {
36   friend AnalysisInfoMixin<PostDominatorTreeAnalysis>;
37   static AnalysisKey Key;
38
39 public:
40   /// \brief Provide the result typedef for this analysis pass.
41   typedef PostDominatorTree Result;
42
43   /// \brief Run the analysis pass over a function and produce a post dominator
44   ///        tree.
45   PostDominatorTree run(Function &F, FunctionAnalysisManager &);
46 };
47
48 /// \brief Printer pass for the \c PostDominatorTree.
49 class PostDominatorTreePrinterPass
50     : public PassInfoMixin<PostDominatorTreePrinterPass> {
51   raw_ostream &OS;
52
53 public:
54   explicit PostDominatorTreePrinterPass(raw_ostream &OS);
55   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
56 };
57
58 struct PostDominatorTreeWrapperPass : public FunctionPass {
59   static char ID; // Pass identification, replacement for typeid
60   PostDominatorTree DT;
61
62   PostDominatorTreeWrapperPass() : FunctionPass(ID) {
63     initializePostDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
64   }
65
66   PostDominatorTree &getPostDomTree() { return DT; }
67   const PostDominatorTree &getPostDomTree() const { return DT; }
68
69   bool runOnFunction(Function &F) override;
70
71   void getAnalysisUsage(AnalysisUsage &AU) const override {
72     AU.setPreservesAll();
73   }
74
75   void releaseMemory() override {
76     DT.releaseMemory();
77   }
78
79   void print(raw_ostream &OS, const Module*) const override;
80 };
81
82 FunctionPass* createPostDomTree();
83
84 template <> struct GraphTraits<PostDominatorTree*>
85   : public GraphTraits<DomTreeNode*> {
86   static NodeRef getEntryNode(PostDominatorTree *DT) {
87     return DT->getRootNode();
88   }
89
90   static nodes_iterator nodes_begin(PostDominatorTree *N) {
91     if (getEntryNode(N))
92       return df_begin(getEntryNode(N));
93     else
94       return df_end(getEntryNode(N));
95   }
96
97   static nodes_iterator nodes_end(PostDominatorTree *N) {
98     return df_end(getEntryNode(N));
99   }
100 };
101
102 } // End llvm namespace
103
104 #endif