[LLVMdev] How to const char* Value for function argument
Dmitry N. Mikushin
maemarcus at gmail.com
Thu Sep 22 03:05:39 PDT 2011
Hi,
I'm trying to replace function call with call to
wrapper(function_name, num_args, ...), where varargs hold args of
original call.
Function* launch = Function::Create(
TypeBuilder<int(const char*, int, ...), false>::get(context),
GlobalValue::ExternalLinkage, "kernelgen_launch_", m2);
{
CallInst* call = dyn_cast<CallInst>(cast<Value>(I));
if (!call) continue;
Function* callee = call->getCalledFunction();
if (!callee && !callee->isDeclaration()) continue;
if (callee->getName() != func2.getName()) continue;
SmallVector<Value*, 16> callargs(call->op_begin(), call->op_end());
callargs.insert(callargs.begin(),
ConstantInt::get(Type::getInt32Ty(context),
call->getNumArgOperands()));
callargs.insert(callargs.begin(), callee->getName());
CallInst* newcall = CallInst::Create(launch, callargs, "", call);
newcall->takeName(call);
newcall->setCallingConv(call->getCallingConv());
newcall->setAttributes(call->getAttributes());
newcall->setDebugLoc(call->getDebugLoc());
call->replaceAllUsesWith(newcall);
found = true;
break;
}
The line callargs.insert(callargs.begin(), callee->getName()); is
invalid: instead of StringRef I need to supply a Value* for the second
argument. How to construct value for const char* ?
Thanks,
- D.
More information about the llvm-dev
mailing list