Commit Graph

2864 Commits

Author SHA1 Message Date
John McCall
f524f3de69 [NFC] Support instructions that define multiple opened archetypes
I've also fixed this so that it should work on instructions that
define multiple values.  Someday we'll change all the open_existential
instructions to produce different values for the type dependency and
the value result; today is not that day, though.
2022-12-13 13:28:13 -05:00
swift-ci
8d9d5b643d Merge remote-tracking branch 'origin/main' into rebranch 2022-12-13 01:53:46 -08:00
eeckstein
cb6737269d Merge pull request #62480 from eeckstein/instruction-iteration
SIL: simplify deleting instructions while iterating over instructions.
2022-12-13 10:45:06 +01:00
swift-ci
da940cac92 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-12 17:33:41 -08:00
Andrew Trick
f9861ec9c0 Add APIs for terminator results that forward ownership.
Add TermInst::forwardedOperand.

Add SILArgument::forwardedTerminatorResultOperand. This API will be
moved into a proper TerminatorResult abstraction.

Remove getSingleTerminatorOperand, which could be misused because it's
not necessarilly forwarding ownership.

Remove the isTransformationTerminator API, which is not useful or well
defined.

Rewrite several instances of complex logic to handle block arguments
with the simple terminator result API. This defines away potential
bugs where we don't detect casts that perform implicit conversion.

Replace uses of the SILPhiArgument type and code that explicitly
handle block arguments. Control flow is irrelevant in these
situations. SILPhiArgument needs to be deleted ASAP. Instead, use
simple APIs like SILArgument::isTerminatorResult(). Eventually this
will be replaced by a TerminatorResult type.
2022-12-12 12:37:35 -08:00
Erik Eckstein
c180d1363e SIL: simplify deleting instruction while iterating over instructions.
Add `deletableInstructions()` and `reverseDeletableInstructions()` in SILBasicBlock.
It allows deleting instructions while iterating over all instructions of the block.
This is a replacement for `InstructionDeleter::updatingRange()`.
It's a simpler implementation than the existing `UpdatingListIterator` and `UpdatingInstructionIteratorRegistry`, because it just needs to keep the prev/next pointers for "deleted" instructions instead of the iterator-registration machinery.
It's also safer, because it doesn't require to delete instructions via a specific instance of an InstructionDeleter (which can be missed easily).
2022-12-12 19:08:54 +01:00
Erik Eckstein
2ca9a3b9ce SIL: fix APIs for (re)moving instructions
Instructions can only be moved and erased, but never _removed_ from a block.
2022-12-12 19:05:59 +01:00
swift-ci
328e716489 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-12 07:33:19 -08:00
nate-chandler
48f63c5055 Merge pull request #62502 from nate-chandler/remove-silvalue-getownershipkind
[NFC] Removed SILValue::getOwnershipKind.
2022-12-12 07:29:54 -08:00
nate-chandler
7768b005a7 Merge pull request #62501 from nate-chandler/remove-in-constant
[SIL] Removed Indirect_In_Constant convention.
2022-12-12 07:29:12 -08:00
nate-chandler
fe4949942d Merge pull request #62486 from nate-chandler/opaque-values/1/20221209
[AddressLowering] Handle store_borrow.
2022-12-12 07:28:19 -08:00
swift-ci
88a4e222f8 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-10 08:53:34 -08:00
Saleem Abdulrasool
77b5e135f0 Merge pull request #62385 from compnerd/isa-dead
AddressLowering: speculative tightening of assertion
2022-12-10 08:45:50 -08:00
Nate Chandler
8d8577e5b0 [SIL] Removed Indirect_In_Constant convention.
It is no different from @in.

