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 PostDomTreeBase<BasicBlock> {
26 typedef PostDomTreeBase<BasicBlock> Base;
28 /// Handle invalidation explicitly.
29 bool invalidate(Function &F, const PreservedAnalyses &PA,
30 FunctionAnalysisManager::Invalidator &);
33 /// \brief Analysis pass which computes a \c PostDominatorTree.
34 class PostDominatorTreeAnalysis
35 : public AnalysisInfoMixin<PostDominatorTreeAnalysis> {
36 friend AnalysisInfoMixin<PostDominatorTreeAnalysis>;
37 static AnalysisKey Key;
40 /// \brief Provide the result typedef for this analysis pass.
41 typedef PostDominatorTree Result;
43 /// \brief Run the analysis pass over a function and produce a post dominator
45 PostDominatorTree run(Function &F, FunctionAnalysisManager &);
48 /// \brief Printer pass for the \c PostDominatorTree.
49 class PostDominatorTreePrinterPass
50 : public PassInfoMixin<PostDominatorTreePrinterPass> {
54 explicit PostDominatorTreePrinterPass(raw_ostream &OS);
55 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
58 struct PostDominatorTreeWrapperPass : public FunctionPass {
59 static char ID; // Pass identification, replacement for typeid
62 PostDominatorTreeWrapperPass() : FunctionPass(ID) {
63 initializePostDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
66 PostDominatorTree &getPostDomTree() { return DT; }
67 const PostDominatorTree &getPostDomTree() const { return DT; }
69 bool runOnFunction(Function &F) override;
71 void getAnalysisUsage(AnalysisUsage &AU) const override {
75 void releaseMemory() override {
79 void print(raw_ostream &OS, const Module*) const override;
82 FunctionPass* createPostDomTree();
84 template <> struct GraphTraits<PostDominatorTree*>
85 : public GraphTraits<DomTreeNode*> {
86 static NodeRef getEntryNode(PostDominatorTree *DT) {
87 return DT->getRootNode();
90 static nodes_iterator nodes_begin(PostDominatorTree *N) {
92 return df_begin(getEntryNode(N));
94 return df_end(getEntryNode(N));
97 static nodes_iterator nodes_end(PostDominatorTree *N) {
98 return df_end(getEntryNode(N));
102 } // End llvm namespace