Programming LLVM Options

The optimizations that LLVM makes and the code generated by LLVM can be controlled using LLVM command-line options. These command-line options can be set using the build options of the compiler metaprogram.

Here is how to interface with LLVM from the metaprogram:

executable_name :: "program";
w := compiler_create_workspace(executable_name);
target_options := get_build_options(w);
target_options.output_executable_name = executable_name;
target_options.optimization_level = .RELEASE;
target_options.llvm_options.command_line = string.[executable_name, "--help"];

In this example, we interact with LLVM, and ask LLVM for it’s command line interface by sending the --help flag. You can find documentation about communicating with LLVM through: llc - LLVM static compiler — LLVM 17.0.0git documentation. Note that the LLVM backend that comes with Jai is a different version than the one provided in the documentation, so the command line interface might be different.

LLVM Commandline Example

This LLVM commandline example says the name of the executable is “executable”, the computer architecture is x86-64, use a greedy register allocation scheme, and assume that there are no infinite values when doing floating point arithmetic.

ARGUMENTS := string.[

target_options.llvm_options.command_line = ARGUMENTS;
1 Like