Commit Graph

52 Commits

Author SHA1 Message Date
Andrew Trick
61d2c0166b Make SILPasses (ARC & Pin removal) aware of IsUniqueInst.
Swift SVN r27888
2015-04-28 22:54:25 +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
Michael Gottesman
edab72fd4c [arc-opts] Teach ARC about when some instructions don't decrement ref counts.
Specifically we teach ARC:

1. StrongPin never decrements ref counts.
2. CheckedCastAddrBranchInst only decrements ref counts if we are taking the
   source value.

<rdar://problem/20368790>

Swift SVN r27000
2015-04-05 02:39:46 +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
1b157d4138 [+0 self][arc] When checking if a cond_br touches reference counts, only perform AA on the operands passed to other blocks, not the integer that is being switched upon.
Perf Results:

RIGHT - Before (ms)
LEFT - After (ms)

TITLE               LEFT         RIGHT        RIGHT/LEFT
InsertionSort       103721.00    110326.00    1.06
NSXMLParser         27031.00     29763.00     1.10

rdar://20355793

Swift SVN r26784
2015-04-01 00:48:29 +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
4ec67e9278 [arc] Teach ARC analysis how to determine uses of terminators rather than just bailing.
We were always treating terminators (even without arguments) as uses. This is
incorrect. With this patch we now say that a terminator can not use a ref count
pointer if all of the terminator's arguments conservatively can not alias the
pointer.

rdar://20335297

Swift SVN r26664
2015-03-28 01:38:29 +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
Chris Lattner
4f708c049b fix const correctness and standardize on names for the successor list of
TerminatorInsts.  Now you can walk over the successor list of a terminator
and actually modify the SILSuccessor directly, allowing better CFG
transformations.  NFC.




Swift SVN r26140
2015-03-14 17:52:27 +00:00
Arnold Schwaighofer
7b9917bd21 Revert "ARCAnalysis: Teach it about array semantic calls that are not may-release"
This reverts commit r25926.

This is not a safe assumption to make. The array implementation does call
Objective C functions which must be assumed to be may-release.

Swift SVN r26106
2015-03-13 18:55:04 +00:00
Arnold Schwaighofer
af98fb95e2 Revert "ARCAnalysis: Teach ARC analysis about certain objective c methods that are not may-release"
This reverts commit r26082.

We cannot assume that NSArray count or objectAtIndex don't not have side effects
that are observed from Swift. We have to assume they could change an object that
is visible from Swift and therefore they are may-release.

Swift SVN r26099
2015-03-13 12:49:17 +00:00
Arnold Schwaighofer
a25b271c94 ARCAnalysis: Teach ARC analysis about certain objective c methods that are not may-release
This enables it to move retain about critical objective c method calls such as
objectAtIndex and count used by Array.

Improves DeltaBlue by 35% at -O.

radar://20147568

Swift SVN r26082
2015-03-13 02:19:54 +00:00
Arnold Schwaighofer
e29b7ca52a ARCAnalysis: Teach it about array semantic calls that are not may-release
Read only array semantic functions such as "array.get_element" only have
balanced retain/release pairs in +0 self mode. Therefore, they are only a use of
the self pointer not a may-release or a guaranteed use. This means we can more
aggressively remove retain/release pairs accross such callees.

radar://20071261

Swift SVN r25926
2015-03-10 15:20:22 +00:00
Arnold Schwaighofer
951dc2875a Nuke isSideEffectFree
We can now compute the same result with Inst.mayHaveSideEffects(). NFC.

Swift SVN r25742
2015-03-04 05:03:44 +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
Michael Gottesman
ae18e7bedd [g-arc-opts] Change fatalName checking to use endswith instead of equals.
Specialization manglings always prepend the specialization information to the
beginning of a function name. Thus we can (until we support multiple @semantic
tags) get better dylib performance.

Swift SVN r25006
2015-02-05 19:11:34 +00:00
Michael Gottesman
7acd7def16 [verifier] Make sure that applies of no-return functions have an unreachable as the next instruction.
This makes it easy to find no-return functions since one must iterate
through all BB with unreachable terminators and check the previous
instruction.

Swift SVN r25004
2015-02-05 19:11:33 +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
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
Joe Groff
ea65d1e60b SIL: Remove the builtin_function_ref instruction.
Swift SVN r22797
2014-10-16 16:18:40 +00:00
Joe Groff
e3f9a2035c SIL: Move SILGen and passes over to use "builtin" instead of "apply (builtin_function_ref)".
Swift SVN r22785
2014-10-15 23:37:22 +00:00
Dave Abrahams
74e27aaab1 [stdlib] uniqueness checking for users
Make unique reference checking available to users, making ManagedBuffer
a complete facility for building COW value types.  Also rationalize the
way we name and organize the runtime primitives we ultimately call.

