Rename members and interfaces of the call graph for clarity.

Small clean-up to try to improve on the clarity of the call graph code.

I think this is an overall improvement although there is still some
clunky naming that could be improved in the future.

Swift SVN r25492
This commit is contained in:
Mark Lacey
2015-02-24 00:08:19 +00:00
parent 5bcd4319b8
commit 64af0798df
3 changed files with 54 additions and 53 deletions

View File

@@ -54,7 +54,7 @@ public:
private:
// The call site represented by this call graph edge.
ApplyInst *CallSite;
ApplyInst *TheApply;
// The set of functions potentially called from this call site. This
// might include functions that are not actually callable based on
@@ -65,8 +65,8 @@ private:
public:
/// Create a call graph edge for a call site where we will fill in
/// the set of potentially called functions later.
CallGraphEdge(ApplyInst *CallSite, CalleeSetType &KnownCallees, bool Complete)
: CallSite(CallSite),
CallGraphEdge(ApplyInst *TheApply, CalleeSetType &KnownCallees, bool Complete)
: TheApply(TheApply),
// FIXME: Do not allocate memory for the singleton callee case.
CalleeSet(new CalleeSetType, Complete) {
@@ -80,18 +80,18 @@ public:
delete CalleeSet.getPointer();
}
const ApplyInst *getCallSite() const {
return CallSite;
const ApplyInst *getApply() const {
return TheApply;
}
/// Return a callee set that is known to be complete.
const CalleeSetType &getCalleeSet() const {
const CalleeSetType &getCompleteCalleeSet() const {
assert(isCalleeSetComplete() && "Attempt to get an incomplete call set!");
return *CalleeSet.getPointer();
}
/// Return a callee set that is not known to be complete.
const CalleeSetType &getKnownCalleeSet() {
const CalleeSetType &getPartialCalleeSet() {
return *CalleeSet.getPointer();
}
@@ -109,10 +109,10 @@ public:
}
};
/// A helper method for use with ArrayRefView. Just returns the CallSite
/// A helper method for use with ArrayRefView. Just returns the
/// ApplyInst of E.
inline const ApplyInst *getEdgeApplyInst(CallGraphEdge * const &E) {
return E->getCallSite();
return E->getApply();
}
class CallGraphNode {
@@ -122,25 +122,25 @@ class CallGraphNode {
/// The call graph node ordinal within the SILModule.
const unsigned Ordinal;
/// The known call sites that call into this function. The
/// caller's call graph node owns these.
llvm::SmallVector<CallGraphEdge *, 4> Callers;
/// Edges representing the known call sites that could call into
/// this function.
llvm::SmallVector<CallGraphEdge *, 4> CallerEdges;
/// The call sites within this function. This CallGraph node owns these.
llvm::SmallVector<CallGraphEdge *, 4> CallSites;
/// Edges representing the call sites within this function.
llvm::SmallVector<CallGraphEdge *, 4> CalleeEdges;
/// Do we know all the potential callers of this function? We initialize this
/// to !canHaveIndirectUses(F) optimistically and if we find any use that we
/// can not prove does not cause a reference to a function_ref to escape in a
/// we set this to false.
bool CallerSetComplete;
bool CallerEdgesComplete;
public:
friend class CallGraph;
CallGraphNode(SILFunction *Function, unsigned Ordinal)
: Function(Function), Ordinal(Ordinal),
CallerSetComplete(!canHaveIndirectUses(Function)) {
CallerEdgesComplete(!canHaveIndirectUses(Function)) {
assert(Function &&
"Cannot build a call graph node with a null function pointer!");
}
@@ -151,10 +151,10 @@ public:
/// Get the complete set of edges associated with call sites that can call
/// into this function.
const llvm::SmallVectorImpl<CallGraphEdge *> &getCallers() const {
assert(isCallerSetComplete() &&
const llvm::SmallVectorImpl<CallGraphEdge *> &getCompleteCallerEdges() const {
assert(isCallerEdgesComplete() &&
"Attempt to get an incomplete caller set!");
return Callers;
return CallerEdges;
}
// An adaptor that is used to show all of the apply insts which call the
@@ -163,31 +163,31 @@ public:
getEdgeApplyInst>;
/// Return the set of apply insts that can call into this function.
CallerCallSiteList getCallerCallSites() const {
return CallerCallSiteList(getCallers());
CallerCallSiteList getCompleteCallerEdgesApplies() const {
return CallerCallSiteList(getCompleteCallerEdges());
}
/// Get the known set of call graph edges that represent calls into this
/// function.
llvm::SmallVectorImpl<CallGraphEdge *> &getKnownCallers() {
return Callers;
/// Get the known set of call graph edges that represent possible
/// calls into this function.
llvm::SmallVectorImpl<CallGraphEdge *> &getPartialCallerEdges() {
return CallerEdges;
}
/// Return the known set of apply insts that can call into this function.
CallerCallSiteList getKnownCallerCallSites() {
return CallerCallSiteList(getKnownCallers());
CallerCallSiteList getPartialCallerEdgesApplies() {
return CallerCallSiteList(getPartialCallerEdges());
}
/// Get the known set of call sites in this function.
llvm::SmallVectorImpl<CallGraphEdge *> &getCallSites() {
return CallSites;
/// Get the set of call sites in this function.
llvm::SmallVectorImpl<CallGraphEdge *> &getCalleeEdges() {
return CalleeEdges;
}
/// Do we know that the set of call sites is complete - i.e. that
/// there is no other place that we can call from that can reach
/// this function?
bool isCallerSetComplete() const {
return CallerSetComplete;
bool isCallerEdgesComplete() const {
return CallerEdgesComplete;
}
unsigned getOrdinal() const {
@@ -196,18 +196,18 @@ public:
private:
/// Mark a set of callers as known to not be complete.
void markCallerSetIncomplete() {
CallerSetComplete = false;
void markCallerEdgesIncomplete() {
CallerEdgesComplete = false;
}
/// Add an edge representing a call site within this function.
void addCallSite(CallGraphEdge *CallSite) {
CallSites.push_back(CallSite);
void addCalleeEdge(CallGraphEdge *CallSite) {
CalleeEdges.push_back(CallSite);
}
/// Add an edge representing a call site that calls into this function.
void addCaller(CallGraphEdge *CallerCallSite) {
Callers.push_back(CallerCallSite);
void addCallerEdge(CallGraphEdge *CallerCallSite) {
CallerEdges.push_back(CallerCallSite);
}
};

View File

@@ -24,10 +24,10 @@ using namespace swift;
#define DEBUG_TYPE "call-graph"
STATISTIC(NumCallGraphNodes, "# of call graph nodes created");
STATISTIC(NumCallSitesWithEdges, "# of call sites with edges");
STATISTIC(NumCallSitesWithoutEdges,
STATISTIC(NumAppliesWithEdges, "# of call sites with edges");
STATISTIC(NumAppliesWithoutEdges,
"# of call sites without call graph edges");
STATISTIC(NumCallSitesOfBuiltins, "# of call sites calling builtins");
STATISTIC(NumAppliesOfBuiltins, "# of call sites calling builtins");
CallGraph::CallGraph(SILModule *M, bool completeModule) {
// Build the initial call graph by creating a node for each
@@ -110,7 +110,7 @@ bool CallGraph::tryGetCalleeSet(SILValue Callee,
return false;
case ValueKind::BuiltinInst:
++NumCallSitesOfBuiltins;
++NumAppliesOfBuiltins;
return false;
case ValueKind::PartialApplyInst:
@@ -135,19 +135,20 @@ void CallGraph::addEdgesForApply(ApplyInst *AI, CallGraphNode *CallerNode) {
bool Complete = false;
if (tryGetCalleeSet(AI->getCallee(), CalleeSet, Complete)) {
auto *CallSite = new (EdgeAllocator.Allocate()) CallGraphEdge(AI, CalleeSet,
Complete);
CallerNode->addCallSite(CallSite);
auto *Edge = new (EdgeAllocator.Allocate()) CallGraphEdge(AI, CalleeSet,
Complete);
CallerNode->addCalleeEdge(Edge);
for (auto *CalleeNode : CalleeSet)
CalleeNode->addCaller(CallSite);
CalleeNode->addCallerEdge(Edge);
// TODO: Compute this from the call graph itself after stripping
// unreachable nodes from graph.
++NumCallSitesWithEdges;
++NumAppliesWithEdges;
return;
}
++NumCallSitesWithoutEdges;
++NumAppliesWithoutEdges;
}
void CallGraph::addEdges(SILFunction *F) {
@@ -172,7 +173,7 @@ void CallGraph::addEdges(SILFunction *F) {
// as being incomplete.
if (!hasAllApplyUsers) {
auto *CalleeNode = getCallGraphNode(CalleeFn);
CalleeNode->markCallerSetIncomplete();
CalleeNode->markCallerEdgesIncomplete();
}
}
}
@@ -214,9 +215,9 @@ public:
DFSStack.insert(Node);
for (auto *CallSite : Node->getCallSites()) {
for (auto *ApplyEdge : Node->getCalleeEdges()) {
llvm::SmallVector<CallGraphNode *, 4> OrderedNodes;
orderCallees(CallSite->getKnownCalleeSet(), OrderedNodes);
orderCallees(ApplyEdge->getPartialCalleeSet(), OrderedNodes);
for (auto *CalleeNode : OrderedNodes) {
if (DFSNum.find(CalleeNode) == DFSNum.end()) {

View File

@@ -811,7 +811,7 @@ public:
continue;
// Now that we have our call graph, grab the CallSites of F.
auto CallSites = FNode->getKnownCallerCallSites();
auto CallSites = FNode->getPartialCallerEdgesApplies();
// If this function is not called anywhere, for now don't do anything.
//
@@ -823,7 +823,7 @@ public:
// Check if we know the callgraph is complete with respect to this
// function. In such a case, we don't need to generate the thunk.
bool CallerSetIsComplete = FNode->isCallerSetComplete();
bool CallerSetIsComplete = FNode->isCallerEdgesComplete();
// Otherwise, try to optimize the function signature of F.
Changed |= optimizeFunctionSignature(Allocator, RCIA, &F, CallSites,