From: weiyu Date: Mon, 24 Jun 2019 19:01:52 +0000 (-0700) Subject: instrument function entries and exits X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6ecaa6a7810d93c6e682b23c7605968ec347e4ff;p=c11llvm.git instrument function entries and exits --- diff --git a/CDSPass.cpp b/CDSPass.cpp index 3cbc4bd..eef8769 100644 --- a/CDSPass.cpp +++ b/CDSPass.cpp @@ -42,6 +42,7 @@ #include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" +#include "llvm/Transforms/Utils/EscapeEnumerator.h" #include using namespace llvm; @@ -167,6 +168,8 @@ void CDSPass::initializeCallbacks(Module &M) { CDSFuncEntry = M.getOrInsertFunction("cds_func_entry", VoidTy, Int8PtrTy); + CDSFuncExit = M.getOrInsertFunction("cds_func_exit", + VoidTy, Int8PtrTy); // Get the function to call from our untime library. for (unsigned i = 0; i < kNumberOfAccessSizes; i++) { @@ -344,23 +347,21 @@ bool CDSPass::runOnFunction(Function &F) { // only instrument functions that contain atomics if (Res && HasAtomic) { - /* IRBuilder<> IRB(F.getEntryBlock().getFirstNonPHI()); Value *ReturnAddress = IRB.CreateCall( Intrinsic::getDeclaration(F.getParent(), Intrinsic::returnaddress), IRB.getInt32(0)); Value * FuncName = IRB.CreateGlobalStringPtr(F.getName()); - */ - //errs() << "function name: " << F.getName() << "\n"; - //IRB.CreateCall(CDSFuncEntry, FuncName); + + errs() << "function name: " << F.getName() << "\n"; + IRB.CreateCall(CDSFuncEntry, FuncName); -/* - EscapeEnumerator EE(F, "tsan_cleanup", ClHandleCxxExceptions); + EscapeEnumerator EE(F, "cds_cleanup", true); while (IRBuilder<> *AtExit = EE.Next()) { - AtExit->CreateCall(TsanFuncExit, {}); + AtExit->CreateCall(CDSFuncExit, FuncName); } -*/ + Res = true; } } @@ -462,10 +463,8 @@ bool CDSPass::instrumentLoadOrStore(Instruction *I, if ( ArgType != Int8PtrTy && ArgType != Int16PtrTy && ArgType != Int32PtrTy && ArgType != Int64PtrTy ) { - //errs() << "A load or store of type "; - //errs() << *ArgType; - //errs() << " is passed in\n"; - return false; // if other types of load or stores are passed in + // if other types of load or stores are passed in + return false; } IRB.CreateCall(OnAccessFunc, IRB.CreatePointerCast(Addr, Addr->getType())); if (IsWrite) NumInstrumentedWrites++; @@ -476,6 +475,8 @@ bool CDSPass::instrumentLoadOrStore(Instruction *I, bool CDSPass::instrumentAtomic(Instruction * I, const DataLayout &DL) { IRBuilder<> IRB(I); + // errs() << "instrumenting: " << *I << "\n"; + if (auto *CI = dyn_cast(I)) { return instrumentAtomicCall(CI, DL); }