mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-07 14:33:15 +00:00
Implement a new mergeInGraph method, which basically factors code out of
the BU class. This will be used by the IPModRef class to do stuff, eventually perhaps the TD pass will use it also. Speaking of the TD pass, this also eliminates the self recursive case, which was broken, and couldn't occur anyway. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4599 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cee3a4ef10
commit
076c1f923b
@ -46,29 +46,6 @@ bool BUDataStructures::run(Module &M) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveArguments - Resolve the formal and actual arguments for a function
|
|
||||||
// call.
|
|
||||||
//
|
|
||||||
static void ResolveArguments(DSCallSite &Call, Function &F,
|
|
||||||
map<Value*, DSNodeHandle> &ScalarMap) {
|
|
||||||
// Resolve all of the function arguments...
|
|
||||||
Function::aiterator AI = F.abegin();
|
|
||||||
for (unsigned i = 0, e = Call.getNumPtrArgs(); i != e; ++i, ++AI) {
|
|
||||||
// Advance the argument iterator to the first pointer argument...
|
|
||||||
while (!isPointerType(AI->getType())) {
|
|
||||||
++AI;
|
|
||||||
#ifndef NDEBUG
|
|
||||||
if (AI == F.aend())
|
|
||||||
std::cerr << "Bad call to Function: " << F.getName() << "\n";
|
|
||||||
#endif
|
|
||||||
assert(AI != F.aend() && "# Args provided is not # Args required!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the link from the argument scalar to the provided value
|
|
||||||
ScalarMap[AI].mergeWith(Call.getPtrArg(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DSGraph &BUDataStructures::calculateGraph(Function &F) {
|
DSGraph &BUDataStructures::calculateGraph(Function &F) {
|
||||||
// Make sure this graph has not already been calculated, or that we don't get
|
// Make sure this graph has not already been calculated, or that we don't get
|
||||||
// into an infinite loop with mutually recursive functions.
|
// into an infinite loop with mutually recursive functions.
|
||||||
@ -115,11 +92,8 @@ DSGraph &BUDataStructures::calculateGraph(Function &F) {
|
|||||||
// actual arguments...
|
// actual arguments...
|
||||||
DEBUG(std::cerr << "\t[BU] Self Inlining: " << F.getName() << "\n");
|
DEBUG(std::cerr << "\t[BU] Self Inlining: " << F.getName() << "\n");
|
||||||
|
|
||||||
// Handle the return value if present...
|
// Handle self recursion by resolving the arguments and return value
|
||||||
Graph->getRetNode().mergeWith(Call.getRetVal());
|
Graph->mergeInGraph(Call, *Graph, true);
|
||||||
|
|
||||||
// Resolve the arguments in the call to the actual values...
|
|
||||||
ResolveArguments(Call, F, Graph->getScalarMap());
|
|
||||||
|
|
||||||
// Erase the entry in the callees vector
|
// Erase the entry in the callees vector
|
||||||
Callees.erase(Callees.begin()+c--);
|
Callees.erase(Callees.begin()+c--);
|
||||||
@ -145,22 +119,8 @@ DSGraph &BUDataStructures::calculateGraph(Function &F) {
|
|||||||
CallSitesForFunc.back().setResolvingCaller(&F);
|
CallSitesForFunc.back().setResolvingCaller(&F);
|
||||||
CallSitesForFunc.back().setCallee(0);
|
CallSitesForFunc.back().setCallee(0);
|
||||||
|
|
||||||
// Clone the callee's graph into the current graph, keeping
|
// Handle self recursion by resolving the arguments and return value
|
||||||
// track of where scalars in the old graph _used_ to point,
|
Graph->mergeInGraph(Call, GI, true);
|
||||||
// and of the new nodes matching nodes of the old graph.
|
|
||||||
map<Value*, DSNodeHandle> OldValMap;
|
|
||||||
map<const DSNode*, DSNode*> 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
|
|
||||||
DSNodeHandle RetVal = Graph->cloneInto(GI, OldValMap, OldNodeMap,
|
|
||||||
/*StripAllocas*/ true);
|
|
||||||
|
|
||||||
// Resolve the arguments in the call to the actual values...
|
|
||||||
ResolveArguments(Call, FI, OldValMap);
|
|
||||||
|
|
||||||
// Handle the return value if present...
|
|
||||||
RetVal.mergeWith(Call.getRetVal());
|
|
||||||
|
|
||||||
// Erase the entry in the Callees vector
|
// Erase the entry in the Callees vector
|
||||||
Callees.erase(Callees.begin()+c--);
|
Callees.erase(Callees.begin()+c--);
|
||||||
|
@ -90,6 +90,7 @@ void DSNode::foldNodeCompletely() {
|
|||||||
Links[0].mergeWith(Links[i]);
|
Links[0].mergeWith(Links[i]);
|
||||||
Links.resize(1);
|
Links.resize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// isNodeCompletelyFolded - Return true if this node has been completely
|
/// isNodeCompletelyFolded - Return true if this node has been completely
|
||||||
/// folded down to something that can never be expanded, effectively losing
|
/// folded down to something that can never be expanded, effectively losing
|
||||||
/// all of the field sensitivity that may be present in the node.
|
/// all of the field sensitivity that may be present in the node.
|
||||||
@ -573,6 +574,57 @@ DSNodeHandle DSGraph::cloneInto(const DSGraph &G,
|
|||||||
return DSNodeHandle(OldNodeMap[G.RetNode.getNode()], G.RetNode.getOffset());
|
return DSNodeHandle(OldNodeMap[G.RetNode.getNode()], G.RetNode.getOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// mergeInGraph - The method is used for merging graphs together. If the
|
||||||
|
/// argument graph is not *this, it makes a clone of the specified graph, then
|
||||||
|
/// merges the nodes specified in the call site with the formal arguments in the
|
||||||
|
/// graph.
|
||||||
|
///
|
||||||
|
void DSGraph::mergeInGraph(DSCallSite &CS, const DSGraph &Graph,
|
||||||
|
bool StripAllocas) {
|
||||||
|
std::map<Value*, DSNodeHandle> OldValMap;
|
||||||
|
DSNodeHandle RetVal;
|
||||||
|
std::map<Value*, DSNodeHandle> *ScalarMap = &OldValMap;
|
||||||
|
|
||||||
|
// If this is not a recursive call, clone the graph into this graph...
|
||||||
|
if (&Graph != this) {
|
||||||
|
// 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<const DSNode*, DSNode*> 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
|
||||||
|
RetVal = cloneInto(Graph, OldValMap, OldNodeMap, StripAllocas);
|
||||||
|
ScalarMap = &OldValMap;
|
||||||
|
} else {
|
||||||
|
RetVal = getRetNode();
|
||||||
|
ScalarMap = &getScalarMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge the return value with the return value of the context...
|
||||||
|
RetVal.mergeWith(CS.getRetVal());
|
||||||
|
|
||||||
|
// Resolve all of the function arguments...
|
||||||
|
Function &F = Graph.getFunction();
|
||||||
|
Function::aiterator AI = F.abegin();
|
||||||
|
for (unsigned i = 0, e = CS.getNumPtrArgs(); i != e; ++i, ++AI) {
|
||||||
|
// Advance the argument iterator to the first pointer argument...
|
||||||
|
while (!isPointerType(AI->getType())) {
|
||||||
|
++AI;
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if (AI == F.aend())
|
||||||
|
std::cerr << "Bad call to Function: " << F.getName() << "\n";
|
||||||
|
#endif
|
||||||
|
assert(AI != F.aend() && "# Args provided is not # Args required!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the link from the argument scalar to the provided value
|
||||||
|
DSNodeHandle &NH = (*ScalarMap)[AI];
|
||||||
|
assert(NH.getNode() && "Pointer argument without scalarmap entry?");
|
||||||
|
NH.mergeWith(CS.getPtrArg(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// cloneGlobalInto - Clone the given global node and all its target links
|
// cloneGlobalInto - Clone the given global node and all its target links
|
||||||
// (and all their llinks, recursively).
|
// (and all their llinks, recursively).
|
||||||
|
@ -149,10 +149,8 @@ DSGraph &TDDataStructures::calculateGraph(Function &F) {
|
|||||||
DEBUG(std::cerr << "\t [TD] Inlining caller #" << c << " '"
|
DEBUG(std::cerr << "\t [TD] Inlining caller #" << c << " '"
|
||||||
<< Caller.getName() << "' into callee: " << F.getName() << "\n");
|
<< Caller.getName() << "' into callee: " << F.getName() << "\n");
|
||||||
|
|
||||||
if (&Caller == &F) {
|
// Self recursion is not tracked in BU pass...
|
||||||
// Self-recursive call: this can happen after a cycle of calls is inlined.
|
assert(&Caller != &F && "This cannot happen!\n");
|
||||||
ResolveCallSite(*Graph, CallSite);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Recursively compute the graph for the Caller. It should be fully
|
// Recursively compute the graph for the Caller. It should be fully
|
||||||
// resolved except if there is mutual recursion...
|
// resolved except if there is mutual recursion...
|
||||||
@ -162,13 +160,16 @@ DSGraph &TDDataStructures::calculateGraph(Function &F) {
|
|||||||
DEBUG(std::cerr << "\t\t[TD] Got graph for " << Caller.getName()
|
DEBUG(std::cerr << "\t\t[TD] Got graph for " << Caller.getName()
|
||||||
<< " in: " << F.getName() << "\n");
|
<< " in: " << F.getName() << "\n");
|
||||||
|
|
||||||
|
// Translate call site from having links into the BU graph
|
||||||
|
DSCallSite CallSiteInCG(CallSite, BUMaps[&Caller]);
|
||||||
|
|
||||||
// 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*, DSNode*> OldNodeMap;
|
||||||
|
|
||||||
// Translate call site from having links into the BU graph
|
// FIXME: Eventually use DSGraph::mergeInGraph here...
|
||||||
DSCallSite CallSiteInCG(CallSite, BUMaps[&Caller]);
|
// Graph->mergeInGraph(CallSiteInCG, CG, false);
|
||||||
|
|
||||||
// Clone the Caller's graph into the current graph, keeping
|
// Clone the Caller'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...
|
||||||
@ -179,7 +180,6 @@ DSGraph &TDDataStructures::calculateGraph(Function &F) {
|
|||||||
/*StripAllocas*/ false);
|
/*StripAllocas*/ false);
|
||||||
ResolveCallSite(*Graph, DSCallSite(CallSiteInCG, OldNodeMap));
|
ResolveCallSite(*Graph, DSCallSite(CallSiteInCG, OldNodeMap));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Recompute the Incomplete markers and eliminate unreachable nodes.
|
// Recompute the Incomplete markers and eliminate unreachable nodes.
|
||||||
Graph->maskIncompleteMarkers();
|
Graph->maskIncompleteMarkers();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user