[LLVMdev] Accessing instruction/operand names

James Stanier j.stanier at sussex.ac.uk
Wed Apr 15 07:26:09 PDT 2009


Hi Luke,

That's no problem - I understand why it would seem confusing. 

The graph I'm constructing is a dataflow graph, and when working with the
bitcode, I'm iterating through each Instruction object and then generating
some nodes and edges. 

Take these instructions as an example:

%x_addr = alloca i32		; <i32*> [#uses=2]
// Instructions omitted...
%2 = load i32* %x_addr, align 4	 ; <i32> [#uses=1]

The first instruction generates an "alloca" node, which has an edge to a
node specifying its type, which is i32*.

When the "load" node is generated, it has an edge to its operand, which
would be the previously generated "alloca" node (i.e. this is where %x_addr
"came from"). This is the reason I was curious about the names; I'm
currently just generating one cluster of nodes per instruction, and need to
be able to map them to something to say "we've just generated this edge,
which needs to point here".

Does this make any sense? I can elaborate with some pictures if it doesn't.

Best,

James

P.S. Milos - thanks for your answer.


Luke Dalessandro-2 wrote:
> 
> 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?
> 
> This question seems a little bit confusing as written, given that LLVM 
> IR is in SSA form. The actual names aren't really relevant to anything.
> 
> Maybe you could be more specific about the task you are trying to 
> accomplish to get a good answer?
> 
> Luke
> 
>> 
>> Thanks in advance - I've been stuck on this for a while.
>> 
>> Best,
>> 
>> James
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 
> 

-- 
View this message in context: http://www.nabble.com/Accessing-instruction-operand-names-tp23058683p23060060.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.




More information about the llvm-dev mailing list