Dibyendu Majumdar
2015-Feb-10 21:57 UTC
[LLVMdev] Some basic questions regarding MCJIT and Kaleidoscope sample
Hi, I am building a new JIT compiler for Lua (actually a derivative of Lua), and am planning to use LLVM for this. I have trying out some basic functions using LLVM 3.5.1. I have been puzzled by one aspect of the MCJIT versions of the Kaleidoscope sample, and would hugely appreciate some insight. Can a single MCJIT instance be used to manage several modules? Why is a separate MCJIT instance created for each module? Unfortunately the tutorial text does not explain the rationale for this. At the moment in my implementation I am putting each compiled function in its own module and creating an engine for it. This is so that each function can be managed independently and linked to garbage collection in Lua. However I do not know if there is a better way - for example creating a shared engine across all modules. I would also like to understand the trade offs with this approach versus other approaches. Many thanks Regards Dibyendu
David Blaikie
2015-Feb-10 22:14 UTC
[LLVMdev] Some basic questions regarding MCJIT and Kaleidoscope sample
We (and by 'we' I mean 'Lang' (cc'd)) have recently been experimenting with improvements/replacements to the MCJIT in the form of Orc, a new layered, composable JIT API. There are examples of this in the Kaleidoscope code samples (llvm/examples/Kaleidoscope/Orc) though not comprehensive tutorials as yet. On Tue, Feb 10, 2015 at 1:57 PM, Dibyendu Majumdar <mobile at majumdar.org.uk> wrote:> Hi, > > I am building a new JIT compiler for Lua (actually a derivative of > Lua), and am planning to use LLVM for this. I have trying out some > basic functions using LLVM 3.5.1. I have been puzzled by one aspect of > the MCJIT versions of the Kaleidoscope sample, and would hugely > appreciate some insight. > > Can a single MCJIT instance be used to manage several modules? > Why is a separate MCJIT instance created for each module? > > Unfortunately the tutorial text does not explain the rationale for this. > > At the moment in my implementation I am putting each compiled function > in its own module and creating an engine for it. This is so that each > function can be managed independently and linked to garbage collection > in Lua. However I do not know if there is a better way - for example > creating a shared engine across all modules. I would also like to > understand the trade offs with this approach versus other approaches. > > Many thanks > > Regards > Dibyendu > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150210/c70a057d/attachment.html>
Lang Hames
2015-Feb-10 22:28 UTC
[LLVMdev] Some basic questions regarding MCJIT and Kaleidoscope sample
HI Dibyendu, A single MCJIT instance can notionally manage multiple modules, but there are caveats (which I'm afraid I don't remember off the top of my head) that make it unattractive in practice. I believe most clients opt for something like the ExecutionEngine-per-Module model used in the Kaleidoscope tutorials. As Dave mentioned, I'm also working on some new JIT APIs (Orc) that are intended to be more feature-rich and easier to use than MCJIT. If you would like to try them out and have any questions about how they work please don't hesitate to ask. You'll need to live on the bleeding edge for those though - they're not available on 3.5. Cheers, Lang. On Tue, Feb 10, 2015 at 2:14 PM, David Blaikie <dblaikie at gmail.com> wrote:> We (and by 'we' I mean 'Lang' (cc'd)) have recently been experimenting > with improvements/replacements to the MCJIT in the form of Orc, a new > layered, composable JIT API. There are examples of this in the Kaleidoscope > code samples (llvm/examples/Kaleidoscope/Orc) though not comprehensive > tutorials as yet. > > On Tue, Feb 10, 2015 at 1:57 PM, Dibyendu Majumdar <mobile at majumdar.org.uk > > wrote: > >> Hi, >> >> I am building a new JIT compiler for Lua (actually a derivative of >> Lua), and am planning to use LLVM for this. I have trying out some >> basic functions using LLVM 3.5.1. I have been puzzled by one aspect of >> the MCJIT versions of the Kaleidoscope sample, and would hugely >> appreciate some insight. >> >> Can a single MCJIT instance be used to manage several modules? >> Why is a separate MCJIT instance created for each module? >> >> Unfortunately the tutorial text does not explain the rationale for this. >> >> At the moment in my implementation I am putting each compiled function >> in its own module and creating an engine for it. This is so that each >> function can be managed independently and linked to garbage collection >> in Lua. However I do not know if there is a better way - for example >> creating a shared engine across all modules. I would also like to >> understand the trade offs with this approach versus other approaches. >> >> Many thanks >> >> Regards >> Dibyendu >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150210/ee918f96/attachment.html>
Dibyendu Majumdar
2015-Feb-10 22:37 UTC
[LLVMdev] Some basic questions regarding MCJIT and Kaleidoscope sample
Hi David, On 10 February 2015 at 22:14, David Blaikie wrote:> We (and by 'we' I mean 'Lang' (cc'd)) have recently been experimenting with > improvements/replacements to the MCJIT in the form of Orc, a new layered, > composable JIT API. There are examples of this in the Kaleidoscope code > samples (llvm/examples/Kaleidoscope/Orc) though not comprehensive tutorials > as yet. >Yes I have noticed that there is a replacement for MCJIT using Orc. But I assume this is still early days for the new api? When will a production release be available? Will Orc support the use case described in my post - i.e. - functions independently JITed and garbage collected? In Lua, function calls go via the runtime so I don't need to link functions. Later on I will look at inlining functions to be able to bypass the Lua runtime when it makes sense. The other requirement I have is to be able to access standard Lua functions (not dynamically linked) from within the JITed function. I discovered that MCJIT has the bug due to which addGlobalMapping() does not work. So I am using sys::DynamicLibrary::AddSymbol() to register the Lua functions. BTW a newbie question - once I have compiled a function - is there a need to retain the module and engine - apart from the fact that the memory allocated to the JITed function is presumably managed by the engine? Thanks and Regards Dibyendu