Unfortunately I didn't have the answer to your question. There is unrolling, but it's normally for loops where you know in advance how many interactions there will be, so you don't need tests between the copies of the body.<br><br>On Monday, June 8, 2015, Zhoulai <<a href="mailto:zell08v@gmail.com">zell08v@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks Bruce. I agree your way to unfold can be shown more interesting. <br><br>My question was <b>how to do this kind of unfolding in LLVM </b>? Because such program transformation is standard in compiler textbooks, one may expect it is already implemented in LLVM, so we do not need to do this by ourselves (such as, detecting the loop head, inserting conditional statement, copying basic blocks, etc, which can be tedious). As mentioned earlier, I would like to unfold the loops at the IR level, although the source code was being used as illustration. <br><br>Thanks. <br><br></div><div class="gmail_extra"><br clear="all"><div><div>Zhoulai</div></div>
<br><div class="gmail_quote">On Mon, Jun 8, 2015 at 1:21 AM, Bruce Hoult <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','bruce@hoult.org');" target="_blank">bruce@hoult.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">What is the use-case that makes this better than the following?<div><br></div><div><div>WHILE (condition) DO</div><span><div> action</div><div> IF (condition) THEN</div><div> action</div></span><div> IF (condition) THEN</div><div> action</div><div> ENDIF</div><div> ENDIF</div><div>ENDWHILE</div></div><div><br></div><div><br></div><div>If your loop normally gets executed a lot of times, then even this should be better, with one fewer duplication of "action"?</div><div><br></div><div><div>WHILE (condition) DO</div><span><div> action</div><div> IF (condition) THEN</div><div> action</div></span><div> ENDIF<br></div><div>ENDWHILE</div></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Sun, Jun 7, 2015 at 8:24 PM, Zhoulai <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','zell08v@gmail.com');" target="_blank">zell08v@gmail.com</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><div dir="ltr"><div><div><div>Hello, <br><br></div>I am looking for a loop unfolding procedure implemented in LLVM that helps to transform a while-loop to n-layer If-statements. The transformation should be on IR, although the example below is illustrated on the source level. <br><br></div>original loop:<br><pre><i> WHILE (condition) DO
action
ENDWHILE</i><br><br></pre><pre>Expected unfolded loop (2-layer):<br><i><br> IF (condition) THEN<br></i></pre><pre><i> action<br></i></pre><pre><i> IF (condition) THEN<br></i></pre><pre><i> action<br></i></pre><pre><i> WHILE (condition) DO
action
ENDWHILE
</i></pre><i> ENDIF<br></i></div><i> ENDIF</i><br clear="all"><div><div><div><div><div><div><div><br><br></div><div>(I thought such transformation is somewhat standard but do not find it the related API of LLVM:loop: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_classllvm-5F1-5F1Loop.html&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=yM0Vi5USSIlDTpHDzlYOLQJuCxxBQnb1HDijbKLUPIA&s=kcfE20E9Tv_peJ2EC7XSVgW0btFfF-joP8HfqPyWes4&e=" target="_blank"><font color="red"><b>MailScanner has detected a possible fraud attempt from "urldefense.proofpoint.com" claiming to be</b></font> http://llvm.org/docs/doxygen/html/classllvm_1_1Loop.html</a>)<br><br>Thanks for your help.<br><br></div><div>Sincerely,<br clear="all"></div><div><div><div>Zhoulai</div></div>
</div>
</div></div></div></div></div></div></div>
<br></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="javascript:_e(%7B%7D,'cvml','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></blockquote></div><br></div>
</blockquote></div><br></div>
<br>--
<br>This message has been scanned for viruses and
<br>dangerous content by
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.mailscanner.info_&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=guB1y0EGBN2zsX-F4zzpmWotYq0JFlkCphvQWfxbHCY&s=DGUV6hsKB01aevoejb2qPS3_s8U64U-4YzDIcW8mm5U&e=" target="_blank"><b>MailScanner</b></a>, and is
<br>believed to be clean.
</blockquote>