## MLton 20241230

# LLVMCodegen

The LLVMCodegen is a code generator that translates the Machine IntermediateLanguage to LLVM assembly, which is further optimized and compiled to native object code by the LLVM toolchain.

In benchmarks performed on the AMD64 architecture, code size with this generator is usually slightly smaller than either the native or the C code generators. Compile time is worse than native, but slightly better than C. Run time is often better than either native or C.

The LLVMCodegen works by generating text LLVM IR (`.ll` files) and compiling it to object code (`.o` files) using the LLVM command-line tools: `llvm-as` (`.ll` to `.bc` assembler), `opt` (`.bc` to `.bc` optimizer), and `llc` (`.bc` to `.o` system compiler). The `-llvm-as <llvm-as>`, `-llvm-opt <opt>`, and `-llvm-llc <llc>` compile-time options can be used to specify the executables to be used when invoking the LLVM command-line tools, which can be used to select a specific version of the LLVM command-line tools (e.g., `-llvm-as llvm-as-14 -llvm-opt opt-14 -llvm-llc llc-14`).

MLton 20210117 requires LLVM 13 or 14, as it invokes `opt` using the "legacy pass manager".

As of 20230522, MLton requires LLVM 14, as it invokes `opt` using the "new pass manager".

As of 20240809, MLton requires LLVM 15, as it generates LLVM IR using "opaque pointers".

## Implementation

- `llvm-codegen.sig`

- `llvm-codegen.fun`

## Details and Notes

The LLVMCodegen was initially developed by Brian Leibig (see An LLVM Back-end for MLton).