Commit Graph

34 Commits

Author SHA1 Message Date
Nadav Rotem
d78b376d07 [passes] Replace the old invalidation lattice with a new invalidation scheme.
The old invalidation lattice was incorrect because changes to control flow could cause changes to the
call graph, so we've decided to change the way passes invalidate analysis.  In the new scheme, the lattice
is replaced with a list of traits that passes preserve or invalidate. The current traits are Calls and Branches.
Now, passes report which traits they preserve, which is the opposite of the previous implementation where
passes needed to report what they invalidate.

Node: I tried to limit the changes in this commit to mechanical changes to ease the review. I will cleanup some
of the code in a following commit.

Swift SVN r26449
2015-03-23 21:18:58 +00:00
Mark Lacey
dc7bb1a6f3 Add support for some editing of the call graph.
Specifically, addEdgesForApply() and removeEdgesForApply() allow for
clients to notify the call graph of apply instructions that are being
added or removed by the client. This allows us to avoid dangling
pointers in the maps kept in the call graph and avoid invalidating the
entire call graph at the end of passes that choose to maintain it.

Also, markCallerEdgesOfCalleesIncomplete() makes it possible to notify
all the callees of an apply that is being removed that we no longer have
complete information about all of the callers.

What this change specifically does not do is recompute the bottom-up
ordering of SCCs or functions in the call graph.

I have some incomplete updates to the inliner to use this functionality,
and it doesn't appear to be completely broken, but at this point I would
say this is experimental and could change once we have more clients
making use of it.

Swift SVN r26097
2015-03-13 08:03:15 +00:00
Mark Lacey
f6337d9688 Make call graph edge sets be SmallPtrSets rather than SmallVectors.
Re-apply r26072 with a fix to ensure that we get stable bottom-up
orderings in the call grpah.

Using SmallPtrSet here makes sense, and paves the way to more reasonable
code for editing the call graph by clients.

One unfortunate casualty of this is the ArrayRevView that was used by
one client.

Swift SVN r26093
2015-03-13 07:33:57 +00:00
Mark Lacey
5cb0d48ea8 Minor new comments to call graph header.
Break up sections of major functionality with comments.

Swift SVN r26092
2015-03-13 07:33:55 +00:00
Mark Lacey
1936396a5b Revert "Make call graph edge sets be SmallPtrSets rather than SmallVectors."
This reverts commit r26072, which could result in non-deterministic
bottom-up ordering in the call graph.

I'll reapply with a fix soon.

Swift SVN r26074
2015-03-13 00:58:51 +00:00
Mark Lacey
0163c66c1e Make call graph edge sets be SmallPtrSets rather than SmallVectors.
It makes more sense, and paves the way to more reasonable code for
editing the call graph by clients.

One unfortunate casualty of this is the ArrayRevView that was used by
one client.

Swift SVN r26072
2015-03-12 23:15:35 +00:00
Michael Gottesman
ef94fa0001 [callgraph] Change a bunch of llvm::SmallVectorImpl => ArrayRef. This hides the unnecessary information that the CallGraph internally uses SmallVectors.
Swift SVN r25838
2015-03-07 04:47:45 +00:00
Michael Gottesman
0aee8f9521 [callgraph] Centralize the calling of destructors in the CallGraph of CallGraphState.
Previously this was scattered in various places . Now we have a simple model that
all CallGraphEdges, CallGraphNodes, and CallGraphSCCs are owned by the CallGraph
since they are allocated by the CallGraph's BumpPtrAllocator.

This additionally fixes a problem where we were calling delete on SCC's owned by
the BumpPtrAllocator.

Swift SVN r25522
2015-02-25 00:41:14 +00:00
Michael Gottesman
114345b773 [callgraph] Add basic verification of the callgraph.
This is currently disabled by default since this verification trips on
ToT when I checked a few days ago.

The current checks that are performed are:

1. For every (SILFunction, CallGraphNode) pair FuncPair in the SILFunction to
   CallGraphNode map check that:
   a. FuncPair.first is a SILFunction in the current module.
   b. FuncPair.first is the SILFunction inside the CallGraphNode FuncPair.second.
   c. All CallGraphEdges mapped to FuncPair.second have ApplyInsts which are in
      the SILFunction FuncPair.first.

2. For every pair (ApplyInst, CallGraphEdge) ApplyPair in the Apply to
   CallGraphEdge map, check that:
   a. ApplyPair.second.getCallSite() == ApplyPair.first.
   b. ApplyPair.first->getFunction() is in the SILFunction to
      CallGraphNode map and the CallGraphEdge for ApplyPair is one of
      CallSiteEdges in the mapped to CallGraphNode.

<rdar://problem/19944399>

Swift SVN r25520
2015-02-24 23:55:21 +00:00
Michael Gottesman
cf27691098 [callgraph] Add a map from Apply -> CallGraphEdge.
This makes it easy to use the callgraph to determine what the Apply
actually calls instead of attempting to ascertain it in an adhoc
manner. This allows for the call graph analysis to be used as the one
point of truth for determing what an apply inst can call.

Swift SVN r25516
2015-02-24 22:49:47 +00:00
Michael Gottesman
28cde0e785 [callgraph] Use one bump ptr alloctor for all memory allocated in the callgraph.
I also did some small llvm style fixes.

Swift SVN r25515
2015-02-24 22:49:47 +00:00
Mark Lacey
64af0798df 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
2015-02-24 00:08:19 +00:00
Mark Lacey
f92d70ec6c Use arena allocation in the call graph builder.
Shave a little more time off the call graph construction.

Thanks go to Erik for the suggestion.

Swift SVN r25439
2015-02-20 22:41:55 +00:00
Erik Eckstein
44fed755cc Use SmallPtrSet instead of DenseSet in CallGraphEdge
The memory allocation of DenseSet had a significant contribution to the compile time.
This change reduces the time of runSILOptimizationPasses by ~25% in a stdlib build => ~2s faster.



Swift SVN r25373
2015-02-18 18:01:21 +00:00
Mark Lacey
9afc924fdf Cast away constness in client, not in call graph code.
Swift SVN r24789
2015-01-28 05:57:08 +00:00
Mark Lacey
f8d9f73777 Refactor call graph to share common code for different kinds of applies.
Swift SVN r24764
2015-01-28 00:37:38 +00:00
Mark Lacey
9be5c4aa71 Minor update to call graph interface.
Provide only a single way to create a call graph edge, and make the
client explicitly inform us whether the callee set is complete.

Swift SVN r24763
2015-01-28 00:37:38 +00:00
Michael Gottesman
a4318845cc Add in a few comments. NFC.
Swift SVN r23717
2014-12-05 02:08:38 +00:00
Michael Gottesman
8eb9ad4591 Change file to fit LLVM coding standard. NFC.
Swift SVN r23716
2014-12-05 02:08:37 +00:00
Michael Gottesman
ebfcc123a3 [callgraph] Teach the callgraph how to determine for simple cases if we have a complete caller set.
We specifically only handle cases of functions that are not visible externally
and for whom all function_refs to the function only have apply inst users.

<rdar://problem/19137435>

Swift SVN r23714
2014-12-05 02:08:36 +00:00
Mark Lacey
445afdc031 Delete the old call graph code.
Swift SVN r22598
2014-10-08 07:47:32 +00:00
Michael Gottesman
e5fcbc6d59 [func-sig-opts] Add get{Known,}CallerCallSites to the CallGraph.
This returns an ArrayRefView that allows one to iterate over the CallSites of a
functions callers in a clean way.

Swift SVN r21730
2014-09-04 23:34:35 +00:00
Michael Gottesman
6d1fef172a Small LLVM style fixups. NFC.
Swift SVN r21617
2014-08-31 19:59:44 +00:00
Mark Lacey
6a695f3099 Move DeadFunctionElimination to using the new call graph.
The old call graph remains, but the new call graph can obtained by
calling getCallGraph() on the analysis pass.

I'll move the few other passes that use the call graph over soon and
then rip out the old call graph.

No diffs in the stdlib.

Swift SVN r21565
2014-08-29 05:03:31 +00:00
Mark Lacey
dc625f7c19 Minor API change in call graph.
Swift SVN r21553
2014-08-29 00:32:17 +00:00
Mark Lacey
36365d79df In the new call graph, find the SCCs in bottom-up order.
With this change we generate the SCCs in the call graph (for the kinds
of calls we currently recognize) in bottom-up, which we can then
iterate over directly or in reverse for invocation- and
reverse-invocation-order traversal of the call graph.

(This still isn't hooked up - but will be after some dumping routines
and verification of the output).

Swift SVN r21552
2014-08-29 00:32:17 +00:00
Mark Lacey
3494d6ab39 Track call graph roots with a SmallVector rather than DenseSet.
This will allow us to search in the order the roots are added which
should improve stability of our output. There is also an ordinal on each
node that we can use to choose order of traversing edges at a given call
site.

Swift SVN r21484
2014-08-27 16:59:50 +00:00
Mark Lacey
dee10cb164 Update the new call graph so that edges have sets of call graph nodes.
Previously we tracked a set of functions that could be called from a given
call site. Now we track a set of call graph nodes (each of which
represents a callable function). As a result we now create call graph
nodes for declarations rather than just definitions.

Swift SVN r21483
2014-08-27 15:54:34 +00:00
Mark Lacey
a3350db69c Add statistics to call graph construction.
Also stub out some of the cases we'll need to handle to build a more
complete call graph.

Swift SVN r21430
2014-08-23 05:48:54 +00:00
Mark Lacey
34a1050222 Add data structures for a new, more detailed, call graph.
This is not yet hooked up. I want to add a dumper and some tests, and
need to implement code to do invocation- and reverse-invocation-ordering
over the SCCs of the call graph before it can fully replace the existing
code.

This call graph has edges for each call site, so it's really a
multigraph. Each call site tracks the set of functions that can be
called from that point. Currently that set is always a singleton since
we only handle applies of direct function_refs (like the existing call
graph). In time it will be expanded to handle other types of function
application.

Swift SVN r21407
2014-08-22 07:46:53 +00:00
Mark Lacey
7b30e832e4 Move contents of CallGraph.h into CallGraphAnalysis.h.
Swift SVN r21393
2014-08-22 00:00:04 +00:00
Mark Lacey
f1f3025838 Add call graph edges based on direct calls.
We were adding call graph edges based on seeing a function_ref. Instead,
we'll only add them now based on a direct apply of a function_ref.

Also a minor refactoring to move the code that walks the blocks and
instructions of a function into its own method.

Swift SVN r21243
2014-08-15 23:29:37 +00:00
Mark Lacey
d5a619bbad Small refactoring of call graph code.
This is a first step towards building a better call graph.

Swift SVN r21152
2014-08-12 18:20:21 +00:00
Nadav Rotem
898bf23738 Move the CallGraphAnalysis to a new file.
Swift SVN r20714
2014-07-29 23:18:56 +00:00