[MLIR][Python] Add method for getting the live operation objects (#78663)

Currently, a method exists to get the count of the operation objects
which are still alive. This helps for sanity checking, but isn't
terribly useful for debugging. This new method returns the actual
operation objects which are still alive.

This allows Python code like the following:

```
    gc.collect()
    live_ops = ir.Context.current._get_live_operation_objects()
    for op in live_ops:
      print(f"Warning: {op} is still live. Referrers:")
      for referrer in gc.get_referrers(op)[0]:
        print(f"  {referrer}")
```
This commit is contained in:
John Demme
2024-02-08 11:39:06 -08:00
committed by GitHub
parent e5924d6499
commit d1fdb41629
4 changed files with 17 additions and 0 deletions

View File

@@ -985,6 +985,7 @@ class Context:
def _get_context_again(self) -> Context: ...
def _get_live_module_count(self) -> int: ...
def _get_live_operation_count(self) -> int: ...
def _get_live_operation_objects(self) -> List[Operation]: ...
def append_dialect_registry(self, registry: DialectRegistry) -> None: ...
def attach_diagnostic_handler(
self, callback: Callable[[Diagnostic], bool]