mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-19 04:32:19 +00:00
Use DSNodeHandleMap instead to be safe
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4622 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5134006f93
commit
f8c6aab05e
@ -470,11 +470,12 @@ Function &DSCallSite::getCaller() const {
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
DSGraph::DSGraph(const DSGraph &G) : Func(G.Func) {
|
DSGraph::DSGraph(const DSGraph &G) : Func(G.Func) {
|
||||||
std::map<const DSNode*, DSNode*> NodeMap;
|
std::map<const DSNode*, DSNodeHandle> NodeMap;
|
||||||
RetNode = cloneInto(G, ScalarMap, NodeMap);
|
RetNode = cloneInto(G, ScalarMap, NodeMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
DSGraph::DSGraph(const DSGraph &G, std::map<const DSNode*, DSNode*> &NodeMap)
|
DSGraph::DSGraph(const DSGraph &G,
|
||||||
|
std::map<const DSNode*, DSNodeHandle> &NodeMap)
|
||||||
: Func(G.Func) {
|
: Func(G.Func) {
|
||||||
RetNode = cloneInto(G, ScalarMap, NodeMap);
|
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
|
/// remapLinks - Change all of the Links in the current node according to the
|
||||||
/// specified mapping.
|
/// specified mapping.
|
||||||
///
|
///
|
||||||
void DSNode::remapLinks(std::map<const DSNode*, DSNode*> &OldNodeMap) {
|
void DSNode::remapLinks(std::map<const DSNode*, DSNodeHandle> &OldNodeMap) {
|
||||||
for (unsigned i = 0, e = Links.size(); i != e; ++i)
|
for (unsigned i = 0, e = Links.size(); i != e; ++i) {
|
||||||
Links[i].setNode(OldNodeMap[Links[i].getNode()]);
|
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<const DSNode*, DSNode*> &OldNodeMap) {
|
|||||||
//
|
//
|
||||||
DSNodeHandle DSGraph::cloneInto(const DSGraph &G,
|
DSNodeHandle DSGraph::cloneInto(const DSGraph &G,
|
||||||
std::map<Value*, DSNodeHandle> &OldValMap,
|
std::map<Value*, DSNodeHandle> &OldValMap,
|
||||||
std::map<const DSNode*, DSNode*> &OldNodeMap,
|
std::map<const DSNode*, DSNodeHandle> &OldNodeMap,
|
||||||
AllocaBit StripAllocas) {
|
AllocaBit StripAllocas) {
|
||||||
assert(OldNodeMap.empty() && "Returned OldNodeMap should be empty!");
|
assert(OldNodeMap.empty() && "Returned OldNodeMap should be empty!");
|
||||||
assert(&G != this && "Cannot clone graph into itself!");
|
assert(&G != this && "Cannot clone graph into itself!");
|
||||||
@ -544,14 +548,14 @@ DSNodeHandle DSGraph::cloneInto(const DSGraph &G,
|
|||||||
for (std::map<Value*, DSNodeHandle>::const_iterator I = G.ScalarMap.begin(),
|
for (std::map<Value*, DSNodeHandle>::const_iterator I = G.ScalarMap.begin(),
|
||||||
E = G.ScalarMap.end(); I != E; ++I) {
|
E = G.ScalarMap.end(); I != E; ++I) {
|
||||||
DSNodeHandle &H = OldValMap[I->first];
|
DSNodeHandle &H = OldValMap[I->first];
|
||||||
H.setNode(OldNodeMap[I->second.getNode()]);
|
DSNodeHandle &MappedNode = OldNodeMap[I->second.getNode()];
|
||||||
H.setOffset(I->second.getOffset());
|
H.setNode(MappedNode.getNode());
|
||||||
|
H.setOffset(I->second.getOffset()+MappedNode.getOffset());
|
||||||
|
|
||||||
if (isa<GlobalValue>(I->first)) { // Is this a global?
|
if (isa<GlobalValue>(I->first)) { // Is this a global?
|
||||||
std::map<Value*, DSNodeHandle>::iterator GVI = ScalarMap.find(I->first);
|
std::map<Value*, DSNodeHandle>::iterator GVI = ScalarMap.find(I->first);
|
||||||
if (GVI != ScalarMap.end()) { // Is the global value in this fn already?
|
if (GVI != ScalarMap.end()) { // Is the global value in this fn already?
|
||||||
GVI->second.mergeWith(H);
|
GVI->second.mergeWith(H);
|
||||||
OldNodeMap[I->second.getNode()] = H.getNode();
|
|
||||||
} else {
|
} else {
|
||||||
ScalarMap[I->first] = H; // Add global pointer to this graph
|
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));
|
FunctionCalls.push_back(DSCallSite(G.FunctionCalls[i], OldNodeMap));
|
||||||
|
|
||||||
// Return the returned node pointer...
|
// 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
|
/// 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
|
// Clone the callee's graph into the current graph, keeping
|
||||||
// track of where scalars in the old graph _used_ to point,
|
// track of where scalars in the old graph _used_ to point,
|
||||||
// and of the new nodes matching nodes of the old graph.
|
// and of the new nodes matching nodes of the old graph.
|
||||||
std::map<const DSNode*, DSNode*> OldNodeMap;
|
std::map<const DSNode*, DSNodeHandle> OldNodeMap;
|
||||||
|
|
||||||
// The clone call may invalidate any of the vectors in the data
|
// The clone call may invalidate any of the vectors in the data
|
||||||
// structure graph. Strip locals and don't copy the list of callers
|
// structure graph. Strip locals and don't copy the list of callers
|
||||||
|
@ -124,7 +124,7 @@ bool Steens::run(Module &M) {
|
|||||||
if (!I->isExternal()) {
|
if (!I->isExternal()) {
|
||||||
std::map<Value*, DSNodeHandle> ValMap;
|
std::map<Value*, DSNodeHandle> ValMap;
|
||||||
{ // Scope to free NodeMap memory ASAP
|
{ // Scope to free NodeMap memory ASAP
|
||||||
std::map<const DSNode*, DSNode*> NodeMap;
|
std::map<const DSNode*, DSNodeHandle> NodeMap;
|
||||||
const DSGraph &FDSG = LDS.getDSGraph(*I);
|
const DSGraph &FDSG = LDS.getDSGraph(*I);
|
||||||
DSNodeHandle RetNode = ResultGraph->cloneInto(FDSG, ValMap, NodeMap);
|
DSNodeHandle RetNode = ResultGraph->cloneInto(FDSG, ValMap, NodeMap);
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ DSGraph &TDDataStructures::calculateGraph(Function &F) {
|
|||||||
DSGraph &BUGraph = BU.getDSGraph(F);
|
DSGraph &BUGraph = BU.getDSGraph(F);
|
||||||
|
|
||||||
// Copy the BU graph, keeping a mapping from the BUGraph to the current Graph
|
// Copy the BU graph, keeping a mapping from the BUGraph to the current Graph
|
||||||
std::map<const DSNode*, DSNode*> BUNodeMap;
|
std::map<const DSNode*, DSNodeHandle> BUNodeMap;
|
||||||
Graph = new DSGraph(BUGraph, BUNodeMap);
|
Graph = new DSGraph(BUGraph, BUNodeMap);
|
||||||
|
|
||||||
// We only need the BUMap entries for the nodes that are used in call sites.
|
// 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"
|
// Loop through te BUNodeMap, keeping only the nodes that are "Needed"
|
||||||
for (std::map<const DSNode*, DSNode*>::iterator I = BUNodeMap.begin();
|
for (std::map<const DSNode*, DSNodeHandle>::iterator I = BUNodeMap.begin();
|
||||||
I != BUNodeMap.end(); )
|
I != BUNodeMap.end(); )
|
||||||
if (NeededNodes.count(I->first) && I->first) // Keep needed nodes...
|
if (NeededNodes.count(I->first) && I->first) // Keep needed nodes...
|
||||||
++I;
|
++I;
|
||||||
else {
|
else {
|
||||||
std::map<const DSNode*, DSNode*>::iterator J = I++;
|
std::map<const DSNode*, DSNodeHandle>::iterator J = I++;
|
||||||
BUNodeMap.erase(J);
|
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_
|
// 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.
|
// to point to, and of new nodes matching nodes of the old graph.
|
||||||
std::map<Value*, DSNodeHandle> OldValMap;
|
std::map<Value*, DSNodeHandle> OldValMap;
|
||||||
std::map<const DSNode*, DSNode*> OldNodeMap;
|
std::map<const DSNode*, DSNodeHandle> OldNodeMap;
|
||||||
|
|
||||||
// FIXME: Eventually use DSGraph::mergeInGraph here...
|
// FIXME: Eventually use DSGraph::mergeInGraph here...
|
||||||
// Graph->mergeInGraph(CallSiteInCG, CG, false);
|
// Graph->mergeInGraph(CallSiteInCG, CG, false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user