[Mlir-commits] [mlir] 43a8943 - Remove deprecated registration APIs (NFC)

Mehdi Amini llvmlistbot at llvm.org
Wed Sep 1 11:53:42 PDT 2021


Author: Mehdi Amini
Date: 2021-09-01T18:53:30Z
New Revision: 43a894365e6c0ac3641f8b49e77e81c20d1992f2

URL: https://github.com/llvm/llvm-project/commit/43a894365e6c0ac3641f8b49e77e81c20d1992f2
DIFF: https://github.com/llvm/llvm-project/commit/43a894365e6c0ac3641f8b49e77e81c20d1992f2.diff

LOG: Remove deprecated registration APIs (NFC)

In D104421, we changed the API for pass registration.
Before you would write:

      void registerPass("my-pass", "My Pass Description.",
                        [] { return createMyPass(); });
while now you’d only write:

      void registerPass([] { return createMyPass(); });

If you’re using TableGen to define your pass registration, you shouldn’t have anything to do. If you’re using directly the C++ API here are some changes.
Your project may also be broken even if you use TableGen and you call the
generated registration API in case your pass implementation didn’t inherit from
the MyPassBase class generated by TableGen.

If you don't use TableGen, the "my-pass" and "My Pass Description." fields must
be provided by overriding methods on the pass itself:

  llvm::StringRef getArgument() const final { return "my-pass"; }
  llvm::StringRef getDescription() const final {
    return "My Pass Description.";
  }

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D104429

Added: 
    

Modified: 
    mlir/include/mlir/Pass/PassRegistry.h
    mlir/lib/Pass/PassRegistry.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Pass/PassRegistry.h b/mlir/include/mlir/Pass/PassRegistry.h
index 449889b91781..8e07fc3f1920 100644
--- a/mlir/include/mlir/Pass/PassRegistry.h
+++ b/mlir/include/mlir/Pass/PassRegistry.h
@@ -123,12 +123,6 @@ void registerPassPipeline(
     std::function<void(function_ref<void(const detail::PassOptions &)>)>
         optHandler);
 
-/// Register a specific dialect pass allocator function with the system,
-/// typically used through the PassRegistration template.
-/// Deprecated: please use the alternate version below.
-void registerPass(StringRef arg, StringRef description,
-                  const PassAllocatorFunction &function);
-
 /// Register a specific dialect pass allocator function with the system,
 /// typically used through the PassRegistration template.
 void registerPass(const PassAllocatorFunction &function);
@@ -149,17 +143,6 @@ template <typename ConcretePass> struct PassRegistration {
   }
   PassRegistration()
       : PassRegistration([] { return std::make_unique<ConcretePass>(); }) {}
-
-  /// Constructor below are deprecated.
-
-  PassRegistration(StringRef arg, StringRef description,
-                   const PassAllocatorFunction &constructor) {
-    registerPass(arg, description, constructor);
-  }
-
-  PassRegistration(StringRef arg, StringRef description)
-      : PassRegistration(arg, description,
-                         [] { return std::make_unique<ConcretePass>(); }) {}
 };
 
 /// PassPipelineRegistration provides a global initializer that registers a Pass

diff  --git a/mlir/lib/Pass/PassRegistry.cpp b/mlir/lib/Pass/PassRegistry.cpp
index b3b94e5cda02..0530ec7f4829 100644
--- a/mlir/lib/Pass/PassRegistry.cpp
+++ b/mlir/lib/Pass/PassRegistry.cpp
@@ -107,14 +107,19 @@ PassInfo::PassInfo(StringRef arg, StringRef description,
             optHandler(allocator()->passOptions);
           }) {}
 
-void mlir::registerPass(StringRef arg, StringRef description,
-                        const PassAllocatorFunction &function) {
+void mlir::registerPass(const PassAllocatorFunction &function) {
+  std::unique_ptr<Pass> pass = function();
+  StringRef arg = pass->getArgument();
+  if (arg.empty())
+    llvm::report_fatal_error(
+        "Trying to register a pass that does not override `getArgument()`");
+  StringRef description = pass->getDescription();
   PassInfo passInfo(arg, description, function);
   passRegistry->try_emplace(arg, passInfo);
 
   // Verify that the registered pass has the same ID as any registered to this
   // arg before it.
-  TypeID entryTypeID = function()->getTypeID();
+  TypeID entryTypeID = pass->getTypeID();
   auto it = passRegistryTypeIDs->try_emplace(arg, entryTypeID).first;
   if (it->second != entryTypeID)
     llvm::report_fatal_error(
@@ -123,16 +128,6 @@ void mlir::registerPass(StringRef arg, StringRef description,
         arg);
 }
 
-void mlir::registerPass(const PassAllocatorFunction &function) {
-  std::unique_ptr<Pass> pass = function();
-  StringRef arg = pass->getArgument();
-  if (arg.empty())
-    llvm::report_fatal_error(
-        "Trying to register a pass that does not override `getArgument()`: " +
-        pass->getName());
-  registerPass(arg, pass->getDescription(), function);
-}
-
 /// Returns the pass info for the specified pass argument or null if unknown.
 const PassInfo *mlir::Pass::lookupPassInfo(StringRef passArg) {
   auto it = passRegistry->find(passArg);


        


More information about the Mlir-commits mailing list