Commit Graph

1065 Commits

Author SHA1 Message Date
Michael Gottesman
59c8cff917 [borrowing] Add support for borrowing/consuming copyable types to be a noimplicitcopy type.
rdar://108383660
2023-06-06 18:12:29 -04:00
Michael Gottesman
70ab38d9da [move-only] Add a new instruction: moveonlywrapper_to_copyable_box.
I am going to use this to unwrap ${ @moveOnly T } so that I can pass it to
partial_apply that expect a ${ T }
2023-06-06 14:26:22 -04:00
Michael Gottesman
611e6760f5 [borrowing/consuming] Add a new instruction called copyable_to_moveonlywrapper_addr.
Just the $*T -> $*@moveOnly T variant for addresses. Unlike the object version
this acts like a cast rather than something that provides semantics from the
frontend to the optimizer.
2023-06-06 12:42:23 -04:00
Michael Gottesman
43f42e2c04 [borrowing/consuming] Add new instruction: moveonlywrapper_to_copyable_addr.
The reason why I am using a different instruction for addresses and objects here
is that the object checker doesnt have to deal with things like initialization.
2023-06-06 12:42:23 -04:00
Andrew Trick
521f0ffc9e [move-only] Verify drop_deinit
drop_deinit only exists in ownership SIL. Remove IRGen support.

A drop_deinit can only ever be destroyed or destructured.

A destructure of a struct-with-deinit requires a drop_deinit operand.
2023-06-06 09:17:53 -07:00
Nate Chandler
efca4e57c8 [SIL] Added on-stack pack metadata marker insts.
The new alloc_pack_metadata and dealloc_pack_metadata are inserted as
part of IRGen lowering.  The former indicates that the next instruction
might result in on-stack pack metadata being emitted.  The latter
indicates that this is the position at which metadata emitted on behalf
of its operand should be cleaned up.
2023-06-05 08:11:28 -07:00
Nate Chandler
ee3cbde8fe [SIL] computeDominatedBoundaryBlocks on non-OSSA.
The algorithm requires no critical edges, but that doesn't mean
require ownership.  Remove the assert to allow the utility to be called
from code where the caller has manually split edges.

In the fullness of time, there should no passes should introduce
critical edges.
2023-06-05 08:11:28 -07:00
Andrew Trick
af49f62d63 Fix drop_deinit side effects.
rdar://109863801 ([move-only] DCE removes drop_deinit, so user-defined
deinitializers call themselves recursively at -O)
2023-06-01 09:46:59 -07:00
Michael Gottesman
b49fccd986 Merge pull request #66065 from gottesmm/pr-415aafa0f5636321e5435cb5f9c8bb95a8138613
[move-only] Fix a thinko in FieldSensitivePrunedLiveBlocks::updateForUse
2023-05-23 10:08:29 -07:00
Michael Gottesman
5bef851dfa [move-only] Fix a thinko in FieldSensitivePrunedLiveBlocks::updateForUse.
I think this was a mistake from when I changed implementations to use pure
scalar bit processing rather than processing all at once. Instead of just
updating the internal found resulting uses array, we were appending to it.

Some notes:

1. This actually did not break anything semantically in the move checker since
we do not use this array in the caller in anyway. We just use it internally in
the routine to first lookup the current state which we then process in the
routine. That being said, this API is written such that a user /could/ do that
and we want to allow for users to be able to do that so that we match what
PrunedLiveness does.

2. This could cause memory corruption due to iterator invalidation if by
appending we caused the SmallVector to reallocate as we iterated over the
array.

So to fix this I did the following:

a. I changed the push_back to be an assignment.
b. I removed llvm::enumerate just out of paranoia if the assignment could
   potentially cause iterator invalidation.

The given test exercises this code path and with the old behavior would crash
with asan or guard malloc.

rdar://109673338
2023-05-22 15:02:00 -07:00
Joe Groff
51f75c99a4 MoveOnlyAddressChecker: Reintroduce debug info for variables after reassignment.
After a value is consumed, we emit a `debug_value undef` to indicate that the
variable value is no longer valid to the debugger. However, once a value is
reassigned, it becomes valid again, so emit a `debug_value %original_address` to
reassociate the variable with the valid memory location. rdar://109218404
2023-05-18 15:08:59 -07:00
Meghana Gupta
1dc713e2f7 Add new flags "reborrow" and "escaping" to SILArgument.
"reborrow" flag on the SILArgument avoids transitive walk over the phi operandsi
to determine if it is a reborrow in multiple utilities.
SIL transforms must keep the flag up-to-date by calling SILArgument::setReborrow.
SILVerifier checks to ensure the flag is not invalidated.

