Commit Graph

167 Commits

Author SHA1 Message Date
Roman Levenstein
dcd3055360 [load-store-opts] Avoid re-loading values of "let"-variables
Teach LoadStoreOpts to handle "let" variables properly. Such variables should be loaded only once and their loaded values can be reused. This is safe, because once assigned these variables cannot change their value.

Swift SVN r27915
2015-04-29 18:02:12 +00:00
Mark Lacey
ed66cfd544 Use a callback in the linker to notify clients of newly deserialized functions.
Previous attempts to update the callgraph explicitly after calls to
linkFunction() weren't completely effective because we can deserialize
deeply and introduce multiple new function bodies in the process.

This gets us a bit closer, but only adds new call graph nodes. It does
not currently add edges for everything that gets deserialized (and this
is not fatal, so it is a step forward).

Swift SVN r27120
2015-04-08 06:46:15 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Mark Lacey
cd6d1488e8 Use SmallVector consistently across the call graph.
Swift SVN r27073
2015-04-07 07:27:06 +00:00
Mark Lacey
f6e577ef42 Remove inexplicable data in CallGraphAnalysis.
I suspect this is a holdover from when I rewrote most of the call graph
code. In any event, it's unused since we store this in the call graph
itself.

Swift SVN r27072
2015-04-07 07:27:05 +00:00
Mark Lacey
fea3321f59 Update the generic specializer to maintain the call graph.
Swift SVN r27024
2015-04-05 19:27:40 +00:00
Mark Lacey
7c62b7d3b2 Coding style tweaks.
Swift SVN r27017
2015-04-05 07:12:33 +00:00
Michael Gottesman
ac55558ba6 [g-arc-opts] Teach ARC how to recognize insts that *must* (notice not
may) use a value and that we will not remove implying that the use will
keep the value alive.

rdar://20368790

Swift SVN r27010
2015-04-05 04:31:41 +00:00
Mark Lacey
3572f1bc20 Maintain the call graph in the closure specializer.
Swift SVN r27009
2015-04-05 04:30:10 +00:00
Mark Lacey
bad8678f89 Add CallGraphEditor helper class and use it in the inliner.
Swift SVN r27008
2015-04-05 04:30:08 +00:00
Mark Lacey
3bcfaec662 Minor tweaks to call graph.
Use the isPossiblyUsedExternally method of SILFunction, remove a
work-around for "main", and delete a big "how" comment that could easily
be made obsolete (and probably will soon).

Swift SVN r26983
2015-04-04 19:00:48 +00:00
Mark Lacey
dd0cbf87fc Update call graph dumping to indicate functions that cannot be reached.
Swift SVN r26982
2015-04-04 19:00:47 +00:00
Erik Eckstein
78a3572fa4 Rename NoDTC to NoTypeCheck. NFC.
Swift SVN r26973
2015-04-04 08:24:59 +00:00
Mark Lacey
37a79ad87c Add text dumping of the call graph.
Compiling with '-Xllvm -sil-dump-call-graph' will result in the graph
being dumped each time it is built.

Swift SVN r26972
2015-04-04 06:52:23 +00:00
Mark Lacey
45301dd944 Fix 80-column violations.
Swift SVN r26967
2015-04-04 02:05:45 +00:00
Erik Eckstein
2f971c22cb re-apply r26871: stdlib: Do the Array fast-path check with a single array property call.
Changes compared to the original version:
I fixed the 2 bugs and added a test for the so far undetected missing range check bug.
To keep the SIL simple (4 basic blocks for arr[x]) I extracted the slow path for getElement into a
non-inlinable function.
On the other hand I inlined _typeCheck into the slow-path function.
This speeds up NSArray accesses because now only a single objectAtIndex is required for both
type checking and element retrieving.

Update on performance: DeltaBlue is now only 12% better (and not 25%). I suspect this is because
now Arnold's tail duplication cannot detect the ObjC call in the slow path.



Swift SVN r26935
2015-04-03 06:48:25 +00:00
Mark Lacey
a85cc9c6e9 Update call graph to track FullApplySites rather than ApplyInsts.
Use FullApplySite rather than ApplyInst through data structures and
function signatures.

This change does not update the call graph to actually look at
TryApply. That will happen in a future change.

Swift SVN r26893
2015-04-02 20:22:10 +00:00
Mark Lacey
ea2cbffb31 Remove IgnoreMissing parameter from removeEdgeForApply().
Instead, add a removeEdge() and update code to use
getCallGraphEdge()/removeEdge() in cases where the apply may not be
represented in the call graph.

Swift SVN r26881
2015-04-02 18:59:18 +00:00
Mark Lacey
23b6bd84f6 Do not build the call graph just to maintain it.
Before this commit, passes that were attempting to maintain the call
graph would actually build it if it wasn't already valid, just for the
sake of maintaining it.