Continue parse @in_constant in textual and serialized SIL, but just as
an alias for @in.
2022-12-09 21:54:00 -08:00
Nate Chandler
fff993a31b [NFC] Removed SILValue::getOwnershipKind.
It has been deprecated for awhile.
2022-12-09 18:30:10 -08:00
Nate Chandler
04471ffb46 [OSLogOpt] Fixed duplicated condition. 2022-12-09 16:11:29 -08:00
Nate Chandler
29067a5dc2 [AddressLowering] Handle store_borrow.
Thanks to the invariants of store_borrow, rewriting a store_borrow is a
simple matter of replacing its (non end_borrow) uses with uses of the
underlying address-only value whose use was stored.
2022-12-09 14:36:52 -08:00
Nate Chandler
f8f32a6be0 [NFC] AddressLowering: Alpha'd declaration. 2022-12-09 11:15:50 -08:00
swift-ci
5cd7bcfc35 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-09 07:13:43 -08:00
nate-chandler
d5e8625db9 Merge pull request #62442 from nate-chandler/opaque-values/1/20221201
[AddressLowering] Handle indirectly yielded values used outside of coroutine range.
2022-12-09 07:00:16 -08:00
Nate Chandler
867143d62d [AddressLowering] Soften assertion for end_borrows
When finding the PrunedLiveness on whose boundary end_borrows are to be
inserted, allow lifetime ending uses if they are end_borrows.  Such
end_borrows appear validly when an inner use is a nested begin_borrow.
2022-12-08 18:29:32 -08:00
Nate Chandler
e527d8bd21 [AddressLowering] Fix indirect coro yield handling
The begin_apply instruction introduces storage which is only valid until
the coroutine is ended via end_apply/abort_apply.  Previously,
AddressLowering assumed the memory was valid "as long as it needed to
be": either as an argument to the function being lowered (so valid for
the whole lifetime) or as a new alloc_stack (whose lifetime is
determined by AddressLowering itself).  The result was that the storage
made available by the begin_apply was used after the
end_apply/abort_apply when there were uses of [a copy of] [a projection
of] the yield after the end_apply/abort_apply.

Here, the behavior is fixed.  Now, the storage is used "as soon as
possible".  There are two cases:

(1) If an indirect value's ownership is transferred into the
caller (i.e. its convention is `@in` or `@in_constant`), the value is
`copy_addr [take]`n into caller-local storage when lowering the
begin_apply.

(2) If an indirect value's ownership is only lent to the caller (i.e.
its convention is `@in_guaranteed`), no equivalent operation could be
done: there's no `copy_addr [borrow]`; on the other hand, there's no
need to do it--uses of the value must have occurred within the
coroutine's range.  Instead, it's necessary to disable the store-copy
optimization in this case: storage must be allocated for a copy of [a
projection of] the yielded value.
2022-12-08 18:29:31 -08:00
swift-ci
5234d2f159 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-08 15:13:30 -08:00
Michael Gottesman
d1d3c1262e Merge pull request #62464 from gottesmm/pr-6d0c4626f8ea10597ecc6b876f1bbfd6432cd4db
[move-addr] Move Field Sensitive Pruned Liveness into its own header/cpp impl.
2022-12-08 15:07:25 -08:00
swift-ci
5b52213478 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-08 12:33:51 -08:00
nate-chandler
5b8cd585cc Merge pull request #62443 from nate-chandler/opaque-values/1/20221207
[AddressLowering] Handle builtins for resumes.
2022-12-08 12:24:40 -08:00
swift-ci
c0d8448914 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-08 10:55:25 -08:00
nate-chandler
b7822789b0 Merge pull request #62453 from nate-chandler/opaque-values/2/20221207
[AddressLowering] Omit dealloc_stack in dead ends.
2022-12-08 10:36:20 -08:00
Michael Gottesman
3f90afb901 [move-addr] Move Field Sensitive Pruned Liveness into its own header/cpp impl. 2022-12-08 10:29:48 -08:00
Nate Chandler
ba424ccf09 [AddressLowering] Omit dealloc_stack in dead ends.
It is valid for owned values not to be destroyed on paths terminating in
unreachable.  Similarly, it is valid for storage not to be deallocated
on paths terminating in unreachable.  However, it is _not_ valid for
storage to be deallocated before being deinitialized, even in paths
terminating in unreachable.  Consequently, when AddressLowering,
dealloc_stacks must not be created in dead-end blocks: because the input
OSSA may not destroy an owned value, the output may not deinitialize
owned storage; so a dealloc_stack in an unreachable block could dealloc
storage which was not deinitialized.
2022-12-07 18:12:24 -08:00
Nate Chandler
b6e6c20865 [AddressLowering] Handle builtins for resumes.
The builtins for resuming UnsafeContinuations traffic in generic values
and must be rewritten to use addresses instead of values.
2022-12-07 13:14:43 -08:00
swift-ci
296dde7d56 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-06 22:16:07 -08:00
Michael Gottesman
37396243a6 Delete dead function. NFC. 2022-12-06 19:22:42 -08:00
swift-ci
5386d75947 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-06 18:14:12 -08:00
Michael Gottesman
23759d5d3f Merge pull request #62423 from gottesmm/move-only-addr-cleanups
[move-only-addr] Misc refactorings/cleanups
2022-12-06 17:55:40 -08:00
Michael Gottesman
c7e18483ea [move-only-addr] Add some clarifying MARKs. 2022-12-06 13:27:37 -08:00
Michael Gottesman
1710f6f6d0 [move-only-addr] Refactor struct LivenessChecker into GlobalDataflow struct and clean it up a little bit to take summaries.
NFCI.
2022-12-06 13:27:25 -08:00
Michael Gottesman
7c2b72f9fa Delete dead code. 2022-12-06 13:11:08 -08:00
Michael Gottesman
1f48f50dcf [move-only-addr] Extract out multi-block liveness initialization into a helper function.
Just more refactoring in preparation for some fixes. NFCI.
2022-12-06 13:07:10 -08:00
Michael Gottesman
2327e77510 [move-only-addr] Refactor out the local dataflow block summary computation into a helper method that returns a summary.
Just refactoring further to make the code easier to understand. NFCI.
2022-12-06 12:52:35 -08:00
Michael Gottesman
b614dd33a4 [move-only] Clean up the local per-block dataflow computation to use a state structure with helpers.
This just allows me to sink busy code into helpers on the state making the
implementation easier to understand. It also gave me a good place to add
comments that will make it clearer what we are actually doing.

