@@ -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
0 commit comments