[Mlir-commits] [mlir] [MLIR][Python] enable ptr dialect bindings (PR #167270)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Dec 15 18:00:42 PST 2025


Aneureka wrote:

I'm not sure if it's related but I recently noticed that the python binding for `vector.gather` op began to support the alignment property. Here's the generated code in `_vector_ops_gen.py`:

```
@_ods_cext.register_operation(_Dialect)
class GatherOp(_ods_ir.OpView):
  OPERATION_NAME = "vector.gather"

  _ODS_REGIONS = (0, True)

  def __init__(self, result, base, offsets, indices, mask, pass_thru, *, alignment=None, loc=None, ip=None):
    operands = []
    attributes = {}
    regions = None
    operands.append(base)
    # ...
    _ods_context = _ods_get_default_loc_context(loc)
    if alignment is not None: attributes["alignment"] = (alignment if (
        isinstance(alignment, _ods_ir.Attribute) or
        not _ods_ir.AttrBuilder.contains('I64Attr')) else
          _ods_ir.AttrBuilder.get('I64Attr')(alignment, context=_ods_context))
    results = []
    results.append(result)
    _ods_successors = None
    super().__init__(self.OPERATION_NAME, self._ODS_REGIONS, self._ODS_OPERAND_SEGMENTS, self._ODS_RESULT_SEGMENTS, attributes=attributes, results=results, operands=operands, successors=_ods_successors, regions=regions, loc=loc, ip=ip)

  @builtins.property
  def base(self) -> _ods_ir.Value:
    return self.operation.operands[0]

  # ...

  @builtins.property
  def alignment(self) -> _Optional[_ods_ir.IntegerAttr]:
    if "alignment" not in self.operation.attributes:
      return None
    return self.operation.attributes["alignment"]

  @alignment.setter
  def alignment(self, value: _Optional[_ods_ir.IntegerAttr]):
    if value is not None:
      self.operation.attributes["alignment"] = value
    elif "alignment" in self.operation.attributes:
      del self.operation.attributes["alignment"]

  @alignment.deleter
  def alignment(self):
    del self.operation.attributes["alignment"]

def gather(result, base, offsets, indices, mask, pass_thru, *, alignment=None, loc=None, ip=None) -> _ods_ir.OpResult:
  return GatherOp(result=result, base=base, offsets=offsets, indices=indices, mask=mask, pass_thru=pass_thru, alignment=alignment, loc=loc, ip=ip).result
```

Does this work? If so, can we refer to this one and add the properties support for the ptr dialect?


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


More information about the Mlir-commits mailing list