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/IR/Dominators.h"
18 #include "llvm/IR/PassManager.h"
22 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
23 /// compute the post-dominator tree.
25 struct PostDominatorTree : public DominatorTreeBase<BasicBlock> {
26 typedef DominatorTreeBase<BasicBlock> Base;
28 PostDominatorTree() : DominatorTreeBase<BasicBlock>(true) {}
31 /// \brief Analysis pass which computes a \c PostDominatorTree.
32 class PostDominatorTreeAnalysis
33 : public AnalysisInfoMixin<PostDominatorTreeAnalysis> {
34 friend AnalysisInfoMixin<PostDominatorTreeAnalysis>;
35 static AnalysisKey Key;
38 /// \brief Provide the result typedef for this analysis pass.
39 typedef PostDominatorTree Result;
41 /// \brief Run the analysis pass over a function and produce a post dominator
43 PostDominatorTree run(Function &F, FunctionAnalysisManager &);
46 /// \brief Printer pass for the \c PostDominatorTree.
47 class PostDominatorTreePrinterPass
48 : public PassInfoMixin<PostDominatorTreePrinterPass> {
52 explicit PostDominatorTreePrinterPass(raw_ostream &OS);
53 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
56 struct PostDominatorTreeWrapperPass : public FunctionPass {
57 static char ID; // Pass identification, replacement for typeid
60 PostDominatorTreeWrapperPass() : FunctionPass(ID) {
61 initializePostDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
64 PostDominatorTree &getPostDomTree() { return DT; }
65 const PostDominatorTree &getPostDomTree() const { return DT; }
67 bool runOnFunction(Function &F) override;
69 void getAnalysisUsage(AnalysisUsage &AU) const override {
73 void releaseMemory() override {
77 void print(raw_ostream &OS, const Module*) const override;
80 FunctionPass* createPostDomTree();
82 template <> struct GraphTraits<PostDominatorTree*>
83 : public GraphTraits<DomTreeNode*> {
84 static NodeRef getEntryNode(PostDominatorTree *DT) {
85 return DT->getRootNode();
88 static nodes_iterator nodes_begin(PostDominatorTree *N) {
90 return df_begin(getEntryNode(N));
92 return df_end(getEntryNode(N));
95 static nodes_iterator nodes_end(PostDominatorTree *N) {
96 return df_end(getEntryNode(N));
100 } // End llvm namespace