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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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