Commit Graph

77 Commits

Author SHA1 Message Date
Roman Levenstein
28645853a4 [load-store-opts] Improvements to let-propagation based on the comments by Chris, Michael and Arnold.
- Support propagation of let properties values on tuples
- Do not treat initial assignment to a let-property as MemBehavior::None
- Improve comments
- Add more tests.

Swift SVN r28069
2015-05-02 02:36:52 +00:00
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
Joe Groff
962a87f444 SIL: Rename address-only existential instructions to '{init,deinit,open}_existential_addr'.
For better consistency with other address-only instruction variants, and to open the door to new exciting existential representations (such as a refcounted boxed representation for ErrorType).

Swift SVN r25902
2015-03-09 23:55:31 +00:00
Arnold Schwaighofer
f7c01f2061 Nuke isReadNone function
We can now compute the same result with Inst.mayReadOrWriteMemory(). NFC.

Swift SVN r25743
2015-03-04 05:03:45 +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
Andrew Trick
08c9a6f8a9 Clarify alias analysis comments for my own sanity.
Swift SVN r25060
2015-02-07 00:31:57 +00:00
Erik Eckstein
c2702fbf8b Fix <rdar://problem/19069205> Stack overflow in SIL alias analysis
The problem was that SILValue::stripAddressProjections() was out of sync with Projection::isAddrProjection().



Swift SVN r23806
2014-12-09 11:16:16 +00:00
Michael Gottesman
7285835422 [projection] Rename isAddressProjection => isAddrProjection and add isValueProjection.
This is apart of some cleanups of the Projection class.

I also improved the comment at the top of projection to make its usage
clearer.

Swift SVN r23355
2014-11-16 04:09:15 +00:00
Michael Gottesman
01a00347ca [aa] Add ProjectionPath::computeSubSeqRelation() and use it to teach AA how to check for partial aliasing.
rdar://18831605

Swift SVN r23076
2014-11-03 03:38:01 +00:00
Michael Gottesman
bb48674cf3 [aa] Move address projection path AA to use projection path infrastructure.
rdar://18831605

Swift SVN r23061
2014-11-02 00:41:13 +00:00
Michael Gottesman
7b34373bf4 [aa] Add PartialAlias. This currently is not returned by any routine or used anywhere.
rdar://18831605

Swift SVN r23059
2014-11-02 00:41:12 +00:00
Joe Groff
5a2f48e3be Add a Builtin.BridgeObject type.
This is a type that has ownership of a reference while allowing access to the
spare bits inside the pointer, but which can also safely hold an ObjC tagged pointer
reference (with no spare bits of course). It additionally blesses one
Foundation-coordinated bit with the meaning of "has swift refcounting" in order
to get a faster short-circuit to native refcounting. It supports the following
builtin operations:

- Builtin.castToBridgeObject<T>(ref: T, bits: Builtin.Word) ->
  Builtin.BridgeObject

  Creates a BridgeObject that contains the bitwise-OR of the bit patterns of
  "ref" and "bits". It is the user's responsibility to ensure "bits" doesn't
  interfere with the reference identity of the resulting value. In other words,
  it is undefined behavior unless:

    castReferenceFromBridgeObject(castToBridgeObject(ref, bits)) === ref

  This means "bits" must be zero if "ref" is a tagged pointer. If "ref" is a real
  object pointer, "bits" must not have any non-spare bits set (unless they're
  already set in the pointer value). The native discriminator bit may only be set
  if the object is Swift-refcounted.

- Builtin.castReferenceFromBridgeObject<T>(bo: Builtin.BridgeObject) -> T

  Extracts the reference from a BridgeObject.

- Builtin.castBitPatternFromBridgeObject(bo: Builtin.BridgeObject) -> Builtin.Word

  Presents the bit pattern of a BridgeObject as a Word.

BridgeObject's bits are set up as follows on the various platforms:

i386, armv7:

  No ObjC tagged pointers
  Swift native refcounting flag bit: 0x0000_0001
  Other available spare bits:        0x0000_0002

x86_64:

  Reserved for ObjC tagged pointers: 0x8000_0000_0000_0001
  Swift native refcounting flag bit: 0x0000_0000_0000_0002
  Other available spare bits:        0x7F00_0000_0000_0004

arm64:

  Reserved for ObjC tagged pointers: 0x8000_0000_0000_0000
  Swift native refcounting flag bit: 0x4000_0000_0000_0000
  Other available spare bits:        0x3F00_0000_0000_0007

