From 1080b9ee534579c67f7c99364cc6fa11edbcd919 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 10 Jan 2005 23:05:53 +0000 Subject: [PATCH] Add support for graph operations, and add a viewGraph method to SelectionDAG. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19440 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/SelectionDAG.h | 19 ++++++++ include/llvm/CodeGen/SelectionDAGNodes.h | 58 ++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/include/llvm/CodeGen/SelectionDAG.h b/include/llvm/CodeGen/SelectionDAG.h index e6f89e9ec5f..fcf42daf5f6 100644 --- a/include/llvm/CodeGen/SelectionDAG.h +++ b/include/llvm/CodeGen/SelectionDAG.h @@ -73,6 +73,15 @@ public: 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::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 @@ private: void DeleteNodeIfDead(SDNode *N, void *NodeSet); }; +template <> struct GraphTraits : public GraphTraits { + 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 diff --git a/include/llvm/CodeGen/SelectionDAGNodes.h b/include/llvm/CodeGen/SelectionDAGNodes.h index 5eb3d5b148f..d61ce2d2b9f 100644 --- a/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/include/llvm/CodeGen/SelectionDAGNodes.h @@ -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 #include @@ -638,6 +641,61 @@ public: } }; + +class SDNodeIterator : public forward_iterator { + 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 { + 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 -- 2.34.1