diff --git a/mlir/include/mlir/TableGen/Operator.h b/mlir/include/mlir/TableGen/Operator.h --- a/mlir/include/mlir/TableGen/Operator.h +++ b/mlir/include/mlir/TableGen/Operator.h @@ -308,6 +308,9 @@ /// Returns the setter name for the accessor of `name`. std::string getSetterName(StringRef name) const; + /// Returns the remove name for the accessor of `name`. + std::string getRemoverName(StringRef name) const; + private: /// Populates the vectors containing operands, attributes, results and traits. void populateOpStructure(); diff --git a/mlir/lib/TableGen/Operator.cpp b/mlir/lib/TableGen/Operator.cpp --- a/mlir/lib/TableGen/Operator.cpp +++ b/mlir/lib/TableGen/Operator.cpp @@ -737,3 +737,7 @@ std::string Operator::getSetterName(StringRef name) const { return "set" + convertToCamelFromSnakeCase(name, /*capitalizeFirst=*/true); } + +std::string Operator::getRemoverName(StringRef name) const { + return "remove" + convertToCamelFromSnakeCase(name, /*capitalizeFirst=*/true); +} diff --git a/mlir/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td --- a/mlir/test/mlir-tblgen/op-decl-and-defs.td +++ b/mlir/test/mlir-tblgen/op-decl-and-defs.td @@ -24,7 +24,7 @@ Variadic:$b, I32Attr:$attr1, - OptionalAttr:$attr2 + OptionalAttr:$some_attr2 ); let results = (outs @@ -60,8 +60,8 @@ // CHECK: ::mlir::ValueRange getB(); // CHECK: ::mlir::IntegerAttr getAttr1Attr(); // CHECK: uint32_t getAttr1(); -// CHECK: ::mlir::FloatAttr getAttr2Attr(); -// CHECK: ::llvm::Optional< ::llvm::APFloat > getAttr2(); +// CHECK: ::mlir::FloatAttr getSomeAttr2Attr(); +// CHECK: ::llvm::Optional< ::llvm::APFloat > getSomeAttr2(); // CHECK: ::mlir::Region &getSomeRegion(); // CHECK: ::mlir::RegionRange getSomeRegions(); // CHECK: private: @@ -87,15 +87,15 @@ // CHECK: ::mlir::MutableArrayRef<::mlir::Region> getSomeRegions(); // CHECK: ::mlir::IntegerAttr getAttr1Attr() // CHECK: uint32_t getAttr1(); -// CHECK: ::mlir::FloatAttr getAttr2Attr() -// CHECK: ::llvm::Optional< ::llvm::APFloat > getAttr2(); -// CHECK: ::mlir::Attribute removeAttr2Attr(); +// CHECK: ::mlir::FloatAttr getSomeAttr2Attr() +// CHECK: ::llvm::Optional< ::llvm::APFloat > getSomeAttr2(); +// CHECK: ::mlir::Attribute removeSomeAttr2Attr(); // CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, Value val); // CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, int integer = 0); -// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type r, ::mlir::TypeRange s, ::mlir::Value a, ::mlir::ValueRange b, ::mlir::IntegerAttr attr1, /*optional*/::mlir::FloatAttr attr2, unsigned someRegionsCount) -// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::ValueRange b, ::mlir::IntegerAttr attr1, /*optional*/::mlir::FloatAttr attr2, unsigned someRegionsCount); -// 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 attr2, unsigned someRegionsCount) -// 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 attr2, unsigned someRegionsCount); +// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type r, ::mlir::TypeRange s, ::mlir::Value a, ::mlir::ValueRange b, ::mlir::IntegerAttr attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount) +// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value a, ::mlir::ValueRange b, ::mlir::IntegerAttr attr1, /*optional*/::mlir::FloatAttr some_attr2, unsigned someRegionsCount); +// 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) +// 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); // CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes, unsigned numRegions) // CHECK: static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); // CHECK: void print(::mlir::OpAsmPrinter &p); diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -1174,9 +1174,8 @@ // use the string interface. Enables better compile time verification. auto emitRemoveAttr = [&](StringRef name) { auto upperInitial = name.take_front().upper(); - auto suffix = name.drop_front(); auto *method = opClass.addMethod("::mlir::Attribute", - "remove" + upperInitial + suffix + "Attr"); + op.getRemoverName(name) + "Attr"); if (!method) return; method->body() << formatv(" return (*this)->removeAttr({0}AttrName());",