Commit Graph

9409 Commits

Author SHA1 Message Date
Michael Gottesman
d08359eb20 [region-isolation] Add support for ref_to_raw_pointer, raw_pointer_to_ref, index_raw_pointer. 2023-12-19 15:21:42 -08:00
Michael Gottesman
c90097f1f0 [region-isolation] Add support for *_existential_box instructions.
NOTE: I am just adding coverage that we support these instructions. One can only
use this with Error today and Error is always Sendable. So this is just going
for completeness.
2023-12-19 13:29:12 -08:00
Michael Gottesman
8178eb0a6e Merge pull request #70514 from gottesmm/pr-763529d8ee9f4164b82d03087fec25439cc1d315
[region-isolation] Fix the dataflow and add support for project_block_storage
2023-12-19 10:21:59 -08:00
Michael Gottesman
ddd8c01877 [region-isolation] Do not treat mark_dependence as an ignore. Treat it as an assign from op 0 -> result and a require of op 1.
Semantically a mark_dependence returns a value that is equal to its first
parameter with the extra semantics that any destroys of the 2nd operand cannot
occur before any uses of the result of the instruction. From a region
perspective this suggests that the instruction should be an assign from the
first operand onto the result and act as a require on the result. Semantically
the requirement that the 2nd operand cannot be destroyed before any uses of the
result does not expose any memory or state from the first operand implying that
we don't need to merge it into the result region. The restriction is purely to
tell the optimizer what it can/cannot do rather.
2023-12-18 16:56:32 -08:00
Michael Gottesman
71a8c8eedc [region-isolation] Some small comment cleanups/reordering of definitions. NFCI. 2023-12-18 16:29:46 -08:00
Michael Gottesman
998f067d59 [region-isolation] Add support for mark_unresolved_move_addr. It is a store. 2023-12-18 16:21:34 -08:00
Joe Groff
614a8e35ac Merge pull request #70507 from jckarter/generic-moveonly-diagnostic-names
Look through copy_addr and opened existentials to diagnose move-only sources.
2023-12-18 13:27:09 -08:00
Michael Gottesman
f6cda45e52 [region-isolation] Add support for alloc_vector. Its an assign fresh. 2023-12-18 12:47:42 -08:00
Michael Gottesman
58a6e2aa4d [region-isolation] Add Asserting support for {alloc,dealloc}_pack_metadata since they only appear in Lowered SIL.
I also added a note to the SIL.rst and an assert into the SILVerifier to better
document this requirement.
2023-12-18 12:35:40 -08:00
Michael Gottesman
4a635b61a4 [region-isolation] Add support for fix_lifetime.
fix_lifetime just acts as a require.
2023-12-18 12:35:40 -08:00
Michael Gottesman
59fe82d878 [region-isolation] Do not run on non-Ownership SSA SIL and mark certain instructions that can only appear in non-OSSA as asserting.
We already only supported Ownership SSA since we run early in the pipeline
before OSSA is lowered. This just formalizes this behavior. I am marking these
instructions as Asserting (even though we will never see them) so I can
semantically be sure that all of the instructions are covered without using an
"unsupported" like moniker that I fear will lead to new instructions being added
as unsupported. Better to have a semantic thing for new instruction adders to
use.
2023-12-18 12:35:40 -08:00
Michael Gottesman
7712639ab0 [region-isolation] Add support for project_block_storage.
rdar://119743743
2023-12-18 09:35:57 -08:00
Meghana Gupta
890ec7d855 Merge pull request #70477 from meg-gupta/fixpredmemopt
Use OSSALifetimeCompletion in PredictableMemOpt
2023-12-15 19:18:22 -08:00
Michael Gottesman
bcb8f1b0d8 [region-isolation] Implement the dataflow correctly.
This involved fixing a few different bugs.

1. We were just performing dataflow by setting that only the initial block needs
to be updated. This means that if there isn’t anything in the initial dataflow
block, we won’t visit any successor blocks. Instead the correct thing to do here
is to visit all blocks in the initial round.

2. I also needed to fix a separate issue where we were updating our union-find
data structure incorrectly as found by an assert on transfernonsendable.swift
that was triggered once I fixed 1. Put simply, we needed to set a new max label
+ 1 when our new max element is less than or equal to the old max label + 1…
before we just did less than so if we had a new max element that is the same as
our fresh label, we wouldn’t increment the fresh label.

