MachineDominators.h [plain text]
#ifndef LLVM_CODEGEN_MACHINEDOMINATORS_H
#define LLVM_CODEGEN_MACHINEDOMINATORS_H
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/DominatorInternals.h"
namespace llvm {
template<>
inline void DominatorTreeBase<MachineBasicBlock>::addRoot(MachineBasicBlock* MBB) {
this->Roots.push_back(MBB);
}
EXTERN_TEMPLATE_INSTANTIATION(class DomTreeNodeBase<MachineBasicBlock>);
EXTERN_TEMPLATE_INSTANTIATION(class DominatorTreeBase<MachineBasicBlock>);
typedef DomTreeNodeBase<MachineBasicBlock> MachineDomTreeNode;
class MachineDominatorTree : public MachineFunctionPass {
public:
static char ID; DominatorTreeBase<MachineBasicBlock>* DT;
MachineDominatorTree();
~MachineDominatorTree();
DominatorTreeBase<MachineBasicBlock>& getBase() { return *DT; }
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
inline const std::vector<MachineBasicBlock*> &getRoots() const {
return DT->getRoots();
}
inline MachineBasicBlock *getRoot() const {
return DT->getRoot();
}
inline MachineDomTreeNode *getRootNode() const {
return DT->getRootNode();
}
virtual bool runOnMachineFunction(MachineFunction &F);
inline bool dominates(MachineDomTreeNode* A, MachineDomTreeNode* B) const {
return DT->dominates(A, B);
}
inline bool dominates(MachineBasicBlock* A, MachineBasicBlock* B) const {
return DT->dominates(A, B);
}
bool dominates(MachineInstr *A, MachineInstr *B) const {
MachineBasicBlock *BBA = A->getParent(), *BBB = B->getParent();
if (BBA != BBB) return DT->dominates(BBA, BBB);
MachineBasicBlock::iterator I = BBA->begin();
for (; &*I != A && &*I != B; ++I) ;
return &*I == A;
}
inline bool properlyDominates(const MachineDomTreeNode* A,
MachineDomTreeNode* B) const {
return DT->properlyDominates(A, B);
}
inline bool properlyDominates(MachineBasicBlock* A,
MachineBasicBlock* B) const {
return DT->properlyDominates(A, B);
}
inline MachineBasicBlock *findNearestCommonDominator(MachineBasicBlock *A,
MachineBasicBlock *B) {
return DT->findNearestCommonDominator(A, B);
}
inline MachineDomTreeNode *operator[](MachineBasicBlock *BB) const {
return DT->getNode(BB);
}
inline MachineDomTreeNode *getNode(MachineBasicBlock *BB) const {
return DT->getNode(BB);
}
inline MachineDomTreeNode *addNewBlock(MachineBasicBlock *BB,
MachineBasicBlock *DomBB) {
return DT->addNewBlock(BB, DomBB);
}
inline void changeImmediateDominator(MachineBasicBlock *N,
MachineBasicBlock* NewIDom) {
DT->changeImmediateDominator(N, NewIDom);
}
inline void changeImmediateDominator(MachineDomTreeNode *N,
MachineDomTreeNode* NewIDom) {
DT->changeImmediateDominator(N, NewIDom);
}
inline void eraseNode(MachineBasicBlock *BB) {
DT->eraseNode(BB);
}
inline void splitBlock(MachineBasicBlock* NewBB) {
DT->splitBlock(NewBB);
}
bool isReachableFromEntry(MachineBasicBlock *A) {
return DT->isReachableFromEntry(A);
}
virtual void releaseMemory();
virtual void print(raw_ostream &OS, const Module*) const;
};
template<class T> struct GraphTraits;
template <> struct GraphTraits<MachineDomTreeNode *> {
typedef MachineDomTreeNode NodeType;
typedef NodeType::iterator ChildIteratorType;
static NodeType *getEntryNode(NodeType *N) {
return N;
}
static inline ChildIteratorType child_begin(NodeType* N) {
return N->begin();
}
static inline ChildIteratorType child_end(NodeType* N) {
return N->end();
}
};
template <> struct GraphTraits<MachineDominatorTree*>
: public GraphTraits<MachineDomTreeNode *> {
static NodeType *getEntryNode(MachineDominatorTree *DT) {
return DT->getRootNode();
}
};
}
#endif