+bool CDSPass::instrumentVolatile(Instruction * I, const DataLayout &DL) {
+ IRBuilder<> IRB(I);
+ Value *position = getPosition(I, IRB);
+
+ if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
+ assert( LI->isVolatile() );
+ Value *Addr = LI->getPointerOperand();
+ int Idx=getMemoryAccessFuncIndex(Addr, DL);
+ if (Idx < 0)
+ return false;
+
+ Value *args[] = {Addr, position};
+ Instruction* funcInst=CallInst::Create(CDSVolatileLoad[Idx], args);
+ ReplaceInstWithInst(LI, funcInst);
+ } else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
+ assert( SI->isVolatile() );
+ Value *Addr = SI->getPointerOperand();
+ int Idx=getMemoryAccessFuncIndex(Addr, DL);
+ if (Idx < 0)
+ return false;
+
+ Value *val = SI->getValueOperand();
+ Value *args[] = {Addr, val, position};
+ Instruction* funcInst=CallInst::Create(CDSVolatileStore[Idx], args);
+ ReplaceInstWithInst(SI, funcInst);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+