Skip to content

Commit 32f5437

Browse files
authored
Revert "[mlir][ODS] Add a generated builder that takes the Properties struct" (#130117)
Reverts #124713. Builders involving sanitizers are failing: https://lab.llvm.org/buildbot/#/builders/169/builds/9106.
1 parent ff993f9 commit 32f5437

File tree

10 files changed

+49
-227
lines changed

10 files changed

+49
-227
lines changed

mlir/docs/DeclarativeRewrites.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ In the above, we are using `BOp`'s result for building `COp`.
237237

238238
Given that `COp` was specified with table-driven op definition, there will be
239239
several `build()` methods generated for it. One of them has aggregated
240-
parameters for result types, operands, and properties in the signature: `void
240+
parameters for result types, operands, and attributes in the signature: `void
241241
COp::build(..., ArrayRef<Type> resultTypes, Array<Value> operands,
242-
const COp::Properties& properties)`. The pattern in the above calls this `build()`
242+
ArrayRef<NamedAttribute> attr)`. The pattern in the above calls this `build()`
243243
method for constructing the `COp`.
244244

245245
In general, arguments in the result pattern will be passed directly to the

mlir/docs/DefiningDialects/Operations.md

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -465,18 +465,7 @@ def MyOp : ... {
465465
The following builders are generated:
466466

467467
```c++
468-
// All result-types/operands/properties/discardable attributes have one
469-
// aggregate parameter. `Properties` is the properties structure of
470-
// `MyOp`.
471-
static void build(OpBuilder &odsBuilder, OperationState &odsState,
472-
TypeRange resultTypes,
473-
ValueRange operands,
474-
Properties properties,
475-
ArrayRef<NamedAttribute> discardableAttributes = {});
476-
477468
// All result-types/operands/attributes have one aggregate parameter.
478-
// Inherent properties and discardable attributes are mixed together in the
479-
// `attributes` dictionary.
480469
static void build(OpBuilder &odsBuilder, OperationState &odsState,
481470
TypeRange resultTypes,
482471
ValueRange operands,
@@ -509,28 +498,20 @@ static void build(OpBuilder &odsBuilder, OperationState &odsState,
509498

510499
// All operands/attributes have aggregate parameters.
511500
// Generated if return type can be inferred.
512-
static void build(OpBuilder &odsBuilder, OperationState &odsState,
513-
ValueRange operands,
514-
Properties properties,
515-
ArrayRef<NamedAttribute> discardableAttributes);
516-
517-
// All operands/attributes have aggregate parameters.
518-
// Generated if return type can be inferred. Uses the legacy merged attribute
519-
// dictionary.
520501
static void build(OpBuilder &odsBuilder, OperationState &odsState,
521502
ValueRange operands, ArrayRef<NamedAttribute> attributes);
522503

523504
// (And manually specified builders depending on the specific op.)
524505
```
525506
526-
The first two forms provide basic uniformity so that we can create ops using
527-
the same form regardless of the exact op. This is particularly useful for
507+
The first form provides basic uniformity so that we can create ops using the
508+
same form regardless of the exact op. This is particularly useful for
528509
implementing declarative pattern rewrites.
529510
530-
The third and fourth forms are good for use in manually written code, given that
511+
The second and third forms are good for use in manually written code, given that
531512
they provide better guarantee via signatures.
532513
533-
The fourth form will be generated if any of the op's attribute has different
514+
The third form will be generated if any of the op's attribute has different
534515
`Attr.returnType` from `Attr.storageType` and we know how to build an attribute
535516
from an unwrapped value (i.e., `Attr.constBuilderCall` is defined.)
536517
Additionally, for the third form, if an attribute appearing later in the

mlir/include/mlir/IR/OpDefinition.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ void ensureRegionTerminator(
7474

7575
/// Structure used by default as a "marker" when no "Properties" are set on an
7676
/// Operation.
77-
struct EmptyProperties {
78-
bool operator==(const EmptyProperties &) const { return true; }
79-
bool operator!=(const EmptyProperties &) const { return false; }
80-
};
77+
struct EmptyProperties {};
8178

8279
/// Traits to detect whether an Operation defined a `Properties` type, otherwise
8380
/// it'll default to `EmptyProperties`.

mlir/include/mlir/IR/OperationSupport.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,24 +1029,6 @@ struct OperationState {
10291029
setProperties(Operation *op,
10301030
function_ref<InFlightDiagnostic()> emitError) const;
10311031

1032-
// Make `newProperties` the source of the properties that will be copied into
1033-
// the operation. The memory referenced by `newProperties` must remain live
1034-
// until after the `Operation` is created, at which time it may be
1035-
// deallocated. Calls to `getOrAddProperties<>() will return references to
1036-
// this memory.
1037-
template <typename T>
1038-
void useProperties(T &newProperties) {
1039-
assert(!properties &&
1040-
"Can't provide a properties struct when one has been allocated");
1041-
properties = &newProperties;
1042-
propertiesDeleter = [](OpaqueProperties) {};
1043-
propertiesSetter = [](OpaqueProperties newProp,
1044-
const OpaqueProperties prop) {
1045-
*newProp.as<T *>() = *prop.as<const T *>();
1046-
};
1047-
propertiesId = TypeID::get<T>();
1048-
}
1049-
10501032
void addOperands(ValueRange newOperands);
10511033

10521034
void addTypes(ArrayRef<Type> newTypes) {

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,13 +2504,6 @@ def TableGenBuildOp6 : TEST_Op<"tblgen_build_6", [AttrSizedOperandSegments]> {
25042504
let results = (outs F32:$result);
25052505
}
25062506

2507-
// An inherent attribute. Test collective builders, both those that take properties as
2508-
// properties structs and those that take an attribute dictionary.
2509-
def TableGenBuildOp7 : TEST_Op<"tblgen_build_7", []> {
2510-
let arguments = (ins BoolAttr:$attr0);
2511-
let results = (outs);
2512-
}
2513-
25142507
//===----------------------------------------------------------------------===//
25152508
// Test BufferPlacement
25162509
//===----------------------------------------------------------------------===//

mlir/test/mlir-tblgen/op-attribute.td

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,6 @@ def AOp : NS_Op<"a_op", []> {
165165
// DEF: ::llvm::ArrayRef<::mlir::NamedAttribute> attributes
166166
// DEF: odsState.addAttributes(attributes);
167167

168-
// DEF: void AOp::build(
169-
// DEF-SAME: const Properties &properties,
170-
// DEF-SAME: ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes
171-
// DEF: odsState.useProperties(const_cast<Properties&>(properties));
172-
// DEF: odsState.addAttributes(discardableAttributes);
173-
174168
// DEF: void AOp::populateDefaultProperties
175169

176170
// Test the above but with prefix.
@@ -285,12 +279,6 @@ def AgetOp : Op<Test2_Dialect, "a_get_op", []> {
285279
// DEF: ::llvm::ArrayRef<::mlir::NamedAttribute> attributes
286280
// DEF: odsState.addAttributes(attributes);
287281

288-
// DEF: void AgetOp::build(
289-
// DEF-SAME: const Properties &properties
290-
// DEF-SAME: ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes
291-
// DEF: odsState.useProperties(const_cast<Properties&>(properties));
292-
// DEF: odsState.addAttributes(discardableAttributes);
293-
294282
// Test the above but using properties.
295283
def ApropOp : NS_Op<"a_prop_op", []> {
296284
let arguments = (ins

mlir/test/mlir-tblgen/op-decl-and-defs.td

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> {
119119
// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type r, ::mlir::TypeRange s, ::mlir::Value a, ::mlir::ValueRange b, uint32_t attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount)
120120
// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::ValueRange b, uint32_t attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount);
121121
// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes, unsigned numRegions)
122-
// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes, unsigned numRegions)
123122
// CHECK: static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result);
124123
// CHECK: void print(::mlir::OpAsmPrinter &p);
125124
// CHECK: ::llvm::LogicalResult verifyInvariants();
@@ -232,7 +231,6 @@ def NS_HCollectiveParamsOp : NS_Op<"op_collective_params", []> {
232231
// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type b, ::mlir::Value a);
233232
// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a);
234233
// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {})
235-
// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {})
236234

237235
// Check suppression of "separate arg, separate result" build method for an op
238236
// with single variadic arg and single variadic result (since it will be
@@ -283,8 +281,6 @@ def NS_IOp : NS_Op<"op_with_same_operands_and_result_types_trait", [SameOperands
283281
// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b);
284282
// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
285283
// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
286-
// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});
287-
// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});
288284

289285
// Check default value of `attributes` for the `genInferredTypeCollectiveParamBuilder` builder
290286
def NS_JOp : NS_Op<"op_with_InferTypeOpInterface_interface", [DeclareOpInterfaceMethods<InferTypeOpInterface>]> {
@@ -297,8 +293,6 @@ def NS_JOp : NS_Op<"op_with_InferTypeOpInterface_interface", [DeclareOpInterface
297293
// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b);
298294
// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
299295
// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
300-
// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});
301-
// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});
302296

303297
// Test usage of TraitList getting flattened during emission.
304298
def NS_KOp : NS_Op<"k_op", [IsolatedFromAbove,
@@ -335,8 +329,6 @@ def NS_LOp : NS_Op<"op_with_same_operands_and_result_types_unwrapped_attr", [Sam
335329
// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::Value b, uint32_t attr1);
336330
// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
337331
// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {});
338-
// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});
339-
// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes = {});
340332

341333
def NS_MOp : NS_Op<"op_with_single_result_and_fold_adaptor_fold", []> {
342334
let results = (outs AnyType:$res);

mlir/test/mlir-tblgen/op-result.td

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ def OpD : NS_Op<"type_attr_as_result_type", [FirstAttrDerivedResultType]> {
5757

5858
// CHECK-LABEL: OpD definitions
5959
// CHECK: void OpD::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes)
60-
// CHECK: odsState.addTypes({::llvm::cast<::mlir::TypeAttr>(typeAttr).getValue()});
61-
// CHECK: void OpD::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes)
62-
// CHECK: odsState.addTypes({::llvm::cast<::mlir::TypeAttr>(typeAttr).getValue()});
60+
// CHECK: odsState.addTypes({::llvm::cast<::mlir::TypeAttr>(attr.getValue()).getValue()});
6361

6462
def OpE : NS_Op<"value_attr_as_result_type", [FirstAttrDerivedResultType]> {
6563
let arguments = (ins I32:$x, F32Attr:$attr);
@@ -68,10 +66,7 @@ def OpE : NS_Op<"value_attr_as_result_type", [FirstAttrDerivedResultType]> {
6866

6967
// CHECK-LABEL: OpE definitions
7068
// CHECK: void OpE::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes)
71-
// CHECK: odsState.addTypes({::llvm::cast<::mlir::TypedAttr>(typeAttr).getType()});
72-
// CHECK: void OpE::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes)
73-
// CHECK: ::mlir::Attribute typeAttr = properties.getAttr();
74-
// CHECK: odsState.addTypes({::llvm::cast<::mlir::TypedAttr>(typeAttr).getType()});
69+
// CHECK: odsState.addTypes({::llvm::cast<::mlir::TypedAttr>(attr.getValue()).getType()});
7570

7671
def OpF : NS_Op<"one_variadic_result_op", []> {
7772
let results = (outs Variadic<I32>:$x);
@@ -123,8 +118,6 @@ def OpK : NS_Op<"only_input_is_variadic_with_same_value_type_op", [SameOperandsA
123118

124119
// CHECK-LABEL: OpK::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes)
125120
// CHECK: odsState.addTypes({operands[0].getType()});
126-
// CHECK-LABEL: OpK::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, const Properties &properties, ::llvm::ArrayRef<::mlir::NamedAttribute> discardableAttributes)
127-
// CHECK: odsState.addTypes({operands[0].getType()});
128121

129122
// Test with inferred shapes and interleaved with operands/attributes.
130123
//

0 commit comments

Comments
 (0)