Skip to content

Commit 12e6719

Browse files
committed
SwiftCompilerSources: add Context.notifyDependency(onBodyOf:)
It notifies the pass manager that the optimization result of the current pass depends on the body (i.e. SIL instructions) of another function than the currently optimized one.
1 parent e102a63 commit 12e6719

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyBuiltin.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ private extension BuiltinInst {
101101
guard let callee = calleeOfOnce, callee.isDefinition else {
102102
return
103103
}
104+
context.notifyDependency(onBodyOf: callee)
105+
104106
// If the callee is side effect-free we can remove the whole builtin "once".
105107
// We don't use the callee's memory effects but instead look at all callee instructions
106108
// because memory effects are not computed in the Onone pipeline, yet.

SwiftCompilerSources/Sources/Optimizer/PassManager/Context.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ extension MutatingContext {
210210
func notifyBranchesChanged() {
211211
_bridged.asNotificationHandler().notifyChanges(.branchesChanged)
212212
}
213+
214+
/// Notifies the pass manager that the optimization result of the current pass depends
215+
/// on the body (i.e. SIL instructions) of another function than the currently optimized one.
216+
func notifyDependency(onBodyOf otherFunction: Function) {
217+
_bridged.notifyDependencyOnBodyOf(otherFunction.bridged)
218+
}
213219
}
214220

215221
/// The context which is passed to the run-function of a FunctionPass.

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ struct BridgedPassContext {
171171

172172
SWIFT_IMPORT_UNSAFE BridgedOwnedString getModuleDescription() const;
173173
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedChangeNotificationHandler asNotificationHandler() const;
174+
BRIDGED_INLINE void notifyDependencyOnBodyOf(BridgedFunction otherFunction) const;
174175
BRIDGED_INLINE SILStage getSILStage() const;
175176
BRIDGED_INLINE bool hadError() const;
176177
BRIDGED_INLINE bool moduleIsSerialized() const;

include/swift/SILOptimizer/OptimizerBridgingImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ BridgedChangeNotificationHandler BridgedPassContext::asNotificationHandler() con
137137
return {invocation};
138138
}
139139

140+
void BridgedPassContext::notifyDependencyOnBodyOf(BridgedFunction otherFunction) const {
141+
// Currently `otherFunction` is ignored. We could design a more accurate dependency system
142+
// in the pass manager, which considers the actual function. But it's probaboly not worth the effort.
143+
invocation->getPassManager()->setDependingOnCalleeBodies();
144+
}
145+
140146
BridgedPassContext::SILStage BridgedPassContext::getSILStage() const {
141147
return (SILStage)invocation->getPassManager()->getModule()->getStage();
142148
}

0 commit comments

Comments
 (0)