Commit Graph

59 Commits

Author SHA1 Message Date
Erik Eckstein
db03a55c79 Swift SIL: add some Builder APIs
* `createCheckedCastAddrBranch`
* `createUnconditionalCheckedCastAddr`
* `createDebugValue`
* `createWitnessMethod`
* `createInitEnumDataAddr`
2025-03-07 15:59:33 +01:00
Erik Eckstein
e0b4f71af6 SIL: remove the alloc_vector instruction
It's not needed anymore, because the "FixedArray" experimental feature is replaced by inline-arrays.
2025-02-12 10:51:14 +01:00
Erik Eckstein
2d10da001a SIL: add some Builder-create functions 2024-12-21 08:28:20 +01:00
Erik Eckstein
bcdbc05260 SIL: make Builde.insertionPoint public 2024-12-10 16:28:11 +01:00
Andrew Trick
442739a176 [NFC] Add a Builder.insertionBlock API.
Some utilities, like Builder.insert(after:) pass a Builder object that
represents an insertion point. That insertion point is sometimes needed to
determine which instructions to create (endApply vs. abortApply). But there is
no way to recover the insertion point. We don't want to simply return an
instruction, because that could be interpreted in different ways. Instead we
provide insertion block, but only in those situations where it makes sense and can't
be used incorrectly.
2024-11-18 01:37:00 -08:00
Andrew Trick
3e26cf81d0 SwiftCompilerSources: bridge createEndApply and createAbortApply. 2024-11-18 01:37:00 -08:00
Erik Eckstein
6bf7cc8f2f Swift SIL: add flag parameters to Builder.createBeginBorrow 2024-10-11 09:41:36 +02:00
Erik Eckstein
10782cf42b SwiftCompilerSources: introduce the AST module
As the optimizer uses more and more AST stuff, it's now time to create an "AST" module.
Initially it defines following AST datastructures:
* declarations: `Decl` + derived classes
* `Conformance`
* `SubstitutionMap`
* `Type` and `CanonicalType`

Some of those were already defined in the SIL module and are now moved to the AST module.
This change also cleans up a few things:
* proper definition of `NominalTypeDecl`-related APIs in `SIL.Type`
* rename `ProtocolConformance` to `Conformance`
* use `AST.Type`/`AST.CanonicalType` instead of `BridgedASTType` in SIL and the Optimizer
2024-10-02 07:10:29 +02:00
Erik Eckstein
f3a9b08e7a SwiftCompilerSources: bridged ProtocolConformance
And use that in some Builder APIs
2024-09-25 19:31:40 +02:00
Kuba Mracek
c7a5569c4f [embedded] Add support for ManagedBuffer to Embedded Swift
This makes ManagedBuffer available and usable in Embedded Swift, by:

- Removing an internal consistency check from ManagedBuffer that relies on metatypes.
- Making the .create() API transparent (to hoist the metatype to the callee).
- Adding a AllocRefDynamicInst simplification to convert `alloc_ref_dynamic` to `alloc_ref`, which removes a metatype use.
- Adding tests for the above.
2024-09-23 13:32:50 -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
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
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
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
7dea051bf6 Review feedback; Builder.createEndAccess() 2024-03-05 17:08:13 -08:00
Meghana Gupta
14578db701 Bridge createEndAccess 2024-02-13 00:12:23 -08:00
Andrew Trick
79fe8bad30 SwiftCompilerSources: improve MarkDependenceInst. 2024-02-12 09:57:14 -08:00
Andrew Trick
da3f583492 Add mark_dependence [unresolved]
In preparation for inserting mark_dependence instructions for lifetime
dependencies early, immediately after SILGen. That will simplify the
implementation of borrowed arguments.

