|This article relies on references to primary sources. (December 2010)|
|Developer(s)||LLVM Developer Group|
|Stable release||3.4.2 / June 19, 2014|
|License||University of Illinois/NCSA Open Source License|
The LLVM compiler infrastructure project (formerly Low Level Virtual Machine) is a compiler infrastructure designed as a set of reusable libraries with well-defined interfaces. It is written in C++ and is designed for compile-time, link-time, run-time, and "idle-time" optimization of programs written in arbitrary programming languages. Originally implemented for C and C++, the language-agnostic design (and the success) of LLVM has since spawned a wide variety of front ends: languages with compilers that use LLVM include ActionScript, Ada, D, Fortran, OpenGL Shading Language, Haskell, Java bytecode, Julia, Objective-C, Swift, Python, Ruby, Rust, Scala, and C#.
The LLVM project started in 2000 at the University of Illinois at Urbana–Champaign, under the direction of Vikram Adve and Chris Lattner. LLVM was originally developed as a research infrastructure to investigate dynamic compilation techniques for static and dynamic programming languages. LLVM was released under the University of Illinois/NCSA Open Source License, a non-copyleft license. In 2005, Apple Inc. hired Lattner and formed a team to work on the LLVM system for various uses within Apple's development systems. LLVM is an integral part of Apple's latest development tools for Mac OS X and iOS.
The name LLVM was originally an initialism for Low Level Virtual Machine, but the initialism caused widespread confusion because the scope of the project is not limited to the creation of virtual machines. As the scope of LLVM grew, it became an umbrella project that included a variety of other compiler and low-level tool technologies as well, making the name even less apt. As such, the project abandoned the initialism. Now, LLVM is a brand that applies to the LLVM umbrella project, the LLVM intermediate representation, the LLVM debugger, the LLVM C++ standard library, etc.
LLVM can provide the middle layers of a complete compiler system, taking intermediate form (IF) code from a compiler and emitting an optimized IF. This new IF can then be converted and linked into machine-dependent assembly code for a target platform. LLVM can accept the IF from the GCC toolchain, allowing it to be used with a wide array of extant compilers written for that project.
LLVM can also generate relocatable machine code at compile-time or link-time or even binary machine code at run-time.
LLVM supports a language-independent instruction set and type system. Each instruction is in static single assignment form (SSA), meaning that each variable (called a typed register) is assigned once and is frozen. This helps simplify the analysis of dependencies among variables. LLVM allows code to be compiled statically, as it is under the traditional GCC system, or left for late-compiling from the IF to machine code in a just-in-time compiler (JIT) fashion similar to Java. The type system consists of basic types such as integers or floats and five derived types: pointers, arrays, vectors, structures, and functions. A type construct in a concrete language can be represented by combining these basic types in LLVM. For example, a class in C++ can be represented by a combination of structures, functions and arrays of function pointers.
The LLVM JIT compiler can optimize unneeded static branches out of a program at runtime, and thus is useful for partial evaluation in cases where a program has many options, most of which can easily be determined unneeded in a specific environment. This feature is used in the OpenGL pipeline of Mac OS X Leopard (v10.5) to provide support for missing hardware features. Graphics code within the OpenGL stack was left in intermediate form, and then compiled when run on the target machine. On systems with high-end GPUs, the resulting code was quite thin, passing the instructions onto the GPU with minimal changes. On systems with low-end GPUs, LLVM would compile optional procedures that run on the local central processing unit (CPU) that emulate instructions that the GPU cannot run internally. LLVM improved performance on low-end machines using Intel GMA chipsets. A similar system was developed under the Gallium3D LLVMpipe, and incorporated into the GNOME shell to allow it to run without a proper 3D hardware driver loaded.
When it comes to the run-time performance of the compiled programs, GCC previously outperformed LLVM by about 10% on average. Newer results do indicate, however, that LLVM has now caught up with GCC in this area, and is now compiling binaries of approximately equal performance, except for programs using OpenMP.
Front ends: programming language support
LLVM was originally written to be a replacement for the existing code generator in the GCC stack, and many of the GCC front ends have been modified to work with it. LLVM currently supports compiling of Ada, C, C++, D, Fortran, and Objective-C, using various front ends, some derived from version 4.0.1 and 4.2 of the GNU Compiler Collection (GCC).
Widespread interest in LLVM has led to a number of efforts to develop entirely new front ends for a variety of languages. The one that has received the most attention is Clang, a new compiler supporting C, Objective-C and C++. Primarily supported by Apple, Clang is aimed at replacing the C/Objective-C compiler in the GCC system with a system that is more easily integrated with integrated development environments (IDEs) and has wider support for multithreading. Objective-C development under GCC was stagnant and Apple's changes to the language were supported in a separately maintained branch.
The Utrecht Haskell compiler can generate code for LLVM which, though the generator is in the early stages of development, has been shown in many cases to be more efficient than the C code generator. The Glasgow Haskell Compiler (GHC) has a working LLVM backend that achieves a 30% speed-up of the compiled code when compared to native code compiling via GHC or C code generation followed by compilation, missing only one of the many optimization techniques implemented by the GHC.
There are many other components in various stages of development, including, but not limited to, a Java bytecode front end, a Common Intermediate Language (CIL) front end, the MacRuby implementation of Ruby 1.9, various front ends for Standard ML, and a new graph coloring register allocator.
Back ends: instruction set and microarchitecture support
At version 3.4 LLVM supports many instruction sets, including ARM, Hexagon, MIPS, Nvidia PTX (called "NVPTX' in LLVM documentation), PowerPC, R600, SPARC, z/Architecture (called "SystemZ" in LLVM documentation), x86/x86-64, and XCore. Not all features are available on all platforms; most features are present for x86/x86-64, z/Architecture, ARM, and PowerPC.
- Amsterdam Compiler Kit (ACK)
- Clang C/C++ compiler
- LLDB (debugger)
- GNU lightning
- GNU Compiler Collection (GCC)
- Pure (programming language)
- Comparison of application virtual machines
- "License", LLVM: Frequently Asked Questions (llvm.org), retrieved 2012-01-27
- Reedy, Geoff (2012-09-24). Compiling Scala to LLVM. St. Louis, Missouri, United States. Retrieved 2013-02-19.
- Mono LLVM, retrieved 2013-03-10
- LLVM, Chris Lattner, in The architecture of Open Source Applications, edited by Amy Brown, Greg Wilson, 2011
- Adam Treat (2005-02-19), mkspecs and patches for LLVM compile of Qt4, retrieved 2012-01-27
- "Apple LLVM Compiler", Developer Tools (Apple), retrieved 2012-01-27
- "Chris Lattner discusses the name LLVM". Retrieved 22 December 2011.
- "ACM Awards". ACM.
- "LLVM Language Reference Manual". Retrieved 16 April 2012.
- Chris Lattner (15 August 2006). "A cool use of LLVM at Apple: the OpenGL stack". LLVMdev mailing list. Retrieved 26 October 2008.
- Michael Larabel, "GNOME Shell Works Without GPU Driver Support", phoronix, 6 November 2011
- V. Makarov. "SPEC2000: Comparison of LLVM-2.9 and GCC4.6.1 on x86". Retrieved 3 October 2011.
- V. Makarov. "SPEC2000: Comparison of LLVM-2.9 and GCC4.6.1 on x86_64". Retrieved 3 October 2011.
- Michael Larabel (27 December 2012). "LLVM/Clang 3.2 Compiler Competing With GCC". Retrieved 31 March 2013.
- Lattner, Chris; Vikram Adve (May 2003). "Architecture For a Next-Generation GCC". First Annual GCC Developers' Summit. Retrieved 6 September 2009.
- "Compiling Haskell To LLVM". Retrieved 22 February 2009.
- "LLVM Project Blog: The Glasgow Haskell Compiler and LLVM". Retrieved 13 August 2010.
- Target-specific Implementation Notes: Target Feature Matrix // The LLVM Target-Independent Code Generator, LLVM site.
- Official website
- LLVM Project Blog
- LLVM: A Compilation Framework for Lifelong Program Analysis & Transformation, a published paper by Chris Lattner, Vikram Adve
- LLVM Language Reference Manual, describes the LLVM intermediate representation
- LLVM - 2.0 and beyond! on YouTube
- Discussion of LLVM by John Siracusa at Ars Technica
- LLVMLinux Wiki
- The Design of LLVM by Chris Lattner, Dr. Dobb's Journal, May 2012