aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/DataStructure/DataStructure.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-03-24 23:46:04 +0000
committerChris Lattner <sabre@nondot.org>2005-03-24 23:46:04 +0000
commit5734e4331e69931724d1a63d2e1484f5acbebf82 (patch)
tree238f0c09461d91d292c2a17c047c90df685e1a49 /lib/Analysis/DataStructure/DataStructure.cpp
parent487cd15fdb78c4972eb41879cda29fc62e62744d (diff)
add a new DSGraph::spliceFrom method, which violently takes the content of
one graph and plops it into another, without breaking a sweat. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20824 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/DataStructure/DataStructure.cpp')
-rw-r--r--lib/Analysis/DataStructure/DataStructure.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/Analysis/DataStructure/DataStructure.cpp b/lib/Analysis/DataStructure/DataStructure.cpp
index e0833c1962..1133743b5d 100644
--- a/lib/Analysis/DataStructure/DataStructure.cpp
+++ b/lib/Analysis/DataStructure/DataStructure.cpp
@@ -1304,6 +1304,47 @@ void DSGraph::cloneInto(const DSGraph &G, unsigned CloneFlags) {
}
}
+/// 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