diff --git a/mlir/docs/DefiningDialects/Operations.md b/mlir/docs/DefiningDialects/Operations.md index d93c0e7146011..5ef0e6b5551d2 100644 --- a/mlir/docs/DefiningDialects/Operations.md +++ b/mlir/docs/DefiningDialects/Operations.md @@ -334,13 +334,13 @@ TODO: Design and implement more primitive constraints #### Optional and default-valued properties -To declare a property with a default value, use `DefaultValuedProperty<..., "...">`. +To declare a property with a default value, use `DefaultValuedProp<..., "...">`. If the property's storage data type is different from its interface type, for example, in the case of array properties (which are stored as `SmallVector`s but use `ArrayRef` as an interface type), add the storage-type equivalent of the default value as the third argument. -To declare an optional property, use `OptionalProperty<...>`. +To declare an optional property, use `OptionalProp<...>`. This wraps the underlying property in an `std::optional` and gives it a default value of `std::nullopt`. @@ -449,7 +449,7 @@ def MyOp : ... { I32Attr:$i32_attr, F32Attr:$f32_attr, ... - I32Property:$i32_prop, + I32Prop:$i32_prop, ... ); @@ -1011,7 +1011,7 @@ foo.op is_read_only foo.op ``` -The same logic applies to a `UnitProperty`. +The same logic applies to a `UnitProp`. ##### Optional "else" Group diff --git a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td index 03172f7ce00e4..f5ca24389065e 100644 --- a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td +++ b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td @@ -1193,7 +1193,7 @@ def AffineLinearizeIndexOp : Affine_Op<"linearize_index", let arguments = (ins Variadic:$multi_index, Variadic:$dynamic_basis, DenseI64ArrayAttr:$static_basis, - UnitProperty:$disjoint); + UnitProp:$disjoint); let results = (outs Index:$linear_index); let assemblyFormat = [{ diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index 25f4f616aecf5..a3aa53b1fcb85 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -60,7 +60,7 @@ class LLVM_IntArithmeticOpWithOverflowFlag traits = []> : LLVM_ArithmeticOpBase], traits)> { - dag iofArg = (ins EnumProperty<"IntegerOverflowFlags", "", "IntegerOverflowFlags::none">:$overflowFlags); + dag iofArg = (ins EnumProp<"IntegerOverflowFlags", "", "IntegerOverflowFlags::none">:$overflowFlags); let arguments = !con(commonArgs, iofArg); string mlirBuilder = [{ @@ -558,7 +558,7 @@ class LLVM_CastOpWithOverflowFlag traits = []> : LLVM_Op], traits)>, LLVM_Builder<"$res = builder.Create" # instName # "($arg, $_resultType, /*Name=*/\"\", op.hasNoUnsignedWrap(), op.hasNoSignedWrap());"> { - let arguments = (ins type:$arg, EnumProperty<"IntegerOverflowFlags", "", "IntegerOverflowFlags::none">:$overflowFlags); + let arguments = (ins type:$arg, EnumProp<"IntegerOverflowFlags", "", "IntegerOverflowFlags::none">:$overflowFlags); let results = (outs resultType:$res); let builders = [LLVM_OneResultOpBuilder]; let assemblyFormat = "$arg `` custom($overflowFlags) attr-dict `:` type($arg) `to` type($res)"; diff --git a/mlir/include/mlir/IR/Properties.td b/mlir/include/mlir/IR/Properties.td index df630ada78d35..212b85876c8df 100644 --- a/mlir/include/mlir/IR/Properties.td +++ b/mlir/include/mlir/IR/Properties.td @@ -14,6 +14,7 @@ #define PROPERTIES include "mlir/IR/Constraints.td" +include "mlir/IR/Utils.td" // Base class for defining properties. class Property { @@ -211,7 +212,7 @@ defvar writeMlirBytecodeWithConvertToAttribute = [{ // Primitive property kinds // Any kind of integer stored as properties. -class IntProperty : +class IntProp : Property { let summary = !if(!empty(desc), storageTypeParam, desc); let optionalParser = [{ @@ -228,10 +229,16 @@ class IntProperty : }]; } -def I32Property : IntProperty<"int32_t">; -def I64Property : IntProperty<"int64_t">; +class IntProperty + : IntProp, Deprecated<"moved to the shorter name IntProp">; -class EnumProperty : +def I32Prop : IntProp<"int32_t">; +def I64Prop : IntProp<"int64_t">; + +def I32Property : IntProp<"int32_t">, Deprecated<"moved to shorter name I32Prop">; +def I64Property : IntProp<"int64_t">, Deprecated<"moved to shorter name I64Prop">; + +class EnumProp : Property { // TODO: implement predicate for enum validity. let writeToMlirBytecode = [{ @@ -246,7 +253,12 @@ class EnumProperty { +class EnumProperty : + EnumProp, + Deprecated<"moved to shorter name EnumProp">; + +// Note: only a class so we can deprecate the old name +class _cls_StringProp : Property<"std::string", "string"> { let interfaceType = "::llvm::StringRef"; let convertFromStorage = "::llvm::StringRef{$_storage}"; let assignToStorage = "$_storage = $_value.str()"; @@ -265,8 +277,11 @@ def StringProperty : Property<"std::string", "string"> { $_writer.writeOwnedString($_storage); }]; } +def StringProp : _cls_StringProp; +def StringProperty : _cls_StringProp, Deprecated<"moved to shorter name StringProp">; -def BoolProperty : IntProperty<"bool", "boolean"> { +// Note: only a class so we can deprecate the old name +class _cls_BoolProp : IntProp<"bool", "boolean"> { let printer = [{ $_printer << ($_storage ? "true" : "false") }]; let readFromMlirBytecode = [{ return $_reader.readBool($_storage); @@ -275,8 +290,11 @@ def BoolProperty : IntProperty<"bool", "boolean"> { $_writer.writeOwnedBool($_storage); }]; } +def BoolProp : _cls_BoolProp; +def BoolProperty : _cls_BoolProp, Deprecated<"moved to shorter name BoolProp">; -def UnitProperty : Property<"bool", "unit property"> { +// Note: only a class so we can deprecate the old name +class _cls_UnitProp : Property<"bool", "unit property"> { let summary = "unit property"; let description = [{ A property whose presence or abscence is used as a flag. @@ -337,6 +355,8 @@ def UnitProperty : Property<"bool", "unit property"> { return ::mlir::failure(); }]; } +def UnitProp : _cls_UnitProp; +def UnitProperty : _cls_UnitProp, Deprecated<"moved to shorter name UnitProp">; //===----------------------------------------------------------------------===// // Property field overwrites @@ -344,7 +364,7 @@ def UnitProperty : Property<"bool", "unit property"> { /// Class for giving a property a default value. /// This doesn't change anything about the property other than giving it a default /// which can be used by ODS to elide printing. -class DefaultValuedProperty : Property { +class DefaultValuedProp : Property { let defaultValue = default; let storageTypeValueOverride = storageDefault; let baseProperty = p; @@ -365,11 +385,13 @@ class DefaultValuedProperty + : DefaultValuedProp, Deprecated<"moved to shorter name DefaultValuedProp">; /// Apply the predicate `pred` to the property `p`, ANDing it with any /// predicates it may already have. If `newSummary` is provided, replace the /// summary of `p` with `newSummary`. -class ConfinedProperty +class ConfinedProp : Property { let predicate = !if(!ne(p.predicate, TruePred), And<[p.predicate, pred]>, pred); let baseProperty = p; @@ -391,6 +413,10 @@ class ConfinedProperty let storageTypeValueOverride = p.storageTypeValueOverride; } +class ConfinedProperty + : ConfinedProp, + Deprecated<"moved to shorter name ConfinedProp">; + //===----------------------------------------------------------------------===// // Primitive property combinators @@ -428,8 +454,8 @@ class _makeStorageWrapperPred { /// `SmallVector` of that property. This uses an `ArrayAttr` as its attribute form /// though subclasses can override this, as is the case with IntArrayAttr below. /// Those wishing to use a non-default number of SmallVector elements should -/// subclass `ArrayProperty`. -class ArrayProperty, string newSummary = ""> : +/// subclass `ArrayProp`. +class ArrayProp, string newSummary = ""> : Property<"::llvm::SmallVector<" # elem.storageType # ">", !if(!empty(newSummary), "array of " # elem.summary, newSummary)> { let interfaceType = "::llvm::ArrayRef<" # elem.storageType # ">"; @@ -548,9 +574,11 @@ class ArrayProperty, string newSummary = ""> : }() }]); } +class ArrayProperty, string newSummary = ""> + : ArrayProp, Deprecated<"moved to shorter name ArrayProp">; -class IntArrayProperty : - ArrayProperty { +class IntArrayProp : + ArrayProp { // Bring back the trivial conversions we don't get in the general case. let convertFromAttribute = [{ return convertFromAttribute($_storage, $_attr, $_diag); @@ -559,6 +587,8 @@ class IntArrayProperty : return convertToAttribute($_ctxt, $_storage); }]; } +class IntArrayProperty + : IntArrayProp, Deprecated<"moved to shorter name IntArrayProp">; /// An optional property, stored as an std::optional /// interfaced with as an std::optional.. @@ -570,7 +600,7 @@ class IntArrayProperty : /// bracketing and delegate to the optional parser. In that case, the syntax is the /// syntax of the underlying property, or the keyword `none` in the rare cases that /// it is needed. This behavior can be disabled by setting `canDelegateParsing` to 0. -class OptionalProperty +class OptionalProp : Property<"std::optional<" # p.storageType # ">", "optional " # p.summary> { // In the cases where the underlying attribute is plain old data that's passed by @@ -754,4 +784,7 @@ class OptionalProperty "For delegated parsing to be used, the default value must be nullopt. " # "To use a non-trivial default, set the canDelegateParsing argument to 0"; } +class OptionalProperty + : OptionalProp, + Deprecated<"moved to shorter name OptionalProp">; #endif // PROPERTIES diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td index 384139d9c32c0..bafab155eb9d5 100644 --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -2994,11 +2994,11 @@ def TestOpWithProperties : TEST_Op<"with_properties"> { `flag` `=` $flag `,` `array` `=` $array attr-dict}]; let arguments = (ins - I64Property:$a, + I64Prop:$a, StrAttr:$b, // Attributes can directly be used here. - StringProperty:$c, - BoolProperty:$flag, - IntArrayProperty:$array // example of an array + StringProp:$c, + BoolProp:$flag, + IntArrayProp:$array // example of an array ); } @@ -3006,7 +3006,7 @@ def TestOpWithPropertiesAndAttr : TEST_Op<"with_properties_and_attr"> { let assemblyFormat = "$lhs prop-dict attr-dict"; - let arguments = (ins I32Attr:$lhs, IntProperty<"int64_t">:$rhs); + let arguments = (ins I32Attr:$lhs, IntProp<"int64_t">:$rhs); } def TestOpWithPropertiesAndInferredType @@ -3015,7 +3015,7 @@ def TestOpWithPropertiesAndInferredType ]> { let assemblyFormat = "$lhs prop-dict attr-dict"; - let arguments = (ins I32Attr:$lhs, IntProperty<"int64_t">:$rhs); + let arguments = (ins I32Attr:$lhs, IntProp<"int64_t">:$rhs); let results = (outs AnyType:$result); } @@ -3040,15 +3040,15 @@ def TestOpWithEmptyProperties : TEST_Op<"empty_properties"> { def TestOpUsingPropertyInCustom : TEST_Op<"using_property_in_custom"> { let assemblyFormat = "custom($prop) attr-dict"; - let arguments = (ins IntArrayProperty:$prop); + let arguments = (ins IntArrayProp:$prop); } def TestOpUsingPropertyInCustomAndOther : TEST_Op<"using_property_in_custom_and_other"> { let assemblyFormat = "custom($prop) prop-dict attr-dict"; let arguments = (ins - IntArrayProperty:$prop, - I64Property:$other + IntArrayProp:$prop, + I64Prop:$other ); } @@ -3063,7 +3063,7 @@ def TestOpWithVariadicSegmentProperties : TEST_Op<"variadic_segment_prop", def TestOpUsingPropertyRefInCustom : TEST_Op<"using_property_ref_in_custom"> { let assemblyFormat = "custom($first) `+` custom($second, ref($first)) attr-dict"; - let arguments = (ins IntProperty<"int64_t">:$first, IntProperty<"int64_t">:$second); + let arguments = (ins IntProp<"int64_t">:$first, IntProp<"int64_t">:$second); } def IntPropertyWithWorseBytecode : Property<"int64_t"> { @@ -3200,9 +3200,9 @@ def TestOpWithDefaultValuedProperties : TEST_Op<"with_default_valued_properties" attr-dict }]; let arguments = (ins DefaultValuedAttr:$a, - DefaultValuedProperty:$b, - DefaultValuedProperty, "-1">:$c, - UnitProperty:$unit); + DefaultValuedProp:$b, + DefaultValuedProp, "-1">:$c, + UnitProp:$unit); } def TestOpWithOptionalProperties : TEST_Op<"with_optional_properties"> { @@ -3219,15 +3219,15 @@ def TestOpWithOptionalProperties : TEST_Op<"with_optional_properties"> { }]; let arguments = (ins OptionalAttr:$anAttr, - OptionalProperty:$simple, - OptionalProperty:$nonTrivialStorage, + OptionalProp:$simple, + OptionalProp:$nonTrivialStorage, // Confirm that properties with default values now default to nullopt and have // the long syntax. - OptionalProperty>:$hasDefault, - OptionalProperty>:$nested, - OptionalProperty:$longSyntax, - UnitProperty:$hasUnit, - OptionalProperty:$maybeUnit); + OptionalProp>:$hasDefault, + OptionalProp>:$nested, + OptionalProp:$longSyntax, + UnitProp:$hasUnit, + OptionalProp:$maybeUnit); } def TestOpWithArrayProperties : TEST_Op<"with_array_properties"> { @@ -3242,37 +3242,37 @@ def TestOpWithArrayProperties : TEST_Op<"with_array_properties"> { attr-dict }]; let arguments = (ins - ArrayProperty:$ints, - ArrayProperty:$strings, - ArrayProperty>:$nested, - OptionalProperty>:$opt, - ArrayProperty>:$explicitOptions, - ArrayProperty:$explicitUnits, - DefaultValuedProperty, + ArrayProp:$ints, + ArrayProp:$strings, + ArrayProp>:$nested, + OptionalProp>:$opt, + ArrayProp>:$explicitOptions, + ArrayProp:$explicitUnits, + DefaultValuedProp, "::llvm::ArrayRef{}", "::llvm::SmallVector{}">:$hasDefault ); } -def NonNegativeI64Property : ConfinedProperty= 0">, "non-negative int64_t">; -class NonEmptyArray : ConfinedProperty - , Neg>, +class NonEmptyArray : ConfinedProp + , Neg>, "non-empty array of " # p.summary>; def OpWithPropertyPredicates : TEST_Op<"op_with_property_predicates"> { let arguments = (ins - NonNegativeI64Property:$scalar, - OptionalProperty:$optional, - DefaultValuedProperty:$defaulted, - ConfinedProperty:$optional, + DefaultValuedProp:$defaulted, + ConfinedProp, "between 0 and 5">:$more_constrained, - ArrayProperty:$array, - NonEmptyArray:$non_empty_unconstrained, - NonEmptyArray:$non_empty_constrained, + ArrayProp:$array, + NonEmptyArray:$non_empty_unconstrained, + NonEmptyArray:$non_empty_constrained, // Test applying predicates when the fromStorage() on the optional<> isn't trivial. - OptionalProperty>:$non_empty_optional, - I64Property:$unconstrained + OptionalProp>:$non_empty_optional, + I64Prop:$unconstrained ); let assemblyFormat = "attr-dict prop-dict"; } diff --git a/mlir/test/lib/Dialect/Test/TestOpsSyntax.td b/mlir/test/lib/Dialect/Test/TestOpsSyntax.td index c988d1f0ec871..2848cb994231b 100644 --- a/mlir/test/lib/Dialect/Test/TestOpsSyntax.td +++ b/mlir/test/lib/Dialect/Test/TestOpsSyntax.td @@ -88,12 +88,12 @@ def OIListTrivial : TEST_Op<"oilist_with_keywords_only"> { // Ops related to OIList primitive def OIListTrivialProperties : TEST_Op<"oilist_with_keywords_only_properties"> { - let arguments = (ins UnitProperty:$keyword, UnitProperty:$otherKeyword, - UnitProperty:$diffNameUnitPropertyKeyword); + let arguments = (ins UnitProp:$keyword, UnitProp:$otherKeyword, + UnitProp:$diffNameUnitPropKeyword); let assemblyFormat = [{ oilist( `keyword` $keyword | `otherKeyword` $otherKeyword - | `thirdKeyword` $diffNameUnitPropertyKeyword) attr-dict + | `thirdKeyword` $diffNameUnitPropKeyword) attr-dict }]; } @@ -404,13 +404,13 @@ def FormatOptionalUnitAttrNoElide } def FormatOptionalUnitProperty : TEST_Op<"format_optional_unit_property"> { - let arguments = (ins UnitProperty:$is_optional); + let arguments = (ins UnitProp:$is_optional); let assemblyFormat = "(`is_optional` $is_optional^)? attr-dict"; } def FormatOptionalUnitPropertyNoElide : TEST_Op<"format_optional_unit_property_no_elide"> { - let arguments = (ins UnitProperty:$is_optional); + let arguments = (ins UnitProp:$is_optional); let assemblyFormat = "($is_optional^)? attr-dict"; } @@ -433,8 +433,8 @@ def FormatOptionalWithElse : TEST_Op<"format_optional_else"> { def FormatOptionalPropDict : TEST_Op<"format_optional_prop_dict"> { let arguments = (ins - OptionalProperty:$a, - DefaultValuedProperty:$b); + OptionalProp:$a, + DefaultValuedProp:$b); let assemblyFormat = "prop-dict attr-dict"; } diff --git a/mlir/test/mlir-tblgen/op-format-invalid.td b/mlir/test/mlir-tblgen/op-format-invalid.td index ce91ceea34cee..3461f14fa5f01 100644 --- a/mlir/test/mlir-tblgen/op-format-invalid.td +++ b/mlir/test/mlir-tblgen/op-format-invalid.td @@ -481,12 +481,12 @@ def VariableInvalidN : TestFormat_Op<[{ // CHECK: error: property 'prop' is already bound def VariableInvalidO : TestFormat_Op<[{ custom($prop, $prop) attr-dict -}]>, Arguments<(ins IntProperty<"int64_t">:$prop)>; +}]>, Arguments<(ins IntProp<"int64_t">:$prop)>; // CHECK: error: property 'prop' must be bound before it is referenced def VariableInvalidP : TestFormat_Op<[{ custom(ref($prop)) attr-dict -}]>, Arguments<(ins IntProperty<"int64_t">:$prop)>; +}]>, Arguments<(ins IntProp<"int64_t">:$prop)>; //===----------------------------------------------------------------------===// // Coverage Checks diff --git a/mlir/test/mlir-tblgen/op-properties-predicates.td b/mlir/test/mlir-tblgen/op-properties-predicates.td index fa06e14fb1998..de59f5166d7e1 100644 --- a/mlir/test/mlir-tblgen/op-properties-predicates.td +++ b/mlir/test/mlir-tblgen/op-properties-predicates.td @@ -12,26 +12,26 @@ def Test_Dialect : Dialect { class NS_Op traits = []> : Op; -def NonNegativeI64Property : ConfinedProperty= 0">, "non-negative int64_t">; -class NonEmptyArray : ConfinedProperty - , Neg>, +class NonEmptyArray : ConfinedProp + , Neg>, "non-empty array of " # p.summary>; def OpWithPredicates : NS_Op<"op_with_predicates"> { let arguments = (ins - NonNegativeI64Property:$scalar, - OptionalProperty:$optional, - DefaultValuedProperty:$defaulted, - ConfinedProperty:$optional, + DefaultValuedProp:$defaulted, + ConfinedProp, "between 0 and 5">:$moreConstrained, - ArrayProperty:$array, - NonEmptyArray:$non_empty_unconstrained, - NonEmptyArray:$non_empty_constrained, + ArrayProp:$array, + NonEmptyArray:$non_empty_unconstrained, + NonEmptyArray:$non_empty_constrained, // Test applying predicates when the fromStorage() on the optional<> isn't trivial. - OptionalProperty>:$non_empty_optional, - I64Property:$unconstrained + OptionalProp>:$non_empty_optional, + I64Prop:$unconstrained ); } diff --git a/mlir/test/mlir-tblgen/op-properties.td b/mlir/test/mlir-tblgen/op-properties.td index bf32ce42cf6fb..66888e60ab997 100644 --- a/mlir/test/mlir-tblgen/op-properties.td +++ b/mlir/test/mlir-tblgen/op-properties.td @@ -20,18 +20,18 @@ def OpWithAttr : NS_Op<"op_with_attr">{ // Test required and optional properties // --- -def DefaultI64Array : IntArrayProperty { +def DefaultI64Array : IntArrayProp { let defaultValue = "::llvm::ArrayRef{}"; let storageTypeValueOverride = "::llvm::SmallVector{}"; } def OpWithProps : NS_Op<"op_with_props"> { let arguments = (ins - BoolProperty:$flag, - StringProperty:$string, - ArrayProperty:$strings, - DefaultValuedProperty:$default_int, - OptionalProperty:$optional, + BoolProp:$flag, + StringProp:$string, + ArrayProp:$strings, + DefaultValuedProp:$default_int, + OptionalProp:$optional, DefaultI64Array:$intArray ); } @@ -39,10 +39,10 @@ def OpWithProps : NS_Op<"op_with_props"> { /// Check that optional arguments to builders only go at the end. def OpWithSomeOptionalProperties : NS_Op<"op_with_some_optional_props"> { let arguments = (ins - OptionalProperty:$mustSpecify, - I64Property:$required, - OptionalProperty:$canOmit, - DefaultValuedProperty:$canOmit2 + OptionalProp:$mustSpecify, + I64Prop:$required, + OptionalProp:$canOmit, + DefaultValuedProp:$canOmit2 ); } @@ -51,10 +51,10 @@ def OpWithSomeOptionalProperties : NS_Op<"op_with_some_optional_props"> { def OpWithOptionalPropsAndAttrs : NS_Op<"with_some_optional_props_and_atts"> { let arguments = (ins - OptionalProperty:$mustSpecify, + OptionalProp:$mustSpecify, OptionalAttr:$ambiguous, OptionalAttr:$canOmit, - OptionalProperty:$canOmitProp + OptionalProp:$canOmitProp ); } diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp index 1f8d8992f898a..f03a3bfd398ed 100644 --- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp @@ -113,13 +113,16 @@ struct AttributeLikeVariable : public VariableElement { return isa(fe) && classof(cast(fe)); } - /// Returns true if the variable is a UnitAttr or a UnitProperty. + /// Returns true if the variable is a UnitAttr or a UnitProp. bool isUnit() const { if (const auto *attr = dyn_cast(this)) return attr->getVar()->attr.getBaseAttr().getAttrDefName() == "UnitAttr"; if (const auto *prop = dyn_cast(this)) { - return prop->getVar()->prop.getBaseProperty().getPropertyDefName() == - "UnitProperty"; + StringRef baseDefName = + prop->getVar()->prop.getBaseProperty().getPropertyDefName(); + // Note: remove the `UnitProperty` case once the deprecation period is + // over. + return baseDefName == "UnitProp" || baseDefName == "UnitProperty"; } llvm_unreachable("Type that wasn't listed in classof()"); }