forked from OSchip/llvm-project
Add a Block::dropAllReferences to drop all references from held instructions and call it when clearing the block. This fixes a bug where ForInst/IfInst instructions may still have references to values while being destroyed.
PiperOrigin-RevId: 229207798
This commit is contained in:
parent
a674ae8bbd
commit
d6b71b0d57
mlir
|
@ -40,6 +40,9 @@ public:
|
||||||
~Block();
|
~Block();
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
|
// Drop all references from within this block.
|
||||||
|
dropAllReferences();
|
||||||
|
|
||||||
// Clear instructions in the reverse order so that uses are destroyed
|
// Clear instructions in the reverse order so that uses are destroyed
|
||||||
// before their defs.
|
// before their defs.
|
||||||
while (!empty())
|
while (!empty())
|
||||||
|
@ -162,6 +165,11 @@ public:
|
||||||
const_cast<Instruction *>(&inst));
|
const_cast<Instruction *>(&inst));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This drops all operand uses from instructions within this block, which is
|
||||||
|
/// an essential step in breaking cyclic dependences between references when
|
||||||
|
/// they are to be deleted.
|
||||||
|
void dropAllReferences();
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
// Terminator management
|
// Terminator management
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
|
|
|
@ -87,6 +87,14 @@ Instruction *Block::findAncestorInstInBlock(Instruction *inst) {
|
||||||
return currInst;
|
return currInst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This drops all operand uses from instructions within this block, which is
|
||||||
|
/// an essential step in breaking cyclic dependences between references when
|
||||||
|
/// they are to be deleted.
|
||||||
|
void Block::dropAllReferences() {
|
||||||
|
for (Instruction &i : *this)
|
||||||
|
i.dropAllReferences();
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Argument list management.
|
// Argument list management.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
|
@ -37,8 +37,7 @@ Function::~Function() {
|
||||||
// Instructions may have cyclic references, which need to be dropped before we
|
// Instructions may have cyclic references, which need to be dropped before we
|
||||||
// can start deleting them.
|
// can start deleting them.
|
||||||
for (auto &bb : *this)
|
for (auto &bb : *this)
|
||||||
for (auto &inst : bb)
|
bb.dropAllReferences();
|
||||||
inst.dropAllReferences();
|
|
||||||
|
|
||||||
// Clean up function attributes referring to this function.
|
// Clean up function attributes referring to this function.
|
||||||
FunctionAttr::dropFunctionReference(this);
|
FunctionAttr::dropFunctionReference(this);
|
||||||
|
|
Loading…
Reference in New Issue