<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 class="gmail_signature">Zhoulai</div></div>
<br><div class="gmail_quote">On Mon, Jun 8, 2015 at 1:21 AM, Bruce Hoult <span dir="ltr"><<a href="mailto: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 class=""><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 class=""><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 class="h5">On Sun, Jun 7, 2015 at 8:24 PM, Zhoulai <span dir="ltr"><<a href="mailto: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 class="h5"><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">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="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></blockquote></div><br></div>
</blockquote></div><br></div>