]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Analysis/PostDominators.h
MFV r319950: 5220 L2ARC does not support devices that do not provide 512B access
[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 DominatorTreeBase<BasicBlock> {
26   typedef DominatorTreeBase<BasicBlock> Base;
27
28   PostDominatorTree() : DominatorTreeBase<BasicBlock>(true) {}
29 };
30
31 /// \brief Analysis pass which computes a \c PostDominatorTree.
32 class PostDominatorTreeAnalysis
33     : public AnalysisInfoMixin<PostDominatorTreeAnalysis> {
34   friend AnalysisInfoMixin<PostDominatorTreeAnalysis>;
35   static AnalysisKey Key;
36
37 public:
38   /// \brief Provide the result typedef for this analysis pass.
39   typedef PostDominatorTree Result;
40
41   /// \brief Run the analysis pass over a function and produce a post dominator
42   ///        tree.
43   PostDominatorTree run(Function &F, FunctionAnalysisManager &);
44 };
45
46 /// \brief Printer pass for the \c PostDominatorTree.
47 class PostDominatorTreePrinterPass
48     : public PassInfoMixin<PostDominatorTreePrinterPass> {
49   raw_ostream &OS;
50
51 public:
52   explicit PostDominatorTreePrinterPass(raw_ostream &OS);
53   PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
54 };
55
56 struct PostDominatorTreeWrapperPass : public FunctionPass {
57   static char ID; // Pass identification, replacement for typeid
58   PostDominatorTree DT;
59
60   PostDominatorTreeWrapperPass() : FunctionPass(ID) {
61     initializePostDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
62   }
63
64   PostDominatorTree &getPostDomTree() { return DT; }
65   const PostDominatorTree &getPostDomTree() const { return DT; }
66
67   bool runOnFunction(Function &F) override;
68
69   void getAnalysisUsage(AnalysisUsage &AU) const override {
70     AU.setPreservesAll();
71   }
72
73   void releaseMemory() override {
74     DT.releaseMemory();
75   }
76
77   void print(raw_ostream &OS, const Module*) const override;
78 };
79
80 FunctionPass* createPostDomTree();
81
82 template <> struct GraphTraits<PostDominatorTree*>
83   : public GraphTraits<DomTreeNode*> {
84   static NodeRef getEntryNode(PostDominatorTree *DT) {
85     return DT->getRootNode();
86   }
87
88   static nodes_iterator nodes_begin(PostDominatorTree *N) {
89     if (getEntryNode(N))
90       return df_begin(getEntryNode(N));
91     else
92       return df_end(getEntryNode(N));
93   }
94
95   static nodes_iterator nodes_end(PostDominatorTree *N) {
96     return df_end(getEntryNode(N));
97   }
98 };
99
100 } // End llvm namespace
101
102 #endif