diff --git a/mlir/include/mlir-c/Registration.h b/mlir/include/mlir-c/Registration.h --- a/mlir/include/mlir-c/Registration.h +++ b/mlir/include/mlir-c/Registration.h @@ -60,6 +60,9 @@ /// Register all translations to LLVM IR for dialects that can support it. MLIR_CAPI_EXPORTED void mlirRegisterAllLLVMTranslations(MlirContext context); +/// Register all compiler passes of MLIR. +MLIR_CAPI_EXPORTED void mlirRegisterAllPasses(); + #ifdef __cplusplus } #endif diff --git a/mlir/lib/Bindings/Python/AllPassesRegistration.cpp b/mlir/lib/Bindings/Python/AllPassesRegistration.cpp new file mode 100644 --- /dev/null +++ b/mlir/lib/Bindings/Python/AllPassesRegistration.cpp @@ -0,0 +1,22 @@ +//===- AllPassesRegistration.cpp - Pybind module to register all passes ---===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "mlir-c/Registration.h" + +#include + +// ----------------------------------------------------------------------------- +// Module initialization. +// ----------------------------------------------------------------------------- + +PYBIND11_MODULE(_mlirAllPassesRegistration, m) { + m.doc() = "MLIR All Passes Convenience Module"; + + // Register all passes on load. + mlirRegisterAllPasses(); +} 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 @@ -25,6 +25,14 @@ 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 @@ -37,7 +45,7 @@ INSTALL_DIR python SOURCES - SparseTensorPasses.cpp + SparseTensorPasses.cpp ) add_dependencies(MLIRBindingsPythonExtension MLIRSparseTensorPassesBindingsPythonExtension) diff --git a/mlir/lib/CAPI/Registration/Registration.cpp b/mlir/lib/CAPI/Registration/Registration.cpp --- a/mlir/lib/CAPI/Registration/Registration.cpp +++ b/mlir/lib/CAPI/Registration/Registration.cpp @@ -10,6 +10,7 @@ #include "mlir/CAPI/IR.h" #include "mlir/InitAllDialects.h" +#include "mlir/InitAllPasses.h" #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" void mlirRegisterAllDialects(MlirContext context) { @@ -21,3 +22,5 @@ void mlirRegisterAllLLVMTranslations(MlirContext context) { mlir::registerLLVMDialectTranslation(*unwrap(context)); } + +void mlirRegisterAllPasses() { mlir::registerAllPasses(); } diff --git a/mlir/python/mlir/all_passes_registration/__init__.py b/mlir/python/mlir/all_passes_registration/__init__.py new file mode 100644 --- /dev/null +++ b/mlir/python/mlir/all_passes_registration/__init__.py @@ -0,0 +1,8 @@ +# 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 + +from .._cext_loader import _load_extension + +_cextAllPasses = _load_extension("_mlirAllPassesRegistration") +del _load_extension