From 433c477edd7b66f823a823a597a6b65eab2941f1 Mon Sep 17 00:00:00 2001 From: Cong Hou Date: Fri, 7 Aug 2015 18:04:17 +0000 Subject: [PATCH] NFC. Use a parent class to avoid reduncant code when specializing GraphTraits for T and const T. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244340 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineDominators.h | 41 ++++++++----------- include/llvm/IR/Dominators.h | 51 +++++++----------------- 2 files changed, 32 insertions(+), 60 deletions(-) diff --git a/include/llvm/CodeGen/MachineDominators.h b/include/llvm/CodeGen/MachineDominators.h index 0ac8a5d0e2a..a69936f6e26 100644 --- a/include/llvm/CodeGen/MachineDominators.h +++ b/include/llvm/CodeGen/MachineDominators.h @@ -246,36 +246,29 @@ public: /// iterable by generic graph iterators. /// -template struct GraphTraits; +template +struct MachineDomTreeGraphTraitsBase { + typedef Node NodeType; + typedef ChildIterator ChildIteratorType; -template <> struct GraphTraits { - 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 { - typedef const MachineDomTreeNode NodeType; - typedef NodeType::const_iterator ChildIteratorType; +template 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 + : public MachineDomTreeGraphTraitsBase {}; + +template <> +struct GraphTraits + : public MachineDomTreeGraphTraitsBase { }; template <> struct GraphTraits diff --git a/include/llvm/IR/Dominators.h b/include/llvm/IR/Dominators.h index 52c2a8e2fc4..f306b0fccc7 100644 --- a/include/llvm/IR/Dominators.h +++ b/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 { - typedef DomTreeNode NodeType; - typedef NodeType::iterator ChildIteratorType; +template struct DomTreeGraphTraitsBase { + typedef Node NodeType; + typedef ChildIterator ChildIteratorType; + typedef df_iterator> 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 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 { - 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 nodes_iterator; - - static nodes_iterator nodes_begin(const DomTreeNode *N) { - return df_begin(getEntryNode(N)); - } +template <> +struct GraphTraits + : public DomTreeGraphTraitsBase {}; - static nodes_iterator nodes_end(const DomTreeNode *N) { - return df_end(getEntryNode(N)); - } -}; +template <> +struct GraphTraits + : public DomTreeGraphTraitsBase {}; template <> struct GraphTraits : public GraphTraits { -- 2.34.1