<div dir="ltr">Here are some specific examples:<div><br><div><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.cs.cmu.edu_afs_cs_academic_class_15745-2Df09_www_lectures_lect3-2Dllvm.pdf&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ugTksgUEW5EPfjDYDvGrQ7IbZMP1bxtkgjbHpat-EqU&s=iXIE1IaR46Q3Z-Tx2_peC2KgKU3OfEUWUjrWiRN1glk&e=">http://www.cs.cmu.edu/afs/cs/academic/class/15745-f09/www/lectures/lect3-llvm.pdf</a> - Slide 30<br></div><div><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__aviral.lab.asu.edu_-3Fp-3D1699&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ugTksgUEW5EPfjDYDvGrQ7IbZMP1bxtkgjbHpat-EqU&s=LKO4YUtKxptM51nGtePGHtWKo9qqdpWGr7qDAa6qH_Q&e=">http://aviral.lab.asu.edu/?p=1699</a> - LLVM Def-Use & Use-Def Chains.<br></div><div><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__stackoverflow.com_questions_6807743_def-2Duse-2Dchain-2Din-2Dllvm&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ugTksgUEW5EPfjDYDvGrQ7IbZMP1bxtkgjbHpat-EqU&s=W8WAFnNis5ddKZAWgscPfy_pR9NMtaOKo6Gqv9auJF8&e=">http://stackoverflow.com/questions/6807743/def-use-chain-in-llvm</a><br></div><div><a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_codelion_pa.llvm_blob_master_CVA_CVA.cpp&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ugTksgUEW5EPfjDYDvGrQ7IbZMP1bxtkgjbHpat-EqU&s=LXboSb2pBfw2rmwQA7hajKrADaRodZMpFRMN6uLAW6g&e=">https://github.com/codelion/pa.llvm/blob/master/CVA/CVA.cpp</a> - RunAnalysis starting line 234<br></div><div><a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-September/034909.html">http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-September/034909.html</a><br></div><div><a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_karrenberg_wfv_blob_master_src_functionPasses_loopLiveValueAnalysis.hpp&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ugTksgUEW5EPfjDYDvGrQ7IbZMP1bxtkgjbHpat-EqU&s=fsHc48Veoug_7asoE9ke6AsGOHnunv8Bwr1EHbiMoc4&e=">https://github.com/karrenberg/wfv/blob/master/src/functionPasses/loopLiveValueAnalysis.hpp</a> - See findUseOutsideLoop function at line 227.</div><div><br></div><div>I've seen other projects using LLVM 3.3 that have similar code.</div><div><br></div><div>Zack</div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 9, 2015 at 8:19 PM, Jonathan Roelofs <span dir="ltr"><<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
<br>
On 6/9/15 8:54 PM, Zack Waters wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks Dan and Jon. I made an incorrect assumption that the "use"<br>
iterator was actually giving me the "user" when de-referencing it.<br>
<br>
Did it always have this behavior in previous LLVM versions?<br>
</blockquote>
<br></span>
Not sure.... I don't know the history of it. Best guess is: "probably".<span class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I've seen<br>
lots of examples of the "use" iterator being dereferenced and resulting<br>
Instruction pointer being treated as the "user"?<br>
</blockquote>
<br></span>
Can you point out specific examples?<br>
<br>
<br>
Jon<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
<br>
Thanks,<br>
Zack<br>
<br>
<br>
On Tue, Jun 9, 2015 at 7:25 PM, Jonathan Roelofs<br></span><span class="">
<<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a> <mailto:<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a>>> wrote:<br>
<br>
<br>
<br>
On 6/9/15 8:02 PM, Zack Waters wrote:<br>
<br>
Hi,<br>
<br>
I'm having a problem with the use iterator. Each "use" that I<br>
see, when<br>
using the use_iterator, is the same as the "def". Meaning, in<br>
the code<br>
below the pDef is always equal to pUse pointer for every<br>
instruction in<br>
all basic blocks (except terminators).<br>
<br>
for (auto i = inst_begin(f), ie = inst_end(f); i<br>
!= ie; ++i)<br>
Instruction* pDef = &(*i);<br>
errs() << "Def: " << *pDef << "\n";<br>
<br>
for (auto ui = pDef->use_begin(), uie =<br>
pDef->use_end(); ui != uie; ++ui)<br>
{<br>
<br>
<br>
'user' != 'use'.<br>
<br>
Think of llvm::Use as the edge between the place where a value is<br>
produced, and the place where that value is consumed. The consumer<br>
is the 'User', and the Use points at it.<br>
<br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_classllvm-5F1-5F1Use.html&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ugTksgUEW5EPfjDYDvGrQ7IbZMP1bxtkgjbHpat-EqU&s=x4E_uVlu5vbZTEYYyqwTCZR8bsp1hA_DeO4M2Z6bWsk&e=" target="_blank">http://llvm.org/docs/doxygen/html/classllvm_1_1Use.html</a><br></span>
<<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_classllvm-5F1-5F1Use.html&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=P9nO53gRzaeWOd6JcPss24m-SNOOVI-ki0Gmt8jG2a4&s=vHntZspdmEIervA_wRJRemP18BYspEqdQnW_J99QC28&e=" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_classllvm-5F1-5F1Use.html&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=P9nO53gRzaeWOd6JcPss24m-SNOOVI-ki0Gmt8jG2a4&s=vHntZspdmEIervA_wRJRemP18BYspEqdQnW_J99QC28&e=</a>><div><div class="h5"><br>
<br>
The confusing thing that's happening below is that the llvm::Use is<br>
implicitly converted via `llvm::Use::operator Value *() const` to a<br>
`Value*`, and that `Value*` is `pDef`.<br>
<br>
<br>
HTH,<br>
<br>
Jon<br>
<br>
Instruction* pUse =<br>
dyn_cast<Instruction>(*ui);<br>
errs() << " Use: \t" << *pUse << "\n";<br>
}<br>
}<br>
<br>
However, everything works as expected when using the range-based use<br>
iterator with the following code.<br>
<br>
for (auto i = inst_begin(f), ie = inst_end(f); i<br>
!= ie; ++i)<br>
{<br>
Instruction* pDef = &(*i);<br>
errs() << "Def: " << *pDef << "\n";<br>
<br>
for (User* pUser : pDef->users())<br>
{<br>
Instruction* pUse =<br>
dyn_cast<Instruction>(pUser);<br>
errs() << " Use: \t" << *pUse << "\n";<br>
}<br>
}<br>
<br>
Also, the code is executed inside a function pass. So was initially<br>
thinking I somehow screwed up the use information in a previous<br>
pass.<br>
However, I would assume the range-based iterator would not work<br>
as well<br>
but it does.<br>
<br>
Finally, I'm currently using LLVM 3.5.1 built for Windows.<br>
Google hasn't<br>
been much help. Anybody have any suggestions as to why the first<br>
example<br>
above doesn't work?<br>
<br>
Thanks,<br>
Zack<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br></div></div>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <mailto:<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>><span class=""><br>
<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/mailman/listinfo/llvmdev</a><br>
<br>
<br>
--<br>
Jon Roelofs<br></span>
<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a> <mailto:<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a>><span class=""><br>
CodeSourcery / Mentor Embedded<br>
<br>
<br>
<br>
<br>
_______________________________________________<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/mailman/listinfo/llvmdev</a><br>
<br>
</span></blockquote><div class="HOEnZb"><div class="h5">
<br>
-- <br>
Jon Roelofs<br>
<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a><br>
CodeSourcery / Mentor Embedded<br>
</div></div></blockquote></div><br></div>