Skip to content

Commit dc6a222

Browse files
committed
[mlir][python] loading dialect module is best effort only
1 parent 8ae7d2d commit dc6a222

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

mlir/lib/Bindings/Python/IRModule.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,8 @@ PyGlobals::lookupAttributeBuilder(const std::string &attributeKind) {
132132

133133
std::optional<py::function> PyGlobals::lookupTypeCaster(MlirTypeID mlirTypeID,
134134
MlirDialect dialect) {
135-
// Make sure dialect module is loaded.
136-
if (!loadDialectModule(unwrap(mlirDialectGetNamespace(dialect))))
137-
return std::nullopt;
138-
135+
// Try to load dialect module.
136+
(void)loadDialectModule(unwrap(mlirDialectGetNamespace(dialect)));
139137
const auto foundIt = typeCasterMap.find(mlirTypeID);
140138
if (foundIt != typeCasterMap.end()) {
141139
assert(foundIt->second && "type caster is defined");
@@ -146,7 +144,8 @@ std::optional<py::function> PyGlobals::lookupTypeCaster(MlirTypeID mlirTypeID,
146144

147145
std::optional<py::function> PyGlobals::lookupValueCaster(MlirTypeID mlirTypeID,
148146
MlirDialect dialect) {
149-
loadDialectModule(unwrap(mlirDialectGetNamespace(dialect)));
147+
// Try to load dialect module.
148+
(void)loadDialectModule(unwrap(mlirDialectGetNamespace(dialect)));
150149
const auto foundIt = valueCasterMap.find(mlirTypeID);
151150
if (foundIt != valueCasterMap.end()) {
152151
assert(foundIt->second && "value caster is defined");

mlir/python/CMakeLists.txt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ declare_mlir_python_sources(MLIRPythonCAPI.HeaderSources
4444
SOURCES_GLOB "mlir-c/*.h"
4545
)
4646

47-
# The builtin dialect is special (e.g., type casters and such expect it to be loaded
48-
# in order to work) so we add it to Core instead of Dialects so that anyone depending on
49-
# Core will get it automatically.
50-
declare_mlir_dialect_python_bindings(
51-
ADD_TO_PARENT MLIRPythonSources.Core
52-
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
53-
TD_FILE dialects/BuiltinOps.td
54-
SOURCES
55-
dialects/builtin.py
56-
DIALECT_NAME builtin)
57-
5847
################################################################################
5948
# Dialect bindings
6049
################################################################################
@@ -95,6 +84,14 @@ declare_mlir_dialect_python_bindings(
9584
"../../include/mlir/Dialect/Bufferization/IR/BufferizationEnums.td"
9685
)
9786

87+
declare_mlir_dialect_python_bindings(
88+
ADD_TO_PARENT MLIRPythonSources.Dialects
89+
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
90+
TD_FILE dialects/BuiltinOps.td
91+
SOURCES
92+
dialects/builtin.py
93+
DIALECT_NAME builtin)
94+
9895
declare_mlir_dialect_python_bindings(
9996
ADD_TO_PARENT MLIRPythonSources.Dialects
10097
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"

0 commit comments

Comments
 (0)