X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=CDSPass.cpp;fp=CDSPass.cpp;h=ce95434a8cd145fe4ab7152c7191d93e6c8cf43c;hb=c8365119a267efb214cef5de284ada7d266706cd;hp=da2949565324a194b338015c5a1c385c7526401e;hpb=f60e865f2e548a5ab85a1003fc7fa73f3739ff94;p=c11llvm.git diff --git a/CDSPass.cpp b/CDSPass.cpp index da29495..ce95434 100644 --- a/CDSPass.cpp +++ b/CDSPass.cpp @@ -42,7 +42,6 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/EscapeEnumerator.h" -// #include "llvm/Transforms/Utils/ModuleUtils.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include @@ -601,39 +600,43 @@ bool CDSPass::instrumentLoadOrStore(Instruction *I, // As such they cannot have regular uses like an instrumentation function and // it makes no sense to track them as memory. if (Addr->isSwiftError()) - return false; + return false; int Idx = getMemoryAccessFuncIndex(Addr, DL); if (Idx < 0) return false; -// not supported by CDS yet -/* if (IsWrite && isVtableAccess(I)) { - LLVM_DEBUG(dbgs() << " VPTR : " << *I << "\n"); - Value *StoredValue = cast(I)->getValueOperand(); - // StoredValue may be a vector type if we are storing several vptrs at once. - // In this case, just take the first element of the vector since this is - // enough to find vptr races. - if (isa(StoredValue->getType())) - StoredValue = IRB.CreateExtractElement( - StoredValue, ConstantInt::get(IRB.getInt32Ty(), 0)); - if (StoredValue->getType()->isIntegerTy()) - StoredValue = IRB.CreateIntToPtr(StoredValue, IRB.getInt8PtrTy()); - // Call TsanVptrUpdate. - IRB.CreateCall(TsanVptrUpdate, - {IRB.CreatePointerCast(Addr, IRB.getInt8PtrTy()), - IRB.CreatePointerCast(StoredValue, IRB.getInt8PtrTy())}); - NumInstrumentedVtableWrites++; - return true; - } - - if (!IsWrite && isVtableAccess(I)) { - IRB.CreateCall(TsanVptrLoad, - IRB.CreatePointerCast(Addr, IRB.getInt8PtrTy())); - NumInstrumentedVtableReads++; - return true; - } -*/ + if (IsWrite && isVtableAccess(I)) { + /* TODO + LLVM_DEBUG(dbgs() << " VPTR : " << *I << "\n"); + Value *StoredValue = cast(I)->getValueOperand(); + // StoredValue may be a vector type if we are storing several vptrs at once. + // In this case, just take the first element of the vector since this is + // enough to find vptr races. + if (isa(StoredValue->getType())) + StoredValue = IRB.CreateExtractElement( + StoredValue, ConstantInt::get(IRB.getInt32Ty(), 0)); + if (StoredValue->getType()->isIntegerTy()) + StoredValue = IRB.CreateIntToPtr(StoredValue, IRB.getInt8PtrTy()); + // Call TsanVptrUpdate. + IRB.CreateCall(TsanVptrUpdate, + {IRB.CreatePointerCast(Addr, IRB.getInt8PtrTy()), + IRB.CreatePointerCast(StoredValue, IRB.getInt8PtrTy())}); + NumInstrumentedVtableWrites++; + */ + return true; + } + + if (!IsWrite && isVtableAccess(I)) { + /* TODO + IRB.CreateCall(TsanVptrLoad, + IRB.CreatePointerCast(Addr, IRB.getInt8PtrTy())); + NumInstrumentedVtableReads++; + */ + return true; + } + + // TODO: unaligned reads and writes Value *OnAccessFunc = nullptr; OnAccessFunc = IsWrite ? CDSStore[Idx] : CDSLoad[Idx]; @@ -930,7 +933,7 @@ bool CDSPass::instrumentAtomicCall(CallInst *CI, const DataLayout &DL) { return true; } else if (funName.contains("atomic") && funName.contains("store") ) { - // does this version of call always have an atomic order as an argument? + // Does this version of call always have an atomic order as an argument? Value *OrigVal = parameters[1]; Value *ptr = IRB.CreatePointerCast(OrigPtr, PtrTy); @@ -1005,7 +1008,13 @@ bool CDSPass::instrumentAtomicCall(CallInst *CI, const DataLayout &DL) { } else if (funName.contains("exchange") && !funName.contains("compare_exchange") ) { if (CI->getType()->isPointerTy()) { - // Can not deal with this now + /** + * TODO: instrument the following case + * mcs-lock.h + * std::atomic m_tail; + * struct T * me; + * struct T * pred = m_tail.exchange(me, memory_order_*); + */ errs() << "atomic exchange captured. Not implemented yet. "; errs() << "See source file :"; getPosition(CI, IRB, true); @@ -1025,9 +1034,11 @@ bool CDSPass::instrumentAtomicCall(CallInst *CI, const DataLayout &DL) { Value *order = IRB.CreateBitOrPointerCast(parameters[2], OrdTy); Value *args[] = {ptr, val, order, position}; int op = AtomicRMWInst::Xchg; - + Instruction* funcInst = CallInst::Create(CDSAtomicRMW[op][Idx], args); ReplaceInstWithInst(CI, funcInst); + + return true; } /* atomic_compare_exchange_*;