LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PostDominators.h

Go to the documentation of this file.
00001 //=- llvm/Analysis/PostDominators.h - Post Dominator Calculation-*- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file exposes interfaces to post dominance information.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_ANALYSIS_POST_DOMINATORS_H
00015 #define LLVM_ANALYSIS_POST_DOMINATORS_H
00016 
00017 #include "llvm/Analysis/Dominators.h"
00018 
00019 namespace llvm {
00020 
00021 /// PostDominatorSet Class - Concrete subclass of DominatorSetBase that is used
00022 /// to compute the post-dominator set.  Because there can be multiple exit nodes
00023 /// in an LLVM function, we calculate post dominators with a special null block
00024 /// which is the virtual exit node that the real exit nodes all virtually branch
00025 /// to.  Clients should be prepared to see an entry in the dominator sets with a
00026 /// null BasicBlock*.
00027 ///
00028 struct PostDominatorSet : public DominatorSetBase {
00029   PostDominatorSet() : DominatorSetBase(true) {}
00030 
00031   virtual bool runOnFunction(Function &F);
00032 
00033   /// getAnalysisUsage - This pass does not modify the function at all.
00034   ///
00035   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
00036     AU.setPreservesAll();
00037   }
00038 };
00039 
00040 
00041 /// ImmediatePostDominators Class - Concrete subclass of ImmediateDominatorsBase
00042 /// that is used to compute the immediate post-dominators.
00043 ///
00044 struct ImmediatePostDominators : public ImmediateDominatorsBase {
00045   ImmediatePostDominators() : ImmediateDominatorsBase(true) {}
00046 
00047   virtual bool runOnFunction(Function &F) {
00048     IDoms.clear();     // Reset from the last time we were run...
00049     PostDominatorSet &DS = getAnalysis<PostDominatorSet>();
00050     Roots = DS.getRoots();
00051     calcIDoms(DS);
00052     return false;
00053   }
00054 
00055   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
00056     AU.setPreservesAll();
00057     AU.addRequired<PostDominatorSet>();
00058   }
00059 private:
00060   void calcIDoms(const DominatorSetBase &DS);
00061 };
00062 
00063 
00064 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
00065 /// compute the a post-dominator tree.
00066 ///
00067 struct PostDominatorTree : public DominatorTreeBase {
00068   PostDominatorTree() : DominatorTreeBase(true) {}
00069 
00070   virtual bool runOnFunction(Function &F) {
00071     reset();     // Reset from the last time we were run...
00072     PostDominatorSet &DS = getAnalysis<PostDominatorSet>();
00073     Roots = DS.getRoots();
00074     calculate(DS);
00075     return false;
00076   }
00077 
00078   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
00079     AU.setPreservesAll();
00080     AU.addRequired<PostDominatorSet>();
00081   }
00082 private:
00083   void calculate(const PostDominatorSet &DS);
00084 };
00085 
00086 
00087 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
00088 /// used to compute the a post-dominance frontier.
00089 ///
00090 struct PostDominanceFrontier : public DominanceFrontierBase {
00091   PostDominanceFrontier() : DominanceFrontierBase(true) {}
00092 
00093   virtual bool runOnFunction(Function &) {
00094     Frontiers.clear();
00095     PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
00096     Roots = DT.getRoots();
00097     if (const DominatorTree::Node *Root = DT.getRootNode())
00098       calculate(DT, Root);
00099     return false;
00100   }
00101 
00102   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
00103     AU.setPreservesAll();
00104     AU.addRequired<PostDominatorTree>();
00105   }
00106 
00107   // stub - dummy function, just ignore it
00108   static void stub();
00109 
00110 private:
00111   const DomSetType &calculate(const PostDominatorTree &DT,
00112                               const DominatorTree::Node *Node);
00113 };
00114 
00115 // Make sure that any clients of this file link in PostDominators.cpp
00116 static IncludeFile
00117 POST_DOMINATOR_INCLUDE_FILE((void*)&PostDominanceFrontier::stub);
00118 
00119 } // End llvm namespace
00120 
00121 #endif