Make delete notifications elective

This commit adds a hook that allows passes, analysis or data structures that can
be registered as receivers of delete notifications to decide if they want to
receive notifications All of the analysis and the currently executing passes are
automatically registered to receive notifications and this hook is useful in
reducing the runtime overhead. With this change the only analysis that accepts
notifications is alias analysis.
This commit is contained in:
Nadav Rotem
2015-12-07 15:59:57 -08:00
parent bef5b4301d
commit 9e311aff6c
4 changed files with 15 additions and 4 deletions

View File

@@ -17,7 +17,7 @@ namespace swift {
class ValueBase;
/// A protocol (or inferface) for handling value deletion notifications.
/// A protocol (or interface) for handling value deletion notifications.
///
/// This class is used as a base class for any class that need to accept
/// instruction deletion notification messages. This is used by passes and
@@ -30,6 +30,12 @@ struct DeleteNotificationHandler {
/// Handle the invalidation message for the value \p Value.
virtual void handleDeleteNotification(swift::ValueBase *Value) { }
/// Returns True if the pass, analysis or other entity wants to receive
/// notifications. This callback is called once when the class is being
/// registered, and not once per notification. Entities that implement
/// this callback should always return a constant answer (true/false).
virtual bool needsNotifications() { return false; }
};
} // end swift namespace

View File

@@ -117,6 +117,9 @@ private:
ValueBaseToIndex.invalidateValue(I);
}
virtual bool needsNotifications() override { return true; }
public:
AliasAnalysis(SILModule *M) :
SILAnalysis(AnalysisKind::Alias), Mod(M), SEA(nullptr) {}

View File

@@ -681,7 +681,11 @@ lookUpFunctionInVTable(ClassDecl *Class, SILDeclRef Member) {
void SILModule::
registerDeleteNotificationHandler(DeleteNotificationHandler* Handler) {
// Ask the handler (that can be an analysis, a pass, or some other data
// structure) if it wants to receive delete notifications.
if (Handler->needsNotifications()) {
NotificationHandlers.insert(Handler);
}
}
void SILModule::

View File

@@ -355,8 +355,6 @@ class SILCombine : public SILFunctionTransform {
}
}
virtual void handleDeleteNotification(ValueBase *I) override { }
StringRef getName() override { return "SIL Combine"; }
};