Skip to content

Commit bd39fa8

Browse files
committed
rebase
1 parent fddfa84 commit bd39fa8

File tree

7 files changed

+65
-67
lines changed

7 files changed

+65
-67
lines changed

mlir/include/mlir/Bindings/Python/Globals.h

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -201,50 +201,6 @@ class PyGlobals {
201201
TracebackLoc tracebackLoc;
202202
TypeIDAllocator typeIDAllocator;
203203
};
204-
205-
/// Wrapper for the global LLVM debugging flag.
206-
struct PyGlobalDebugFlag {
207-
static void set(nanobind::object &o, bool enable) {
208-
nanobind::ft_lock_guard lock(mutex);
209-
mlirEnableGlobalDebug(enable);
210-
}
211-
212-
static bool get(const nanobind::object &) {
213-
nanobind::ft_lock_guard lock(mutex);
214-
return mlirIsGlobalDebugEnabled();
215-
}
216-
217-
static void bind(nanobind::module_ &m) {
218-
// Debug flags.
219-
nanobind::class_<PyGlobalDebugFlag>(m, "_GlobalDebug")
220-
.def_prop_rw_static("flag", &PyGlobalDebugFlag::get,
221-
&PyGlobalDebugFlag::set, "LLVM-wide debug flag.")
222-
.def_static(
223-
"set_types",
224-
[](const std::string &type) {
225-
nanobind::ft_lock_guard lock(mutex);
226-
mlirSetGlobalDebugType(type.c_str());
227-
},
228-
nanobind::arg("types"),
229-
"Sets specific debug types to be produced by LLVM.")
230-
.def_static(
231-
"set_types",
232-
[](const std::vector<std::string> &types) {
233-
std::vector<const char *> pointers;
234-
pointers.reserve(types.size());
235-
for (const std::string &str : types)
236-
pointers.push_back(str.c_str());
237-
nanobind::ft_lock_guard lock(mutex);
238-
mlirSetGlobalDebugTypes(pointers.data(), pointers.size());
239-
},
240-
nanobind::arg("types"),
241-
"Sets multiple specific debug types to be produced by LLVM.");
242-
}
243-
244-
private:
245-
static nanobind::ft_mutex mutex;
246-
};
247-
248204
} // namespace python
249205
} // namespace mlir
250206

mlir/include/mlir/Bindings/Python/IRCore.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,12 +1350,12 @@ void registerMLIRErrorInCore();
13501350

