Skip to content

Commit f1bec99

Browse files
authored
Merge pull request #69250 from atrick/fix-deserialize-access
Fix deserialization to avoid invoking a pass N times per function
2 parents 407ebdc + ef29250 commit f1bec99

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

include/swift/SIL/SILModule.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ class SILModule {
393393
/// This gets set in OwnershipModelEliminator pass.
394394
bool regDeserializationNotificationHandlerForAllFuncOME;
395395

396+
// True if a DeserializationNotificationHandler is set for
397+
// AccessMarkerElimination.
398+
bool hasAccessMarkerHandler;
399+
396400
bool prespecializedFunctionDeclsImported;
397401

398402
/// Action to be executed for serializing the SILModule.
@@ -445,6 +449,13 @@ class SILModule {
445449
regDeserializationNotificationHandlerForAllFuncOME = true;
446450
}
447451

452+
bool checkHasAccessMarkerHandler() {
453+
return hasAccessMarkerHandler;
454+
}
455+
void setHasAccessMarkerHandler() {
456+
hasAccessMarkerHandler = true;
457+
}
458+
448459
/// Returns the instruction which defines the given root local archetype,
449460
/// e.g. an open_existential_addr.
450461
///

lib/SIL/IR/SILModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ SILModule::SILModule(llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
100100
irgenOptions(irgenOptions), serialized(false),
101101
regDeserializationNotificationHandlerForNonTransparentFuncOME(false),
102102
regDeserializationNotificationHandlerForAllFuncOME(false),
103+
hasAccessMarkerHandler(false),
103104
prespecializedFunctionDeclsImported(false), SerializeSILAction(),
104105
Types(TC) {
105106
assert(!context.isNull());

lib/SILOptimizer/Mandatory/AccessMarkerElimination.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,16 @@ struct AccessMarkerEliminationPass : SILModuleTransform {
183183
auto InvalidKind = SILAnalysis::InvalidationKind::Instructions;
184184
invalidateAnalysis(&F, InvalidKind);
185185
}
186-
187-
// Markers from all current SIL functions are stripped. Register a
188-
// callback to strip an subsequently loaded functions on-the-fly.
189-
if (!EnableOptimizedAccessMarkers) {
190-
using NotificationHandlerTy =
191-
FunctionBodyDeserializationNotificationHandler;
192-
auto *n = new NotificationHandlerTy(prepareSILFunctionForOptimization);
193-
std::unique_ptr<DeserializationNotificationHandler> ptr(n);
194-
M.registerDeserializationNotificationHandler(std::move(ptr));
195-
}
186+
}
187+
// Markers from all current SIL functions are stripped. Register a
188+
// callback to strip an subsequently loaded functions on-the-fly.
189+
if (!EnableOptimizedAccessMarkers && !M.checkHasAccessMarkerHandler()) {
190+
using NotificationHandlerTy =
191+
FunctionBodyDeserializationNotificationHandler;
192+
auto *n = new NotificationHandlerTy(prepareSILFunctionForOptimization);
193+
std::unique_ptr<DeserializationNotificationHandler> ptr(n);
194+
M.registerDeserializationNotificationHandler(std::move(ptr));
195+
M.setHasAccessMarkerHandler();
196196
}
197197
}
198198
};

0 commit comments

Comments
 (0)