TODO: BridgeObject doesn't present any extra inhabitants. It ought to at least provide null as an extra inhabitant for Optional.

Swift SVN r22880
2014-10-23 00:09:23 +00:00
Joe Groff
3f23b82e6d SIL: Rename SILGlobalAddr to GlobalAddr.
All globals are SIL globals now.

Swift SVN r22827
2014-10-18 17:08:28 +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
Joe Groff
bb46f4bbd9 SIL: Remove the global_addr instruction.
It's no longer needed now that we always lower to SIL globals.

Swift SVN r22693
2014-10-12 17:19:06 +00:00
Joe Groff
be45322668 SIL: Drop the upcast_existential* instructions.
Swift SVN r22388
2014-09-30 16:11:54 +00:00
Joe Groff
152aa9e244 Revert "SIL: Drop the upcast_existential* instructions."
This reverts commit r22345.

Swift SVN r22353
2014-09-29 13:46:41 +00:00
Joe Groff
1e343fb430 SIL: Drop the upcast_existential* instructions.
Swift SVN r22345
2014-09-28 19:24:33 +00:00
Joe Groff
0518f2067f Revert "SIL: Drop the upcast_existential* instructions."
This reverts commit r22333.

Swift SVN r22337
2014-09-28 18:41:05 +00:00
Joe Groff
727c9b5ed7 SIL: Drop the upcast_existential* instructions.
Swift SVN r22333
2014-09-28 16:38:13 +00:00
Joe Groff
a3126706da SIL: Eliminate the dead 'alloc_array' insn.
Swift SVN r22292
2014-09-26 02:28:10 +00:00
Manman Ren
bea41c0bd3 [Alias Analysis] handle casts in projection path.
We ignore casts when generating projection paths for alias analysis. When
comparing two paths, we say no alias when accessing different fields of
the same Decl Context.


Swift SVN r20353
2014-07-23 00:02:28 +00:00
Manman Ren
0a1be06531 [Alias Analysis] accessing different fields of the same object do not alias.
Also stripCasts in findAddressProjectionPathBetweenValues.
We can now move "load of an invariant field" out of the loop even though we
have "store to a different field" in the loop.

Performance:
O3 -----
Phonebook 4367 3866 -11.4724%
Ofast ------
NBody 1623 1292 -20.3943%
EditDistance 3043 2589 -14.9195%


Swift SVN r20327
2014-07-22 19:30:50 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
John McCall
c266b15293 Cache whether a type involves an archetype in the recursive
type properties.

Swift SVN r18773
2014-06-10 01:41:00 +00:00
Michael Gottesman
fc91eb68fa [sil-aa] Remove type classifier methods from SILType.
Swift SVN r18165
2014-05-16 03:04:17 +00:00
Michael Gottesman
2c84a0ac82 [sil-aa] Typed Based TBAA with all the necessary fixes.
This commit fixes a bunch of problems I found in TBAA. Some fun
examples:

1. We were not handling protocols correctly.
2. We were not handling enums correctly.
3. We were not handling builtins correctly all the time.
...
And much more.

I also added a fairly exhaustive test.

Additionally I checked the benchmarks and did not see any regressions.

rdar://16651852

Swift SVN r18148
2014-05-16 00:21:41 +00:00
Michael Gottesman
32dee228f8 [sil-aa] Change TBAA to use type oracle instructions instead of the raw types of instructions.
The reason that this is important is that we *ARE* allowing the stdlib
to perform certain types of type punning for efficiency implying we need
to have a type oracle instruction to have safety.

A type oracle instruction is an instruction which implies undefined behavior
unless its operand/result is of a certain type (allowing us to ignore that
possibility).

In a following commit I am going to go over and fix any problems in the
actual TBAA implementation and give all the various checks tests.

rdar://16651852

Swift SVN r18090
2014-05-15 00:59:55 +00:00
Michael Gottesman
834a38fdfe [sil-aa] Add support to SILAA for running various forms of Alias Analysis to enable testing the various AA separately.
This is conditionally compiled out without asserts on.

I am going to use this functionality to test basic-aa and tbaa
separately in different test files.

<rdar://problem/16651852>

Swift SVN r18075
2014-05-14 18:24:19 +00:00
Michael Gottesman
8ffc0f10a3 [sil-aa] AA::may{Read,Write,ReadOrWrite}FromMemory do not care about ref counts. Add a flag to ignore ref counts during such a query.
This is due to MayHaveSideEffects encompassing ref count effects and a
myriad of other effects. If/when we separate the two concepts (which is
cleaner IMHO), the flag will no longer be necessary.