13511351
/// Helper for creating an @classmethod.
13521352
template <class Func, typename... Args>
1353-
static nanobind::object classmethod(Func f, Args... args) {
1353+
nanobind::object classmethod(Func f, Args... args) {
13541354
nanobind::object cf = nanobind::cpp_function(f, args...);
13551355
return nanobind::borrow<nanobind::object>((PyClassMethod_New(cf.ptr())));
13561356
}
13571357

1358-
static nanobind::object
1358+
inline nanobind::object
13591359
createCustomDialectWrapper(const std::string &dialectNamespace,
13601360
nanobind::object dialectDescriptor) {
13611361
auto dialectClass = PyGlobals::get().lookupDialectClass(dialectNamespace);
@@ -1368,21 +1368,21 @@ createCustomDialectWrapper(const std::string &dialectNamespace,
13681368
return (*dialectClass)(std::move(dialectDescriptor));
13691369
}
13701370

1371-
static MlirStringRef toMlirStringRef(const std::string &s) {
1371+
inline MlirStringRef toMlirStringRef(const std::string &s) {
13721372
return mlirStringRefCreate(s.data(), s.size());
13731373
}
13741374

1375-
static MlirStringRef toMlirStringRef(std::string_view s) {
1375+
inline MlirStringRef toMlirStringRef(std::string_view s) {
13761376
return mlirStringRefCreate(s.data(), s.size());
13771377
}
13781378

1379-
static MlirStringRef toMlirStringRef(const nanobind::bytes &s) {
1379+
inline MlirStringRef toMlirStringRef(const nanobind::bytes &s) {
13801380
return mlirStringRefCreate(static_cast<const char *>(s.data()), s.size());
13811381
}
13821382

13831383
/// Create a block, using the current location context if no locations are
13841384
/// specified.
1385-
static MlirBlock
1385+
inline MlirBlock
13861386
createBlock(const nanobind::sequence &pyArgTypes,
13871387
const std::optional<nanobind::sequence> &pyArgLocs) {
13881388
SmallVector<MlirType> argTypes;
@@ -1871,7 +1871,7 @@ class PyOpResult : public PyConcreteValue<PyOpResult> {
18711871

18721872
/// Returns the list of types of the values held by container.
18731873
template <typename Container>
1874-
static std::vector<nanobind::typed<nanobind::object, PyType>>
1874+
std::vector<nanobind::typed<nanobind::object, PyType>>
18751875
getValueTypes(Container &container, PyMlirContextRef &context) {
18761876
std::vector<nanobind::typed<nanobind::object, PyType>> result;
18771877
result.reserve(container.size());

mlir/lib/Bindings/Python/Globals.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,4 @@ bool PyGlobals::TracebackLoc::isUserTracebackFilename(
267267
}
268268
return isUserTracebackFilenameCache[file];
269269
}
270-
271-
nanobind::ft_mutex PyGlobalDebugFlag::mutex;
272-
273270
} // namespace mlir::python

mlir/lib/Bindings/Python/IRAttributes.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,6 @@ struct nb_format_descriptor<double> {
228228
static const char *format() { return "d"; }
229229
};
230230

231-
static MlirStringRef toMlirStringRef(const std::string &s) {
232-
return mlirStringRefCreate(s.data(), s.size());
233-
}
234-
235-
static MlirStringRef toMlirStringRef(const nb::bytes &s) {
236-
return mlirStringRefCreate(static_cast<const char *>(s.data()), s.size());
237-
}
238-
239231
class PyAffineMapAttribute : public PyConcreteAttribute<PyAffineMapAttribute> {
240232
public:
241233
static constexpr IsAFunctionTy isaFunction = mlirAttributeIsAAffineMap;

mlir/lib/Bindings/Python/IRCore.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <iostream>
2828
#include <optional>
29+
#include <typeinfo>
2930

3031
namespace nb = nanobind;
3132
using namespace nb::literals;

mlir/lib/Bindings/Python/MainModule.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,51 @@ maybeGetTracebackLocation(const std::optional<PyLocation> &location) {
185185
PyMlirContextRef ref = PyMlirContext::forContext(ctx.get());
186186
return {ref, mlirLoc};
187187
}
188+
189+
/// Wrapper for the global LLVM debugging flag.
190+
struct PyGlobalDebugFlag {
191+
static void set(nanobind::object &o, bool enable) {
192+
nanobind::ft_lock_guard lock(mutex);
193+
mlirEnableGlobalDebug(enable);
194+
}
195+
196+
static bool get(const nanobind::object &) {
197+
nanobind::ft_lock_guard lock(mutex);
198+
return mlirIsGlobalDebugEnabled();
199+
}
200+
201+
static void bind(nanobind::module_ &m) {
202+
// Debug flags.
203+
nanobind::class_<PyGlobalDebugFlag>(m, "_GlobalDebug")
204+
.def_prop_rw_static("flag", &PyGlobalDebugFlag::get,
205+
&PyGlobalDebugFlag::set, "LLVM-wide debug flag.")
206+
.def_static(
207+
"set_types",
208+
[](const std::string &type) {
209+
nanobind::ft_lock_guard lock(mutex);
210+
mlirSetGlobalDebugType(type.c_str());
211+
},
212+
nanobind::arg("types"),
213+
"Sets specific debug types to be produced by LLVM.")
214+
.def_static(
215+
"set_types",
216+
[](const std::vector<std::string> &types) {
217+
std::vector<const char *> pointers;
218+
pointers.reserve(types.size());
219+
for (const std::string &str : types)
220+
pointers.push_back(str.c_str());
221+
nanobind::ft_lock_guard lock(mutex);
222+
mlirSetGlobalDebugTypes(pointers.data(), pointers.size());
223+
},
224+
nanobind::arg("types"),
225+
"Sets multiple specific debug types to be produced by LLVM.");
226+
}
227+
228+
private:
229+
static nanobind::ft_mutex mutex;
230+
};
231+
232+
nanobind::ft_mutex PyGlobalDebugFlag::mutex;
188233
} // namespace
189234

190235
//------------------------------------------------------------------------------
@@ -1241,6 +1286,14 @@ static void populateIRCore(nb::module_ &m) {
12411286
return PyOpSuccessors(self.getOperation().getRef());
12421287
},
12431288
"Returns the list of Operation successors.")
1289+
.def(
1290+
"replace_uses_of_with",
1291+
[](PyOperation &self, PyValue &of, PyValue &with) {
1292+
mlirOperationReplaceUsesOfWith(self.get(), of.get(), with.get());
1293+
},
1294+
"of"_a, "with_"_a,
1295+
"Replaces uses of the 'of' value with the 'with' value inside the "
1296+
"operation.")
12441297
.def("_set_invalid", &PyOperation::setInvalid,
12451298
"Invalidate the operation.");
12461299

mlir/python/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,12 +1022,11 @@ add_mlir_library(MLIRPythonSupport
10221022
${NB_LIBRARY_TARGET_NAME}
10231023
MLIRPythonCAPI
10241024
)
1025-
nanobind_link_options(MLIRPythonSupport)
1026-
get_target_property(_current_link_options MLIRPythonSupport LINK_OPTIONS)
1027-
if(_current_link_options)
1028-
string(REPLACE "LINKER:-z,defs" "" _modified_link_options "${_current_link_options}")
1029-
set_property(TARGET MLIRPythonSupport PROPERTY LINK_OPTIONS "${_modified_link_options}")
1025+
if((CMAKE_SYSTEM_NAME STREQUAL "Linux") AND (NOT LLVM_USE_SANITIZER))
1026+
target_link_options(MLIRPythonSupport PRIVATE "-Wl,-z,undefs")
1027+
target_link_options(${NB_LIBRARY_TARGET_NAME} PRIVATE "-Wl,-z,undefs")
10301028
endif()
1029+
nanobind_link_options(MLIRPythonSupport)
10311030
set_target_properties(MLIRPythonSupport PROPERTIES
10321031
LIBRARY_OUTPUT_DIRECTORY "${MLIRPythonModules_ROOT_PREFIX}/_mlir_libs"
10331032
BINARY_OUTPUT_DIRECTORY "${MLIRPythonModules_ROOT_PREFIX}/_mlir_libs"

0 commit comments

Comments
 (0)