diff options
-rw-r--r-- | llvm/include/llvm/CodeGen/MachineDominators.h | 41 | ||||
-rw-r--r-- | llvm/include/llvm/IR/Dominators.h | 51 |
2 files changed, 32 insertions, 60 deletions
diff --git a/llvm/include/llvm/CodeGen/MachineDominators.h b/llvm/include/llvm/CodeGen/MachineDominators.h index 0ac8a5d0e2a..a69936f6e26 100644 --- a/llvm/include/llvm/CodeGen/MachineDominators.h +++ b/llvm/include/llvm/CodeGen/MachineDominators.h @@ -246,36 +246,29 @@ public: /// iterable by generic graph iterators. /// -template<class T> struct GraphTraits; +template <class Node, class ChildIterator> +struct MachineDomTreeGraphTraitsBase { + typedef Node NodeType; + typedef ChildIterator ChildIteratorType; -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) { + 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(); - } + static inline ChildIteratorType child_end(NodeType *N) { return N->end(); } }; -template <> struct GraphTraits<const MachineDomTreeNode *> { - typedef const MachineDomTreeNode NodeType; - typedef NodeType::const_iterator ChildIteratorType; +template <class T> struct GraphTraits; - 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<MachineDomTreeNode *> + : public MachineDomTreeGraphTraitsBase<MachineDomTreeNode, + MachineDomTreeNode::iterator> {}; + +template <> +struct GraphTraits<const MachineDomTreeNode *> + : public MachineDomTreeGraphTraitsBase<const MachineDomTreeNode, + MachineDomTreeNode::const_iterator> { }; template <> struct GraphTraits<MachineDominatorTree*> diff --git a/llvm/include/llvm/IR/Dominators.h b/llvm/include/llvm/IR/Dominators.h index 52c2a8e2fc4..f306b0fccc7 100644 --- a/llvm/include/llvm/IR/Dominators.h +++ b/llvm/include/llvm/IR/Dominators.h @@ -125,55 +125,34 @@ public: // DominatorTree GraphTraits specializations so the DominatorTree can be // iterable by generic graph iterators. -template <> struct GraphTraits<DomTreeNode*> { - typedef DomTreeNode NodeType; - typedef NodeType::iterator ChildIteratorType; +template <class Node, class ChildIterator> struct DomTreeGraphTraitsBase { + typedef Node NodeType; + typedef ChildIterator ChildIteratorType; + typedef df_iterator<Node *, SmallPtrSet<NodeType *, 8>> nodes_iterator; - static NodeType *getEntryNode(NodeType *N) { - return N; - } + 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(); - } + static inline ChildIteratorType child_end(NodeType *N) { return N->end(); } - typedef df_iterator<DomTreeNode*> nodes_iterator; - - static nodes_iterator nodes_begin(DomTreeNode *N) { + static nodes_iterator nodes_begin(NodeType *N) { return df_begin(getEntryNode(N)); } - static nodes_iterator nodes_end(DomTreeNode *N) { + static nodes_iterator nodes_end(NodeType *N) { return df_end(getEntryNode(N)); } }; -template <> struct GraphTraits<const DomTreeNode *> { - typedef const DomTreeNode NodeType; - typedef NodeType::const_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(); - } - - typedef df_iterator<const DomTreeNode *> nodes_iterator; - - static nodes_iterator nodes_begin(const DomTreeNode *N) { - return df_begin(getEntryNode(N)); - } +template <> +struct GraphTraits<DomTreeNode *> + : public DomTreeGraphTraitsBase<DomTreeNode, DomTreeNode::iterator> {}; - static nodes_iterator nodes_end(const DomTreeNode *N) { - return df_end(getEntryNode(N)); - } -}; +template <> +struct GraphTraits<const DomTreeNode *> + : public DomTreeGraphTraitsBase<const DomTreeNode, + DomTreeNode::const_iterator> {}; template <> struct GraphTraits<DominatorTree*> : public GraphTraits<DomTreeNode*> { |