Commit Graph

32 Commits

Author SHA1 Message Date
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
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
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
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
Michael Gottesman
07acb16da8 [arc-analysis] Add a helper routine getFinalReleasesForValue that determines for a value a set of post-dominating live releases.
This is refactored code from AllocBoxToStack with some small forward
looking changes. The user passes in a ReleaseTracker object that via a
closure decides what users are acceptable. I am going to use this in
closure specialization to remove dead closures.

The main limitation currently is that the code:

1. Assumes that the user deals with any issues relating to whether or
not the value is local.
2. Only visits the direct users of the value instead of visiting the
users recursively. This is safe for my uses now since I will only accept
users that are retains or releases. These have no uses.

The reason why I am leaving in these limitations is I am trying to limit
the amount of changes to the code.

Swift SVN r25048
2015-02-06 21:59:51 +00:00
Andrew Trick
6f19952379 Fixup some comment grammar.
Swift SVN r24907
2015-02-02 23:19:29 +00:00
Michael Gottesman
3b5e703d68 [g-arc-opts] Teach the ARC Optimizer how to understand @guaranteed parameters directly.
Swift SVN r24602
2015-01-21 14:52:37 +00:00
Michael Gottesman
38a0c69fc1 Rename some arc routines to use may instead of can as a prefix to match AliasAnalysis more closely.
Swift SVN r24509
2015-01-19 10:03:06 +00:00
Michael Gottesman
39817d5fd8 Remove arc namespace.
Swift SVN r24500
2015-01-19 00:10:48 +00:00
Michael Gottesman
3639691de2 Now that SmallMapVector is in llvm trunk... use it!
Swift SVN r24170
2015-01-04 22:50:11 +00:00
Michael Gottesman
7a2e1fb4d3 [arc-opts] After the arc optimizer converges, run another round of the ARC
optimizer freezing releases in the epilogue of functions that match to
SILArguments. This allows us to treat all such SILArguments throughout the
entire function as having a post dominating release.

<rdar://problem/18923030>

Swift SVN r23253
2014-11-11 23:37:09 +00:00
Michael Gottesman
3d396f8b12 [arc-analysis] Refactor OwnedArgToEpilogueReleaseMatcher from FunctionSigOpts.
Given a function F, this utility class attempts to match up owned arguments with
releases in the epilogue of the function.

I am refactoring this from FunctionSigOpts so I can use it in the ARC optimizer.

<rdar://problem/18923030>

Swift SVN r23219
2014-11-11 00:42:30 +00:00
Michael Gottesman
a014c65205 Expose canInstUseRefCountValues as swift::canNeverUseValues.
canInstUseRefCountValues should have always been named
canInstNotUseRefCountValues. I don't remember how it get renamed as such. Even
though it is a little weird to have a "canNever" in a function name, it makes
sense here to contrast it with canUseValue which returns if a specific user can
use a ptr in a way that requires the ptr to be alive. This in contrast says that
a user can never use a ptr in a manner where the ptr must be alive. I.e. this is
a universal quantifier.

Swift SVN r22961
2014-10-27 09:15:57 +00:00
Jordan Rose
3fcdfd40e9 Remove the "swift/Basic/Optional.h" header.
llvm::Optional lives in "llvm/ADT/Optional.h". Like Clang, we can get
Optional in the 'swift' namespace by including "swift/Basic/LLVM.h".

We're now fully switched over to llvm::Optional!

Swift SVN r22477
2014-10-02 18:51:45 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Michael Gottesman
f541019660 [codemotion] Extract out isARCInertTrapBB into ARCAnalysis from GARCOpts and teach SILCodeMotion to use it to not move retains into trap bbs.
This reduces the number of retains, releases in the stdlib by another 5% to
15167.

rdar://18328074

Swift SVN r21936
2014-09-13 03:15:29 +00:00
Michael Gottesman
4609513593 Remove SILValue::stripRCIdentityPreservingArgs and teach all uses of that method to use the new RCIdentityAnalysis.
Currently, the pass just calls a local version of that function. After OzU, I
will enable the full pass (which is currently disabled behind a flag).

