Skip to content

Commit 378e179

Browse files
authored
[mlir][Properties] Shorten "Property" to "Prop" in most places (llvm#120368)
Since the property system isn't currently in heavy use, it's probably the right time to fix a choice I made when expanding ODS property support. Specifically, most of the property subclasses, like OptionalProperty or IntProperty, wrote out the word "Property" in full. The corresponding classes in the Attribute hierarchy uses the short-form "Attr" in those cases, as in OptionalAttr or DefaultValuedAttr. This commit changes all those uses of "Property" to "Prop" in order to prevent excessively verbose tablegen files that needlessly repeat the full name of a core concept that can be abbreviated. So, this commit renames all the FooProperty classes to FooProp, and keeps the existing names as alias with a Deprecated<> on them to warn people. In addition, this commit updates the documentation around properties to mention the constraint support.
1 parent 1c25a3b commit 378e179

File tree

10 files changed

+132
-96
lines changed

10 files changed

+132
-96
lines changed

mlir/docs/DefiningDialects/Operations.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,13 @@ TODO: Design and implement more primitive constraints
334334

335335
#### Optional and default-valued properties
336336

337-
To declare a property with a default value, use `DefaultValuedProperty<..., "...">`.
337+
To declare a property with a default value, use `DefaultValuedProp<..., "...">`.
338338
If the property's storage data type is different from its interface type,
339339
for example, in the case of array properties (which are stored as `SmallVector`s
340340
but use `ArrayRef` as an interface type), add the storage-type equivalent
341341
of the default value as the third argument.
342342

343-
To declare an optional property, use `OptionalProperty<...>`.
343+
To declare an optional property, use `OptionalProp<...>`.
344344
This wraps the underlying property in an `std::optional` and gives it a
345345
default value of `std::nullopt`.
346346

@@ -449,7 +449,7 @@ def MyOp : ... {
449449
I32Attr:$i32_attr,
450450
F32Attr:$f32_attr,
451451
...
452-
I32Property:$i32_prop,
452+
I32Prop:$i32_prop,
453453
...
454454
);
455455
@@ -1011,7 +1011,7 @@ foo.op is_read_only
10111011
foo.op
10121012
```
10131013

1014-
The same logic applies to a `UnitProperty`.
1014+
The same logic applies to a `UnitProp`.
10151015

10161016
##### Optional "else" Group
10171017

mlir/include/mlir/Dialect/Affine/IR/AffineOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ def AffineLinearizeIndexOp : Affine_Op<"linearize_index",
11931193
let arguments = (ins Variadic<Index>:$multi_index,
11941194
Variadic<Index>:$dynamic_basis,
11951195
DenseI64ArrayAttr:$static_basis,
1196-
UnitProperty:$disjoint);
1196+
UnitProp:$disjoint);
11971197
let results = (outs Index:$linear_index);
11981198

11991199
let assemblyFormat = [{

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class LLVM_IntArithmeticOpWithOverflowFlag<string mnemonic, string instName,
6060
list<Trait> traits = []> :
6161
LLVM_ArithmeticOpBase<AnySignlessInteger, mnemonic, instName,
6262
!listconcat([DeclareOpInterfaceMethods<IntegerOverflowFlagsInterface>], traits)> {
63-
dag iofArg = (ins EnumProperty<"IntegerOverflowFlags", "", "IntegerOverflowFlags::none">:$overflowFlags);
63+
dag iofArg = (ins EnumProp<"IntegerOverflowFlags", "", "IntegerOverflowFlags::none">:$overflowFlags);
6464
let arguments = !con(commonArgs, iofArg);
6565

6666
string mlirBuilder = [{
@@ -558,7 +558,7 @@ class LLVM_CastOpWithOverflowFlag<string mnemonic, string instName, Type type,
558558
Type resultType, list<Trait> traits = []> :
559559
LLVM_Op<mnemonic, !listconcat([Pure], [DeclareOpInterfaceMethods<IntegerOverflowFlagsInterface>], traits)>,
560560
LLVM_Builder<"$res = builder.Create" # instName # "($arg, $_resultType, /*Name=*/\"\", op.hasNoUnsignedWrap(), op.hasNoSignedWrap());"> {
561-
let arguments = (ins type:$arg, EnumProperty<"IntegerOverflowFlags", "", "IntegerOverflowFlags::none">:$overflowFlags);
561+
let arguments = (ins type:$arg, EnumProp<"IntegerOverflowFlags", "", "IntegerOverflowFlags::none">:$overflowFlags);
562562
let results = (outs resultType:$res);
563563
let builders = [LLVM_OneResultOpBuilder];
564564
let assemblyFormat = "$arg `` custom<OverflowFlags>($overflowFlags) attr-dict `:` type($arg) `to` type($res)";

mlir/include/mlir/IR/Properties.td

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define PROPERTIES
1515

1616
include "mlir/IR/Constraints.td"
17+
include "mlir/IR/Utils.td"
1718

1819
// Base class for defining properties.
1920
class Property<string storageTypeParam = "", string desc = ""> {
@@ -211,7 +212,7 @@ defvar writeMlirBytecodeWithConvertToAttribute = [{
211212
// Primitive property kinds
212213

213214
// Any kind of integer stored as properties.
214-
class IntProperty<string storageTypeParam, string desc = ""> :
215+
class IntProp<string storageTypeParam, string desc = ""> :
215216
Property<storageTypeParam, desc> {
216217
let summary = !if(!empty(desc), storageTypeParam, desc);
217218
let optionalParser = [{
@@ -228,10 +229,16 @@ class IntProperty<string storageTypeParam, string desc = ""> :
228229
}];
229230
}
230231

231-
def I32Property : IntProperty<"int32_t">;
232-
def I64Property : IntProperty<"int64_t">;
232+
class IntProperty<string storageTypeParam, string desc = "">
233+
: IntProp<storageTypeParam, desc>, Deprecated<"moved to the shorter name IntProp">;
233234

234-
class EnumProperty<string storageTypeParam, string desc = "", string default = ""> :
235+
def I32Prop : IntProp<"int32_t">;
236+
def I64Prop : IntProp<"int64_t">;
237+
238+
def I32Property : IntProp<"int32_t">, Deprecated<"moved to shorter name I32Prop">;
239+
def I64Property : IntProp<"int64_t">, Deprecated<"moved to shorter name I64Prop">;
240+
241+
class EnumProp<string storageTypeParam, string desc = "", string default = ""> :
235242
Property<storageTypeParam, desc> {
236243
// TODO: implement predicate for enum validity.
237244
let writeToMlirBytecode = [{
@@ -246,7 +253,12 @@ class EnumProperty<string storageTypeParam, string desc = "", string default = "
246253
let defaultValue = default;
247254
}
248255

249-
def StringProperty : Property<"std::string", "string"> {
256+
class EnumProperty<string storageTypeParam, string desc = "", string default = ""> :
257+
EnumProp<storageTypeParam, desc, default>,
258+
Deprecated<"moved to shorter name EnumProp">;
259+
260+
// Note: only a class so we can deprecate the old name
261+
class _cls_StringProp : Property<"std::string", "string"> {
250262
let interfaceType = "::llvm::StringRef";
251263
let convertFromStorage = "::llvm::StringRef{$_storage}";
252264
let assignToStorage = "$_storage = $_value.str()";
@@ -265,8 +277,11 @@ def StringProperty : Property<"std::string", "string"> {
265277
$_writer.writeOwnedString($_storage);
266278
}];
267279
}
280+
def StringProp : _cls_StringProp;
281+
def StringProperty : _cls_StringProp, Deprecated<"moved to shorter name StringProp">;
268282

269-
def BoolProperty : IntProperty<"bool", "boolean"> {
283+
// Note: only a class so we can deprecate the old name
284+
class _cls_BoolProp : IntProp<"bool", "boolean"> {
270285
let printer = [{ $_printer << ($_storage ? "true" : "false") }];
271286
let readFromMlirBytecode = [{
272287
return $_reader.readBool($_storage);
@@ -275,8 +290,11 @@ def BoolProperty : IntProperty<"bool", "boolean"> {
275290
$_writer.writeOwnedBool($_storage);
276291
}];
277292
}
293+
def BoolProp : _cls_BoolProp;
294+
def BoolProperty : _cls_BoolProp, Deprecated<"moved to shorter name BoolProp">;
278295

279-
def UnitProperty : Property<"bool", "unit property"> {
296+
// Note: only a class so we can deprecate the old name
297+
class _cls_UnitProp : Property<"bool", "unit property"> {
280298
let summary = "unit property";
281299
let description = [{
282300
A property whose presence or abscence is used as a flag.
@@ -337,14 +355,16 @@ def UnitProperty : Property<"bool", "unit property"> {
337355
return ::mlir::failure();
338356
}];
339357
}
358+
def UnitProp : _cls_UnitProp;
359+
def UnitProperty : _cls_UnitProp, Deprecated<"moved to shorter name UnitProp">;
340360

341361
//===----------------------------------------------------------------------===//
342362
// Property field overwrites
343363

344364
/// Class for giving a property a default value.
345365
/// This doesn't change anything about the property other than giving it a default
346366
/// which can be used by ODS to elide printing.
347-
class DefaultValuedProperty<Property p, string default = "", string storageDefault = ""> : Property<p.storageType, p.summary> {
367+
class DefaultValuedProp<Property p, string default = "", string storageDefault = ""> : Property<p.storageType, p.summary> {
348368
let defaultValue = default;
349369
let storageTypeValueOverride = storageDefault;
350370
let baseProperty = p;
@@ -365,11 +385,13 @@ class DefaultValuedProperty<Property p, string default = "", string storageDefau
365385
let readFromMlirBytecode = p.readFromMlirBytecode;
366386
let writeToMlirBytecode = p.writeToMlirBytecode;
367387
}
388+
class DefaultValuedProperty<Property p, string default = "", string storageDefault = "">
389+
: DefaultValuedProp<p, default, storageDefault>, Deprecated<"moved to shorter name DefaultValuedProp">;
368390

369391
/// Apply the predicate `pred` to the property `p`, ANDing it with any
370392
/// predicates it may already have. If `newSummary` is provided, replace the
371393
/// summary of `p` with `newSummary`.
372-
class ConfinedProperty<Property p, Pred pred, string newSummary = "">
394+
class ConfinedProp<Property p, Pred pred, string newSummary = "">
373395
: Property<p.storageType, !if(!empty(newSummary), p.summary, newSummary)> {
374396
let predicate = !if(!ne(p.predicate, TruePred), And<[p.predicate, pred]>, pred);
375397
let baseProperty = p;
@@ -391,6 +413,10 @@ class ConfinedProperty<Property p, Pred pred, string newSummary = "">
391413
let storageTypeValueOverride = p.storageTypeValueOverride;
392414
}
393415

416+
class ConfinedProperty<Property p, Pred pred, string newSummary = "">
417+
: ConfinedProp<p, pred, newSummary>,
418+
Deprecated<"moved to shorter name ConfinedProp">;
419+
394420
//===----------------------------------------------------------------------===//
395421
// Primitive property combinators
396422

@@ -428,8 +454,8 @@ class _makeStorageWrapperPred<Property wrappedProp> {
428454
/// `SmallVector` of that property. This uses an `ArrayAttr` as its attribute form
429455
/// though subclasses can override this, as is the case with IntArrayAttr below.
430456
/// Those wishing to use a non-default number of SmallVector elements should
431-
/// subclass `ArrayProperty`.
432-
class ArrayProperty<Property elem = Property<>, string newSummary = ""> :
457+
/// subclass `ArrayProp`.
458+
class ArrayProp<Property elem = Property<>, string newSummary = ""> :
433459
Property<"::llvm::SmallVector<" # elem.storageType # ">",
434460
!if(!empty(newSummary), "array of " # elem.summary, newSummary)> {
435461
let interfaceType = "::llvm::ArrayRef<" # elem.storageType # ">";
@@ -548,9 +574,11 @@ class ArrayProperty<Property elem = Property<>, string newSummary = ""> :
548574
}()
549575
}]);
550576
}
577+
class ArrayProperty<Property elem = Property<>, string newSummary = "">
578+
: ArrayProp<elem, newSummary>, Deprecated<"moved to shorter name ArrayProp">;
551579

552-
class IntArrayProperty<Property elem, string newSummary=""> :
553-
ArrayProperty<elem, newSummary> {
580+
class IntArrayProp<Property elem, string newSummary=""> :
581+
ArrayProp<elem, newSummary> {
554582
// Bring back the trivial conversions we don't get in the general case.
555583
let convertFromAttribute = [{
556584
return convertFromAttribute($_storage, $_attr, $_diag);
@@ -559,6 +587,8 @@ class IntArrayProperty<Property elem, string newSummary=""> :
559587
return convertToAttribute($_ctxt, $_storage);
560588
}];
561589
}
590+
class IntArrayProperty<Property elem, string newSummary="">
591+
: IntArrayProp<elem, newSummary>, Deprecated<"moved to shorter name IntArrayProp">;
562592

563593
/// An optional property, stored as an std::optional<p.storageType>
564594
/// interfaced with as an std::optional<p.interfaceType>..
@@ -570,7 +600,7 @@ class IntArrayProperty<Property elem, string newSummary=""> :
570600
/// bracketing and delegate to the optional parser. In that case, the syntax is the
571601
/// syntax of the underlying property, or the keyword `none` in the rare cases that
572602
/// it is needed. This behavior can be disabled by setting `canDelegateParsing` to 0.
573-
class OptionalProperty<Property p, bit canDelegateParsing = 1>
603+
class OptionalProp<Property p, bit canDelegateParsing = 1>
574604
: Property<"std::optional<" # p.storageType # ">", "optional " # p.summary> {
575605

576606
// In the cases where the underlying attribute is plain old data that's passed by
@@ -754,4 +784,7 @@ class OptionalProperty<Property p, bit canDelegateParsing = 1>
754784
"For delegated parsing to be used, the default value must be nullopt. " #
755785
"To use a non-trivial default, set the canDelegateParsing argument to 0";
756786
}
787+
class OptionalProperty<Property p, bit canDelegateParsing = 1>
788+
: OptionalProp<p, canDelegateParsing>,
789+
Deprecated<"moved to shorter name OptionalProp">;
757790
#endif // PROPERTIES

mlir/test/lib/Dialect/Test/TestOps.td

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,19 +2994,19 @@ def TestOpWithProperties : TEST_Op<"with_properties"> {
29942994
`flag` `=` $flag `,`
29952995
`array` `=` $array attr-dict}];
29962996
let arguments = (ins
2997-
I64Property:$a,
2997+
I64Prop:$a,
29982998
StrAttr:$b, // Attributes can directly be used here.
2999-
StringProperty:$c,
3000-
BoolProperty:$flag,
3001-
IntArrayProperty<I64Property>:$array // example of an array
2999+
StringProp:$c,
3000+
BoolProp:$flag,
3001+
IntArrayProp<I64Prop>:$array // example of an array
30023002
);
30033003
}
30043004

30053005
def TestOpWithPropertiesAndAttr
30063006
: TEST_Op<"with_properties_and_attr"> {
30073007
let assemblyFormat = "$lhs prop-dict attr-dict";
30083008

3009-
let arguments = (ins I32Attr:$lhs, IntProperty<"int64_t">:$rhs);
3009+
let arguments = (ins I32Attr:$lhs, IntProp<"int64_t">:$rhs);
30103010
}
30113011

30123012
def TestOpWithPropertiesAndInferredType
@@ -3015,7 +3015,7 @@ def TestOpWithPropertiesAndInferredType
30153015
]> {
30163016
let assemblyFormat = "$lhs prop-dict attr-dict";
30173017

3018-
let arguments = (ins I32Attr:$lhs, IntProperty<"int64_t">:$rhs);
3018+
let arguments = (ins I32Attr:$lhs, IntProp<"int64_t">:$rhs);
30193019
let results = (outs AnyType:$result);
30203020
}
30213021

@@ -3040,15 +3040,15 @@ def TestOpWithEmptyProperties : TEST_Op<"empty_properties"> {
30403040

30413041
def TestOpUsingPropertyInCustom : TEST_Op<"using_property_in_custom"> {
30423042
let assemblyFormat = "custom<UsingPropertyInCustom>($prop) attr-dict";
3043-
let arguments = (ins IntArrayProperty<I64Property>:$prop);
3043+
let arguments = (ins IntArrayProp<I64Prop>:$prop);
30443044
}
30453045

30463046
def TestOpUsingPropertyInCustomAndOther
30473047
: TEST_Op<"using_property_in_custom_and_other"> {
30483048
let assemblyFormat = "custom<UsingPropertyInCustom>($prop) prop-dict attr-dict";
30493049
let arguments = (ins
3050-
IntArrayProperty<I64Property>:$prop,
3051-
I64Property:$other
3050+
IntArrayProp<I64Prop>:$prop,
3051+
I64Prop:$other
30523052
);
30533053
}
30543054

@@ -3063,7 +3063,7 @@ def TestOpWithVariadicSegmentProperties : TEST_Op<"variadic_segment_prop",
30633063

30643064
def TestOpUsingPropertyRefInCustom : TEST_Op<"using_property_ref_in_custom"> {
30653065
let assemblyFormat = "custom<IntProperty>($first) `+` custom<SumProperty>($second, ref($first)) attr-dict";
3066-
let arguments = (ins IntProperty<"int64_t">:$first, IntProperty<"int64_t">:$second);
3066+
let arguments = (ins IntProp<"int64_t">:$first, IntProp<"int64_t">:$second);
30673067
}
30683068

30693069
def IntPropertyWithWorseBytecode : Property<"int64_t"> {
@@ -3200,9 +3200,9 @@ def TestOpWithDefaultValuedProperties : TEST_Op<"with_default_valued_properties"
32003200
attr-dict
32013201
}];
32023202
let arguments = (ins DefaultValuedAttr<I32Attr, "0">:$a,
3203-
DefaultValuedProperty<StringProperty, "\"\"">:$b,
3204-
DefaultValuedProperty<IntProperty<"int32_t">, "-1">:$c,
3205-
UnitProperty:$unit);
3203+
DefaultValuedProp<StringProp, "\"\"">:$b,
3204+
DefaultValuedProp<IntProp<"int32_t">, "-1">:$c,
3205+
UnitProp:$unit);
32063206
}
32073207

32083208
def TestOpWithOptionalProperties : TEST_Op<"with_optional_properties"> {
@@ -3219,15 +3219,15 @@ def TestOpWithOptionalProperties : TEST_Op<"with_optional_properties"> {
32193219
}];
32203220
let arguments = (ins
32213221
OptionalAttr<I32Attr>:$anAttr,
3222-
OptionalProperty<I64Property>:$simple,
3223-
OptionalProperty<StringProperty>:$nonTrivialStorage,
3222+
OptionalProp<I64Prop>:$simple,
3223+
OptionalProp<StringProp>:$nonTrivialStorage,
32243224
// Confirm that properties with default values now default to nullopt and have
32253225
// the long syntax.
3226-
OptionalProperty<DefaultValuedProperty<I64Property, "0">>:$hasDefault,
3227-
OptionalProperty<OptionalProperty<I64Property>>:$nested,
3228-
OptionalProperty<StringProperty, 0>:$longSyntax,
3229-
UnitProperty:$hasUnit,
3230-
OptionalProperty<UnitProperty>:$maybeUnit);
3226+
OptionalProp<DefaultValuedProp<I64Prop, "0">>:$hasDefault,
3227+
OptionalProp<OptionalProp<I64Prop>>:$nested,
3228+
OptionalProp<StringProp, 0>:$longSyntax,
3229+
UnitProp:$hasUnit,
3230+
OptionalProp<UnitProp>:$maybeUnit);
32313231
}
32323232

32333233
def TestOpWithArrayProperties : TEST_Op<"with_array_properties"> {
@@ -3242,37 +3242,37 @@ def TestOpWithArrayProperties : TEST_Op<"with_array_properties"> {
32423242
attr-dict
32433243
}];
32443244
let arguments = (ins
3245-
ArrayProperty<I64Property>:$ints,
3246-
ArrayProperty<StringProperty>:$strings,
3247-
ArrayProperty<ArrayProperty<I32Property>>:$nested,
3248-
OptionalProperty<ArrayProperty<I32Property>>:$opt,
3249-
ArrayProperty<OptionalProperty<I64Property>>:$explicitOptions,
3250-
ArrayProperty<UnitProperty>:$explicitUnits,
3251-
DefaultValuedProperty<ArrayProperty<I64Property>,
3245+
ArrayProp<I64Prop>:$ints,
3246+
ArrayProp<StringProp>:$strings,
3247+
ArrayProp<ArrayProp<I32Prop>>:$nested,
3248+
OptionalProp<ArrayProp<I32Prop>>:$opt,
3249+
ArrayProp<OptionalProp<I64Prop>>:$explicitOptions,
3250+
ArrayProp<UnitProp>:$explicitUnits,
3251+
DefaultValuedProp<ArrayProp<I64Prop>,
32523252
"::llvm::ArrayRef<int64_t>{}", "::llvm::SmallVector<int64_t>{}">:$hasDefault
32533253
);
32543254
}
32553255

3256-
def NonNegativeI64Property : ConfinedProperty<I64Property,
3256+
def NonNegativeI64Prop : ConfinedProp<I64Prop,
32573257
CPred<"$_self >= 0">, "non-negative int64_t">;
32583258

3259-
class NonEmptyArray<Property p> : ConfinedProperty
3260-
<ArrayProperty<p>, Neg<CPred<"$_self.empty()">>,
3259+
class NonEmptyArray<Property p> : ConfinedProp
3260+
<ArrayProp<p>, Neg<CPred<"$_self.empty()">>,
32613261
"non-empty array of " # p.summary>;
32623262

32633263
def OpWithPropertyPredicates : TEST_Op<"op_with_property_predicates"> {
32643264
let arguments = (ins
3265-
NonNegativeI64Property:$scalar,
3266-
OptionalProperty<NonNegativeI64Property>:$optional,
3267-
DefaultValuedProperty<NonNegativeI64Property, "0">:$defaulted,
3268-
ConfinedProperty<NonNegativeI64Property,
3265+
NonNegativeI64Prop:$scalar,
3266+
OptionalProp<NonNegativeI64Prop>:$optional,
3267+
DefaultValuedProp<NonNegativeI64Prop, "0">:$defaulted,
3268+
ConfinedProp<NonNegativeI64Prop,
32693269
CPred<"$_self <= 5">, "between 0 and 5">:$more_constrained,
3270-
ArrayProperty<NonNegativeI64Property>:$array,
3271-
NonEmptyArray<I64Property>:$non_empty_unconstrained,
3272-
NonEmptyArray<NonNegativeI64Property>:$non_empty_constrained,
3270+
ArrayProp<NonNegativeI64Prop>:$array,
3271+
NonEmptyArray<I64Prop>:$non_empty_unconstrained,
3272+
NonEmptyArray<NonNegativeI64Prop>:$non_empty_constrained,
32733273
// Test applying predicates when the fromStorage() on the optional<> isn't trivial.
3274-
OptionalProperty<NonEmptyArray<NonNegativeI64Property>>:$non_empty_optional,
3275-
I64Property:$unconstrained
3274+
OptionalProp<NonEmptyArray<NonNegativeI64Prop>>:$non_empty_optional,
3275+
I64Prop:$unconstrained
32763276
);
32773277
let assemblyFormat = "attr-dict prop-dict";
32783278
}

0 commit comments

Comments
 (0)