Marking them unresolved is needed to make OSSA verification
conservative until lifetime dependence diagnostics runs.
2024-02-08 22:53:16 -08:00
Erik Eckstein
a98448b89a swift Builder: add a few instruction creation functions 2024-01-31 17:16:12 +01:00
Erik Eckstein
bc99986cf9 SIL: add a dependency token operand to global_addr
Optionally, the dependency to the initialization of the global can be specified with a dependency token `depends_on <token>`.
This is usually a `builtin "once"` which calls the initializer for the global variable.
2024-01-10 09:33:58 +01:00
Andrew Trick
264cbaea42 Add mark_dependence [nonescaping] flag.
The dependent 'value' may be marked 'nonescaping', which guarantees that the
lifetime dependence is statically enforceable. In this case, the compiler
must be able to follow all values forwarded from the dependent 'value', and
recognize all final (non-forwarded, non-escaping) use points. This implies
that `findPointerEscape` is false. A diagnostic pass checks that the
incoming SIL to verify that these use points are all initially within the
'base' lifetime. Regular 'mark_dependence' semantics ensure that
optimizations cannot violate the lifetime dependence after diagnostics.
2024-01-04 14:47:35 -08: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
Erik Eckstein
0bd6034270 SwiftCompilerSources: add some Builder APIs
* `createAddressToPointer`
* `createLoadBorrow`
2023-12-09 18:48:50 +01:00
Erik Eckstein
bfeb2128cb remove default value for the keepUnique argument of Builder.createEndCOWMutation
This avoids bugs because the default value false is sometimes not the right choice.
NFC
2023-12-06 15:40:08 +01:00
Erik Eckstein
37c715c58c SwiftCompilerSources: add EndLifetimeInst 2023-11-27 09:21:33 +01:00
Erik Eckstein
6f6c0a5608 SwiftCompilerSources: add a few enum related APIs in Type and Builder
* `Type.getEnumCases`
* `Builder.createUncheckedTakeEnumDataAddr`
* `Builder.createSwitchEnumAddr`
2023-11-27 09:21:33 +01:00
Erik Eckstein
b6938475b9 Optimizer: add simplification for the convert_escape_to_noescape instruction
Including the required bridging stuff.

  %2 = thin_to_thick_function %1 to $() -> ()
  %3 = convert_escape_to_noescape %2 : $() -> () to $@noescape () -> ()
->
  %3 = thin_to_thick_function %1 to $@noescape () -> ()
2023-10-27 10:47:07 +02:00
Erik Eckstein
2dbd6cc56b SwiftCompilerSources: rework bridging
Introduce two modes of bridging:
* inline mode: this is basically how it worked so far. Using full C++ interop which allows bridging functions to be inlined.
* pure mode: bridging functions are not inlined but compiled in a cpp file. This allows to reduce the C++ interop requirements to a minimum. No std/llvm/swift headers are imported.

This change requires a major refactoring of bridging sources. The implementation of bridging functions go to two separate files: SILBridgingImpl.h and OptimizerBridgingImpl.h.
Depending on the mode, those files are either included in the corresponding header files (inline mode), or included in the c++ file (pure mode).

The mode can be selected with the BRIDGING_MODE cmake variable. By default it is set to the inline mode (= existing behavior). The pure mode is only selected in certain configurations to work around C++ interop issues:
* In debug builds, to workaround a problem with LLDB's `po` command (rdar://115770255).
* On windows to workaround a build problem.
2023-10-09 09:52:52 +02:00
Erik Eckstein
f0b811c45f SIL: add the end_init_let_ref instruction
This instructions marks the point where all let-fields of a class are initialized.
This is important to ensure the correctness of ``ref_element_addr [immutable]`` for let-fields,
because in the initializer of a class, its let-fields are not immutable, yet.
2023-09-19 15:10:30 +02:00
Erik Eckstein
e5eb15dcbe Swift SIL: replace the set_deallocating instruction with begin_dealloc_ref
Codegen is the same, but `begin_dealloc_ref` consumes the operand and produces a new SSA value.
This cleanly splits the liferange to the region before and within the destructor of a class.
2023-09-19 15:10:30 +02:00
Erik Eckstein
83754fa085 Swift SIL: add Builder.createEndCOWMutation 2023-09-19 15:10:30 +02:00
Kuba Mracek
50f6430a27 [embedded] Convert thick->thin metatypes on array builtins (copy, take, assign) in mandatory optimizations 2023-09-14 18:09:08 -07:00
Erik Eckstein
2baaf4890e Swift SIL: add a few new create functions in Builder 2023-07-21 07:19:12 +02:00
Erik Eckstein
efcd90af7d Swift SIL: rename ownership enums and properties in LoadInst and StoreInst
`ownership` is a bad name in `LoadInst`, because it hides `Value.ownership`.
Therefore rename it to `loadOwnership`.
Do the same for ownership in StoreInst to be consistent.
2023-07-11 22:33:02 +02:00
Erik Eckstein
205c841ed8 Swift SIL: add some Builder APIs
* `createStructExtract`
* `createStructElementAddr`
* `createTupleExtract`
* `createTupleElementAddr`
2023-07-05 21:33:24 +02:00
Erik Eckstein
625619ee17 SIL: add a bare attribute to global_value
The `bare` attribute indicates that the object header is not used throughout the lifetime of the value.
This means, no reference counting operations are performed on the object and its metadata is not used.
The header of bare objects doesn't need to be initialized.
2023-06-29 06:57:05 +02:00
Erik Eckstein
9474b9d1f0 Optimizer: add simplifications for checked_cast_br and unchecked_ref_cast
Look through `upcast` and `init_existential_ref` instructions and replace the operand of this cast instruction with the original value.
For example:
```
  %2 = upcast %1 : $Derived to $Base
  %3 = init_existential_ref %2 : $Base : $Base, $AnyObject
  checked_cast_br %3 : $AnyObject to Derived, bb1, bb2
```

