Pass-By-Reference to Pass-By-Value

Hi,

Is there any existing pass in LLVM which convert pass-by-reference to pass-by-value ?

Consider below test:
static void foo(int *P) {
int PVal = *P; // Last usage of P
// All the usage are based on PVal

}

void bar() {
int X = 0;
foo(&X);
}

In this case reference mechanism is just used to pass the value of ‘X’ in the call chain.

Instead user could have passed the value directly.

The above code can be converted to:

static void foo(int PVal) {
// All the usage are based on PVal
}

void bar() {
int X = 0;
foo(X);
}

I could not find any relevant transformation in llvm source base, probably my search is limited. if something already exist please point me.

Thanks,
Ashutosh

The argument promotion pass does this: llvm-project/ArgumentPromotion.cpp at main · llvm/llvm-project · GitHub

Thanks Nikita, i’ll check this pass.