Reputation: 133
Is there any LLVM built in method that allows making my variable volatile or const.
For example, if my program in C is,
#include<stdio.h>
int main() {
int x=1,y=2,z=10;
z=x+y;
return 0;
}
I want to change this program using LLVM pass such that it behaves as below,
#include<stdio.h>
int main() {
volatile int x=1,y=2,z=10;
z=x+y;
return 0;
}
Upvotes: 2
Views: 363
Reputation: 133
Ok, I got it. It would be simple setVolatile(1).
Pass would look something like this,
for(Module::iterator F=M.begin(),e=M.end();F!=e;++F){
for(Function::iterator B=F->begin(),e=F->end();B!=e;++B){
for(BasicBlock::iterator i=B->begin(),e=B->end();i!=e;++i){
if(isa<StoreInst>(i)){
StoreInst *temps=dyn_cast<StoreInst>(i);
temps->setVolatile(1);
}
if(isa<LoadInst>(i)){
LoadInst *temps=dyn_cast<LoadInst>(i);
temps->setVolatile(1);
}
}
}
}
Upvotes: 3