I have tracing the calls to materializeFunction in the LLVM code in hopes of determining how to properly utilize this function but from my explorations I gather it's just a hook which is called by the JIT system and I would mostly have to do the work myself. What is the preferred way to inject a llvm:Function which contains basic blocks into the Module + JIT? My understanding (perhaps erroneous) from some experimentation that modifying the module by inserting functions into it after you have created the EE does not automatically update the EE. Thanks in advance, Carter.
Carter Cheng wrote:> I have tracing the calls to materializeFunction in the LLVM code in hopes of determining how to properly utilize this function but from my explorations I gather it's just a hook which is called by the JIT system and I would mostly have to do the work myself. > > What is the preferred way to inject a llvm:Function which contains basic blocks into the Module + JIT? My understanding (perhaps erroneous) from some experimentation that modifying the module by inserting functions into it after you have created the EE does not automatically update the EE.You should be able to add the Function to the Module at any time, then call EE->runFunction or EE->getPointerToFunction on it. materializeFunction is used to load only part of a .bc file from disk. The functions which aren't loaded are given GhostLinkage then loaded later (materialized) when needed. Nick
Thanks for the reply. So I gather from what you are saying that if I do use materializeFunction to load a unresolved function when the JIT requests it I can do so just by using a standard Function::Create call (with the optional module argument)? Thanks again, Carter. --- On Sat, 7/4/09, Nick Lewycky <nicholas at mxc.ca> wrote:> From: Nick Lewycky <nicholas at mxc.ca> > Subject: Re: [LLVMdev] ModuleProvider materializeFunction > To: "LLVM Developers Mailing List" <llvmdev at cs.uiuc.edu> > Date: Saturday, July 4, 2009, 9:02 AM > Carter Cheng wrote: > > I have tracing the calls to materializeFunction in the > LLVM code in hopes of determining how to properly utilize > this function but from my explorations I gather it's just a > hook which is called by the JIT system and I would mostly > have to do the work myself. > > > > What is the preferred way to inject a llvm:Function > which contains basic blocks into the Module + JIT? My > understanding (perhaps erroneous) from some experimentation > that modifying the module by inserting functions into it > after you have created the EE does not automatically update > the EE. > > You should be able to add the Function to the Module at any > time, then > call EE->runFunction or EE->getPointerToFunction on > it. > > materializeFunction is used to load only part of a .bc file > from disk. > The functions which aren't loaded are given GhostLinkage > then loaded > later (materialized) when needed. > > Nick > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu > http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
On Jul 4, 2009, at 5:59 AM, Carter Cheng wrote:> I have tracing the calls to materializeFunction in the LLVM code in > hopes of determining how to properly utilize this function but from > my explorations I gather it's just a hook which is called by the JIT > system and I would mostly have to do the work myself.ModuleProvider is a very simple concept. You can either load an entire module at once (e.g. with ParseBitcodeFile) or you can load just the outline and load functions on demand (with getBitcodeModuleProvider). This allows clients to lazily load functions as they are needed instead of loading everything off the disk. The JIT is one example that knows how to use this, it lazily loads functions the first time a function is called or its address is taken.> What is the preferred way to inject a llvm:Function which contains > basic blocks into the Module + JIT? My understanding (perhaps > erroneous) from some experimentation that modifying the module by > inserting functions into it after you have created the EE does not > automatically update the EE.What kind of update of the EE do you want? -Chris
Thanks for the reply. I actually managed to resolve this problem mostly to my satisfaction. I suspect based on your description of materializeFunction I may be best served by subclassing the ModuleProvider to do what I want. Thanks again. --- On Mon, 7/6/09, Chris Lattner <clattner at apple.com> wrote:> From: Chris Lattner <clattner at apple.com> > Subject: Re: [LLVMdev] ModuleProvider materializeFunction > To: "LLVM Developers Mailing List" <llvmdev at cs.uiuc.edu> > Date: Monday, July 6, 2009, 10:27 PM > On Jul 4, 2009, at 5:59 AM, Carter > Cheng wrote: > > I have tracing the calls to materializeFunction in the > LLVM code in > > hopes of determining how to properly utilize this > function but from > > my explorations I gather it's just a hook which is > called by the JIT > > system and I would mostly have to do the work myself. > > ModuleProvider is a very simple concept. You can > either load an > entire module at once (e.g. with ParseBitcodeFile) or you > can load > just the outline and load functions on demand (with > getBitcodeModuleProvider). This allows clients to > lazily load > functions as they are needed instead of loading everything > off the > disk. The JIT is one example that knows how to use > this, it lazily > loads functions the first time a function is called or its > address is > taken. > > > What is the preferred way to inject a llvm:Function > which contains > > basic blocks into the Module + JIT? My understanding > (perhaps > > erroneous) from some experimentation that modifying > the module by > > inserting functions into it after you have created the > EE does not > > automatically update the EE. > > What kind of update of the EE do you want? > > -Chris > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu > http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >