llvm-project/mlir/tools/mlir-tblgen
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
..
AttrOrTypeDefGen.cpp [ODS/AsmParser] Don't pass MLIRContext with DialectAsmParser. 2021-09-30 05:10:28 +00:00
CMakeLists.txt [mlir-tblgen] Minor Refactor for StaticVerifierFunctionEmitter. 2021-08-12 20:53:05 +00:00
CodeGenHelpers.cpp [mlir-tblgen] Minor Refactor for StaticVerifierFunctionEmitter. 2021-08-12 20:53:05 +00:00
DialectGen.cpp Emit strong definition for TypeID storage in Op/Type/Attributes definition 2021-07-28 23:58:39 +00:00
DirectiveCommonGen.cpp [mlir][openacc] Use TableGen information for default enum 2021-01-12 09:42:42 -05:00
DocGenUtilities.h Mass update the MLIR license header to mention "Part of the LLVM project" 2020-01-26 03:58:30 +00:00
EnumsGen.cpp [mlir][ODS] Support specialized Attribute class for Enums 2021-03-17 16:44:24 +03:00
LLVMIRConversionGen.cpp [mlir] generate enum translation functions with unused attribute 2021-02-18 09:44:40 +01:00
LLVMIRIntrinsicGen.cpp Support alias.scope and noalias metadata lowering on intrinsics. 2021-09-01 16:54:20 +00:00
OpDefinitionsGen.cpp Fix bug for Ops with default valued attributes and successors/variadic regions. 2021-09-22 21:22:31 +00:00
OpDocGen.cpp [mlir][ods] Skip adding TOC in doc gen when present 2021-08-20 07:01:54 -07:00
OpFormatGen.cpp [ODS/AsmParser] Don't pass MLIRContext with DialectAsmParser. 2021-09-30 05:10:28 +00:00
OpFormatGen.h [mlir] Add initial support for parsing a declarative operation assembly format 2020-01-30 11:43:40 -08:00
OpGenHelpers.cpp [mlir] Hoist out getRequestedOpDefinitions helper 2021-04-06 12:53:28 -07:00
OpGenHelpers.h [mlir] Hoist out getRequestedOpDefinitions helper 2021-04-06 12:53:28 -07:00
OpInterfacesGen.cpp [mlir] Improve description of interface options 2021-07-22 19:35:56 +02:00
OpPythonBindingGen.cpp [mlir][python] support taking ops instead of values in op constructors 2021-10-08 09:49:48 +02:00
PassCAPIGen.cpp Add basic Python bindings for the PassManager and bind libTransforms 2020-11-10 19:55:21 +00:00
PassDocGen.cpp [mlir][Pass] Update the PassGen to generate base classes instead of utilities 2020-04-07 14:08:52 -07:00
PassGen.cpp [mlir][ODS] Fix copy ctor for generate Pass classes 2021-06-21 14:07:31 +03:00
RewriterGen.cpp [mlir] Fix build on Windows on Arm 2021-09-23 09:04:28 +02:00
SPIRVUtilsGen.cpp [mlir] Add an 'cppNamespace' field to availability 2021-10-05 09:38:09 -04:00
StructsGen.cpp Revert "Revert "Reorder MLIRContext location in BuiltinAttributes.h"" 2021-02-08 10:39:58 +01:00
mlir-tblgen.cpp Mass update the MLIR license header to mention "Part of the LLVM project" 2020-01-26 03:58:30 +00:00