Skip to content

Commit 3d7cdb9

Browse files
authored
Merge pull request #69308 from atrick/510-fix-deserialize-access
[5.10] Fix deserialization to avoid invoking a pass N times per function
2 parents 4c2c3d3 + db8917e commit 3d7cdb9

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
@@ -390,6 +390,10 @@ class SILModule {
390390
/// This gets set in OwnershipModelEliminator pass.
391391
bool regDeserializationNotificationHandlerForAllFuncOME;
392392

393+
// True if a DeserializationNotificationHandler is set for
394+
// AccessMarkerElimination.
395+
bool hasAccessMarkerHandler;
396+
393397
bool prespecializedFunctionDeclsImported;
394398

395399
/// Action to be executed for serializing the SILModule.
@@ -442,6 +446,13 @@ class SILModule {
442446
regDeserializationNotificationHandlerForAllFuncOME = true;
443447
}
444448

449+
bool checkHasAccessMarkerHandler() {
450+
return hasAccessMarkerHandler;
451+
}
452+
void setHasAccessMarkerHandler() {
453+
hasAccessMarkerHandler = true;
454+
}
455+
445456
/// Returns the instruction which defines the given root local archetype,
446457
/// e.g. an open_existential_addr.
447458
///

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)