I am trying to see how to avoid LLVM JIT compilation every time and use the cached copy. I see that LLVM has ObjectCache
support for code generation from module, but to get module from a file or code string, it needs to be compiled and go through different optimization passes. What is the best way to go about it?
Cache the final image object to some file and first lookup the file, and try to parse and try to create
ExecutionEngine
with the image so that one can execute (get pointer to function and call it)Save the intermediate output of code compilation and optimization - i.e. write a module to some file (e.g., using dump) and try to read it (parse IR). then use
ObjectCache
support for code generation from this module.
Option (2) seems two steps and likely worse than (1), but is (1) the right way to go about it?
Given that you have an instance of
ObjectFile
you can write it to the disk:Then you can read it back from disk:
You can take this code and plug it in your custom
ObjectCache
, then feed the object cache to the JIT engine.I hope it helps.