NFCI.
2022-12-06 12:25:34 -08:00
swift-ci
6b55c320e5 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-05 18:13:16 -08:00
Nate Chandler
693d6013d3 [AddressLowering] Shorten stack lifetimes.
During storage allocation, create all alloc_stacks at the front of the
function entry block, except those for opened existential types.  Do not
create any dealloc_stacks, even for opened existential types.

Then, after function rewriting, position the alloc_stacks according to
uses, except those for opened existential types.  This means allocating
in the block that's the least common ancestor of all uses. At this
point, create dealloc_stacks on the dominance frontier of the
alloc_stacks, even for allocations for opened existential types.

The behavior for opened existential types diverges from all others in
order to maintain SIL validity (as much as possible) while the pass
runs.  It would be invalid to create the alloc_stacks for opened
existential types at the front of the entry block because the type which
is opened is not yet available, but that type's opening must dominate
the corresponding alloc_stack.
2022-12-05 14:49:38 -08:00
Saleem Abdulrasool
df9c085c12 AddressLowering: speculative tightening of assertion
On Windows CI builds, we have observed a failure to build the Swift
Standard Library after 10/27 (first noticed on 11/11 snapshot due to
other failures).  The failure is an invalid `isa` cast where the
instance is a `nullptr`.  The SILPipeline suggests that the
SILOptimizer might be the one triggering the incorrect use of `isa`.
The only instance of `isa` introduced in that range in the
SILOptimizer/Mandatory region for that duration is this particular
instance.  Tighten the assertion to ensure that `oper->getUser()`
returns a non-`nullptr` value.

Thanks for @gwynne for helping narrow down the search area.
2022-12-03 10:39:57 -08:00
swift-ci
a6cb9711b7 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-29 18:14:57 -08:00
swift-ci
e9c3f84d4a Merge pull request #62303 from adrian-prantl/102296138
Use SILBuilderWithScope in the DefiniteInitialization pass
2022-11-29 18:13:55 -08:00
swift-ci
7fc7931558 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-29 17:14:04 -08:00
swift-ci
ec2d7fc847 Merge pull request #62198 from nate-chandler/opaque-values/3/20221118
[AddressLowering] Don't end_borrow trivial args.
2022-11-29 17:07:24 -08:00
Adrian Prantl
c4695d5861 Use SILBuilderWithScope in the DefiniteInitialization pass
DefiniteInitialization used a running SILBuilder to insert all instructions and
didn't consistently set the scope to a meaningful value. This patch replaces all
uses of the running Builder with ad-hoc instances of SILBuilderWithScope which
should capture the intention of the code better.

rdar://102296138
2022-11-29 13:19:16 -08:00
swift-ci
e39df5b422 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-29 10:34:25 -08:00