mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 19:08:21 +08:00
[mlir][python] expose isAttached (#153045)
This commit is contained in:
@@ -3442,6 +3442,14 @@ void mlir::python::populateIRCore(nb::module_ &m) {
|
||||
return operation.createOpView();
|
||||
},
|
||||
"Detaches the operation from its parent block.")
|
||||
.def_prop_ro(
|
||||
"attached",
|
||||
[](PyOperationBase &self) {
|
||||
PyOperation &operation = self.getOperation();
|
||||
operation.checkValid();
|
||||
return operation.isAttached();
|
||||
},
|
||||
"Reports if the operation is attached to its parent block.")
|
||||
.def("erase", [](PyOperationBase &self) { self.getOperation().erase(); })
|
||||
.def("walk", &PyOperationBase::walk, nb::arg("callback"),
|
||||
nb::arg("walk_order") = MlirWalkPostOrder);
|
||||
|
||||
@@ -194,6 +194,13 @@ class _OperationBase:
|
||||
"""
|
||||
Detaches the operation from its parent block.
|
||||
"""
|
||||
|
||||
@property
|
||||
def attached(self) -> bool:
|
||||
"""
|
||||
Reports if the operation is attached to its parent block.
|
||||
"""
|
||||
|
||||
def erase(self) -> None: ...
|
||||
|
||||
@overload
|
||||
|
||||
@@ -1021,6 +1021,8 @@ def testDetachFromParent():
|
||||
with Context():
|
||||
m1 = Module.parse("func.func private @foo()")
|
||||
func = m1.body.operations[0].detach_from_parent()
|
||||
# CHECK: func.attached=False
|
||||
print(f"{func.attached=}")
|
||||
|
||||
try:
|
||||
func.detach_from_parent()
|
||||
|
||||
Reference in New Issue
Block a user