get the identifies of the unnamed temporaries from the instruction of LLVM IR

hello guys:
I am in trouble with get the identifies of the unnamed temporaries from the
instruction of LLVM IR.
for example:
instruction: %4 = mul nsw i32 %1, %width
unnamed temporaries: %4, %1
how to get them?
I have tried several iterators(op_iterator,value_op_iterator) and
getOperand(int) function,but none of them works.
does anyone know how to get it? thanks very much

Hi,

hello guys:
I am in trouble with get the identifies of the unnamed temporaries from the
instruction of LLVM IR.

this is a FAQ. Most names in the IR are just there to make it easier to read
and can safely be removed. You can't rely on instructions having names, and as
you saw often they do not have a name. Even if they start off with a name, the
optimizers may change the name, eg when inlining.

for example:
instruction: %4 = mul nsw i32 %1, %width
unnamed temporaries: %4, %1

These are not temporaries, they are values without a name. The numbers %4 and
%1 only exist in the human readable IR (.ll file), as without them it wouldn't
be possible to convert the human readable IR back into bitcode. You can't get
hold of them from the API since they don't exist.

how to get them?
I have tried several iterators(op_iterator,value_op_iterator) and
getOperand(int) function,but none of them works.
does anyone know how to get it? thanks very much

Why do you want them? Maybe you are really looking for debug info?

Ciao, Duncan.

hi, Duncan Sands:
thanks for your reply old friend.
the reason why I want to get the unnamed value is that I am doing some
analysis based on the IR code. And IR is in the form of SSA(static single
assignment). so i need to get the operands of each instructions including a
lot of instructions like this (%4 = mul nsw i32 %1, %width).
the unnamed values are the connection of instructions, if i can't get that,
how can i know the dependency of the instructions?

Hi,

hi, Duncan:
thanks for your patience.
i have tried it.
using instuction: errs()<<i->getOperand(0);
but it prints the address: someting like 0x1139700;
i checked the defination of getOperand() is Value* getOperand( unsigned int
i);
so is there someting i missed?

Hi,

hi, Duncan:
thanks for your patience.
i have tried it.
using instuction: errs()<<i->getOperand(0);

   errs()<<*i->getOperand(0);

You can also use: i->getOperand(0)->dump();

Ciao, Duncan.

hi, Duncan,
thank you for your reply;
instruction "i->getOperand(0)->dump()" may print the %4 in the screen, but
how can i store it in a variable like char * oprand="%4" ?

http://llvm.org/docs/FAQ.html#what-api-do-i-use-to-store-a-value-to-one-of-the-virtual-registers-in-llvm-ir-s-ssa-representation

-- Sean Silva

This may help you understand the situation a bit better:
http://llvm.org/docs/FAQ.html#what-api-do-i-use-to-store-a-value-to-one-of-the-virtual-registers-in-llvm-ir-s-ssa-representation

-- Sean Silva

hi Sean Silva:
i really appriciate for your reply.
but you konw that "dump()" instruction can print "%4" in the screen and each
time print the same name "%4" not "%5" or "%6" for the same unnamed value.
so there must be a way to determinate it. if "dump()" instruction can print
it on the screen, can i find some way to store it in a char * variable?

From: llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu]
On Behalf Of Dong Chen
Subject: Re: [LLVMdev] get the identifies of the unnamed temporaries from the instruction of LLVM IR

but you konw that "dump()" instruction can print "%4" in the screen and each
time print the same name "%4" not "%5" or "%6" for the same unnamed value.

That the symbols are the same each time is a characteristic of what you're doing, not of LLVM itself. The symbols are only generated for printing, and are not an attribute of the underlying Instruction object. Running additional optimization passes after a first printing will usually change the generated number, as instructions are removed, reordered, and coalesced.

- Chuck

THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

Value::dump() just calls Value::print(raw_ostream &OS), which you can call with a raw_string_ostream or raw_svector_ostream, but it’s a pretty expensive operation (O(instructions + BB’s)) meant for debugging. Printing a single instruction like that essentially requires a linear scan of the entire function to calculate the numbers. The AsmWriter doesn’t use Value::print to generate the names (it’s actually the other way around: Value::print essentially instantiates a complete AsmWriter just to get the name of a single Value).

Like it says at that FAQ, the numbers are not stored explicitly in the in-memory IR. Look in lib/IR/AsmWriter.cpp. especially Value::print() and the SlotTracker class (which is what actually calculates the numbers).

Also, be aware that the numbers can change if you insert instructions/BB’s into the function.

– Sean Silva