Skip to content

Commit e85d9c8

Browse files
committed
factor registereverything
1 parent b02964f commit e85d9c8

File tree

11 files changed

+193
-6
lines changed

11 files changed

+193
-6
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- mlir-c/RegisterAllExtensions.h - Register all MLIR Extensions ---*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
4+
// Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef MLIR_C_REGISTER_Extensions_H
11+
#define MLIR_C_REGISTER_Extensions_H
12+
13+
#include "mlir-c/IR.h"
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
19+
/// Register all compiler Extensions of MLIR.
20+
MLIR_CAPI_EXPORTED void mlirRegisterAllExtensions(MlirDialectRegistry registry);
21+
22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
26+
#endif // MLIR_C_REGISTER_Extensions_H
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- mlir-c/RegisterAllLLVMTranslations.h - Register all LLVM translations //
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
4+
// Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef MLIR_C_REGISTER_LLVM_TRANSLATIONS_H
11+
#define MLIR_C_REGISTER_LLVM_TRANSLATIONS_H
12+
13+
#include "mlir-c/IR.h"
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
19+
/// Register all LLVM translations of MLIR.
20+
MLIR_CAPI_EXPORTED void mlirRegisterAllLLVMTranslations(MlirContext context);
21+
22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
26+
#endif // MLIR_C_REGISTER_LLVM_TRANSLATIONS_H
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- mlir-c/RegisterAllPasses.h - Register all MLIR Pass --*- C ------*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
4+
// Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef MLIR_C_REGISTER_PASSES_H
11+
#define MLIR_C_REGISTER_PASSES_H
12+
13+
#include "mlir-c/IR.h"
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
19+
/// Register all compiler passes of MLIR.
20+
MLIR_CAPI_EXPORTED void mlirRegisterAllPasses(void);
21+
22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
26+
#endif // MLIR_C_REGISTER_PASSES_H

mlir/include/mlir-c/RegisterEverything.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ MLIR_CAPI_EXPORTED void mlirRegisterAllDialects(MlirDialectRegistry registry);
2828
/// Register all translations to LLVM IR for dialects that can support it.
2929
MLIR_CAPI_EXPORTED void mlirRegisterAllLLVMTranslations(MlirContext context);
3030

31-
/// Register all compiler passes of MLIR.
32-
MLIR_CAPI_EXPORTED void mlirRegisterAllPasses(void);
31+
// /// Register all compiler passes of MLIR.
32+
// MLIR_CAPI_EXPORTED void mlirRegisterAllPasses(void);
3333

3434
#ifdef __cplusplus
3535
}

mlir/lib/Bindings/Python/RegisterEverything.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "mlir-c/RegisterEverything.h"
9+
#include "mlir-c/RegisterAllExtensions.h"
10+
#include "mlir-c/RegisterAllLLVMTranslations.h"
11+
#include "mlir-c/RegisterAllPasses.h"
1012
#include "mlir/Bindings/Python/Nanobind.h"
1113
#include "mlir/Bindings/Python/NanobindAdaptors.h"
1214

