Commit Graph

9594 Commits

Author SHA1 Message Date
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
Konrad `ktoso` Malawski
828f589be4 Initial Task Executor implementation Task(on:), addTask(on:) etc. (#68793)
Co-authored-by: John McCall <rjmccall@gmail.com>
2023-12-12 17:14:24 +09:00
Michael Gottesman
f328e7893b [region-isolation] Add support for representing ApplyIsolationCrossing at the SIL level on apply, begin_apply, try_apply.
Some notes:

This is not emitted by SILGen. This is just intended to be used so I can write
SIL test cases for transfer non sendable. I did this by adding an
ActorIsolationCrossing field to all FullApplySites rather than adding it into
the type system on a callee. The reason that this makes sense from a modeling
perspective is that an actor isolation crossing is a caller concept since it is
describing a difference in between the caller's and callee's isolation. As a
bonus it makes this a less viral change.

For simplicity, I made it so that the isolation is represented as an optional
modifier on the instructions:

  apply [callee_isolation=XXXX] [caller_isolation=XXXX]

where XXXX is a printed representation of the actor isolation.

When neither callee or caller isolation is specified then the
ApplyIsolationCrossing is std::nullopt. If only one is specified, we make the
other one ActorIsolation::Unspecified.

This required me to move ActorIsolationCrossing from AST/Expr.h ->
AST/ActorIsolation.h to work around compilation issues... Arguably that is where
it should exist anyways so it made sense.

rdar://118521597
2023-12-11 19:27:27 -06:00
Kuba Mracek
08053b6794 [embedded] Order externally visible functions first in PerformanceDiagnostics when diagnosing embedded Swift restrictions 2023-12-11 14:42:54 -08:00
Alejandro Alonso
49b0a23561 Add getEnumTag and injectEnumTag builtins 2023-12-11 10:58:29 -08:00
Joe Groff
96c87dbf81 Move-only-check the yielded result from read coroutines when they're noncopyable.
Mark the result of starting a read coroutine to be checked by the move-only checker, and then
update the pattern matching in the move checker itself so that it recognizes code patterns
involving yielding from and receiving yields from read coroutines. Teach move only diagnostics
to get the property name for an access through a read coroutine from the referenced declaration.
2023-12-11 10:54:52 -08:00
Kuba Mracek
ff1f8adac8 [embedded] Implement non-allocating embedded Swift mode, under -no-allocations flag 2023-12-11 09:00:50 -08:00
Kuba Mracek
df638b0e63 [embedded] Add explaining comment for running DeadFunctionAndGlobalElimination in embedded Swift 2023-12-11 08:48:13 -08:00
Kuba (Brecka) Mracek
eef0427ae9 Merge pull request #70286 from kubamracek/embedded-diag-loc
[embedded] When missing a source location in a PerformanceDiagnostic, at least print the function name
2023-12-11 08:42:45 -08:00
Kuba Mracek
ea47c813ec [embedded] Print demangled function names in PerformanceDiagnostics 2023-12-10 16:33:37 -08:00
Kuba Mracek
75450c7d2f [embedded] When missing a source location in a PerformanceDiagnostic, at least print the function name 2023-12-10 16:24:15 -08:00
Kuba Mracek
bb1ba7c95c [embedded] Run DeadFunctionAndGlobalElimination after MandatoryPerformanceOptimizations 2023-12-09 22:39:55 -08:00
Erik Eckstein
ae278058e6 Add an experimental pass to lower allocateVector builtins
By default it lowers the builtin to an `alloc_vector` with a paired `dealloc_stack`.
If the builtin appears in the initializer of a global variable and the vector elements are initialized,
a statically initialized global is created where the initializer is a `vector` instruction.
2023-12-09 18:49:58 +01:00
Erik Eckstein
cc83a7d414 add the "array.copy_into_vector" array-semantic 2023-12-09 18:49:57 +01:00
Erik Eckstein
dd9ce40ba1 add the allocVector builtin 2023-12-09 18:49:57 +01:00
Erik Eckstein
e652f2c92e SIL: add the alloc_vector and vector instructions
* `alloc_vector`: allocates an uninitialized vector of elements on the stack or in a statically initialized global
* `vector`: creates an initialized vector in a statically initialized global
2023-12-09 18:49:55 +01:00