Chethan Ravindranath
Chethan Ravindranath

Reputation: 2061

Creating a call instruction using the IRBuilder to have variable number of arguments - llvm 2.8

I am trying to create a Call Instruction using the llvm IRBuilder as below

llvm::Value* FunctionCall::genLLVM(GenLLVM* g){
    std::vector<llvm::Value*> paramArrayRef;
    std::list<Value*> paramList = getParamList();
    std::list<Value*>::iterator paramIter = paramList.begin();
    unsigned int i = 0;
    for(; paramIter != paramList.end(); ++paramIter, ++i)
        paramArrayRef.push_back((*paramIter)->genLLVM(g));

    llvm::FunctionType *FT = &getFunctionType(getFunction());
    llvm::Function *F = static_cast<llvm::Function*>(g->getModule().getOrInsertFunction(getFunction().getName(), FT));

    return g->getBuilder().CreateCall(F, paramArrayRef,"");
}

./genllvm.cpp:67: error: no matching function for call to ‘llvm::IRBuilder<true, llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true> >::CreateCall(llvm::Function*&, std::vector<llvm::Value*, std::allocator<llvm::Value*> >&, const char [1])’
/usr/include/llvm/Support/IRBuilder.h:891: note: candidates are: llvm::CallInst* llvm::IRBuilder<preserveNames, T, Inserter>::CreateCall(llvm::Value*, const llvm::Twine&) [with bool preserveNames = true, T = llvm::ConstantFolder, Inserter = llvm::IRBuilderDefaultInserter<true>]
/usr/include/llvm/Support/IRBuilder.h:894: note:                 llvm::CallInst* llvm::IRBuilder<preserveNames, T, Inserter>::CreateCall(llvm::Value*, llvm::Value*, const llvm::Twine&) [with bool preserveNames = true, T = llvm::ConstantFolder, Inserter = llvm::IRBuilderDefaultInserter<true>]

I went throught the IRBuilder.h file but couldn't find any function that can take variable arguments. Is there a function that creates a function call with variable number of arguments. Btw, I am using llvm 2.8

Upvotes: 1

Views: 4087

Answers (1)

Anton Korobeynikov
Anton Korobeynikov

Reputation: 9324

I do not remember the situation in 2.8 (it's pretty ancient by now), but currently there are a bunch of methods to create calls with different number of arguments, e.g. CreateCall{2,3,4,5} and generic CreateCall which accepts arbitrary number of args. See e.g. http://llvm.org/doxygen/classllvm_1_1IRBuilder.html#a7e31b0c02df2aeed261b103b790cc01e

If there is no such API functions in 2.8, then you either need to update to more recent version of LLVM, or insert the call by hands, that is via CallInst::Create() and after this - IRBuilder::Insert() calls.

Upvotes: 1

Related Questions