[llvm-commits] [poolalloc] r105831 - in /poolalloc/trunk/lib/DSA: BottomUpClosure.cpp DSGraph.cpp
John Criswell
criswell at uiuc.edu
Fri Jun 11 13:21:36 PDT 2010
Author: criswell
Date: Fri Jun 11 15:21:36 2010
New Revision: 105831
URL: http://llvm.org/viewvc/llvm-project?rev=105831&view=rev
Log:
Added comments.
Improved formatting.
No functionality changes.
Modified:
poolalloc/trunk/lib/DSA/BottomUpClosure.cpp
poolalloc/trunk/lib/DSA/DSGraph.cpp
Modified: poolalloc/trunk/lib/DSA/BottomUpClosure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/BottomUpClosure.cpp?rev=105831&r1=105830&r2=105831&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/BottomUpClosure.cpp (original)
+++ poolalloc/trunk/lib/DSA/BottomUpClosure.cpp Fri Jun 11 15:21:36 2010
@@ -72,14 +72,26 @@
//
mergeSCCs();
- //Post order traversal:
+ //
+ // Do a post-order traversal of the SCC callgraph and do bottom-up inlining.
+ //
{
//errs() << *DSG.knownRoots.begin() << " -> " << *DSG.knownRoots.rbegin() << "\n";
svset<const Function*> marked;
for (DSCallGraph::root_iterator ii = callgraph.root_begin(),
ee = callgraph.root_end(); ii != ee; ++ii) {
//errs() << (*ii)->getName() << "\n";
+
+ //
+ // Do bottom-up inlining of the function.
+ //
DSGraph* G = postOrder(*ii, marked);
+
+ //
+ // Update the list of unresolved indirect function call sites in the
+ // globals graph with the new information learned about the current
+ // function.
+ //
CloneAuxIntoGlobal(G);
}
}
@@ -132,16 +144,19 @@
// Method: mergeSCCs()
//
// Description:
-// For every Strongly Connected Component (SCC) in the callgraph, this method
-// iterates through every function in the SCC and merges its DSGraph into a
-// single DSGraph for the SCC.
+// Create a single DSGraph for every Strongly Connected Component (SCC) in the
+// callgraph. This is done by merging the DSGraphs of every function within
+// each SCC.
//
void BUDataStructures::mergeSCCs() {
for (DSCallGraph::flat_key_iterator ii = callgraph.flat_key_begin(),
ee = callgraph.flat_key_end(); ii != ee; ++ii) {
- // Externals can be singleton SCCs
+ //
+ // External functions form their own singleton SCC.
+ //
if ((*ii)->isDeclaration()) continue;
+
DSGraph* SCCGraph = getOrCreateGraph(*ii);
unsigned SCCSize = 1;
callgraph.assertSCCRoot(*ii);
@@ -177,18 +192,22 @@
// Inputs:
// F - The function on which to do whatever.
// marked - A reference to a set containing all values processed by
-// previous invocation (this method is recursive).
+// previous invocations (this method is recursive).
//
// Outputs:
// marked - Updated to contain function F.
//
DSGraph* BUDataStructures::postOrder(const Function* F,
svset<const Function*>& marked) {
+ //
+ // If we have already processed this function before, do not process it
+ // again.
+ //
callgraph.assertSCCRoot(F);
DSGraph* G = getDSGraph(*F);
if (marked.count(F)) return G;
- for(DSCallGraph::flat_iterator ii = callgraph.flat_callee_begin(F),
+ for (DSCallGraph::flat_iterator ii = callgraph.flat_callee_begin(F),
ee = callgraph.flat_callee_end(F); ii != ee; ++ii) {
callgraph.assertSCCRoot(*ii);
assert (*ii != F && "Simple loop in callgraph");
@@ -196,9 +215,20 @@
postOrder(*ii, marked);
}
+ //
+ // Record that we are about to process the given function.
+ //
marked.insert(F);
+
+ //
+ // Inline the graphs of callees into this function's callgraph.
+ //
calculateGraph(G);
- //once calculated, we can update the callgraph
+
+ //
+ // Now that we have new information merged into the function's DSGraph,
+ // update the call graph using this new information.
+ //
G->buildCallGraph(callgraph);
return G;
}
Modified: poolalloc/trunk/lib/DSA/DSGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/DSGraph.cpp?rev=105831&r1=105830&r2=105831&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/DSGraph.cpp (original)
+++ poolalloc/trunk/lib/DSA/DSGraph.cpp Fri Jun 11 15:21:36 2010
@@ -1226,8 +1226,15 @@
}
}
-// Filter potential call targets
-static bool functionIsCallable(CallSite CS, const Function* F) {
+//
+// Function: functionIsCallable()
+//
+// Description:
+// Determine whether the specified function can be a target of the specified
+// call site. We allow the user to configure what we consider to be
+// uncallable at an indirect function call site.
+//
+static bool functionIsCallable (CallSite CS, const Function* F) {
//Which targets do we choose?
//Conservative: all of them
//Pretty Safe: same calling convention, otherwise undefined behavior
@@ -1258,18 +1265,46 @@
return true;
}
+//
+// Method: buildCallGraph()
+//
+// Description:
+// This method updates the given call graph with new information about targets
+// of function calls that can be inferred from the unresolved call sites
+// within the DSGraph.
+//
void DSGraph::buildCallGraph(DSCallGraph& DCG) const {
+ //
+ // Get the list of unresolved call sites.
+ //
const std::list<DSCallSite>& Calls = getAuxFunctionCalls();
- for (std::list<DSCallSite>::const_iterator ii = Calls.begin(), ee = Calls.end();
- ii != ee; ++ii)
+ for (std::list<DSCallSite>::const_iterator ii = Calls.begin(),
+ ee = Calls.end();
+ ii != ee; ++ii) {
+ //
+ // Direct calls are easy. We know to where they go.
+ //
if (ii->isDirectCall()) {
DCG.insert(ii->getCallSite(), ii->getCalleeFunc());
} else {
CallSite CS = ii->getCallSite();
std::vector<const Function*> MaybeTargets;
+
+ //
+ // Get the list of known targets of this function.
+ //
ii->getCalleeNode()->addFullFunctionList(MaybeTargets);
- //Assure have a record for this callsite
+
+ //
+ // Ensure that the call graph at least knows about (has a record of) this
+ // call site.
+ //
DCG.insert(CS, 0);
+
+ //
+ // Add to the call graph only function targets that have well-defined
+ // behavior using LLVM semantics.
+ //
for (std::vector<const Function*>::iterator Fi = MaybeTargets.begin(),
Fe = MaybeTargets.end(); Fi != Fe; ++Fi)
if (functionIsCallable(CS, *Fi))
@@ -1277,4 +1312,5 @@
else
++NumFiltered;
}
+ }
}
More information about the llvm-commits
mailing list