loop clone?


     I want to add a branch before a loop, and clone the loop to the else part. After that, I can do instrumentation in one loop, and keep the other one uninstrumented. Does llvm have existing functionality to clone loops, or similar codes I can check?

     Thanks a lot!



Hi Linhai,

I'm not aware of a function to clone a loop but you can extract the loop
into its own function [1] and clone the function [2]. In the end you
just need a conditional to decide which function to call.

I hope this helps,

[1] http://llvm.org/docs/doxygen/html/classllvm_1_1CodeExtractor.html#a52e4200738c1e0cb57d15647de3125a0
[2] http://llvm.org/docs/doxygen/html/namespacellvm.html#a5596246c2350cb74f31ffa7695d5923c

Hi Linhai,

The similar transformation is done in LoopUnswitch.cpp [1] and it has a static CloneLoop [2] function too.

[1] http://llvm.org/docs/doxygen/html/LoopUnswitch_8cpp_source.html
[2] http://llvm.org/docs/doxygen/html/LoopUnswitch_8cpp_source.html#l00668