Skip to content

Commit a415d87

Browse files
committed
Register deserialization notification handlers in ome only once
1 parent 9c9a8ef commit a415d87

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

include/swift/SIL/SILModule.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,15 @@ class SILModule {
263263
/// to ensure that the module is serialized only once.
264264
bool serialized;
265265

266+
/// Set if we have registered a deserialization notification handler for
267+
/// lowering ownership in non transparent functions.
268+
/// This gets set in NonTransparent OwnershipModelEliminator pass.
269+
bool regDeserializationNotificationHandlerForNonTransparentFuncOME;
270+
/// Set if we have registered a deserialization notification handler for
271+
/// lowering ownership in transparent functions.
272+
/// This gets set in OwnershipModelEliminator pass.
273+
bool regDeserializationNotificationHandlerForAllFuncOME;
274+
266275
/// Action to be executed for serializing the SILModule.
267276
ActionCallback SerializeSILAction;
268277

@@ -301,6 +310,19 @@ class SILModule {
301310
deserializationNotificationHandlers.erase(handler);
302311
}
303312

313+
bool hasRegisteredDeserializationNotificationHandlerForNonTransparentFuncOME() {
314+
return regDeserializationNotificationHandlerForNonTransparentFuncOME;
315+
}
316+
bool hasRegisteredDeserializationNotificationHandlerForAllFuncOME() {
317+
return regDeserializationNotificationHandlerForAllFuncOME;
318+
}
319+
void setRegisteredDeserializationNotificationHandlerForNonTransparentFuncOME() {
320+
regDeserializationNotificationHandlerForNonTransparentFuncOME = true;
321+
}
322+
void setRegisteredDeserializationNotificationHandlerForAllFuncOME() {
323+
regDeserializationNotificationHandlerForAllFuncOME = true;
324+
}
325+
304326
/// Add a delete notification handler \p Handler to the module context.
305327
void registerDeleteNotificationHandler(DeleteNotificationHandler* Handler);
306328

lib/SIL/IR/SILModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class SILModule::SerializationCallback final
9595
SILModule::SILModule(llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
9696
Lowering::TypeConverter &TC, const SILOptions &Options)
9797
: Stage(SILStage::Raw), Options(Options), serialized(false),
98+
regDeserializationNotificationHandlerForNonTransparentFuncOME(false),
99+
regDeserializationNotificationHandlerForAllFuncOME(false),
98100
SerializeSILAction(), Types(TC) {
99101
assert(!context.isNull());
100102
if (auto *file = context.dyn_cast<FileUnit *>()) {

lib/SILOptimizer/Mandatory/OwnershipModelEliminator.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,19 @@ struct OwnershipModelEliminator : SILFunctionTransform {
432432
FunctionBodyDeserializationNotificationHandler;
433433
std::unique_ptr<DeserializationNotificationHandler> ptr;
434434
if (SkipTransparent) {
435-
ptr.reset(new NotificationHandlerTy(
436-
prepareNonTransparentSILFunctionForOptimization));
435+
if (!Mod.hasRegisteredDeserializationNotificationHandlerForNonTransparentFuncOME()) {
436+
ptr.reset(new NotificationHandlerTy(
437+
prepareNonTransparentSILFunctionForOptimization));
438+
Mod.registerDeserializationNotificationHandler(std::move(ptr));
439+
Mod.setRegisteredDeserializationNotificationHandlerForNonTransparentFuncOME();
440+
}
437441
} else {
438-
ptr.reset(new NotificationHandlerTy(prepareSILFunctionForOptimization));
442+
if (!Mod.hasRegisteredDeserializationNotificationHandlerForAllFuncOME()) {
443+
ptr.reset(new NotificationHandlerTy(prepareSILFunctionForOptimization));
444+
Mod.registerDeserializationNotificationHandler(std::move(ptr));
445+
Mod.setRegisteredDeserializationNotificationHandlerForAllFuncOME();
446+
}
439447
}
440-
Mod.registerDeserializationNotificationHandler(std::move(ptr));
441448
}
442449
};
443450

0 commit comments

Comments
 (0)