[llvm-commits] CVS: llvm/include/llvm/CodeGen/SelectionDAG.h SelectionDAGNodes.h
Chris Lattner
lattner at cs.uiuc.edu
Wed Nov 9 15:46:54 PST 2005
Changes in directory llvm/include/llvm/CodeGen:
SelectionDAG.h updated: 1.67 -> 1.68
SelectionDAGNodes.h updated: 1.72 -> 1.73
---
Log message:
Switch the allnodes list from a vector of pointers to an ilist of nodes.
This eliminates the vector, allows constant time removal of a node from
a graph, and makes iteration over the all nodes list stable when adding
nodes to the graph.
---
Diffs of the changes: (+52 -14)
SelectionDAG.h | 20 ++++++++++++--------
SelectionDAGNodes.h | 46 ++++++++++++++++++++++++++++++++++++++++------
2 files changed, 52 insertions(+), 14 deletions(-)
Index: llvm/include/llvm/CodeGen/SelectionDAG.h
diff -u llvm/include/llvm/CodeGen/SelectionDAG.h:1.67 llvm/include/llvm/CodeGen/SelectionDAG.h:1.68
--- llvm/include/llvm/CodeGen/SelectionDAG.h:1.67 Tue Nov 8 17:30:11 2005
+++ llvm/include/llvm/CodeGen/SelectionDAG.h Wed Nov 9 17:46:43 2005
@@ -16,6 +16,8 @@
#define LLVM_CODEGEN_SELECTIONDAG_H
#include "llvm/CodeGen/SelectionDAGNodes.h"
+#include "llvm/ADT/ilist"
+
#include <map>
#include <list>
#include <string> // FIXME remove eventually, turning map into const char* map.
@@ -43,8 +45,8 @@
// Root - The root of the entire DAG. EntryNode - The starting token.
SDOperand Root, EntryNode;
- // AllNodes - All of the nodes in the DAG
- std::vector<SDNode*> AllNodes;
+ // AllNodes - A linked list of nodes in the current DAG.
+ ilist<SDNode> AllNodes;
// ValueNodes - track SrcValue nodes
std::map<std::pair<const Value*, int>, SDNode*> ValueNodes;
@@ -64,11 +66,13 @@
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(); }
- unsigned allnodes_size() const { return AllNodes.size(); }
-
+ typedef ilist<SDNode>::const_iterator allnodes_const_iterator;
+ allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
+ allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
+ typedef ilist<SDNode>::iterator allnodes_iterator;
+ allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
+ allnodes_iterator allnodes_end() { return AllNodes.end(); }
+
/// getRoot - Return the root tag of the SelectionDAG.
///
const SDOperand &getRoot() const { return Root; }
@@ -413,6 +417,6 @@
}
};
-}
+} // end namespace llvm
#endif
Index: llvm/include/llvm/CodeGen/SelectionDAGNodes.h
diff -u llvm/include/llvm/CodeGen/SelectionDAGNodes.h:1.72 llvm/include/llvm/CodeGen/SelectionDAGNodes.h:1.73
--- llvm/include/llvm/CodeGen/SelectionDAGNodes.h:1.72 Tue Nov 8 17:30:11 2005
+++ llvm/include/llvm/CodeGen/SelectionDAGNodes.h Wed Nov 9 17:46:43 2005
@@ -22,7 +22,6 @@
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/Value.h"
#include "llvm/ADT/GraphTraits.h"
-#include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/iterator"
#include "llvm/Support/DataTypes.h"
#include <cassert>
@@ -35,6 +34,9 @@
class MachineBasicBlock;
class SDNode;
template <typename T> struct simplify_type;
+template <typename T> struct ilist_traits;
+template<typename NodeTy, typename Traits> class iplist;
+template<typename NodeTy> class ilist_iterator;
/// ISD namespace - This namespace contains an enum which represents all of the
/// SelectionDAG node types and value types.
@@ -501,12 +503,20 @@
/// NumOperands/NumValues - The number of entries in the Operand/Value list.
unsigned short NumOperands, NumValues;
+
+ /// Prev/Next pointers - These pointers form the linked list of of the
+ /// AllNodes list in the current DAG.
+ SDNode *Prev, *Next;
+ friend struct ilist_traits<SDNode>;
/// Uses - These are all of the SDNode's that use a value produced by this
/// node.
std::vector<SDNode*> Uses;
public:
-
+ virtual ~SDNode() {
+ assert(NumOperands == 0 && "Operand list not cleared before deletion");
+ }
+
//===--------------------------------------------------------------------===//
// Accessors
//
@@ -586,6 +596,7 @@
OperandList = 0; NumOperands = 0;
ValueList = getValueTypeList(VT);
NumValues = 1;
+ Prev = 0; Next = 0;
}
SDNode(unsigned NT, SDOperand Op)
: NodeType(NT), NodeDepth(Op.Val->getNodeDepth()+1) {
@@ -595,6 +606,7 @@
Op.Val->Uses.push_back(this);
ValueList = 0;
NumValues = 0;
+ Prev = 0; Next = 0;
}
SDNode(unsigned NT, SDOperand N1, SDOperand N2)
: NodeType(NT) {
@@ -609,6 +621,7 @@
N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
ValueList = 0;
NumValues = 0;
+ Prev = 0; Next = 0;
}
SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
: NodeType(NT) {
@@ -629,6 +642,7 @@
N3.Val->Uses.push_back(this);
ValueList = 0;
NumValues = 0;
+ Prev = 0; Next = 0;
}
SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4)
: NodeType(NT) {
@@ -652,6 +666,7 @@
N3.Val->Uses.push_back(this); N4.Val->Uses.push_back(this);
ValueList = 0;
NumValues = 0;
+ Prev = 0; Next = 0;
}
SDNode(unsigned Opc, const std::vector<SDOperand> &Nodes) : NodeType(Opc) {
NumOperands = Nodes.size();
@@ -667,10 +682,7 @@
NodeDepth = ND+1;
ValueList = 0;
NumValues = 0;
- }
-
- virtual ~SDNode() {
- assert(NumOperands == 0 && "Operand list not cleared before deletion");
+ Prev = 0; Next = 0;
}
/// MorphNodeTo - This clears the return value and operands list, and sets the
@@ -1075,6 +1087,28 @@
}
};
+template<>
+struct ilist_traits<SDNode> {
+ static SDNode *getPrev(const SDNode *N) { return N->Prev; }
+ static SDNode *getNext(const SDNode *N) { return N->Next; }
+
+ static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
+ static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
+
+ static SDNode *createSentinel() {
+ return new SDNode(ISD::EntryToken, MVT::Other);
+ }
+ static void destroySentinel(SDNode *N) { delete N; }
+ //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
+
+
+ void addNodeToList(SDNode *NTy) {}
+ void removeNodeFromList(SDNode *NTy) {}
+ void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
+ const ilist_iterator<SDNode> &X,
+ const ilist_iterator<SDNode> &Y) {}
+};
+
} // end llvm namespace
#endif
More information about the llvm-commits
mailing list