[Mlir-commits] [mlir] [mlir, python] Fix case when `FuncOp.arg_attrs` is not set (PR #117188)

Perry Gibson llvmlistbot at llvm.org
Fri Nov 22 09:59:22 PST 2024


================
@@ -105,6 +105,10 @@ def add_entry_block(self, arg_locs: Optional[Sequence[Location]] = None):
 
     @property
     def arg_attrs(self):
+        if ARGUMENT_ATTRIBUTE_NAME not in self.attributes:
+            self.attributes[ARGUMENT_ATTRIBUTE_NAME] = ArrayAttr.get(
----------------
Wheest wrote:

I can see your point, however in the code I was working on, I have something like:

```python
for arg, arg_attr in zip(block.arguments, func_op.arg_attrs):
    if "my.value" in arg_attr:
        lst1.append(arg)
    else:
        lst2.append(arg)
```

In your proposal, I would need to add a `None` check such as:

```python
if func_op.arg_attrs is None:
    lst2.extend(block.arguments)
else:
    for arg, arg_attr in zip(block.arguments, func_op.arg_attrs):
        if "my.value" in arg_attr:
            lst1.append(arg)
        else:
            lst2.append(arg)
```

This would improve performance, but this is Python and perhaps not the chief concern, rather simplicity.

Happy to make the change to return `None` if you prefer, but from my perspective the overhead of generating empty dicts and then walking over an empty list makes more sense.



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


More information about the Mlir-commits mailing list