Optimizing the compiler
Simple ways to speed up the compilation of your CaffeineC program
Using a different LLVM compiler
By default CaffeineC uses clang
to compile the generated LLVM IR to an executable file (or any other format supported by clang). This is by far not optimal. There are other compilers that can be used, some even have configurations for them builtin to CaffeineC.
Using LLC + GCC
If you have both llc
and gcc
installed on your system, you can make use of them to compile your code a little faster. The CaffeineC compiler makes using this combination easy, you only have to add the-G
flag. Depending on the system, the change in compilation speed can be pretty big. Here is an example benchmark performed on a simple Hello, World program
Using LLC + TCC
If you want to go even faster, and don't mind having a less optimized/slower executable file generated, you can go to the extreme and use Tiny C Compiler (TCC). Once you install it, you add the -G
flag as in the example above, but you also add the -T
flag. This configuration speeds up the compilation over 2x compared to the default configuration.
Using a different linker
Using GOLD
You can pass arguments directly to the compiler (clang
, gcc
, or tcc
) by using the -a
flag for clang
or the -g
flag for gcc
and tcc
. By adding the -fuse-ld
flag, you can specify what linker you would like the compiler to use. So by appending -a -fuse-ld=gold
you can tell the clang
compiler to use the GOLD linker. On a more complicated example program, that requires linking with the X11 library, you can see a slight improvement in compilation speed when using GOLD.
Using MOLD
Last updated
Was this helpful?