Commit Graph

372 Commits

Author SHA1 Message Date
Andrew Trick
e84bcf520f Add computeBorrowLiveRange
Compute the live range for the borrow scopes of a guaranteed value. This returns a separate instruction range for
each of the value's borrow introducers. Unioning those ranges would be incorrect. We typically want their
intersection.
2024-03-05 17:08:13 -08:00
Andrew Trick
73f7f8f28a Add NonEscapingClosureDefUseWalker
To find all effective applications of partial_apply [on-stack].
2024-03-05 17:08:13 -08:00
Andrew Trick
a3fe978cc4 LifetimeDependenceUtils: handle borrowed ProjectBox 2024-03-05 17:08:13 -08:00
Andrew Trick
ef940c5297 Redesign gatherBorrowIntroducers to return BeginBorrowValues.
This avoids a lot of confusion because the callers expect this type. Fixing it just required some redundancy and
bridging in the EnclosigValues implementation.
2024-03-05 17:08:13 -08:00
Andrew Trick
a0c85be52c OwnershipLiveness: handle ProjectBox like an interior pointer. 2024-03-05 17:08:13 -08:00
Alejandro Alonso
1752b48a78 Merge pull request #71997 from Azoy/fix-zero-init-escape
[EscapeAnalysis] Handle atomic instructions in escape analysis
2024-03-05 13:44:46 -08:00
Alejandro Alonso
254e4f041f Handle atomic instructions in escape analysis
Split atomic loads/stores

no more guard

invert condition
2024-03-05 08:32:51 -08:00
cui fliter
127077b3aa chore: fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-05 17:23:22 +08:00
Erik Eckstein
8137adf89e SwiftCompilerSources: support Undef.parentFunction and PlaceholderValue.parentFunction
After support in the C++ SIL, we can implement parentFunction for those values in swift, too.
It simplifies a few things.
2024-03-01 09:07:12 +01:00
Michael Gottesman
11f0ff6e32 [sil] Ensure that all SILValues have a parent function by making it so that SILUndef is uniqued at the function instead of module level.
For years, optimizer engineers have been hitting a common bug caused by passes
assuming all SILValues have a parent function only to be surprised by SILUndef.
Generally we see SILUndef not that often so we see this come up later in
testing. This patch eliminates that problem by making SILUndef uniqued at the
function level instead of the module level. This ensures that it makes sense for
SILUndef to have a parent function, eliminating this possibility since we can
define an API to get its parent function.

rdar://123484595
2024-02-27 13:14:47 -08:00
Andrew Trick
a7e4e900c4 Fix LifetimeDependenceUtils to use OwnershipTransitionInstruction 2024-02-26 00:20:46 -08:00
Andrew Trick
5fc50a0092 AddressUtils: refactor the findSingleInitializer API. 2024-02-25 10:29:15 -08:00
Erik Eckstein
a13a6e0bf7 SIL: verify forwarding conformances
Verify that the C++ view of forwarding instructions agrees with the swift ForwardInstruction conformances.
2024-02-22 07:12:11 +01:00
Erik Eckstein
71fcae7fe8 SwiftCompilerSources: add the ability to implement SIL verification in swift 2024-02-22 07:12:10 +01:00
Meghana Gupta
12ac8042ab Handle YieldInst in LifetimeDependenceUtils 2024-02-19 15:28:04 -08:00
Andrew Trick
41043948c1 LifetimeDependenceDiagnostics: enable mutably borrowed lifetimes.
This allows basic prototyping. A separate analysis will ensure no
mutation of the original value during the borrow.
2024-02-15 02:39:34 -08:00
Andrew Trick
68037faa61 LifetimeDependenceScopeFixup: handle nested access
After extending access scopes, rewrite the mark_depenendence to be on
the outermost scope.
2024-02-13 22:22:28 -08:00
Andrew Trick
f0b04004ff LifetimeDepenenceUtils; improve VariableIntroducerUseDefWalker
Stop at formal access to a mutable variable.
2024-02-13 20:57:02 -08:00
Andrew Trick
c440cca939 Merge pull request #71570 from atrick/lifetime-inherit
LifetimeDependenceInsertion: do not emit inherited dependencies.
2024-02-12 23:02:14 -08:00
eeckstein
77cd7b5e87 Merge pull request #71554 from eeckstein/fix-escape-utils
EscapeUtils: fix escape result in case an address is stored
2024-02-13 07:13:51 +01:00
Andrew Trick
1cdf9d56ac LifetimeDefUseWalker handles inherited dependencies.
This is needed when we don't insert mark_dependence.
2024-02-12 20:05:24 -08:00
Andrew Trick
2e7c29cdf5 Restrict findSingleInitializer @out arguments.
The client should handle @in/@inout arguments differently.
2024-02-12 20:03:38 -08:00
Andrew Trick
c4eab6a54a Merge pull request #71266 from atrick/lifetime-insertion
Add the LifetimeDependenceInsertion pass.
2024-02-12 13:07:03 -08:00
Nate Chandler
f9ee089c04 [Test] Added troubleshooting note. 2024-02-12 10:23:13 -08:00
Andrew Trick
af39b0fb1f LifetimeDependenceUtils improvements
Improve noescape function handling. Use the mayEscape API.

