[Mlir-commits] [mlir] [MLIR][Python] Add bindings for PDL native rewrite function registering (PR #159926)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Sep 23 03:57:22 PDT 2025
================
@@ -24,6 +27,27 @@ using namespace mlir::python;
namespace {
#if MLIR_ENABLE_PDL_IN_PATTERNMATCH
+nb::object objectFromPDLValue(MlirPDLValue value) {
+ if (mlirPDLValueIsValue(value))
+ return nb::cast(mlirPDLValueAsValue(value));
+ if (mlirPDLValueIsOperation(value))
+ return nb::cast(mlirPDLValueAsOperation(value));
+ if (mlirPDLValueIsAttribute(value))
+ return nb::cast(mlirPDLValueAsAttribute(value));
+ if (mlirPDLValueIsType(value))
+ return nb::cast(mlirPDLValueAsType(value));
+
+ throw std::runtime_error("unsupported PDL value type");
+}
+
+MlirLogicalResult logicalResultFromObject(const nb::object &obj) {
+ if (obj.is_none())
+ return mlirLogicalResultSuccess();
----------------
PragmaTwice wrote:
As mentioned here https://github.com/llvm/llvm-project/pull/159926#discussion_r2365739180, we treat `False` as success here, and in python `bool(None)` is `False`. Not sure why nanobind cannot handle `nb::cast<bool>(obj)` when `obj` is `None` so here I added a special check.
https://github.com/llvm/llvm-project/pull/159926
More information about the Mlir-commits
mailing list