Swift SVN r22594
2014-10-08 04:48:52 +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
Joe Groff
a3126706da SIL: Eliminate the dead 'alloc_array' insn.
Swift SVN r22292
2014-09-26 02:28:10 +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
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
2ee9dab15a [arc-analysis] unchecked_ref_bit_cast can never use reference count values in a way we care about. Trivial bit casts do not either as long as we are not converting a ref count value to a trivial value.
Swift SVN r19911
2014-07-13 23:44:13 +00:00
Michael Gottesman
4f115c63c3 [arc-analysis] {struct,tuple}_element_addr, unchecked_take_enum_data_addr do not use reference counted objects in a way we care about.
The reason we do not care is since this predicate is meant to be used in a
backward dataflow pass implying that we will see the GEPs users before we see
the GEP itself.

Swift SVN r19910
2014-07-13 22:26:47 +00:00
Michael Gottesman
f45ea97a8b [arc-analysis] ReadNone builtins that do not take values with reference semantics can not use values with reference semantics.
Swift SVN r19909
2014-07-13 22:26:46 +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
Manman Ren
357640494a [global-arc] treat isUniquelyReferenced as known to not decrement ref count.
This removes a pair of retain|release from MD5.hash().
rdar://17360691


Swift SVN r19024
2014-06-20 01:20:17 +00:00
Michael Gottesman
6db91f76c9 [g-arc-opts] swift_keepAlive does not decrement reference counts.
Swift SVN r18708
2014-06-05 05:14:17 +00:00
Michael Gottesman
5def9ae5dc [local-arc-analysis] Teach ARC analysis about more instructions that only use pointers via users. These uses will be caught by the dataflow.
Swift SVN r18695
2014-06-03 08:58:29 +00:00
Michael Gottesman
fc7438b79c [sil-arc] Casts do not use pointers in an interesting way.
The reason that this is true is that if the cast is dead, we will delete
it. If it is not dead there must be some other use after the cast that
uses our pointer via the cast. If that is true and there is a release
after that use we will not move the release over the use. On the other
hand if the release is in between the cast and the use it is of course
safe to move the release forward.

Swift SVN r16797
2014-04-25 02:16:43 +00:00
Michael Gottesman
5283a351e4 [sil-arc] Fix up a few comments and teach the optimizer that fix_lifetime_inst, copy_block, and retain_value can not decrement ref counts.
Swift SVN r16790
2014-04-25 01:27:44 +00:00
Michael Gottesman
9b09c562cd [sil-arc-optimizer] Teach the ARC optimizer that it needs to check if a ptr escapes in order to say that a callee can not affect the ptr.
<rdar://problem/16424681>

Swift SVN r16298
2014-04-14 04:44:54 +00:00
Mark Lacey
1452d24671 Small cleanup: Remove unnecessary calls to getDef(), mostly in dyn_cast<>(...).
Swift SVN r16235
2014-04-11 23:05:16 +00:00
Joe Groff
8adaab0233 Fold ExtInfo::isThin and ::isBlock into a "Representation" enum.
These bits are orthogonal to each other, so combine them into one, and diagnose attempts to produce a type that's both. Spot-fix a bunch of places this revealed by inspection that we would have crashed in SILGen or IRGen if blocks were be handled.

Swift SVN r16088
2014-04-09 00:37:26 +00:00
Nadav Rotem
a72cd1af2a ARCOpt: fix an object ownership bug.
When checking for users of an object we need to consider all values
because any use of the object may increase its lifetime. 

For example, in the sil code below, instruction %26 increases the lifetime of
object %9. If we remove the retain-release pair then the apply inst may
release %9 and the load would become invalid. 

  strong_retain %9#0 : $Builtin.ObjectPointer
  %24 = apply %19<>()
  %26 = load %9#1 : $*Int
  strong_release %9#0 : $Builtin.ObjectPointer
  return %26 : $Int

This fixes rdar://16233340



Swift SVN r14745
2014-03-06 19:46:18 +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
Doug Gregor
5d8bd84dfa Introduce the SIL instruction alloc_ref_dynamic.
alloc_ref_dynamic allocates an instance of a class type based on the
value in its metatype operand. Start emitting these instructions for
the allocating constructor of a complete object initializer (not yet
tested) and for the allocating constructor synthesized for an imported
Objective-C init method.

Still missing:
  - IRGen still does the same thing as alloc_ref right now. That
  change will follow.
  - There are devirtualization opportunities when we know the value of
  the metatype that would turn an alloc_ref_dynamic into an alloc_ref;
  I'm not planning to do this optimization.



Swift SVN r14560
2014-03-01 21:55:50 +00:00
Joe Groff
88b6efcc43 Rename ArchetypeMethodInst -> WitnessMethodInst more thoroughly.
Swift SVN r14501
2014-02-28 06:41:18 +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
fbe2ccf0d6 [sil-aa] Add in convenience methods for querying AliasAnalysis::getMemoryBehavior.
The methods are:

 * mayWriteToMemory()
 * mayReadFromMemory()
 * mayReadOrWriteMemory()
 * mayHaveSideEffects() [Side effects + writing to memory]
 * mayHavePureSideEffects() [Only side effects, ignores writes to memory]

Swift SVN r13791
2014-02-12 00:14:29 +00:00