Scf.if Python binding doesn't work

The generated scf.if binding is as follows.

@_ods_cext.register_operation(_Dialect)
@_ods_extend_opview_class(_ods_ext_module)
class IfOp(_ods_ir.OpView):
  OPERATION_NAME = "scf.if"

  _ODS_REGIONS = (2, True)

  @builtins.property
  def condition(self):
    return self.operation.operands[0]

  @builtins.property
  def results_(self):
    _ods_variadic_group_length = len(self.operation.results) - 1 + 1
    return self.operation.results[0:0 + _ods_variadic_group_length]

  @builtins.property
  def thenRegion(self):
    return self.regions[0]

  @builtins.property
  def elseRegion(self):
    return self.regions[1]

But it does not allow me to pass in InsertionPoint, and when I try to access its region, it throws an error.

_scf_ops_gen.py", line 123, in thenRegion
    return self.regions[0]
IndexError: attempt to access out of bounds region

When creating the operation, you also need to create the regions for it by passing regions=2 to the constructor, otherwise it has none. As you can see, there is no generated __init__, so the generic one is used. It would be helpful to add a custom builder for scf.if similarly to how it’s done for scf.for here.

Thanks for replying! But how can an out-of-tree dialect add a constructor to an in-tree dialect (scf)? I suppose this should be changed inside the llvm-project.

I did mean an in-tree change and your original question did not mention out-of-tree projects. Contributing to MLIR is relatively easy - How to Contribute - MLIR - feel free to add me as a reviewer.

Hi, sorry for the late reply. I’ve submitted a PR and added you as a reviewer, please check D121076. Thanks!