[LLVMdev] Accessing instruction/operand names
Anthony Danalis
adanalis at eecs.utk.edu
Wed Apr 15 07:33:28 PDT 2009
James, the "variables" %number don't really exist in the IR, they are
there for the textual representation. In memory all you've got is
interconnected Value objects.
To understand this, imagine you have the following code:
%3 = add i32 %2, %1
%5 = add i32 %3, %2
and you have a pointer to the Value that holds the "%5 = ..." add
instruction. Now, if you call getOperand(0) on it, it will not return
a "variable" named %3, it will return another Value, which will be the
Instruction "add i32 %2, %1"
However, if you're trying to do what I think you are, you can write a
recursive function exprToString()
that keeps following the pointers up the tree until it hits a
constant, or a function call, or a named variable and rebuilds the
expressions in a human readable way.
Anthony
On Apr 15, 2009, at 9:20 AM, James Stanier wrote:
>
> Hello everyone,
>
> I'm currently constructing a graph from LLVM bitcode, and I have a
> question
> about accessing the names of the variables shown in the .ll assembly
> file,
> assuming it's possible...
>
> For example, with
>
> %2 = load i32* %x_addr, align 4 ; <i32> [#uses=1]
>
> I can retrieve the opcodeName() from the Instruction object, which is
> "load". I can also access the operand and use getName() to retrieve
> "x_addr". However, this instruction is storing into %2 - how do I
> access the
> name of that?
>
> Also, when an operand is a numbered temporary such as
>
> %3 = add i32 %2, %1 ; <i32> [#uses=1]
>
> I'm also unable to access the name of it. Are these numberings no
> longer
> present in the bitcode? If not, is there any way to find out the
> name of
> which local variable it is referencing?
>
> Thanks in advance - I've been stuck on this for a while.
>
> Best,
>
> James
> --
> View this message in context: http://www.nabble.com/Accessing-instruction-operand-names-tp23058683p23058683.html
> Sent from the LLVM - Dev mailing list archive at Nabble.com.
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list