Currently "escaping" is not used anywhere.
2023-05-11 12:31:37 -07:00
Erik Eckstein
e95c6425f2 Swift SIL: add some APIs for global variables 2023-05-08 21:23:36 +02:00
nate-chandler
2984f0a236 Merge pull request #65417 from nate-chandler/rdar108514447
[SemanticARCOpts] Promote moved load [copy]s to load_borrows.
2023-04-27 06:59:02 -07:00
Nate Chandler
b686e81085 [OwnershipUtils] Add move as OwnedValueIntroducer. 2023-04-25 11:37:30 -07:00
Michael Gottesman
c577055100 [move-only] Instead of using AccessUseVisitor to visit addresses use TransitiveAddressVisitor.
This makes it so that the move address checker is not dependent on starting the
traversal at a base object. I also included verifier checks that the API can
visit all address uses for:

1. project_box.
2. alloc_stack.
3. ref_element_addr.
4. ref_tail_addr.
5. global_addr_inst.

this is because this visitor is now apart of the SIL API definition as being
able to enumerate /all/ addresses derived from a specific chosen address value.

This is a refactoring NFCI change.

rdar://108510644
2023-04-25 10:51:03 -07:00
nate-chandler
28bbbd5614 Merge pull request #65114 from nate-chandler/nfc/20230412/2/delete-duplicate-api
[SIL] NFC: Removed visitBorrowIntroducingUserResults.
2023-04-24 15:20:16 -07:00
Meghana Gupta
3d75abc570 Add an option to force boundary completion of lexical values 2023-04-21 22:41:22 -07:00
nate-chandler
c972a9337d Merge pull request #65309 from nate-chandler/rdar98542123
[SIL] Accesses to globals are deinit barriers.
2023-04-21 07:02:40 -07:00
Nate Chandler
5b6c1d6660 [SIL] Accesses to globals are deinit barriers.
Accesses to globals can't be reordered with deinits since deinits could
read such globals.

rdar://98542123
2023-04-20 18:02:41 -07:00
Nate Chandler
c40f7c3d0a [OwnershipUtils] Undef isn't introduced/enclosed.
Previously, calling `visitEnclosingDefs` or `visitBorrowIntroducers`
would crash if the `SILValue` argument were an instance of `SILUndef`
because both instantiate a `::FindEnclosingDefs` with the the result of
of calling `getFunction()` on that argument and `::FindEnclosingDefs` in
turn uses that result to create a `ValueSet`; but
`SILUndef::getFunction` returns `nullptr`, which is illegal to use as
the function for a `ValueSet`(or any other data structure relying on
`NodeBits`).

If the function specified as a separate argument, no values would be
visited and `true` would be returned.  Instead of burdening the API with
a separate argument, check for `SILUndef` up front and return `true`.
2023-04-19 13:57:59 -07:00
swift-ci
54f18b0848 Merge pull request #65181 from nate-chandler/rdar108043268
[MemAccessUtils] Handle debug_step in visitAccessedAddress.
2023-04-14 09:36:14 -07:00
Nate Chandler
9d3722fdb9 [MemAccessUtils] Add inst to visitAccessedAddress.
The debug_step returns true for mayReadOrWriteMemory so it has to be
handled there.

rdar://108043268
2023-04-14 07:23:29 -07:00
Meghana Gupta
aace4599f0 Merge pull request #65074 from meg-gupta/completelifetimefixes
Fixes to utilities used by OSSALifetimeCompletion
2023-04-13 13:22:37 -04:00
Michael Gottesman
94fb5ce2f9 [move-only] Treat empty structs as if they have a single element.
rdar://104395115
2023-04-12 20:56:31 -07:00
Meghana Gupta
264d86d26c Implement InteriorLivenessVisitor::handleInnerBorrow for all BorrowingOperand kinds
Not all BorrowingOperand introduce a BorrowedValue. Add a new api to get the defining value
for use in InteriorLivenessVisitor::handleInnerBorrow.
2023-04-12 14:42:23 -07:00
Nate Chandler
b1ccb59f01 [SIL] NFC: Removed visitBorrowIntroUserResults.
It's equivalent to getBorrowIntroducingUserResult except that it's less
convenient to use.  There's only ever one result, so there's no need for
a visitor.  Updated all users to call getBorrowIntroducingUserResult
instead.
2023-04-12 13:41:42 -07:00
Nate Chandler
6a5330b1d7 [SIL] NFC: Duplicated assertions.
Added the assertions from visitBorrowIntroducingUserResults to
getBorrowIntroducingUserResult.  In preparation for deleting the former
in favor of the latter.
2023-04-12 13:41:31 -07:00
Nate Chandler
0fceb33905 [SIL] NFC: Marked function const.
Make it available on const instances.
2023-04-12 13:29:05 -07:00
Erik Eckstein
7d70a70acf SIL: add the drop_deinit instruction
his instruction is a marker for a following destroy instruction to suppress the call of the move-only type's deinitializer.
2023-04-11 10:25:48 +02:00
Meghana Gupta
8346eb3199 Fix dead end block collection while completing lexical lifetimes
A dead end block can be visited multiple times on each of its
predecessors path. Use BasicBlockWorklist::pushIfNotVisited api for insertion.
2023-04-06 15:47:32 -07:00
Andrew Trick
c9eb1aea91 MultiDefPrunedLiveness: add support for arbitrary uses/defs.
This now supports liveness holes within blocks where previously we
expected a phi def.

