15 #ifndef LLVM_SUPPORT_CFG_H
16 #define LLVM_SUPPORT_CFG_H
28 template <
class Ptr,
class USE_iterator>
29 class PredIterator :
public std::iterator<std::forward_iterator_tag,
30 Ptr, ptrdiff_t, Ptr*, Ptr*> {
31 typedef std::iterator<std::forward_iterator_tag, Ptr, ptrdiff_t, Ptr*,
36 inline void advancePastNonTerminators() {
38 while (!It.atEnd() && !isa<TerminatorInst>(*It))
48 advancePastNonTerminators();
56 assert(!It.atEnd() &&
"pred_iterator out of range!");
57 return cast<TerminatorInst>(*It)->getParent();
62 assert(!It.atEnd() &&
"pred_iterator out of range!");
63 ++It; advancePastNonTerminators();
68 Self tmp = *
this; ++*
this;
return tmp;
74 return It.getOperandNo();
103 template <
class Term_,
class BB_>
104 class SuccIterator :
public std::iterator<std::bidirectional_iterator_tag,
105 BB_, ptrdiff_t, BB_*, BB_*> {
108 typedef std::iterator<std::bidirectional_iterator_tag, BB_, ptrdiff_t, BB_*,
112 inline bool index_is_valid(
int idx) {
113 return idx >= 0 && (
unsigned) idx < Term->getNumSuccessors();
126 idx = Term->getNumSuccessors();
137 assert(Term == I.Term &&
"Cannot assign iterators to two different blocks!");
155 Self tmp = *
this; ++*
this;
return tmp;
160 Self tmp = *
this; --*
this;
return tmp;
164 assert(Term == x.Term &&
"Cannot compare iterators of different blocks!");
169 assert(Term == x.Term &&
"Cannot compare iterators of different blocks!");
173 assert(Term == x.Term &&
"Cannot compare iterators of different blocks!");
178 assert(Term == x.Term &&
"Cannot compare iterators of different blocks!");
183 unsigned new_idx = idx + Right;
184 assert(index_is_valid(new_idx) &&
"Iterator index out of bound");
204 assert(Term == x.Term &&
"Cannot work on iterators of different blocks!");
205 int distance = idx - x.idx;
221 assert(Term &&
"Source not available, if basic block was malformed");
222 return Term->getParent();
static NodeType * getEntryNode(Inverse< Function * > G)
SuccIterator< const TerminatorInst *, const BasicBlock > succ_const_iterator
bool operator==(const Self &x) const
bool operator==(const Self &x) const
static ChildIteratorType child_begin(NodeType *N)
bool operator!=(const Self &x) const
static ChildIteratorType child_end(NodeType *N)
PredIterator< const BasicBlock, Value::const_use_iterator > const_pred_iterator
PredIterator(Ptr *bb, bool)
static ChildIteratorType child_begin(NodeType *N)
static ChildIteratorType child_end(NodeType *N)
static NodeType * getEntryNode(const BasicBlock *BB)
bool operator>=(const Self &x) const
succ_const_iterator ChildIteratorType
super::reference reference
Interval::succ_iterator succ_begin(Interval *I)
succ_iterator ChildIteratorType
Self operator-(int Right)
static NodeType * getEntryNode(BasicBlock *BB)
bool operator<(const Self &x) const
unsigned getOperandNo() const
bool operator>(const Self &x) const
Interval::succ_iterator succ_end(Interval *I)
static nodes_iterator nodes_begin(const Function *F)
reference operator*() const
SuccIterator< TerminatorInst *, BasicBlock > succ_iterator
LLVM Basic Block Representation.
Interval::pred_iterator pred_begin(Interval *I)
Interval::pred_iterator pred_end(Interval *I)
bool operator<=(const Self &x) const
static nodes_iterator nodes_end(const Function *F)
const Self & operator=(const Self &I)
static ChildIteratorType child_end(NodeType *N)
static ChildIteratorType child_begin(NodeType *N)
unsigned getSuccessorIndex() const
static NodeType * getEntryNode(Function *F)
const BasicBlock & getEntryBlock() const
reference operator*() const
BB_ * getSource()
Get the source BB of this iterator.
static ChildIteratorType child_begin(NodeType *N)
super::reference reference
static size_t size(const Function *F)
pointer operator->() const
pred_iterator ChildIteratorType
SuccIterator(Term_ T, bool)
bool operator!=(const Self &x) const
Self operator+(int Right)
Function::iterator nodes_iterator
static NodeType * getEntryNode(const Function *F)
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
const BasicBlock NodeType
static NodeType * getEntryNode(Inverse< BasicBlock * > G)
static nodes_iterator nodes_end(Function *F)
static ChildIteratorType child_end(NodeType *N)
Self & operator+=(int Right)
int operator-(const Self &x)
const BasicBlock NodeType
static nodes_iterator nodes_begin(Function *F)
const_pred_iterator ChildIteratorType
static NodeType * getEntryNode(Inverse< const BasicBlock * > G)
PredIterator< BasicBlock, Value::use_iterator > pred_iterator
static NodeType * getEntryNode(Inverse< const Function * > G)
Self & operator-=(int Right)
Function::const_iterator nodes_iterator
static size_t size(Function *F)
pointer * operator->() const