<div dir="ltr"><span style="font-size:13px">Hi Mats,</span><br style="font-size:13px"><br style="font-size:13px"><span style="font-size:13px"> so, my overall goal is to insert annotations in the original C</span><br style="font-size:13px"><span style="font-size:13px">source. I produce these annotations after analyzing the bytecode that</span><br style="font-size:13px"><span style="font-size:13px">clangs gives me for that source. Thus, I need debugging information in</span><br style="font-size:13px"><span style="font-size:13px">the bytecode file. What are these annotations? They are comments</span><br style="font-size:13px"><span style="font-size:13px">relating variables which are pointers and their sizes, as program</span><br style="font-size:13px"><span style="font-size:13px">symbols. For instance, if I have a program like this one below:</span><br style="font-size:13px"><br style="font-size:13px"><span style="font-size:13px">void foo(int *v, int N) {</span><br style="font-size:13px"><span style="font-size:13px"> int i;</span><br style="font-size:13px"><span style="font-size:13px"> for (i = 0; i < N; i++) {</span><br style="font-size:13px"><span style="font-size:13px"> v[i] = 0;</span><br style="font-size:13px"><span style="font-size:13px"> }</span><br style="font-size:13px"><span style="font-size:13px">}</span><br style="font-size:13px"><br style="font-size:13px"><span style="font-size:13px">I insert the following comment on this code:</span><br style="font-size:13px"><br style="font-size:13px"><span style="font-size:13px">void foo(int *v, int N) {</span><br style="font-size:13px"><span style="font-size:13px"> int i;</span><br style="font-size:13px"><span style="font-size:13px"> // v is accessed within the loop, and its size is [0..N-1]</span><br style="font-size:13px"><span style="font-size:13px"> for (i = 0; i < N; i++) {</span><br style="font-size:13px"><span style="font-size:13px"> v[i] = 0;</span><br style="font-size:13px"><span style="font-size:13px"> }</span><br style="font-size:13px"><span style="font-size:13px">}</span><br style="font-size:13px"><br style="font-size:13px"><span style="font-size:13px"> My prototype infers that 'v' is a pointer, and that it ranges on</span><br style="font-size:13px"><span style="font-size:13px">the region &v + 0 till &v + N - 1, where 'N' is a variable alive at</span><br style="font-size:13px"><span style="font-size:13px">the beginning of the loop. In the end, my analysis works for many</span><br style="font-size:13px"><span style="font-size:13px">kinds of programs, but I am having problems to infer that 'v' is an</span><br style="font-size:13px"><span style="font-size:13px">array with stable bounds whenever its base pointer (GetElementPtr)</span><br style="font-size:13px"><span style="font-size:13px">comes out of a load instruction which is inside the loop. That's way I</span><br style="font-size:13px"><span style="font-size:13px">would like to be able to hoist out as many loads as I can. The</span><br style="font-size:13px"><span style="font-size:13px">question then is: what is the command line that I should pass to opt</span><br style="font-size:13px"><span style="font-size:13px">that is likely to hoist loads outside loops while preserving debugging</span><br style="font-size:13px"><span style="font-size:13px">info? Mehdi's suggestion got me really close (clang -O1 -S -o - -mllvm</span><br style="font-size:13px"><span style="font-size:13px">-print-after-all), but it is removing debugging information away from</span><br style="font-size:13px"><span style="font-size:13px">the code. Without debugging information, I can't associate names at</span><br style="font-size:13px"><span style="font-size:13px">the bytecode level with names at the C-source level.</span><br style="font-size:13px"><br style="font-size:13px"><span style="font-size:13px">Regards,</span><br><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px"> Gleison</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-02-03 11:06 GMT-02:00 mats petersson <span dir="ltr"><<a href="mailto:mats@planetcatfish.com" target="_blank">mats@planetcatfish.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Just to be clear, "What are you actually trying to achieve?" was meant to ask what is your overall goal, and given that overall goal - not the transformation of the IR, but "why do you need to do this" - as a simple performance enhancement, or for some other reason?<br><br></div><div>And like has been stated, alias-analysis will help here, but some cases, the compiler will not be able to certainly say that no access from the pointer will affect something else, meaning that the compiler NEEDS to take the conservative route and reload the pointer - it doesn't seem to be a -fstrict-alias flag for clang, like that of gcc.<br></div><div><br>--<br></div>Mats<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On 3 February 2016 at 12:05, Gleison Souza via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div>Thanks Mehdi,</div><div><br></div><div>I tried to use this, but some debug information can be lost in these optimizations.</div><div>I need write in the source file to insert information before the loops, and in</div><div>some cases, I'm writing after the loop header.</div><div><br></div><div>Please, take a look:</div><div><br></div><div>int foo1 (int *a, int *b, int n) { </div><div> int i, s= 0; </div><div> for (i = 0; i < n; i++) { </div><div> s = s * a[i]; </div><div> } </div><div> </div><div> for (i = 0; i < n; i++) { </div><div> b[i] = a[i] + 3; </div><div> s += a[i]; </div><div> } </div><div> return s; </div><div>} </div><div><br></div><div>In this case, using the line obtained by this one in the LLVM's IR:</div><div><br></div><div>Line = l->getStartLoc().getLine(); </div><div><br></div><div>The source file is cloned, and I'm writing my annotations inside the loop now.</div><div>I can't do several modifications in the struct of code, just the necessary, thats the problem.</div><div><br></div><div>Regards,</div><div><br></div><div> Gleison</div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2016-02-03 1:07 GMT-02:00 Mehdi Amini <span dir="ltr"><<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span><blockquote type="cite"><div>On Feb 2, 2016, at 8:35 AM, Gleison Souza via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br><div><div dir="ltr"><div style="font-size:13px">Dear LLVMers,</div><div style="font-size:13px"><br></div><div style="font-size:13px"> I am trying to implement a particular type of loop optimization, but I am having problems with global variables. To solve this problem, I would like to know if LLVM has some pass that moves loads outside loops. I will illustrate with an example. I want to transform this code below. I am writing in C for readability, but I am analysing LLVM IR:</div><div style="font-size:13px"><br></div><div style="font-size:13px">int *vectorE;</div><div style="font-size:13px"><br></div><div style="font-size:13px">void foo (int n) { </div><div style="font-size:13px"> int i;</div><div style="font-size:13px"> for (i = 0; i < n; i++)</div><div style="font-size:13px"> vectorE[i] = i;</div><div style="font-size:13px">}</div><div style="font-size:13px"><br></div><div style="font-size:13px">into this one:</div><div style="font-size:13px"><br></div><div style="font-size:13px">int *vectorE;</div><div style="font-size:13px"><br></div><div style="font-size:13px">void foo (int n) { </div><div style="font-size:13px"> int i;</div><div style="font-size:13px"> int* aux = vectorE;</div><div style="font-size:13px"> for (i = 0; i < n; i++)</div><div style="font-size:13px"> aux[i] = i;</div><div style="font-size:13px">}</div></div></div></blockquote><div><br></div><div><br></div></span><div>Have you looked at the output of clang with optimization enabled (even O1)? For this C++ code the optimizer moves the access to the global in the loop preheader, and then the loop itself does not access the global at all, which seems to be what you’re looking for.</div><div><br></div><div>Try: clang -O1 -S -o - -mllvm -print-after-all</div><div><br></div><div>— </div><span><font color="#888888"><div>Mehdi</div><div><br></div><div><br></div></font></span></div></div></blockquote></div><br></div>
</div></div><br></div></div><span class="">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></span></blockquote></div><br></div>
</blockquote></div><br></div>