[LLVMdev] MCJIT and Kaleidoscope Tutorial

Kaylor, Andrew andrew.kaylor at intel.com
Mon Jun 3 17:13:03 PDT 2013


Hi Dmitri,

You might want to try replacing the call to JMM->invalidInstructionCache() with a call to TheExecutionEngine->finalizeObject().  If you are getting a non-NULL pointer from getPointerToFunction but it crashes when you try to call it, that is most likely because the memory for the generated code has not been marked as executable.  That happens inside finalizeObject, which also invalidates the code cache.

Even so, this will likely only work in cases where code generation is only invoked once.

You are correct that MCJIT won't work in this case because of the function-by-function approach used in the Kaleidoscope example.  Basically, with MCJIT once code has been generated for a module nothing else can be added to the Module.

Making Kaleidoscope work with MCJIT would require introducing some sort of scheme where a new module was created each time a new function was created.  In the current implementation of MCJIT in trunk it is at least theoretically possible to make such a solution work by also creating a new instance of the MCJIT engine for each Module.  It is our intention to enhance MCJIT to allow multiple modules to be handled by a single instance, but there would still be the requirement that once code was generated for a Module it couldn't be modified again.  There may also be some work necessary in the memory manager to link the modules together.

Obviously it wouldn't be a trivial job to modify the Kaleidoscope example to work with MCJIT, but I think it should be possible.

I don't have a concrete time frame for when multiple module support will be available in MCJIT.

-Andy

-----Original Message-----
From: Dmitri Rubinstein [mailto:dmitri.rubinstein at googlemail.com] 
Sent: Monday, June 03, 2013 4:57 AM
To: LLVM Dev
Cc: Kaylor, Andrew
Subject: MCJIT and Kaleidoscope Tutorial

Hi all,

I tried to modify Kaleidoscope Tutorial (toy.cpp from llvm/examples/Kaleidoscope/Chapter7, LLVM 3.3 release branch) in order to use MCJIT instead of JIT. I get segmentation fault when running toy.cpp with fibonacci example from the tutorial. My modified toy.cpp is in attachment and still works with JIT (when #define USE_MCJIT line is commented out).

I read discussions regarding MCJIT in this mailing list, and I understand it that MCJIT currently cannot be used in the same way as JIT. The separate function-by-function (i.e. incremental) compilation approach with getPointerToFunction, like the one used in the Kaleidoscope tutorial, will not work. Is this correct or do I do something wrong in my code ?

There was also a discussion about using multi-module approach instead of getPointerToFunction, but it seems that support for this is not yet available. I would like to know if there is any way currently to let Kaleidoscope-style of compilation work with MCJIT, and if no when it will be available ?

Also, even if MCJIT does not support currently this compilation style I still not understand why getPointerToFunction returns me a non-NULL pointer ? I expected to get at least assertion or a NULL pointer.

Thanks,

Dmitri




More information about the llvm-dev mailing list