[PATCH] D84826: [NewPM][PassInstrumentation] Add AfterPassSkipped callback
Yevgeny Rouban via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 28 22:44:56 PDT 2020
yrouban created this revision.
yrouban added reviewers: fedor.sergeev, kuhar, asbirlea.
Herald added a project: LLVM.
yrouban requested review of this revision.
//AfterPassSkipped// callback is added to have //BeforePass// callback correspond to some //After*// callback:
- //AfterPass// - if the pass ran
- //AfterPassInvalidated// - if the pass ran but invalidated the IRUnit
- //AfterPassSkipped// - if the pass was skipped because some of the //BeforePass// callbacks returned //false//.
These complete Before-After braces are needed for maintaining pass-related data structures in instrumentation passes. For example, stack of CFGs before passes in D81558 <https://reviews.llvm.org/D81558> that checks //PreserveCFG//: in //BeforePass// a CFG snapshot is created and pushed to the stack, then in //AfterPass// it is popped from the stack and compared with current CFG. Even if we do not need to compare CFG we need to push and pop it from the stack.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84826
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
@@ -75,7 +75,10 @@
// 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.
+ // For every Before callback called there is either After, AfterInvalidated
+ // or AfterSkipped call with the same pass name and IRUnit if available.
using BeforePassFunc = bool(StringRef, Any);
+ using AfterPassSkippedFunc = void(StringRef, Any);
using AfterPassFunc = void(StringRef, Any, const PreservedAnalyses &);
using AfterPassInvalidatedFunc = void(StringRef, const PreservedAnalyses &);
using BeforeAnalysisFunc = void(StringRef, Any);
@@ -92,6 +95,11 @@
BeforePassCallbacks.emplace_back(std::move(C));
}
+ template <typename CallableT>
+ void registerAfterPassSkippedCallback(CallableT C) {
+ AfterPassSkippedCallbacks.emplace_back(std::move(C));
+ }
+
template <typename CallableT> void registerAfterPassCallback(CallableT C) {
AfterPassCallbacks.emplace_back(std::move(C));
}
@@ -115,6 +123,8 @@
friend class PassInstrumentation;
SmallVector<llvm::unique_function<BeforePassFunc>, 4> BeforePassCallbacks;
+ SmallVector<llvm::unique_function<AfterPassSkippedFunc>, 4>
+ AfterPassSkippedCallbacks;
SmallVector<llvm::unique_function<AfterPassFunc>, 4> AfterPassCallbacks;
SmallVector<llvm::unique_function<AfterPassInvalidatedFunc>, 4>
AfterPassInvalidatedCallbacks;
@@ -169,6 +179,11 @@
for (auto &C : Callbacks->BeforePassCallbacks)
ShouldRun &= C(Pass.name(), llvm::Any(&IR));
ShouldRun = ShouldRun || isRequired(Pass);
+
+ if (!ShouldRun)
+ for (auto &C : Callbacks->AfterPassSkippedCallbacks)
+ C(Pass.name(), llvm::Any(&IR));
+
return ShouldRun;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84826.281471.patch
Type: text/x-patch
Size: 2009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200729/00b3a017/attachment.bin>
More information about the llvm-commits
mailing list