[llvm] ff554a9 - Let PassBuilder Expose PassInstrumentationCallbacks
Juneyoung Lee via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 6 21:10:44 PST 2020
Author: Juneyoung Lee
Date: 2020-01-07T14:10:37+09:00
New Revision: ff554a9179032167953595ca885a8fd12ac61036
URL: https://github.com/llvm/llvm-project/commit/ff554a9179032167953595ca885a8fd12ac61036
DIFF: https://github.com/llvm/llvm-project/commit/ff554a9179032167953595ca885a8fd12ac61036.diff
LOG: Let PassBuilder Expose PassInstrumentationCallbacks
Summary:
This is an effort to allowing external libraries register their own pass instrumentation during their llvmGetPassPluginInfo() calls.
By exposing this through the added getPIC(), now a pass writer can do something like this:
```
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo() {
return {
..,
[](llvm::PassBuilder &PB) {
PB.getPIC()->registerAfterPassCallback(move(f));
}
};
}
```
Reviewers: chandlerc, philip.pfaffe, fedor.sergeev
Reviewed By: fedor.sergeev
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71086
Added:
Modified:
llvm/include/llvm/Passes/PassBuilder.h
llvm/unittests/IR/PassBuilderCallbacksTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index 7fe03f72305b..e7db8fd421fe 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -631,6 +631,13 @@ class PassBuilder {
std::string ProfileFile,
std::string ProfileRemappingFile);
+
+ /// Returns PIC. External libraries can use this to register pass
+ /// instrumentation callbacks.
+ PassInstrumentationCallbacks *getPassInstrumentationCallbacks() const {
+ return PIC;
+ }
+
private:
static Optional<std::vector<PipelineElement>>
parsePipelineText(StringRef Text);
diff --git a/llvm/unittests/IR/PassBuilderCallbacksTest.cpp b/llvm/unittests/IR/PassBuilderCallbacksTest.cpp
index 7306257851a1..3f800b308e26 100644
--- a/llvm/unittests/IR/PassBuilderCallbacksTest.cpp
+++ b/llvm/unittests/IR/PassBuilderCallbacksTest.cpp
@@ -418,6 +418,9 @@ class PassBuilderCallbacksTest<PassManager<
PB(nullptr, PipelineTuningOptions(), None, &CallbacksHandle.Callbacks),
PM(true), LAM(true), FAM(true), CGAM(true), AM(true) {
+ EXPECT_TRUE(&CallbacksHandle.Callbacks ==
+ PB.getPassInstrumentationCallbacks());
+
/// Register a callback for analysis registration.
///
/// The callback is a function taking a reference to an AnalyisManager
More information about the llvm-commits
mailing list