NFC.
authorCong Hou <congh@google.com>
Fri, 7 Aug 2015 18:04:17 +0000 (18:04 +0000)
committerCong Hou <congh@google.com>
Fri, 7 Aug 2015 18:04:17 +0000 (18:04 +0000)
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
include/llvm/IR/Dominators.h

index 0ac8a5d0e2a4dafb24147a53a991c3528a6c9385..a69936f6e267ca339f2c6444e25bdf97be8eb69f 100644 (file)
@@ -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*>
index 52c2a8e2fc418c327ae9e1d54d08e981c3703d62..f306b0fccc72705ba53643f708f7bceff804f5d3 100644 (file)
@@ -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*> {