Alexandru Ionut Diaconescu
2013-Jan-11 10:12 UTC
[LLVMdev] LLVM Instruction*->getOperand() not working properly for ICMP
Hi Duncan, Thank you for your response! Now it works. But I have another problem: Do you know how can I iterate through a Value*? For instance, I have : Instruction *I1; // I take only I1 that are ICmp errs()<<"\n "<<*I1->getOperand(0)<<" \n"; // %3 = load i32* %c, align 4 As expected. Now I want to get %c from the previous to use "%c" in comparisons. I tried : for (llvm::Value::use_iterator VI=(*I1->getOperand(0)).use_begin(), VE=(*I1->getOperand(0)).use_end(); VI != VE ; ++VI) { errs()<<"\n "<<**VI<<" \n"; // %cmp3 = icmp ne i32 %3, 0 } Not as expected. It is printing the I1 instruction. Do you know how I can get %c from the "load instruction"? Thank you a lot ! On Thu, Jan 10, 2013 at 11:21 AM, Duncan Sands <baldrick at free.fr> wrote:> Hi, > > > On 10/01/13 10:56, Alexandru Ionut Diaconescu wrote: > >> Hello everyone ! >> >> In my pass I inspect the penultimate instruction from every basic block in >> runOnFunction(). I am interested in ICMP instructions only. >> >> |if(BB->size()>1) >> if(last->getPrevNode()) >> { >> previous = last->getPrevNode(); >> ok=1; >> } >> | >> >> I want to get the operands of previous, which is of type Instruction*. >> Due tests >> based on getNumOperands, ICMP has 2 (as normal). >> >> |if ( ok && ((previous->getNumOperands())>**=2) ) >> >> errs()<<"\nTTTTT "<<previous->getOperand(0)->**getName()<<" | " >> <<previous->getOperand(0)->**getValueName()<<" | " >> <<previous->getOperand(0)->**getValueID()<<" | " >> <<previous->getOperand(0)->**getNumUses()<<" TTTTT\n"; >> | >> >> The results with getOperand(1) are similar. The output is: >> >> |*PREVIOUS: store i32 %conv15, i32* %i, align 4 >> TTTTT conv15 | 0x9b69090 | 59 | 1 TTTTT >> ... >> *PREVIOUS: store i32 %inc13, i32* %i, align 4 >> TTTTT inc13 | 0x9b76478 | 30 | 1 TTTTT >> ... >> *PREVIOUS: %cmp11 = icmp sgt i32 %8, 3 >> TTTTT | 0x0 | 49 | 1 TTTTT >> ... >> *PREVIOUS: store i32 %dec, i32* %i, align 4 >> TTTTT dec | 0x9b69130 | 30 | 1 TTTTT >> ... >> *PREVIOUS: %cmp8 = icmp sle i32 %6, 2 >> TTTTT | 0x0 | 49 | 1 TTTTT >> ... >> *PREVIOUS: store i32 %inc, i32* %i, align 4 >> TTTTT inc | 0x9b761c8 | 30 | 1 TTTTT >> | >> >> Do you know how I can get the operands from ICMP instructions? I need to >> use >> them in some conditions? (also their attributes). Thank you a lot ! >> > > this is the correct way to get the operands. However you are wrongly > assuming > that all instructions have a name. If you look at > > %cmp11 = icmp sgt i32 %8, 3 > the fact that the first operand is %8 (rather than something like %i) > tells you > it has no name. That is why the name comes out as null. > > Ciao, Duncan. > > > >> >> >> -- >> Best regards, >> Alexandru Ionut Diaconescu >> >> >> ______________________________**_________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/**mailman/listinfo/llvmdev<http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev> >> >> > ______________________________**_________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/**mailman/listinfo/llvmdev<http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev> >-- Best regards, Alexandru Ionut Diaconescu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130111/79f556a5/attachment.html>
Óscar Fuentes
2013-Jan-11 11:07 UTC
[LLVMdev] LLVM Instruction*->getOperand() not working properly for ICMP
Alexandru Ionut Diaconescu <alexandruionutdiaconescu at gmail.com> writes:> But I have another problem: Do you know how can I iterate through a Value*? > For instance, I have : > > Instruction *I1; // I take only I1 that are ICmp > > errs()<<"\n "<<*I1->getOperand(0)<<" \n"; > // %3 = load i32* %c, align 4 > > As expected. Now I want to get %c from the previous to use "%c" in > comparisons. I tried : > > for (llvm::Value::use_iterator VI=(*I1->getOperand(0)).use_begin(), > VE=(*I1->getOperand(0)).use_end(); VI != VE ; ++VI) > { > > errs()<<"\n "<<**VI<<" \n"; > // %cmp3 = icmp ne i32 %3, 0 > } > > Not as expected. It is printing the I1 instruction. > > Do you know how I can get %c from the "load instruction"?In this case, you get %c starting from I1 this way: I1->getOperand(0)->getOperand(0) because "%3 = load i32* %c, align 4" (or %3, for short) is the first operand of I1, and %c is the first operand of %3. Please note that some Instructions are Values too. This is the case for the Instruction `load'.
Alexandru Ionut Diaconescu
2013-Jan-11 11:50 UTC
[LLVMdev] LLVM Instruction*->getOperand() not working properly for ICMP
Hi Óscar, But if I do "I1->getOperand(0)->getOperand(0)" I get " ‘class llvm::Value’ has no member named ‘getOperand’ ". getOperand() I think it's only defined for Instruction class. Do you know any equivalent method for Value? On Fri, Jan 11, 2013 at 12:07 PM, Óscar Fuentes <ofv at wanadoo.es> wrote:> Alexandru Ionut Diaconescu <alexandruionutdiaconescu at gmail.com> writes: > > > But I have another problem: Do you know how can I iterate through a > Value*? > > For instance, I have : > > > > Instruction *I1; // I take only I1 that are ICmp > > > > errs()<<"\n "<<*I1->getOperand(0)<<" \n"; > > // %3 = load i32* %c, align 4 > > > > As expected. Now I want to get %c from the previous to use "%c" in > > comparisons. I tried : > > > > for (llvm::Value::use_iterator VI=(*I1->getOperand(0)).use_begin(), > > VE=(*I1->getOperand(0)).use_end(); VI != VE ; ++VI) > > { > > > > errs()<<"\n "<<**VI<<" \n"; > > // %cmp3 = icmp ne i32 %3, 0 > > } > > > > Not as expected. It is printing the I1 instruction. > > > > Do you know how I can get %c from the "load instruction"? > > In this case, you get %c starting from I1 this way: > > I1->getOperand(0)->getOperand(0) > > because "%3 = load i32* %c, align 4" (or %3, for short) is the first > operand of I1, and %c is the first operand of %3. > > Please note that some Instructions are Values too. This is the case for > the Instruction `load'. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- Best regards, Alexandru Ionut Diaconescu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130111/c34ef86b/attachment.html>
Seemingly Similar Threads
- [LLVMdev] LLVM Instruction*->getOperand() not working properly for ICMP
- [LLVMdev] LLVM Instruction*->getOperand() not working properly for ICMP
- [LLVMdev] llvm get Value* iterators
- [LLVMdev] LLVM Instruction*->getOperand() not working properly for ICMP
- [LLVMdev] LLVM Instruction*->getOperand() not working properly for ICMP