[LLVMdev] How can I get the destination operand of an instruction?

883 views
Skip to first unread message

Launcher

unread,
May 8, 2012, 10:48:46 PM5/8/12
to llv...@cs.uiuc.edu

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?



--
View this message in context: http://old.nabble.com/How-can-I-get-the-destination-operand-of-an-instruction--tp33763595p33763595.html
Sent from the LLVM - Dev mailing list archive at Nabble.com.

_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

John Criswell

unread,
May 8, 2012, 10:52:31 PM5/8/12
to Launcher, llv...@cs.uiuc.edu
On 5/8/12 9:48 PM, Launcher wrote:
> 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.

>
> 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?
>
>
>

=?utf-8?Q?=C3=93scar_Fuentes?=

unread,
May 8, 2012, 11:14:22 PM5/8/12
to Launcher, llv...@cs.uiuc.edu
Launcher <st.li...@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.

Cheng Liu

unread,
May 9, 2012, 9:55:03 AM5/9/12
to Óscar Fuentes, llv...@cs.uiuc.edu
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)<<" ";
}
...
// --------------------------------------------------------------------

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

<o...@wanadoo.es>(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 *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).
//----------------------------------------------------------------------------------------
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()<<it->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:
::getValueID, don't you?

Duncan Sands

unread,
May 9, 2012, 10:38:04 AM5/9/12
to llv...@cs.uiuc.edu
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.

陳韋任

unread,
May 9, 2012, 10:51:53 AM5/9/12
to Duncan Sands, llv...@cs.uiuc.edu
> > 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

--
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj

Cheng Liu

unread,
May 10, 2012, 3:06:36 AM5/10/12
to Óscar Fuentes, llv...@cs.uiuc.edu
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.

On 5/9/2012 11:14 AM, =?utf-8?Q?=C3=93scar_Fuentes?= wrote:
> Launcher<st.li...@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.


--
Cheng Liu
PhD Candidate
Department of Electrical and Electronic Engineering
The University of Hong Kong
Reply all
Reply to author
Forward
0 new messages