SkillAgentSearch skills...

JitFromScratch

Example project from my talks in the LLVM Social Berlin and C++ User Group

Install / Use

/learn @weliveindetail/JitFromScratch
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

:warning: This repository works with LLVM versions 4.0 to 8.0 and is now archived. Please find examples for more recent versions in-tree: https://github.com/llvm/llvm-project/blob/main/llvm/examples/OrcV2Examples/

<br> <br>

JitFromScratch

<a href="https://github.com/weliveindetail/JitFromScratch/blob/master/LICENSE.md"><img src="https://licensebuttons.net/l/by-sa/3.0/88x31.png" alt="CC BY-SA 4.0" width="57" height="20"></a> Build Status <a href="https://gitpod.io/#https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a>

Collection of examples from my talks in the LLVM Social Berlin and C++ User Group Berlin that implement various aspects of a JIT compiler based on the LLVM Orc libraries.

Contribute

The repository follows a perfect history policy to foster traceability and understanding. If you find a bug or want to submit an improvement, please file a pull request against the respective step.

Structure

The examples are organized around a nonsense command line program that compiles the code for a simple function at runtime:

template <size_t sizeOfArray>
int *integerDistances(const int (&x)[sizeOfArray], int *y) {
  int items = arrayElements(x);
  int *results = customIntAllocator(items);

  for (int i = 0; i < items; i++) {
    results[i] = abs(x[i] - y[i]);
  }

  return results;
}

Steps

The example project is built in a series of self-contained steps. You can immediatedly explore and build each change in your Browser with GitPod:

| Step | Change | Travis | GitPod | Description | | ---- | ------ | ------ | ------ | ----------- | | 0 | 87cb540 | Build Status | <a href="https://gitpod.io/#CHECKOUT=87cb540/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Wire up LLVM | | 1 | 82465fc | Build Status | <a href="https://gitpod.io/#CHECKOUT=82465fc/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Add lit tests | | 2 | b1b268b | Build Status | <a href="https://gitpod.io/#CHECKOUT=b1b268b/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Add TravisCI config to run tests in prebuilt docker | | 3 | 81a9d8b | Build Status | <a href="https://gitpod.io/#CHECKOUT=81a9d8b/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Initialize LLVM for native target codegen | | 4 | 731f482 | Build Status | <a href="https://gitpod.io/#CHECKOUT=731f482/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Add minimal JIT compiler based on LLJIT | | 5 | 73a565a | Build Status | <a href="https://gitpod.io/#CHECKOUT=73a565a/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Create empty module and pass it to the JIT | | 6 | 7690ac1 | Build Status | <a href="https://gitpod.io/#CHECKOUT=7690ac1/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | In debug mode dump extra info when passing -debug -debug-only=jitfromscratch | | 7 | 3b47ce8 | Build Status | <a href="https://gitpod.io/#CHECKOUT=3b47ce8/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Generate function that takes two ints and returns zero | | 8 | 8a4bba8 | Build Status | <a href="https://gitpod.io/#CHECKOUT=8a4bba8/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Add basic sanity checks for IR code | | 9 | 402e9d1 | Build Status | <a href="https://gitpod.io/#CHECKOUT=402e9d1/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Request and run trivial function | | 10 | e08ff57 | Build Status | <a href="https://gitpod.io/#CHECKOUT=e08ff57/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Emit IR code for substraction and use it in the integerDistances function | | 11 | 8cf690b | Build Status | <a href="https://gitpod.io/#CHECKOUT=8cf690b/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Emit variable names to make IR more readable | | 12 | 03b8701 | Build Status | <a href="https://gitpod.io/#CHECKOUT=03b8701/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Allow symbol resolution from the host process | | 13 | a0cdaad | Build Status | <a href="https://gitpod.io/#CHECKOUT=a0cdaad/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Emit call to stdlib function abs in JITed code | | 14 | 2653289 | Build Status | <a href="https://gitpod.io/#CHECKOUT=2653289/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" width="86" height="20"></a> | Emit unrolled loop in JITed code | | 15 | 2291ee4 | Build Status | <a href="https://gitpod.io/#CHECKOUT=2291ee4/https://github.com/weliveindetail/JitFromScratch"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in G

View on GitHub
GitHub Stars176
CategoryDevelopment
Updated5mo ago
Forks21

Languages

C++

Security Score

97/100

Audited on Nov 3, 2025

No findings