diff --git a/mlir/include/mlir/IR/ExtensibleDialect.h b/mlir/include/mlir/IR/ExtensibleDialect.h --- 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 @@ 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 --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -136,7 +136,8 @@ 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 @@ 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 @@ /// 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 @@ *properties.as()); } - LogicalResult setPropertiesFromAttr(Operation *op, Attribute attr, + LogicalResult setPropertiesFromAttr(OperationName opName, + OpaqueProperties properties, + Attribute attr, InFlightDiagnostic *diag) final { - if constexpr (hasProperties) - return ConcreteOp::setPropertiesFromAttr( - cast(op).getProperties(), attr, diag); + if constexpr (hasProperties) { + auto p = properties.as(); + 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 --- 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::populateDefaultProperties( OperationName opName, OpaqueProperties properties) {} LogicalResult OperationName::UnregisteredOpModel::setPropertiesFromAttr( - Operation *op, Attribute attr, InFlightDiagnostic *diag) { - *op->getPropertiesStorage().as() = attr; + OperationName opName, OpaqueProperties properties, Attribute attr, + InFlightDiagnostic *diag) { + *properties.as() = attr; return success(); } Attribute diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -361,7 +361,8 @@ *getPropertiesStorage().as() = attr; return success(); } - return info->setOpPropertiesFromAttribute(this, attr, diagnostic); + return info->setOpPropertiesFromAttribute( + this->getName(), attr, this->getPropertiesStorage(), diagnostic); } void Operation::copyProperties(OpaqueProperties rhs) {