[Mlir-commits] [mlir] [MLIR][Python] remove `liveOperations` (PR #155114)

Maksim Levental llvmlistbot at llvm.org
Tue Sep 23 22:29:40 PDT 2025


makslevental wrote:

Re using `gc.get_objects()`: this works (copy-pasta from [SO](https://stackoverflow.com/a/55026299)):

```python
# Recursively expand slist's objects
# into olist, using seen to track
# already processed objects.
def _getr(slist, olist, seen):
    for e in slist:
        if id(e) in seen:
            continue
        seen[id(e)] = None
        olist.append(e)
        tl = gc.get_referents(e)
        if tl:
            _getr(tl, olist, seen)


# The public function.
def get_all_objects():
    """Return a list of all live Python
    objects, not including the list itself."""
    gcl = gc.get_objects()
    olist = []
    seen = {}
    # Just in case:
    seen[id(gcl)] = None
    seen[id(olist)] = None
    seen[id(seen)] = None
    # _getr does the real work.
    _getr(gcl, olist, seen)
    return olist

ops = [op1, op2, op3]

for obj in get_all_objects():
    if isinstance(obj, (Operation, OpView)):
        print(obj)
```


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


More information about the Mlir-commits mailing list