1315
NB_MODULE(_mlirRegisterEverything, m) {
14-
m.doc() = "MLIR All Upstream Dialects, Translations and Passes Registration";
16+
m.doc() =
17+
"MLIR All Upstream Extensions, Translations and Passes Registration";
1518

16-
m.def("register_dialects", [](MlirDialectRegistry registry) {
17-
mlirRegisterAllDialects(registry);
19+
m.def("register_extensions", [](MlirDialectRegistry registry) {
20+
mlirRegisterAllExtensions(registry);
1821
});
1922
m.def("register_llvm_translations",
2023
[](MlirContext context) { mlirRegisterAllLLVMTranslations(context); });

mlir/lib/CAPI/RegisterEverything/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)
33
add_mlir_upstream_c_api_library(MLIRCAPIRegisterEverything
44
RegisterEverything.cpp
5+
PARTIAL_SOURCES_INTENDED
56

67
LINK_LIBS PUBLIC
78
${translation_libs}
@@ -14,3 +15,32 @@ add_mlir_upstream_c_api_library(MLIRCAPIRegisterEverything
1415
MLIRRegisterAllExtensions
1516
MLIRRegisterAllPasses
1617
)
18+
19+
add_mlir_upstream_c_api_library(MLIRCAPIRegisterAllPasses
20+
RegisterAllPasses.cpp
21+
PARTIAL_SOURCES_INTENDED
22+
23+
LINK_LIBS PUBLIC
24+
MLIRCAPIIR
25+
MLIRRegisterAllPasses
26+
)
27+
28+
add_mlir_upstream_c_api_library(MLIRCAPIRegisterAllLLVMTranslations
29+
RegisterAllLLVMTranslations.cpp
30+
PARTIAL_SOURCES_INTENDED
31+
32+
LINK_LIBS PUBLIC
33+
MLIRCAPIIR
34+
${translation_libs}
35+
MLIRBuiltinToLLVMIRTranslation
36+
MLIRLLVMToLLVMIRTranslation
37+
)
38+
39+
add_mlir_upstream_c_api_library(MLIRCAPIRegisterAllExtensions
40+
RegisterAllExtensions.cpp
41+
PARTIAL_SOURCES_INTENDED
42+
43+
LINK_LIBS PUBLIC
44+
MLIRCAPIIR
45+
MLIRRegisterAllExtensions
46+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//===- RegisterAllExtensions.cpp - Register all MLIR entities
2+
//-----------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "mlir-c/RegisterAllExtensions.h"
11+
#include "mlir/CAPI/IR.h"
12+
#include "mlir/InitAllExtensions.h"
13+
14+
void mlirRegisterAllExtensions(MlirDialectRegistry registry) {
15+
mlir::registerAllExtensions(*unwrap(registry));
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===- RegisterAllPasses.cpp - Register all MLIR entities -----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "mlir-c/RegisterAllLLVMTranslations.h"
10+
#include "mlir/CAPI/IR.h"
11+
#include "mlir/Target/LLVMIR/Dialect/All.h"
12+
#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h"
13+
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
14+
15+
void mlirRegisterAllLLVMTranslations(MlirContext context) {
16+
auto &ctx = *unwrap(context);
17+
mlir::DialectRegistry registry;
18+
mlir::registerAllToLLVMIRTranslations(registry);
19+
ctx.appendDialectRegistry(registry);
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//===- RegisterAllPasses.cpp - Register all MLIR entities -----------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "mlir-c/RegisterAllPasses.h"
10+
#include "mlir/InitAllPasses.h"
11+
12+
void mlirRegisterAllPasses() { mlir::registerAllPasses(); }

mlir/python/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,29 @@ declare_mlir_python_extension(MLIRPythonExtension.Core
670670
MLIRCAPIFunc
671671
)
672672

673+
# This extension exposes an API to register all dialects, extensions, and passes
674+
# packaged in upstream MLIR and it is used for the upstream "mlir" Python
675+
# package. Downstreams will likely want to provide their own and not depend
676+
# on this one, since it links in the world.
677+
# Note that this is not added to any top-level source target for transitive
678+
# inclusion: It must be included explicitly by downstreams if desired. Note that
679+
# this has a very large impact on what gets built/packaged.
680+
declare_mlir_python_extension(MLIRPythonExtension.RegisterEverything
681+
MODULE_NAME _mlirRegisterEverything
682+
ROOT_DIR "${PYTHON_SOURCE_DIR}"
683+
PYTHON_BINDINGS_LIBRARY nanobind
684+
SOURCES
685+
RegisterEverything.cpp
686+
PRIVATE_LINK_LIBS
687+
LLVMSupport
688+
EMBED_CAPI_LINK_LIBS
689+
MLIRCAPIConversion
690+
MLIRCAPITransforms
691+
MLIRCAPIRegisterAllPasses
692+
MLIRCAPIRegisterAllExtensions
693+
MLIRCAPIRegisterAllLLVMTranslations
694+
)
695+
673696
declare_mlir_python_extension(MLIRPythonExtension.Dialects.Linalg.Pybind
674697
MODULE_NAME _mlirDialectsLinalg
675698
ADD_TO_PARENT MLIRPythonSources.Dialects.linalg
@@ -988,6 +1011,7 @@ add_mlir_python_common_capi_library(${MLIR_PYTHON_CAPI_DYLIB_NAME}
9881011
MLIRPythonCAPI.HeaderSources
9891012
DECLARED_SOURCES
9901013
MLIRPythonSources
1014+
MLIRPythonExtension.RegisterEverything
9911015
${_ADDL_TEST_SOURCES}
9921016
)
9931017

@@ -1096,6 +1120,7 @@ endif()
10961120

10971121
set(_declared_sources
10981122
MLIRPythonSources
1123+
MLIRPythonExtension.RegisterEverything
10991124
MLIRPythonCAPICTypesBinding)
11001125
if(NOT CMAKE_CROSSCOMPILING)
11011126
list(APPEND _declared_sources MLIRPythonExtension.Core.type_stub_gen)

0 commit comments

Comments
 (0)