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!
I'm not aware of a function to clone a loop but you can extract the loop
into its own function  and clone the function . In the end you
just need a conditional to decide which function to call.
I hope this helps,
The similar transformation is done in LoopUnswitch.cpp  and it has a static CloneLoop  function too.