void PandaInstrumentVisitor::visitMemSetInst(MemSetInst &I){ Function *F = mod->getFunction("log_dynval"); if (!F) { printf("Instrumentation function not found\n"); assert(1==0); } int bytes = 0; Value *length = I.getLength(); if (ConstantInt* CI = dyn_cast<ConstantInt>(length)) { if (CI->getBitWidth() <= 64) { bytes = CI->getSExtValue(); } } if (bytes > 100) { //This mostly happens in cpu state reset printf("Note: dyn log ignoring memset greater than 100 bytes\n"); return; } PtrToIntInst *PTII; CallInst *CI; std::vector<Value*> argValues; PTII = static_cast<PtrToIntInst*>(IRB.CreatePtrToInt( I.getOperand(0), wordType)); argValues.push_back(ConstantInt::get(ptrType, (uintptr_t)dynval_buffer)); argValues.push_back(ConstantInt::get(intType, ADDRENTRY)); argValues.push_back(ConstantInt::get(intType, STORE)); argValues.push_back(static_cast<Value*>(PTII)); CI = IRB.CreateCall(F, ArrayRef<Value*>(argValues)); CI->insertBefore(static_cast<Instruction*>(&I)); PTII->insertBefore(static_cast<Instruction*>(CI)); }
void PropagateJuliaAddrspaces::visitMemSetInst(MemSetInst &MI) { unsigned AS = MI.getDestAddressSpace(); if (!isSpecialAS(AS)) return; Value *Replacement = LiftPointer(MI.getRawDest()); if (!Replacement) return; Value *TheFn = Intrinsic::getDeclaration(MI.getModule(), Intrinsic::memset, {Replacement->getType(), MI.getOperand(1)->getType()}); MI.setCalledFunction(TheFn); MI.setArgOperand(0, Replacement); }