[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 10:33:23 PDT 2020


ychen created this revision.
ychen added reviewers: asbirlea, aeubanks, hans.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
ychen requested review of this revision.

- PrintIRInstrumentation and TimePassesHandler would be using this new

callback.

- "Running pass" logging will also be moved to use this callback.


Repository:
  rG LLVM Github Monorepo

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.
+  // BeforePassRunFunc 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 BeforePassRunFunc = 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 registerBeforePassRunCallback(CallableT C) {
+    BeforePassRunCallbacks.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<BeforePassRunFunc>, 4>
+      BeforePassRunCallbacks;
   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->BeforePassRunCallbacks)
+        C(Pass.name(), llvm::Any(&IR));
+    }
+
     return ShouldRun;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84772.281285.patch
Type: text/x-patch
Size: 2394 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200728/d78ef91f/attachment.bin>


More information about the llvm-commits mailing list