[llvm-commits] CVS: llvm/lib/Analysis/DataStructure/DataStructure.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Mar 24 15:46:17 PST 2005



Changes in directory llvm/lib/Analysis/DataStructure:

DataStructure.cpp updated: 1.233 -> 1.234
---
Log message:

add a new DSGraph::spliceFrom method, which violently takes the content of
one graph and plops it into another, without breaking a sweat.


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

 DataStructure.cpp |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+)


Index: llvm/lib/Analysis/DataStructure/DataStructure.cpp
diff -u llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.233 llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.234
--- llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.233	Thu Mar 24 17:06:02 2005
+++ llvm/lib/Analysis/DataStructure/DataStructure.cpp	Thu Mar 24 17:46:04 2005
@@ -1304,6 +1304,47 @@
   }
 }
 
+/// spliceFrom - Logically perform the operation of cloning the RHS graph into
+/// this graph, then clearing the RHS graph.  Instead of performing this as
+/// two seperate operations, do it as a single, much faster, one.
+///
+void DSGraph::spliceFrom(DSGraph &RHS) {
+  // Change all of the nodes in RHS to think we are their parent.
+  for (NodeListTy::iterator I = RHS.Nodes.begin(), E = RHS.Nodes.end();
+       I != E; ++I)
+    I->setParentGraph(this);
+  // Take all of the nodes.
+  Nodes.splice(Nodes.end(), RHS.Nodes);
+  
+  // Take all of the calls.
+  FunctionCalls.splice(FunctionCalls.end(), RHS.FunctionCalls);
+  AuxFunctionCalls.splice(AuxFunctionCalls.end(), RHS.AuxFunctionCalls);
+
+  // Take all of the return nodes.
+  ReturnNodes.insert(RHS.ReturnNodes.begin(), RHS.ReturnNodes.end());
+  RHS.ReturnNodes.clear();
+
+  // Merge the scalar map in.
+  ScalarMap.spliceFrom(RHS.ScalarMap);
+}
+
+/// spliceFrom - Copy all entries from RHS, then clear RHS.
+///
+void DSScalarMap::spliceFrom(DSScalarMap &RHS) {
+  // Special case if this is empty.
+  if (ValueMap.empty()) {
+    ValueMap.swap(RHS.ValueMap);
+    GlobalSet.swap(RHS.GlobalSet);
+  } else {
+    GlobalSet.insert(RHS.GlobalSet.begin(), RHS.GlobalSet.end());
+    for (ValueMapTy::iterator I = RHS.ValueMap.begin(), E = RHS.ValueMap.end();
+         I != E; ++I)
+      ValueMap[I->first].mergeWith(I->second);
+    RHS.ValueMap.clear();
+  }
+}
+
+
 /// getFunctionArgumentsForCall - Given a function that is currently in this
 /// graph, return the DSNodeHandles that correspond to the pointer-compatible
 /// function arguments.  The vector is filled in with the return value (or






More information about the llvm-commits mailing list