How can I get the destination operand of an instruction?

I am able to access the source operands of an instruction using either
getOperand() or op_iterator, However, I can't find any method available for
destination operand. Someone suggests that instruction itself can represent
the destination operand.
http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-January/037518.html

The getOperand() returns an unsigned value like 0x9063498, while I can't
find any instruction's method that returns unsigned value. I have tried
getValue(), but it actually returns the opcode of the instruction instead of
a unique value of of an instruction instance.

Anyone gives any suggestions about this?

I am able to access the source operands of an instruction using either
getOperand() or op_iterator, However, I can't find any method available for
destination operand. Someone suggests that instruction itself can represent
the destination operand.
http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-January/037518.html

In LLVM, the instruction *is* the same as it's result. Let us say that instruction pointer I1 points to an add instruction and I2 points to a subtract instruction. Then:

I2->setOperand (I1, 1);

will make instruction I1 the first operand of instruction I2 (note that I didn't check the exact arguments of the setOperand() method, so they may be off, but I think you get the idea).

-- John T.

Launcher <st.liucheng@gmail.com> writes:

I am able to access the source operands of an instruction using either
getOperand() or op_iterator, However, I can't find any method available for
destination operand. Someone suggests that instruction itself can represent
the destination operand.
http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-January/037518.html

That's correct: the llvm::Instruction itself represents the result of
the operation. Note that class llvm::Instruction derives from
llvm::Value through llvm::User.

The getOperand() returns an unsigned value like 0x9063498,

Uh? User::getOperand returns a Value*.

while I can't
find any instruction's method that returns unsigned value. I have tried
getValue(),

You mean Value::getValueID, don't you?

but it actually returns the opcode of the instruction instead of
a unique value of of an instruction instance.

Anyone gives any suggestions about this?

Read again the message you linked at the beginning.

Sorry, I have typo in my question.
I will be careful next time.

This is how I obtain the source operands of an instruction.
// -----------------------------------------------------------------
BasicBlock::iterator it;

for(int k=0; k<OpNum; k++){
errs()<getOperand(k)<<" ";
}

// --------------------------------------------------------------------

Also I try
it->getVaueID(), and it->InstructionVal
to get destination operand.
They don’t work and I know what they return now ).

(My computer can’t display your name correctly, and I am sorry for this.) is right, getOperand() actually returns Value*. The reason that I see string like ‘0x9063489’ is that I print it using ‘errs()<<’. I notice that all the variables with different names have different strings like ‘0x9063489’ and I think I can use it to identify different variables as well as instruction instances (I need this to extract data dependence graph/data flow graph from each basicblcok). I guess there may be operator<< overload in value.h and I looked into the source code value.h, but I didn’t find it. I still do not know how to get strings/number like ‘0x9063489’ without using errs()<<. As for destination operand or instruction, I need similar numbers or strings to identify all the variables and instruction instances. John gave a suggestion, but I am not sure whether I got it right. //---------------------------------------------------------------------------------------------- --In LLVM, the instruction the same as it’s result. Let us say that instruction pointer I1 points to an add instruction and I2 points to a subtract instruction. Then: --I2->setOperand (I1, 1); --will make instruction I1 the first operand of instruction I2 (note that I didn’t check the exact arguments of the setOperand() method, so they may be off, but I think you get the --idea). //---------------------------------------------------------------------------------------- Since I can get the representation (I mean the strings like 0x9063489 ) of all source operands, and I can trace back to get the instruction’s representation. It seems a little bit wired for me because I am finding unique representations for variables and instruction instances to determine the instruction dependence. In this case, now finding dependence turns to be a preliminary issue ). -------------------------------------------------------------------- I think people may get confused about what I am talking. Just make it short and clear. For example, I have a few instructions in the same basic block. instruction1: add %a %b %c … instruction10: add %e %d %a Now I use this code to identify the source operands. for(int k=0; k<OpNum; k++){ errs()<getOperand(k)<<" "; } I find that %b->0x90 %c->0x91 %d->0x92 %a->0x93 but I do not know %a->? %e->? Actually I am expecting that %a->0x93, and then I can declare that instruction10 depends instruction1. On 5/9/2012 11:14 AM, =?utf-8?Q?=C3=93scar_Fuentes?= wrote:

Hi,

Sorry, I have typo in my question.
I will be careful next time.

This is how I obtain the source operands of an instruction.
// -----------------------------------------------------------------
BasicBlock::iterator it;
...
for(int k=0; k<OpNum; k++){
errs()<<it->getOperand(k)<<" ";

try this:
   it->getOperand(k)->dump()

}
...
// --------------------------------------------------------------------

Also I try
it->getVaueID(), and it->InstructionVal
to get destination operand.

What do you mean by "destination operand"?

Ciao, Duncan.

> Also I try
> it->getVaueID(), and it->InstructionVal
> to get destination operand.

What do you mean by "destination operand"?

  I believe he mean the result, see
  http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-May/049603.html

Regards,
chenwj

I read previous link according to your suggestion, and find that the pointers of basicblock, instruction, operand can display strings like '0x908784' using errs()<<*ptr
Theses strings are unique representation for different instruction instances, basic blocks and variables. Thus they can help me to build data flow graph in operand level.

Thank you very much.