mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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
This commit is contained in:
@@ -18,7 +18,7 @@ import OptimizerBridging
|
||||
/// It provides access to all functions, v-tables and witness tables of a module,
|
||||
/// but it doesn't provide any APIs to modify functions.
|
||||
/// In order to modify a function, a module pass must use `transform(function:)`.
|
||||
struct ModulePassContext {
|
||||
struct ModulePassContext : Context {
|
||||
let _bridged: BridgedPassContext
|
||||
|
||||
struct FunctionList : CollectionLikeSequence, IteratorProtocol {
|
||||
@@ -91,15 +91,13 @@ struct ModulePassContext {
|
||||
DefaultWitnessTableList(first: PassContext_firstDefaultWitnessTableInModule(_bridged).table)
|
||||
}
|
||||
|
||||
var options: Options { Options(_bridged: _bridged) }
|
||||
|
||||
/// Run a closure with a `PassContext` for a function, which allows to modify that function.
|
||||
///
|
||||
/// Only a single `transform` can be alive at the same time, i.e. it's not allowed to nest
|
||||
/// calls to `transform`.
|
||||
func transform(function: Function, _ runOnFunction: (PassContext) -> ()) {
|
||||
func transform(function: Function, _ runOnFunction: (FunctionPassContext) -> ()) {
|
||||
PassContext_beginTransformFunction(function.bridged, _bridged)
|
||||
runOnFunction(PassContext(_bridged: _bridged))
|
||||
runOnFunction(FunctionPassContext(_bridged: _bridged))
|
||||
PassContext_endTransformFunction(_bridged);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user