I want to write a pass for adding a function call in for loop.
Let's assume the original source code is below.
for (int i=0; i<10; ++i)
{
printf("%d\n", i);
}
I want to make pass like changing the upper source code to below. (Not mean that changing the source code, but IR code in real.)
for (int i=0; i<10; ++i)
{
EXTERNALFUNC(i); // function call for external function
// and args is induction variable.
printf("%d\n", i);
}
I know about usage of getOrInsertFunction method but have no idea about
- finding the loop & induction variables,
- put the function call inside of function,
- if there is many loop, put function calls in all loops.