Switch the Nodes list from being an std::vector<DSNode*> to an ilist<DSNode>
authorChris Lattner <sabre@nondot.org>
Sun, 8 Feb 2004 00:53:26 +0000 (00:53 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 8 Feb 2004 00:53:26 +0000 (00:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11173 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/DSGraph.h
include/llvm/Analysis/DSNode.h
include/llvm/Analysis/DataStructure/DSGraph.h
include/llvm/Analysis/DataStructure/DSNode.h
lib/Analysis/DataStructure/DataStructure.cpp

index 2cfcfb950564d355279bf3e4ee3786aea30e314f..568a90bc6062be7d82e837c06fb31eb76aeefe8e 100644 (file)
@@ -92,7 +92,7 @@ struct DSGraph {
   typedef DSScalarMap ScalarMapTy;
   typedef hash_map<Function*, DSNodeHandle> ReturnNodesTy;
   typedef hash_set<GlobalValue*> GlobalSetTy;
-  typedef std::vector<DSNode*> NodeListTy;
+  typedef ilist<DSNode> NodeListTy;
 
   /// NodeMapTy - This data type is used when cloning one graph into another to
   /// keep track of the correspondence between the nodes in the old and new
@@ -171,9 +171,9 @@ public:
 
   /// getNodes - Get a vector of all the nodes in the graph
   /// 
-  typedef NodeListTy::const_iterator node_iterator;
-  node_iterator node_begin() const { return Nodes.begin(); }
-  node_iterator node_end()   const { return Nodes.end(); }
+  typedef NodeListTy::compat_iterator node_iterator;
+  node_iterator node_begin() const { return Nodes.compat_begin(); }
+  node_iterator node_end()   const { return Nodes.compat_end(); }
 
   /// getFunctionNames - Return a space separated list of the name of the
   /// functions in this graph (if any)
index 6ddc7ec85e837f08dac41022117cb179adf5a7fd..e76a48090f0a7b6d8393dfc7da56c28d5b3301b6 100644 (file)
@@ -42,6 +42,11 @@ class DSNode {
   /// null.
   DSNodeHandle ForwardNH;
 
+  /// Next, Prev - These instance variables are used to keep the node on a
+  /// doubly-linked ilist in the DSGraph.
+  DSNode *Next, *Prev;
+  friend class ilist_traits<DSNode>;
+
   /// Size - The current size of the node.  This should be equal to the size of
   /// the current type record.
   ///
@@ -334,6 +339,30 @@ private:
   static void MergeNodes(DSNodeHandle& CurNodeH, DSNodeHandle& NH);
 };
 
+//===----------------------------------------------------------------------===//
+// Define the ilist_traits specialization for the DSGraph ilist.
+//
+template<>
+struct ilist_traits<DSNode> {
+  static DSNode *getPrev(const DSNode *N) { return N->Prev; }
+  static DSNode *getNext(const DSNode *N) { return N->Next; }
+
+  static void setPrev(DSNode *N, DSNode *Prev) { N->Prev = Prev; }
+  static void setNext(DSNode *N, DSNode *Next) { N->Next = Next; }
+
+  static DSNode *createNode() { return new DSNode(0,0); }
+  //static DSNode *createNode(const DSNode &V) { return new DSNode(V); }
+
+
+  void addNodeToList(DSNode *NTy) {}
+  void removeNodeFromList(DSNode *NTy) {}
+  void transferNodesFromList(iplist<DSNode, ilist_traits> &L2,
+                             ilist_iterator<DSNode> first,
+                             ilist_iterator<DSNode> last) {}
+};
+
+template<>
+struct ilist_traits<const DSNode> : public ilist_traits<DSNode> {};
 
 //===----------------------------------------------------------------------===//
 // Define inline DSNodeHandle functions that depend on the definition of DSNode
index 2cfcfb950564d355279bf3e4ee3786aea30e314f..568a90bc6062be7d82e837c06fb31eb76aeefe8e 100644 (file)
@@ -92,7 +92,7 @@ struct DSGraph {
   typedef DSScalarMap ScalarMapTy;
   typedef hash_map<Function*, DSNodeHandle> ReturnNodesTy;
   typedef hash_set<GlobalValue*> GlobalSetTy;
-  typedef std::vector<DSNode*> NodeListTy;
+  typedef ilist<DSNode> NodeListTy;
 
   /// NodeMapTy - This data type is used when cloning one graph into another to
   /// keep track of the correspondence between the nodes in the old and new
@@ -171,9 +171,9 @@ public:
 
   /// getNodes - Get a vector of all the nodes in the graph
   /// 
-  typedef NodeListTy::const_iterator node_iterator;
-  node_iterator node_begin() const { return Nodes.begin(); }
-  node_iterator node_end()   const { return Nodes.end(); }
+  typedef NodeListTy::compat_iterator node_iterator;
+  node_iterator node_begin() const { return Nodes.compat_begin(); }
+  node_iterator node_end()   const { return Nodes.compat_end(); }
 
   /// getFunctionNames - Return a space separated list of the name of the
   /// functions in this graph (if any)
index 6ddc7ec85e837f08dac41022117cb179adf5a7fd..e76a48090f0a7b6d8393dfc7da56c28d5b3301b6 100644 (file)
@@ -42,6 +42,11 @@ class DSNode {
   /// null.
   DSNodeHandle ForwardNH;
 
+  /// Next, Prev - These instance variables are used to keep the node on a
+  /// doubly-linked ilist in the DSGraph.
+  DSNode *Next, *Prev;
+  friend class ilist_traits<DSNode>;
+
   /// Size - The current size of the node.  This should be equal to the size of
   /// the current type record.
   ///
@@ -334,6 +339,30 @@ private:
   static void MergeNodes(DSNodeHandle& CurNodeH, DSNodeHandle& NH);
 };
 
+//===----------------------------------------------------------------------===//
+// Define the ilist_traits specialization for the DSGraph ilist.
+//
+template<>
+struct ilist_traits<DSNode> {
+  static DSNode *getPrev(const DSNode *N) { return N->Prev; }
+  static DSNode *getNext(const DSNode *N) { return N->Next; }
+
+  static void setPrev(DSNode *N, DSNode *Prev) { N->Prev = Prev; }
+  static void setNext(DSNode *N, DSNode *Next) { N->Next = Next; }
+
+  static DSNode *createNode() { return new DSNode(0,0); }
+  //static DSNode *createNode(const DSNode &V) { return new DSNode(V); }
+
+
+  void addNodeToList(DSNode *NTy) {}
+  void removeNodeFromList(DSNode *NTy) {}
+  void transferNodesFromList(iplist<DSNode, ilist_traits> &L2,
+                             ilist_iterator<DSNode> first,
+                             ilist_iterator<DSNode> last) {}
+};
+
+template<>
+struct ilist_traits<const DSNode> : public ilist_traits<DSNode> {};
 
 //===----------------------------------------------------------------------===//
 // Define inline DSNodeHandle functions that depend on the definition of DSNode
index 03f010a963321c39d9f8c594a99d42b3853df4af..9311b10151957c28317327bd0c5486d8a9d45a2a 100644 (file)
@@ -1041,11 +1041,11 @@ DSGraph::~DSGraph() {
   ReturnNodes.clear();
 
   // Drop all intra-node references, so that assertions don't fail...
-  std::for_each(Nodes.begin(), Nodes.end(),
-                std::mem_fun(&DSNode::dropAllReferences));
+  for (node_iterator NI = node_begin(), E = node_end(); NI != E; ++NI)
+    (*NI)->dropAllReferences();
 
-  // Delete all of the nodes themselves...
-  std::for_each(Nodes.begin(), Nodes.end(), deleter<DSNode>);
+  // Free all of the nodes.
+  Nodes.clear();
 }
 
 // dump - Allow inspection of graph in a debugger.
@@ -1496,45 +1496,44 @@ void DSGraph::removeTriviallyDeadNodes() {
   bool isGlobalsGraph = !GlobalsGraph;
 
   for (NodeListTy::iterator NI = Nodes.begin(), E = Nodes.end(); NI != E; ) {
-    DSNode *Node = *NI;
+    DSNode &Node = *NI;
 
     // Do not remove *any* global nodes in the globals graph.
     // This is a special case because such nodes may not have I, M, R flags set.
-    if (Node->isGlobalNode() && isGlobalsGraph) {
+    if (Node.isGlobalNode() && isGlobalsGraph) {
       ++NI;
       continue;
     }
 
-    if (Node->isComplete() && !Node->isModified() && !Node->isRead()) {
+    if (Node.isComplete() && !Node.isModified() && !Node.isRead()) {
       // This is a useless node if it has no mod/ref info (checked above),
       // outgoing edges (which it cannot, as it is not modified in this
       // context), and it has no incoming edges.  If it is a global node it may
       // have all of these properties and still have incoming edges, due to the
       // scalar map, so we check those now.
       //
-      if (Node->getNumReferrers() == Node->getGlobals().size()) {
-        const std::vector<GlobalValue*> &Globals = Node->getGlobals();
+      if (Node.getNumReferrers() == Node.getGlobals().size()) {
+        const std::vector<GlobalValue*> &Globals = Node.getGlobals();
 
         // Loop through and make sure all of the globals are referring directly
         // to the node...
         for (unsigned j = 0, e = Globals.size(); j != e; ++j) {
           DSNode *N = getNodeForValue(Globals[j]).getNode();
-          assert(N == Node && "ScalarMap doesn't match globals list!");
+          assert(N == &Node && "ScalarMap doesn't match globals list!");
         }
 
         // Make sure NumReferrers still agrees, if so, the node is truly dead.
-        if (Node->getNumReferrers() == Globals.size()) {
+        if (Node.getNumReferrers() == Globals.size()) {
           for (unsigned j = 0, e = Globals.size(); j != e; ++j)
             ScalarMap.erase(Globals[j]);
-          Node->makeNodeDead();
+          Node.makeNodeDead();
         }
       }
     }
 
-    if (Node->getNodeFlags() == 0 && Node->hasNoReferrers()) {
+    if (Node.getNodeFlags() == 0 && Node.hasNoReferrers()) {
       // This node is dead!
-      delete Node;                        // Free node memory.
-      NI = Nodes.erase(NI);               // Remove from node list.
+      NI = Nodes.erase(NI);    // Erase & remove from node list.
     } else {
       ++NI;
     }
@@ -1766,14 +1765,13 @@ void DSGraph::removeDeadNodes(unsigned Flags) {
   std::vector<DSNode*> DeadNodes;
   DeadNodes.reserve(Nodes.size());
   for (NodeListTy::iterator NI = Nodes.begin(), E = Nodes.end(); NI != E;)
-    if (!Alive.count(*NI)) {
+    if (!Alive.count(NI)) {
       ++NumDNE;
-      DSNode *N = *NI;
-      NI = Nodes.erase(NI);          // Erase node from list.
+      DSNode *N = Nodes.remove(NI++);
       DeadNodes.push_back(N);
       N->dropAllReferences();
     } else {
-      assert((*NI)->getForwardNode() == 0 && "Alive forwarded node?");
+      assert(NI->getForwardNode() == 0 && "Alive forwarded node?");
       ++NI;
     }