[llvm] [SandboxIR][Tracker] Track eraseFromParent() (PR #99431)
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 18 10:03:38 PDT 2024
================
@@ -341,10 +341,26 @@ void Instruction::removeFromParent() {
void Instruction::eraseFromParent() {
assert(users().empty() && "Still connected to users, can't erase!");
std::unique_ptr<Value> Detached = Ctx.detach(this);
- // We don't have Tracking yet, so just erase the LLVM IR instructions.
+ auto LLVMInstrs = getLLVMInstrs();
+
+ auto &Tracker = Ctx.getTracker();
+ if (Tracker.isTracking()) {
+ Tracker.track(
+ std::make_unique<EraseFromParent>(std::move(Detached), Tracker));
+ // We don't actually delete the IR instruction, because then it would be
+ // impossible to bring it back from the dead at the same memory location.
+ // Instead we remove it from its BB and track its current location.
+ for (llvm::Instruction *I : LLVMInstrs)
+ I->removeFromParent();
+ // TODO: Multi-instructions need special treatment because some of the
+ // references are internal to the instruction.
+ for (llvm::Instruction *I : LLVMInstrs)
+ I->dropAllReferences();
+ return;
+ }
----------------
aeubanks wrote:
imo putting an `else` here rather than the `return` is a bit clearer
https://github.com/llvm/llvm-project/pull/99431
More information about the llvm-commits
mailing list