[Mlir-commits] [mlir] 69b6454 - [mlir] Plumb through default attribute populate for extensible dialect.

Jacques Pienaar llvmlistbot at llvm.org
Wed Jul 13 09:05:10 PDT 2022


Author: Jacques Pienaar
Date: 2022-07-13T09:05:04-07:00
New Revision: 69b6454fff872fecb936d5f0388a837d15a24933

URL: https://github.com/llvm/llvm-project/commit/69b6454fff872fecb936d5f0388a837d15a24933
DIFF: https://github.com/llvm/llvm-project/commit/69b6454fff872fecb936d5f0388a837d15a24933.diff

LOG: [mlir] Plumb through default attribute populate for extensible dialect.

Added: 
    

Modified: 
    mlir/include/mlir/IR/ExtensibleDialect.h
    mlir/lib/IR/ExtensibleDialect.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/ExtensibleDialect.h b/mlir/include/mlir/IR/ExtensibleDialect.h
index 65f9f190f57ec..84dc56749e775 100644
--- a/mlir/include/mlir/IR/ExtensibleDialect.h
+++ b/mlir/include/mlir/IR/ExtensibleDialect.h
@@ -362,7 +362,8 @@ class DynamicOpDefinition {
       OperationName::PrintAssemblyFn &&printFn,
       OperationName::FoldHookFn &&foldHookFn,
       OperationName::GetCanonicalizationPatternsFn
-          &&getCanonicalizationPatternsFn);
+          &&getCanonicalizationPatternsFn,
+      OperationName::PopulateDefaultAttrsFn &&populateDefaultAttrsFn);
 
   /// Returns the op typeID.
   TypeID getTypeID() { return typeID; }
@@ -405,15 +406,23 @@ class DynamicOpDefinition {
     getCanonicalizationPatternsFn = std::move(getCanonicalizationPatterns);
   }
 
+  /// Set the hook populating default attributes.
+  void setPopulateDefaultAttrsFn(
+      OperationName::PopulateDefaultAttrsFn &&populateDefaultAttrs) {
+    populateDefaultAttrsFn = std::move(populateDefaultAttrs);
+  }
+
 private:
-  DynamicOpDefinition(StringRef name, ExtensibleDialect *dialect,
-                      OperationName::VerifyInvariantsFn &&verifyFn,
-                      OperationName::VerifyRegionInvariantsFn &&verifyRegionFn,
-                      OperationName::ParseAssemblyFn &&parseFn,
-                      OperationName::PrintAssemblyFn &&printFn,
-                      OperationName::FoldHookFn &&foldHookFn,
-                      OperationName::GetCanonicalizationPatternsFn
-                          &&getCanonicalizationPatternsFn);
+  DynamicOpDefinition(
+      StringRef name, ExtensibleDialect *dialect,
+      OperationName::VerifyInvariantsFn &&verifyFn,
+      OperationName::VerifyRegionInvariantsFn &&verifyRegionFn,
+      OperationName::ParseAssemblyFn &&parseFn,
+      OperationName::PrintAssemblyFn &&printFn,
+      OperationName::FoldHookFn &&foldHookFn,
+      OperationName::GetCanonicalizationPatternsFn
+          &&getCanonicalizationPatternsFn,
+      OperationName::PopulateDefaultAttrsFn &&populateDefaultAttrsFn);
 
   /// Unique identifier for this operation.
   TypeID typeID;
@@ -431,7 +440,7 @@ class DynamicOpDefinition {
   OperationName::PrintAssemblyFn printFn;
   OperationName::FoldHookFn foldHookFn;
   OperationName::GetCanonicalizationPatternsFn getCanonicalizationPatternsFn;
-  OperationName::PopulateDefaultAttrsFn getPopulateDefaultAttrsFn;
+  OperationName::PopulateDefaultAttrsFn populateDefaultAttrsFn;
 
   friend ExtensibleDialect;
 };

