[libc-commits] [PATCH] D121076: [MLIR][Python] Add SCFIfOp Python binding

Hongzheng Chen via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Mar 7 09:33:38 PST 2022


chhzh123 updated this revision to Diff 413520.
chhzh123 added a comment.

Revert


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121076/new/

https://reviews.llvm.org/D121076

Files:
  mlir/python/mlir/dialects/_scf_ops_ext.py


Index: mlir/python/mlir/dialects/_scf_ops_ext.py
===================================================================
--- mlir/python/mlir/dialects/_scf_ops_ext.py
+++ mlir/python/mlir/dialects/_scf_ops_ext.py
@@ -64,3 +64,44 @@
     To obtain the loop-carried operands, use `iter_args`.
     """
     return self.body.arguments[1:]
+
+
+class IfOp:
+  """Specialization for the SCF if op class."""
+
+  def __init__(self,
+               results_,
+               cond,
+               withElseRegion=False,
+               *,
+               loc=None,
+               ip=None):
+    """Creates an SCF `if` operation.
+
+    - `cond` is a boolean value to determine which regions of code will be executed.
+    - `withElseRegion` determines whether the if operation has the else branch.
+    """
+    operands = []
+    operands.append(cond)
+    results = []
+    results.extend(results_)
+    super().__init__(
+        self.build_generic(
+            regions=2,
+            results=results,
+            operands=operands,
+            loc=loc,
+            ip=ip))
+    self.regions[0].blocks.append(*results)
+    if withElseRegion:
+        self.regions[1].blocks.append(*results)
+
+  @property
+  def then_block(self):
+    """Returns the then block of the if operation."""
+    return self.regions[0].blocks[0]
+
+  @property
+  def else_block(self):
+    """Returns the else block of the if operation."""
+    return self.regions[1].blocks[0]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121076.413520.patch
Type: text/x-patch
Size: 1455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20220307/2ad54fab/attachment-0001.bin>


More information about the libc-commits mailing list