Swift SVN r21894
2014-09-11 22:29:31 +00:00
Michael Gottesman
5561b3f538 Convert Nothing_t::Nothing => Nothing.
Swift SVN r21605
2014-08-30 03:11:55 +00:00
Michael Gottesman
b617d1b6d1 [arc] Change valueHasARC*InInstructionRange to return either the offending instruction or Nothing_t::None instead of a bool.
This enables us to both check if any instructions may use or decrement a value
in an instruction range and if we find such an instruction know the furthest
where we can move the retain or release.

Swift SVN r21522
2014-08-28 08:00:44 +00:00
Andrew Trick
292d9b3bb2 Fix SILCodeMotion: do not move retains across isUniquelyReferenced.
Sinking retains will simply make the unique check useless and eliminate
Array copies even when we need them.

Fix for:
<rdar://problem/18109082> ARC: make _isUniquelyReferenced a barrier to avoid lost copies

Swift SVN r21485
2014-08-27 18:28:36 +00:00
Michael Gottesman
e998695670 [g-arc-opts] Refactor global arc opts to use the PostOrderAnalysis.
Swift SVN r19915
2014-07-14 01:32:27 +00:00
Michael Gottesman
8685173e21 [arc-analysis] Add two functions for applying canUseValue and canDecrementValue to a contiguous range of instructions in the same BB.
The two functions are:

1. valueHasARCUsesInInstructionRange.
2. valueHasARCDecrementsInInstructionRange.

They operate on the range [Start, End).

I am going to use them in enum simplification and sil code motion.

Swift SVN r19893
2014-07-13 06:32:44 +00:00
Michael Gottesman
fd8f3b197f Add more informative DEBUG messages to valueMayBeCaptured and fix a little bit of formatting in ARCAnalysis.h. NFC.
Swift SVN r18892
2014-06-14 05:42:32 +00:00
Michael Gottesman
a12fb013f7 [g-arc-opts] Create a context object for the matching set computation which stores an evaluator and both state maps. This allows us to not need to recompute the reverse post order over and over again for a single function.
<rdar://problem/17181185>

Swift SVN r18724
2014-06-06 03:45:34 +00:00
Michael Gottesman
c2b2e52260 [g-arc-opts] Implement the merge functions to complete Stage 2 of global arc opts.
Also fixed a small bug related to how we handle arguments. We were not
clearing the state of the argument when we saw a potential decrement of
the argument.

<rdar://problem/17013194>

Swift SVN r18706
2014-06-05 04:35:14 +00:00
Michael Gottesman
445c474ed0 [g-arc-opts] Wired up the Release->RetainState (TDMap), Retain->ReleaseState (BUMap) dataflow into the pair matcher analysis which matches up sets of retains, releases.
This completes the implementation of the bottom up decrement data flow
data analysis.

<rdar://problem/16965332>

Swift SVN r18580
2014-05-23 01:34:13 +00:00
Michael Gottesman
592c2bb265 [g-arc-opts] Move the ARC pairing and dataflow analysis into their own analysis file.
Now the actual GlobalARCOpts pass itself is complete. The rest of the
work is improving the analysis.

rdar://16965332

Swift SVN r18542
2014-05-22 00:58:34 +00:00
Nadav Rotem
e620ed323c Additional negative logic changes. NFC.
Swift SVN r14743
2014-03-06 19:10:32 +00:00
Nadav Rotem
15ec637128 Reverse the negative logic. NFC.
Swift SVN r14742
2014-03-06 19:02:42 +00:00
Michael Gottesman
0044c1d379 [arc-opts] Teach cannotDecrementRefCount how to use alias information to prove
that an apply which may decrement ref counts can not decrement a value with
reference semantics if we can prove the value does not alias any of the applies
arguments.

Swift SVN r14120
2014-02-20 01:08:49 +00:00
Michael Gottesman
8cb9693830 [sil-arc-opts] Teach SILARCOpts how to use alias analysis to determine if a store/load could use a value.
Swift SVN r13658
2014-02-07 22:56:59 +00:00
Michael Gottesman
7461dbd70a Now that we have a PM, separate passes from analyses by creating a separate library swiftSILAnalysis and a separate folder/etc.
Swift SVN r13511
2014-02-05 22:17:50 +00:00