<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 25, 2016, at 9:25 PM, Ammar Naqvi via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Everyone,<br class=""><br class="">I asked a question on the dev list related to the topic to which John Criswell and Jeremy Lakeman kindly provided some valuable insight.<br class=""><br class="">I'm still stuck on the issue and i'm hoping i didn't phrase the question well enough.<br class=""></div></div></blockquote><div><br class=""></div><div>Usual practice is to continue the discussion in the original thread if the question is not a new one.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><br class="">I have a <b class="">foo.c</b> file that is :<div class=""><b class=""><br class=""></b></div><div class=""><div class=""><b class="">#include <stdio.h></b></div><div class=""><b class="">int foo(int a, int b){</b></div><div class=""><b class="">  </b></div><div class=""><b class="">  return a+b;</b></div><div class=""><b class="">}</b></div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">int main() {</b></div><div class=""><b class="">int x=foo(3,1);  </b></div><div class=""><b class="">printf("%d\n",x);</b></div><div class=""><b class="">return 0;</b></div><div class=""><b class="">}</b></div></div><div class=""><b class=""><br class=""></b></div><div class="">Now, i obtain the foo.bc/foo.ll file,<br class="">the code i'm interested in looks like:<br class=""><br class=""><div class=""><b class="">; Function Attrs: norecurse nounwind readnone uwtable</b></div><div class=""><b class="">define i32 @addd(i32 %a, i32 %b) #0 {</b></div><div class=""><b class="">entry:</b></div><div class=""><b class="">  %add = add nsw i32 %b, %a</b></div><div class=""><b class="">  ret i32 %add</b></div><div class=""><b class="">}</b></div></div><div class=""><b class=""><br class=""></b></div><div class="">running the file with <b class="">lli</b> <b class="">foo.ll outputs </b></div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">4</b></div><div class=""><b class=""><br class=""></b></div><div class="">Now we know that the values of %a and %b are 3 and 1 respectively</div></div></div></blockquote><div><br class=""></div><div>I'm not sure what you mean with this sentence. lli just interpreted the file, starting in main() and executing instruction one after each other.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">, is there any way i can retrieve these values by running foo.bc through a pass??<br class=""><br class="">I know i->getOperand(0) would get me <b class="">i32 %a </b> </div><div class="">i->getOperand(1) would get me <b class="">i32 %b</b></div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">How do i retrieve 3 and 1, the integer values that these operands hold ?</b></div></div></div></blockquote><div><br class=""></div><div>3 and 1 are arguments at the *call site*, while %a and %b are the actual parameter to the function `foo()`. You need to inspect the call site (there are potentially/usually multiple call-sites) if you have a pointer to the function `foo()`.</div><div>The call sites will be amongst the user of the Function. The best is to look for example in the LLVM codebase, for instance:</div><div><br class=""></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">/// AllCallersPassInValidPointerForArgument - Return true if we can prove that</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">/// all callees pass in a valid pointer for the specified function argument.</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">static</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">bool</span><span style="font-variant-ligatures: no-common-ligatures" class=""> AllCallersPassInValidPointerForArgument(</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Argument</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *Arg) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Function</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *Callee = Arg-></span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">getParent</span><span style="font-variant-ligatures: no-common-ligatures" class="">();</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">const</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">DataLayout</span><span style="font-variant-ligatures: no-common-ligatures" class=""> &DL = Callee->getParent()->getDataLayout();</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">unsigned</span><span style="font-variant-ligatures: no-common-ligatures" class=""> ArgNo = Arg-></span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">getArgNo</span><span style="font-variant-ligatures: no-common-ligatures" class="">();</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">  </span><span style="font-variant-ligatures: no-common-ligatures" class="">// Look at all call sites of the function.  At this pointer we know we only</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">  </span><span style="font-variant-ligatures: no-common-ligatures" class="">// have direct callees.</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">for</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (User *U : Callee->users()) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    CallSite CS(U);</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(180, 38, 26);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">assert</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(CS && </span><span style="font-variant-ligatures: no-common-ligatures" class="">"Should only have direct calls!"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">);</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (!isDereferenceablePointer(CS.getArgument(ArgNo), DL))</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(4, 51, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">      </span><span style="font-variant-ligatures: no-common-ligatures" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">false</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(4, 51, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">  </span><span style="font-variant-ligatures: no-common-ligatures" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">true</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">;</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">Visible here as well: <a href="http://llvm.org/docs/doxygen/html/ArgumentPromotion_8cpp_source.html#l00344" class="">http://llvm.org/docs/doxygen/html/ArgumentPromotion_8cpp_source.html#l00344</a></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Given an Argument (in your case %a or %b), it will first get a pointer to the Function in `Callee` (for you it is foo()), and then loop over the users of the function which it expects to be of type `CallSite`.</div><div class=""><br class=""></div><div class="">-- </div><div class="">Mehdi</div><div class=""><br class=""></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><b class=""><br class=""></b></div><div class="">Thanks in advance for any guidance and help! :)<br class=""><br class="">Best Regards,<br class="">Ammar Naqvi</div></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></body></html>