2003-09-30 18:37:50 +00:00
|
|
|
//=- llvm/Analysis/PostDominators.h - Post Dominator Calculation-*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-08-21 23:43:50 +00:00
|
|
|
//
|
|
|
|
// This file exposes interfaces to post dominance information.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ANALYSIS_POST_DOMINATORS_H
|
|
|
|
#define LLVM_ANALYSIS_POST_DOMINATORS_H
|
|
|
|
|
|
|
|
#include "llvm/Analysis/Dominators.h"
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2004-02-29 23:55:11 +00:00
|
|
|
/// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
|
|
|
|
/// compute the a post-dominator tree.
|
|
|
|
///
|
2007-10-23 20:58:37 +00:00
|
|
|
struct PostDominatorTree : public FunctionPass {
|
2007-05-06 13:37:16 +00:00
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2007-10-23 20:58:37 +00:00
|
|
|
DominatorTreeBase<BasicBlock>* DT;
|
2007-05-01 21:15:47 +00:00
|
|
|
|
2010-08-06 18:33:48 +00:00
|
|
|
PostDominatorTree() : FunctionPass(ID) {
|
2007-10-23 21:42:49 +00:00
|
|
|
DT = new DominatorTreeBase<BasicBlock>(true);
|
2007-10-23 20:58:37 +00:00
|
|
|
}
|
2002-08-21 23:43:50 +00:00
|
|
|
|
2008-05-03 20:25:26 +00:00
|
|
|
~PostDominatorTree();
|
|
|
|
|
2007-10-03 03:20:17 +00:00
|
|
|
virtual bool runOnFunction(Function &F);
|
2002-08-21 23:43:50 +00:00
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
2010-01-11 22:22:46 +00:00
|
|
|
|
2007-10-23 20:58:37 +00:00
|
|
|
inline const std::vector<BasicBlock*> &getRoots() const {
|
|
|
|
return DT->getRoots();
|
|
|
|
}
|
2010-01-11 22:22:46 +00:00
|
|
|
|
2007-10-23 20:58:37 +00:00
|
|
|
inline DomTreeNode *getRootNode() const {
|
|
|
|
return DT->getRootNode();
|
|
|
|
}
|
2010-01-11 22:22:46 +00:00
|
|
|
|
2007-10-23 20:58:37 +00:00
|
|
|
inline DomTreeNode *operator[](BasicBlock *BB) const {
|
|
|
|
return DT->getNode(BB);
|
|
|
|
}
|
2010-01-11 22:22:46 +00:00
|
|
|
|
2010-01-11 22:22:32 +00:00
|
|
|
inline DomTreeNode *getNode(BasicBlock *BB) const {
|
|
|
|
return DT->getNode(BB);
|
|
|
|
}
|
|
|
|
|
2009-09-27 17:39:12 +00:00
|
|
|
inline bool dominates(DomTreeNode* A, DomTreeNode* B) const {
|
|
|
|
return DT->dominates(A, B);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool dominates(const BasicBlock* A, const BasicBlock* B) const {
|
|
|
|
return DT->dominates(A, B);
|
|
|
|
}
|
|
|
|
|
2007-10-23 20:58:37 +00:00
|
|
|
inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const {
|
|
|
|
return DT->properlyDominates(A, B);
|
|
|
|
}
|
2010-01-11 22:22:46 +00:00
|
|
|
|
2007-10-23 20:58:37 +00:00
|
|
|
inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const {
|
|
|
|
return DT->properlyDominates(A, B);
|
|
|
|
}
|
2008-02-27 18:38:29 +00:00
|
|
|
|
2010-03-07 11:15:04 +00:00
|
|
|
inline BasicBlock *findNearestCommonDominator(BasicBlock *A, BasicBlock *B) {
|
|
|
|
return DT->findNearestCommonDominator(A, B);
|
|
|
|
}
|
|
|
|
|
2009-09-27 17:39:12 +00:00
|
|
|
virtual void releaseMemory() {
|
|
|
|
DT->releaseMemory();
|
|
|
|
}
|
|
|
|
|
2009-08-23 06:03:38 +00:00
|
|
|
virtual void print(raw_ostream &OS, const Module*) const;
|
2002-08-21 23:43:50 +00:00
|
|
|
};
|
|
|
|
|
2008-05-29 17:00:13 +00:00
|
|
|
FunctionPass* createPostDomTree();
|
2002-08-21 23:43:50 +00:00
|
|
|
|
2009-10-18 04:05:53 +00:00
|
|
|
template <> struct GraphTraits<PostDominatorTree*>
|
|
|
|
: public GraphTraits<DomTreeNode*> {
|
|
|
|
static NodeType *getEntryNode(PostDominatorTree *DT) {
|
|
|
|
return DT->getRootNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
static nodes_iterator nodes_begin(PostDominatorTree *N) {
|
2009-11-30 12:06:37 +00:00
|
|
|
if (getEntryNode(N))
|
|
|
|
return df_begin(getEntryNode(N));
|
|
|
|
else
|
|
|
|
return df_end(getEntryNode(N));
|
2009-10-18 04:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static nodes_iterator nodes_end(PostDominatorTree *N) {
|
|
|
|
return df_end(getEntryNode(N));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-02-29 23:55:11 +00:00
|
|
|
/// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
|
|
|
|
/// used to compute the a post-dominance frontier.
|
|
|
|
///
|
2002-08-21 23:43:50 +00:00
|
|
|
struct PostDominanceFrontier : public DominanceFrontierBase {
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID;
|
2010-01-11 22:22:46 +00:00
|
|
|
PostDominanceFrontier()
|
2010-08-06 18:33:48 +00:00
|
|
|
: DominanceFrontierBase(ID, true) {}
|
2002-08-21 23:43:50 +00:00
|
|
|
|
|
|
|
virtual bool runOnFunction(Function &) {
|
|
|
|
Frontiers.clear();
|
|
|
|
PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
|
2003-09-10 20:36:51 +00:00
|
|
|
Roots = DT.getRoots();
|
2007-06-04 00:32:22 +00:00
|
|
|
if (const DomTreeNode *Root = DT.getRootNode())
|
2003-09-15 15:47:40 +00:00
|
|
|
calculate(DT, Root);
|
2002-08-21 23:43:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
AU.addRequired<PostDominatorTree>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const DomSetType &calculate(const PostDominatorTree &DT,
|
2007-06-04 00:32:22 +00:00
|
|
|
const DomTreeNode *Node);
|
2002-08-21 23:43:50 +00:00
|
|
|
};
|
|
|
|
|
2008-05-29 17:00:13 +00:00
|
|
|
FunctionPass* createPostDomFrontier();
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2002-08-21 23:43:50 +00:00
|
|
|
#endif
|