[LLVMdev] Removing Instructions

1,432 views
Skip to first unread message

Michael Kiperberg

unread,
Feb 26, 2011, 2:48:23 PM2/26/11
to LLVM-Dev
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?

Thanks,
Michael.
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Frits van Bommel

unread,
Feb 26, 2011, 2:59:29 PM2/26/11
to Michael Kiperberg, LLVM-Dev
On Sat, Feb 26, 2011 at 8:48 PM, Michael Kiperberg <mkipe...@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.

Reply all
Reply to author
Forward
0 new messages