diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -3135,6 +3135,7 @@ class APFloatParameter : AttrOrTypeParameter<"::llvm::APFloat", desc> { let comparator = "$_lhs.bitwiseIsEqual($_rhs)"; + let cppAccessorType = "const ::llvm::APFloat &"; } // For standard ArrayRefs, which require allocation. diff --git a/mlir/lib/IR/BuiltinAttributes.cpp b/mlir/lib/IR/BuiltinAttributes.cpp --- a/mlir/lib/IR/BuiltinAttributes.cpp +++ b/mlir/lib/IR/BuiltinAttributes.cpp @@ -283,7 +283,7 @@ } LogicalResult FloatAttr::verify(function_ref emitError, - Type type, APFloat value) { + Type type, const APFloat &value) { // Verify that the type is correct. if (!type.isa()) return emitError() << "expected floating point type"; diff --git a/mlir/test/lib/Dialect/Test/TestAttributes.cpp b/mlir/test/lib/Dialect/Test/TestAttributes.cpp --- a/mlir/test/lib/Dialect/Test/TestAttributes.cpp +++ b/mlir/test/lib/Dialect/Test/TestAttributes.cpp @@ -129,7 +129,7 @@ LogicalResult TestAttrWithFormatAttr::verify(function_ref emitError, - int64_t one, std::string two, IntegerAttr three, + int64_t one, StringRef two, IntegerAttr three, ArrayRef four) { if (four.size() != static_cast(one)) return emitError() << "expected 'one' to equal 'four.size()'"; diff --git a/mlir/test/mlir-tblgen/attrdefs.td b/mlir/test/mlir-tblgen/attrdefs.td --- a/mlir/test/mlir-tblgen/attrdefs.td +++ b/mlir/test/mlir-tblgen/attrdefs.td @@ -61,8 +61,8 @@ let genVerifyDecl = 1; // DECL-LABEL: class CompoundAAttr : public ::mlir::Attribute -// DECL: static CompoundAAttr getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::MLIRContext *context, int widthOfSomething, ::test::SimpleTypeA exampleTdType, ::llvm::APFloat apFloat, ::llvm::ArrayRef dims, ::mlir::Type inner); -// DECL: static ::mlir::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, int widthOfSomething, ::test::SimpleTypeA exampleTdType, ::llvm::APFloat apFloat, ::llvm::ArrayRef dims, ::mlir::Type inner); +// DECL: static CompoundAAttr getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::MLIRContext *context, int widthOfSomething, ::test::SimpleTypeA exampleTdType, const ::llvm::APFloat &apFloat, ::llvm::ArrayRef dims, ::mlir::Type inner); +// DECL: static ::mlir::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, int widthOfSomething, ::test::SimpleTypeA exampleTdType, const ::llvm::APFloat &apFloat, ::llvm::ArrayRef dims, ::mlir::Type inner); // DECL: static constexpr ::llvm::StringLiteral getMnemonic() { // DECL: return {"cmpnd_a"}; // DECL: } @@ -71,7 +71,7 @@ // DECL: void print(::mlir::AsmPrinter &printer) const; // DECL: int getWidthOfSomething() const; // DECL: ::test::SimpleTypeA getExampleTdType() const; -// DECL: ::llvm::APFloat getApFloat() const; +// DECL: const ::llvm::APFloat &getApFloat() const; // Check that AttributeSelfTypeParameter is handled properly. // DEF-LABEL: struct CompoundAAttrStorage @@ -139,5 +139,5 @@ // DECL-LABEL: class ParamWithAccessorTypeAttr // DECL: StringRef getParam() // DEF: ParamWithAccessorTypeAttrStorage -// DEF: ParamWithAccessorTypeAttrStorage(std::string param) +// DEF: ParamWithAccessorTypeAttrStorage(StringRef param) // DEF: StringRef ParamWithAccessorTypeAttr::getParam() diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp --- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp +++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp @@ -315,7 +315,7 @@ SmallVector builderParams; builderParams.append(prefix.begin(), prefix.end()); for (auto ¶m : params) - builderParams.emplace_back(param.getCppType(), param.getName()); + builderParams.emplace_back(param.getCppAccessorType(), param.getName()); return builderParams; }