[all-commits] [llvm/llvm-project] b164f2: [mlir][python] support taking ops instead of value...
ftynse via All-commits
all-commits at lists.llvm.org
Fri Oct 8 00:50:01 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: b164f23c29fdf8b1e82fc4cfeab79c9fb6df918d
https://github.com/llvm/llvm-project/commit/b164f23c29fdf8b1e82fc4cfeab79c9fb6df918d
Author: Alex Zinenko <zinenko at google.com>
Date: 2021-10-08 (Fri, 08 Oct 2021)
Changed paths:
M mlir/python/mlir/dialects/_linalg_ops_ext.py
M mlir/python/mlir/dialects/_ods_common.py
M mlir/python/mlir/dialects/_scf_ops_ext.py
M mlir/python/mlir/dialects/linalg/opdsl/lang/dsl.py
M mlir/python/mlir/dialects/linalg/opdsl/lang/emitter.py
M mlir/test/mlir-tblgen/op-python-bindings.td
M mlir/test/python/dialects/linalg/ops.py
M mlir/test/python/dialects/scf.py
M mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
Log Message:
-----------
[mlir][python] support taking ops instead of values in op constructors
Introduce support for accepting ops instead of values when constructing ops. A
single-result op can be used instead of a value, including in lists of values,
and any op can be used instead of a list of values. This is similar to, but
more powerful, than the C++ API that allows for implicitly casting an OpType to
Value if it is statically known to have a single result - the cast in Python is
based on the op dynamically having a single result, and also handles the
multi-result case. This allows to build IR in a more concise way:
op = dialect.produce_multiple_results()
other = dialect.produce_single_result()
dialect.consume_multiple_results(other, op)
instead of having to access the results manually
op = dialect.produce.multiple_results()
other = dialect.produce_single_result()
dialect.consume_multiple_results(other.result, op.operation.results)
The dispatch is implemented directly in Python and is triggered automatically
for autogenerated OpView subclasses. Extension OpView classes should use the
functions provided in ods_common.py if they want to implement this behavior.
An alternative could be to implement the dispatch in the C++ bindings code, but
it would require to forward opaque types through all Python functions down to a
binding call, which makes it hard to inspect them in Python, e.g., to obtain
the types of values.
Reviewed By: gysit
Differential Revision: https://reviews.llvm.org/D111306
More information about the All-commits
mailing list