This is an archive of the discontinued LLVM Phabricator instance.

[mlir][ods] Simplify signature of `custom` printers and parsers of Attributes and Types in presence of default constructible parameters
ClosedPublic

Authored by zero9178 on Jan 22 2023, 2:45 AM.

Details

Summary

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

Diff Detail

Event Timeline

zero9178 created this revision.Jan 22 2023, 2:45 AM
zero9178 requested review of this revision.Jan 22 2023, 2:45 AM
zero9178 updated this revision to Diff 491144.Jan 22 2023, 3:23 AM

clang-format

This revision is now accepted and ready to land.Jan 22 2023, 6:57 AM