Now we only maintain it if we already had a valid call graph built.

Swift SVN r26873
2015-04-02 17:16:01 +00:00
Ted Kremenek
69a12dfcb8 Revert "stdlib: Do the Array fast-path check with a single array property call."
This was causing test '1_stdlib/ArrayTraps.swift.gyb' to fail.

Swift SVN r26872
2015-04-02 14:47:19 +00:00
Erik Eckstein
834645a901 stdlib: Do the Array fast-path check with a single array property call.
Now that we can check isNative and NoDTC (no deffered type check needed) with a single bit-mask operation,
it makes sense to have a single array property call for it.
I replaced the the semantics call array.props.needsElementTypeCheck with array.props.isNativeNoDTC,
which is the combination of isNative && !needsElementTypeCheck. I kept array.props.isNative, which is not used for now,
but might be useful in the future, e.g. for array operations which don't care about type checks.

The optimized SIL for a class array access arr[i] now contains the minimum of 4 basic blocks.
PerfTests show +25% for DeltaBlue and some improvemements for -Onone.



Swift SVN r26871
2015-04-02 14:10:54 +00:00
Michael Gottesman
2dc936bd27 Remove code that snuck in.
Swift SVN r26864
2015-04-02 05:39:39 +00:00
Michael Gottesman
b122c0da47 [array-semantics] Teach array semantics to update the CallGraph when deleting instructions.
Swift SVN r26859
2015-04-02 05:01:09 +00:00
Michael Gottesman
8b36c031a2 [sil-combine] Update the CallGraph when deleting apply insts.
Swift SVN r26858
2015-04-02 05:01:07 +00:00
Michael Gottesman
2c1aed9b27 [cow] Teach uniqueness check hoisting how to ignore guaranteed calls to ArraySemantic functions.
We ignore calls to ArraySemantic functions when we hoist uniqueness checks. With
+0 self, this is disrupted by the release that now is in the caller instead of
the callee.

This patch fixes that problem by teaching COWArrayOpts about "guaranteed call
sequences". This is the following pattern:

retain(x)
... nothing that decrements reference counts ...
call f1(@guaranteed_self x)
... nothing that decrements or uses ref counts ...
call f2(@guaranteed_self x)
... nothing that decrements or uses ref counts ...
...
... nothing that decrements or uses ref counts ...
call f$(n-1)(@guaranteed_self x)
... nothing that decrements or uses ref counts ...
call fn(@guaranteed_self x)
... nothing that uses ref counts ...
release(x)

This pattern is created when there are a bunch of guaranteed calls together in a
row (which seems to happen at the "semantic" SIL level). We pattern match the
sequence and then verify that all of the calls are semantic calls. If the
verification succeeds, we can hoist the uniqueness check.

rdar://20340699

Swift SVN r26835
2015-04-01 23:30:03 +00:00
Erik Eckstein
160b8e07db SILPassManager: A new method to reduce the number of SIL pass runs.
It avoids that a pass runs a second time if didn't make any changes in the previous run and no other pass changed the function in between.
rdar://problem/20336764

In this change I also removed the CompleteFunctions analysis which is now obsolete.

Some measurements with swiftbench (-wmo, single threaded):
It reduces the number of pass runs by about 28%. Because only passes are skipped that don't do anything, the effect on compile time is not so dramatic.
The time spent in runSILOptimizationPasses is reduced by ~9% which gives a total compile time reduction of about 3%.




Swift SVN r26757
2015-03-31 14:19:51 +00:00
Michael Gottesman
9a215e078a [arc] Add support for performing a ARCUse query on a reverse range.
I am going to use this in a subsequent commit in SILCodeMotion.

Swift SVN r26670
2015-03-28 02:47:06 +00:00
Michael Gottesman
74777a6c3a [remove-pin] Teach remove pin how to recognize a safe guaranteed array semantic call sequence.
Given a strong_pin for which we have not yet seen a strong_unpin, a safe
guaranteed call sequence is of the following form:

retain(x)
call f(@guaranteed x)
release(x)

where f is an array semantic call that we know does not touch globals and thus
are known to not change ref counts.

rdar://20305817

Swift SVN r26662
2015-03-28 00:43:47 +00:00
Nadav Rotem
240ff14db1 Split DominanceAnalysis into Dom and PDom using FunctionAnalysisBase.
This commit splits DominanceAnalysis into two analysis (Dom and PDom) that
can be cached and invalidates using the common FunctionAnalysisBase interface
independent of one another.