Swift SVN r16807
2014-04-25 06:37:02 +00:00
Michael Gottesman
a75de1c9a5 [sil-aa] Teach AA::getMemoryBehavior about a bunch more instructions which do
not have their normal memory behavior if the value we are trying to find memory
behavior relative to does not alias their arguments.

Also cond_fail is inert from an AA perspective.

Swift SVN r16806
2014-04-25 06:37:01 +00:00
Michael Gottesman
9401b1b0f4 [sil-aa] Refactor memory behavior implementation to use a visitor instead of a large switch to make things more readable.
This is in preparation for increasing the amount of instructions handled
by memory behavior.

Swift SVN r16788
2014-04-25 00:52:02 +00:00
Michael Gottesman
20ef9c08fc [sil-aa] Globals are identified objects at compile time. <rdar://problem/16696826>.
Swift SVN r16694
2014-04-23 08:53:25 +00:00
John McCall
8681963bcb A couple of long-overdue renames.
Builtin.ObjectPointer -> Builtin.NativeObject
Builtin.ObjCPointer -> Builtin.UnknownObject

Swift SVN r16634
2014-04-22 00:17:08 +00:00
Michael Gottesman
b04b14e0fa Refactor isNonEscapingLocalObject/getUnderlying object into their own file ValueTracking.cpp.
This is because I need them in ARCAnalysis.cpp and from a modeling
perspective it is no longer just going to be used just in AA since they
are of larger functionality.

Swift SVN r16297
2014-04-14 04:44:53 +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
fd9a9b5881 SIL: Add a CopyBlockInst instruction.
This maps down to a _Block_copy call that gives us the result, which may be different from the original object, back.

Swift SVN r16042
2014-04-08 02:43:17 +00:00
Chris Lattner
afea47b621 rename "destroy_value" to "release_value", part of rdar://15889208.
Swift SVN r15777
2014-04-02 05:33:52 +00:00
Chris Lattner
6540423613 rename CopyValueInst -> RetainValueInst. The .sil syntax
isn't changed yet.


Swift SVN r15775
2014-04-02 05:11:31 +00:00
Michael Gottesman
62eb79eb7b [sil-aa] Change aggregateContainsRecord to compare CanonicalTypes instead of Types. One should never compare non-canonicalized types.
Swift SVN r15698
2014-03-31 22:57:01 +00:00
Joe Groff
584009d27e SIL: Remove copy_value's result.
We won't have any types where copying has an effect on the bit pattern (except for blocks, which need special handling anyway), and copy_value having a result makes optimizations more complex, so remove it.

Swift SVN r15640
2014-03-30 03:40:45 +00:00
Joe Groff
afd59130f0 SIL: Add a FixLifetime instruction.
This will be a signal to ARC optimization, RVO, and other lifetime-affecting optimizations that they should not shorten the lifetime of a value past a certain point. We need this for C pointer bridging. This adds the instruction, but does not add any knowledge of it to the ARC optimizers.

Swift SVN r15601
2014-03-29 02:50:34 +00:00
Nadav Rotem
722c5f8817 Reverse the boolean logic of the function to make it more readable. NFC.
Swift SVN r15488
2014-03-26 05:51:23 +00:00
Nadav Rotem
da6a9fe7b3 TBAA: Recurse into unbound generic types when analyzing nonimal types.
This allows us to inspect UnsafePointer<T> that does not store T anywhere.
This commit removes the retains and releases in RC4 again.



Swift SVN r15483
2014-03-26 05:19:16 +00:00
Nadav Rotem
35f00fd23a TBAA: Fix the type relationship between aggregate types by scanning the record types recursively.
Example: Float* may alias Point* because Point may contain a float.

This commit regresses RC4::swapByIndex.



Swift SVN r15477
2014-03-26 00:31:12 +00:00
Nadav Rotem
fe1e135413 Add more alias analysis TBAA rules.
These new rules remove all of the redundant retains and releases in RC4::swapByIndex.



Swift SVN r15383
2014-03-23 07:02:14 +00:00
Nadav Rotem
1bfa103362 Add a basic TBAA rule.
Swift SVN r15358
2014-03-22 01:12:09 +00:00
Doug Gregor
82c1ba2e29 Remove peer_method instruction; we're no longer using it.
Swift SVN r14599
2014-03-03 17:13:06 +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