[mlir][ods] Simplify signature of `custom` printers and parsers of Attributes and...
authorMarkus Böck <markus.boeck02@gmail.com>
Sun, 22 Jan 2023 15:11:27 +0000 (16:11 +0100)
committerMarkus Böck <markus.boeck02@gmail.com>
Sun, 22 Jan 2023 15:18:44 +0000 (16:18 +0100)
commit715b0258522ff3c99aa57801d1f4d2b1b7a90ee1
tree49be74322ffa64aba932dfeab8518816d2981b66
parent6aa43fed4c17fe39ce17cc105aec9f838d1adbbd
[mlir][ods] Simplify signature of `custom` printers and parsers of Attributes and Types in presence of default constructible parameters

The vast majority of parameters of C++ types used as parameters for Attributes and Types are likely to be default constructible. Nevertheless, TableGen conservatively generates code for the custom directive, expecting signatures using FailureOr<T> for all parameter types T to accomodate them possibly not being default constructible. This however reduces the ergonomics of the likely case of default constructible parameters.

This patch fixes that issue, while barely changing the generated TableGen code, by using a helper function that is used to pass any parameters into custom parser methods. If the type is default constructible, as deemed by the C++ compiler, a default constructible instance is created and passed into the parser method by reference. In all other cases it is a Noop and a FailureOr is passed as before.

Documentation was also updated to document the new behaviour.

Fixes https://github.com/llvm/llvm-project/issues/60178

Differential Revision: https://reviews.llvm.org/D142301
mlir/docs/DefiningDialects/AttributesAndTypes.md
mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h
mlir/include/mlir/IR/AttributeSupport.h
mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
mlir/test/lib/Dialect/Test/TestAttributes.cpp
mlir/test/lib/Dialect/Test/TestTypes.cpp
mlir/test/mlir-tblgen/attr-or-type-format.td
mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp