Skip to content

Commit 1ffcd72

Browse files
committed
kind of working
1 parent b696366 commit 1ffcd72

File tree

17 files changed

+3428
-3340
lines changed

17 files changed

+3428
-3340
lines changed

mlir/cmake/modules/AddMLIRPython.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ function(add_mlir_python_extension libname extname)
780780
nanobind_add_module(${libname}
781781
NB_DOMAIN ${MLIR_BINDINGS_PYTHON_NB_DOMAIN}
782782
FREE_THREADED
783+
NB_SHARED
783784
${ARG_SOURCES}
784785
)
785786

mlir/lib/Bindings/Python/Globals.h renamed to mlir/include/mlir/Bindings/Python/Globals.h

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
#include <unordered_set>
1616
#include <vector>
1717

18-
#include "NanobindUtils.h"
18+
#include "mlir-c/Debug.h"
1919
#include "mlir-c/IR.h"
2020
#include "mlir-c/Support.h"
21+
#include "mlir/Bindings/Python/NanobindUtils.h"
2122
#include "mlir/CAPI/Support.h"
23+
2224
#include "llvm/ADT/DenseMap.h"
2325
#include "llvm/ADT/StringExtras.h"
2426
#include "llvm/ADT/StringRef.h"
@@ -200,6 +202,50 @@ class PyGlobals {
200202
TypeIDAllocator typeIDAllocator;
201203
};
202204

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+
248+
203249
} // namespace python
204250
} // namespace mlir
205251

0 commit comments

Comments
 (0)