X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FCFG.h;h=f5dc8ea055a37e064f4f0776714a2fe887f4ea9e;hb=cbeb8d9869aafec3c2c1ee0922f0a4d5bb4a916a;hp=1aa289178bc494b62ebfc560d955ac497db5369c;hpb=6193e5b128489c529176c038c76c11e549c4ee12;p=oota-llvm.git diff --git a/include/llvm/Support/CFG.h b/include/llvm/Support/CFG.h index 1aa289178bc..f5dc8ea055a 100644 --- a/include/llvm/Support/CFG.h +++ b/include/llvm/Support/CFG.h @@ -25,7 +25,7 @@ namespace llvm { // BasicBlock pred_iterator definition //===----------------------------------------------------------------------===// -template // Predecessor Iterator +template // Predecessor Iterator class PredIterator : public std::iterator { typedef std::iterator super; @@ -33,7 +33,7 @@ class PredIterator : public std::iterator(*It)) ++It; } @@ -41,7 +41,8 @@ class PredIterator : public std::iteratoruse_begin()) { + PredIterator() {} + explicit inline PredIterator(Ptr *bb) : It(bb->use_begin()) { advancePastNonTerminators(); } inline PredIterator(Ptr *bb, bool) : It(bb->use_end()) {} @@ -53,7 +54,7 @@ public: assert(!It.atEnd() && "pred_iterator out of range!"); return cast(*It)->getParent(); } - inline pointer *operator->() const { return &(operator*()); } + inline pointer *operator->() const { return &operator*(); } inline Self& operator++() { // Preincrement assert(!It.atEnd() && "pred_iterator out of range!"); @@ -64,6 +65,18 @@ public: inline Self operator++(int) { // Postincrement Self tmp = *this; ++*this; return tmp; } + + /// getOperandNo - Return the operand number in the predecessor's + /// terminator of the successor. + unsigned getOperandNo() const { + return It.getOperandNo(); + } + + /// getUse - Return the operand Use in the predecessor's terminator + /// of the successor. + Use &getUse() const { + return It.getUse(); + } }; typedef PredIterator pred_iterator; @@ -101,12 +114,19 @@ public: typedef typename super::pointer pointer; // TODO: This can be random access iterator, only operator[] missing. - inline SuccIterator(Term_ T) : Term(T), idx(0) { // begin iterator - assert(T && "getTerminator returned null!"); + explicit inline SuccIterator(Term_ T) : Term(T), idx(0) {// begin iterator } inline SuccIterator(Term_ T, bool) // end iterator - : Term(T), idx(Term->getNumSuccessors()) { - assert(T && "getTerminator returned null!"); + : Term(T) { + if (Term) + idx = Term->getNumSuccessors(); + else + // Term == NULL happens, if a basic block is not fully constructed and + // consequently getTerminator() returns NULL. In this case we construct a + // SuccIterator which describes a basic block that has zero successors. + // Defining SuccIterator for incomplete and malformed CFGs is especially + // useful for debugging. + idx = 0; } inline const Self &operator=(const Self &I) { @@ -194,7 +214,8 @@ public: /// Get the source BB of this iterator. inline BB_ *getSource() { - return Term->getParent(); + assert(Term && "Source not available, if basic block was malformed"); + return Term->getParent(); } }; @@ -299,6 +320,7 @@ template <> struct GraphTraits : public GraphTraits { typedef Function::iterator nodes_iterator; static nodes_iterator nodes_begin(Function *F) { return F->begin(); } static nodes_iterator nodes_end (Function *F) { return F->end(); } + static unsigned size (Function *F) { return F->size(); } }; template <> struct GraphTraits : public GraphTraits { @@ -308,6 +330,7 @@ template <> struct GraphTraits : typedef Function::const_iterator nodes_iterator; static nodes_iterator nodes_begin(const Function *F) { return F->begin(); } static nodes_iterator nodes_end (const Function *F) { return F->end(); } + static unsigned size (const Function *F) { return F->size(); } };