Skip to content

Commit 74ae66b

Browse files
authored
Merge pull request swiftlang#18725 from gottesmm/pr-1e9eaf3649841fc06185d9b353db89111ed4c380
[sil-pass-manager] Wire up pass manager to the new deserialization notification infrastructure.
2 parents 9b036b2 + aa11068 commit 74ae66b

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

include/swift/SILOptimizer/PassManager/PassManager.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "swift/SIL/Notifications.h"
1314
#include "swift/SILOptimizer/Analysis/Analysis.h"
1415
#include "swift/SILOptimizer/PassManager/PassPipeline.h"
1516
#include "swift/SILOptimizer/PassManager/Passes.h"
@@ -101,6 +102,14 @@ class SILPassManager {
101102
/// The IRGen SIL passes. These have to be dynamically added by IRGen.
102103
llvm::DenseMap<unsigned, SILTransform *> IRGenPasses;
103104

105+
/// The notification handler for this specific SILPassManager.
106+
///
107+
/// This is not owned by the pass manager, it is owned by the SILModule which
108+
/// is guaranteed to outlive any pass manager associated with it. We keep this
109+
/// bare pointer to ensure that we can deregister the notification after this
110+
/// pass manager is destroyed.
111+
DeserializationNotificationHandler *deserializationNotificationHandler;
112+
104113
public:
105114
/// C'tor. It creates and registers all analysis passes, which are defined
106115
/// in Analysis.def.

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,36 @@ class DebugPrintEnabler {
230230
}
231231
};
232232

233+
//===----------------------------------------------------------------------===//
234+
// Serialization Notification Implementation
235+
//===----------------------------------------------------------------------===//
236+
237+
namespace {
238+
239+
class PassManagerDeserializationNotificationHandler final
240+
: public DeserializationNotificationHandler {
241+
NullablePtr<SILPassManager> pm;
242+
243+
public:
244+
PassManagerDeserializationNotificationHandler(SILPassManager *pm) : pm(pm) {}
245+
~PassManagerDeserializationNotificationHandler() override = default;
246+
247+
StringRef getName() const override {
248+
return "PassManagerDeserializationNotificationHandler";
249+
}
250+
251+
/// Observe that we deserialized a function declaration.
252+
void didDeserialize(ModuleDecl *mod, SILFunction *fn) override {
253+
pm.get()->notifyAnalysisOfFunction(fn);
254+
}
255+
};
256+
257+
} // end anonymous namespace
233258

234259
SILPassManager::SILPassManager(SILModule *M, llvm::StringRef Stage,
235-
bool isMandatoryPipeline) :
236-
Mod(M), StageName(Stage), isMandatoryPipeline(isMandatoryPipeline) {
237-
260+
bool isMandatoryPipeline)
261+
: Mod(M), StageName(Stage), isMandatoryPipeline(isMandatoryPipeline),
262+
deserializationNotificationHandler(nullptr) {
238263
#define ANALYSIS(NAME) \
239264
Analyses.push_back(create##NAME##Analysis(Mod));
240265
#include "swift/SILOptimizer/Analysis/Analysis.def"
@@ -243,6 +268,11 @@ SILPassManager::SILPassManager(SILModule *M, llvm::StringRef Stage,
243268
A->initialize(this);
244269
M->registerDeleteNotificationHandler(A);
245270
}
271+
272+
std::unique_ptr<DeserializationNotificationHandler> handler(
273+
new PassManagerDeserializationNotificationHandler(this));
274+
deserializationNotificationHandler = handler.get();
275+
M->registerDeserializationNotificationHandler(std::move(handler));
246276
}
247277

248278
SILPassManager::SILPassManager(SILModule *M, irgen::IRGenModule *IRMod,
@@ -539,6 +569,10 @@ SILPassManager::~SILPassManager() {
539569
assert(IRGenPasses.empty() && "Must add IRGen SIL passes that were "
540570
"registered to the list of transformations");
541571

572+
// Remove our deserialization notification handler.
573+
Mod->removeDeserializationNotificationHandler(
574+
deserializationNotificationHandler);
575+
542576
// Free all transformations.
543577
for (auto *T : Transformations)
544578
delete T;

0 commit comments

Comments
 (0)