@@ -9,9 +9,6 @@ include "mlir/IR/OpBase.td"
9
9
def Test_Dialect : Dialect {
10
10
let name = "test";
11
11
let cppNamespace = "foobar";
12
-
13
- // TODO: Flip to _Prefixed
14
- let emitAccessorPrefix = kEmitAccessorPrefix_Raw;
15
12
}
16
13
class NS_Op<string mnemonic, list<Trait> traits> :
17
14
Op<Test_Dialect, mnemonic, traits>;
@@ -49,19 +46,19 @@ def AOp : NS_Op<"a_op", []> {
49
46
// DECL-SAME: {::llvm::StringRef("aAttr"), ::llvm::StringRef("bAttr"), ::llvm::StringRef("cAttr"), ::llvm::StringRef("dAttr")};
50
47
// DECL-NEXT: return ::llvm::makeArrayRef(attrNames);
51
48
52
- // DECL: ::mlir::StringAttr aAttrAttrName ()
49
+ // DECL: ::mlir::StringAttr getAAttrAttrName ()
53
50
// DECL-NEXT: return getAttributeNameForIndex(0);
54
- // DECL: ::mlir::StringAttr aAttrAttrName (::mlir::OperationName name)
51
+ // DECL: ::mlir::StringAttr getAAttrAttrName (::mlir::OperationName name)
55
52
// DECL-NEXT: return getAttributeNameForIndex(name, 0);
56
53
57
- // DECL: ::mlir::StringAttr bAttrAttrName ()
54
+ // DECL: ::mlir::StringAttr getBAttrAttrName ()
58
55
// DECL-NEXT: return getAttributeNameForIndex(1);
59
- // DECL: ::mlir::StringAttr bAttrAttrName (::mlir::OperationName name)
56
+ // DECL: ::mlir::StringAttr getBAttrAttrName (::mlir::OperationName name)
60
57
// DECL-NEXT: return getAttributeNameForIndex(name, 1);
61
58
62
- // DECL: ::mlir::StringAttr cAttrAttrName ()
59
+ // DECL: ::mlir::StringAttr getCAttrAttrName ()
63
60
// DECL-NEXT: return getAttributeNameForIndex(2);
64
- // DECL: ::mlir::StringAttr cAttrAttrName (::mlir::OperationName name)
61
+ // DECL: ::mlir::StringAttr getCAttrAttrName (::mlir::OperationName name)
65
62
// DECL-NEXT: return getAttributeNameForIndex(name, 2);
66
63
67
64
// DEF-LABEL: AOp definitions
@@ -74,7 +71,7 @@ def AOp : NS_Op<"a_op", []> {
74
71
// DEF-NEXT: while (true) {
75
72
// DEF-NEXT: if (namedAttrIt == namedAttrRange.end())
76
73
// DEF-NEXT: return emitError(loc, "'test.a_op' op ""requires attribute 'aAttr'");
77
- // DEF-NEXT: if (namedAttrIt->getName() == AOp::aAttrAttrName (*odsOpName)) {
74
+ // DEF-NEXT: if (namedAttrIt->getName() == AOp::getAAttrAttrName (*odsOpName)) {
78
75
// DEF-NEXT: tblgen_aAttr = namedAttrIt->getValue();
79
76
// DEF-NEXT: break;
80
77
// DEF: ::mlir::Attribute tblgen_bAttr;
@@ -83,9 +80,9 @@ def AOp : NS_Op<"a_op", []> {
83
80
// DEF-NEXT: while (true) {
84
81
// DEF-NEXT: if (namedAttrIt == namedAttrRange.end())
85
82
// DEF-NEXT: break;
86
- // DEF: if (namedAttrIt->getName() == AOp::bAttrAttrName (*odsOpName))
83
+ // DEF: if (namedAttrIt->getName() == AOp::getBAttrAttrName (*odsOpName))
87
84
// DEF-NEXT: tblgen_bAttr = namedAttrIt->getValue();
88
- // DEF: if (namedAttrIt->getName() == AOp::cAttrAttrName (*odsOpName))
85
+ // DEF: if (namedAttrIt->getName() == AOp::getCAttrAttrName (*odsOpName))
89
86
// DEF-NEXT: tblgen_cAttr = namedAttrIt->getValue();
90
87
// DEF: if (tblgen_aAttr && !((some-condition)))
91
88
// DEF-NEXT: return emitError(loc, "'test.a_op' op ""attribute 'aAttr' failed to satisfy constraint: some attribute kind");
@@ -99,68 +96,68 @@ def AOp : NS_Op<"a_op", []> {
99
96
// Test getter methods
100
97
// ---
101
98
102
- // DEF: some-attr-kind AOp::aAttrAttr ()
103
- // DEF-NEXT: ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, aAttrAttrName ()).cast<some-attr-kind>()
104
- // DEF: some-return-type AOp::aAttr () {
105
- // DEF-NEXT: auto attr = aAttrAttr ()
99
+ // DEF: some-attr-kind AOp::getAAttrAttr ()
100
+ // DEF-NEXT: ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getAAttrAttrName ()).cast<some-attr-kind>()
101
+ // DEF: some-return-type AOp::getAAttr () {
102
+ // DEF-NEXT: auto attr = getAAttrAttr ()
106
103
// DEF-NEXT: return attr.some-convert-from-storage();
107
104
108
- // DEF: some-attr-kind AOp::bAttrAttr ()
109
- // DEF-NEXT: ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, bAttrAttrName ()).dyn_cast_or_null<some-attr-kind>()
110
- // DEF: some-return-type AOp::bAttr () {
111
- // DEF-NEXT: auto attr = bAttrAttr ();
105
+ // DEF: some-attr-kind AOp::getBAttrAttr ()
106
+ // DEF-NEXT: ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getBAttrAttrName ()).dyn_cast_or_null<some-attr-kind>()
107
+ // DEF: some-return-type AOp::getBAttr () {
108
+ // DEF-NEXT: auto attr = getBAttrAttr ();
112
109
// DEF-NEXT: return attr.some-convert-from-storage();
113
110
114
- // DEF: some-attr-kind AOp::cAttrAttr ()
115
- // DEF-NEXT: ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, cAttrAttrName ()).dyn_cast_or_null<some-attr-kind>()
116
- // DEF: ::llvm::Optional<some-return-type> AOp::cAttr () {
117
- // DEF-NEXT: auto attr = cAttrAttr ()
111
+ // DEF: some-attr-kind AOp::getCAttrAttr ()
112
+ // DEF-NEXT: ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getCAttrAttrName ()).dyn_cast_or_null<some-attr-kind>()
113
+ // DEF: ::llvm::Optional<some-return-type> AOp::getCAttr () {
114
+ // DEF-NEXT: auto attr = getCAttrAttr ()
118
115
// DEF-NEXT: return attr ? ::llvm::Optional<some-return-type>(attr.some-convert-from-storage()) : (::llvm::None);
119
116
120
- // DEF: some-attr-kind AOp::dAttrAttr ()
121
- // DEF-NEXT: ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, dAttrAttrName ()).dyn_cast_or_null<some-attr-kind>()
122
- // DEF: some-return-type AOp::dAttr () {
123
- // DEF-NEXT: auto attr = dAttrAttr ();
117
+ // DEF: some-attr-kind AOp::getDAttrAttr ()
118
+ // DEF-NEXT: ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getDAttrAttrName ()).dyn_cast_or_null<some-attr-kind>()
119
+ // DEF: some-return-type AOp::getDAttr () {
120
+ // DEF-NEXT: auto attr = getDAttrAttr ();
124
121
// DEF-NEXT: if (!attr)
125
122
// DEF-NEXT: return some-const-builder-call(::mlir::Builder((*this)->getContext()), 4.2).some-convert-from-storage();
126
123
// DEF-NEXT: return attr.some-convert-from-storage();
127
124
128
125
// Test setter methods
129
126
// ---
130
127
131
- // DEF: void AOp::aAttrAttr (some-attr-kind attr) {
132
- // DEF-NEXT: (*this)->setAttr(aAttrAttrName (), attr);
133
- // DEF: void AOp::bAttrAttr (some-attr-kind attr) {
134
- // DEF-NEXT: (*this)->setAttr(bAttrAttrName (), attr);
135
- // DEF: void AOp::cAttrAttr (some-attr-kind attr) {
136
- // DEF-NEXT: (*this)->setAttr(cAttrAttrName (), attr);
128
+ // DEF: void AOp::setAAttrAttr (some-attr-kind attr) {
129
+ // DEF-NEXT: (*this)->setAttr(getAAttrAttrName (), attr);
130
+ // DEF: void AOp::setBAttrAttr (some-attr-kind attr) {
131
+ // DEF-NEXT: (*this)->setAttr(getBAttrAttrName (), attr);
132
+ // DEF: void AOp::setCAttrAttr (some-attr-kind attr) {
133
+ // DEF-NEXT: (*this)->setAttr(getCAttrAttrName (), attr);
137
134
138
135
// Test remove methods
139
136
// ---
140
137
141
138
// DEF: ::mlir::Attribute AOp::removeCAttrAttr() {
142
- // DEF-NEXT: return (*this)->removeAttr(cAttrAttrName ());
139
+ // DEF-NEXT: return (*this)->removeAttr(getCAttrAttrName ());
143
140
144
141
// Test build methods
145
142
// ---
146
143
147
144
// DEF: void AOp::build(
148
- // DEF: odsState.addAttribute(aAttrAttrName (odsState.name), aAttr);
149
- // DEF: odsState.addAttribute(bAttrAttrName (odsState.name), bAttr);
145
+ // DEF: odsState.addAttribute(getAAttrAttrName (odsState.name), aAttr);
146
+ // DEF: odsState.addAttribute(getBAttrAttrName (odsState.name), bAttr);
150
147
// DEF: if (cAttr) {
151
- // DEF-NEXT: odsState.addAttribute(cAttrAttrName (odsState.name), cAttr);
148
+ // DEF-NEXT: odsState.addAttribute(getCAttrAttrName (odsState.name), cAttr);
152
149
153
- // DEF: odsState.addAttribute(aAttrAttrName (odsState.name), some-const-builder-call(odsBuilder, aAttr));
154
- // DEF-NEXT: odsState.addAttribute(bAttrAttrName (odsState.name), some-const-builder-call(odsBuilder, bAttr));
150
+ // DEF: odsState.addAttribute(getAAttrAttrName (odsState.name), some-const-builder-call(odsBuilder, aAttr));
151
+ // DEF-NEXT: odsState.addAttribute(getBAttrAttrName (odsState.name), some-const-builder-call(odsBuilder, bAttr));
155
152
// DEF-NEXT: if (cAttr) {
156
- // DEF-NEXT: odsState.addAttribute(cAttrAttrName (odsState.name), cAttr);
153
+ // DEF-NEXT: odsState.addAttribute(getCAttrAttrName (odsState.name), cAttr);
157
154
// DEF-NEXT: }
158
155
// DEF-NOT: if (dAttr)
159
- // DEF: odsState.addAttribute(dAttrAttrName (odsState.name), some-const-builder-call(odsBuilder, dAttr));
156
+ // DEF: odsState.addAttribute(getDAttrAttrName (odsState.name), some-const-builder-call(odsBuilder, dAttr));
160
157
161
158
// DEF: void AOp::build(
162
159
// DEF: some-return-type aAttr, some-return-type bAttr, /*optional*/some-attr-kind cAttr
163
- // DEF: odsState.addAttribute(aAttrAttrName (odsState.name), some-const-builder-call(odsBuilder, aAttr));
160
+ // DEF: odsState.addAttribute(getAAttrAttrName (odsState.name), some-const-builder-call(odsBuilder, aAttr));
164
161
165
162
// DEF: void AOp::build(
166
163
// DEF: ::llvm::ArrayRef<::mlir::NamedAttribute> attributes
@@ -321,19 +318,19 @@ def BOp : NS_Op<"b_op", []> {
321
318
// Test common attribute kind getters' return types
322
319
// ---
323
320
324
- // DEF: ::mlir::Attribute BOp::any_attr ()
325
- // DEF: bool BOp::bool_attr ()
326
- // DEF: uint32_t BOp::i32_attr ()
327
- // DEF: uint64_t BOp::i64_attr ()
328
- // DEF: ::llvm::APFloat BOp::f32_attr ()
329
- // DEF: ::llvm::APFloat BOp::f64_attr ()
330
- // DEF: ::llvm::StringRef BOp::str_attr ()
331
- // DEF: ::mlir::ElementsAttr BOp::elements_attr ()
332
- // DEF: ::llvm::StringRef BOp::function_attr ()
333
- // DEF: SomeType BOp::some_type_attr ()
334
- // DEF: ::mlir::ArrayAttr BOp::array_attr ()
335
- // DEF: ::mlir::ArrayAttr BOp::some_attr_array ()
336
- // DEF: ::mlir::Type BOp::type_attr ()
321
+ // DEF: ::mlir::Attribute BOp::getAnyAttr ()
322
+ // DEF: bool BOp::getBoolAttr ()
323
+ // DEF: uint32_t BOp::getI32Attr ()
324
+ // DEF: uint64_t BOp::getI64Attr ()
325
+ // DEF: ::llvm::APFloat BOp::getF32Attr ()
326
+ // DEF: ::llvm::APFloat BOp::getF64Attr ()
327
+ // DEF: ::llvm::StringRef BOp::getStrAttr ()
328
+ // DEF: ::mlir::ElementsAttr BOp::getElementsAttr ()
329
+ // DEF: ::llvm::StringRef BOp::getFunctionAttr ()
330
+ // DEF: SomeType BOp::getSomeTypeAttr ()
331
+ // DEF: ::mlir::ArrayAttr BOp::getArrayAttr ()
332
+ // DEF: ::mlir::ArrayAttr BOp::getSomeAttrArray ()
333
+ // DEF: ::mlir::Type BOp::getTypeAttr ()
337
334
338
335
// Test building constant values for array attribute kinds
339
336
// ---
@@ -384,8 +381,8 @@ def DOp : NS_Op<"d_op", []> {
384
381
// 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)
385
382
386
383
// DEF-LABEL: DOp definitions
387
- // DEF: odsState.addAttribute(str_attrAttrName (odsState.name), odsBuilder.getStringAttr(str_attr));
388
- // DEF: odsState.addAttribute(dv_str_attrAttrName (odsState.name), odsBuilder.getStringAttr(dv_str_attr));
384
+ // DEF: odsState.addAttribute(getStrAttrAttrName (odsState.name), odsBuilder.getStringAttr(str_attr));
385
+ // DEF: odsState.addAttribute(getDvStrAttrAttrName (odsState.name), odsBuilder.getStringAttr(dv_str_attr));
389
386
390
387
// Test derived type attr.
391
388
// ---
@@ -435,7 +432,7 @@ def NamespaceOp : NS_Op<"namespace_op", []> {
435
432
);
436
433
}
437
434
// DECL: NamespaceOp
438
- // DECL: foobar::SomeAttrAttr AttrDef ()
435
+ // DECL: foobar::SomeAttrAttr getAttrDef ()
439
436
440
437
441
438
// Test mixing operands and attributes in arbitrary order
@@ -470,11 +467,11 @@ def OpWithDefaultAndSuccessor : NS_Op<"default_with_succ", []> {
470
467
// DECL: static void build({{.*}}, bool dv_bool_attr, ::mlir::BlockRange succ)
471
468
472
469
// DEF-LABEL: MixOperandsAndAttrs definitions
473
- // DEF-DAG: ::mlir::TypedValue<::mlir::FloatType> MixOperandsAndAttrs::operand ()
474
- // DEF-DAG: ::mlir::TypedValue<::mlir::FloatType> MixOperandsAndAttrs::otherArg ()
470
+ // DEF-DAG: ::mlir::TypedValue<::mlir::FloatType> MixOperandsAndAttrs::getOperand ()
471
+ // DEF-DAG: ::mlir::TypedValue<::mlir::FloatType> MixOperandsAndAttrs::getOtherArg ()
475
472
// DEF-DAG: void MixOperandsAndAttrs::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::FloatAttr attr, ::mlir::Value operand, ::mlir::FloatAttr otherAttr, ::mlir::Value otherArg)
476
- // DEF-DAG: ::llvm::APFloat MixOperandsAndAttrs::attr ()
477
- // DEF-DAG: ::llvm::APFloat MixOperandsAndAttrs::otherAttr ()
473
+ // DEF-DAG: ::llvm::APFloat MixOperandsAndAttrs::getAttr ()
474
+ // DEF-DAG: ::llvm::APFloat MixOperandsAndAttrs::getOtherAttr ()
478
475
479
476
// Test unit attributes.
480
477
// ---
@@ -484,11 +481,11 @@ def UnitAttrOp : NS_Op<"unit_attr_op", []> {
484
481
}
485
482
486
483
// DEF-LABEL: UnitAttrOp definitions
487
- // DEF: bool UnitAttrOp::attr () {
484
+ // DEF: bool UnitAttrOp::getAttr () {
488
485
// DEF: return {{.*}} != nullptr
489
486
490
487
// DEF: ::mlir::Attribute UnitAttrOp::removeAttrAttr() {
491
- // DEF-NEXT: (*this)->removeAttr(attrAttrName ());
488
+ // DEF-NEXT: (*this)->removeAttr(getAttrAttrName ());
492
489
493
490
// DEF: build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, /*optional*/::mlir::UnitAttr attr)
494
491
0 commit comments