[Mlir-commits] [mlir] 863e812 - [mlir] Move attr -> properties to not require Operation

Jacques Pienaar llvmlistbot at llvm.org
Fri Jul 21 14:54:50 PDT 2023


Author: Jacques Pienaar
Date: 2023-07-21T14:54:43-07:00
New Revision: 863e8123df5e7dfb58af93e65e4da3ced96d358f

URL: https://github.com/llvm/llvm-project/commit/863e8123df5e7dfb58af93e65e4da3ced96d358f
DIFF: https://github.com/llvm/llvm-project/commit/863e8123df5e7dfb58af93e65e4da3ced96d358f.diff

LOG: [mlir] Move attr -> properties to not require Operation

This allows for converting before/without an Operation is created.

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

Added: 
    

Modified: 
    mlir/include/mlir/IR/ExtensibleDialect.h
    mlir/include/mlir/IR/OperationSupport.h
    mlir/lib/IR/MLIRContext.cpp
    mlir/lib/IR/Operation.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/ExtensibleDialect.h b/mlir/include/mlir/IR/ExtensibleDialect.h
index 4ca27ea509868c..9a35077017e436 100644
--- a/mlir/include/mlir/IR/ExtensibleDialect.h
+++ b/mlir/include/mlir/IR/ExtensibleDialect.h
@@ -24,6 +24,7 @@
 #include "mlir/IR/DialectInterface.h"
 #include "mlir/IR/MLIRContext.h"
 #include "mlir/IR/OpDefinition.h"
+#include "mlir/IR/OperationSupport.h"
 #include "mlir/Support/TypeID.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -485,7 +486,9 @@ class DynamicOpDefinition : public OperationName::Impl {
   void populateDefaultProperties(OperationName opName,
                                  OpaqueProperties properties) final {}
 
-  LogicalResult setPropertiesFromAttr(Operation *op, Attribute attr,
+  LogicalResult setPropertiesFromAttr(OperationName opName,
+                                      OpaqueProperties properties,
+                                      Attribute attr,
                                       InFlightDiagnostic *diag) final {
     return failure();
   }

diff  --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index 82efa9dfecacdf..303e0303a87fa0 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -136,7 +136,8 @@ class OperationName {
     virtual void deleteProperties(OpaqueProperties) = 0;
     virtual void populateDefaultProperties(OperationName opName,
                                            OpaqueProperties properties) = 0;
-    virtual LogicalResult setPropertiesFromAttr(Operation *, Attribute,
+    virtual LogicalResult setPropertiesFromAttr(OperationName, OpaqueProperties,
+                                                Attribute,
                                                 InFlightDiagnostic *) = 0;
     virtual Attribute getPropertiesAsAttr(Operation *) = 0;
     virtual void copyProperties(OpaqueProperties, OpaqueProperties) = 0;
@@ -215,8 +216,8 @@ class OperationName {
     void deleteProperties(OpaqueProperties) final;
     void populateDefaultProperties(OperationName opName,
                                    OpaqueProperties properties) final;
-    LogicalResult setPropertiesFromAttr(Operation *, Attribute,
-                                        InFlightDiagnostic *) final;
+    LogicalResult setPropertiesFromAttr(OperationName, OpaqueProperties,
+                                        Attribute, InFlightDiagnostic *) final;
     Attribute getPropertiesAsAttr(Operation *) final;
     void copyProperties(OpaqueProperties, OpaqueProperties) final;
     llvm::hash_code hashProperties(OpaqueProperties) final;
@@ -425,9 +426,11 @@ class OperationName {
 
   /// Define the op properties from the provided Attribute.
   LogicalResult
-  setOpPropertiesFromAttribute(Operation *op, Attribute properties,
+  setOpPropertiesFromAttribute(OperationName opName,
+                               OpaqueProperties properties, Attribute attr,
                                InFlightDiagnostic *diagnostic) const {
-    return getImpl()->setPropertiesFromAttr(op, properties, diagnostic);
+    return getImpl()->setPropertiesFromAttr(opName, properties, attr,
+                                            diagnostic);
   }
 
   void copyOpProperties(OpaqueProperties lhs, OpaqueProperties rhs) const {
@@ -614,11 +617,14 @@ class RegisteredOperationName : public OperationName {
                                               *properties.as<Properties *>());
     }
 
-    LogicalResult setPropertiesFromAttr(Operation *op, Attribute attr,
+    LogicalResult setPropertiesFromAttr(OperationName opName,
+                                        OpaqueProperties properties,
+                                        Attribute attr,
                                         InFlightDiagnostic *diag) final {
-      if constexpr (hasProperties)
-        return ConcreteOp::setPropertiesFromAttr(
-            cast<ConcreteOp>(op).getProperties(), attr, diag);
+      if constexpr (hasProperties) {
+        auto p = properties.as<Properties *>();
+        return ConcreteOp::setPropertiesFromAttr(*p, attr, diag);
+      }
       if (diag)
         *diag << "This operation does not support properties";
       return failure();

diff  --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
index bb309d509dbd6c..e19c3d4d54179b 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -24,6 +24,7 @@
 #include "mlir/IR/IntegerSet.h"
 #include "mlir/IR/Location.h"
 #include "mlir/IR/OpImplementation.h"
+#include "mlir/IR/OperationSupport.h"
 #include "mlir/IR/Types.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
@@ -850,8 +851,9 @@ void OperationName::UnregisteredOpModel::deleteProperties(
 void OperationName::UnregisteredOpModel::populateDefaultProperties(
     OperationName opName, OpaqueProperties properties) {}
 LogicalResult OperationName::UnregisteredOpModel::setPropertiesFromAttr(
-    Operation *op, Attribute attr, InFlightDiagnostic *diag) {
-  *op->getPropertiesStorage().as<Attribute *>() = attr;
+    OperationName opName, OpaqueProperties properties, Attribute attr,
+    InFlightDiagnostic *diag) {
+  *properties.as<Attribute *>() = attr;
   return success();
 }
 Attribute

diff  --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index 1c70bc3d218285..3453f9d1640674 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -361,7 +361,8 @@ Operation::setPropertiesFromAttribute(Attribute attr,
     *getPropertiesStorage().as<Attribute *>() = attr;
     return success();
   }
-  return info->setOpPropertiesFromAttribute(this, attr, diagnostic);
+  return info->setOpPropertiesFromAttribute(
+      this->getName(), this->getPropertiesStorage(), attr, diagnostic);
 }
 
 void Operation::copyProperties(OpaqueProperties rhs) {


        


More information about the Mlir-commits mailing list