[LLVMdev] Loop Unfolding in LLVM

Bruce Hoult bruce at hoult.org
Mon Jun 8 08:15:02 PDT 2015


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.

On Monday, June 8, 2015, Zhoulai <zell08v at gmail.com> wrote:

> Thanks Bruce. I agree your way to unfold can be shown more interesting.
>
> My question was *how to do this kind of unfolding in LLVM *? 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.
>
> Thanks.
>
>
> Zhoulai
>
> On Mon, Jun 8, 2015 at 1:21 AM, Bruce Hoult <bruce at hoult.org
> <javascript:_e(%7B%7D,'cvml','bruce at hoult.org');>> wrote:
>
>> 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
>> <javascript:_e(%7B%7D,'cvml','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:   *MailScanner has detected a possible
>>> fraud attempt from "urldefense.proofpoint.com" claiming to be*
>>> 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
>>> <javascript:_e(%7B%7D,'cvml','LLVMdev at cs.uiuc.edu');>
>>> http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>>
>>>
>>
>
> --
> This message has been scanned for viruses and
> dangerous content by *MailScanner* <http://www.mailscanner.info/>, and is
> believed to be clean.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150608/58397c19/attachment.html>


More information about the llvm-dev mailing list