Fix major bugs in incompleteness marking that were pessimizing results
llvm-svn: 5515
This commit is contained in:
parent
e4059b4ed6
commit
93fdaf9cb9
|
@ -106,115 +106,120 @@ void TDDataStructures::calculateGraph(Function &F) {
|
||||||
const std::vector<DSCallSite> &CallSites = Graph.getFunctionCalls();
|
const std::vector<DSCallSite> &CallSites = Graph.getFunctionCalls();
|
||||||
if (CallSites.empty()) {
|
if (CallSites.empty()) {
|
||||||
DEBUG(std::cerr << " [TD] No callees for: " << F.getName() << "\n");
|
DEBUG(std::cerr << " [TD] No callees for: " << F.getName() << "\n");
|
||||||
return; // If no call sites, there is nothing more to do here
|
} else {
|
||||||
}
|
// Loop over all of the call sites, building a multi-map from Callees to
|
||||||
|
// DSCallSite*'s. With this map we can then loop over each callee, cloning
|
||||||
|
// this graph once into it, then resolving arguments.
|
||||||
|
//
|
||||||
|
std::multimap<Function*, const DSCallSite*> CalleeSites;
|
||||||
|
for (unsigned i = 0, e = CallSites.size(); i != e; ++i) {
|
||||||
|
const DSCallSite &CS = CallSites[i];
|
||||||
|
if (CS.isDirectCall()) {
|
||||||
|
if (!CS.getCalleeFunc()->isExternal()) // If it's not external
|
||||||
|
CalleeSites.insert(std::make_pair(CS.getCalleeFunc(), &CS));// Keep it
|
||||||
|
} else {
|
||||||
|
const std::vector<GlobalValue*> &Callees =
|
||||||
|
CS.getCalleeNode()->getGlobals();
|
||||||
|
|
||||||
// Loop over all of the call sites, building a multi-map from Callees to
|
// Loop over all of the functions that this call may invoke...
|
||||||
// DSCallSite*'s. With this map we can then loop over each callee, cloning
|
for (unsigned c = 0, e = Callees.size(); c != e; ++c)
|
||||||
// this graph once into it, then resolving arguments.
|
if (Function *F = dyn_cast<Function>(Callees[c]))// If this is a fn...
|
||||||
//
|
if (!F->isExternal()) // If it's not extern
|
||||||
std::multimap<Function*, const DSCallSite*> CalleeSites;
|
CalleeSites.insert(std::make_pair(F, &CS)); // Keep track of it!
|
||||||
for (unsigned i = 0, e = CallSites.size(); i != e; ++i) {
|
}
|
||||||
const DSCallSite &CS = CallSites[i];
|
|
||||||
if (CS.isDirectCall()) {
|
|
||||||
if (!CS.getCalleeFunc()->isExternal()) // If it's not external
|
|
||||||
CalleeSites.insert(std::make_pair(CS.getCalleeFunc(), &CS)); // Keep it
|
|
||||||
} else {
|
|
||||||
const std::vector<GlobalValue*> &Callees =
|
|
||||||
CS.getCalleeNode()->getGlobals();
|
|
||||||
|
|
||||||
// Loop over all of the functions that this call may invoke...
|
|
||||||
for (unsigned c = 0, e = Callees.size(); c != e; ++c)
|
|
||||||
if (Function *F = dyn_cast<Function>(Callees[c])) // If this is a fn...
|
|
||||||
if (!F->isExternal()) // If it's not extern
|
|
||||||
CalleeSites.insert(std::make_pair(F, &CS)); // Keep track of it!
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Now that we have information about all of the callees, propagate the
|
// Now that we have information about all of the callees, propagate the
|
||||||
// current graph into the callees.
|
// current graph into the callees.
|
||||||
//
|
//
|
||||||
DEBUG(std::cerr << " [TD] Inlining '" << F.getName() << "' into "
|
DEBUG(std::cerr << " [TD] Inlining '" << F.getName() << "' into "
|
||||||
<< CalleeSites.size() << " callees.\n");
|
<< CalleeSites.size() << " callees.\n");
|
||||||
|
|
||||||
// Loop over all the callees...
|
// Loop over all the callees...
|
||||||
for (std::multimap<Function*, const DSCallSite*>::iterator
|
for (std::multimap<Function*, const DSCallSite*>::iterator
|
||||||
I = CalleeSites.begin(), E = CalleeSites.end(); I != E; )
|
I = CalleeSites.begin(), E = CalleeSites.end(); I != E; )
|
||||||
if (I->first == &F) { // Bottom-up pass takes care of self loops!
|
if (I->first == &F) { // Bottom-up pass takes care of self loops!
|
||||||
++I;
|
++I;
|
||||||
} else {
|
} else {
|
||||||
// For each callee...
|
// For each callee...
|
||||||
Function *Callee = I->first;
|
Function *Callee = I->first;
|
||||||
DSGraph &CG = getOrCreateDSGraph(*Callee); // Get the callee's graph...
|
DSGraph &CG = getOrCreateDSGraph(*Callee); // Get the callee's graph...
|
||||||
|
|
||||||
DEBUG(std::cerr << "\t [TD] Inlining into callee '" << Callee->getName()
|
DEBUG(std::cerr << "\t [TD] Inlining into callee '" << Callee->getName()
|
||||||
<< "'\n");
|
<< "'\n");
|
||||||
|
|
||||||
// Clone our current graph into the callee...
|
// Clone our current graph into the callee...
|
||||||
hash_map<Value*, DSNodeHandle> OldValMap;
|
hash_map<Value*, DSNodeHandle> OldValMap;
|
||||||
hash_map<const DSNode*, DSNodeHandle> OldNodeMap;
|
hash_map<const DSNode*, DSNodeHandle> OldNodeMap;
|
||||||
CG.cloneInto(Graph, OldValMap, OldNodeMap,
|
CG.cloneInto(Graph, OldValMap, OldNodeMap,
|
||||||
DSGraph::StripModRefBits |
|
DSGraph::StripModRefBits |
|
||||||
DSGraph::KeepAllocaBit | DSGraph::DontCloneCallNodes);
|
DSGraph::KeepAllocaBit | DSGraph::DontCloneCallNodes);
|
||||||
OldValMap.clear(); // We don't care about the ValMap
|
OldValMap.clear(); // We don't care about the ValMap
|
||||||
|
|
||||||
// Loop over all of the invocation sites of the callee, resolving
|
// Loop over all of the invocation sites of the callee, resolving
|
||||||
// arguments to our graph. This loop may iterate multiple times if the
|
// arguments to our graph. This loop may iterate multiple times if the
|
||||||
// current function calls this callee multiple times with different
|
// current function calls this callee multiple times with different
|
||||||
// signatures.
|
// signatures.
|
||||||
//
|
//
|
||||||
for (; I != E && I->first == Callee; ++I) {
|
for (; I != E && I->first == Callee; ++I) {
|
||||||
// Map call site into callee graph
|
// Map call site into callee graph
|
||||||
DSCallSite NewCS(*I->second, OldNodeMap);
|
DSCallSite NewCS(*I->second, OldNodeMap);
|
||||||
|
|
||||||
// Resolve the return values...
|
// Resolve the return values...
|
||||||
NewCS.getRetVal().mergeWith(CG.getRetNode());
|
NewCS.getRetVal().mergeWith(CG.getRetNode());
|
||||||
|
|
||||||
// Resolve all of the arguments...
|
// Resolve all of the arguments...
|
||||||
Function::aiterator AI = Callee->abegin();
|
Function::aiterator AI = Callee->abegin();
|
||||||
for (unsigned i = 0, e = NewCS.getNumPtrArgs();
|
for (unsigned i = 0, e = NewCS.getNumPtrArgs();
|
||||||
i != e && AI != Callee->aend(); ++i, ++AI) {
|
i != e && AI != Callee->aend(); ++i, ++AI) {
|
||||||
// Advance the argument iterator to the first pointer argument...
|
// Advance the argument iterator to the first pointer argument...
|
||||||
while (!DS::isPointerType(AI->getType())) {
|
while (!DS::isPointerType(AI->getType())) {
|
||||||
++AI;
|
++AI;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (AI == Callee->aend())
|
if (AI == Callee->aend())
|
||||||
std::cerr << "Bad call to Function: " << Callee->getName()<< "\n";
|
std::cerr << "Bad call to Func: " << Callee->getName() << "\n";
|
||||||
#endif
|
#endif
|
||||||
assert(AI != Callee->aend() &&
|
assert(AI != Callee->aend() &&
|
||||||
"# Args provided is not # Args required!");
|
"# Args provided is not # Args required!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the link from the argument scalar to the provided value
|
// Add the link from the argument scalar to the provided value
|
||||||
DSNodeHandle &NH = CG.getNodeForValue(AI);
|
DSNodeHandle &NH = CG.getNodeForValue(AI);
|
||||||
assert(NH.getNode() && "Pointer argument without scalarmap entry?");
|
assert(NH.getNode() && "Pointer argument without scalarmap entry?");
|
||||||
NH.mergeWith(NewCS.getPtrArg(i));
|
NH.mergeWith(NewCS.getPtrArg(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Done with the nodemap...
|
||||||
|
OldNodeMap.clear();
|
||||||
|
|
||||||
|
// Recompute the Incomplete markers and eliminate unreachable nodes.
|
||||||
|
CG.maskIncompleteMarkers();
|
||||||
|
CG.markIncompleteNodes(DSGraph::MarkFormalArgs);
|
||||||
|
CG.removeDeadNodes(DSGraph::RemoveUnreachableGlobals);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done with the nodemap...
|
DEBUG(std::cerr << " [TD] Done inlining into callees for: " << F.getName()
|
||||||
OldNodeMap.clear();
|
<< " [" << Graph.getGraphSize() << "+"
|
||||||
|
<< Graph.getFunctionCalls().size() << "]\n");
|
||||||
|
|
||||||
// Recompute the Incomplete markers and eliminate unreachable nodes.
|
// Loop over all the callees... making sure they are all resolved now...
|
||||||
CG.maskIncompleteMarkers();
|
Function *LastFunc = 0;
|
||||||
CG.markIncompleteNodes(Callee->hasInternalLinkage() ?
|
for (std::multimap<Function*, const DSCallSite*>::iterator
|
||||||
DSGraph::IgnoreFormalArgs : DSGraph::MarkFormalArgs
|
I = CalleeSites.begin(), E = CalleeSites.end(); I != E; ++I)
|
||||||
/*&& FIXME: NEED TO CHECK IF ALL CALLERS FOUND!*/);
|
if (I->first != LastFunc) { // Only visit each callee once...
|
||||||
CG.removeDeadNodes(DSGraph::RemoveUnreachableGlobals);
|
LastFunc = I->first;
|
||||||
}
|
calculateGraph(*I->first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG(std::cerr << " [TD] Done inlining into callees for: " << F.getName()
|
// Recompute the Incomplete markers and eliminate unreachable nodes.
|
||||||
<< " [" << Graph.getGraphSize() << "+"
|
Graph.maskIncompleteMarkers();
|
||||||
<< Graph.getFunctionCalls().size() << "]\n");
|
// FIXME: Need to check if all callers have been found, or rather if a
|
||||||
|
// funcpointer escapes!
|
||||||
|
unsigned Flags = F.hasInternalLinkage() ?
|
||||||
// Loop over all the callees... making sure they are all resolved now...
|
DSGraph::IgnoreFormalArgs : DSGraph::MarkFormalArgs;
|
||||||
Function *LastFunc = 0;
|
Graph.markIncompleteNodes(Flags | DSGraph::IgnoreGlobals);
|
||||||
for (std::multimap<Function*, const DSCallSite*>::iterator
|
Graph.removeDeadNodes(DSGraph::RemoveUnreachableGlobals);
|
||||||
I = CalleeSites.begin(), E = CalleeSites.end(); I != E; ++I)
|
|
||||||
if (I->first != LastFunc) { // Only visit each callee once...
|
|
||||||
LastFunc = I->first;
|
|
||||||
calculateGraph(*I->first);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue