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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 00:45:19 +00:00
|
|
|
#ifndef LLVM_ANALYSIS_POSTDOMINATORS_H
|
|
|
|
#define LLVM_ANALYSIS_POSTDOMINATORS_H
|
2002-08-21 23:43:50 +00:00
|
|
|
|
2014-01-13 09:26:24 +00:00
|
|
|
#include "llvm/IR/Dominators.h"
|
2002-08-21 23:43:50 +00:00
|
|
|
|
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
|
2014-08-29 21:53:01 +00:00
|
|
|
/// compute the post-dominator tree.
|
2004-02-29 23:55:11 +00:00
|
|
|
///
|
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) {
|
2010-10-19 17:21:58 +00:00
|
|
|
initializePostDominatorTreePass(*PassRegistry::getPassRegistry());
|
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
|
|
|
|
2015-04-11 02:11:45 +00:00
|
|
|
~PostDominatorTree() override;
|
2008-05-03 20:25:26 +00:00
|
|
|
|
2014-03-05 07:30:04 +00:00
|
|
|
bool runOnFunction(Function &F) override;
|
2002-08-21 23:43:50 +00:00
|
|
|
|
2014-03-05 07:30:04 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2002-08-21 23:43:50 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-06-09 15:09:30 +00:00
|
|
|
inline const BasicBlock *findNearestCommonDominator(const BasicBlock *A,
|
|
|
|
const BasicBlock *B) {
|
|
|
|
return DT->findNearestCommonDominator(A, B);
|
|
|
|
}
|
|
|
|
|
2013-11-26 20:11:12 +00:00
|
|
|
/// Get all nodes post-dominated by R, including R itself.
|
|
|
|
void getDescendants(BasicBlock *R,
|
|
|
|
SmallVectorImpl<BasicBlock *> &Result) const {
|
|
|
|
DT->getDescendants(R, Result);
|
|
|
|
}
|
|
|
|
|
2014-03-05 07:30:04 +00:00
|
|
|
void releaseMemory() override {
|
2009-09-27 17:39:12 +00:00
|
|
|
DT->releaseMemory();
|
|
|
|
}
|
|
|
|
|
2014-03-05 07:30:04 +00:00
|
|
|
void print(raw_ostream &OS, const Module*) const override;
|
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));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-23 09:49:53 +00:00
|
|
|
} // End llvm namespace
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2002-08-21 23:43:50 +00:00
|
|
|
#endif
|