Skip to content

Commit 9808538

Browse files
committed
[mlir][Properties] Shorten "Property" to "Prop" in most places
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 12a6e24 commit 9808538

File tree

10 files changed

+135
-101
lines changed

10 files changed

+135
-101
lines changed

mlir/docs/DefiningDialects/Operations.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ their semantics via a special [TableGen backend][TableGenBackend]:
102102
constraints over attributes. A notable subclass hierarchy is `Attr`, which
103103
stands for constraints for attributes whose values are of common types.
104104
* The `Property` class hierarchy: They are used to specify non-attribute-backed
105-
properties that are inherent to operations. This will be expanded to a
106-
`PropertyConstraint` class or something similar in the future.
105+
properties that are inherent to operations. These properties can have
106+
constraints imposed them using their `predicate` field or the
107+
`ConfinedProp` class.
107108

108109
An operation is defined by specializing the `Op` class with concrete contents
109110
for all the fields it requires. For example, `tf.AvgPool` is defined as
@@ -202,15 +203,15 @@ let arguments = (ins
202203
...
203204
<attr-constraint>:$<attr-name>,
204205
...
205-
<property-constraint>:$<property-name>,
206+
<property>:$<property-name>,
206207
);
207208
```
208209

209210
Here `<type-constraint>` is a TableGen `def` from the `TypeConstraint` class
210211
hierarchy. Similarly, `<attr-constraint>` is a TableGen `def` from the
211-
`AttrConstraint` class hierarchy and `<property-constraint>` is a subclass
212-
of `Property` (though a `PropertyConstraint` hierarchy is planned).
213-
See [Constraints](#constraints) for more information.
212+
`AttrConstraint` class hierarchy and `<property>` is a subclass
213+
of `Property` (constraints can be imposed onto it using its `predicate` field
214+
or the `ConfinedProp` subclass).
214215

215216
There is no requirements on the relative order of operands and attributes; they
216217
can mix freely. The relative order of operands themselves matters. From each
@@ -334,13 +335,13 @@ TODO: Design and implement more primitive constraints
334335

335336
#### Optional and default-valued properties
336337

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

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

@@ -449,7 +450,7 @@ def MyOp : ... {
449450
I32Attr:$i32_attr,
450451
F32Attr:$f32_attr,
451452
...
452-
I32Property:$i32_prop,
453+
I32Prop:$i32_prop,
453454
...
454455
);
455456
@@ -1011,7 +1012,7 @@ foo.op is_read_only
10111012
foo.op
10121013
```
10131014

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

10161017
##### Optional "else" Group
10171018

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

0 commit comments

Comments
 (0)