I am doing a project on LLVM.
I'm trying to make a pass:
For a function, if the arguments(parameters) are constants, it will make a new function that the constants are converted to a local variable, and deleted from arguments.
For example:
void main(){
c=foo(a,b);
d=foo(a,100);
}
double foo(x,y){return x+y;}
will get optimized into:
void main(){
c=foo(a,b);
d=foo1(a);
}
double foo(x,y){return x+y;}
double foo1(x){
int y=100;
return x+y;
}
To do this, I'm trying to make a new local variable
and then using replaceAllUsesWith
function.
But I can't seem to allocate a new local variable.
I did try defining new Value*
but when I assign it to the argument,
it becomes same pointer as the argument, which makes replaceAllUsesWith
function useless.
Is there a way to allocate (in the memory) a new local variable in type of Value*
?