<div dir="rtl"><div dir="ltr">r203364</div><div dir="ltr"><a href="http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140303/207915.html">http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140303/207915.html</a> </div>

<div dir="ltr"><br></div><div dir="ltr">The for code could be ranged</div><div dir="ltr"><pre style="font-family:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;font-size:0.95em;line-height:15.960000038146973px;padding:0.5em;border:1px solid rgb(204,204,204);background-color:rgb(248,248,248);color:rgb(0,0,0)">

<span class="" style="color:rgb(0,112,32);font-weight:bold">for</span> <span class="">(llvm</span><span class="" style="color:rgb(102,102,102)">::</span><span class="">user i : F->users()</span><span class="">)</span>
  <span class="" style="color:rgb(0,112,32);font-weight:bold">if</span> <span class="">(</span><span class="">Instruction</span> <span class="" style="color:rgb(102,102,102)">*</span><span class="">Inst</span> <span class="" style="color:rgb(102,102,102)">=</span> <span class="">dyn_cast</span><span class="" style="color:rgb(102,102,102)"><</span><span class="">Instruction</span><span class="" style="color:rgb(102,102,102)">></span><span class="">(</span><span class="">i</span><span class="">))</span> <span class="">{</span></pre>

</div><div dir="ltr">and the next code segment could be</div><div dir="ltr"><pre style="font-family:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;font-size:0.95em;line-height:15.960000038146973px;padding:0.5em;border:1px solid rgb(204,204,204);background-color:rgb(248,248,248);color:rgb(0,0,0)">

<span class="" style="color:rgb(0,112,32);font-weight:bold">for</span> <span class="">(llvm::use</span> i : <span class="">pi</span><span class="" style="color:rgb(102,102,102)">->uses()</span><span class="">)</span> <span class="">{</span><br>

</pre></div><div dir="ltr"><br></div><div dir="ltr"><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div dir="ltr">2014-04-30 16:15 GMT+03:00 Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span>:</div>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think so. Chandler, is this changed in r203364, no?<br>
<div class="HOEnZb"><div class="h5"><br>
On 30 April 2014 06:13, Yaron Keren <<a href="mailto:yaron.keren@gmail.com">yaron.keren@gmail.com</a>> wrote:<br>
> Thanks, using getUser() indeed works.  I am still confused by the example in<br>
> the LLVM Programmer's Manual that says<br>
><br>
> <a href="http://www.llvm.org/docs/ProgrammersManual.html#iterating-over-def-use-use-def-chains" target="_blank">http://www.llvm.org/docs/ProgrammersManual.html#iterating-over-def-use-use-def-chains</a><br>
><br>
> Finding all of the instructions that use foo is as simple as iterating over<br>
> the def-use chain of F:<br>
><br>
> Function *F = ...;<br>
><br>
> for (Value::use_iterator i = F->use_begin(), e = F->use_end(); i != e; ++i)<br>
>   if (Instruction *Inst = dyn_cast<Instruction>(*i)) {<br>
><br>
> won't (*i) get us back the llvm::Value (def) which is F ?<br>
> should the example code read<br>
><br>
>   if (Instruction *Inst = dyn_cast<Instruction>(i->getUser())) {<br>
><br>
> Yaron<br>
><br>
><br>
> 2014-04-30 12:49 GMT+03:00 James Molloy <<a href="mailto:james@jamesmolloy.co.uk">james@jamesmolloy.co.uk</a>>:<br>
><br>
>> Hi Yaron,<br>
>><br>
>> A Use is an edge between a Value and its users. If you dereference a Use,<br>
>> you get the Value it points to (which of course is your function - the thing<br>
>> that "is being used" is F). What you want is the *user* of that use, so you<br>
>> need to call U.getUser().<br>
>><br>
>> <a href="http://llvm.org/docs/doxygen/html/classllvm_1_1Use.html#details" target="_blank">http://llvm.org/docs/doxygen/html/classllvm_1_1Use.html#details</a><br>
>><br>
>> Cheers,<br>
>><br>
>> James<br>
><br>
><br>
><br>
> On 30 April 2014 10:01, Yaron Keren <<a href="mailto:yaron.keren@gmail.com">yaron.keren@gmail.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I use the code from the LLVM programmer manual<br>
>><br>
>><br>
>> <a href="http://www.llvm.org/docs/ProgrammersManual.html#iterating-over-def-use-use-def-chains" target="_blank">http://www.llvm.org/docs/ProgrammersManual.html#iterating-over-def-use-use-def-chains</a><br>
>><br>
>>   for (llvm::Value::use_iterator i = F->use_begin(), e = F->use_end(); i<br>
>> != e; ++i) {<br>
>><br>
>> to iterate over Function '_Z2tcv' uses in the trivial module<br>
>><br>
>> ; ModuleID = 'module'<br>
>> target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"<br>
>> target triple = "i686-pc-windows-gnu"<br>
>><br>
>> ; Function Attrs: nounwind<br>
>> define void @_Z2tcv() #0 {<br>
>> entry:<br>
>>   ret void<br>
>> }<br>
>><br>
>> ; Function Attrs: nounwind<br>
>> define i32 @main() #0 {<br>
>> entry:<br>
>>   call void @_Z2tcv()<br>
>>   ret i32 0<br>
>> }<br>
>><br>
>> attributes #0 = { nounwind "less-precise-fpmad"="false"<br>
>> "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"<br>
>> "no-infs-fp-math"="false" "no-nans-fp-math"="false"<br>
>> "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft<br>
>> -float"="false" }<br>
>><br>
>> !llvm.ident = !{!0}<br>
>><br>
>> !0 = metadata !{metadata !"clang version 3.5.0 (207351)"}<br>
>><br>
>> _Z2tcv has indeed one use, as expected, but the use is not a call<br>
>> instruction as in main as expected so<br>
>><br>
>>  llvm::Instruction *Inst = dyn_cast<llvm::Instruction>(*i)<br>
>><br>
>> results in NULL.<br>
>><br>
>> Examining the use value with the code<br>
>><br>
>> const llvm::Use &U = (*i);<br>
>><br>
>> indeed shows that U is same value as F, so F uses itself??<br>
>><br>
>> I have seen this in more complicated cases, the number of uses is as<br>
>> expected but the uses always point to the function or variable and not the<br>
>> real users.<br>
>><br>
>> What is wrong?<br>
>><br>
>> Thanks, Yaron<br>
>><br>
>><br>
>><br>
>> _______________________________________________<br>
>> cfe-dev mailing list<br>
>> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
><br>
</div></div></blockquote></div><br></div>