Commit Graph

490 Commits

Author SHA1 Message Date
Erik Eckstein
0f359ff6f8 SideEffects: fix effects of indirect-in apply arguments
Indirect-in arguments are consumed by the caller and that not only counts as read but also as a write.
2024-07-29 17:33:43 +02:00
Erik Eckstein
4c49e0039b Verifier: in the swift verifier call the bridged C++ verificationFailure function in case of a failure
This brings all the nice verifier features to the swift verifier, like printing the surrounding instructions in case of a failure, etc.
2024-07-29 17:33:43 +02:00
Erik Eckstein
95bd329b1f Swift SIL: bridge the hasPointerEscape flags of MoveValueInst and BeginBorrowInst 2024-07-29 17:33:43 +02:00
Erik Eckstein
04e0907ab0 SIL: rename Type.instanceTypeOfMetatype -> Type.loweredInstanceTypeOfMetatype
The same for SILType

It needs to be made clear that this is not the "original", but the lowered SIL type.

NFC
2024-07-29 17:33:36 +02:00
Andrew Trick
25825e25ee SwiftCompilerSources: use Type.isVoid instead of Type.isEmpty. 2024-07-26 17:32:23 -07:00
Erik Eckstein
b739c6263b WalkUtils: handle unsafe_ref_cast which casts between AnyObject and a class
We need to ignore such casts because otherwise the constructed walking path wouldn't contain the right `existential` field kind.
Fixes a miscompile caused by redundant load elimination.

rdar://132364917
2024-07-24 11:35:08 +02:00
Andrew Trick
c32c238720 Fix LifetimeDependenceDiagnostics to handle invalid SIL types
Invalid types are not considered Escapable. This makes it difficult to make any
assumptions about nonescapable types.

