Changing Long Int to Int using AllocaInst

Hi.
I want to change all the Long Int type variables into Int type variables. Below is my code:
for(auto &BB: F){
for(auto &I: BB){
if (AllocaInst *AI = dyn_cast(&I)) {

     if (AI->getAllocatedType()->isIntegerTy(64)) {


                	

                    LLVMContext &Context = F.getContext();

                    Type *intType = Type::getInt32Ty(Context);

		IRBuilder<> Builder(AI);

          		AllocaInst *newAI = Builder.CreateAlloca(intType, AI->getArraySize(), AI->getName());

                    // Replace all uses of the original alloca instruction with the new one

                    AI->replaceAllUsesWith(newAI);

                    // Erase the original alloca instruction



                    AI->eraseFromParent();

  
                } 

}
}
}
After doing this, in the same pass, I iterate over all the instructions and it turns out that all the alloca i64 are now alloca i32. But when I run this pass on a C file, this transformation is not reflected in the LLVM IR of the C file. For example, I declare a Long Int variable and its type remains Long Int even after applying the pass. Can anyone know what could be the issue?

Thank You,
Syed Kabir

You’ll need to elaborate on what you mean with this. You don’t run an IR transformation pass on a C file, you run it on the IR that comes out of the frontend. Nor does LLVM IR have “int” and “long int”; it has fixed-width integer types. Please be more specific and more accurate.

I generate .ll file of my C file and then run my pass on the generated .ll file. But I don’t see any difference between the generated .ll file of the C file and the .ll file generated after running the pass. Like, i64 remains i64 in the LLVM IR.

What exact command do you run to compile C to IR?

Following is to get .ll of the C file.
clang -O0 -S -emit-llvm input.c -o input.ll
And the following for running pass on LLVM IR (input.ll)
opt -load build/skeleton/libSkeletonPass.so -S <input.ll> output.ll

-O0 adds the optnone attribute to every function, which will disable running any optimisation passes on them. You’ll want to use -Xclang -disable-O0-optnone when compiling C to IR to stop that.

Still can’t see updates in output.ll:(

Aren’t you missing “- o” before output.ll to specify that it is an output?

I think your command line would result in an error saying
“opt: Too many positional arguments specified!”?

No, it doesn’t show any such error

Probably <input.ll> is being written exactly like that and acting as confusingly-formatted redirection operators.