Improve handling of @_unsafeNonescapableResult.

Improve handling of initialized scopes. Use findSingleInitializer.
2024-02-12 09:57:14 -08:00
Andrew Trick
ac457abab9 LifetimeDependenceUseDefWalker: track the owner of the value. 2024-02-12 09:57:14 -08:00
Andrew Trick
b08f2dedf1 Add AccessBase.findSingleInitializer 2024-02-12 09:57:14 -08:00
Andrew Trick
63413916a1 LifetimeDependenceDiagnostics; handle @_unsafeNonescapableResult. 2024-02-12 09:57:14 -08:00
Andrew Trick
8b24382494 SwiftCompilerSources: cleanup and extend ArgumentConventions
Provide APIs needed by lifetime dependence diagnostics, namely LifetimeDependenceConvention.

Reorganize the APIs so it's easy to find related functionality which
API is responsible for which functionality.

Remove the originalFunctionConvention complexity. It is no longer
needed for lifetime dependence inference, and generally should be
avoided in SIL.

Add some placeholder FIXMEs because this not a good PR in which to
change existing functionality.
2024-02-12 09:57:14 -08:00
Andrew Trick
15fef6868c BorrowUtils: add a comment 2024-02-12 09:57:14 -08:00
Andrew Trick
f713587aa5 Fix OSSA support for mark_dependence [nonescaping]
Handle escapes to function results.
2024-02-12 09:57:14 -08:00
Erik Eckstein
abd6ce0c9d EscapeUtils: fix escape result in case an address is stored
This unusual situation can happen if an address is converted to a raw pointer and that pointer is stored to a memory location.
In this case the walkers need to follow load instructions even if the visitor and current projection path don't say so.

Fixes a miscompile
rdar://122805546
2024-02-12 17:56:09 +01:00
Erik Eckstein
7fb4fc0f36 MandatoryPerformanceOptimizations: fix the linkage of function-signature-specialized functions
We need to keep the original linkage because it would be illegal to call a shared not-serialized function from a serialized function.

Also, rename the API to create the specialized function.
2024-02-02 07:27:38 +01:00
Erik Eckstein
bd7db677ed MandatoryPerformanceOptimizations: perform function signature optimization to remove metatype arguments
Generic specialization already takes care of removing metatype arguments of generic functions.
But sometimes non-generic functions have metatype arguments which must be removed.
We need handle this case with a function signature optimization.

This enables, for example, to use `OptionSet` in embedded swift.

rdar://121206953
2024-01-31 17:16:18 +01:00
Andrew Trick
ddceffaf3b LifetimeDependenceDiagnostics pass
Initial diagnostic pass to enforce ~Escapable types.
2024-01-30 11:45:55 -08:00
Andrew Trick
25cff623ab Improve LifetimeDependenceUtils 2024-01-30 08:38:57 -08:00
Andrew Trick
17319fa843 Improve the AddressUtils and OwnershipLiveness APIs 2024-01-30 08:38:57 -08:00
Andrew Trick
800fa167a9 ForwardingUtils; minor cleanup 2024-01-30 08:38:57 -08:00
Andrew Trick
2ef870a52b Add LifetimeDependence utilities 2024-01-22 23:57:03 -08:00
Andrew Trick
37171e698a Handle mark_dependence [nonescaping] like a borrowing instruction. 2024-01-22 23:57:03 -08:00
Andrew Trick
d663924eb0 Rewrite OwnershipUtils
For AddressUtils and LifetimeDepenendenceUtils.
2024-01-22 23:55:50 -08:00
Andrew Trick
3f8a35e64f ForwardingUtils comments and cleanup. 2024-01-22 23:55:29 -08:00
Andrew Trick
3bf7e715e7 Add AddressUtils.swift 2024-01-22 23:42:54 -08:00
Andrew Trick
8341b73b8c Update OwnershipLiveness comments for code review. 2024-01-17 09:07:02 -08:00
Andrew Trick
b6b45f0701 Rename AddressUseVisitor to AddressLifetimeDefUseWalker. 2024-01-17 08:37:14 -08:00
Andrew Trick
fa27b4ba02 Reorder code in OwnershipUtils.swift.
To occur in the order that people will likely want to read.
2024-01-17 08:37:14 -08:00
Andrew Trick
196ae17405 Add a reborrow cache to EnclosingValues.
Along with motivating unit tests.
2024-01-17 08:37:14 -08:00
Andrew Trick
c10c545cbe OwnershipUtils review feedback: code formatting. 2024-01-17 08:37:14 -08:00
Andrew Trick
d445754e6f OwnershipUtils review feedback: Comments and examples. 2024-01-17 08:37:14 -08:00
Andrew Trick
9a822b75a1 AddressUseVisitor 2024-01-17 08:37:14 -08:00