[Mlir-commits] [mlir] [mlir][Python] downcast ir.Value to BlockArgument or OpResult (PR #175264)
Maksim Levental
llvmlistbot at llvm.org
Fri Jan 9 20:02:52 PST 2026
================
@@ -2012,26 +2006,23 @@ nb::typed<nb::object, PyValue> PyValue::maybeDownCast() {
PyGlobals::get().lookupValueCaster(mlirTypeID, mlirTypeGetDialect(type));
// nb::rv_policy::move means use std::move to move the return value
// contents into a new instance that will be owned by Python.
- nb::object thisObj = nb::cast(this, nb::rv_policy::move);
- if (!valueCaster)
- return thisObj;
- return valueCaster.value()(thisObj);
+ nb::object thisObj;
+ if (mlirValueIsAOpResult(value))
+ thisObj = nb::cast<PyOpResult>(*this, nb::rv_policy::move);
+ else if (mlirValueIsABlockArgument(value))
+ thisObj = nb::cast<PyBlockArgument>(*this, nb::rv_policy::move);
+ else
+ assert(false && "Value must be an block arg or op result.");
+ if (valueCaster)
+ return valueCaster.value()(thisObj);
+ return thisObj;
----------------
makslevental wrote:
this is the only significant part of the PR...
https://github.com/llvm/llvm-project/pull/175264
More information about the Mlir-commits
mailing list