rdar://119584497
2023-12-15 17:14:09 -08:00
Joe Groff
02800046c6 Look through copy_addr and opened existentials to diagnose move-only sources. 2023-12-15 16:36:09 -08:00
Joe Groff
58bf935e48 Merge pull request #70475 from jckarter/noncopyable-addressors
Move-only check the value projected from addressors.
2023-12-15 15:35:58 -08:00
Meghana Gupta
06f0d15c45 Use OSSALifetimeCompletion in PredictableMemOpt
The current algorithm to complete lifetimes is incorrect in a few cases.
Use OSSALifetimeCompletion instead.

Fixes rdar://119204768
2023-12-15 15:16:55 -08:00
Michael Gottesman
1f9b074a8d Merge pull request #70481 from gottesmm/more-translation-stuff
[region-isolation] Begin filling out unhandled instructions.
2023-12-15 11:17:41 -08:00
Joe Groff
1b9a0712bf Move-only check the value projected from addressors.
Mark the result of a move-only addressor as unresolved. The pointed-at value
cannot be consumed so ensure that only [read] or [modify] accesses are
performed. Update the move-only checker to recognize code patterns
from addressors.
2023-12-15 10:10:44 -08:00
nate-chandler
680c737ddb Merge pull request #64789 from nate-chandler/more-move-values
[SILGen] Used move_value for more lexical values.
2023-12-15 07:07:54 -08:00
Michael Gottesman
09151bd800 [region-isolation] Add lookthrough support for a bunch of instructions.
Specifically:

* MoveValueInst
* MarkUnresolvedNonCopyableValueInst
* MarkUnresolvedReferenceBindingInst
* CopyableToMoveOnlyWrapperValueInst
* MoveOnlyWrapperToCopyableValueInst
* MoveOnlyWrapperToCopyableBoxInst
* MoveOnlyWrapperToCopyableAddrInst
* CopyableToMoveOnlyWrapperAddrInst
* MarkUninitializedInst
2023-12-14 19:11:06 -08:00
Michael Gottesman
13d48d2de3 [region-isolation] Add support for explicit_copy_value as a look through instruction. 2023-12-14 19:11:06 -08:00
Michael Gottesman
b178843602 [region-isolation] Add support for yield, switch_enum_addr. 2023-12-14 19:11:06 -08:00
Michael Gottesman
5e1ca5ccb9 [region-isolation] Make instruction translation use a covered visitor and add a TranslationSemantics enum to guide users updating the code.
More specifically this patch does the following:

* Rather than having a large switch with misc code, I changed the partition op
translator to use a visitor that defines a declaration for all SILInstructions
and in translateSILInstruction visits all such instructions. This ensures via
the linker that when ever a new SILInstruction is added, a link error occurs.

* Rather than just have misc translation code from the switch in the visitor, I
created a new enum called TranslationSemantics that describes the semantics for
instructions and made it so that the visitor methods return an instance of the
enum. This enum is then switched over to determine the action to perform. This
handles the vast majority of cases and allows for a reader of the translation
code to read a small amount of code (< 20-30 lines) to understand at a glance
the available semantics rather than having to read a huge switch. To make it
easy to implement the constant semantics that most instructions have, I followed
what we did in OperandOwnership (the model that I followed here) by using
preprocessor macros to define explicitly the semantics for each instruction. In
the case where special handling is needed, we can create a custom method, handle
the translation by hand, and then return TranslationSemantics::Special to signal
to the handling loop to just not do anything.
2023-12-14 19:11:06 -08:00
Nate Chandler
72ff0ae589 [Gardening] Improved owned canonicalization logs. 2023-12-14 13:35:26 -08:00
Nate Chandler
5513dd1e32 [SAO] Redundant move elimination is mandatory. 2023-12-14 13:35:26 -08:00
Nate Chandler
d805e5e413 [ConsumeValueChecker] Visit lexical moves.
Now that SILGen almost always represents a lexical lifetime with

    move_value [lexical]

