diff --git a/mlir/cmake/modules/AddMLIRPythonExtension.cmake b/mlir/cmake/modules/AddMLIRPythonExtension.cmake --- a/mlir/cmake/modules/AddMLIRPythonExtension.cmake +++ b/mlir/cmake/modules/AddMLIRPythonExtension.cmake @@ -136,17 +136,27 @@ endfunction() -function(add_mlir_dialect_python_bindings tblgen_target filename dialectname) - set(LLVM_TARGET_DEFINITIONS ${filename}) - mlir_tablegen("${dialectname}.py" -gen-python-op-bindings - -bind-dialect=${dialectname}) - add_public_tablegen_target(${tblgen_target}) +function(add_mlir_dialect_python_bindings tblgen_target) + cmake_parse_arguments(ARG + "" + "TD_FILE;DIALECT_NAME" + "DEPENDS" + ${ARGN}) + + set(LLVM_TARGET_DEFINITIONS ${ARG_TD_FILE}) + mlir_tablegen("${ARG_DIALECT_NAME}.py" -gen-python-op-bindings + -bind-dialect=${ARG_DIALECT_NAME}) + add_public_tablegen_target( + ${tblgen_target}) + if(ARG_DEPENDS) + add_dependencies(${tblgen_target} ${ARG_DEPENDS}) + endif() add_custom_command( TARGET ${tblgen_target} POST_BUILD - COMMENT "Copying generated python source \"dialects/${dialectname}.py\"" + COMMENT "Copying generated python source \"dialects/${ARG_DIALECT_NAME}.py\"" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${CMAKE_CURRENT_BINARY_DIR}/${dialectname}.py" - "${PROJECT_BINARY_DIR}/python/mlir/dialects/${dialectname}.py") + "${CMAKE_CURRENT_BINARY_DIR}/${ARG_DIALECT_NAME}.py" + "${PROJECT_BINARY_DIR}/python/mlir/dialects/${ARG_DIALECT_NAME}.py") endfunction() diff --git a/mlir/lib/Bindings/Python/CMakeLists.txt b/mlir/lib/Bindings/Python/CMakeLists.txt --- a/mlir/lib/Bindings/Python/CMakeLists.txt +++ b/mlir/lib/Bindings/Python/CMakeLists.txt @@ -35,11 +35,27 @@ # Generate dialect-specific bindings. ################################################################################ +add_mlir_dialect_python_bindings(MLIRBindingsPythonLinalgOps + TD_FILE LinalgOps.td + DIALECT_NAME linalg + DEPENDS LinalgOdsGen) +add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonLinalgOps) + +add_mlir_dialect_python_bindings(MLIRBindingsPythonShapeOps + TD_FILE ShapeOps.td + DIALECT_NAME shape) +add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonShapeOps) + add_mlir_dialect_python_bindings(MLIRBindingsPythonStandardOps - StandardOps.td - std) + TD_FILE StandardOps.td + DIALECT_NAME std) add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonStandardOps) +add_mlir_dialect_python_bindings(MLIRBindingsPythonTensorOps + TD_FILE TensorOps.td + DIALECT_NAME tensor) +add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonTensorOps) + ################################################################################ # Build core python extension ################################################################################ diff --git a/mlir/lib/Bindings/Python/LinalgOps.td b/mlir/lib/Bindings/Python/LinalgOps.td new file mode 100644 --- /dev/null +++ b/mlir/lib/Bindings/Python/LinalgOps.td @@ -0,0 +1,16 @@ +//===-- LinalgOps.td - Entry point for linalg bind ---------*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef PYTHON_BINDINGS_LINALG_OPS +#define PYTHON_BINDINGS_LINALG_OPS + +include "mlir/Bindings/Python/Attributes.td" +include "mlir/Dialect/Linalg/IR/LinalgOps.td" +include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.td" + +#endif diff --git a/mlir/lib/Bindings/Python/ShapeOps.td b/mlir/lib/Bindings/Python/ShapeOps.td new file mode 100644 --- /dev/null +++ b/mlir/lib/Bindings/Python/ShapeOps.td @@ -0,0 +1,15 @@ +//===-- ShapeOps.td - Entry point for TensorOps bind -------*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef PYTHON_BINDINGS_SHAPE_OPS +#define PYTHON_BINDINGS_SHAPE_OPS + +include "mlir/Bindings/Python/Attributes.td" +include "mlir/Dialect/Shape/IR/ShapeOps.td" + +#endif diff --git a/mlir/lib/Bindings/Python/TensorOps.td b/mlir/lib/Bindings/Python/TensorOps.td new file mode 100644 --- /dev/null +++ b/mlir/lib/Bindings/Python/TensorOps.td @@ -0,0 +1,15 @@ +//===-- TensorOps.td - Entry point for TensorOps bind ------*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef PYTHON_BINDINGS_TENSOR_OPS +#define PYTHON_BINDINGS_TENSOR_OPS + +include "mlir/Bindings/Python/Attributes.td" +include "mlir/Dialect/Tensor/IR/TensorOps.td" + +#endif diff --git a/mlir/test/Bindings/Python/CMakeLists.txt b/mlir/test/Bindings/Python/CMakeLists.txt --- a/mlir/test/Bindings/Python/CMakeLists.txt +++ b/mlir/test/Bindings/Python/CMakeLists.txt @@ -1,4 +1,4 @@ include(AddMLIRPythonExtension) add_mlir_dialect_python_bindings(MLIRBindingsPythonTestOps - python_test_ops.td - python_test) + TD_FILE python_test_ops.td + DIALECT_NAME python_test)