Hi Duncan,<br><br>Thank you for your response! Now it works.<br><br>But I have another problem: Do you know how can I iterate through a Value*? For instance, I have :<br><br>Instruction *I1; // I take only I1 that are ICmp<br>
<br>errs()<<"\n "<<*I1->getOperand(0)<<" \n";<br>// %3 = load i32* %c, align 4 <br><br>As expected. Now I want to get %c from the previous to use "%c" in comparisons. I tried :<br>
<br>for (llvm::Value::use_iterator VI=(*I1->getOperand(0)).use_begin(), VE=(*I1->getOperand(0)).use_end(); VI != VE ; ++VI)<br> {<br> <br> errs()<<"\n "<<**VI<<" \n";<br>
// %cmp3 = icmp ne i32 %3, 0<br> }<br><br>Not as expected. It is printing the I1 instruction. <br><br>Do you know how I can get %c from the "load instruction"?<br><br>Thank you a lot !<br><br><br><br><br><div class="gmail_quote">
On Thu, Jan 10, 2013 at 11:21 AM, Duncan Sands <span dir="ltr"><<a href="mailto:baldrick@free.fr" target="_blank">baldrick@free.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<div><div class="h5"><br>
<br>
On 10/01/13 10:56, Alexandru Ionut Diaconescu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello everyone !<br>
<br>
In my pass I inspect the penultimate instruction from every basic block in<br>
runOnFunction(). I am interested in ICMP instructions only.<br>
<br>
|if(BB->size()>1)<br>
if(last->getPrevNode())<br>
{<br>
previous = last->getPrevNode();<br>
ok=1;<br>
}<br>
|<br>
<br>
I want to get the operands of previous, which is of type Instruction*. Due tests<br>
based on getNumOperands, ICMP has 2 (as normal).<br>
<br>
|if ( ok && ((previous->getNumOperands())><u></u>=2) )<br>
<br>
errs()<<"\nTTTTT "<<previous->getOperand(0)-><u></u>getName()<<" | "<br>
<<previous->getOperand(0)-><u></u>getValueName()<<" | "<br>
<<previous->getOperand(0)-><u></u>getValueID()<<" | "<br>
<<previous->getOperand(0)-><u></u>getNumUses()<<" TTTTT\n";<br>
|<br>
<br>
The results with getOperand(1) are similar. The output is:<br>
<br>
|*PREVIOUS: store i32 %conv15, i32* %i, align 4<br>
TTTTT conv15 | 0x9b69090 | 59 | 1 TTTTT<br>
...<br>
*PREVIOUS: store i32 %inc13, i32* %i, align 4<br>
TTTTT inc13 | 0x9b76478 | 30 | 1 TTTTT<br>
...<br>
*PREVIOUS: %cmp11 = icmp sgt i32 %8, 3<br>
TTTTT | 0x0 | 49 | 1 TTTTT<br>
...<br>
*PREVIOUS: store i32 %dec, i32* %i, align 4<br>
TTTTT dec | 0x9b69130 | 30 | 1 TTTTT<br>
...<br>
*PREVIOUS: %cmp8 = icmp sle i32 %6, 2<br>
TTTTT | 0x0 | 49 | 1 TTTTT<br>
...<br>
*PREVIOUS: store i32 %inc, i32* %i, align 4<br>
TTTTT inc | 0x9b761c8 | 30 | 1 TTTTT<br>
|<br>
<br>
Do you know how I can get the operands from ICMP instructions? I need to use<br>
them in some conditions? (also their attributes). Thank you a lot !<br>
</blockquote>
<br></div></div>
this is the correct way to get the operands. However you are wrongly assuming<br>
that all instructions have a name. If you look at<div class="im"><br>
%cmp11 = icmp sgt i32 %8, 3<br></div>
the fact that the first operand is %8 (rather than something like %i) tells you<br>
it has no name. That is why the name comes out as null.<br>
<br>
Ciao, Duncan.<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<br>
<br>
<br>
--<br>
Best regards,<br>
Alexandru Ionut Diaconescu<br>
<br>
<br></div>
______________________________<u></u>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
<br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><font style="background-color:rgb(255,255,255);color:rgb(153,153,153)">Best regards,</font><br style="background-color:rgb(255,255,255);color:rgb(153,153,153)"><font style="background-color:rgb(255,255,255);color:rgb(153,153,153)">Alexandru Ionut Diaconescu</font><br>