[Mlir-commits] [mlir] [MLIR][Python] Python binding support for AffineIfOp (PR #108323)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Tue Oct 29 13:29:35 PDT 2024


================
@@ -156,3 +156,61 @@ def for_(
             yield iv, iter_args[0]
         else:
             yield iv
+
+
+ at _ods_cext.register_operation(_Dialect, replace=True)
+class AffineIfOp(AffineIfOp):
+    """Specialization for the Affine if op class."""
+
+    def __init__(
+        self,
+        cond: IntegerSet,
+        results_: Optional[Type] = None,
+        *,
+        cond_operands: Optional[_VariadicResultValueT] = None,
+        hasElse: bool = False,
+        loc=None,
+        ip=None,
+    ):
+        """Creates an Affine `if` operation.
+
+        - `cond` is the integer set used to determine which regions of code
+          will be executed.
+        - `results` are the list of types to be yielded by the operand.
+        - `cond_operands` is the list of arguments to substitute the
+          dimensions, then symbols in the `cond` integer set expression to
+          determine whether they are in the set.
+        - `hasElse` determines whether the affine if operation has the else
+          branch.
+        """
+        if results_ is None:
+            results_ = []
+        if cond_operands is None:
+            cond_operands = []
+
+        if not (actual_n_inputs := len(cond_operands)) == (
+            exp_n_inputs := cond.n_inputs
+        ):
----------------
ftynse wrote:

Nit: I'm not sure using `:=` actually makes code shorter here, but less readable... Could we just assign variables above?

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


More information about the Mlir-commits mailing list