[Mlir-commits] [mlir] [mlir][python] value casting (PR #69644)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Wed Oct 25 01:43:11 PDT 2023


================
@@ -123,3 +130,52 @@ def get_op_result_or_op_results(
         if len(op.results) > 0
         else op
     )
+
+
+U = _TypeVar("U", bound=_cext.ir.Value)
+SubClassValueT = _Type[U]
+
+ValueCasterT = _Callable[
+    [_Union[_cext.ir.Value, _cext.ir.OpResult]], _Union[SubClassValueT, None]
+]
+
+_VALUE_CASTERS: defaultdict[
+    _cext.ir.TypeID,
+    _Sequence[ValueCasterT],
+] = defaultdict(list)
+
+
+def has_value_caster(typeid: _cext.ir.TypeID):
+    if not isinstance(typeid, _cext.ir.TypeID):
+        raise ValueError(f"{typeid=} is not a TypeID")
+    if typeid in _VALUE_CASTERS:
+        return True
+    return False
----------------
ftynse wrote:

```suggestion
    return typeid in _VALUE_CASTERS
```

would this work?

https://github.com/llvm/llvm-project/pull/69644


More information about the Mlir-commits mailing list