llvm-project/mlir/lib/Bindings/Python/CMakeLists.txt

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.9 KiB
CMake
Raw Normal View History

include(AddMLIRPython)
add_custom_target(MLIRBindingsPythonExtension)
[mlir] Add basic support for attributes in ODS-generated Python bindings In ODS, attributes of an operation can be provided as a part of the "arguments" field, together with operands. Such attributes are accepted by the op builder and have accessors generated. Implement similar functionality for ODS-generated op-specific Python bindings: the `__init__` method now accepts arguments together with operands, in the same order as in the ODS `arguments` field; the instance properties are introduced to OpView classes to access the attributes. This initial implementation accepts and returns instances of the corresponding attribute class, and not the underlying values since the mapping scheme of the value types between C++, C and Python is not yet clear. Default-valued attributes are not supported as that would require Python to be able to parse C++ literals. Since attributes in ODS are tightely related to the actual C++ type system, provide a separate Tablegen file with the mapping between ODS storage type for attributes (typically, the underlying C++ attribute class), and the corresponding class name. So far, this might look unnecessary since all names match exactly, but this is not necessarily the cases for non-standard, out-of-tree attributes, which may also be placed in non-default namespaces or Python modules. This also allows out-of-tree users to generate Python bindings without having to modify the bindings generator itself. Storage type was preferred over the Tablegen "def" of the attribute class because ODS essentially encodes attribute _constraints_ rather than classes, e.g. there may be many Tablegen "def"s in the ODS that correspond to the same attribute type with additional constraints The presence of the explicit mapping requires the change in the .td file structure: instead of just calling the bindings generator directly on the main ODS file of the dialect, it becomes necessary to create a new file that includes the main ODS file of the dialect and provides the mapping for attribute types. Arguably, this approach offers better separability of the Python bindings in the build system as the main dialect no longer needs to know that it is being processed by the bindings generator. Reviewed By: stellaraccident Differential Revision: https://reviews.llvm.org/D91542
2020-11-16 23:17:03 +08:00
################################################################################
# Build core python extension
################################################################################
add_mlir_python_extension(MLIRCoreBindingsPythonExtension _mlir
INSTALL_DIR
python
SOURCES
DialectLinalg.cpp
DialectSparseTensor.cpp
MainModule.cpp
IRAffine.cpp
IRAttributes.cpp
IRCore.cpp
IRModule.cpp
IRTypes.cpp
PybindUtils.cpp
Pass.cpp
ExecutionEngine.cpp
)
add_dependencies(MLIRBindingsPythonExtension MLIRCoreBindingsPythonExtension)
add_subdirectory(Transforms)
add_subdirectory(Conversions)
add_mlir_python_extension(MLIRAllPassesRegistrationBindingsPythonExtension _mlirAllPassesRegistration
INSTALL_DIR
python
SOURCES
AllPassesRegistration.cpp
)
add_dependencies(MLIRBindingsPythonExtension MLIRAllPassesRegistrationBindingsPythonExtension)
add_mlir_python_extension(MLIRAsyncPassesBindingsPythonExtension _mlirAsyncPasses
INSTALL_DIR
python
SOURCES
AsyncPasses.cpp
)
add_dependencies(MLIRBindingsPythonExtension MLIRAsyncPassesBindingsPythonExtension)
add_mlir_python_extension(MLIRSparseTensorPassesBindingsPythonExtension _mlirSparseTensorPasses
INSTALL_DIR
python
SOURCES
SparseTensorPasses.cpp
)
add_dependencies(MLIRBindingsPythonExtension MLIRSparseTensorPassesBindingsPythonExtension)
add_mlir_python_extension(MLIRGPUPassesBindingsPythonExtension _mlirGPUPasses
INSTALL_DIR
python
SOURCES
GPUPasses.cpp
)
add_dependencies(MLIRBindingsPythonExtension MLIRGPUPassesBindingsPythonExtension)
add_mlir_python_extension(MLIRLinalgPassesBindingsPythonExtension _mlirLinalgPasses
INSTALL_DIR
python
SOURCES
LinalgPasses.cpp
)
add_dependencies(MLIRBindingsPythonExtension MLIRLinalgPassesBindingsPythonExtension)