[llvm-commits] CVS: llvm/include/llvm/CodeGen/SelectionDAG.h SelectionDAGNodes.h

Chris Lattner lattner at cs.uiuc.edu
Mon Jan 10 15:06:09 PST 2005



Changes in directory llvm/include/llvm/CodeGen:

SelectionDAG.h updated: 1.8 -> 1.9
SelectionDAGNodes.h updated: 1.6 -> 1.7
---
Log message:

Add support for graph operations, and add a viewGraph method to SelectionDAG.


---
Diffs of the changes:  (+77 -0)

Index: llvm/include/llvm/CodeGen/SelectionDAG.h
diff -u llvm/include/llvm/CodeGen/SelectionDAG.h:1.8 llvm/include/llvm/CodeGen/SelectionDAG.h:1.9
--- llvm/include/llvm/CodeGen/SelectionDAG.h:1.8	Fri Jan  7 15:08:55 2005
+++ llvm/include/llvm/CodeGen/SelectionDAG.h	Mon Jan 10 17:05:53 2005
@@ -73,6 +73,15 @@
   MachineFunction &getMachineFunction() const { return MF; }
   const TargetMachine &getTarget() { return TM; }
 
+  /// viewGraph - Pop up a ghostview window with the DAG rendered using 'dot'.
+  ///
+  void viewGraph();
+
+
+  typedef std::vector<SDNode*>::const_iterator allnodes_iterator;
+  allnodes_iterator allnodes_begin() const { return AllNodes.begin(); }
+  allnodes_iterator allnodes_end() const { return AllNodes.end(); }
+  
   /// getRoot - Return the root tag of the SelectionDAG.
   ///
   const SDOperand &getRoot() const { return Root; }
@@ -161,6 +170,16 @@
   void DeleteNodeIfDead(SDNode *N, void *NodeSet);
 };
 
+template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
+  typedef SelectionDAG::allnodes_iterator nodes_iterator;
+  static nodes_iterator nodes_begin(SelectionDAG *G) {
+    return G->allnodes_begin();
+  }
+  static nodes_iterator nodes_end(SelectionDAG *G) {
+    return G->allnodes_end();
+  }
+};
+
 }
 
 #endif


Index: llvm/include/llvm/CodeGen/SelectionDAGNodes.h
diff -u llvm/include/llvm/CodeGen/SelectionDAGNodes.h:1.6 llvm/include/llvm/CodeGen/SelectionDAGNodes.h:1.7
--- llvm/include/llvm/CodeGen/SelectionDAGNodes.h:1.6	Sat Jan  8 13:49:51 2005
+++ llvm/include/llvm/CodeGen/SelectionDAGNodes.h	Mon Jan 10 17:05:53 2005
@@ -20,6 +20,9 @@
 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
 
 #include "llvm/CodeGen/ValueTypes.h"
+#include "llvm/ADT/GraphTraits.h"
+#include "llvm/ADT/GraphTraits.h"
+#include "llvm/ADT/iterator"
 #include "llvm/Support/DataTypes.h"
 #include <cassert>
 #include <vector>
@@ -638,6 +641,61 @@
   }
 };
 
+
+class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
+  SDNode *Node;
+  unsigned Operand;
+  
+  SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
+public:
+  bool operator==(const SDNodeIterator& x) const {
+    return Operand == x.Operand;
+  }
+  bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
+
+  const SDNodeIterator &operator=(const SDNodeIterator &I) {
+    assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
+    Operand = I.Operand;
+    return *this;
+  }
+  
+  pointer operator*() const {
+    return Node->getOperand(Operand).Val;
+  }
+  pointer operator->() const { return operator*(); }
+  
+  SDNodeIterator& operator++() {                // Preincrement
+    ++Operand;
+    return *this;
+  }
+  SDNodeIterator operator++(int) { // Postincrement
+    SDNodeIterator tmp = *this; ++*this; return tmp; 
+  }
+
+  static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
+  static SDNodeIterator end  (SDNode *N) {
+    return SDNodeIterator(N, N->getNumOperands());
+  }
+
+  unsigned getOperand() const { return Operand; }
+  const SDNode *getNode() const { return Node; }
+};
+
+template <> struct GraphTraits<SDNode*> {
+  typedef SDNode NodeType;
+  typedef SDNodeIterator ChildIteratorType;
+  static inline NodeType *getEntryNode(SDNode *N) { return N; }
+  static inline ChildIteratorType child_begin(NodeType *N) { 
+    return SDNodeIterator::begin(N);
+  }
+  static inline ChildIteratorType child_end(NodeType *N) { 
+    return SDNodeIterator::end(N);
+  }
+};
+
+
+
+
 } // end llvm namespace
 
 #endif






More information about the llvm-commits mailing list