diff  --git a/mlir/lib/IR/ExtensibleDialect.cpp b/mlir/lib/IR/ExtensibleDialect.cpp
index 0dcc971ca2e5a..148ba9f04f1a4 100644
--- a/mlir/lib/IR/ExtensibleDialect.cpp
+++ b/mlir/lib/IR/ExtensibleDialect.cpp
@@ -295,13 +295,15 @@ DynamicOpDefinition::DynamicOpDefinition(
     OperationName::PrintAssemblyFn &&printFn,
     OperationName::FoldHookFn &&foldHookFn,
     OperationName::GetCanonicalizationPatternsFn
-        &&getCanonicalizationPatternsFn)
+        &&getCanonicalizationPatternsFn,
+    OperationName::PopulateDefaultAttrsFn &&populateDefaultAttrsFn)
     : typeID(dialect->allocateTypeID()),
       name((dialect->getNamespace() + "." + name).str()), dialect(dialect),
       verifyFn(std::move(verifyFn)), verifyRegionFn(std::move(verifyRegionFn)),
       parseFn(std::move(parseFn)), printFn(std::move(printFn)),
       foldHookFn(std::move(foldHookFn)),
-      getCanonicalizationPatternsFn(std::move(getCanonicalizationPatternsFn)) {}
+      getCanonicalizationPatternsFn(std::move(getCanonicalizationPatternsFn)),
+      populateDefaultAttrsFn(std::move(populateDefaultAttrsFn)) {}
 
 std::unique_ptr<DynamicOpDefinition> DynamicOpDefinition::get(
     StringRef name, ExtensibleDialect *dialect,
@@ -336,25 +338,31 @@ std::unique_ptr<DynamicOpDefinition> DynamicOpDefinition::get(
   auto getCanonicalizationPatternsFn = [](RewritePatternSet &, MLIRContext *) {
   };
 
+  auto populateDefaultAttrsFn = [](const RegisteredOperationName &,
+                                   NamedAttrList &) {};
+
   return DynamicOpDefinition::get(name, dialect, std::move(verifyFn),
                                   std::move(verifyRegionFn), std::move(parseFn),
                                   std::move(printFn), std::move(foldHookFn),
-                                  std::move(getCanonicalizationPatternsFn));
+                                  std::move(getCanonicalizationPatternsFn),
+                                  std::move(populateDefaultAttrsFn));
 }
 
-std::unique_ptr<DynamicOpDefinition>
-DynamicOpDefinition::get(StringRef name, ExtensibleDialect *dialect,
-                         OperationName::VerifyInvariantsFn &&verifyFn,
-                         OperationName::VerifyInvariantsFn &&verifyRegionFn,
-                         OperationName::ParseAssemblyFn &&parseFn,
-                         OperationName::PrintAssemblyFn &&printFn,
-                         OperationName::FoldHookFn &&foldHookFn,
-                         OperationName::GetCanonicalizationPatternsFn
-                             &&getCanonicalizationPatternsFn) {
+std::unique_ptr<DynamicOpDefinition> DynamicOpDefinition::get(
+    StringRef name, ExtensibleDialect *dialect,
+    OperationName::VerifyInvariantsFn &&verifyFn,
+    OperationName::VerifyInvariantsFn &&verifyRegionFn,
+    OperationName::ParseAssemblyFn &&parseFn,
+    OperationName::PrintAssemblyFn &&printFn,
+    OperationName::FoldHookFn &&foldHookFn,
+    OperationName::GetCanonicalizationPatternsFn
+        &&getCanonicalizationPatternsFn,
+    OperationName::PopulateDefaultAttrsFn &&populateDefaultAttrsFn) {
   return std::unique_ptr<DynamicOpDefinition>(new DynamicOpDefinition(
       name, dialect, std::move(verifyFn), std::move(verifyRegionFn),
       std::move(parseFn), std::move(printFn), std::move(foldHookFn),
-      std::move(getCanonicalizationPatternsFn)));
+      std::move(getCanonicalizationPatternsFn),
+      std::move(populateDefaultAttrsFn)));
 }
 
 //===----------------------------------------------------------------------===//
@@ -448,7 +456,7 @@ void ExtensibleDialect::registerDynamicOp(
       std::move(op->verifyRegionFn), std::move(op->foldHookFn),
       std::move(op->getCanonicalizationPatternsFn),
       detail::InterfaceMap::get<>(), std::move(hasTraitFn), {},
-      std::move(op->getPopulateDefaultAttrsFn));
+      std::move(op->populateDefaultAttrsFn));
 }
 
 bool ExtensibleDialect::classof(const Dialect *dialect) {


        


More information about the Mlir-commits mailing list