llvm-project/mlir/tools
Alex Zinenko b164f23c29 [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
2021-10-08 09:49:48 +02:00
..
mlir-cpu-runner [mlir][Standard] NFC - Drop remaining EDSC usage 2021-05-21 10:40:39 +00:00
mlir-linalg-ods-gen [mlir][linalg] Add unsigned min/max/cast function to OpDSL. 2021-10-07 06:27:20 +00:00
mlir-lsp-server [mlir][Standard] NFC - Drop remaining EDSC usage 2021-05-21 10:40:39 +00:00
mlir-opt [mlir] Create a generic reduction detection utility 2021-09-24 20:45:59 +00:00
mlir-reduce [MLIR] Move TestDialect to ::test namespace 2021-08-14 13:24:41 -07:00
mlir-shlib [MLIR] Reapply: Adjust libMLIR building to more closely follow libClang 2020-05-04 20:47:57 -07:00
mlir-spirv-cpu-runner [mlir] Fix CMake option for enabling SPIR-V CPU runner 2021-07-29 16:34:09 -04:00
mlir-tblgen [mlir][python] support taking ops instead of values in op constructors 2021-10-08 09:49:48 +02:00
mlir-translate Revert "[RFC] Factor out repetitive cmake patterns for llvm-style projects" 2020-10-04 15:17:34 -07:00
mlir-vulkan-runner Fix clang-tidy warning "modernize-use-nullptr" in MLIR VulkanRuntime (NFC) 2021-09-26 22:06:00 +00:00
CMakeLists.txt [mlir][mlir-lsp] Add a new C++ LSP server for MLIR named mlir-lsp-server 2021-04-21 14:44:37 -07:00