Inlining with the ORC JIT

Is it possible to inline functions compiled from C++ code into generated code that is fed, Module by Module, into the ORC JIT?

I’d like to add a Module compiled from C++ code into the JIT and then as I add later modules, functions from the first module are inlined in the later ones.

I already do this for file compilation/linking in my Common Lisp compiler “Clasp” (github.com/drmeister/clasp).

I have followed the new ORC Kaleidoscope demo and set up the ORC layers to do optimization and compilation but the examples are all for function optimization and do not describe inlining.

Christian Schafmeister

Professor, Chemistry Department
Temple University
meister@temple.edu

As far as i know, optimizations can only be done on a module level.
If you compile and pass modules to the object-linking-layer, you won’t be able to perform any optimizations.
Thus, what you could do is:

  • merge the generated modules into a big monolithic module
  • repeatedly perform optimization passes eg. inlining
  • copy new functions into a new module ( so you don’t re-compile and re-link the same functions)
  • compile and link new module

This seems fragile to me: it could break with optimizations unless you mark everything such that the optimizer does not do any inter-procedural optimizations (other than inlining).