Debian Codegraph @

doc/guide/src/LLVMCodegen.adoc

raw
1 = LLVMCodegen
2
3 The <<LLVMCodegen#>> is a <<Codegen#,code generator>> that translates the
4 <<Machine#>> <<IntermediateLanguage#>> to <<LLVM#>> assembly, which is
5 further optimized and compiled to native object code by the <<LLVM#>>
6 toolchain.
7
8 In benchmarks performed on the <<RunningOnAMD64#,AMD64>> architecture,
9 code size with this generator is usually slightly smaller than either
10 the <<AMD64Codegen#,native>> or the <<CCodegen#,C>> code generators. Compile
11 time is worse than <<AMD64Codegen#,native>>, but slightly better than
12 <<CCodegen#,C>>. Run time is often better than either <<AMD64Codegen#,native>>
13 or <<CCodegen#,C>>.
14
15 The <<LLVMCodegen#>> works by generating text LLVM IR (`.ll` files) and
16 compiling it to object code (`.o` files) using the LLVM command-line tools:
17 `llvm-as` (`.ll` to `.bc` assembler), `opt` (`.bc` to `.bc` optimizer), and
18 `llc` (`.bc` to `.o` system compiler). The `-llvm-as <llvm-as>`,
19 `-llvm-opt <opt>`, and `-llvm-llc <llc>`
20 <<CompileTimeOptions#,compile-time options>> can be used to specify the
21 executables to be used when invoking the LLVM command-line tools, which can be
22 used to select a specific version of the LLVM command-line tools (e.g.,
23 `-llvm-as llvm-as-14 -llvm-opt opt-14 -llvm-llc llc-14`).
24
25 <<Release20210117#,MLton 20210117>> requires LLVM 13 or 14, as it invokes `opt`
26 using the
27 https://releases.llvm.org/14.0.0/docs/ReleaseNotes.html#changes-to-the-llvm-ir:["legacy
28 pass manager"].
29
30 As of 20230522, MLton requires LLVM 14, as it invokes `opt` using the
31 https://releases.llvm.org/14.0.0/docs/ReleaseNotes.html#changes-to-the-llvm-ir:["new
32 pass manager"].
33
34 As of 20240809, MLton requires LLVM 15, as it generates LLVM IR using
35 https://releases.llvm.org/15.0.0/docs/ReleaseNotes.html#changes-to-the-llvm-ir:["opaque
36 pointers"].
37
38 == Implementation
39
40 * https://github.com/MLton/mlton/blob/master/mlton/codegen/llvm-codegen/llvm-codegen.sig[`llvm-codegen.sig`]
41 * https://github.com/MLton/mlton/blob/master/mlton/codegen/llvm-codegen/llvm-codegen.fun[`llvm-codegen.fun`]
42
43 == Details and Notes
44
45 The <<LLVMCodegen#>> was initially developed by Brian Leibig (see
46 <<References#Leibig13,An LLVM Back-end for MLton>>).