Building a JIT compiler class from scratch
Using the layered approach of ORC, it is very easy to build a JIT compiler customized for the requirements. There is no one-size-fits-all JIT compiler, and the first section of this chapter gave some examples. Let’s have a look at how to set up a JIT compiler from scratch.
The ORC API uses layers that are stacked together. The lowest level is the object-linking layer, represented by the llvm::orc::RTDyldObjectLinkingLayer
class. It is responsible for linking in-memory objects and turning them into executable code. The memory required for this task is managed by an instance of the MemoryManager
interface. There is a default implementation, but we can also use a custom version if we need.
Above the object-linking layer is the compile layer, which is responsible for creating an in-memory object file. The llvm::orc::IRCompileLayer
class takes an IR module as input and compiles it to an object file. The IRCompileLayer
class is a subclass...