diff --git a/mlir/include/mlir/IR/ExtensibleDialect.h b/mlir/include/mlir/IR/ExtensibleDialect.h index d26ddafd2ef1d..15904358def11 100644 --- a/mlir/include/mlir/IR/ExtensibleDialect.h +++ b/mlir/include/mlir/IR/ExtensibleDialect.h @@ -551,25 +551,23 @@ class DynamicOpDefinition : public OperationName::Impl { return success(); } int getOpPropertyByteSize() final { return 0; } - void initProperties(OperationName opName, OpaqueProperties storage, - OpaqueProperties init) final {} - void deleteProperties(OpaqueProperties prop) final {} + void initProperties(OperationName opName, PropertyRef storage, + PropertyRef init) final {} + void deleteProperties(PropertyRef prop) final {} void populateDefaultProperties(OperationName opName, - OpaqueProperties properties) final {} + PropertyRef properties) final {} LogicalResult - setPropertiesFromAttr(OperationName opName, OpaqueProperties properties, + setPropertiesFromAttr(OperationName opName, PropertyRef properties, Attribute attr, function_ref emitError) final { emitError() << "extensible Dialects don't support properties"; return failure(); } Attribute getPropertiesAsAttr(Operation *op) final { return {}; } - void copyProperties(OpaqueProperties lhs, OpaqueProperties rhs) final {} - bool compareProperties(OpaqueProperties, OpaqueProperties) final { - return true; - } - llvm::hash_code hashProperties(OpaqueProperties prop) final { return {}; } + void copyProperties(PropertyRef lhs, PropertyRef rhs) final {} + bool compareProperties(PropertyRef, PropertyRef) final { return true; } + llvm::hash_code hashProperties(PropertyRef prop) final { return {}; } private: DynamicOpDefinition( diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h index be92fe0a6c7e3..e886ac45675e2 100644 --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -243,9 +243,10 @@ class OpState { /// so we can cast it away here. explicit OpState(Operation *state) : state(state) {} - /// For all op which don't have properties, we keep a single instance of - /// `EmptyProperties` to be used where a reference to a properties is needed: - /// this allow to bind a pointer to the reference without triggering UB. + /// For all ops which don't have properties, we keep a single instance of + /// `EmptyProperties` to be used where a pointer to a struct of properties + /// is needed: this allows binding a pointer to the reference without + /// triggering UB. static EmptyProperties &getEmptyProperties() { static EmptyProperties emptyProperties; return emptyProperties; @@ -1978,7 +1979,7 @@ class Op : public OpState, public Traits... { if constexpr (!hasProperties()) return getEmptyProperties(); return *getOperation() - ->getPropertiesStorageUnsafe() + ->getPropertiesStorage() .template as *>(); } @@ -2152,4 +2153,6 @@ struct DenseMapInfo(const_cast( - getTrailingObjects()))}; - return {nullptr}; + return PropertyRef( + name.getOpPropertiesTypeID(), + reinterpret_cast(const_cast( + getTrailingObjects()))); + return {}; } - /// Returns the properties storage without checking whether properties are - /// present. - OpaqueProperties getPropertiesStorageUnsafe() { - return { - reinterpret_cast(getTrailingObjects())}; + + /// Returns a pointer to the properties storage (if it exists) with no type + /// information. + void *getRawPropertiesStorageUnsafe() { + return reinterpret_cast(const_cast( + getTrailingObjects())); } /// Return the properties converted to an attribute. @@ -961,7 +964,7 @@ class alignas(8) Operation final /// Copy properties from an existing other properties object. The two objects /// must be the same type. - void copyProperties(OpaqueProperties rhs); + void copyProperties(PropertyRef rhs); /// Compute a hash for the op properties (if any). llvm::hash_code hashProperties(); @@ -990,7 +993,7 @@ class alignas(8) Operation final Operation(Location location, OperationName name, unsigned numResults, unsigned numSuccessors, unsigned numRegions, int propertiesStorageSize, DictionaryAttr attributes, - OpaqueProperties properties, bool hasOperandStorage); + PropertyRef properties, bool hasOperandStorage); // Operations are deleted through the destroy() member because they are // allocated with malloc. diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h index ac069df1d3e7d..f801947f2a252 100644 --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -63,22 +63,33 @@ template class ValueTypeRange; //===----------------------------------------------------------------------===// -// OpaqueProperties +// PropertyRef //===----------------------------------------------------------------------===// -/// Simple wrapper around a void* in order to express generically how to pass -/// in op properties through APIs. -class OpaqueProperties { +/// Type-safe wrapper around a void* for passing properties, including the +/// properties structs of operations, generically through APIs. Pairs data with +/// a TypeID for assert-based type checking. Note that the type in the type ID +/// is the **storage** type of the property, and that the default object has a +/// null data pointer and a type ID equal to the type ID for `void`. +class PropertyRef { public: - OpaqueProperties(void *prop) : properties(prop) {} - operator bool() const { return properties != nullptr; } + PropertyRef() = default; + PropertyRef(TypeID typeID, void *data) : typeID(typeID), data(data) {} + operator bool() const { return data != nullptr; } template Dest as() const { - return static_cast(const_cast(properties)); + static_assert(std::is_pointer_v, + "PropertyRef::as() requires T to be a pointer type"); + using RawType = std::remove_cv_t>; + assert((typeID == TypeID::get()) && + "Property type mismatch: TypeID does not match requested type"); + return static_cast(data); } + TypeID getTypeID() const { return typeID; } private: - void *properties; + TypeID typeID; + void *data = nullptr; }; //===----------------------------------------------------------------------===// @@ -130,18 +141,18 @@ class OperationName { verifyInherentAttrs(OperationName opName, NamedAttrList &attributes, function_ref emitError) = 0; virtual int getOpPropertyByteSize() = 0; - virtual void initProperties(OperationName opName, OpaqueProperties storage, - OpaqueProperties init) = 0; - virtual void deleteProperties(OpaqueProperties) = 0; + virtual void initProperties(OperationName opName, PropertyRef storage, + PropertyRef init) = 0; + virtual void deleteProperties(PropertyRef) = 0; virtual void populateDefaultProperties(OperationName opName, - OpaqueProperties properties) = 0; + PropertyRef properties) = 0; virtual LogicalResult - setPropertiesFromAttr(OperationName, OpaqueProperties, Attribute, + setPropertiesFromAttr(OperationName, PropertyRef, Attribute, function_ref emitError) = 0; virtual Attribute getPropertiesAsAttr(Operation *) = 0; - virtual void copyProperties(OpaqueProperties, OpaqueProperties) = 0; - virtual bool compareProperties(OpaqueProperties, OpaqueProperties) = 0; - virtual llvm::hash_code hashProperties(OpaqueProperties) = 0; + virtual void copyProperties(PropertyRef, PropertyRef) = 0; + virtual bool compareProperties(PropertyRef, PropertyRef) = 0; + virtual llvm::hash_code hashProperties(PropertyRef) = 0; }; public: @@ -160,6 +171,7 @@ class OperationName { Dialect *getDialect() const { return dialect; } StringAttr getName() const { return name; } TypeID getTypeID() const { return typeID; } + TypeID getPropertiesTypeID() const { return propertiesTypeID; } ArrayRef getAttributeNames() const { return attributeNames; } protected: @@ -186,13 +198,20 @@ class OperationName { /// lookup/creation/etc., as opposed to raw strings. ArrayRef attributeNames; + /// The TypeID of the Properties struct for this operation. + TypeID propertiesTypeID; + friend class RegisteredOperationName; }; protected: /// Default implementation for unregistered operations. struct UnregisteredOpModel : public Impl { - using Impl::Impl; + UnregisteredOpModel(StringAttr name, Dialect *dialect, TypeID typeID, + detail::InterfaceMap interfaceMap) + : Impl(name, dialect, typeID, std::move(interfaceMap)) { + propertiesTypeID = TypeID::get(); + } LogicalResult foldHook(Operation *, ArrayRef, SmallVectorImpl &) final; void getCanonicalizationPatterns(RewritePatternSet &, MLIRContext *) final; @@ -211,18 +230,18 @@ class OperationName { verifyInherentAttrs(OperationName opName, NamedAttrList &attributes, function_ref emitError) final; int getOpPropertyByteSize() final; - void initProperties(OperationName opName, OpaqueProperties storage, - OpaqueProperties init) final; - void deleteProperties(OpaqueProperties) final; + void initProperties(OperationName opName, PropertyRef storage, + PropertyRef init) final; + void deleteProperties(PropertyRef) final; void populateDefaultProperties(OperationName opName, - OpaqueProperties properties) final; + PropertyRef properties) final; LogicalResult - setPropertiesFromAttr(OperationName, OpaqueProperties, Attribute, + setPropertiesFromAttr(OperationName, PropertyRef, Attribute, function_ref emitError) final; Attribute getPropertiesAsAttr(Operation *) final; - void copyProperties(OpaqueProperties, OpaqueProperties) final; - bool compareProperties(OpaqueProperties, OpaqueProperties) final; - llvm::hash_code hashProperties(OpaqueProperties) final; + void copyProperties(PropertyRef, PropertyRef) final; + bool compareProperties(PropertyRef, PropertyRef) final; + llvm::hash_code hashProperties(PropertyRef) final; }; public: @@ -413,18 +432,23 @@ class OperationName { return getImpl()->getOpPropertyByteSize(); } + /// Return the TypeID of the op properties. + TypeID getOpPropertiesTypeID() const { + return getImpl()->getPropertiesTypeID(); + } + /// This hooks destroy the op properties. - void destroyOpProperties(OpaqueProperties properties) const { + void destroyOpProperties(PropertyRef properties) const { getImpl()->deleteProperties(properties); } /// Initialize the op properties. - void initOpProperties(OpaqueProperties storage, OpaqueProperties init) const { + void initOpProperties(PropertyRef storage, PropertyRef init) const { getImpl()->initProperties(*this, storage, init); } /// Set the default values on the ODS attribute in the properties. - void populateDefaultProperties(OpaqueProperties properties) const { + void populateDefaultProperties(PropertyRef properties) const { getImpl()->populateDefaultProperties(*this, properties); } @@ -435,21 +459,21 @@ class OperationName { /// Define the op properties from the provided Attribute. LogicalResult setOpPropertiesFromAttribute( - OperationName opName, OpaqueProperties properties, Attribute attr, + OperationName opName, PropertyRef properties, Attribute attr, function_ref emitError) const { return getImpl()->setPropertiesFromAttr(opName, properties, attr, emitError); } - void copyOpProperties(OpaqueProperties lhs, OpaqueProperties rhs) const { + void copyOpProperties(PropertyRef lhs, PropertyRef rhs) const { return getImpl()->copyProperties(lhs, rhs); } - bool compareOpProperties(OpaqueProperties lhs, OpaqueProperties rhs) const { + bool compareOpProperties(PropertyRef lhs, PropertyRef rhs) const { return getImpl()->compareProperties(lhs, rhs); } - llvm::hash_code hashOpProperties(OpaqueProperties properties) const { + llvm::hash_code hashOpProperties(PropertyRef properties) const { return getImpl()->hashProperties(properties); } @@ -528,9 +552,13 @@ class RegisteredOperationName : public OperationName { /// to a concrete op implementation. template struct Model : public Impl { + using Properties = std::remove_reference_t< + decltype(std::declval().getProperties())>; Model(Dialect *dialect) : Impl(ConcreteOp::getOperationName(), dialect, - TypeID::get(), ConcreteOp::getInterfaceMap()) {} + TypeID::get(), ConcreteOp::getInterfaceMap()) { + propertiesTypeID = TypeID::get(); + } LogicalResult foldHook(Operation *op, ArrayRef attrs, SmallVectorImpl &results) final { return ConcreteOp::getFoldHookFn()(op, attrs, results); @@ -560,9 +588,6 @@ class RegisteredOperationName : public OperationName { /// Implementation for "Properties" - using Properties = std::remove_reference_t< - decltype(std::declval().getProperties())>; - std::optional getInherentAttr(Operation *op, StringRef name) final { if constexpr (hasProperties) { @@ -606,8 +631,8 @@ class RegisteredOperationName : public OperationName { return sizeof(Properties); return 0; } - void initProperties(OperationName opName, OpaqueProperties storage, - OpaqueProperties init) final { + void initProperties(OperationName opName, PropertyRef storage, + PropertyRef init) final { using Properties = typename ConcreteOp::template InferredProperties; if (init) @@ -618,18 +643,18 @@ class RegisteredOperationName : public OperationName { ConcreteOp::populateDefaultProperties(opName, *storage.as()); } - void deleteProperties(OpaqueProperties prop) final { + void deleteProperties(PropertyRef prop) final { prop.as()->~Properties(); } void populateDefaultProperties(OperationName opName, - OpaqueProperties properties) final { + PropertyRef properties) final { if constexpr (hasProperties) ConcreteOp::populateDefaultProperties(opName, *properties.as()); } LogicalResult - setPropertiesFromAttr(OperationName opName, OpaqueProperties properties, + setPropertiesFromAttr(OperationName opName, PropertyRef properties, Attribute attr, function_ref emitError) final { if constexpr (hasProperties) { @@ -647,15 +672,15 @@ class RegisteredOperationName : public OperationName { } return {}; } - bool compareProperties(OpaqueProperties lhs, OpaqueProperties rhs) final { + bool compareProperties(PropertyRef lhs, PropertyRef rhs) final { if constexpr (hasProperties) return *lhs.as() == *rhs.as(); return true; } - void copyProperties(OpaqueProperties lhs, OpaqueProperties rhs) final { + void copyProperties(PropertyRef lhs, PropertyRef rhs) final { *lhs.as() = *rhs.as(); } - llvm::hash_code hashProperties(OpaqueProperties prop) final { + llvm::hash_code hashProperties(PropertyRef prop) final { if constexpr (hasProperties) return ConcreteOp::computePropertiesHash(*prop.as()); @@ -959,11 +984,9 @@ struct OperationState { Attribute propertiesAttr; private: - OpaqueProperties properties = nullptr; - TypeID propertiesId; - llvm::function_ref propertiesDeleter; - llvm::function_ref - propertiesSetter; + PropertyRef properties; + llvm::function_ref propertiesDeleter; + llvm::function_ref propertiesSetter; friend class Operation; public: @@ -984,13 +1007,13 @@ struct OperationState { OperationState &operator=(const OperationState &other) = delete; ~OperationState(); - /// Get (or create) a properties of the provided type to be set on the + /// Get (or create) the properties of the provided type to be set on the /// operation on creation. template T &getOrAddProperties() { if (!properties) { T *p = new T{}; - properties = p; + properties = PropertyRef(TypeID::get(), p); #if defined(__clang__) #if __has_warning("-Wdangling-assignment-gsl") #pragma clang diagnostic push @@ -998,11 +1021,8 @@ struct OperationState { #pragma clang diagnostic ignored "-Wdangling-assignment-gsl" #endif #endif - propertiesDeleter = [](OpaqueProperties prop) { - delete prop.as(); - }; - propertiesSetter = [](OpaqueProperties newProp, - const OpaqueProperties prop) { + propertiesDeleter = [](PropertyRef prop) { delete prop.as(); }; + propertiesSetter = [](PropertyRef newProp, const PropertyRef prop) { *newProp.as() = *prop.as(); }; #if defined(__clang__) @@ -1010,12 +1030,12 @@ struct OperationState { #pragma clang diagnostic pop #endif #endif - propertiesId = TypeID::get(); } - assert(propertiesId == TypeID::get() && "Inconsistent properties"); + assert(properties.getTypeID() == TypeID::get() && + "Inconsistent properties"); return *properties.as(); } - OpaqueProperties getRawProperties() { return properties; } + PropertyRef getRawProperties() { return properties; } // Set the properties defined on this OpState on the given operation, // optionally emit diagnostics on error through the provided diagnostic. @@ -1026,13 +1046,13 @@ struct OperationState { // Make `newProperties` the source of the properties that will be copied into // the operation. The memory referenced by `newProperties` must remain live // until after the `Operation` is created, at which time it may be - // deallocated. Calls to `getOrAddProperties<>() will return references to + // deallocated. Calls to `getOrAddProperties<>()` will return references to // this memory. template void useProperties(T &newProperties) { assert(!properties && "Can't provide a properties struct when one has been allocated"); - properties = &newProperties; + properties = PropertyRef(TypeID::get(), &newProperties); #if defined(__clang__) #if __has_warning("-Wdangling-assignment-gsl") #pragma clang diagnostic push @@ -1040,9 +1060,8 @@ struct OperationState { #pragma clang diagnostic ignored "-Wdangling-assignment-gsl" #endif #endif - propertiesDeleter = [](OpaqueProperties) {}; - propertiesSetter = [](OpaqueProperties newProp, - const OpaqueProperties prop) { + propertiesDeleter = [](PropertyRef) {}; + propertiesSetter = [](PropertyRef newProp, const PropertyRef prop) { *newProp.as() = *prop.as(); }; #if defined(__clang__) @@ -1050,7 +1069,6 @@ struct OperationState { #pragma clang diagnostic pop #endif #endif - propertiesId = TypeID::get(); } void addOperands(ValueRange newOperands); diff --git a/mlir/include/mlir/Interfaces/InferTypeOpInterface.td b/mlir/include/mlir/Interfaces/InferTypeOpInterface.td index 67568f731f597..36397d596aed6 100644 --- a/mlir/include/mlir/Interfaces/InferTypeOpInterface.td +++ b/mlir/include/mlir/Interfaces/InferTypeOpInterface.td @@ -53,7 +53,7 @@ def InferTypeOpInterface : OpInterface<"InferTypeOpInterface"> { "::std::optional<::mlir::Location>":$location, "::mlir::ValueRange":$operands, "::mlir::DictionaryAttr":$attributes, - "::mlir::OpaqueProperties":$properties, + "::mlir::PropertyRef":$properties, "::mlir::RegionRange":$regions, "::llvm::SmallVectorImpl<::mlir::Type>&":$inferredReturnTypes) >, @@ -87,7 +87,7 @@ def InferTypeOpInterface : OpInterface<"InferTypeOpInterface"> { "::std::optional<::mlir::Location>":$location, "::mlir::ValueRange":$operands, "::mlir::DictionaryAttr":$attributes, - "::mlir::OpaqueProperties":$properties, + "::mlir::PropertyRef":$properties, "::mlir::RegionRange":$regions, "::llvm::SmallVectorImpl<::mlir::Type>&":$returnTypes), /*methodBody=*/[{}], @@ -164,7 +164,7 @@ def InferShapedTypeOpInterface : OpInterface<"InferShapedTypeOpInterface"> { "::std::optional<::mlir::Location>":$location, "::mlir::ValueShapeRange":$operands, "::mlir::DictionaryAttr":$attributes, - "::mlir::OpaqueProperties":$properties, + "::mlir::PropertyRef":$properties, "::mlir::RegionRange":$regions, "::llvm::SmallVectorImpl<::mlir::ShapedTypeComponents>&": $inferredReturnShapes), @@ -220,7 +220,7 @@ class InferTypeOpAdaptorBase : TraitList< $cppClass::inferReturnTypes(::mlir::MLIRContext *context, std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, - ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions, + ::mlir::PropertyRef properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { $cppClass::Adaptor adaptor(operands, attributes, properties, regions); return $cppClass::inferReturnTypes(context, @@ -258,7 +258,7 @@ class InferShapedTypeOpAdaptorBase overridenMethods = []> : TraitLi $cppClass::inferReturnTypeComponents(::mlir::MLIRContext *context, std::optional<::mlir::Location> location, ::mlir::ValueShapeRange operands, ::mlir::DictionaryAttr attributes, - ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions, + ::mlir::PropertyRef properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::ShapedTypeComponents> &inferredReturnShapes) { $cppClass::Adaptor adaptor(operands, attributes, properties, regions); return $cppClass::inferReturnTypeComponents(context, @@ -293,7 +293,7 @@ class InferTensorTypeBase overridenMethods = []> : TraitList< $cppClass::inferReturnTypes(::mlir::MLIRContext *context, std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, - ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions, + ::mlir::PropertyRef properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { ::llvm::SmallVector<::mlir::ShapedTypeComponents, 2> retComponents; if (failed($cppClass::inferReturnTypeComponents(context, location, @@ -331,7 +331,7 @@ class InferTensorTypeAdaptorBase overridenMethods = []> : TraitList $cppClass::inferReturnTypes(::mlir::MLIRContext *context, std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, - ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions, + ::mlir::PropertyRef properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { SmallVector retComponents; if (failed($cppClass::inferReturnTypeComponents(context, location, diff --git a/mlir/lib/AsmParser/Parser.cpp b/mlir/lib/AsmParser/Parser.cpp index 22928df03fbc7..06a3dfa65e933 100644 --- a/mlir/lib/AsmParser/Parser.cpp +++ b/mlir/lib/AsmParser/Parser.cpp @@ -1236,7 +1236,7 @@ Value OperationParser::createForwardRefPlaceholder(SMLoc loc, Type type) { auto name = OperationName("builtin.unrealized_conversion_cast", getContext()); auto *op = Operation::create( getEncodedSourceLocation(loc), name, type, /*operands=*/{}, - /*attributes=*/NamedAttrList(), /*properties=*/nullptr, + /*attributes=*/NamedAttrList(), /*properties=*/PropertyRef(), /*successors=*/{}, /*numRegions=*/0); forwardRefPlaceholders[op->getResult(0)] = loc; forwardRefOps.insert(op); diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp index c7ecab15a04d4..481130e5069db 100644 --- a/mlir/lib/CAPI/IR/IR.cpp +++ b/mlir/lib/CAPI/IR/IR.cpp @@ -552,11 +552,11 @@ static LogicalResult inferOperationTypes(OperationState &state) { } DictionaryAttr attributes = state.attributes.getDictionary(context); - OpaqueProperties properties = state.getRawProperties(); + PropertyRef properties = state.getRawProperties(); if (!properties && info->getOpPropertyByteSize() > 0 && !attributes.empty()) { - auto prop = std::make_unique(info->getOpPropertyByteSize()); - properties = OpaqueProperties(prop.get()); + auto propAlloc = std::make_unique(info->getOpPropertyByteSize()); + properties = PropertyRef(info->getOpPropertiesTypeID(), propAlloc.get()); if (properties) { auto emitError = [&]() { return mlir::emitError(state.location) diff --git a/mlir/lib/CAPI/Interfaces/Interfaces.cpp b/mlir/lib/CAPI/Interfaces/Interfaces.cpp index 437a1dbab9dae..bfa9fbf3e6217 100644 --- a/mlir/lib/CAPI/Interfaces/Interfaces.cpp +++ b/mlir/lib/CAPI/Interfaces/Interfaces.cpp @@ -107,9 +107,15 @@ MlirLogicalResult mlirInferTypeOpInterfaceInferReturnTypes( unwrapRegions(nRegions, regions); SmallVector inferredTypes; + // The C API passes an opaque void*; we trust the caller to pass the correct + // properties type for this operation. + // TODO: Create a C API that's more type-safe. + PropertyRef propertyRef = + properties ? PropertyRef(info->getOpPropertiesTypeID(), properties) + : PropertyRef(); if (failed(info->getInterface()->inferReturnTypes( unwrap(context), maybeLocation, unwrappedOperands, attributeDict, - properties, unwrappedRegions, inferredTypes))) + propertyRef, unwrappedRegions, inferredTypes))) return mlirLogicalResultFailure(); SmallVector wrappedInferredTypes; @@ -141,11 +147,16 @@ MlirLogicalResult mlirInferShapedTypeOpInterfaceInferReturnTypes( unwrapRegions(nRegions, regions); SmallVector inferredTypeComponents; + // The C API passes an opaque void*; we trust the caller to pass the correct + // properties type for this operation. + PropertyRef propertyRef = + properties ? PropertyRef(info->getOpPropertiesTypeID(), properties) + : PropertyRef(); if (failed(info->getInterface() ->inferReturnTypeComponents( unwrap(context), maybeLocation, mlir::ValueRange(llvm::ArrayRef(unwrappedOperands)), - attributeDict, properties, unwrappedRegions, + attributeDict, propertyRef, unwrappedRegions, inferredTypeComponents))) return mlirLogicalResultFailure(); diff --git a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUOps.cpp b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUOps.cpp index e85b03cc3befe..d245094b85882 100644 --- a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUOps.cpp +++ b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUOps.cpp @@ -103,7 +103,7 @@ static FailureOr getFatRawBufferTypeLike(MemRefType source, LogicalResult FatRawBufferCastOp::inferReturnTypes( MLIRContext *context, std::optional location, ValueRange operands, - DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions, + DictionaryAttr attributes, PropertyRef properties, RegionRange regions, SmallVectorImpl &inferredReturnTypes) { Adaptor adaptor(operands, attributes, properties, regions); auto sourceType = diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp index 71ad8bbf91c3b..c525ec116f699 100644 --- a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp +++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp @@ -908,7 +908,7 @@ std::optional CloneOp::buildClone(OpBuilder &builder, Value alloc) { LogicalResult DeallocOp::inferReturnTypes( MLIRContext *context, std::optional<::mlir::Location> location, - ValueRange operands, DictionaryAttr attributes, OpaqueProperties properties, + ValueRange operands, DictionaryAttr attributes, PropertyRef properties, RegionRange regions, SmallVectorImpl &inferredReturnTypes) { DeallocOpAdaptor adaptor(operands, attributes, properties, regions); inferredReturnTypes = SmallVector(adaptor.getRetained().size(), diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp index f31811ad7b98e..8c9fb17630029 100644 --- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp @@ -634,7 +634,7 @@ LogicalResult DistinctObjectsOp::verify() { LogicalResult DistinctObjectsOp::inferReturnTypes( MLIRContext * /*context*/, std::optional /*location*/, ValueRange operands, DictionaryAttr /*attributes*/, - OpaqueProperties /*properties*/, RegionRange /*regions*/, + PropertyRef /*properties*/, RegionRange /*regions*/, SmallVectorImpl &inferredReturnTypes) { llvm::copy(operands.getTypes(), std::back_inserter(inferredReturnTypes)); return success(); diff --git a/mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp b/mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp index d6d5e90275015..20d543b7210b1 100644 --- a/mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp +++ b/mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp @@ -935,7 +935,7 @@ class ExtractStridedMetadataOpReinterpretCastFolder SmallVector inferredReturnTypes; if (failed(extractStridedMetadataOp.inferReturnTypes( rewriter.getContext(), loc, {reinterpretCastOp.getSource()}, - /*attributes=*/{}, /*properties=*/nullptr, /*regions=*/{}, + /*attributes=*/{}, /*properties=*/{}, /*regions=*/{}, inferredReturnTypes))) return rewriter.notifyMatchFailure( reinterpretCastOp, "reinterpret_cast source's type is incompatible"); diff --git a/mlir/lib/Dialect/Ptr/IR/PtrDialect.cpp b/mlir/lib/Dialect/Ptr/IR/PtrDialect.cpp index 51f25f755a8a6..444197d12097f 100644 --- a/mlir/lib/Dialect/Ptr/IR/PtrDialect.cpp +++ b/mlir/lib/Dialect/Ptr/IR/PtrDialect.cpp @@ -355,7 +355,7 @@ OpFoldResult PtrAddOp::fold(FoldAdaptor adaptor) { LogicalResult PtrAddOp::inferReturnTypes( MLIRContext *context, std::optional location, ValueRange operands, - DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions, + DictionaryAttr attributes, PropertyRef properties, RegionRange regions, SmallVectorImpl &inferredReturnTypes) { // Get the base pointer and offset types. Type baseType = operands[0].getType(); diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp index 91375d2f56b3e..9f4f4dc9f58e6 100644 --- a/mlir/lib/Dialect/SCF/IR/SCF.cpp +++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp @@ -2025,7 +2025,7 @@ void IfOp::build(OpBuilder &builder, OperationState &result, Value cond, MLIRContext *ctx = builder.getContext(); auto attrDict = DictionaryAttr::get(ctx, result.attributes); if (succeeded(inferReturnTypes(ctx, std::nullopt, result.operands, attrDict, - /*properties=*/nullptr, result.regions, + /*properties=*/PropertyRef{}, result.regions, inferredReturnTypes))) { result.addTypes(inferredReturnTypes); } diff --git a/mlir/lib/Dialect/SMT/IR/SMTOps.cpp b/mlir/lib/Dialect/SMT/IR/SMTOps.cpp index c517ef2b18f6f..06ad4ab51b88b 100644 --- a/mlir/lib/Dialect/SMT/IR/SMTOps.cpp +++ b/mlir/lib/Dialect/SMT/IR/SMTOps.cpp @@ -22,7 +22,7 @@ using namespace mlir; LogicalResult BVConstantOp::inferReturnTypes( mlir::MLIRContext *context, std::optional location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, - ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions, + ::mlir::PropertyRef properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { inferredReturnTypes.push_back( properties.as()->getValue().getType()); @@ -173,7 +173,7 @@ LogicalResult ExtractOp::verify() { LogicalResult ConcatOp::inferReturnTypes( MLIRContext *context, std::optional location, ValueRange operands, - DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions, + DictionaryAttr attributes, PropertyRef properties, RegionRange regions, SmallVectorImpl &inferredReturnTypes) { inferredReturnTypes.push_back(BitVectorType::get( context, cast(operands[0].getType()).getWidth() + diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp index 05b2e07b88ba5..b77a536861d2a 100644 --- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp +++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp @@ -1605,8 +1605,7 @@ OpFoldResult ReinterpretMapOp::fold(FoldAdaptor adaptor) { template static LogicalResult inferSparseBufferType(ValueRange ops, DictionaryAttr attr, - OpaqueProperties prop, - RegionRange region, + PropertyRef prop, RegionRange region, SmallVectorImpl &ret) { typename ToBufferOp::Adaptor adaptor(ops, attr, prop, region); SparseTensorType stt = getSparseTensorType(adaptor.getTensor()); @@ -1647,7 +1646,7 @@ LogicalResult ToPositionsOp::verify() { LogicalResult ToPositionsOp::inferReturnTypes(MLIRContext *ctx, std::optional loc, ValueRange ops, DictionaryAttr attr, - OpaqueProperties prop, RegionRange region, + PropertyRef prop, RegionRange region, SmallVectorImpl &ret) { return inferSparseBufferType(ops, attr, prop, region, ret); } @@ -1664,7 +1663,7 @@ LogicalResult ToCoordinatesOp::verify() { LogicalResult ToCoordinatesOp::inferReturnTypes(MLIRContext *ctx, std::optional loc, ValueRange ops, DictionaryAttr attr, - OpaqueProperties prop, RegionRange region, + PropertyRef prop, RegionRange region, SmallVectorImpl &ret) { return inferSparseBufferType(ops, attr, prop, region, ret); } @@ -1678,7 +1677,7 @@ LogicalResult ToCoordinatesBufferOp::verify() { LogicalResult ToCoordinatesBufferOp::inferReturnTypes( MLIRContext *ctx, std::optional loc, ValueRange ops, - DictionaryAttr attr, OpaqueProperties prop, RegionRange region, + DictionaryAttr attr, PropertyRef prop, RegionRange region, SmallVectorImpl &ret) { return inferSparseBufferType(ops, attr, prop, region, ret); @@ -1695,8 +1694,7 @@ LogicalResult ToValuesOp::verify() { LogicalResult ToValuesOp::inferReturnTypes(MLIRContext *ctx, std::optional loc, ValueRange ops, DictionaryAttr attr, - OpaqueProperties prop, - RegionRange region, + PropertyRef prop, RegionRange region, SmallVectorImpl &ret) { return inferSparseBufferType(ops, attr, prop, region, ret); } @@ -2367,7 +2365,7 @@ parseSparseCoIterateLoop(OpAsmParser &parser, OperationState &state, LogicalResult ExtractIterSpaceOp::inferReturnTypes( MLIRContext *ctx, std::optional loc, ValueRange ops, - DictionaryAttr attr, OpaqueProperties prop, RegionRange region, + DictionaryAttr attr, PropertyRef prop, RegionRange region, SmallVectorImpl &ret) { ExtractIterSpaceOp::Adaptor adaptor(ops, attr, prop, region); diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp index f3413ac6d0d29..bbc8ebe8941aa 100644 --- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp +++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp @@ -1831,8 +1831,8 @@ LogicalResult tosa::ConcatOp::verify() { LogicalResult tosa::EqualOp::inferReturnTypeComponents( MLIRContext *context, ::std::optional location, - ValueShapeRange operands, DictionaryAttr attributes, - OpaqueProperties properties, RegionRange regions, + ValueShapeRange operands, DictionaryAttr attributes, PropertyRef properties, + RegionRange regions, SmallVectorImpl &inferredReturnShapes) { auto elementType = IntegerType::get(context, /*width=*/1); @@ -2332,8 +2332,8 @@ LogicalResult tosa::SliceOp::verify() { LogicalResult tosa::MulOp::inferReturnTypeComponents( MLIRContext *context, ::std::optional location, - ValueShapeRange operands, DictionaryAttr attributes, - OpaqueProperties properties, RegionRange regions, + ValueShapeRange operands, DictionaryAttr attributes, PropertyRef properties, + RegionRange regions, SmallVectorImpl &inferredReturnShapes) { // mul op's output shape only depend on input1 and input2, not on shift ValueShapeRange twoInputs = operands.drop_back(); @@ -3370,7 +3370,7 @@ static LogicalResult NAryInferReturnTypes( LogicalResult OP::inferReturnTypeComponents( \ MLIRContext *context, ::std::optional location, \ ValueShapeRange operands, DictionaryAttr attributes, \ - OpaqueProperties properties, RegionRange regions, \ + PropertyRef properties, RegionRange regions, \ SmallVectorImpl &inferredReturnShapes) { \ return NAryInferReturnTypes(operands, inferredReturnShapes); \ } diff --git a/mlir/lib/Dialect/WasmSSA/IR/WasmSSAOps.cpp b/mlir/lib/Dialect/WasmSSA/IR/WasmSSAOps.cpp index a514ea9218bd7..f3eb601bed5c3 100644 --- a/mlir/lib/Dialect/WasmSSA/IR/WasmSSAOps.cpp +++ b/mlir/lib/Dialect/WasmSSA/IR/WasmSSAOps.cpp @@ -362,7 +362,7 @@ Block *IfOp::getLabelTarget() { return getTarget(); } LogicalResult LocalOp::inferReturnTypes( MLIRContext *context, ::std::optional location, - ValueRange operands, DictionaryAttr attributes, OpaqueProperties properties, + ValueRange operands, DictionaryAttr attributes, PropertyRef properties, RegionRange regions, SmallVectorImpl &inferredReturnTypes) { LocalOp::GenericAdaptor adaptor{operands, attributes, properties, regions}; @@ -380,7 +380,7 @@ LogicalResult LocalOp::inferReturnTypes( LogicalResult LocalGetOp::inferReturnTypes( MLIRContext *context, ::std::optional location, - ValueRange operands, DictionaryAttr attributes, OpaqueProperties properties, + ValueRange operands, DictionaryAttr attributes, PropertyRef properties, RegionRange regions, SmallVectorImpl &inferredReturnTypes) { return inferTeeGetResType(operands, inferredReturnTypes); } @@ -401,7 +401,7 @@ LogicalResult LocalSetOp::verify() { LogicalResult LocalTeeOp::inferReturnTypes( MLIRContext *context, ::std::optional location, - ValueRange operands, DictionaryAttr attributes, OpaqueProperties properties, + ValueRange operands, DictionaryAttr attributes, PropertyRef properties, RegionRange regions, SmallVectorImpl &inferredReturnTypes) { return inferTeeGetResType(operands, inferredReturnTypes); } diff --git a/mlir/lib/IR/ExtensibleDialect.cpp b/mlir/lib/IR/ExtensibleDialect.cpp index 3312549ddfcd4..b51d330160646 100644 --- a/mlir/lib/IR/ExtensibleDialect.cpp +++ b/mlir/lib/IR/ExtensibleDialect.cpp @@ -304,6 +304,8 @@ DynamicOpDefinition::DynamicOpDefinition( getCanonicalizationPatternsFn(std::move(getCanonicalizationPatternsFn)), populateDefaultAttrsFn(std::move(populateDefaultAttrsFn)) { typeID = dialect->allocateTypeID(); + // DynamicOpDefinition doesn't support properties, so use the ID of void. + propertiesTypeID = TypeID(); } std::unique_ptr DynamicOpDefinition::get( diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp index f5edd81862299..21891db11aa65 100644 --- a/mlir/lib/IR/MLIRContext.cpp +++ b/mlir/lib/IR/MLIRContext.cpp @@ -902,20 +902,20 @@ LogicalResult OperationName::UnregisteredOpModel::verifyInherentAttrs( int OperationName::UnregisteredOpModel::getOpPropertyByteSize() { return sizeof(Attribute); } -void OperationName::UnregisteredOpModel::initProperties( - OperationName opName, OpaqueProperties storage, OpaqueProperties init) { +void OperationName::UnregisteredOpModel::initProperties(OperationName opName, + PropertyRef storage, + PropertyRef init) { new (storage.as()) Attribute(); if (init) *storage.as() = *init.as(); } -void OperationName::UnregisteredOpModel::deleteProperties( - OpaqueProperties prop) { +void OperationName::UnregisteredOpModel::deleteProperties(PropertyRef prop) { prop.as()->~Attribute(); } void OperationName::UnregisteredOpModel::populateDefaultProperties( - OperationName opName, OpaqueProperties properties) {} + OperationName opName, PropertyRef properties) {} LogicalResult OperationName::UnregisteredOpModel::setPropertiesFromAttr( - OperationName opName, OpaqueProperties properties, Attribute attr, + OperationName opName, PropertyRef properties, Attribute attr, function_ref emitError) { *properties.as() = attr; return success(); @@ -924,16 +924,16 @@ Attribute OperationName::UnregisteredOpModel::getPropertiesAsAttr(Operation *op) { return *op->getPropertiesStorage().as(); } -void OperationName::UnregisteredOpModel::copyProperties(OpaqueProperties lhs, - OpaqueProperties rhs) { +void OperationName::UnregisteredOpModel::copyProperties(PropertyRef lhs, + PropertyRef rhs) { *lhs.as() = *rhs.as(); } -bool OperationName::UnregisteredOpModel::compareProperties( - OpaqueProperties lhs, OpaqueProperties rhs) { +bool OperationName::UnregisteredOpModel::compareProperties(PropertyRef lhs, + PropertyRef rhs) { return *lhs.as() == *rhs.as(); } llvm::hash_code -OperationName::UnregisteredOpModel::hashProperties(OpaqueProperties prop) { +OperationName::UnregisteredOpModel::hashProperties(PropertyRef prop) { return llvm::hash_combine(*prop.as()); } diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index 46030936a3910..7267c84048463 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -50,9 +50,8 @@ Operation *Operation::create(const OperationState &state) { /// Create a new Operation with the specific fields. Operation *Operation::create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, - NamedAttrList &&attributes, - OpaqueProperties properties, BlockRange successors, - RegionRange regions) { + NamedAttrList &&attributes, PropertyRef properties, + BlockRange successors, RegionRange regions) { unsigned numRegions = regions.size(); Operation *op = create(location, name, resultTypes, operands, std::move(attributes), @@ -66,9 +65,8 @@ Operation *Operation::create(Location location, OperationName name, /// Create a new Operation with the specific fields. Operation *Operation::create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, - NamedAttrList &&attributes, - OpaqueProperties properties, BlockRange successors, - unsigned numRegions) { + NamedAttrList &&attributes, PropertyRef properties, + BlockRange successors, unsigned numRegions) { // Populate default attributes. name.populateDefaultAttrs(attributes); @@ -81,9 +79,8 @@ Operation *Operation::create(Location location, OperationName name, /// unnecessarily uniquing a list of attributes. Operation *Operation::create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, - DictionaryAttr attributes, - OpaqueProperties properties, BlockRange successors, - unsigned numRegions) { + DictionaryAttr attributes, PropertyRef properties, + BlockRange successors, unsigned numRegions) { assert(llvm::all_of(resultTypes, [](Type t) { return t; }) && "unexpected null result type"); @@ -146,7 +143,7 @@ Operation *Operation::create(Location location, OperationName name, for (unsigned i = 0; i != numSuccessors; ++i) new (&blockOperands[i]) BlockOperand(op, successors[i]); - // This must be done after properties are initalized. + // This must be done after properties are initialized. op->setAttrs(attributes); return op; @@ -155,7 +152,7 @@ Operation *Operation::create(Location location, OperationName name, Operation::Operation(Location location, OperationName name, unsigned numResults, unsigned numSuccessors, unsigned numRegions, int fullPropertiesStorageSize, DictionaryAttr attributes, - OpaqueProperties properties, bool hasOperandStorage) + PropertyRef properties, bool hasOperandStorage) : location(location), numResults(numResults), numSuccs(numSuccessors), numRegions(numRegions), hasOperandStorage(hasOperandStorage), propertiesStorageSize((fullPropertiesStorageSize + 7) / 8), name(name) { @@ -363,7 +360,7 @@ LogicalResult Operation::setPropertiesFromAttribute( this->getName(), this->getPropertiesStorage(), attr, emitError); } -void Operation::copyProperties(OpaqueProperties rhs) { +void Operation::copyProperties(PropertyRef rhs) { name.copyOpProperties(getPropertiesStorage(), rhs); } diff --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp index a4ce7e6fea8b9..31f71c3949003 100644 --- a/mlir/lib/IR/OperationSupport.cpp +++ b/mlir/lib/IR/OperationSupport.cpp @@ -972,3 +972,5 @@ OperationFingerPrint::OperationFingerPrint(Operation *topOp, hash = hasher.result(); } + +MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::EmptyProperties) diff --git a/mlir/lib/Target/IRDLToCpp/Templates/PerOperationDecl.txt b/mlir/lib/Target/IRDLToCpp/Templates/PerOperationDecl.txt index 93ce0bef1f269..18edc17f8a28a 100644 --- a/mlir/lib/Target/IRDLToCpp/Templates/PerOperationDecl.txt +++ b/mlir/lib/Target/IRDLToCpp/Templates/PerOperationDecl.txt @@ -54,7 +54,7 @@ class __OP_CPP_NAME__GenericAdaptor using Base = detail::__OP_CPP_NAME__GenericAdaptorBase; public: __OP_CPP_NAME__GenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, - ::mlir::OpaqueProperties properties, + ::mlir::PropertyRef properties, ::mlir::RegionRange regions = {}) : __OP_CPP_NAME__GenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp index 71cb0438e3955..cad27763ab165 100644 --- a/mlir/lib/Transforms/Utils/DialectConversion.cpp +++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp @@ -688,10 +688,10 @@ class ModifyOperationRewrite : public OperationRewrite { name(op->getName()), loc(op->getLoc()), attrs(op->getAttrDictionary()), operands(op->operand_begin(), op->operand_end()), successors(op->successor_begin(), op->successor_end()) { - if (OpaqueProperties prop = op->getPropertiesStorage()) { + if (PropertyRef prop = op->getPropertiesStorage()) { // Make a copy of the properties. propertiesStorage = operator new(op->getPropertiesStorageSize()); - OpaqueProperties propCopy(propertiesStorage); + PropertyRef propCopy(name.getOpPropertiesTypeID(), propertiesStorage); name.initOpProperties(propCopy, /*init=*/prop); } } @@ -712,7 +712,7 @@ class ModifyOperationRewrite : public OperationRewrite { listener->notifyOperationModified(op); if (propertiesStorage) { - OpaqueProperties propCopy(propertiesStorage); + PropertyRef propCopy(name.getOpPropertiesTypeID(), propertiesStorage); // Note: The operation may have been erased in the mean time, so // OperationName must be stored in this object. name.destroyOpProperties(propCopy); @@ -728,7 +728,7 @@ class ModifyOperationRewrite : public OperationRewrite { for (const auto &it : llvm::enumerate(successors)) op->setSuccessor(it.value(), it.index()); if (propertiesStorage) { - OpaqueProperties propCopy(propertiesStorage); + PropertyRef propCopy(name.getOpPropertiesTypeID(), propertiesStorage); op->copyProperties(propCopy); name.destroyOpProperties(propCopy); operator delete(propertiesStorage); diff --git a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp index 5d2121ce26671..5fee060689d24 100644 --- a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp +++ b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp @@ -256,7 +256,7 @@ OpFoldResult TestOpInPlaceFold::fold(FoldAdaptor adaptor) { LogicalResult OpWithInferTypeInterfaceOp::inferReturnTypes( MLIRContext *, std::optional location, ValueRange operands, - DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions, + DictionaryAttr attributes, PropertyRef properties, RegionRange regions, SmallVectorImpl &inferredReturnTypes) { if (operands[0].getType() != operands[1].getType()) { return emitOptionalError(location, "operand type mismatch ", @@ -273,8 +273,8 @@ LogicalResult OpWithInferTypeInterfaceOp::inferReturnTypes( LogicalResult OpWithShapedTypeInferTypeInterfaceOp::inferReturnTypeComponents( MLIRContext *context, std::optional location, - ValueShapeRange operands, DictionaryAttr attributes, - OpaqueProperties properties, RegionRange regions, + ValueShapeRange operands, DictionaryAttr attributes, PropertyRef properties, + RegionRange regions, SmallVectorImpl &inferredReturnShapes) { // Create return type consisting of the last element of the first operand. auto operandType = operands.front().getType(); @@ -1194,7 +1194,7 @@ LogicalResult OpWithInferTypeAdaptorInterfaceOp::inferReturnTypes( // refineReturnType, currently only refineReturnType can be omitted. LogicalResult OpWithRefineTypeInterfaceOp::inferReturnTypes( MLIRContext *context, std::optional location, ValueRange operands, - DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions, + DictionaryAttr attributes, PropertyRef properties, RegionRange regions, SmallVectorImpl &returnTypes) { returnTypes.clear(); return OpWithRefineTypeInterfaceOp::refineReturnTypes( @@ -1204,7 +1204,7 @@ LogicalResult OpWithRefineTypeInterfaceOp::inferReturnTypes( LogicalResult OpWithRefineTypeInterfaceOp::refineReturnTypes( MLIRContext *, std::optional location, ValueRange operands, - DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions, + DictionaryAttr attributes, PropertyRef properties, RegionRange regions, SmallVectorImpl &returnTypes) { if (operands[0].getType() != operands[1].getType()) { return emitOptionalError(location, "operand type mismatch ", @@ -1286,7 +1286,7 @@ OpWithShapedTypeInferTypeAdaptorInterfaceOp::reifyReturnTypeShapes( LogicalResult TestOpWithPropertiesAndInferredType::inferReturnTypes( MLIRContext *context, std::optional, ValueRange operands, - DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions, + DictionaryAttr attributes, PropertyRef properties, RegionRange regions, SmallVectorImpl &inferredReturnTypes) { Adaptor adaptor(operands, attributes, properties, regions); diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td index f9ffddd1300b6..a82d5d831a3ce 100644 --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -546,7 +546,7 @@ def VariadicRegionInferredTypesOp : TEST_Op<"variadic_region_inferred", let extraClassDeclaration = [{ static llvm::LogicalResult inferReturnTypes(mlir::MLIRContext *context, std::optional<::mlir::Location> location, mlir::ValueRange operands, - mlir::DictionaryAttr attributes, mlir::OpaqueProperties properties, mlir::RegionRange regions, + mlir::DictionaryAttr attributes, mlir::PropertyRef properties, mlir::RegionRange regions, llvm::SmallVectorImpl &inferredReturnTypes) { inferredReturnTypes.assign({mlir::IntegerType::get(context, 16)}); return mlir::success(); @@ -2836,7 +2836,7 @@ class TableGenBuildInferReturnTypeBaseOp location, ::mlir::ValueRange operands, - ::mlir::DictionaryAttr attributes, mlir::OpaqueProperties properties, ::mlir::RegionRange regions, + ::mlir::DictionaryAttr attributes, mlir::PropertyRef properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { inferredReturnTypes.assign({operands[0].getType()}); return ::mlir::success(); diff --git a/mlir/test/lib/Dialect/Test/TestOpsSyntax.cpp b/mlir/test/lib/Dialect/Test/TestOpsSyntax.cpp index cc131ad9757f9..5880c2a2302b0 100644 --- a/mlir/test/lib/Dialect/Test/TestOpsSyntax.cpp +++ b/mlir/test/lib/Dialect/Test/TestOpsSyntax.cpp @@ -285,7 +285,7 @@ void ParseB64BytesOp::print(OpAsmPrinter &p) { ::llvm::LogicalResult FormatInferType2Op::inferReturnTypes( ::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, - OpaqueProperties properties, ::mlir::RegionRange regions, + PropertyRef properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { inferredReturnTypes.assign({::mlir::IntegerType::get(context, 16)}); return ::mlir::success(); diff --git a/mlir/test/lib/Dialect/Test/TestOpsSyntax.td b/mlir/test/lib/Dialect/Test/TestOpsSyntax.td index 35a34b493035a..096d4d255b729 100644 --- a/mlir/test/lib/Dialect/Test/TestOpsSyntax.td +++ b/mlir/test/lib/Dialect/Test/TestOpsSyntax.td @@ -717,7 +717,7 @@ def FormatInferTypeOp : TEST_Op<"format_infer_type", [InferTypeOpInterface]> { let extraClassDeclaration = [{ static ::llvm::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, - ::mlir::DictionaryAttr attributes, mlir::OpaqueProperties properties, ::mlir::RegionRange regions, + ::mlir::DictionaryAttr attributes, mlir::PropertyRef properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { inferredReturnTypes.assign({::mlir::IntegerType::get(context, 16)}); return ::mlir::success(); @@ -740,7 +740,7 @@ class FormatInferAllTypesBaseOp traits = []> let extraClassDeclaration = [{ static ::llvm::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, - ::mlir::DictionaryAttr attributes, mlir::OpaqueProperties properties, ::mlir::RegionRange regions, + ::mlir::DictionaryAttr attributes, mlir::PropertyRef properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { ::mlir::TypeRange operandTypes = operands.getTypes(); inferredReturnTypes.assign(operandTypes.begin(), operandTypes.end()); @@ -787,7 +787,7 @@ def FormatInferTypeRegionsOp let extraClassDeclaration = [{ static ::llvm::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, - ::mlir::DictionaryAttr attributes, mlir::OpaqueProperties properties, ::mlir::RegionRange regions, + ::mlir::DictionaryAttr attributes, mlir::PropertyRef properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { if (regions.empty()) return ::mlir::failure(); @@ -808,7 +808,7 @@ def FormatInferTypeVariadicOperandsOp let extraClassDeclaration = [{ static ::llvm::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, - ::mlir::DictionaryAttr attributes, mlir::OpaqueProperties properties, ::mlir::RegionRange regions, + ::mlir::DictionaryAttr attributes, mlir::PropertyRef properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { FormatInferTypeVariadicOperandsOpAdaptor adaptor( operands, attributes, *properties.as(), {}); diff --git a/mlir/test/lib/Dialect/Test/TestPatterns.cpp b/mlir/test/lib/Dialect/Test/TestPatterns.cpp index 6c44ace831e96..c8be4bf3f0f8d 100644 --- a/mlir/test/lib/Dialect/Test/TestPatterns.cpp +++ b/mlir/test/lib/Dialect/Test/TestPatterns.cpp @@ -744,10 +744,13 @@ static void invokeCreateWithInferredReturnType(Operation *op) { for (int j = 0; j < e; ++j) { std::array values = {{fop.getArgument(i), fop.getArgument(j)}}; SmallVector inferredReturnTypes; + // Only pass properties if the op's properties type matches OpTy's. + PropertyRef properties = op->getPropertiesStorage(); + if (properties.getTypeID() != TypeID::get()) + properties = PropertyRef(); if (succeeded(OpTy::inferReturnTypes( context, std::nullopt, values, op->getDiscardableAttrDictionary(), - op->getPropertiesStorage(), op->getRegions(), - inferredReturnTypes))) { + properties, op->getRegions(), inferredReturnTypes))) { OperationState state(location, OpTy::getOperationName()); // TODO: Expand to regions. OpTy::build(b, state, values, op->getAttrs()); diff --git a/mlir/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td index 80dedb8475b9e..e92b4044668c1 100644 --- a/mlir/test/mlir-tblgen/op-decl-and-defs.td +++ b/mlir/test/mlir-tblgen/op-decl-and-defs.td @@ -75,7 +75,7 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> { // CHECK: class AOpGenericAdaptor : public detail::AOpGenericAdaptorBase { // CHECK: public: // CHECK: AOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, const Properties &properties, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} -// CHECK: AOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : AOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} +// CHECK: AOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::PropertyRef properties, ::mlir::RegionRange regions = {}) : AOpGenericAdaptor(values, attrs, (properties ? *properties.as() : Properties{}), regions) {} // CHECK: AOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = nullptr) : AOpGenericAdaptor(values, attrs, Properties{}, {}) {} // CHECK: AOpGenericAdaptor(RangeT values, const AOpGenericAdaptorBase &base) : Base(base), odsOperands(values) {} // CHECK: RangeT getODSOperands(unsigned index) { diff --git a/mlir/test/python/python_test_ops.td b/mlir/test/python/python_test_ops.td index cfc1d72bb479d..96e951424ca51 100644 --- a/mlir/test/python/python_test_ops.td +++ b/mlir/test/python/python_test_ops.td @@ -135,7 +135,7 @@ def InferResultsOp : TestOp<"infer_results_op", [InferTypeOpInterface]> { static ::llvm::LogicalResult inferReturnTypes( ::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, - ::mlir::OpaqueProperties, + ::mlir::PropertyRef, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { ::mlir::Builder b(context); @@ -158,7 +158,7 @@ def InferResultsVariadicInputsOp : TestOp<"infer_results_variadic_inputs_op", static ::llvm::LogicalResult inferReturnTypes( ::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, - ::mlir::OpaqueProperties, + ::mlir::PropertyRef, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { ::mlir::Builder b(context); @@ -187,7 +187,7 @@ def InferShapedTypeComponentsOp : TestOp<"infer_shaped_type_components_op", ::llvm::LogicalResult $cppClass::inferReturnTypeComponents( ::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueShapeRange operands, ::mlir::DictionaryAttr attributes, - ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions, + ::mlir::PropertyRef properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl< ::mlir::ShapedTypeComponents>& inferredShapedTypeComponents) { $cppClass::Adaptor adaptor(operands, attributes, properties, regions); diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index e93f91bb540c2..edb009938f005 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -2852,8 +2852,8 @@ void OpEmitter::genInferredTypeCollectiveParamBuilder( // function. body << formatv(R"( if (!attributes.empty()) { - ::mlir::OpaqueProperties properties = - &{1}.getOrAddProperties<{0}::Properties>(); + (void){1}.getOrAddProperties<{0}::Properties>(); + ::mlir::PropertyRef properties = {1}.getRawProperties(); std::optional<::mlir::RegisteredOperationName> info = {1}.name.getRegisteredInfo(); if (failed(info->setOpPropertiesFromAttribute({1}.name, properties, @@ -3145,8 +3145,8 @@ void OpEmitter::genCollectiveParamBuilder(CollectiveBuilderKind kind) { // function. body << formatv(R"( if (!attributes.empty()) { - ::mlir::OpaqueProperties properties = - &{1}.getOrAddProperties<{0}::Properties>(); + (void){1}.getOrAddProperties<{0}::Properties>(); + ::mlir::PropertyRef properties = {1}.getRawProperties(); std::optional<::mlir::RegisteredOperationName> info = {1}.name.getRegisteredInfo(); if (failed(info->setOpPropertiesFromAttribute({1}.name, properties, @@ -4430,22 +4430,22 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter( constructor->addMemberInitializer("Base", "attrs, properties, regions"); constructor->addMemberInitializer("odsOperands", "values"); - // Add a forwarding constructor to the previous one that accepts - // OpaqueProperties instead and check for null and perform the cast to the - // actual properties type. + // Add a forwarding constructor that accepts PropertyRef instead of a + // concrete properties struct. It checks for null and casts to the actual + // properties type. paramList[1] = MethodParameter("::mlir::DictionaryAttr", "attrs"); - paramList[2] = MethodParameter("::mlir::OpaqueProperties", "properties"); - auto *opaquePropertiesConstructor = + paramList[2] = MethodParameter("::mlir::PropertyRef", "properties"); + auto *propertyRefConstructor = genericAdaptor.addConstructor(std::move(paramList)); if (useProperties) { - opaquePropertiesConstructor->addMemberInitializer( + propertyRefConstructor->addMemberInitializer( genericAdaptor.getClassName(), "values, " "attrs, " "(properties ? *properties.as() : Properties{}), " "regions"); } else { - opaquePropertiesConstructor->addMemberInitializer( + propertyRefConstructor->addMemberInitializer( genericAdaptor.getClassName(), "values, " "attrs, " @@ -4702,6 +4702,7 @@ static void emitOpClasses( for (auto *def : defs) { Operator op(*def); + OpOrAdaptorHelper emitHelper(op, /*emitForOp=*/true); if (emitDecl) { { NamespaceEmitter emitter(os, op.getCppNamespace()); @@ -4711,9 +4712,15 @@ static void emitOpClasses( OpEmitter::emitDecl(op, os, staticVerifierEmitter); } // Emit the TypeID explicit specialization to have a single definition. - if (!op.getCppNamespace().empty()) + if (!op.getCppNamespace().empty()) { os << "MLIR_DECLARE_EXPLICIT_TYPE_ID(" << op.getCppNamespace() - << "::" << op.getCppClassName() << ")\n\n"; + << "::" << op.getCppClassName() << ")\n"; + if (emitHelper.hasNonEmptyPropertiesStruct()) + os << "MLIR_DECLARE_EXPLICIT_TYPE_ID(" << op.getCppNamespace() + << "::detail::" << op.getCppClassName() + << "GenericAdaptorBase::Properties)\n"; + os << "\n"; + } } else { { NamespaceEmitter emitter(os, op.getCppNamespace()); @@ -4722,9 +4729,15 @@ static void emitOpClasses( OpEmitter::emitDef(op, os, staticVerifierEmitter); } // Emit the TypeID explicit specialization to have a single definition. - if (!op.getCppNamespace().empty()) + if (!op.getCppNamespace().empty()) { os << "MLIR_DEFINE_EXPLICIT_TYPE_ID(" << op.getCppNamespace() - << "::" << op.getCppClassName() << ")\n\n"; + << "::" << op.getCppClassName() << ")\n"; + if (emitHelper.hasNonEmptyPropertiesStruct()) + os << "MLIR_DEFINE_EXPLICIT_TYPE_ID(" << op.getCppNamespace() + << "::detail::" << op.getCppClassName() + << "GenericAdaptorBase::Properties)\n"; + os << "\n"; + } } } } diff --git a/mlir/unittests/Debug/FileLineColLocBreakpointManagerTest.cpp b/mlir/unittests/Debug/FileLineColLocBreakpointManagerTest.cpp index 6a81422b6b66b..a345aec72f583 100644 --- a/mlir/unittests/Debug/FileLineColLocBreakpointManagerTest.cpp +++ b/mlir/unittests/Debug/FileLineColLocBreakpointManagerTest.cpp @@ -24,8 +24,7 @@ static Operation *createOp(MLIRContext *context, Location loc, unsigned int numRegions = 0) { context->allowUnregisteredDialects(); return Operation::create(loc, OperationName(operationName, context), {}, {}, - NamedAttrList(), OpaqueProperties(nullptr), {}, - numRegions); + NamedAttrList(), PropertyRef(), {}, numRegions); } namespace { diff --git a/mlir/unittests/IR/OperationSupportTest.cpp b/mlir/unittests/IR/OperationSupportTest.cpp index e3d63e0b159ed..90e59808c984a 100644 --- a/mlir/unittests/IR/OperationSupportTest.cpp +++ b/mlir/unittests/IR/OperationSupportTest.cpp @@ -23,9 +23,9 @@ static Operation *createOp(MLIRContext *context, ArrayRef operands = {}, ArrayRef resultTypes = {}, unsigned int numRegions = 0) { context->allowUnregisteredDialects(); - return Operation::create(UnknownLoc::get(context), - OperationName("foo.bar", context), resultTypes, - operands, NamedAttrList(), nullptr, {}, numRegions); + return Operation::create( + UnknownLoc::get(context), OperationName("foo.bar", context), resultTypes, + operands, NamedAttrList(), PropertyRef(), {}, numRegions); } namespace { @@ -237,7 +237,7 @@ TEST(OperationFormatPrintTest, CanPrintNameAsPrefix) { Operation *op = Operation::create( NameLoc::get(StringAttr::get(&context, "my_named_loc")), OperationName("t.op", &context), builder.getIntegerType(16), {}, - NamedAttrList(), nullptr, {}, 0); + NamedAttrList(), PropertyRef(), {}, 0); std::string str; OpPrintingFlags flags; diff --git a/mlir/unittests/IR/ValueTest.cpp b/mlir/unittests/IR/ValueTest.cpp index 97e32d474d522..df354a57fe474 100644 --- a/mlir/unittests/IR/ValueTest.cpp +++ b/mlir/unittests/IR/ValueTest.cpp @@ -20,9 +20,9 @@ static Operation *createOp(MLIRContext *context, ArrayRef operands = {}, ArrayRef resultTypes = {}, unsigned int numRegions = 0) { context->allowUnregisteredDialects(); - return Operation::create(UnknownLoc::get(context), - OperationName("foo.bar", context), resultTypes, - operands, NamedAttrList(), nullptr, {}, numRegions); + return Operation::create( + UnknownLoc::get(context), OperationName("foo.bar", context), resultTypes, + operands, NamedAttrList(), PropertyRef(), {}, numRegions); } namespace { diff --git a/mlir/unittests/IR/VerifierTest.cpp b/mlir/unittests/IR/VerifierTest.cpp index 9b2dd3c73454a..c4f4e1a71cf41 100644 --- a/mlir/unittests/IR/VerifierTest.cpp +++ b/mlir/unittests/IR/VerifierTest.cpp @@ -30,7 +30,7 @@ TEST(VerifierTest, CrossContextResultType) { Type i32B = IntegerType::get(&ctxB, 32); Operation *op = Operation::create(UnknownLoc::get(&ctxA), OperationName("foo.bar", &ctxA), - {i32B}, {}, NamedAttrList(), nullptr, {}, 0); + {i32B}, {}, NamedAttrList(), PropertyRef(), {}, 0); ScopedDiagnosticHandler suppress(&ctxA, [](Diagnostic &) { return success(); }); @@ -50,7 +50,7 @@ TEST(VerifierTest, CrossContextDiscardableAttr) { Operation *op = Operation::create(UnknownLoc::get(&ctxA), OperationName("foo.bar", &ctxA), - {}, {}, std::move(attrs), nullptr, {}, 0); + {}, {}, std::move(attrs), PropertyRef(), {}, 0); ScopedDiagnosticHandler suppress(&ctxA, [](Diagnostic &) { return success(); }); @@ -67,13 +67,13 @@ TEST(VerifierTest, CrossContextOperand) { Type i32B = IntegerType::get(&ctxB, 32); Operation *producerOp = Operation::create( UnknownLoc::get(&ctxB), OperationName("foo.producer", &ctxB), {i32B}, {}, - NamedAttrList(), nullptr, {}, 0); + NamedAttrList(), PropertyRef(), {}, 0); Value valFromCtxB = producerOp->getResult(0); // Consumer op lives in ctxA but uses the value (whose type is in ctxB). Operation *consumerOp = Operation::create( UnknownLoc::get(&ctxA), OperationName("foo.consumer", &ctxA), {}, - {valFromCtxB}, NamedAttrList(), nullptr, {}, 0); + {valFromCtxB}, NamedAttrList(), PropertyRef(), {}, 0); ScopedDiagnosticHandler suppress(&ctxA, [](Diagnostic &) { return success(); }); @@ -92,7 +92,7 @@ TEST(VerifierTest, CrossContextOperationName) { // OperationName is the independent source of a cross-context violation here. Operation *op = Operation::create(UnknownLoc::get(&ctxA), OperationName("foo.bar", &ctxB), - {}, {}, NamedAttrList(), nullptr, {}, 0); + {}, {}, NamedAttrList(), PropertyRef(), {}, 0); ScopedDiagnosticHandler suppress(&ctxA, [](Diagnostic &) { return success(); }); @@ -108,7 +108,7 @@ TEST(VerifierTest, CrossContextOperationLocation) { // Create an outer op in ctxA with one region. Operation *outerOp = Operation::create( UnknownLoc::get(&ctxA), OperationName("foo.outer", &ctxA), {}, {}, - NamedAttrList(), nullptr, {}, /*numRegions=*/1); + NamedAttrList(), PropertyRef(), {}, /*numRegions=*/1); Block *block = new Block(); outerOp->getRegion(0).push_back(block); @@ -116,9 +116,9 @@ TEST(VerifierTest, CrossContextOperationLocation) { // Create an inner op whose location (and thus context) comes from ctxB, and // place it inside the ctxA block. This is the cross-context violation: // op.getContext() == ctxB but the enclosing block belongs to ctxA. - Operation *innerOp = Operation::create(UnknownLoc::get(&ctxB), - OperationName("foo.inner", &ctxB), {}, - {}, NamedAttrList(), nullptr, {}, 0); + Operation *innerOp = Operation::create( + UnknownLoc::get(&ctxB), OperationName("foo.inner", &ctxB), {}, {}, + NamedAttrList(), PropertyRef(), {}, 0); block->push_back(innerOp); // The verifier emits via the parent op's location (ctxA), so only ctxA's @@ -135,9 +135,9 @@ TEST(VerifierTest, CrossContextBlockArgType) { ctxB.allowUnregisteredDialects(); // Create an unregistered op in ctxA with one region. - Operation *op = - Operation::create(UnknownLoc::get(&ctxA), OperationName("foo.bar", &ctxA), - {}, {}, NamedAttrList(), nullptr, {}, /*numRegions=*/1); + Operation *op = Operation::create( + UnknownLoc::get(&ctxA), OperationName("foo.bar", &ctxA), {}, {}, + NamedAttrList(), PropertyRef(), {}, /*numRegions=*/1); // Add a block with one argument whose type comes from ctxB. Block *block = new Block(); @@ -157,9 +157,9 @@ TEST(VerifierTest, CrossContextBlockArgLocation) { ctxB.allowUnregisteredDialects(); // Create an unregistered op in ctxA with one region. - Operation *op = - Operation::create(UnknownLoc::get(&ctxA), OperationName("foo.bar", &ctxA), - {}, {}, NamedAttrList(), nullptr, {}, /*numRegions=*/1); + Operation *op = Operation::create( + UnknownLoc::get(&ctxA), OperationName("foo.bar", &ctxA), {}, {}, + NamedAttrList(), PropertyRef(), {}, /*numRegions=*/1); // Add a block with one argument whose location comes from ctxB. Block *block = new Block(); diff --git a/mlir/unittests/Interfaces/MemorySlotUtilsTest.cpp b/mlir/unittests/Interfaces/MemorySlotUtilsTest.cpp index ae9eefbf03f7c..ae38768435005 100644 --- a/mlir/unittests/Interfaces/MemorySlotUtilsTest.cpp +++ b/mlir/unittests/Interfaces/MemorySlotUtilsTest.cpp @@ -19,7 +19,7 @@ static Operation *createOp(MLIRContext &ctx, StringRef name, unsigned numRegions = 0) { return Operation::create(UnknownLoc::get(&ctx), OperationName(name, &ctx), resultTypes, /*operands=*/{}, NamedAttrList(), - /*properties=*/nullptr, /*successors=*/{}, + /*properties=*/PropertyRef(), /*successors=*/{}, numRegions); } diff --git a/mlir/unittests/Transforms/DialectConversion.cpp b/mlir/unittests/Transforms/DialectConversion.cpp index 6418c9dc0ac5b..d29a14abd47c8 100644 --- a/mlir/unittests/Transforms/DialectConversion.cpp +++ b/mlir/unittests/Transforms/DialectConversion.cpp @@ -13,9 +13,9 @@ using namespace mlir; static Operation *createOp(MLIRContext *context) { context->allowUnregisteredDialects(); - return Operation::create(UnknownLoc::get(context), - OperationName("foo.bar", context), {}, {}, - NamedAttrList(), /*properties=*/nullptr, {}, 0); + return Operation::create( + UnknownLoc::get(context), OperationName("foo.bar", context), {}, {}, + NamedAttrList(), /*properties=*/PropertyRef(), {}, 0); } namespace {