Commit Graph

109 Commits

Author SHA1 Message Date
Nadav Rotem
34238e5701 [AliasAnalysis] Remove duplicate code in TBAA.
We have two places in TBAA that uses the class hierarchy to disambiguate types.
This commit removes one of the checks (the one that looked more ad-hock) and
keeps the check in line 540 that uses Type.isSuperclassOf.
2015-11-24 10:13:45 -08:00
Nadav Rotem
a07da67d6f [AliasAnalysis] Cache the results of TBAA.
Add a cache for calls to typesMayAlias. We never invalidate this cache
because type aliasing relations never change.

The hit rate of this cache is really high.
2015-11-23 22:20:37 -08:00
Nadav Rotem
3d35b031e2 [AliasAnalysis] Document and cleanup referenceTypeTBAAMayAlias. 2015-11-23 15:18:59 -08:00
Nadav Rotem
89a8103497 [AliasAnalysis] Minor cleanup. 2015-11-23 15:06:57 -08:00
Nadav Rotem
971aa239e4 [AliasAnalysis] Remove the AliasAnalysis Cache.
The AliasAnalysis is unsafe. When we delete instructions we don't have a good
mechanism for invalidating the cache and we don't want instructions to
explicitly invalidate AliasAnalysis after every deletion of an instruction.

Morever, the alias analysis cache _always_ misses. Removing the cache did not
change the build time of the standard library at all.
2015-11-22 19:38:37 -08:00
Nadav Rotem
2276a93917 [AliasAnalysis] Clean some of the docs.
Move some comments from the definition to the decleration and tidy
some of the comments.
2015-11-22 19:37:59 -08:00
Nadav Rotem
08d75ca865 Abbreviate AliasResult. 2015-11-22 19:37:44 -08:00
Ted Kremenek
3e779dbc66 Revert "Revert "Safely implement strict TBAA rules.""
We believe the failure now may be in the setup of the test harness.
Re-applying this change, since the tests passed in our other
configurations.
2015-11-20 15:08:58 -08:00
Ted Kremenek
ddc9c52d5a Revert "Safely implement strict TBAA rules."
This reverts commit 3d5c4969a0.

This is breaking the iOS device tests.
2015-11-20 14:51:25 -08:00
Andrew Trick
3d5c4969a0 Safely implement strict TBAA rules.
This fixes type punning issues with unsafeBitCast.