Swift SVN r26643
2015-03-27 20:54:28 +00:00
Nadav Rotem
50803a7653 Create FunctionAnalysisBase to handle the boiler plate of caching and invalidating function specific analysis.
Swift SVN r26642
2015-03-27 20:54:22 +00:00
Nadav Rotem
f0fa502d56 Split the RCIdentityAnalysis analysis to allow per-function invalidation.
Before the change the RCIdentityAnalysis kept a single map that contained
the module's RC information. When function passes needed to invalidate the
analysis they had to clear the RC information for the entire module. The
problem was mitigated by the fact that we process one function at a time, and
we start processing a new function less frequently.

II adopted the DominanceAnalysis structure. We should probably implement
this functionality as CRTP.

Swift SVN r26636
2015-03-27 16:55:36 +00:00
Mark Lacey
62065f7f50 Update function sig opts to work with upcoming call graph changes.
Small tweak to function signature optimization so that it filters out
applies that might have multiple targets, as well as applies of partial
applies, which will take some updates to handle.

Resolves rdar://problem/19632244 and rdar://problem/20049782.

I've opened rdar://problem/20306331 to consider handling
apply-of-partial-apply at some point in the future.

Swift SVN r26585
2015-03-26 09:00:32 +00:00
Michael Gottesman
0688dbf607 [rcid] Teach RCIdentityAnalaysis::getRCUses() how to ignore certain uses that are inert from its perspective.
This includes:

1. Extract instructions which extracts a trivial part of an aggregate that has
one RCIdentity.
2. Instructions which take a pointer out of ARC's control by converting it to a
trivial type. This is safe to do since we can assume that the object that is
convered is alive when the conversion happens. So assuming that we can
conservatively find all RC users, we will have at least one RC user that
post dominates the use (since otherwise we would be touching a dangling
pointer). We leave it to the user of the pass to determine what is safe to do
with this information. Potentially in the future it might make sense to return
this information as well so that a user can use that information directly.

rdar://20305817

Swift SVN r26583
2015-03-26 07:19:41 +00:00
Michael Gottesman
254c784c94 [+0 self][pin removal] Teach pinremoval how to use RCIdentityAnalysis when removing pins.
Previously, we were being very conservative and were not trying to look through
any RCId uses. Now we understand how to look through RCIdentical instructions to
pair a pin and unpin. We also understand how to use the new getRCUses API on
RCIdentityAnalysis to get all uses of a value, looking through RCIdentical
instructions.

I also added some code to COWArrayOpts to teach it how to look through enum insts (which I needed).

Additionally I got stuck and added support for automatic indentation in Debug
statements. This is better than having to indent by hand every time.

There were no significant perf changes since this code was not being emitted by
the frontend. But without this +0 self causes COW to break.

rdar://20267677

Swift SVN r26529
2015-03-25 06:21:11 +00:00
Nadav Rotem
da92b6f81b Turn the analysis invalidation code into an early exit. NFC.
Swift SVN r26450
2015-03-23 21:19:04 +00:00
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
Nadav Rotem
bff2349442 [compile time] Rewrite the code to reduce the number of map lookups.
Swift SVN r26387
2015-03-21 03:26:07 +00:00
Nadav Rotem
bbeee760c2 Remove the old API for preserving LoopInfo and DomInfo
Swift SVN r26377
2015-03-20 22:53:10 +00:00
Nadav Rotem
141c0d8310 [PM] Add the ability to lock analysis and make sure they do not respond to invalidation messages.
Swift SVN r26374
2015-03-20 22:53:07 +00:00
Nadav Rotem
0a11a60f95 Fix a doc line.
Swift SVN r26370
2015-03-20 22:52:56 +00:00
Arnold Schwaighofer
63f4170a0e ArraySemantics: To facilitate make_unique hoisting add a array.owner call
After this change we can also hoist uniqueness checks for array of classes.

rdar://19955624

Swift SVN r26311
2015-03-19 19:32:16 +00:00
Mark Lacey
c3d6f70ee9 Fix coding style.
Swift SVN r26171
2015-03-15 23:30:37 +00:00
Arnold Schwaighofer
513df867cf Revert "ArraySemantic: Add isMayRelease method"
This reverts commit r25925.

We cannot assume that these functions are not mayRelease because they call
Objective C functions which we must assume to be mayRelase.

Swift SVN r26107
2015-03-13 18:55:05 +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
Arnold Schwaighofer
a68f488e99 Revert "DestructorAnalysis: Don't rely on stable cannonical type pointers"
This reverts commit r26049.

Canonical types really should to be stable across the lifetime of one module.

Swift SVN r26080
2015-03-13 02:01:35 +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
Arnold Schwaighofer
07ef1bb68a DestructorAnalysis: Don't rely on stable cannonical type pointers
This should be NFC. Pointers to cannonical types should be stable accross
processing of a module.

Swift SVN r26049
2015-03-12 17:43:44 +00:00