Erik Eckstein
5c0ae940eb
Optimizer: add simplification for the value_to_bridge_object instruction
...
This comes up in the code for constructing an empty string literal.
With this optimization it's possible to statically initialize empty string global variables.
2023-05-25 16:28:41 +02:00
Erik Eckstein
4284dc10d0
Optimizer: implement the ObjectOutliner pass in Swift
2023-05-22 15:34:26 +02:00
Erik Eckstein
f3851f7503
Optimizer: implement load simplification in Swift
2023-05-22 15:34:26 +02:00
Erik Eckstein
61857f379b
Swift Optimizer: add the ValueWorklist typealias
2023-05-22 15:34:26 +02:00
Erik Eckstein
585395b67c
Swift Optimizer: add Context.lookupStdlibFunction
2023-05-22 15:34:26 +02:00
Erik Eckstein
38de5b1ab5
Swift SIL/Optimizer: implement cloning of static init values of globals in Swift
...
* add the StaticInitCloner utility
* remove bridging of `copyStaticInitializer` and `createStaticInitializer`
* add `Context.mangleOutlinedVariable` and `Context.createGlobalVariable`
2023-05-22 15:34:26 +02:00
Erik Eckstein
ee1c52bc77
Swift SIL: add some APIs
2023-05-22 15:34:26 +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
a4225a9088
Swift SIL: add a few SIL instructions and instruction APIs
2023-05-22 15:34:26 +02:00
Erik Eckstein
7bbf66ab5b
ReadOnlyGlobalVariables: don't convert external global vars to lets
...
Because we don't know if external variables will be written
Fixes a miscompile
rdar://109476745
2023-05-19 18:28:22 +02:00
Erik Eckstein
dc3cb18029
Swift Optimizer: add the MandatoryPerformanceOptimizations pass
...
As a replacement for the old MandatoryGenericSpecializer
The pass it not enabled yet in the pass pipeline
2023-05-11 08:11:44 +02:00
Erik Eckstein
1355e94eca
Simplification: simplify builtin "canBeClass" and builtin "assert_configuration"
2023-05-11 08:11:44 +02:00
Erik Eckstein
b9169064c6
Swift SIL: add some APIs
...
* `Options.assertConfiguration`
* `Argument.isIndirectResult`
* in `Function`: `selfArgument`, `isTransparent`, `performanceConstraints` and `inlineStrategy`
* `BuiltinInst.substitutionMap`
* `SubstitutionMap.replacementTypes`
* `Type.canBeClass`
2023-05-11 08:11:44 +02:00
Erik Eckstein
82734b6ac2
Swift Optimizer: simplification for apply, try_apply, begin_apply and partial_apply
...
* move the apply of partial_apply transformation from simplify-apply to simplify-partial_apply
* delete dead partial_apply instructions
* devirtualize apply, try_apply and begin_apply
2023-05-11 08:11:44 +02:00
Erik Eckstein
6eff928989
Swift Optimizer: add a message to an assert
2023-05-11 08:11:44 +02:00
Erik Eckstein
92a17f8a01
Optimizer: extract the NamedReturnValueOptimization from CopyForwarding to a separate function pass
...
This allows to run the NamedReturnValueOptimization only late in the pipeline.
The optimization shouldn't be done before serialization, because it might prevent predictable memory optimizations in the caller after inlining.
2023-05-11 08:11:44 +02:00
Erik Eckstein
08e75f2c50
Swift SIL: add the Operand.set API
...
as a shortcut for `Instruction.setOperand`
2023-05-11 08:03:19 +02:00
Erik Eckstein
4dcd91af7b
Swift SIL: add all deallocation instructions and let them conform to the Deallocation protocol
2023-05-11 08:03:19 +02:00
Erik Eckstein
5e2e7e3884
SIL Bridging: use bool for boolean properties
...
This was a leftover from the time we didn't use C++ interop
2023-05-11 08:03:19 +02:00
Erik Eckstein
3d555a412a
refactor two swift passes
...
NFC
2023-05-10 16:04:57 +02:00
Erik Eckstein
fa1ecff143
Swift Optimizer: rewrite the MemBehaviorDumper test pass in swift.
2023-05-09 08:25:09 +02:00
Erik Eckstein
960ca70def
Swift Optimizer: add the module pass ReadOnlyGlobalVariables
...
It marks global `var` variables as `let` if they are never written.
2023-05-08 21:23:36 +02:00
Erik Eckstein
88a4a9769e
Swift Optimizer: add simplification for load
...
Replace loads of global let variables with there static initializer values.
2023-05-08 21:23:36 +02:00
Erik Eckstein
6d6b94e430
Swift Optimizer: add the InitializeStaticGlobals function pass
...
It converts a lazily initialized global to a statically initialized global variable.
When this pass runs on a global initializer `[global_init_once_fn]` it tries to create a static initializer for the initialized global.
```
sil [global_init_once_fn] @globalinit {
alloc_global @the_global
%a = global_addr @the_global
%i = some_const_initializer_insts
store %i to %a
}
```
The pass creates a static initializer for the global:
```
sil_global @the_global = {
%initval = some_const_initializer_insts
}
```
and removes the allocation and store instructions from the initializer function:
```
sil [global_init_once_fn] @globalinit {
%a = global_addr @the_global
%i = some_const_initializer_insts
}
```
The initializer then becomes a side-effect free function which let's the builtin-simplification remove the `builtin "once"` which calls the initializer.
2023-05-08 21:23:36 +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
78ce13dbd6
WalkUtils: Don't treat end_access as leaf-use in the AddressDefUseWalker
...
Instead just ignore it.
2023-05-08 21:23:36 +02:00
Erik Eckstein
3e04b8681c
make ModulePassContext conform to CustomStringConvertible
...
and let its description return a dump of the whole module.
This is useful for debugging
2023-05-08 21:23:36 +02:00
Erik Eckstein
e95c6425f2
Swift SIL: add some APIs for global variables
2023-05-08 21:23:36 +02:00
Erik Eckstein
c4096bc723
Swift Optimizer: simplify builtin "once"
...
If the callee is side effect-free we can remove the whole builtin "once".
2023-05-08 21:23:36 +02:00
Erik Eckstein
9b51e69dac
Swift Optimizer: constant fold builtins in the simplification passes
2023-05-08 21:23:36 +02:00
Erik Eckstein
88973a3cd5
Swift Optimizer: add simplification for tuple_extract
...
Replace tuple_extract(tuple(x)) -> x
2023-05-08 21:23:36 +02:00
Erik Eckstein
5a3ab6ee2e
Swift Optimizer: add simplifications for destructure_struct and destructure_tuple
...
Eliminate the redundant instruction pair
```
%t = tuple (%0, %1, %2)
(%3, %4, %5) = destructure_tuple %t
```
and replace the results %3, %4, %5 with %0, %1, %2, respectively.
The same for structs.
2023-05-08 21:23:36 +02:00
Erik Eckstein
0a05124023
Swift Optimizer: add simplification of debug_step
...
When compiling with optimizations, unconditionally remove `debug_step`
2023-05-08 21:23:36 +02:00
Erik Eckstein
a8c9aae1e0
Swift Optimizer: add simplification for cond_fail
2023-05-08 21:23:36 +02:00
Erik Eckstein
8a8a895239
alias analysis: compute more precise memory effects of builtin "once"
...
* Check if the address in question is even visible from outside the function
* Return the memory effects of the called function
Also, add a new API `Instruction.memoryEffects`, which is internally used by `mayReadFromMemory` et al.
2023-05-08 21:23:36 +02:00
eeckstein
3bad9069a6
Merge pull request #65622 from eeckstein/improve-escape-utils
...
EscapeUtils: better handling of noescape closures and convert_function instructions
2023-05-04 07:54:23 +02:00
Erik Eckstein
5992e68d23
EscapeUtils: better handling of noescape closures and convert_function instructions
...
* Assume that a noescape closure argument cannot escape a called function
* Handle convert_function instructions
rdar://108837480
2023-05-03 19:53:19 +02:00
Erik Eckstein
da3f126322
CalleeAnalysis: no need to provide the PassManager to the getMemBehaviorFn
...
A NFC simplification
2023-05-03 14:33:45 +02:00
Alex Lorenz
220e6faad4
Revert "[cxx-interop][SwiftCompilerSources] Use swift::DiagnosticEngine instead of BridgedDiagnosticEngine"
...
This reverts commit e9dedf3c27 .
The revert is required as foreign reference types are available for SwiftStdlib 5.8 and above, but the Swift compiler
sources back deploy to older stdlibs as well.
2023-04-11 15:28:14 -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
Slava Pestov
3d9a79e4b1
Merge pull request #64777 from slavapestov/sil-optimizer-variadic-generics
...
SIL optimizer fixes for variadic generics
2023-04-03 11:30:03 -04:00
Slava Pestov
e24cbbc42f
SILOptimizer: Bridge new Pack_Inout, Pack_Owned, Pack_Guaranteed ownership kinds
2023-03-30 14:10:27 -04:00
Nate Chandler
fc13686403
[ObjCBridgingOpt] Look through copy_value insts.
2023-03-29 11:39:43 -07: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
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
Erik Eckstein
82d9da5981
Swift Bridging: use C++ instead of C bridging for BridgedMultiValueResult
2023-03-21 15:33:09 +01:00
Erik Eckstein
47ac2d2818
Swift Bridging: use C++ instead of C bridging for BridgedArgument
2023-03-21 15:33:09 +01:00
Erik Eckstein
7789b4063e
Swift Bridging: remove BridgedMemoryBehavior and use swift.MemoryBehavior instead
2023-03-21 15:33:09 +01:00