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) {}
30 /// Handle invalidation explicitly.
31 bool invalidate(Function &F, const PreservedAnalyses &PA,
32 FunctionAnalysisManager::Invalidator &);
35 /// \brief Analysis pass which computes a \c PostDominatorTree.
36 class PostDominatorTreeAnalysis
37 : public AnalysisInfoMixin<PostDominatorTreeAnalysis> {
38 friend AnalysisInfoMixin<PostDominatorTreeAnalysis>;
39 static AnalysisKey Key;
42 /// \brief Provide the result typedef for this analysis pass.
43 typedef PostDominatorTree Result;
45 /// \brief Run the analysis pass over a function and produce a post dominator
47 PostDominatorTree run(Function &F, FunctionAnalysisManager &);
50 /// \brief Printer pass for the \c PostDominatorTree.
51 class PostDominatorTreePrinterPass
52 : public PassInfoMixin<PostDominatorTreePrinterPass> {
56 explicit PostDominatorTreePrinterPass(raw_ostream &OS);
57 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
60 struct PostDominatorTreeWrapperPass : public FunctionPass {
61 static char ID; // Pass identification, replacement for typeid
64 PostDominatorTreeWrapperPass() : FunctionPass(ID) {
65 initializePostDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
68 PostDominatorTree &getPostDomTree() { return DT; }
69 const PostDominatorTree &getPostDomTree() const { return DT; }
71 bool runOnFunction(Function &F) override;
73 void getAnalysisUsage(AnalysisUsage &AU) const override {
77 void releaseMemory() override {
81 void print(raw_ostream &OS, const Module*) const override;
84 FunctionPass* createPostDomTree();
86 template <> struct GraphTraits<PostDominatorTree*>
87 : public GraphTraits<DomTreeNode*> {
88 static NodeRef getEntryNode(PostDominatorTree *DT) {
89 return DT->getRootNode();
92 static nodes_iterator nodes_begin(PostDominatorTree *N) {
94 return df_begin(getEntryNode(N));
96 return df_end(getEntryNode(N));
99 static nodes_iterator nodes_end(PostDominatorTree *N) {
100 return df_end(getEntryNode(N));
104 } // End llvm namespace