From: weiyu Date: Fri, 14 Jun 2019 22:35:11 +0000 (-0700) Subject: add source line number as a argument X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6f6588a61182c45280645a332e04666ccefd9272;hp=b8ee0fcbdf6e8d37dc8bf48da920241dd50fe503;p=c11llvm.git add source line number as a argument --- diff --git a/CDSPass.cpp b/CDSPass.cpp index 605a028..886621f 100644 --- a/CDSPass.cpp +++ b/CDSPass.cpp @@ -25,7 +25,6 @@ #include "llvm/Analysis/ValueTracking.h" #include "llvm/Analysis/CaptureTracking.h" #include "llvm/IR/BasicBlock.h" -#include "llvm/IR/CFG.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instructions.h" @@ -33,7 +32,6 @@ #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" -#include "llvm/IR/DebugLoc.h" #include "llvm/Pass.h" #include "llvm/ProfileData/InstrProf.h" #include "llvm/Support/raw_ostream.h" @@ -48,6 +46,8 @@ #define DEBUG_TYPE "CDS" using namespace llvm; +#include "getPosition.hpp" + #define FUNCARRAYSIZE 4 STATISTIC(NumInstrumentedReads, "Number of instrumented reads"); @@ -238,15 +238,6 @@ bool CDSPass::runOnFunction(Function &F) { for (auto &I : B) { if ( (&I)->isAtomic() || isAtomicCall(&I) ) { AtomicAccesses.push_back(&I); - - const llvm::DebugLoc & debug_location = I.getDebugLoc(); - std::string position_string; - { - llvm::raw_string_ostream position_stream (position_string); - debug_location . print (position_stream); - } - - errs() << I << "\n" << (position_string) << "\n\n"; } else if (isa(I) || isa(I)) { LocalLoadsAndStores.push_back(&I); } else if (isa(I) || isa(I)) { @@ -390,18 +381,20 @@ bool CDSPass::instrumentAtomic(Instruction * I, const DataLayout &DL) { return instrumentAtomicCall(CI, DL); } + Value *position = getPosition(I, IRB); + if (StoreInst *SI = dyn_cast(I)) { int atomic_order_index = getAtomicOrderIndex(SI->getOrdering()); Value *val = SI->getValueOperand(); Value *ptr = SI->getPointerOperand(); Value *order = ConstantInt::get(OrdTy, atomic_order_index); - Value *args[] = {ptr, val, order}; + Value *args[] = {ptr, val, order, position}; int size=getTypeSize(ptr->getType()); int index=sizetoindex(size); - Instruction* funcInst=CallInst::Create(CDSAtomicStore[index], args,""); + Instruction* funcInst=CallInst::Create(CDSAtomicStore[index], args); ReplaceInstWithInst(SI, funcInst); // errs() << "Store replaced\n"; } else if (LoadInst *LI = dyn_cast(I)) { @@ -409,12 +402,12 @@ bool CDSPass::instrumentAtomic(Instruction * I, const DataLayout &DL) { Value *ptr = LI->getPointerOperand(); Value *order = ConstantInt::get(OrdTy, atomic_order_index); - Value *args[] = {ptr, order}; + Value *args[] = {ptr, order, position}; int size=getTypeSize(ptr->getType()); int index=sizetoindex(size); - Instruction* funcInst=CallInst::Create(CDSAtomicLoad[index], args, ""); + Instruction* funcInst=CallInst::Create(CDSAtomicLoad[index], args); ReplaceInstWithInst(LI, funcInst); // errs() << "Load Replaced\n"; } else if (AtomicRMWInst *RMWI = dyn_cast(I)) { @@ -423,12 +416,12 @@ bool CDSPass::instrumentAtomic(Instruction * I, const DataLayout &DL) { Value *val = RMWI->getValOperand(); Value *ptr = RMWI->getPointerOperand(); Value *order = ConstantInt::get(OrdTy, atomic_order_index); - Value *args[] = {ptr, val, order}; + Value *args[] = {ptr, val, order, position}; int size = getTypeSize(ptr->getType()); int index = sizetoindex(size); - Instruction* funcInst = CallInst::Create(CDSAtomicRMW[RMWI->getOperation()][index], args, ""); + Instruction* funcInst = CallInst::Create(CDSAtomicRMW[RMWI->getOperation()][index], args); ReplaceInstWithInst(RMWI, funcInst); // errs() << RMWI->getOperationName(RMWI->getOperation()); // errs() << " replaced\n"; @@ -454,7 +447,7 @@ bool CDSPass::instrumentAtomic(Instruction * I, const DataLayout &DL) { Value *Args[] = {IRB.CreatePointerCast(Addr, PtrTy), CmpOperand, NewOperand, - order_succ, order_fail}; + order_succ, order_fail, position}; CallInst *funcInst = IRB.CreateCall(CDSAtomicCAS_V1[index], Args); Value *Success = IRB.CreateICmpEQ(funcInst, CmpOperand); @@ -475,7 +468,7 @@ bool CDSPass::instrumentAtomic(Instruction * I, const DataLayout &DL) { } else if (FenceInst *FI = dyn_cast(I)) { int atomic_order_index = getAtomicOrderIndex(FI->getOrdering()); Value *order = ConstantInt::get(OrdTy, atomic_order_index); - Value *Args[] = {order}; + Value *Args[] = {order, position}; CallInst *funcInst = CallInst::Create(CDSAtomicThreadFence, Args); ReplaceInstWithInst(FI, funcInst); diff --git a/initializeCallbacks.hpp b/initializeCallbacks.hpp index df128c0..e23fc96 100644 --- a/initializeCallbacks.hpp +++ b/initializeCallbacks.hpp @@ -36,9 +36,12 @@ void CDSPass::initializeCallbacks(Module &M) { CDSLoad[i] = M.getOrInsertFunction(LoadName, VoidTy, PtrTy); CDSStore[i] = M.getOrInsertFunction(StoreName, VoidTy, PtrTy); - CDSAtomicInit[i] = M.getOrInsertFunction(AtomicInitName, VoidTy, PtrTy, Ty); - CDSAtomicLoad[i] = M.getOrInsertFunction(AtomicLoadName, Ty, PtrTy, OrdTy); - CDSAtomicStore[i] = M.getOrInsertFunction(AtomicStoreName, VoidTy, PtrTy, Ty, OrdTy); + CDSAtomicInit[i] = M.getOrInsertFunction(AtomicInitName, + VoidTy, PtrTy, Ty, Int8PtrTy); + CDSAtomicLoad[i] = M.getOrInsertFunction(AtomicLoadName, + Ty, PtrTy, OrdTy, Int8PtrTy); + CDSAtomicStore[i] = M.getOrInsertFunction(AtomicStoreName, + VoidTy, PtrTy, Ty, OrdTy, Int8PtrTy); for (int op = AtomicRMWInst::FIRST_BINOP; op <= AtomicRMWInst::LAST_BINOP; ++op) { @@ -61,17 +64,19 @@ void CDSPass::initializeCallbacks(Module &M) { continue; SmallString<32> AtomicRMWName("cds_atomic" + NamePart + BitSizeStr); - CDSAtomicRMW[op][i] = M.getOrInsertFunction(AtomicRMWName, Ty, PtrTy, Ty, OrdTy); + CDSAtomicRMW[op][i] = M.getOrInsertFunction(AtomicRMWName, + Ty, PtrTy, Ty, OrdTy, Int8PtrTy); } // only supportes strong version SmallString<32> AtomicCASName_V1("cds_atomic_compare_exchange" + BitSizeStr + "_v1"); SmallString<32> AtomicCASName_V2("cds_atomic_compare_exchange" + BitSizeStr + "_v2"); CDSAtomicCAS_V1[i] = M.getOrInsertFunction(AtomicCASName_V1, - Ty, PtrTy, Ty, Ty, OrdTy, OrdTy); + Ty, PtrTy, Ty, Ty, OrdTy, OrdTy, Int8PtrTy); CDSAtomicCAS_V2[i] = M.getOrInsertFunction(AtomicCASName_V2, - Int1Ty, PtrTy, PtrTy, Ty, OrdTy, OrdTy); + Int1Ty, PtrTy, PtrTy, Ty, OrdTy, OrdTy, Int8PtrTy); } - CDSAtomicThreadFence = M.getOrInsertFunction("cds_atomic_thread_fence", VoidTy, OrdTy); + CDSAtomicThreadFence = M.getOrInsertFunction("cds_atomic_thread_fence", + VoidTy, OrdTy, Int8PtrTy); } \ No newline at end of file diff --git a/instrumentAtomicCall.hpp b/instrumentAtomicCall.hpp index 0c96df8..9052013 100644 --- a/instrumentAtomicCall.hpp +++ b/instrumentAtomicCall.hpp @@ -1,7 +1,3 @@ -bool containsStr() { - -} - bool CDSPass::instrumentAtomicCall(CallInst *CI, const DataLayout &DL) { IRBuilder<> IRB(CI); Function *fun = CI->getCalledFunction(); @@ -15,6 +11,9 @@ bool CDSPass::instrumentAtomicCall(CallInst *CI, const DataLayout &DL) { parameters.push_back(param); } + // obtain source line number of the CallInst + Value *position = getPosition(CI, IRB); + // the pointer to the address is always the first argument Value *OrigPtr = parameters[0]; int Idx = getMemoryAccessFuncIndex(OrigPtr, DL); @@ -30,9 +29,9 @@ bool CDSPass::instrumentAtomicCall(CallInst *CI, const DataLayout &DL) { if (funName.contains("atomic_init")) { Value *ptr = IRB.CreatePointerCast(OrigPtr, PtrTy); Value *val = IRB.CreateBitOrPointerCast(parameters[1], Ty); - Value *args[] = {ptr, val}; + Value *args[] = {ptr, val, position}; - Instruction* funcInst=CallInst::Create(CDSAtomicInit[Idx], args,""); + Instruction* funcInst=CallInst::Create(CDSAtomicInit[Idx], args); ReplaceInstWithInst(CI, funcInst); return true; @@ -49,9 +48,9 @@ bool CDSPass::instrumentAtomicCall(CallInst *CI, const DataLayout &DL) { else order = ConstantInt::get(OrdTy, (int) AtomicOrderingCABI::seq_cst); - Value *args[] = {ptr, order}; + Value *args[] = {ptr, order, position}; - Instruction* funcInst=CallInst::Create(CDSAtomicLoad[Idx], args,""); + Instruction* funcInst=CallInst::Create(CDSAtomicLoad[Idx], args); ReplaceInstWithInst(CI, funcInst); return true; @@ -70,9 +69,9 @@ bool CDSPass::instrumentAtomicCall(CallInst *CI, const DataLayout &DL) { else order = ConstantInt::get(OrdTy, (int) AtomicOrderingCABI::seq_cst); - Value *args[] = {ptr, val, order}; + Value *args[] = {ptr, val, order, position}; - Instruction* funcInst=CallInst::Create(CDSAtomicStore[Idx], args,""); + Instruction* funcInst=CallInst::Create(CDSAtomicStore[Idx], args); ReplaceInstWithInst(CI, funcInst); return true; @@ -110,9 +109,9 @@ bool CDSPass::instrumentAtomicCall(CallInst *CI, const DataLayout &DL) { else order = ConstantInt::get(OrdTy, (int) AtomicOrderingCABI::seq_cst); - Value *args[] = {ptr, val, order}; + Value *args[] = {ptr, val, order, position}; - Instruction* funcInst=CallInst::Create(CDSAtomicRMW[op][Idx], args,""); + Instruction* funcInst=CallInst::Create(CDSAtomicRMW[op][Idx], args); ReplaceInstWithInst(CI, funcInst); return true; @@ -140,9 +139,9 @@ bool CDSPass::instrumentAtomicCall(CallInst *CI, const DataLayout &DL) { } Value *args[] = {Addr, CmpOperand, NewOperand, - order_succ, order_fail}; + order_succ, order_fail, position}; - Instruction* funcInst=CallInst::Create(CDSAtomicCAS_V2[Idx], args,""); + Instruction* funcInst=CallInst::Create(CDSAtomicCAS_V2[Idx], args); ReplaceInstWithInst(CI, funcInst); return true; diff --git a/isAtomicCall.hpp b/isAtomicCall.hpp index 419312c..11e5e68 100644 --- a/isAtomicCall.hpp +++ b/isAtomicCall.hpp @@ -10,7 +10,7 @@ bool isAtomicCall(Instruction *I) if ( (CI->isTailCall() && funName.contains("atomic_")) || funName.contains("atomic_compare_exchange_") ) { - printArgs(CI); + // printArgs(CI); return true; } } @@ -26,7 +26,7 @@ void printArgs (CallInst *CI) User::op_iterator begin = CI->arg_begin(); User::op_iterator end = CI->arg_end(); - if (funName.find("atomic_") != -1) { + if ( funName.contains("atomic_") ) { std::vector parameters; for (User::op_iterator it = begin; it != end; ++it) {