LLVM

This is an old revision of LLVM, edited by Jonas at . The current revision is 117306.

/* Frequently Asked Questions */ Fixed second mailing list link

The current status of Low Level Virtual Machine (LLVM) support is in progress.

The information in this section has been updated as of June 2019 and might be outdated by the time you read it

Progress

FPC with an LLVM code generator backend is available in svn trunk. It currently supports the following targets:

Usage

Install Clang

You can use a version included in an LLVM release available from the official LLVM site, or use a version that comes with Xcode (macOS) or your Linux distribution.

Note: while FPC can generate LLVM code that can be compiled with LLVM 3.4 till 8.0, older versions of LLVM may contain bugs that break your program. It is recommended to use at least LLVM/Clang 7.0 or Xcode 9.3.

Build FPC with LLVM support

First build the compiler with LLVM support (using FPC 3.0.4 as a starting compiler)

 make LLVM=1
 #ifdef CPULLVM
 -FD/Users/Me/clang+llvm-8.0.0-x86_64-apple-darwin/bin
 #endif

Link-time optimisation means that potentially the entire program and all units that it uses are all optimised together.

To compile units with LTO support, or to compile a program or library with LTO, add -CLflto on the compiler command line. If you add this to OPT when building FPC, all standard units and the compiler itself will also be built with LTO.

Note:

Open tasks

Frequently Asked Questions

Will the FPC team, somewhere in the future, adopt the LLVM as the backend on all platforms?

No, for various reasons:

  • LLVM will almost certainly never support all targets that FPC supports (Gameboy Advance, OS/2, WinCE, ...), or at some point drop support for targets that FPC still supports (as already happened with Mac OS X for PowerPC/PowerPC64).
  • the native FPC code generators require very little maintenance once written, as they are quite well insulated via abstractions from the rest of the compiler, so there is no reason to drop them
  • FPC is a volunteer/hobby project, and several developers' main interest is working on native FPC code generators
  • you still need some of the hardest parts of the FPC native code generators anyway for LLVM (entry/exit code handling, parameter manager) to deal with assembler routines, and because LLVM does not fully abstract parameter passing
  • a hardware architecture seldom changes in backward-compatibility breaking ways once released, while LLVM makes no such promises.
  • LLVM changes a lot, all the time. That means there is a high chance of introducing regressions.
  • FPC's native code generators are much faster than LLVM's (even if you would neglect the overhead of FPC generating bitcode and the LLVM tool chain reading it back in), so especially while developing it may be more interesting to use FPC's own code generators
Is it at all likely that an LLVM compiler would produce significantly better/faster optimizations than FPC as it stand currently?

It depends on the kind of code. The more pure maths (floating point or integer, especially in tight loops), the more likely it will be faster.

Artificial benchmarks will also be much faster.

For a typical database program, don't expect much change.

Example 1: the compiler itself on x86-64 is about 10% faster when compiled with LLVM on an Intel Haswell processor, or 18% if you also enable link-time optimization.

Example 2: A Viprinet benchmark compiled for ARMv7, running on an APM Mustang X-Gene board: 18% faster.

See Also