【发布时间】:2012-04-04 05:29:58
【问题描述】:
我想用对 cumemhostalloc 函数的调用替换对 malloc 的调用。
float *h_A=(float *)malloc(size);
should be replaced with
cuMemHostAlloc((void **)&h_A,size,2);
我为此使用以下代码,
*if (dyn_cast<CallInst> (j))
{
Ip=cast<Instruction>(j);
CastInst* ci_hp = new BitCastInst(ptr_h_A, PointerTy_23, "" );
BB->getInstList().insert(Ip,ci_hp);
errs()<<"\n Cast instruction is inserted"<<*ci_hp;
li_size = new LoadInst(al_size, "", false);
li_size->setAlignment(4);
BB->getInstList().insert(Ip,li_size);
errs()<<"\n Load instruction is inserted"<<*li_size;
ConstantInt* const_int32_34 = ConstantInt::get(M->getContext(), APInt(32, StringRef("2"), 10));
std::vector<Value*> cumemhaparams;
cumemhaparams.push_back(ci_hp);
cumemhaparams.push_back(li_size);
cumemhaparams.push_back(const_int32_34);
CallInst* cumemha = CallInst::Create(func_cuMemHostAlloc, cumemhaparams, "");
cumemha->setCallingConv(CallingConv::C);
cumemha->setTailCall(false);
AttrListPtr cumemha_PAL;
cumemha->setAttributes(cumemha_PAL);
ReplaceInstWithInst(callinst->getParent()->getInstList(), j,cumemha);*
}
但我收到以下错误, /home/project/llvmfin/llvm-3.0.src/lib/VMCore/Value.cpp:287: void llvm::Value::replaceAllUsesWith(llvm::Value*): 断言`New->getType() == getType () && "replaceAllUses of value with new value of different type!"' 失败。 是不是因为对 malloc 的调用被替换为具有不同签名的函数?
【问题讨论】:
-
您能详细说明您的评论吗?如何用负载代替呼叫?是否可以先插入对 cumemhostalloc 的调用,用 cumemhostalloc 替换所有 malloc 的使用,然后删除对 malloc 的调用?我应该使用什么说明?
标签: llvm