[mlir][python] Provide more convenient wrappers for std.ConstantOp
authorAlex Zinenko <zinenko@google.com>
Mon, 4 Oct 2021 09:38:53 +0000 (11:38 +0200)
committerAlex Zinenko <zinenko@google.com>
Mon, 4 Oct 2021 09:45:27 +0000 (11:45 +0200)
commit3a3a09f65412dc38aba6b7370b93f9d2c7fd1c30
treefeb40709f9c5470451cba97b549142890b97cb77
parented9e52f3af4e1d95033268b60b91cbdebe38182c
[mlir][python] Provide more convenient wrappers for std.ConstantOp

Constructing a ConstantOp using the default-generated API is verbose and
requires to specify the constant type twice: for the result type of the
operation and for the type of the attribute. It also requires to explicitly
construct the attribute. Provide custom constructors that take the type once
and accept a raw value instead of the attribute. This requires dynamic dispatch
based on type in the constructor. Also provide the corresponding accessors to
raw values.

In addition, provide a "refinement" class ConstantIndexOp similar to what
exists in C++. Unlike other "op view" Python classes, operations cannot be
automatically downcasted to this class since it does not correspond to a
specific operation name. It only exists to simplify construction of the
operation.

Depends On D110946

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D110947
mlir/python/CMakeLists.txt
mlir/python/mlir/dialects/_std_ops_ext.py [new file with mode: 0644]
mlir/test/python/dialects/std.py [new file with mode: 0644]