Merge pull request #43746 from trentlo:clear_opnds_for_removed_hlos

PiperOrigin-RevId: 335915793
Change-Id: I938fe587a47dc425d2ed6e227c0b938981039e62
This commit is contained in:
TensorFlower Gardener 2020-10-07 11:58:45 -07:00
commit 6f2bb31b57
2 changed files with 4 additions and 0 deletions

View File

@ -315,6 +315,8 @@ Status HloComputation::RemoveInstructionImpl(HloInstruction* instruction,
(*inst_it->second)->set_parent(nullptr);
to_be_deleted_.emplace_back(inst_it->second->release());
to_be_deleted_.back()->DetachFromOperandsAndUsers();
// Clear all operands to avoid Null operands.
to_be_deleted_.back()->RemoveAllOperands();
to_be_deleted_.back()->MarkAsDead();
instructions_.erase(inst_it->second);
instruction_iterators_.erase(inst_it);

View File

@ -1911,6 +1911,8 @@ class HloInstruction {
// by factory methods.
HloInstruction(HloOpcode opcode, const Shape& shape);
void RemoveAllOperands() { operands_.clear(); }
void RemoveOperandAt(int index) {
operands_.erase(operands_.begin() + index);
}