[LLVMdev] Removing Instructions

Frits van Bommel fvbommel at gmail.com
Sat Feb 26 11:59:29 PST 2011


On Sat, Feb 26, 2011 at 8:48 PM, Michael Kiperberg <mkiperberg at gmail.com> wrote:
> I try to write a pass that clones a function and then removes some instruction from the clone, the clone is then added to the module (the parent of the source function).
> I call removeFromParent() on the appropriate instruction and it is actually removed (I see it in module's dump). However I get a failed assertion at Module Verifier which says:
> ---
> Instruction referencing instruction not embedded in a basic block!
> <existing instruction>
> <removed instruction>
> ---
> The problem is, the existing instruction holds a reference to the removed instruction in its UseList, i.e. the removed instruction needs the result if the existing instruction (so the removal is legal).
> Should I go over all the UseList`s and remove the reference?

removeFromParent() doesn't delete the instruction, it just removes it
from the basic block. This is useful if you want to re-insert it
somewhere else.
However, I think what you're looking for is eraseFromParent(), which
actually deletes the instruction after removing it from its parent.
This also takes care of removing it from the use lists of all of its
operands.



More information about the llvm-dev mailing list