All Projects → weliveindetail → Jitfromscratch

weliveindetail / Jitfromscratch

Licence: cc-by-sa-4.0
Example project from my talks in the LLVM Social Berlin and C++ User Group

Projects that are alternatives of or similar to Jitfromscratch

Leekscript V2
A dynamically typed, compiled just-in-time programming language used in Leek Wars' AIs
Stars: ✭ 46 (-70.89%)
Mutual labels:  compiler, llvm, jit
Llvm Tutorial Standalone
DEPRECATED (Use: https://github.com/llvm-hs/llvm-hs-kaleidoscope )
Stars: ✭ 38 (-75.95%)
Mutual labels:  compiler, llvm, jit
Ghdl
VHDL 2008/93/87 simulator
Stars: ✭ 1,285 (+713.29%)
Mutual labels:  compiler, llvm
Enzyme.jl
Julia bindings for the Enzyme automatic differentiator
Stars: ✭ 90 (-43.04%)
Mutual labels:  compiler, llvm
Rhine
🔬 a C++ compiler middle-end, using an LLVM backend
Stars: ✭ 157 (-0.63%)
Mutual labels:  compiler, llvm
Seeless
C IDE for iOS
Stars: ✭ 71 (-55.06%)
Mutual labels:  compiler, llvm
Jit Compiler
JIT compiler in Go
Stars: ✭ 70 (-55.7%)
Mutual labels:  compiler, jit
Faust
Functional programming language for signal processing and sound synthesis
Stars: ✭ 1,360 (+760.76%)
Mutual labels:  compiler, llvm
Nanojit
NanoJIT is a small, cross-platform C++ library that emits machine code.
Stars: ✭ 101 (-36.08%)
Mutual labels:  compiler, jit
Brain
An esoteric programming language compiler on top of LLVM based on Brainfuck
Stars: ✭ 112 (-29.11%)
Mutual labels:  compiler, llvm
Flax
general purpose programming language, in the vein of C++
Stars: ✭ 111 (-29.75%)
Mutual labels:  compiler, llvm
Kai
An expressive low level programming language
Stars: ✭ 68 (-56.96%)
Mutual labels:  compiler, llvm
Llvm Hs Examples
Examples for Haskell bindings to LLVM
Stars: ✭ 51 (-67.72%)
Mutual labels:  llvm, jit
Akilang
A compiler for a simple language, built with Python and LLVM
Stars: ✭ 71 (-55.06%)
Mutual labels:  compiler, llvm
B2dpipe
2D Pipeline Compiler.
Stars: ✭ 51 (-67.72%)
Mutual labels:  compiler, jit
Numba Scipy
numba_scipy extends Numba to make it aware of SciPy
Stars: ✭ 98 (-37.97%)
Mutual labels:  compiler, llvm
Jphp
JPHP - an implementation of PHP on Java VM
Stars: ✭ 1,665 (+953.8%)
Mutual labels:  compiler, jit
Nativejit
A C++ expression -> x64 JIT
Stars: ✭ 999 (+532.28%)
Mutual labels:  compiler, jit
Fanx
A portable programming language
Stars: ✭ 101 (-36.08%)
Mutual labels:  compiler, llvm
Hikari
LLVM Obfuscator
Stars: ✭ 1,585 (+903.16%)
Mutual labels:  compiler, llvm

JitFromScratch

CC BY-SA 4.0 Build Status Open in Gitpod

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 Open in Gitpod Wire up LLVM
1 82465fc Build Status Open in Gitpod Add lit tests
2 b1b268b Build Status Open in Gitpod Add TravisCI config to run tests in prebuilt docker
3 81a9d8b Build Status Open in Gitpod Initialize LLVM for native target codegen
4 731f482 Build Status Open in Gitpod Add minimal JIT compiler based on LLJIT
5 73a565a Build Status Open in Gitpod Create empty module and pass it to the JIT
6 7690ac1 Build Status Open in Gitpod In debug mode dump extra info when passing -debug -debug-only=jitfromscratch
7 3b47ce8 Build Status Open in Gitpod Generate function that takes two ints and returns zero
8 8a4bba8 Build Status Open in Gitpod Add basic sanity checks for IR code
9 402e9d1 Build Status Open in Gitpod Request and run trivial function
10 e08ff57 Build Status Open in Gitpod Emit IR code for substraction and use it in the integerDistances function
11 8cf690b Build Status Open in Gitpod Emit variable names to make IR more readable
12 03b8701 Build Status Open in Gitpod Allow symbol resolution from the host process
13 a0cdaad Build Status Open in Gitpod Emit call to stdlib function abs in JITed code
14 2653289 Build Status Open in Gitpod Emit unrolled loop in JITed code
15 2291ee4 Build Status Open in Gitpod Emit call to allocator in JITed code
16 bf72028 Build Status Open in Gitpod Remove wrapper function and call JITed code directly
17 96f4c8e Build Status Open in Gitpod Break free from LLJIT
18 a4b88a0 Build Status Open in Gitpod Implement GDB JIT interface
19 b7212c3 Build Status Open in Gitpod Add optimization passes controlled via -Ox command line flag
20 75dff62 Build Status Open in Gitpod Simple name-based object cache

Build and run locally

$ git clone https://github.com/weliveindetail/JitFromScratch jitfromscratch
$ mkdir build && cd build
$ cmake -GNinja -DLLVM_DIR=/path/to/llvm-build/lib/cmake/llvm ../jitfromscratch
$ ninja run

The project was tested on Ubuntu 19.04 and macOS 10.14. Please find real-world examples for commands and expected output on Travis CI.

Build and run in docker

$ git clone https://github.com/weliveindetail/JitFromScratch jitfromscratch
$ cd jitfromscratch
$ docker run -it -v $(pwd):/host/jitfromscratch -e REMOTE=/host/jitfromscratch -e CHECKOUT=$(git rev-parse HEAD) weliveindetail/jitfromscratch:llvm09-test-release

Further images can be pulled from dockerhub or created manually based on the given Dockerfiles.

Setup vscode

Install the C/C++, CMake Tools and CodeLLDB extensions and use the given configuration files.

Previous Versions

You can easily diff for a specific 8.0 to 9.0 change set, e.g.:

$ git diff origin/llvm08/master origin/llvm09/master
$ git diff origin/llvm08/steps/A00 origin/llvm09/steps/A00 -- CMakeLists.txt
$ git diff origin/llvm08/steps/A18 origin/llvm09/steps/A18 -- JitFromScratch.cpp

In LLVM 8, the Orc library was almost entirely rewritten and I used the opportunity to also refine my examples. You can still find the old examples here:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].