How to recompile functions with ORC JIT?

Hello,

I am trying to figure out how to recompile functions multiple times during run-time with ORC JIT

and I'd appreciate any help/advice.

My use case is t he following: every time a function of interest (annotated) is called, profiling data

are gathered. Given enough data the function is recompiled using different optimizations. This happens

repeatedly until the "best" optimization parameters are found.

A similar question was asked before and a solution was suggested:

http://lists.llvm.org/pipermail/llvm-dev/2015-July/088665.html

What I am trying to figure out is how the function pointer can be updated to point to the newly

compiled version.

Thanks,

Theodor

+Lang

Ultravague answer: There are a few different Orc layers for different levels of indirection needed for different levels of substitutability. One way is to indirect every call through global function pointers - so when you want to replace the function you write the new function pointer to the global variable. I forget which layers do which kinds of indirection.

  • Dave

H Theodoros, David,

What I am trying to figure out is how the function pointer can be updated to point to the newly compiled version.

As Dave implied, it depends on how you’ve set up your ORC stack. These days, the API directly responsible for this is the IndirectStubsManager (see llvm/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h). If you have access to the appropriate IndirectStubsManager you just need to call the updatePointer method with the name of the function you want to update and the new address.

If you’re using the CompileOnDemand layer to compile lazily from IR, the problem is that that layer doesn’t (currently) expose the IndirectStubManager for each module. I think it would be reasonable to add support for that if you need it though.

So - what is your current setup?

You may also be interested in the latest chapter of the Building A JIT tutorial series that I’m working on. There’s no chapter text yet, but the code was just committed as r271054 and is (hopefully) fairly readable if you’re already familiar with Orc.

Cheers,
Lang.

Hello Lang, David,

I am just using an ObjectLinkingLayer and an IRCompileLayer. I had a look at Chapter 4 of “Building A JIT” and I found exactly what I needed.

I have a working implementation.

Thanks a lot for the help,

Theodor