diff options
author | Chris Lattner <sabre@nondot.org> | 2001-09-28 22:56:31 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-09-28 22:56:31 +0000 |
commit | 3ff4387113d7e74a8aa73f80c3518cb95f09a64b (patch) | |
tree | 7e55b84e841721d133477294b2fee246ee6ceaed /include/llvm/BasicBlock.h | |
parent | c56d779501901e22103a1236768cb97fd9b5c9b0 (diff) |
Pull iterators out of CFG.h and CFGdecls and put them in Support directory
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@664 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/BasicBlock.h')
-rw-r--r-- | include/llvm/BasicBlock.h | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index fc41a12156..50ec4c0fbd 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -24,7 +24,9 @@ #include "llvm/Value.h" // Get the definition of Value #include "llvm/ValueHolder.h" -#include "llvm/CFGdecls.h" +#include "llvm/Support/GraphTraits.h" + +#include "llvm/CFGdecls.h" // TODO FIXME: remove class Instruction; class Method; @@ -140,4 +142,68 @@ public: BasicBlock *splitBasicBlock(iterator I); }; +#include "llvm/CFG.h" // TODO FIXME when succ iterators are in BB.h + +// Provide specializations of GraphTraits to be able to treat a method as a +// graph of basic blocks... + +template <> struct GraphTraits<BasicBlock*> { + typedef BasicBlock NodeType; + typedef BasicBlock::succ_iterator ChildIteratorType; + + static NodeType *getEntryNode(BasicBlock *BB) { return BB; } + static inline ChildIteratorType child_begin(NodeType *N) { + return cfg::succ_begin(N); + } + static inline ChildIteratorType child_end(NodeType *N) { + return cfg::succ_end(N); + } +}; + +template <> struct GraphTraits<const BasicBlock*> { + typedef const BasicBlock NodeType; + typedef BasicBlock::succ_const_iterator ChildIteratorType; + + static NodeType *getEntryNode(const BasicBlock *BB) { return BB; } + + static inline ChildIteratorType child_begin(NodeType *N) { + return cfg::succ_begin(N); + } + static inline ChildIteratorType child_end(NodeType *N) { + return cfg::succ_end(N); + } +}; + +// Provide specializations of GraphTraits to be able to treat a method as a +// graph of basic blocks... and to walk it in inverse order. Inverse order for +// a method is considered to be when traversing the predecessor edges of a BB +// instead of the successor edges. +// +template <> struct GraphTraits<Inverse<BasicBlock*> > { + typedef BasicBlock NodeType; + typedef BasicBlock::pred_iterator ChildIteratorType; + static NodeType *getEntryNode(Inverse<BasicBlock *> G) { return G.Graph; } + static inline ChildIteratorType child_begin(NodeType *N) { + return cfg::pred_begin(N); + } + static inline ChildIteratorType child_end(NodeType *N) { + return cfg::pred_end(N); + } +}; + +template <> struct GraphTraits<Inverse<const BasicBlock*> > { + typedef const BasicBlock NodeType; + typedef BasicBlock::pred_const_iterator ChildIteratorType; + static NodeType *getEntryNode(Inverse<const BasicBlock*> G) { + return G.Graph; + } + static inline ChildIteratorType child_begin(NodeType *N) { + return cfg::pred_begin(N); + } + static inline ChildIteratorType child_end(NodeType *N) { + return cfg::pred_end(N); + } +}; + + #endif |