Thank you very much for you help, Renato!
I read through paper you referred and also this document -
http://llvm.org/docs/tutorial/JITTutorial1.html
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();
Cheers,
Oleg.
2009/11/5 Renato Golin <rengolin at
systemcall.org>:> 2009/11/5 Oleg Knut <oleg77 at gmail.com>:
>> 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);
>
> Hi Oleg,
>
> 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:
>
>
http://www.systemcall.org/rengolin/stuff/compiler/download/LLVM-pet-project.pdf
>
> cheers,
> --renato
>
> Reclaim your digital rights, eliminate DRM, learn more at
> http://www.defectivebydesign.org/what_is_drm
>
2009/11/5 Oleg Knut <oleg77 at gmail.com>:> So, I believe this is just outdated information? I think it just need > some quick attention with getting materials up to date.Yup, outdated information. If you see the same example on the svn tree (examples/Kaleidoscope) the code is right and up-to-date.> In the end I got following code, that satisfy my needs:Return void an a dummy basic block, all you needed. ;) Glad to help. cheers, --renato Reclaim your digital rights, eliminate DRM, learn more at http://www.defectivebydesign.org/what_is_drm
What exactly is M in that code you posted? Oleg Knut wrote:> > Thank you very much for you help, Renato! > > I read through paper you referred and also this document - > http://llvm.org/docs/tutorial/JITTutorial1.html > > 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(); > > Cheers, > Oleg. > > 2009/11/5 Renato Golin <rengolin at systemcall.org>: >> 2009/11/5 Oleg Knut <oleg77 at gmail.com>: >>> 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); >> >> Hi Oleg, >> >> 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: >> >> http://www.systemcall.org/rengolin/stuff/compiler/download/LLVM-pet-project.pdf >> >> cheers, >> --renato >> >> Reclaim your digital rights, eliminate DRM, learn more at >> http://www.defectivebydesign.org/what_is_drm >> > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-- View this message in context: http://old.nabble.com/create-dummy-function-tp26212354p26362436.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
M is llvm::Module instance. Cheers, Oleg. 2009/11/15 blah32 <blah32 at live.com>:> > What exactly is M in that code you posted? > > > > Oleg Knut wrote: >> >> Thank you very much for you help, Renato! >> >> I read through paper you referred and also this document - >> http://llvm.org/docs/tutorial/JITTutorial1.html >> >> 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(); >> >> Cheers, >> Oleg. >> >> 2009/11/5 Renato Golin <rengolin at systemcall.org>: >>> 2009/11/5 Oleg Knut <oleg77 at gmail.com>: >>>> 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); >>> >>> Hi Oleg, >>> >>> 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: >>> >>> http://www.systemcall.org/rengolin/stuff/compiler/download/LLVM-pet-project.pdf >>> >>> cheers, >>> --renato >>> >>> Reclaim your digital rights, eliminate DRM, learn more at >>> http://www.defectivebydesign.org/what_is_drm >>> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> > > -- > View this message in context: http://old.nabble.com/create-dummy-function-tp26212354p26362436.html > Sent from the LLVM - Dev mailing list archive at Nabble.com. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >