[LLVMdev] Loop Unfolding in LLVM
Zhoulai
zell08v at gmail.com
Mon Jun 8 08:10:31 PDT 2015
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> 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> 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/e662474d/attachment.html>
More information about the llvm-dev
mailing list