Commit Graph

1057 Commits

Author SHA1 Message Date
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
Andrew Trick
cbe856e53a Cleanup PrunedLiveBlocks
Use BasicBlockBitfield to record per-block liveness state. This has
been the intention since BasicBlockBitfield was first introduced.

Remove the per-field bitfield from PrunedLiveBlocks. This
(re)specializes the data structure for scalar liveness and drastically
simplifies the implementation.

This utility is fundamental to all ownership utilities. It will be on
the critical path in many areas of the compiler, including at
-Onone. It needs to be minimal and as easy as possible for compiler
engineers to understand, investigate, and debug.

This is in preparation for fixing bugs related to multi-def liveness
as used by the move checker.
2023-03-22 02:36:57 -07:00
Andrew Trick
15796e3ff9 PrunedLiveness: add a SILFunction argument
So that liveness can migrate to using a SILBitfield.
2023-03-22 01:36:48 -07:00
nate-chandler
1482108c84 Merge pull request #64483 from nate-chandler/nfc/20230320/1/redundant-move
[NFC] Readability for isRedundantMoveValue.
2023-03-21 13:44:23 -07:00
Nate Chandler
b7f447da6c [NFC] Readability for isRedundantMoveValue.
Improved comments and flattened conditions.
2023-03-21 07:57:43 -07:00
Erik Eckstein
a092ecb5c2 remove SILBridgingUtils.h 2023-03-21 15:33:09 +01:00
Erik Eckstein
04c90166c4 Swift Bridging: use C++ instead of C bridging for BridgedBuilder 2023-03-21 15:33:09 +01:00
Erik Eckstein
b4510105a6 Swift Bridging: remove BridgedNode 2023-03-21 15:33:09 +01:00
Erik Eckstein
7905a9ac64 Swift Bridging: remove C bridging functions for SILDebugLocation 2023-03-21 15:33:09 +01:00