Launcher
2012-May-09 02:48 UTC
[LLVMdev] 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? -- 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.
John Criswell
2012-May-09 02:52 UTC
[LLVMdev] How can I get the destination operand of an instruction?
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.htmlIn 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? > > >
ofv at wanadoo.es
2012-May-09 03:14 UTC
[LLVMdev] How can I get the destination operand of an instruction?
Launcher <st.liucheng at 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.htmlThat'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
2012-May-09 13:55 UTC
[LLVMdev] How can I get the destination operand of an instruction?
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 ). <ofv at 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?-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120509/19879381/attachment.html>
Cheng Liu
2012-May-10 07:06 UTC
[LLVMdev] How can I get the destination operand of an instruction?
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.liucheng at 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
Apparently Analagous Threads
- [LLVMdev] How can I get the destination operand of an instruction?
- [LLVMdev] How can I get the destination operand of an instruction?
- [LLVMdev] [HEADSUP] Another attempt at CallInst operand rotation
- [LLVMdev] LLVM related question
- [LLVMdev] Printing Function Arguments