How to insert two instructions with the same name?

Hi,

i want to insert a PHI into one basicblock like this:

%s.1 = phi int [ 80, %entry ], [ %tmp21, %bb17 ]

then, insert a cast inst. into another basicblock like this:

%s.1 = cast int %s.1 to uint

But, when i do this, the llvm automatically change the same name into a new one.

Actually, i found that sometimes, llvm will create bytecode containing two instructions with same name. So, how can i implement that?

Thanks,
Sheng.

i want to insert a PHI into one basicblock like this:

%s.1 = phi int [ 80, %entry ], [ %tmp21, %bb17 ]

then, insert a cast inst. into another basicblock like this:

%s.1 = cast int %s.1 to uint

But, when i do this, the llvm automatically change the same name into a new one.

In SSA, any assignment creates a new variable. So it'd probably be called something like "%s.2" or whatever. Technically, LLVM doesn't care what the names of these variables are. They aren't used in the internal representation. Only pointers to instructions matter (and they're unique).

Actually, i found that sometimes, llvm will create bytecode containing two instructions with same name. So, how can i implement that?

Again, the names are meaningless and are given only because the user needs to be able to understand the .ll code. So it's entirely possible to have multiple variables with the same name.

-bw

Just to be clear ...

> Actually, i found that sometimes, llvm will create bytecode
> containing two instructions with same name. So, how can i implement
> that?
>
Again, the names are meaningless and are given only because the user
needs to be able to understand the .ll code. So it's entirely
possible to have multiple variables with the same name.

The same variable name can only appear across "type planes". That is,
there cannot be two identical names that refer to the same type.
However, the same name can be used to refer to different types. To
assist in this, the LLVM SymbolTable will automatically append an
monotonically increasing integer value to the name of any duplicate.
For example:

void %func() {
  %s = cast int 1 to int
  %s = cast long 1 to long
  %a = cast int 2 to int
  %a = cast long 2 to long
ret void
}

is completely legal. The %s and %a names don't conflict because they
have different types (int and long).

Reid.