Let PassBuilder Expose PassInstrumentationCallbacks
authorJuneyoung Lee <aqjune@gmail.com>
Tue, 7 Jan 2020 05:04:32 +0000 (14:04 +0900)
committerJuneyoung Lee <aqjune@gmail.com>
Tue, 7 Jan 2020 05:10:37 +0000 (14:10 +0900)
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

llvm/include/llvm/Passes/PassBuilder.h
llvm/unittests/IR/PassBuilderCallbacksTest.cpp

index 7fe03f7..e7db8fd 100644 (file)
@@ -631,6 +631,13 @@ public:
                               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);
index 7306257..3f800b3 100644 (file)
@@ -418,6 +418,9 @@ protected:
         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