[LLVMdev] How to delete a instruction?

John Criswell criswell at uiuc.edu
Tue Apr 20 06:46:45 PDT 2010


lucefe wrote:
> Hi,
>
> when I delete some instruction, I got some error prompt message.

Deleting instructions can be a little tricky.  The problem is that you 
can't delete an instruction until there are no other instructions that 
are using it.  There are two things that you can do:

1) Order your deletions so that the instructions at the end of def-use 
chains are deleted first; or
2) Replace all uses of the instructions to delete with an Undef value 
first and then delete the instruction.

-- John T.

>
> -  %i.0.reg2mem.0 = phi i32 [ 0, %bb5 ], [ %indvar.next, %bb12 ] ; 
> <i32> [#uses=2]
> -  %s.0.reg2mem.0 = phi i32 [ 0, %bb5 ], [ %tmp16, %bb12 ] ; <i32> 
> [#uses=1]
> -  %tmp14 = tail call i32 @foobar(i32 %i.0.reg2mem.0) nounwind ; <i32> 
> [#uses=1]
> -  %tmp16 = add i32 %tmp14, %s.0.reg2mem.0         ; <i32> [#uses=2]
>    %indvar.next = add i32 %i.0.reg2mem.0, 1        ; <i32> [#uses=2]
>    %exitcond = icmp eq i32 %indvar.next, %n        ; <i1> [#uses=1]
>    br i1 %exitcond, label %bb25, label %bb12
>
> For example, I want to delete the instructions above with symbol '-' 
> in front, but when I delete the first one, I got the next prompt message:
>
> While deleting: i32 %s.0.reg2mem.0
> Use still stuck around after Def is destroyed:  %tmp16 = add i32 
> %tmp14, %s.0.reg2mem.0         ; <i32> [#uses=1]
> opt: Value.cpp:81: virtual llvm::Value::~Value(): Assertion 
> `use_empty() && "Uses remain when a value is destroyed!"' failed.
>
> Program received signal SIGABRT, Aborted.
>
> I know I should do some work before the deletion to guarantee that no 
> other instructions will use the instruction being deleted. Who can 
> tell me what I should do?
>
> With Best Regards!
>
>
>
>




More information about the llvm-dev mailing list