[LLVMdev] Loop Unfolding in LLVM

Bruce Hoult bruce at hoult.org
Mon Jun 8 01:21:03 PDT 2015


What is the use-case that makes this better than the following?

WHILE (condition) DO
          action
          IF (condition) THEN
               action
               IF (condition) THEN
                    action
               ENDIF
          ENDIF
ENDWHILE


If your loop normally gets executed a lot of times, then even this should
be better, with one fewer duplication of "action"?

WHILE (condition) DO
          action
          IF (condition) THEN
               action
          ENDIF
ENDWHILE



On Sun, Jun 7, 2015 at 8:24 PM, Zhoulai <zell08v at gmail.com> wrote:

> Hello,
>
> 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.
>
> original loop:
>
> * WHILE (condition) DO
>          action
>  ENDWHILE*
>
> Expected unfolded loop (2-layer):
>
>
> * IF (condition) THEN*
>
>
> *          action*
>
>
> *          IF (condition) THEN*
>
>
> *               action*
>
> *               WHILE (condition) DO
>                     action
>                ENDWHILE
> *
>
>
> *                      ENDIF*
> *  ENDIF*
>
>
> (I thought such transformation is somewhat standard but do not find it the
> related API of LLVM:loop:
> http://llvm.org/docs/doxygen/html/classllvm_1_1Loop.html
> <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=>
> )
>
> Thanks for your help.
>
> Sincerely,
> Zhoulai
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150608/01837def/attachment.html>


More information about the llvm-dev mailing list