This makes it more likely that the cast can be constant folded because the source operand's type is more accurate.
In the example above, the cast reduces to
```
  checked_cast_br %1 : $Derived to Derived, bb1, bb2
```
which can be trivially folded to always-succeeds.

Found while looking at `_SwiftDeferredNSDictionary.bridgeValues()`
2023-06-20 16:45:58 +02:00
Erik Eckstein
5325a4fe21 Swift SIL: add some instruction classes and APIs
* add `UnownedRetainInst` and `UnownedReleaseInst`
* add `var value` to `RetainValueInst` and `ReleaseValueInst`
* make the protocol `UnaryInstruction` be an `Instruction`
* add `var Type.isValueTypeWithDeinit`
* add `var Type.isUnownedStorageType`
* add `var OperandArray.values`
2023-06-07 12:55:56 +02:00
Erik Eckstein
d02765fd54 Swift SIL: some new APIs and some refactoring 2023-05-25 16:28:41 +02:00
Erik Eckstein
b707b5a595 Swift SIL: improve the Builder
* add new create-functions for instructions
* allow the Builder to build static initializer instructions for global variables
* some refactoring to simplify the implementation
2023-05-22 15:34:26 +02:00
Erik Eckstein
2b117fd3ee Swift Optimizer: add APIs to copy from or to a global static initializer
* `Context.copyStaticInitializer(fromInitValue:, to:)`
* `FunctionPassContext.createStaticInitializer(for:,initValue:)`
2023-05-08 21:23:36 +02:00
Erik Eckstein
010efc1ca6 Swift Bridging: use C++ instead of C bridging for the optimizer 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
4445373808 Swift Bridging: use C++ instead of C bridging for BridgedInstruction 2023-03-21 15:33:09 +01:00
Michael Gottesman
4a309575d7 [sil] Rename [moved] flag on debug_value/alloc_stack to moveable_value_debuginfo.
This is in preparation for wiring up debug info support for noncopyable
values. Originally this flag name made sense since it was set when we performed
consume operator checking. Now I am going to use it for noncopyable types as
well. I think the new name uses_moveable_value_debuginfo actually describes what
the flag is supposed to do, tell IRGen that the value may be moved since it
needs to use moveable value debug info emission.
2023-03-19 15:38:42 -07:00
Erik Eckstein
cef6ef9a84 SIL: add a debug_step instruction
This instruction can be inserted by Onone optimizations as a replacement for deleted instructions to
ensure that it's possible to single step on its location.
2023-02-09 06:50:05 +01:00
Erik Eckstein
221a16ba17 Swift SIL: add more arguments to Builder.createApply
add the `isNonThrowing` and `isNonAsync` flags and the `specializationInfo`
2023-01-16 19:00:09 +01:00
Erik Eckstein
cc68bd98c9 Swift Optimizer: rework pass context types and instruction passes
* split the `PassContext` into multiple protocols and structs: `Context`, `MutatingContext`, `FunctionPassContext` and `SimplifyContext`
* change how instruction passes work: implement the `simplify` function in conformance to `SILCombineSimplifyable`
* add a mechanism to add a callback for inserted instructions
2023-01-16 15:11:34 +01:00
Erik Eckstein
9e0b86ddbd Swift SIL: add Builder.createUnreachable() 2022-12-12 19:08:57 +01:00