RE: [LLVMdev] modify instructions

I think since we use the replaceAllUsesWith to replace all
uses of old one, the old one should already be a instruction
with # of uses equals 0. So it should be Ok to directly delete
it. Can you let me know if there is anything wrong with simple
deletion? Why can we create illegal LLVM?

Thanks,
xiaodong

Date: Thu, 26 Sep 2002 10:50:00 -0500
From: "Vikram S. Adve" <vadve@cs.uiuc.edu>
Subject: RE: [LLVMdev] modify instructions
To: <xli3@uiuc.edu>, <llvmdev@cs.uiuc.edu>

The simplest way is to create a new instruction and use

replaceAllUsesWith

on the old one.

Think about a simple way to get rid of the old one (without

producing

illegal LLVM as the output of your phase).

--Vikram

From: llvmdev-admin@cs.uiuc.edu

[mailto:llvmdev-admin@cs.uiuc.edu]On

Behalf Of xli3@uiuc.edu
Sent: Thursday, September 26, 2002 9:24 AM
To: llvmdev@cs.uiuc.edu
Subject: [LLVMdev] modify instructions

Hi, I have a question about the modify of instruction:
Say I want to modify
%a = getelementptr %struct %S, long 0, ubyte 1
into
%a.f0 = getelementptr int* %S.f0, long 0

There are 3 ways I can think of to implement, but I'm not

sure

what should I do.

1. I can use new GetElementPtr to create a new instruction

and

use ReplaceInstWithInst() function to replace the old one.

2. I can use new GetElementPtr to create a new instruction

and

then insert it into the code, then delete the old

instruction,

but the problem is the program will automatically change

the

name of the new instruction if you give it the same name

with

the old one?

3. Just modify the operand 0 and delete the operand 2. But

I

I think since we use the replaceAllUsesWith to replace all
uses of old one, the old one should already be a instruction
with # of uses equals 0. So it should be Ok to directly delete
it. Can you let me know if there is anything wrong with simple
deletion? Why can we create illegal LLVM?

You can't 'delete' it because the instruction is probably still embedded
in the program, so data structures are still using it.

Please see this section of the programmers manual to see how to do it:
http://llvm.cs.uiuc.edu/docs/ProgrammersManual.html#schanges_deleting

And yes, after calling replaceAllUsesWith, it is legal to remove the
instruction from the program.

-Chris