[mlir][ods] Enable emitting getter/setter prefix
authorJacques Pienaar <jpienaar@google.com>
Thu, 14 Oct 2021 22:58:44 +0000 (15:58 -0700)
committerJacques Pienaar <jpienaar@google.com>
Thu, 14 Oct 2021 22:58:44 +0000 (15:58 -0700)
commit65c9907c809a275e57bd925d1eda5a743a462d20
tree287250e56a7c409f420dfa4d04270ad1002f6ebb
parent6965a776ee192cb4c1a2618c270254fbf70879df
[mlir][ods] Enable emitting getter/setter prefix

Allow emitting get & set prefix for accessors generated for ops. If
enabled, then the argument/return/region name gets converted from
snake_case to UpperCamel and prefix added. The attribute also allows
generating both the current "raw" method along with the prefix'd one to
make it easier to stage changes.

The option is added on the dialect and currently defaults to existing
raw behavior. The expectation is that the staging where both are
generated would be short lived and so optimized to keeping the changes
local/less invasive (it just generates two functions for each accessor
with the same body - most of these internally again call a helper
function). But generation can be optimized if needed.

I'm unsure about OpAdaptor classes as there it is all get methods (it is
a named view into raw data structures), so prefix doesn't add much.

This starts with emitting raw-only form (as current behavior) as
default, then one can opt-in to raw & prefixed, then just prefixed. The
default in OpBase will switch to prefixed-only to be consistent with
MLIR style guide. And the option potentially removed later (considered
enabling specifying prefix but current discussion more pro keeping it
limited and stuck with that).

Also add more explicit checking for pruned functions to avoid emitting
where no function was added (and so avoiding dereferencing nullptr)
during op def/decl generation.

See https://bugs.llvm.org/show_bug.cgi?id=51916 for further discussion.

Differential Revision: https://reviews.llvm.org/D111033
mlir/include/mlir/IR/OpBase.td
mlir/include/mlir/TableGen/Dialect.h
mlir/lib/TableGen/Dialect.cpp
mlir/test/mlir-tblgen/op-attribute.td
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp