Hello,
I have a simple question. How to create "dummy" function which will
have no functionality behind (return nothing and do nothing)?
Currently I'm trying to do this:
llvm::Constant* c = Module.getOrInsertFunction("dummy",
FunctionThatNeedsToBeReplaced.getFunctionType());
llvm::Function* dummy = llvm::cast<llvm::Function>(c);
This way I create new function that do nothing.Then next step is:
Every function needs a BasicBlock, even if the basic block just
contains a return.
The only reason to create a function without a basic block is when the
function is extern'd and imported via JIT, but I guess it's not what
you're attempting.
Try this presentation and let me know if it's helpful:
Following these instructions to create successful function I run into
some problems:
1) llvm::getGlobalContext() does not exists anymore? "llvm/LLVMContext.h" too?
2) creating instance of IRBuilder don't require template (from
tutorial paper - IRBuilder<> builder(block))
So, I believe this is just outdated information? I think it just need
some quick attention with getting materials up to date.
In the end I got following code, that satisfy my needs:
llvm::Constant* c = M.getOrInsertFunction(dummyFunctionName,
F.getFunctionType());
llvm::Function* dummy = llvm::cast<llvm::Function>(c);
dummy->setLinkage(llvm::Function::ExternalLinkage);
dummy->setCallingConv(llvm::CallingConv::C);
llvm::BasicBlock* block = llvm::BasicBlock::Create("entry", dummy);
// no context needed
llvm::IRBuilder builder(block); // no need in <>
builder.CreateRetVoid();