Commit Graph

1084 Commits

Author SHA1 Message Date
Andrew Trick
75f2f88bce Add AddressOwnershipLiveRange
A live range representing the ownership of addressible memory.

This live range represents the minimal guaranteed lifetime of the object being addressed. Uses of derived addresses
may be extended up to the ends of this scope without violating ownership.

.liveOut objects (@in_guaranteed, @out and globals) have no instruction range.

.local objects (alloc_stack, yield, @in, @inout) report the single live range of the full assignment that reaches
this address.

.owned values (boxes and references) simply report OSSA liveness.

.borrow values report each borrow scope's range. The effective live range is their intersection. A valid use must
lie within
2024-03-05 17:08:13 -08:00
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
e40fd35cc4 SwiftCompilerSources: add Value.nextInstruction 2024-03-05 17:08:13 -08:00
Andrew Trick
33ed895a7d SwiftCompilerSources: make BasicBlock hashable 2024-03-05 17:08:13 -08:00
Andrew Trick
d01d74e20c LifetimeDependenceDiagnostics: find the correct variable introducer. 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
5c956f7437 Review feedback; only rewrite access scopes when necessary 2024-03-05 17:08:13 -08:00
Andrew Trick
7dea051bf6 Review feedback; Builder.createEndAccess() 2024-03-05 17:08:13 -08:00
Andrew Trick
d1a75e725c LifetimeDependenceScopeFixup: handle non-dominated dependent uses. 2024-03-05 17:08:13 -08:00
Andrew Trick
1122cc445f LifetimeDependenceScopeFixup: fix handling of returned dependence
Only rewrite the mark_dependence to depend on the function argument when the
dependent value is actually returned.

Also, find all uses even if an escaping use is seen.
2024-03-05 17:08:13 -08:00
Andrew Trick
8aa1d91a2c LifetimeDependence: clarify log headers 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
Andrew Trick
28c1fdb96f SwiftCompilerSources: Add Instruction.endInstruction
To make the ScopedInstruction abstraction useful and formalize to use-points of scoped operations.

This is specifically for scoped operations that use their operands up to the end of their scope.

This is not for the many instructions that introduce scoped lifetimes. Allocations are not considered scoped
operations. Every owned value has a scoped lifetime just like an allocation, but the scope-ending instructions are not
considered use points.
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
Andrew Trick
7aab3c54ec Factor InstructionRange.beginningInstruction for use elsewhere. 2024-03-04 16:03:54 -08:00
Andrew Trick
d6d8323775 Add SingleInlineArray read/_modify accessors
For mutable access.
2024-03-04 10:17:13 -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
Holly Borla
2c6344f461 [SILOptimizer] Handle FunctionExtractIsolationInst in the mandatory passes. 2024-02-26 17:59:27 -08:00
Meghana Gupta
4fe0429705 Merge pull request #71880 from meg-gupta/ossasilcombine
Add silcombines for destructure_tuple and destructure_struct
2024-02-26 14:01:05 -08:00
Meghana Gupta
7508a90af0 Enable destructure_struct/destructure_tuple simplifications in silcombine 2024-02-26 10:58:08 -08:00
Andrew Trick
e3198ed38e Fix AccessUtils.swift to use the project_box reference root. 2024-02-26 00:20:46 -08:00
Andrew Trick
7574c1fede Fix AccessUtils Value.referenceRoot to handle ForwardingInstructions.
This fixes all analyses that use AccessUtils in the presence of new
forwarding instructions. This is also needed for consistency with the
C++ source base. And for general sanity.

Utilities that walk the use-def chain should never hard-code a list of
opcodes that happened to work with some specific pass. Passes should
never assume that a basic SIL utility handles specific SIL operations
a certain way. Instead, the utility needs to be defined in terms of
SIL semantics. In this case, the utility is supposed to handle all
instructions that semantically forward ownership of a reference.
2024-02-26 00:20:46 -08:00
Andrew Trick
56126e9db9 Fix LetPropertyLowering to correctly find mark_uninitialized uses. 2024-02-26 00:20:46 -08:00
Andrew Trick
a7e4e900c4 Fix LifetimeDependenceUtils to use OwnershipTransitionInstruction 2024-02-26 00:20:46 -08:00
Andrew Trick
760fa24d1e Add ForwardingInstruction.preservesIdentity.
Mirror isIdentityPreservingRefCase.

I don't know why this does not apply to boxes and existentials, but am convervatively staying consistent with the
current behavior.
2024-02-26 00:20:46 -08:00
Andrew Trick
0752ea5824 Add OwnershipTransitionInstruction.
These instructions carry lifetime dependence from a single operand to a single result. They are not forwarding
instructions because we use them to indicate the boundaries of a forwarded lifetime.
2024-02-26 00:12:07 -08:00
Andrew Trick
d7205edd70 Code formatting cleanup related to CopyingInstruction 2024-02-26 00:12:07 -08:00
Andrew Trick
f9a26d42d3 Make MoveOnlyWrapperToCopyableBoxInst a ConversionInstruction.
This appears to be an obvious oversight.
2024-02-25 10:29:15 -08:00
Andrew Trick
0b81392dff Code formatting cleanup related to ForwardingInstruction. 2024-02-25 10:29:15 -08:00
Andrew Trick
5fc50a0092 AddressUtils: refactor the findSingleInitializer API. 2024-02-25 10:29:15 -08:00
Andrew Trick
a3cbc28078 SwiftCompilerSources: Add enum BeginAccess.AccessKind
So we can switch over it.
2024-02-25 10:22:06 -08:00
eeckstein
d1961e1126 Merge pull request #71808 from eeckstein/global_async_function_pointers
Support statically initialized global async function pointers
2024-02-22 16:44:38 +01:00
Erik Eckstein
9aff04a65a Support statically initialized global async function pointers
rdar://123327436
2024-02-22 09:38:18 +01: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
c805f6cbd8 SwiftCompilerSources: refactor and fix forwarding instructions
* add ForwardingInstruction conformances to missing forwarding instruction classes
* move all the forwarding instruction conformance definitions into ForwardingInstructions.swift
* remove the default implementations of the requirements, so that every instruction needs to specify them
2024-02-22 07:12:11 +01:00
Erik Eckstein
68cc6c8780 SwiftCompilerSources: add all missing instruction classes
And require that all new instructions must be added and registered in SwiftCompilerSources as well.
2024-02-22 07:12:10 +01:00
Erik Eckstein
aadb0598c9 SIL: remove the var operands requirement from UnaryInstruction
It's not needed because UnaryInstruction is "derived" from Instruction which has this property.
2024-02-22 07:12:10 +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
bc0f60afc9 LifetimeDependenceDiagnostics: cleanup. remove unused code. 2024-02-13 20:57:02 -08:00
Meghana Gupta
75bd5b08dd Add LifetimeDependenceScopeFixup pass 2024-02-13 16:52:01 -08:00
Meghana Gupta
14578db701 Bridge createEndAccess 2024-02-13 00:12:23 -08:00