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?
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.