The optimizer is still too aggressive with UnsafePointer. To fix that,
we first need an explicit API for circumventing type safety
(rdar://23406272).

I should be able to fix the following regressions by migrating the
stdlib away from unsafeBitCast to unsafeReferenceCast (~2 weeks).

Slowdowns:
|.Benchmark.................|..Before.|...After.|.Speedup|
|.ArrayInClass..............|...49.00.|...78.00.|.-37.2%.|
|.Sim2DArray................|..471.00.|..549.00.|.-14.2%.|
|.PrimeNum..................|.1876.00.|.1980.00.|..-5.3%.|

Speedups:
|.Benchmark.................|..Before.|...After.|.Speedup|
|.HeapSort..................|.2962.00.|.2663.00.|..11.2%.|
|.StdlibSort................|.2672.00.|.2537.00.|...5.3%.|
2015-11-20 09:59:56 -08:00
Andrew Trick
2016e3323b Revert today's changes to SIL AliasAnalysis.
This series of commits is reverted because it introduces risk. This type
of change requires design discussion and thorough unit testing.

Revert "Refactor in alias analysis. NFC"

This reverts commit 3390a584b8.

Revert "Update SILArgument alias analysis to make use of the new alias() interface"

This reverts commit 5940fcca78.

Revert "Clean up uneeded SIL in a LIT test"

This reverts commit 81ebb5667f.

Revert "Fix LIT test in basic-aa."

This reverts commit a55340394f.

Revert "Improve comments in alias analysis"

This reverts commit 44ddc5b4df.

Revert "Implement SILArgument and select_enum handling for alias analysis"

This reverts commit 23c257938f.
2015-11-19 16:53:24 -08:00
Xin Tong
3390a584b8 Refactor in alias analysis. NFC 2015-11-19 13:58:47 -08:00
Xin Tong
5940fcca78 Update SILArgument alias analysis to make use of the new alias() interface 2015-11-19 13:42:57 -08:00
Xin Tong
23c257938f Implement SILArgument and select_enum handling for alias analysis 2015-11-19 09:22:00 -08:00
Roman Levenstein
46fda83a51 [AliasAnalysis] Don't cache the results between queries.
The cache is using SILValues as keys and such key would contain dangling pointers after the instruction corresponding to a given SILValue is erased.
Therefore, the cache needs to be invalidated between queries. It still makes sense to use the cache during queries, because sometimes queries may be recursive and pretty expensive to compute. It is safe to use  caching during the query, because no instructions are being erased while processing it.

The removal of the cache does not seem to affect compile times in a negative way.
2015-11-18 18:14:29 -08:00
Xin Tong
95a328d5d4 [AA] Use isSuperclassOf to determine whether 2 SILTypes share parent-child relationship. NFC. 2015-11-11 11:20:24 -08:00
Xin Tong
ac980f263c Enhancing type based alias analysis for 2 reference types with disjoint hierarchies.
rdar://22806515
2015-11-04 14:56:29 -08:00
Michael Gottesman
39aeac882b Refactor MemoryBehavior into its own file from AliasAnalysis.cpp.
This code is self contained was almost 1/2 of all of the code in
AliasAnalysis.cpp. This combined with the fact that we are most likely going to
add more code suggests that it should be refactored out.

Swift SVN r32284
2015-09-28 22:26:01 +00:00
Xin Tong
abe92d52cf Improve comment for alloc_stack around ARC releases
Swift SVN r32235
2015-09-25 18:23:21 +00:00
Erik Eckstein
4bac733603 AliasAnalysis: code reformatting and fixing comments.
Thanks, Michael, for the feedback.



Swift SVN r32206
2015-09-24 20:03:19 +00:00
Xin Tong
69af6931f7 More accurate side effect for StrongRelease, UnownedRelease and
ReleaseValue, rdar://22570613

Swift SVN r32201
2015-09-24 17:41:01 +00:00
Erik Eckstein
7122a825f2 Improve alias analysis for projections.
Now we get a no-alias for addresses of different fields, even if the base pointer is not known.



Swift SVN r32192
2015-09-24 00:25:32 +00:00
Erik Eckstein
a0f670b8bd Add getMemBehavior utility functions to SideEffectAnalysis.
Swift SVN r32169
2015-09-23 00:26:40 +00:00
Erik Eckstein
62b5490d68 Reapply r31960: Use side effect analysis in alias analysis.
This improves alias analysis results when dealing with function calls.
All clients of the alias analysis (like load-store opts, etc.) will benefit from this.

Reapplying again as rdar://problem/22709812 is resolved.



Swift SVN r32022
2015-09-17 00:14:10 +00:00
Arnold Schwaighofer
f805577738 Revert "Use side effect analysis in alias analysis."
This reverts commit r31960.

It triggers breakage on a build bot.

rdar://22709812

Swift SVN r31980
2015-09-15 23:37:53 +00:00
Erik Eckstein
253d56cbdf Use side effect analysis in alias analysis.
This improves alias analysis results when dealing with function calls.
All clients of the alias analysis (like load-store opts, etc.) will benefit from this.



Swift SVN r31960
2015-09-15 17:37:42 +00:00
Erik Eckstein
b468f9f339 Add a way that SILAnalysis can retrieve (and store) other analysis which they depend on.
So far this was done by directly calling PM->getAnalysis() in create*Analysis().
But this required a correct order of analysis definitions in Analysis.def.



Swift SVN r31941
2015-09-14 22:34:36 +00:00
Erik Eckstein
06bfdbf131 Add missing "static" and comment.
Swift SVN r31606
2015-09-01 17:48:26 +00:00
Erik Eckstein
c6c9b26dc9 AliasAnalysis: Corretly handle the case of two global_addr referencing the same global.
Swift SVN r31605
2015-09-01 17:43:39 +00:00
Michael Gottesman
96999655c0 Move option out of #endif so we don't break release no assert builds.
Swift SVN r31553
2015-08-28 03:03:50 +00:00
Michael Gottesman
9a51543af7 [aa] Add an option -cache-aa-results that turns off caching of AA results.
This is useful when attempting to debug AA.

Swift SVN r31552
2015-08-28 03:01:39 +00:00
Michael Gottesman
0276d86694 Add Analysis.def to allow for metaprogramming with Analysis names.
This allows one by editing one place to create an Analysis kind and ensure that
your analysis is properly registered in all of the relevant places for use with
swift/sil-opt.

If we add tools like a sil bugpoint, this will make it easy to add analysis
without having to know about all of these locations.

It also standardizes the create***Analysis API to take a SILModule and a
SILPassManager. All passes take in a SILModule and some take in a
SILPassManager. By standardizing the API and in the cases where SILPassManager
is not used, just making it a dead argument enables metaprogramming.

Swift SVN r31420
2015-08-23 19:31:27 +00:00
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