1 //=- llvm/Analysis/PostDominators.h - Post Dominator Calculation --*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes interfaces to post dominance information.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_POSTDOMINATORS_H
15 #define LLVM_ANALYSIS_POSTDOMINATORS_H
17 #include "llvm/ADT/DepthFirstIterator.h"
18 #include "llvm/IR/Dominators.h"
19 #include "llvm/IR/PassManager.h"
20 #include "llvm/Pass.h"
27 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
28 /// compute the post-dominator tree.
29 struct PostDominatorTree : public PostDomTreeBase<BasicBlock> {
30 using Base = PostDomTreeBase<BasicBlock>;
32 /// Handle invalidation explicitly.
33 bool invalidate(Function &F, const PreservedAnalyses &PA,
34 FunctionAnalysisManager::Invalidator &);
37 /// \brief Analysis pass which computes a \c PostDominatorTree.
38 class PostDominatorTreeAnalysis
39 : public AnalysisInfoMixin<PostDominatorTreeAnalysis> {
40 friend AnalysisInfoMixin<PostDominatorTreeAnalysis>;
42 static AnalysisKey Key;
45 /// \brief Provide the result type for this analysis pass.
46 using Result = PostDominatorTree;
48 /// \brief Run the analysis pass over a function and produce a post dominator
50 PostDominatorTree run(Function &F, FunctionAnalysisManager &);
53 /// \brief Printer pass for the \c PostDominatorTree.
54 class PostDominatorTreePrinterPass
55 : public PassInfoMixin<PostDominatorTreePrinterPass> {
59 explicit PostDominatorTreePrinterPass(raw_ostream &OS);
61 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
64 struct PostDominatorTreeWrapperPass : public FunctionPass {
65 static char ID; // Pass identification, replacement for typeid
69 PostDominatorTreeWrapperPass() : FunctionPass(ID) {
70 initializePostDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
73 PostDominatorTree &getPostDomTree() { return DT; }
74 const PostDominatorTree &getPostDomTree() const { return DT; }
76 bool runOnFunction(Function &F) override;
78 void getAnalysisUsage(AnalysisUsage &AU) const override {
82 void releaseMemory() override {
86 void print(raw_ostream &OS, const Module*) const override;
89 FunctionPass* createPostDomTree();
91 template <> struct GraphTraits<PostDominatorTree*>
92 : public GraphTraits<DomTreeNode*> {
93 static NodeRef getEntryNode(PostDominatorTree *DT) {
94 return DT->getRootNode();
97 static nodes_iterator nodes_begin(PostDominatorTree *N) {
99 return df_begin(getEntryNode(N));
101 return df_end(getEntryNode(N));
104 static nodes_iterator nodes_end(PostDominatorTree *N) {
105 return df_end(getEntryNode(N));
109 } // end namespace llvm
111 #endif // LLVM_ANALYSIS_POSTDOMINATORS_H