[mlir][py] Enable building ops with raw inputs
authorJacques Pienaar <jpienaar@google.com>
Wed, 21 Dec 2022 18:10:31 +0000 (10:10 -0800)
committerJacques Pienaar <jpienaar@google.com>
Wed, 21 Dec 2022 18:10:31 +0000 (10:10 -0800)
commit3781b7905d8d808e5d4e97d597263f8ac48541b8
tree20442b66107661aa1a1db33ec328dc2c9d5ba4dd
parent2b60ed405b8110b20ab2e383839759ea34003127
[mlir][py] Enable building ops with raw inputs

For cases where we can automatically construct the Attribute allow for more
user-friendly input. This is consistent with C++ builder generation as well
choice of which single builder to generate here (most
specialized/user-friendly).

Registration of attribute builders from more pythonic input is all Python side.
The downside is that
  * extra checking to see if user provided a custom builder in op builders,
  * the ODS attribute name is load bearing
upside is that
  * easily change these/register dialect specific ones in downstream projects,
  * adding support/changing to different convenience builders are all along with
    the rest of the convenience functions in Python (and no additional changes
    to tablegen file or recompilation needed);

Allow for both building with Attributes as well as raw inputs. This change
should therefore be backwards compatible as well as allow for avoiding
recreating Attribute where already available.

Differential Revision: https://reviews.llvm.org/D139568
mlir/docs/Bindings/Python.md
mlir/lib/Bindings/Python/Globals.h
mlir/lib/Bindings/Python/IRCore.cpp
mlir/lib/Bindings/Python/IRModule.cpp
mlir/python/mlir/ir.py
mlir/test/mlir-tblgen/op-python-bindings.td
mlir/test/python/dialects/shape.py
mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp