[PATCH] D84772: [NewPM][PassInstrument] Add a new kind of before-pass callback that only get called if the pass is not skipped
Yuanfang Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 28 11:54:04 PDT 2020
ychen updated this revision to Diff 281316.
ychen edited the summary of this revision.
ychen added a comment.
- Use BeforeNonSkippedPassFunc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D84772/new/
https://reviews.llvm.org/D84772
Files:
llvm/include/llvm/IR/PassInstrumentation.h
Index: llvm/include/llvm/IR/PassInstrumentation.h
===================================================================
--- llvm/include/llvm/IR/PassInstrumentation.h
+++ llvm/include/llvm/IR/PassInstrumentation.h
@@ -67,11 +67,14 @@
// to take them as constant pointers, wrapped with llvm::Any.
// For the case when IRUnit has been invalidated there is a different
// callback to use - AfterPassInvalidated.
+ // BeforeNonSkippedPassFunc is called when we know for sure that the pass
+ // would be run. BeforePassFunc could not make such assumption.
// TODO: currently AfterPassInvalidated does not accept IRUnit, since passing
- // already invalidated IRUnit is unsafe. There are ways to handle invalidated IRUnits
- // in a safe way, and we might pursue that as soon as there is a useful instrumentation
- // that needs it.
+ // already invalidated IRUnit is unsafe. There are ways to handle invalidated
+ // IRUnits in a safe way, and we might pursue that as soon as there is a
+ // useful instrumentation that needs it.
using BeforePassFunc = bool(StringRef, Any);
+ using BeforeNonSkippedPassFunc = void(StringRef, Any);
using AfterPassFunc = void(StringRef, Any);
using AfterPassInvalidatedFunc = void(StringRef);
using BeforeAnalysisFunc = void(StringRef, Any);
@@ -88,6 +91,11 @@
BeforePassCallbacks.emplace_back(std::move(C));
}
+ template <typename CallableT>
+ void registerBeforeNonSkippedPassCallback(CallableT C) {
+ BeforeNonSkippedPassCallbacks.emplace_back(std::move(C));
+ }
+
template <typename CallableT> void registerAfterPassCallback(CallableT C) {
AfterPassCallbacks.emplace_back(std::move(C));
}
@@ -111,6 +119,8 @@
friend class PassInstrumentation;
SmallVector<llvm::unique_function<BeforePassFunc>, 4> BeforePassCallbacks;
+ SmallVector<llvm::unique_function<BeforeNonSkippedPassFunc>, 4>
+ BeforeNonSkippedPassCallbacks;
SmallVector<llvm::unique_function<AfterPassFunc>, 4> AfterPassCallbacks;
SmallVector<llvm::unique_function<AfterPassInvalidatedFunc>, 4>
AfterPassInvalidatedCallbacks;
@@ -165,6 +175,12 @@
for (auto &C : Callbacks->BeforePassCallbacks)
ShouldRun &= C(Pass.name(), llvm::Any(&IR));
ShouldRun = ShouldRun || isRequired(Pass);
+
+ if (ShouldRun) {
+ for (auto &C : Callbacks->BeforeNonSkippedPassCallbacks)
+ C(Pass.name(), llvm::Any(&IR));
+ }
+
return ShouldRun;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84772.281316.patch
Type: text/x-patch
Size: 2443 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200728/0cc9393b/attachment.bin>
More information about the llvm-commits
mailing list