Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit b027d9f

Browse files
authored
[mlir,python] Fix case when FuncOp.arg_attrs is not set (#117188)
FuncOps can have `arg_attrs`, an array of dictionary attributes associated with their arguments. E.g., ```mlir func.func @main(%arg0: tensor<8xf32> {test.attr_name = "value"}, %arg1: tensor<8x16xf32>) ``` These are exposed via the MLIR Python bindings with `my_funcop.arg_attrs`. In this case, it would return `[{test.attr_name = "value"}, {}]`, i.e., `%arg1` has an empty `DictAttr`. However, if I try and access this property from a FuncOp with an empty `arg_attrs`, e.g., ```mlir func.func @main(%arg0: tensor<8xf32>, %arg1: tensor<8x16xf32>) ``` This raises the error: ```python return ArrayAttr(self.attributes[ARGUMENT_ATTRIBUTE_NAME]) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^ KeyError: 'attempt to access a non-existent attribute' ``` This PR fixes this by returning the expected `[{}, {}]`.
1 parent c33df21 commit b027d9f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

mlir/python/mlir/dialects/func.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ def add_entry_block(self, arg_locs: Optional[Sequence[Location]] = None):
105105

106106
@property
107107
def arg_attrs(self):
108+
if ARGUMENT_ATTRIBUTE_NAME not in self.attributes:
109+
return ArrayAttr.get([DictAttr.get({}) for _ in self.type.inputs])
108110
return ArrayAttr(self.attributes[ARGUMENT_ATTRIBUTE_NAME])
109111

110112
@arg_attrs.setter

0 commit comments

Comments
 (0)