1

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

1
  • 1
    Show your attempted code. Commented May 6, 2016 at 22:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.