Function permutation at IR bytecode level

Hi All,

I am working on writing pass in LLVM and interested in doing function permutation at intermediate representation byte code level?

If I have lets say C program having three functions and its corresponding IR bytecode.

void findLen(char a[10])
{
int tmp = strlen(a);
printf(“Len is : %d\n”, tmp);
}

void muladd(int a, int b, int c)
{
int tmp = a + b;
int tmp1 = tmp * c;
printf(“Addition is : %d Multiplication is : %d\n”, tmp, tmp1);
char d[10] = “abhd”;
findLen(d);
}
void main()
{
int x = 8, y = 5, z = 3;
muladd(x, y, z);
}

In its corresponding .s [IR bytecode] file function sequence will be same first findLen() then muladd() and then main().
Suppose I want to change this sequence i.e. swap findLen() and muladd() function’s positions. I am expecting to have IR bytecode of first muladd() then findLen() and then main() in the output file.

Can you please tell me how can I achieve it ?

Thanks,
Teja

Have you tried changing the order in which the Functions are inserted into the Module? That might work if the code generator generates functions in the order in which they appear in the Module. – John T.