本文整理汇总了C++中llvm::Module::getOrInsertFunction方法的典型用法代码示例。如果您正苦于以下问题:C++ Module::getOrInsertFunction方法的具体用法?C++ Module::getOrInsertFunction怎么用?C++ Module::getOrInsertFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类llvm::Module
的用法示例。
在下文中一共展示了Module::getOrInsertFunction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cloneFunctions
void InstructionReplace::cloneFunctions(llvm::Module& M)
{
for(llvm::Module::iterator F = M.begin(), ME = M.end(); F != ME; ++F) {
//if(!F->getFnAttributes().hasAttribute(Attributes::AttrVal::MaskedCopy)) { continue; }
cerr << "Masking " << F->getName().str();
assert(F->arg_size() == 1);
Type* rettype = F->getReturnType();
auto args = F->arg_begin();
Argument* a1 = args++;
Type* paramtype = a1->getType();
assert(isa<IntegerType>(rettype));
assert(isa<IntegerType>(paramtype));
stringstream ss("");
ss << "__masked__" << F->getName().str();
llvm::LLVMContext& Ctx = M.getContext();
llvm::Constant* FunSym;
std::vector<Type*> paramtypes;
for(unsigned int i = 0; i <= MaskingOrder; i++) { paramtypes.push_back(paramtype); } //TODO riducibile?
for(unsigned int i = 0; i <= MaskingOrder; i++) { paramtypes.push_back(rettype->getPointerTo()); }
llvm::FunctionType* ftype = llvm::FunctionType::get(llvm::Type::getVoidTy(Ctx), llvm::ArrayRef<Type*>(paramtypes), false);
FunSym = M.getOrInsertFunction(ss.str(), ftype);
llvm::Function* newF = llvm::cast<llvm::Function>(FunSym);
maskedfn[F] = newF;
SmallVector<llvm::ReturnInst*, 4> rets;
ValueToValueMapTy vmap;
llvm::BasicBlock* Entry = llvm::BasicBlock::Create(Ctx, "entry", newF);
llvm::IRBuilder<> ib_entry = llvm::IRBuilder<>(Entry->getContext());
ib_entry.SetInsertPoint(Entry);
NoCryptoFA::InstructionMetadata* md = new NoCryptoFA::InstructionMetadata();
md->hasBeenMasked = true;
auto arg = newF->arg_begin();
for(unsigned int i = 0; i <= MaskingOrder; i++) { md->MaskedValues.push_back(arg++); }
Value* fakevalue = ib_entry.CreateAdd(md->MaskedValues[0], md->MaskedValues[1]);
md->my_instruction = cast<Instruction>(fakevalue);
NoCryptoFA::known[ md->my_instruction] = md;
deletionqueue.insert(md->my_instruction);
vmap.insert(std::make_pair(a1, fakevalue));
CloneFunctionInto(newF, F, vmap, true, rets);
ib_entry.CreateBr(cast<BasicBlock>(vmap[&F->getEntryBlock()]));
/*
AttrBuilder toremove;
//toremove.addAttribute(Attributes::AttrVal::MaskedCopy);
toremove.addAttribute(Attributes::AttrVal::ZExt);
toremove.addAttribute(Attributes::AttrVal::SExt);
toremove.addAttribute(Attributes::AttrVal::NoAlias);
toremove.addAttribute(Attributes::AttrVal::NoCapture);
toremove.addAttribute(Attributes::AttrVal::StructRet);
toremove.addAttribute(Attributes::AttrVal::ByVal);
toremove.addAttribute(Attributes::AttrVal::Nest);
newF->removeFnAttr(Attributes::get(Ctx, toremove));
newF->removeAttribute(0, Attributes::get(Ctx, toremove)); //Thr..ehm,Zero is a magic number! Toglie gli attributi zeroext e simili dal valore di ritorno.
*/
TaggedData& td = getAnalysis<TaggedData>(*F);
//td.markFunction(newF);
//setFullyMasked(newF);
}
}
示例2: runOnModule
bool DeclareAssumePass::runOnModule(llvm::Module &M){
bool modified_M = false;
CheckModule::check_assume(&M);
llvm::Function *F_assume = M.getFunction("__VERIFIER_assume");
if(!F_assume){
llvm::FunctionType *assumeTy;
{
llvm::Type *voidTy = llvm::Type::getVoidTy(M.getContext());
llvm::Type *i1Ty = llvm::Type::getInt1Ty(M.getContext());
assumeTy = llvm::FunctionType::get(voidTy,{i1Ty},false);
}
llvm::AttributeSet assumeAttrs =
llvm::AttributeSet::get(M.getContext(),llvm::AttributeSet::FunctionIndex,
std::vector<llvm::Attribute::AttrKind>({llvm::Attribute::NoUnwind}));
F_assume = llvm::dyn_cast<llvm::Function>(M.getOrInsertFunction("__VERIFIER_assume",assumeTy,assumeAttrs));
assert(F_assume);
modified_M = true;
}
return modified_M;
}
示例3: materializeValueFor
virtual llvm::Value* materializeValueFor(llvm::Value* v) {
// llvm::errs() << "materializing\n";
// v->dump();
llvm::Value* r = NULL;
if (llvm::Function* f = llvm::dyn_cast<llvm::Function>(v)) {
// llvm::errs() << "is function\n";
r = new_module->getOrInsertFunction(f->getName(), f->getFunctionType());
} else if (llvm::GlobalVariable* gv = llvm::dyn_cast<llvm::GlobalVariable>(v)) {
// llvm::errs() << " is gv\n";
assert(gv->getLinkage() != llvm::GlobalVariable::PrivateLinkage);
llvm::GlobalVariable* new_gv = llvm::cast<llvm::GlobalVariable>(
new_module->getOrInsertGlobal(gv->getName(), gv->getType()->getElementType()));
RELEASE_ASSERT(!gv->isThreadLocal(), "I don't think MCJIT supports thread-local variables yet");
new_gv->setThreadLocalMode(gv->getThreadLocalMode());
r = new_gv;
} else if (llvm::GlobalAlias* alias = llvm::dyn_cast<llvm::GlobalAlias>(v)) {
#if LLVMREV < 209040
llvm::Value* addressee = llvm::cast<llvm::Constant>(materializeValueFor(alias->getAliasedGlobal()));
#else
llvm::Value* addressee = llvm::cast<llvm::Constant>(materializeValueFor(alias->getAliasee()));
#endif
assert(addressee);
assert(alias->getType() == addressee->getType());
r = addressee;
// r = new llvm::GlobalAlias(alias->getType(), alias->getLinkage(), alias->getName(), addressee,
// new_module);
} else if (llvm::isa<llvm::Constant>(v)) {
// llvm::errs() << " is a constant\n";
r = NULL;
} else {
r = v;
}
// if (r)
// r->dump();
// llvm::errs() << "---\n";
return r;
}