PrunedLiveness is streamlined for SSA liveness where we expect the
defs and uses to be related in the SSA def-use graph.
MultiDefPrunedLiveness was added on top of SSAPrunedLivenes to handle
extended SSA liveness that occurs with phis, but are still connected
in the def-use graph. Recently MultiDefPrunedLiveness was repurposed
for liveness of addressible storage. This means that we can now have
uses before defs in the same block without a corresponding phi.

Fortunately, handling this case is a straightforward extension of
MultiDefPrunedLiveness that does not complicate or penalize the
streamlined SSA case.
2023-04-04 10:22:32 -07:00
Andrew Trick
d44c7f3b99 [NFC] Move the updateForUse API into PrunedliveRange
PrunedLiveness only knows about the live blocks and uses.

The PrunedLiveRange subclass is now responsible for updating liveness
based on both the defs and uses. This is in preparation for handling
non-SSA liveness when uses occur before the first def.
2023-04-04 10:22:32 -07:00
Andrew Trick
54d40822f8 Fix a comment typo 2023-04-04 10:22:32 -07:00
Andrew Trick
927d526ac9 silence a noasserts warning 2023-04-04 10:22:32 -07:00
Slava Pestov
3c4c72dcb8 SILOptimizer: Teach visitAccessedAddress() about pack instructions 2023-03-31 22:18:09 -04:00
swift-ci
9807267e02 Merge pull request #64708 from meg-gupta/fixinfinite
Fix infinite loop in the new hasPointerEscape(SILValue) api
2023-03-29 01:27:10 -07:00
swift-ci
54862c1439 Merge pull request #64700 from meg-gupta/updatehaspointerescapedce
Support all BorrowedValueKind in hasPointerEscape(BorrowedValue) api
2023-03-29 00:36:03 -07:00
Meghana Gupta
84d643fc85 Fix infinite loop in the new hasPointerEscape(SILValue) api 2023-03-28 20:47:27 -07:00
Meghana Gupta
64d344ab07 Support all BorrowedValueKind in hasPointerEscape(BorrowedValue) api 2023-03-28 20:31:27 -07:00
Andrew Trick
0c8ecb54bf Revert "MultiDefPrunedLiveness: add support for arbitrary uses/defs." 2023-03-28 17:43:42 -07:00
Andrew Trick
95a92fda30 Merge pull request #64625 from atrick/fix-liveblocks
MultiDefPrunedLiveness: add support for arbitrary uses/defs.
2023-03-28 14:19:42 -07:00
Konrad `ktoso` Malawski
0586c14b60 [Concurrency] SerialExecutor.isSameExclusiveExecutionContext (#64604) 2023-03-28 15:56:28 +09:00
Andrew Trick
6b77b79ac8 MultiDefPrunedLiveness: add support for arbitrary uses/defs.
This now supports liveness holes within blocks where previously we
expected a phi def.

PrunedLiveness is streamlined for SSA liveness where we expect the
defs and uses to be related in the SSA def-use graph.
MultiDefPrunedLiveness was added on top of SSAPrunedLivenes to handle
extended SSA liveness that occurs with phis, but are still connected
in the def-use graph. Recently MultiDefPrunedLiveness was repurposed
for liveness of addressible storage. This means that we can now have
uses before defs in the same block without a corresponding phi.

Fortunately, handling this case is a straightforward extension of
MultiDefPrunedLiveness that does not complicate or penalize the
streamlined SSA case.
2023-03-24 18:40:31 -07:00
Andrew Trick
44fc97d340 [NFC] Move the updateForUse API into PrunedliveRange
PrunedLiveness only knows about the live blocks and uses.

The PrunedLiveRange subclass is now responsible for updating liveness
based on both the defs and uses. This is in preparation for handling
non-SSA liveness when uses occur before the first def.
2023-03-23 22:05:54 -07:00
Andrew Trick
8a0d5ff5fd Fix a comment typo 2023-03-23 18:59:32 -07:00
Andrew Trick
f30fd127fa silence a noasserts warning 2023-03-23 16:08:36 -07:00
nate-chandler
a5fe75ed82 Merge pull request #64549 from nate-chandler/hop_to_executor-may-synchronize
[SILOptimizer] hop_to_executor may synchronize.
2023-03-23 14:48:23 -07:00
Andrew Trick
119e712c32 Merge pull request #64534 from atrick/liveblocks-bitfield
Cleanup PrunedLiveBlocks
2023-03-22 16:33:08 -07:00
Nate Chandler
a2c81df849 [SILOptimizer] hop_to_executor may synchronize.
If a deinitializer has an external side-effect, it should execute after
any other tasks have executed on the same actor with potentially
external side effects.

rdar://98542036
2023-03-22 14:22:26 -07:00