diff options
author | Oleksandr "Alex" Zinenko <git@ozinenko.com> | 2024-05-30 10:06:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-30 10:06:02 +0200 |
commit | 67897d77eda4c312cfe81b19a20abed43227ecb8 (patch) | |
tree | ae8152c468db91043fb337ba50e5ac2aa3c5665b /mlir/lib/Bindings/Python/IRModule.h | |
parent | 540a36ad7e31bfeb11e795047a42bb6e30bf9985 (diff) | |
download | llvm-67897d77eda4c312cfe81b19a20abed43227ecb8.zip llvm-67897d77eda4c312cfe81b19a20abed43227ecb8.tar.gz llvm-67897d77eda4c312cfe81b19a20abed43227ecb8.tar.bz2 |
[mlir][py] invalidate nested operations when parent is deleted (#93339)
When an operation is erased in Python, its children may still be in the
"live" list inside Python bindings. After this, if some of the newly
allocated operations happen to reuse the same pointer address, this will
trigger an assertion in the bindings. This assertion would be incorrect
because the operations aren't actually live. Make sure we remove the
children operations from the "live" list when erasing the parent.
This also concentrates responsibility over the removal from the "live"
list and invalidation in a single place.
Note that this requires the IR to be sufficiently structurally valid so
a walk through it can succeed. If this invariant was broken by, e.g, C++
pass called from Python, there isn't much we can do.
Diffstat (limited to 'mlir/lib/Bindings/Python/IRModule.h')
-rw-r--r-- | mlir/lib/Bindings/Python/IRModule.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/mlir/lib/Bindings/Python/IRModule.h b/mlir/lib/Bindings/Python/IRModule.h index b038a0c..8c34c11 100644 --- a/mlir/lib/Bindings/Python/IRModule.h +++ b/mlir/lib/Bindings/Python/IRModule.h @@ -218,6 +218,8 @@ public: /// This is useful for when some non-bindings code destroys the operation and /// the bindings need to made aware. For example, in the case when pass /// manager is run. + /// + /// Note that this does *NOT* clear the nested operations. void clearOperation(MlirOperation op); /// Clears all operations nested inside the given op using @@ -225,6 +227,10 @@ public: void clearOperationsInside(PyOperationBase &op); void clearOperationsInside(MlirOperation op); + /// Clears the operaiton _and_ all operations inside using + /// `clearOperation(MlirOperation)`. + void clearOperationAndInside(PyOperationBase &op); + /// Gets the count of live modules associated with this context. /// Used for testing. size_t getLiveModuleCount(); @@ -246,6 +252,7 @@ public: private: PyMlirContext(MlirContext context); + // Interns the mapping of live MlirContext::ptr to PyMlirContext instances, // preserving the relationship that an MlirContext maps to a single // PyMlirContext wrapper. This could be replaced in the future with an |