the fact that the checker doesn't consider such lifetimes is exposed.
Fix it to look for such lifetimes.
2023-12-14 13:35:26 -08:00
Nate Chandler
bb3dc295d4 [Gardening] Tweaked comment. 2023-12-14 13:35:26 -08:00
Nate Chandler
673c03bba1 [JVPCloner] Handle move_value. 2023-12-14 13:35:26 -08:00
Nate Chandler
0ea22e5cbd [JVPCloner] Cloned begin_borrow keeps flags. 2023-12-14 13:35:26 -08:00
Nate Chandler
2a5aafe9d7 [ForEachLoopUnroll] Fix move_value handling. 2023-12-14 09:10:05 -08:00
Nate Chandler
88a0bd7015 [OSLogOpt] Fix move_value handling. 2023-12-14 09:09:58 -08:00
Erik Eckstein
1a94f1ccb7 PerformanceDiagnostics: allow metatype arguments to _diagnoseUnexpectedEnumCaseValue
This is a fatal error function, used for imported C enums.

rdar://117520459
2023-12-14 12:51:01 +01:00
Meghana Gupta
f113eaae9d Merge pull request #70438 from meg-gupta/fixkeypathsilcombine
Invalidate stack nesting in keypath silcombine
2023-12-13 20:10:29 -08:00
Meghana Gupta
63a8d8c501 Merge pull request #70440 from meg-gupta/badcopy
Disable a silcombine pattern that creates unoptimizable copies
2023-12-13 16:08:34 -08:00
Meghana Gupta
367b5fe03e Invalidate stack nesting in keypath silcombine
KeyPathProjector creates alloc_stack and dealloc_stack for temporaries.
Insertion of new dealloc_stack can modify stack discipline.

Invalidate stack nesting so that it can be fixed up in the pass.
2023-12-13 15:22:35 -08:00
Meghana Gupta
d0de3a9c6c Merge pull request #70439 from meg-gupta/debugmsgs
[NFC] Add some debug logging to optimizer passes
2023-12-13 13:35:24 -08:00
Meghana Gupta
4c6b5400d3 Disable a silcombine pattern that creates unoptimizable copies
The SILCombine of ref_to_raw_pointer uses ossa rauw which creates a copy.
The copy created cannot be removed because it has an escaping ownership.
Disabling the silcombine for ossa here to avoid generating unoptimizable copies.
2023-12-13 10:42:28 -08:00
Meghana Gupta
8cb2086c62 [NFC] Add debug msgs to inliner 2023-12-13 10:38:12 -08:00
Meghana Gupta
78d499f42e [NFC] Add debug msgs to SILCombine 2023-12-13 10:38:12 -08:00
Meghana Gupta
24aa3296dc [NFC] Add debug msgs in copy value opts 2023-12-13 10:38:12 -08:00
Meghana Gupta
90c5b80b0b [NFC] Add some debug msgs in LoopUnroll 2023-12-13 10:38:12 -08:00
Erik Eckstein
b3cccb3ef5 PassManager: correctly pass the CalleeCache to SILModule::verify
Fixes a compiler warning and improves verification.
2023-12-13 13:45:53 +01:00
Alejandro Alonso
f365316d74 Merge pull request #70327 from Azoy/inject-get-enum-tag-builtins
[IRGen] Add getEnumTag and injectEnumTag builtins
2023-12-12 16:07:56 -08:00
Kuba (Brecka) Mracek
91956a1f65 Merge pull request #70314 from kubamracek/embedded-no-alloc
[embedded] Implement non-allocating embedded Swift mode, under -no-allocations flag
2023-12-12 15:15:10 -08:00
Joe Groff
957443e16c Merge pull request #70404 from jckarter/modify-coroutines-yielding-noncopyable-values
Move-only-check the result of modify coroutines.
2023-12-12 14:38:48 -08:00
Michael Gottesman
486b7ceb94 Merge pull request #70394 from gottesmm/pr-f328e7893b344f5252d43a4358baf49fb4589abe
[region-isolation] Add the ability to write SIL tests for actor isolation
2023-12-12 15:47:12 -06:00
Kuba (Brecka) Mracek
b9f7acb8b5 Merge pull request #70309 from kubamracek/embedded-dfe
[embedded] Run DeadFunctionAndGlobalElimination after MandatoryPerformanceOptimizations
2023-12-12 10:21:11 -08:00
Joe Groff
a0b133020c Merge pull request #70333 from jckarter/read-coroutines-yielding-noncopyable-values
Move-only-check the yielded result from read coroutines when they're noncopyable.
2023-12-12 09:35:39 -08:00
Joe Groff
18e31157fd Move-only-check the result of modify coroutines.
Following https://github.com/apple/swift/pull/70333, do the same thing for
modify coroutines, marking the result so that we check uses of the result to
ensure it isn't consumed (without being reinitialized).
2023-12-12 09:02:24 -08:00