@@ -9,7 +9,6 @@ include "mlir/IR/OpBase.td"
9
9
def Test_Dialect : Dialect {
10
10
let name = "test";
11
11
let cppNamespace = "foobar";
12
- let usePropertiesForAttributes = 0;
13
12
}
14
13
class NS_Op<string mnemonic, list<Trait> traits> :
15
14
Op<Test_Dialect, mnemonic, traits>;
@@ -69,23 +68,12 @@ def AOp : NS_Op<"a_op", []> {
69
68
// ---
70
69
71
70
// DEF: ::llvm::LogicalResult AOpAdaptor::verify
72
- // DEF: ::mlir::Attribute tblgen_aAttr;
73
- // DEF: while (true) {
74
- // DEF-NEXT: if (namedAttrIt == namedAttrRange.end())
75
- // DEF-NEXT: return emitError(loc, "'test.a_op' op ""requires attribute 'aAttr'");
76
- // DEF-NEXT: if (namedAttrIt->getName() == AOp::getAAttrAttrName(*odsOpName)) {
77
- // DEF-NEXT: tblgen_aAttr = namedAttrIt->getValue();
78
- // DEF-NEXT: break;
79
- // DEF: ::mlir::Attribute tblgen_bAttr;
80
- // DEF-NEXT: ::mlir::Attribute tblgen_cAttr;
81
- // DEF-NEXT: ::mlir::Attribute tblgen_dAttr;
82
- // DEF-NEXT: while (true) {
83
- // DEF-NEXT: if (namedAttrIt == namedAttrRange.end())
84
- // DEF-NEXT: break;
85
- // DEF: if (namedAttrIt->getName() == AOp::getBAttrAttrName(*odsOpName))
86
- // DEF-NEXT: tblgen_bAttr = namedAttrIt->getValue();
87
- // DEF: if (namedAttrIt->getName() == AOp::getCAttrAttrName(*odsOpName))
88
- // DEF-NEXT: tblgen_cAttr = namedAttrIt->getValue();
71
+ // DEF-NEXT: auto tblgen_aAttr = getProperties().aAttr; (void)tblgen_aAttr;
72
+ // DEF-NEXT: if (!tblgen_aAttr) return emitError(loc, "'test.a_op' op ""requires attribute 'aAttr'");
73
+ // DEF-NEXT: auto tblgen_bAttr = getProperties().bAttr; (void)tblgen_bAttr;
74
+ // DEF-NEXT: auto tblgen_cAttr = getProperties().cAttr; (void)tblgen_cAttr;
75
+ // DEF-NEXT: auto tblgen_dAttr = getProperties().dAttr; (void)tblgen_dAttr;
76
+
89
77
// DEF: if (tblgen_aAttr && !((some-condition)))
90
78
// DEF-NEXT: return emitError(loc, "'test.a_op' op ""attribute 'aAttr' failed to satisfy constraint: some attribute kind");
91
79
// DEF: if (tblgen_bAttr && !((some-condition)))
@@ -99,25 +87,25 @@ def AOp : NS_Op<"a_op", []> {
99
87
// ---
100
88
101
89
// DECL: some-attr-kind getAAttrAttr()
102
- // DECL-NEXT: ::llvm::cast<some-attr-kind>(::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getAAttrAttrName()) )
90
+ // DECL-NEXT: ::llvm::cast<some-attr-kind>(getProperties().aAttr )
103
91
// DEF: some-return-type AOp::getAAttr() {
104
92
// DEF-NEXT: auto attr = getAAttrAttr()
105
93
// DEF-NEXT: return attr.some-convert-from-storage();
106
94
107
95
// DECL: some-attr-kind getBAttrAttr()
108
- // DECL-NEXT: ::llvm::dyn_cast_or_null<some-attr-kind>(::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getBAttrAttrName()) )
96
+ // DECL-NEXT: ::llvm::dyn_cast_or_null<some-attr-kind>(getProperties().bAttr )
109
97
// DEF: some-return-type AOp::getBAttr() {
110
98
// DEF-NEXT: auto attr = getBAttrAttr();
111
99
// DEF-NEXT: return attr.some-convert-from-storage();
112
100
113
101
// DECL: some-attr-kind getCAttrAttr()
114
- // DECL-NEXT: ::llvm::dyn_cast_or_null<some-attr-kind>(::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getCAttrAttrName()) )
102
+ // DECL-NEXT: ::llvm::dyn_cast_or_null<some-attr-kind>(getProperties().cAttr )
115
103
// DEF: ::std::optional<some-return-type> AOp::getCAttr() {
116
104
// DEF-NEXT: auto attr = getCAttrAttr()
117
105
// DEF-NEXT: return attr ? ::std::optional<some-return-type>(attr.some-convert-from-storage()) : (::std::nullopt);
118
106
119
107
// DECL: some-attr-kind getDAttrAttr()
120
- // DECL-NEXT: ::llvm::dyn_cast_or_null<some-attr-kind>(::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getDAttrAttrName()) )
108
+ // DECL-NEXT: ::llvm::dyn_cast_or_null<some-attr-kind>(getProperties().dAttr )
121
109
// DEF: some-return-type AOp::getDAttr() {
122
110
// DEF-NEXT: auto attr = getDAttrAttr();
123
111
// DEF-NEXT: if (!attr)
@@ -128,59 +116,62 @@ def AOp : NS_Op<"a_op", []> {
128
116
// ---
129
117
130
118
// DECL: void setAAttrAttr(some-attr-kind attr) {
131
- // DECL-NEXT: (*this)->setAttr(getAAttrAttrName(), attr) ;
119
+ // DECL-NEXT: getProperties().aAttr = attr;
132
120
// DEF: void AOp::setAAttr(some-return-type attrValue) {
133
- // DEF-NEXT: (*this)->setAttr(getAAttrAttrName(), some-const-builder-call(::mlir::Builder((*this)->getContext()), attrValue) );
121
+ // DEF-NEXT: getProperties().aAttr = some-const-builder-call(::mlir::Builder((*this)->getContext()), attrValue);
134
122
// DECL: void setBAttrAttr(some-attr-kind attr) {
135
- // DECL-NEXT: (*this)->setAttr(getBAttrAttrName(), attr) ;
123
+ // DECL-NEXT: getProperties().bAttr = attr;
136
124
// DEF: void AOp::setBAttr(some-return-type attrValue) {
137
- // DEF-NEXT: (*this)->setAttr(getBAttrAttrName(), some-const-builder-call(::mlir::Builder((*this)->getContext()), attrValue) );
125
+ // DEF-NEXT: getProperties().bAttr = some-const-builder-call(::mlir::Builder((*this)->getContext()), attrValue);
138
126
// DECL: void setCAttrAttr(some-attr-kind attr) {
139
- // DECL-NEXT: (*this)->setAttr(getCAttrAttrName(), attr) ;
127
+ // DECL-NEXT: getProperties().cAttr = attr;
140
128
// DEF: void AOp::setCAttr(::std::optional<some-return-type> attrValue) {
129
+ // DEF-NEXT: auto &odsProp = getProperties().cAttr;
141
130
// DEF-NEXT: if (attrValue)
142
- // DEF-NEXT: return (*this)->setAttr(getCAttrAttrName(), some-const-builder-call(::mlir::Builder((*this)->getContext()), *attrValue));
143
- // DEF-NEXT: (*this)->removeAttr(getCAttrAttrName());
131
+ // DEF-NEXT: odsProp = some-const-builder-call(::mlir::Builder((*this)->getContext()), *attrValue);
132
+ // DEF-NEXT: else
133
+ // DEF-NEXT: odsProp = nullptr;
144
134
145
135
// Test remove methods
146
136
// ---
147
137
148
138
// DECL: ::mlir::Attribute removeCAttrAttr() {
149
- // DECL-NEXT: return (*this)->removeAttr(getCAttrAttrName());
139
+ // DECL-NEXT: auto attr = getProperties().cAttr;
140
+ // DECL-NEXT: getProperties().cAttr = {};
141
+ // DECL-NEXT: return attr;
150
142
151
143
// Test build methods
152
144
// ---
153
145
154
146
// DEF: void AOp::build(
155
- // DEF: odsState.addAttribute(getAAttrAttrName(odsState.name), aAttr) ;
156
- // DEF: odsState.addAttribute(getBAttrAttrName(odsState.name), bAttr) ;
147
+ // DEF: odsState.getOrAddProperties<Properties>().aAttr = aAttr;
148
+ // DEF: odsState.getOrAddProperties<Properties>().bAttr = bAttr;
157
149
// DEF: if (cAttr) {
158
- // DEF-NEXT: odsState.addAttribute(getCAttrAttrName(odsState.name), cAttr) ;
150
+ // DEF-NEXT: odsState.getOrAddProperties<Properties>().cAttr = cAttr;
159
151
160
- // DEF: odsState.addAttribute(getAAttrAttrName(odsState.name), some-const-builder-call(odsBuilder, aAttr) );
161
- // DEF-NEXT: odsState.addAttribute(getBAttrAttrName(odsState.name), some-const-builder-call(odsBuilder, bAttr) );
152
+ // DEF: odsState.getOrAddProperties<Properties>().aAttr = some-const-builder-call(odsBuilder, aAttr);
153
+ // DEF-NEXT: odsState.getOrAddProperties<Properties>().bAttr = some-const-builder-call(odsBuilder, bAttr);
162
154
// DEF-NEXT: if (cAttr) {
163
- // DEF-NEXT: odsState.addAttribute(getCAttrAttrName(odsState.name), cAttr) ;
155
+ // DEF-NEXT: odsState.getOrAddProperties<Properties>().cAttr = cAttr;
164
156
// DEF-NEXT: }
165
157
// DEF-NOT: if (dAttr)
166
- // DEF: odsState.addAttribute(getDAttrAttrName(odsState.name), some-const-builder-call(odsBuilder, dAttr) );
158
+ // DEF: odsState.getOrAddProperties<Properties>().dAttr = some-const-builder-call(odsBuilder, dAttr);
167
159
168
160
// DEF: void AOp::build(
169
161
// DEF: some-return-type aAttr, some-return-type bAttr, /*optional*/some-attr-kind cAttr
170
- // DEF: odsState.addAttribute(getAAttrAttrName(odsState.name), some-const-builder-call(odsBuilder, aAttr) );
162
+ // DEF: odsState.getOrAddProperties<Properties>().aAttr = some-const-builder-call(odsBuilder, aAttr);
171
163
172
164
// DEF: void AOp::build(
173
165
// DEF: ::llvm::ArrayRef<::mlir::NamedAttribute> attributes
174
166
// DEF: odsState.addAttributes(attributes);
175
167
176
- // DEF: void AOp::populateDefaultAttrs
168
+ // DEF: void AOp::populateDefaultProperties
177
169
178
170
// Test the above but with prefix.
179
171
180
172
def Test2_Dialect : Dialect {
181
173
let name = "test2";
182
174
let cppNamespace = "foobar2";
183
- let usePropertiesForAttributes = 0;
184
175
}
185
176
def AgetOp : Op<Test2_Dialect, "a_get_op", []> {
186
177
let arguments = (ins
@@ -221,13 +212,10 @@ def AgetOp : Op<Test2_Dialect, "a_get_op", []> {
221
212
// ---
222
213
223
214
// DEF: ::llvm::LogicalResult AgetOpAdaptor::verify
224
- // DEF: ::mlir::Attribute tblgen_aAttr;
225
- // DEF: while (true)
226
- // DEF: ::mlir::Attribute tblgen_bAttr;
227
- // DEF-NEXT: ::mlir::Attribute tblgen_cAttr;
228
- // DEF: while (true)
229
- // DEF: if (tblgen_aAttr && !((some-condition)))
230
- // DEF-NEXT: return emitError(loc, "'test2.a_get_op' op ""attribute 'aAttr' failed to satisfy constraint: some attribute kind");
215
+ // DEF: auto tblgen_aAttr = getProperties().aAttr; (void)tblgen_aAttr;
216
+ // DEF: if (!tblgen_aAttr) return emitError(loc, "'test2.a_get_op' op ""requires attribute 'aAttr'");
217
+ // DEF: auto tblgen_bAttr = getProperties().bAttr; (void)tblgen_bAttr;
218
+ // DEF: auto tblgen_cAttr = getProperties().cAttr; (void)tblgen_cAttr;
231
219
// DEF: if (tblgen_bAttr && !((some-condition)))
232
220
// DEF-NEXT: return emitError(loc, "'test2.a_get_op' op ""attribute 'bAttr' failed to satisfy constraint: some attribute kind");
233
221
// DEF: if (tblgen_cAttr && !((some-condition)))
@@ -237,21 +225,21 @@ def AgetOp : Op<Test2_Dialect, "a_get_op", []> {
237
225
// ---
238
226
239
227
// DECL: some-attr-kind getAAttrAttr()
240
- // DECL-NEXT: ::llvm::cast<some-attr-kind>(::mlir::impl::getAttrFromSortedRange({{.*}}) )
228
+ // DECL-NEXT: ::llvm::cast<some-attr-kind>(getProperties().aAttr )
241
229
// DEF: some-return-type AgetOp::getAAttr() {
242
230
// DEF-NEXT: auto attr = getAAttrAttr()
243
231
// DEF-NEXT: return attr.some-convert-from-storage();
244
232
245
233
// DECL: some-attr-kind getBAttrAttr()
246
- // DECL-NEXT: return ::llvm::dyn_cast_or_null<some-attr-kind>(::mlir::impl::getAttrFromSortedRange({{.*}}) )
234
+ // DECL-NEXT: return ::llvm::dyn_cast_or_null<some-attr-kind>(getProperties().bAttr )
247
235
// DEF: some-return-type AgetOp::getBAttr() {
248
236
// DEF-NEXT: auto attr = getBAttrAttr();
249
237
// DEF-NEXT: if (!attr)
250
238
// DEF-NEXT: return some-const-builder-call(::mlir::Builder((*this)->getContext()), 4.2).some-convert-from-storage();
251
239
// DEF-NEXT: return attr.some-convert-from-storage();
252
240
253
241
// DECL: some-attr-kind getCAttrAttr()
254
- // DECL-NEXT: return ::llvm::dyn_cast_or_null<some-attr-kind>(::mlir::impl::getAttrFromSortedRange({{.*}}) )
242
+ // DECL-NEXT: return ::llvm::dyn_cast_or_null<some-attr-kind>(getProperties().cAttr )
255
243
// DEF: ::std::optional<some-return-type> AgetOp::getCAttr() {
256
244
// DEF-NEXT: auto attr = getCAttrAttr()
257
245
// DEF-NEXT: return attr ? ::std::optional<some-return-type>(attr.some-convert-from-storage()) : (::std::nullopt);
@@ -260,30 +248,32 @@ def AgetOp : Op<Test2_Dialect, "a_get_op", []> {
260
248
// ---
261
249
262
250
// DECL: void setAAttrAttr(some-attr-kind attr) {
263
- // DECL-NEXT: (*this)->setAttr(getAAttrAttrName(), attr) ;
251
+ // DECL-NEXT: getProperties().aAttr = attr;
264
252
// DECL: void setBAttrAttr(some-attr-kind attr) {
265
- // DECL-NEXT: (*this)->setAttr(getBAttrAttrName(), attr) ;
253
+ // DECL-NEXT: getProperties().bAttr = attr;
266
254
// DECL: void setCAttrAttr(some-attr-kind attr) {
267
- // DECL-NEXT: (*this)->setAttr(getCAttrAttrName(), attr) ;
255
+ // DECL-NEXT: getProperties().cAttr = attr;
268
256
269
257
// Test remove methods
270
258
// ---
271
259
272
260
// DECL: ::mlir::Attribute removeCAttrAttr() {
273
- // DECL-NEXT: return (*this)->removeAttr(getCAttrAttrName());
261
+ // DECL-NEXT: auto attr = getProperties().cAttr;
262
+ // DECL-NEXT: getProperties().cAttr = {};
263
+ // DECL-NEXT: return attr;
274
264
275
265
// Test build methods
276
266
// ---
277
267
278
268
// DEF: void AgetOp::build(
279
- // DEF: odsState.addAttribute(getAAttrAttrName(odsState.name), aAttr) ;
280
- // DEF: odsState.addAttribute(getBAttrAttrName(odsState.name), bAttr) ;
269
+ // DEF: odsState.getOrAddProperties<Properties>().aAttr = aAttr;
270
+ // DEF: odsState.getOrAddProperties<Properties>().bAttr = bAttr;
281
271
// DEF: if (cAttr) {
282
- // DEF-NEXT: odsState.addAttribute(getCAttrAttrName(odsState.name), cAttr) ;
272
+ // DEF-NEXT: odsState.getOrAddProperties<Properties>().cAttr = cAttr;
283
273
284
274
// DEF: void AgetOp::build(
285
275
// DEF: some-return-type aAttr, /*optional*/some-return-type bAttr, /*optional*/some-attr-kind cAttr
286
- // DEF: odsState.addAttribute(getAAttrAttrName(odsState.name), some-const-builder-call(odsBuilder, aAttr) );
276
+ // DEF: odsState.getOrAddProperties<Properties>().aAttr = some-const-builder-call(odsBuilder, aAttr);
287
277
288
278
// DEF: void AgetOp::build(
289
279
// DEF: ::llvm::ArrayRef<::mlir::NamedAttribute> attributes
@@ -405,8 +395,8 @@ def DOp : NS_Op<"d_op", []> {
405
395
// DECL: static void build({{.*}}, uint32_t i32_attr, ::llvm::APFloat f64_attr, ::llvm::StringRef str_attr, bool bool_attr, ::SomeI32Enum enum_attr, uint32_t dv_i32_attr, ::llvm::APFloat dv_f64_attr, ::llvm::StringRef dv_str_attr = "abc", bool dv_bool_attr = true, ::SomeI32Enum dv_enum_attr = ::SomeI32Enum::case5)
406
396
407
397
// DEF-LABEL: DOp definitions
408
- // DEF: odsState.addAttribute(getStrAttrAttrName(odsState.name), odsBuilder.getStringAttr(str_attr) );
409
- // DEF: odsState.addAttribute(getDvStrAttrAttrName(odsState.name), odsBuilder.getStringAttr(dv_str_attr) );
398
+ // DEF: odsState.getOrAddProperties<Properties>().str_attr = odsBuilder.getStringAttr(str_attr);
399
+ // DEF: odsState.getOrAddProperties<Properties>().dv_str_attr = odsBuilder.getStringAttr(dv_str_attr);
410
400
411
401
412
402
// Test default dictionary attribute.
@@ -420,10 +410,10 @@ def DefaultDictAttrOp : NS_Op<"default_dict_attr_op", []> {
420
410
}
421
411
422
412
// DEF-LABEL: DefaultDictAttrOp definitions
423
- // DEF: if (!attributes.get(attrNames[0]) )
424
- // DEF: attributes.append(attrNames[0], odsBuilder.getDictionaryAttr({}) );
425
- // DEF: if (!attributes.get(attrNames[1]) )
426
- // DEF: attributes.append(attrNames[1], odsBuilder.getDictionaryAttr(getDefaultDictAttrs(odsBuilder) ));
413
+ // DEF: if (!properties.empty )
414
+ // DEF: properties.empty = odsBuilder.getDictionaryAttr({});
415
+ // DEF: if (!properties.non_empty )
416
+ // DEF: properties.non_empty = odsBuilder.getDictionaryAttr(getDefaultDictAttrs(odsBuilder));
427
417
428
418
// DECL-LABEL: DefaultDictAttrOp declarations
429
419
// DECL: build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::DictionaryAttr empty = nullptr, ::mlir::DictionaryAttr non_empty = nullptr)
@@ -538,7 +528,9 @@ def UnitAttrOp : NS_Op<"unit_attr_op", []> {
538
528
539
529
// DECL-LABEL: UnitAttrOp declarations
540
530
// DECL: ::mlir::Attribute removeAttrAttr() {
541
- // DECL-NEXT: (*this)->removeAttr(getAttrAttrName());
531
+ // DECL-NEXT: auto attr = getProperties().attr;
532
+ // DECL-NEXT: getProperties().attr = {};
533
+ // DECL-NEXT: return attr;
542
534
// DECL: build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, /*optional*/bool attr = false)
543
535
544
536
0 commit comments