Fixes rdar://132348528 (Fix LifetimeDependenceDiagnostics to handle invalid SIL types)
2024-07-23 16:03:32 -07:00
Meghana Gupta
154989463b Add support for lifetime dependence in parameter position 2024-07-10 14:20:03 -07:00
Akira Hatanaka
42bc49d3fe Add a new parameter convention @in_cxx for non-trivial C++ classes that are passed indirectly and destructed by the caller (#73019)
This corresponds to the parameter-passing convention of the Itanium C++
ABI, in which the argument is passed indirectly and possibly modified,
but not destroyed, by the callee.

@in_cxx is handled the same way as @in in callers and @in_guaranteed in
callees. OwnershipModelEliminator emits the call to destroy_addr that is
needed to destroy the argument in the caller.

rdar://122707697
2024-06-27 09:44:04 -07:00
Erik Eckstein
c61733f985 SwiftCompilerSources: refactor Function.mayBindDynamicSelf
Instead of bridging the whole function, just bridge `hasDynamicSelfMetadata` and do the other work in swift.
2024-06-25 17:59:23 +02:00
Ellie Shin
41ee82a589 [SwiftCompilerSources] Remove warning: add unknown default case for bridged function serializedkind. 2024-06-13 14:42:13 -07:00
Ellie Shin
8b00478bc6 [SwiftCompilerSources] Remove unnecessary default case from SerializedKind funcs 2024-06-11 23:59:43 -07:00
Meghana Gupta
af1d6017f9 Merge pull request #74132 from meg-gupta/deleteresultdependson
Remove resultDependsOn/resultDependsOnSelf
2024-06-06 10:23:31 -07:00
Nate Chandler
2a5d07522d [SIL] Add extend_lifetime instruction.
It indicates that the value's lifetime continues to at least this point.
The boundary formed by all consuming uses together with these
instructions will encompass all uses of the value.
2024-06-05 16:28:26 -07:00
Meghana Gupta
470fa2f365 Remove resultDependsOn/resultDependsOnSelf 2024-06-05 11:36:16 -07:00
Ellie Shin
6216ec648f Merge pull request #73902 from apple/elsh/pkg-cmo-inline
[SIL][PackageCMO] Allow optimizing [serialized_for_pkg] functions
2024-06-04 11:39:19 -07:00
Emil Pedersen
531469f70e Merge pull request #73864 from Snowy1803/scs-builder-skip-meta
Skip meta instructions for Builder.init with automatic location
2024-05-30 09:50:48 -07:00
Ellie Shin
c3ded85c4f Update SILBridgedFunction APIs.
Add isAnySerialized() and canBeInlinedIntoCaller(SerializedKind).
2024-05-29 15:54:36 -07:00
Emil Pedersen
d39d838c2b Skip meta instructions for Builder.init with automatic location 2024-05-24 16:01:11 -07:00
Emil Pedersen
4b1ce86f48 Add Location.isInlined to SwiftCompilerSources 2024-05-23 16:04:05 -07:00
Kshitij Jain
64da348ee9 Merge pull request #73688 from jkshtj/main
[Autodiff] Adds logic to rewrite call-sites using functions specialized by the closure-spec optimization
2024-05-23 14:21:31 -07:00
Andrew Trick
b88566a36c Merge pull request #73621 from atrick/fix-access-mark-uninit
Allow AddressUseDefWalker to continue past MarkUninitializedInst
2024-05-22 18:18:51 -07:00
Kshitij
c288d95c1e [Autodiff] Separates out changes for using non-ossa instructions in the closure-spec optimization pass
The OSSA elimination pass has not yet been moved below all high level
function passes. Until that work has been completed the Autodiff
closure-spec optimization pass cannot solely support OSSA instructions.
2024-05-21 12:02:28 -07:00
Kshitij
12faf79911 [Autodiff] Adds logic to rewrite call-sites using functions specialized by the closure-spec optimization 2024-05-21 12:02:28 -07:00
Erik Eckstein
af68435d90 Optimizer: support static initialization of global arrays
The buffer of global arrays could already be statically initialized.
The missing piece was the array itself, which is basically a reference to the array buffer.
For example:
```
var a = [1, 2, 3]
```
ends up in two statically initialized globals:
1. the array buffer, which contains the elements
2. the variable `a` which is a single reference (= pointer) of the array buffer

This optimization removes the need for lazy initialization of such variables.

rdar://127757554
2024-05-16 21:34:36 +02:00
Andrew Trick
dfe62b442e Allow AddressUseDefWalker to continue past MarkUninitializedInst.
This makes SwiftCompilerSources address/access utilities consistent with C++ and
allows them to be used in diagnostic passes.
2024-05-14 10:31:24 -07:00
Kshitij
74166a4ab6 [Autodiff] Moves bridging code accesses in closure-spec opt behind APIs
Addresses some other surfacial feedback as well.
2024-05-13 15:37:30 -07:00
Kshitij
ab751d57ab [Autodiff] Adds logic to generate specialized functions in the closure-spec pass 2024-05-13 11:16:42 -07:00
Kshitij
003c9082cb [Autodiff] Adds SwiftCompilerSources changes in preparation for the Autodiff closure-spec optimization pass 2024-05-02 09:14:05 -07:00
eeckstein
7bf193e764 SwiftCompilerSources: workaround a compiler crash on windows by disabling convert_function simplification 2024-04-29 10:52:25 +02:00
Erik Eckstein
3c368575b4 SwiftCompilerSources: add a few utility APIs 2024-04-10 13:38:10 +02:00
Erik Eckstein
ac4bc89c9a SIL: add the borrowed-from instruction.
It declares from which enclosing values a guaranteed phi argument is borrowed from.
2024-04-10 13:38:10 +02:00
Meghana Gupta
9c57458163 Fix index numbering in lifetime dependence 2024-04-08 22:33:28 -07:00
Andrew Trick
581010d00c SIL: Make drop_deinit a ForwardingInstruction.
drop_deinit forwards ownership while effectively stripping the deinitializer. It is similar to a type cast.

Fixes rdar://125590074 ([NonescapableTypes] Nonescapable types
cannot have deinits)
2024-04-03 18:53:18 -07:00
Andrew Trick
89063c93e4 Add Value.definingInstructionOrTerminator 2024-04-03 10:46:09 -07:00
Andrew Trick
6fcec2ff96 SwiftCompilerSources: organize parameter pack instructions 2024-04-01 21:46:18 -07:00
Andrew Trick
66dcf6a35c SwiftCompilerSources: fix PackElementSetInst
It is not a SingleValueInstruction.
2024-04-01 21:46:10 -07:00
Andrew Trick
a1bb9f401a Fix SILVerifier and AddressUtils handling of addr casts.
These core utils did not handle UnconditionalCheckedCastAddrInst or
UncheckedRefCastAddrInst correctly.
2024-04-01 21:46:10 -07:00
Mayank Kumar Gupta
3093925aa0 [Minor][SIL] Refactor matches function in Effects 2024-03-26 00:22:07 +05:30
Andrew Trick
a0b2ae9c2c Add AccessBase.storeBorrow.
Don't treat StoreBorrow addresses as unknown bases. While they are never the base of a formal access, they are returned
as the AccessBase when querying the enclosing scope of an address.
2024-03-22 11:51:58 -07:00
Erik Eckstein
367dc1a299 SwiftCompilerSources: add OperandSet and OperandWorklist
Implemented by bridging the C++ OperandSet, similar to BasicBlockSet and NodeSet
2024-03-21 15:52:39 +01:00
Andrew Trick
7da493498a Merge pull request #72407 from atrick/pointer-escape-bailout
Fix lifetime dependence in the presence of pointer escapes.
2024-03-19 11:40:38 -07:00
Erik Eckstein
6bb5ad6230 Swift SIL: complete APIs for CheckedCastAddrBranchInst 2024-03-19 09:02:06 +01:00
Andrew Trick
aa208bbf91 Add SILType::containsNoEscapeFunction()
Add PartialApplyInst.hasNoescapeCapture
Add PartialApplyInst.mayEscape

Refactor DiagnoseInvalidEscapingCaptures. This may change functionality because tuples containing a noescape closure are now correctly recognized. Although I'm not sure such tupes can ever be captured directly.
2024-03-18 17:38:12 -07:00
Andrew Trick
6b3d62cb5e SwiftCompilerSources: Add append methods to SingleInlineArray. 2024-03-18 17:38:12 -07:00
Nate Chandler
8ed11e1788 [SIL] Expose alloc_stack flag to Swift sources.
Code in SwiftCompilerSources should be able to create an `alloc_stack`
with the `var_decl` flag.
2024-03-11 21:15:58 -07:00
Andrew Trick
df7326d790 Fix SILType::isEscapable for box types.
SILBoxTypes have their own generic signature and substitution
map. This means that every time we query isEscapable or mayEscape, we
need to extract the type of the box's field and perform type
substitution so that the AST query only sees types from the function's
generic environment.

Fixes rdar://124179106 (Assertion failed in SIL:
(!type->hasTypeParameter() && "caller forgot to mapTypeIntoContext!"))
2024-03-07 13:34:46 -08:00
eeckstein
d1ec089c72 Merge pull request #72088 from language-core/main
chore: fix some comments
2024-03-06 10:08:50 +01:00
Andrew Trick
e40fd35cc4 SwiftCompilerSources: add Value.nextInstruction 2024-03-05 17:08:13 -08:00
Andrew Trick
33ed895a7d SwiftCompilerSources: make BasicBlock hashable 2024-03-05 17:08:13 -08:00