Commit Graph

361 Commits

Author SHA1 Message Date
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
Andrew Trick
a9126d4fd0 Add OwnershipLiveness.swift. Core OSSA APIs.
This is what you need to correctly analyze OSSA.

- computeLinearLiveness

- computeInteriorLiveness

- InteriorUseVisitor

- OwnershipUseVisitor

- LivenessBoundary

Along with BorrowUtils.swift, all of our OSSA transformations are
built on top of these fundamentals. With these APIs, we can build
anything OSSA-related in SwiftCompilerSources. These utilities are
immediately needed for borrowed arguments and lifetime dependence. In
the near future, we can also use them to complete OSSA lifetimes and
*correctly* fixup OSSA after transformation without introducing lots
of copies and creating lots of incorrect corner cases.
2024-01-17 08:37:14 -08:00
Andrew Trick
8a2ae0b23c BorrowIntroducer unit tests 2024-01-17 08:37:14 -08:00
Andrew Trick
1646a667c1 Add BorrowUtils: OSSA infrastructure for borrow scopes.
Key APIs necessary for using OSSA.

- BorrowingInstruction

- BeginBorrowValue

- scopeEndingOperands

- BorrowIntroducers

- EnclosingValues

- innerAdjacentPhis

These need to be complete to be correct.
2024-01-17 08:37:14 -08:00
Andrew Trick
2cac9fbd4c ForwardingUtils.swift cleanup. Make the API easier to extend. 2024-01-17 08:37:14 -08:00
Andrew Trick
5759d428e2 ForwardingUtils comment formatting.
Format comments so they are readable on github and 80-col tools.
2024-01-17 08:37:14 -08:00
Meghana Gupta
5d2454f3e3 Merge pull request #68180 from meg-gupta/lowerb4inline
Lower OwnershipModelEliminator to just before inlining
2024-01-10 13:53:34 -08:00
Erik Eckstein
3229749257 SwiftCompilerSources: move some private utilities of passes into OptUtils
* `var Function.initializedGlobal`
* `func getGlobalInitialization`

and add `var CollectionLikeSequence.singleElement`
2024-01-10 09:34:01 +01:00
Meghana Gupta
9dbf7ccec2 Address review comments from #68150 2024-01-05 13:20:52 -08:00
Andrew Trick
2128c21106 Migrate SwiftCompilerSources to FunctionConvention.
Layers:
- FunctionConvention: AST FunctionType: results, parameters
- ArgumentConventions: SIL function arguments
- ApplyOperandConventions: applied operands

The meaning of an integer index is determined by the collection
type. All the mapping between the various indices (results,
parameters, SIL argument, applied arguments) is restricted to the
collection type that owns that mapping. Remove the concept of a
"caller argument index".
2024-01-03 12:24:50 -08:00
Andrew Trick
7dc3d72483 Merge pull request #70485 from atrick/bridge-util
[NFC] Bridging and utilities for SwiftCompilerSources required by lifetime dependence utilities.
2023-12-19 13:07:45 -08:00
Andrew Trick
c1f0f06907 [SIL] Add FunctionConvention.swift
Bridge information about the AST function type that does not require a
SIL function body.

Support querying the function type's ResultInfo.
2023-12-18 09:43:18 -08:00