From f8c6aab05e2625611ac98b0b56c9c7376192afc0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 8 Nov 2002 05:01:14 +0000 Subject: [PATCH] Use DSNodeHandleMap instead to be safe git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4622 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/DataStructure/DataStructure.cpp | 28 +++++++++++-------- lib/Analysis/DataStructure/Steensgaard.cpp | 2 +- lib/Analysis/DataStructure/TopDownClosure.cpp | 8 +++--- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/Analysis/DataStructure/DataStructure.cpp b/lib/Analysis/DataStructure/DataStructure.cpp index 8d798e3dc28..fa1dce41256 100644 --- a/lib/Analysis/DataStructure/DataStructure.cpp +++ b/lib/Analysis/DataStructure/DataStructure.cpp @@ -470,11 +470,12 @@ Function &DSCallSite::getCaller() const { //===----------------------------------------------------------------------===// DSGraph::DSGraph(const DSGraph &G) : Func(G.Func) { - std::map NodeMap; + std::map NodeMap; RetNode = cloneInto(G, ScalarMap, NodeMap); } -DSGraph::DSGraph(const DSGraph &G, std::map &NodeMap) +DSGraph::DSGraph(const DSGraph &G, + std::map &NodeMap) : Func(G.Func) { RetNode = cloneInto(G, ScalarMap, NodeMap); } @@ -501,9 +502,12 @@ void DSGraph::dump() const { print(std::cerr); } /// remapLinks - Change all of the Links in the current node according to the /// specified mapping. /// -void DSNode::remapLinks(std::map &OldNodeMap) { - for (unsigned i = 0, e = Links.size(); i != e; ++i) - Links[i].setNode(OldNodeMap[Links[i].getNode()]); +void DSNode::remapLinks(std::map &OldNodeMap) { + for (unsigned i = 0, e = Links.size(); i != e; ++i) { + DSNodeHandle &H = OldNodeMap[Links[i].getNode()]; + Links[i].setNode(H.getNode()); + Links[i].setOffset(Links[i].getOffset()+H.getOffset()); + } } @@ -515,7 +519,7 @@ void DSNode::remapLinks(std::map &OldNodeMap) { // DSNodeHandle DSGraph::cloneInto(const DSGraph &G, std::map &OldValMap, - std::map &OldNodeMap, + std::map &OldNodeMap, AllocaBit StripAllocas) { assert(OldNodeMap.empty() && "Returned OldNodeMap should be empty!"); assert(&G != this && "Cannot clone graph into itself!"); @@ -544,14 +548,14 @@ DSNodeHandle DSGraph::cloneInto(const DSGraph &G, for (std::map::const_iterator I = G.ScalarMap.begin(), E = G.ScalarMap.end(); I != E; ++I) { DSNodeHandle &H = OldValMap[I->first]; - H.setNode(OldNodeMap[I->second.getNode()]); - H.setOffset(I->second.getOffset()); + DSNodeHandle &MappedNode = OldNodeMap[I->second.getNode()]; + H.setNode(MappedNode.getNode()); + H.setOffset(I->second.getOffset()+MappedNode.getOffset()); if (isa(I->first)) { // Is this a global? std::map::iterator GVI = ScalarMap.find(I->first); if (GVI != ScalarMap.end()) { // Is the global value in this fn already? GVI->second.mergeWith(H); - OldNodeMap[I->second.getNode()] = H.getNode(); } else { ScalarMap[I->first] = H; // Add global pointer to this graph } @@ -565,7 +569,9 @@ DSNodeHandle DSGraph::cloneInto(const DSGraph &G, FunctionCalls.push_back(DSCallSite(G.FunctionCalls[i], OldNodeMap)); // Return the returned node pointer... - return DSNodeHandle(OldNodeMap[G.RetNode.getNode()], G.RetNode.getOffset()); + DSNodeHandle &MappedRet = OldNodeMap[G.RetNode.getNode()]; + return DSNodeHandle(MappedRet.getNode(), + MappedRet.getOffset()+G.RetNode.getOffset()); } /// mergeInGraph - The method is used for merging graphs together. If the @@ -584,7 +590,7 @@ void DSGraph::mergeInGraph(DSCallSite &CS, const DSGraph &Graph, // Clone the callee's graph into the current graph, keeping // track of where scalars in the old graph _used_ to point, // and of the new nodes matching nodes of the old graph. - std::map OldNodeMap; + std::map OldNodeMap; // The clone call may invalidate any of the vectors in the data // structure graph. Strip locals and don't copy the list of callers diff --git a/lib/Analysis/DataStructure/Steensgaard.cpp b/lib/Analysis/DataStructure/Steensgaard.cpp index 88d845559f9..028bf919e2f 100644 --- a/lib/Analysis/DataStructure/Steensgaard.cpp +++ b/lib/Analysis/DataStructure/Steensgaard.cpp @@ -124,7 +124,7 @@ bool Steens::run(Module &M) { if (!I->isExternal()) { std::map ValMap; { // Scope to free NodeMap memory ASAP - std::map NodeMap; + std::map NodeMap; const DSGraph &FDSG = LDS.getDSGraph(*I); DSNodeHandle RetNode = ResultGraph->cloneInto(FDSG, ValMap, NodeMap); diff --git a/lib/Analysis/DataStructure/TopDownClosure.cpp b/lib/Analysis/DataStructure/TopDownClosure.cpp index bc27b92ccd9..98fec671b56 100644 --- a/lib/Analysis/DataStructure/TopDownClosure.cpp +++ b/lib/Analysis/DataStructure/TopDownClosure.cpp @@ -93,7 +93,7 @@ DSGraph &TDDataStructures::calculateGraph(Function &F) { DSGraph &BUGraph = BU.getDSGraph(F); // Copy the BU graph, keeping a mapping from the BUGraph to the current Graph - std::map BUNodeMap; + std::map BUNodeMap; Graph = new DSGraph(BUGraph, BUNodeMap); // We only need the BUMap entries for the nodes that are used in call sites. @@ -113,12 +113,12 @@ DSGraph &TDDataStructures::calculateGraph(Function &F) { } // Loop through te BUNodeMap, keeping only the nodes that are "Needed" - for (std::map::iterator I = BUNodeMap.begin(); + for (std::map::iterator I = BUNodeMap.begin(); I != BUNodeMap.end(); ) if (NeededNodes.count(I->first) && I->first) // Keep needed nodes... ++I; else { - std::map::iterator J = I++; + std::map::iterator J = I++; BUNodeMap.erase(J); } @@ -167,7 +167,7 @@ DSGraph &TDDataStructures::calculateGraph(Function &F) { // These two maps keep track of where scalars in the old graph _used_ // to point to, and of new nodes matching nodes of the old graph. std::map OldValMap; - std::map OldNodeMap; + std::map OldNodeMap; // FIXME: Eventually use DSGraph::mergeInGraph here... // Graph->mergeInGraph(CallSiteInCG, CG, false); -- 2.34.1