ModuleProvider materializeFunction

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.

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.

Yep, deriving from ModuleProvider will let you lazily generate functions any way you want to.

-Chris