LLVM

from Wikipedia, the free encyclopedia
The LLVM Compiler Infrastructure

DragonFull.png
Basic data

Maintainer Chris Lattner
developer The LLVM team
Publishing year October 24, 2003
Current  version 10.0.1
( July 22, 2020 )
operating system Platform independence
programming language C ++ , C , assembly language
category Compiler
License University of Illinois / NCSA Open Source License , Apache License
German speaking No
www.llvm.org

LLVM (formerly Low Level Virtual Machine ) is a modular compiler - substructure architecture with a virtual instruction set , a virtual machine that virtualizes a main processor , and a comprehensive, optimizing translation concept. It is characteristic, among other things, that all time phases of a program ( runtime , compile time , link time ) including the idle phase can be used for optimization. The purpose is to simply develop your own front ends for different languages ​​that use the LLVM intermediate language. The LLVM library, which is called from the front end, takes care of generating the machine or VM code.

LLVM's development began in 2000 under the direction of Chris Lattner and Vikram Adve at the University of Illinois . The project was originally developed as a research to investigate dynamic compilation and optimization. Today it is home to a large number of sub-projects and extensions from current compiler research and development.

LLVM is available as free software under the University of Illinois / NCSA Open Source License , which is similar to the 3-clause BSD license and the MIT license .

The name “Low Level Virtual Machine” sometimes causes confusion, since LLVM can also be used for virtualization. Over time, LLVM became a framework project that included various compiler and low-level techniques. In the meantime, LLVM is the brand for the actual project, the LLVM intermediate language (LLVM-IR), the LLVM debugger (LLDB), the LLVM standard C ++ library (libc ++) etc.

Working method

Conventional compiler systems usually perform optimization processes during compilation and then connect the compiled modules with one another. This second process is called binding or linking and also offers optimization options that have so far been little used, since the linker only sees the individual modules and not the entire program. This is where LLVM comes in by creating a virtual bytecode modeled on the RISC instruction sets , which can be optimized again during the link.

The name LLVM already reveals that part of the architecture is based on a virtual machine that virtualizes a processor. A processor can not only be a main processor (CPU), but also a graphics processor (GPU). The virtual machine is able to translate the internally generated language (so-called intermediate language) of the compiler (LLVM Assembly Language) during execution for the processor of the current system. It is characterized by the fact that it is highly efficient, which also enables just-in-time translation (i.e. on request, if necessary), and with a size of only 20 kB it is extremely compact, which means that it can also be executed on simple, older processors Graphics processors (GPUs) or embedded CPUs, and in particular even directly in the cache is possible. A flexible back-end system makes it possible to support almost any number of different processor architectures.

The LLVM libraries can be used by compiler projects for which it would be too time-consuming to write their own code generator in order to generate machine code (bit code, microcode) in a simple manner . For example, Clang, which is part of LLVM, only needs to parse the C or C ++ code and translate it into the LLVM intermediate language (LLVM Intermediate Representation, LLVM IR). The generation of efficient machine code can be left to the LLVM backend. In this example, the virtual machine is not used, as LLVM only acts as a compiler backend for the respective architecture (x86, PowerPC, IA64, ...).

construction

As of version 2.9, the LLVM compiler primarily uses Clang as a front end . LLVM is suitable for compiling programs that have been written in freely selectable programming languages. Currently, program code can be compiled in the programming languages C , C ++ , Objective-C , Swift , Java , Delphi , Julia , D , Ada , Fortran , Haskell , Dylan , Gambas , Python , Ruby , Rust , ActionScript , Vala, Genie and GLSL , among others become.

LLVM can be used to create virtual machines for languages ​​such as Java, platform-specific code generators, and optimizers that are independent of language and platform. The LLVM intermediate layer (IR) lies between language-specific modules and the respective code generators and can be viewed as a kind of platform-independent assembly language. LLVM also supports dynamic, inter- procedural optimization as well as static ahead-of-time and just-in-time compilation . An example for LLVM-IR:

; String-Konstante als globale Konstante deklarieren
@.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00"

; Externe Deklaration der `puts()`-Funktion (enthalten in libc)
declare i32 @puts(i8* nocapture) nounwind

; Definition der `main()`-Funktion
define i32 @main() {  ; i32()*
  ; Konvertiere [13 x i8]* zu i8 *... (Pointer auf i8-Elemente)
  %cast210 = getelementptr [13 x i8]* @.str, i64 0, i64 0

  ; Rufe `puts()`-Funktion auf, um Text auszugeben
  call i32 @puts(i8* %cast210)
  ret i32 0
}

; Metadaten
!1 = metadata !{i32 42}
!foo = !{!1, null}

Clang

Clang is a frontend developed for LLVM that is optimized for C -like languages. Compared to the GCC superstructure, it enables faster compilation runs with lower memory consumption and, as a result, often smaller executable programs . In addition, it has more extensive and more precise static analysis methods that the developer z. B. facilitate troubleshooting. The support of the programming language C ++ is considered stable from version 2.7.

Since September 2009, Clang has officially been considered stable and productive. As of LLVM version 2.6, it is an integral part of the LLVM compiler package. Clang can also be used as a purely static code analysis and debug tool without LLVM, for example when used with other compilers. For static code analysis, Clang is integrated into Apple's Xcode development environment for the programming languages ​​C, Objective-C and C ++.

LLDB

LLDB is a modular and highly dynamic debugger based on the techniques of the LLVM project and optimized for C-based languages . It should be particularly memory-efficient and at the same time extremely powerful and fast. It has a plug-in interface, for example for supporting other programming languages. In addition, tasks can be automated with the help of Python . A special feature is the special support for debugging multithreading code.

DragonEgg

DragonEgg is an LLVM plug-in for the GNU Compiler Collection (from version 4.5). This enables LLVM to be used optionally as a compiler backend for an unpatched GCC installation. DragonEgg was just called "the gcc plugin" at the beginning of development. DragonEgg replaces the previously frequently used LLVM-GCC mixed configuration.

vmkit

This is a modified branch ( fork ) of the LLVM-VM, which enables the direct execution of Java and CIL bytecode ( .NET / Mono ). The compiler or linker can pack and execute the highly compact vmkit (approx. 20 kB) in front of the Java or CIL bytecode, which enables execution on any processor architectures and on systems without prior installation of Java or .NET. The project is currently no longer officially supported.

CLOVER

With KLEE you can have programs unmonitored and automatically examined for program errors. The program is carried out step by step. Instead of specific values, input and intermediate results are used symbolically and what values ​​they could have are saved. In the case of "dangerous operations", for example divisions or memory accesses via pointer), a check is made to see whether they could generate an error, for example division by zero or access to unreserved memory. KLEE then outputs which input the program generates the error and which path is taken through the source code.

Supported Architectures

LLVM supports a large number of processor architectures :

However, there are still some restrictions. The frontend (llvm-gcc) is not yet executable for every platform. This can be circumvented by using the LLVM as a cross compiler . Any dependencies, for example the program library , should be taken into account here.

history

The project started in 2000 at the University of Illinois at Urbana-Champaign as a study project by Vikram Adve and Chris Lattner. When Apple became aware of this, in 2005 they put together a permanent development team for the further development of LLVM and hired Chris Lattner as its project manager. LLVM has been the standard compiler in Apple's Xcode development environment since July 2008 . As of version 2.6 of October 2009, the compiler front-end Clang is an integral part of LLVM.

In 2011, LLVM received the Programming Languages ​​Software Award from ACM SIGPLAN.

Current development

Many other components are currently in intensive development, including front ends for Java Bytecode , OpenCL , Microsoft's CIL , Python , Lua , PHP , Ruby , Mono and Adobe ActionScript . The LLVM- JIT compiler can recognize unused static branches of the program at runtime and then remove them. This optimizes programs with a high degree of branching. For this reason Apple has been using LLVM in the OpenGL stack since macOS 10.5 , on the one hand to shorten rarely changing branch paths and on the other hand to optimize vertex shaders.

Web links

Individual evidence

  1. a b The LLVM Compiler Infrastructure Project (English) - official website
  2. llvm.org
  3. Chris Lattner: The LLVM 1.0 Release is finally available! .
  4. Release 10.0.1 . July 22, 2020 (accessed July 22, 2020).
  5. The llvm Open Source Project on Open Hub: Languages Page . In: Open Hub . (accessed on July 18, 2018).
  6. The llvm Open Source Project on Open Hub: Languages Page . In: Open Hub . (English, accessed July 27, 2018).
  7. The llvm Open Source Project on Open Hub: Languages Page . In: Open Hub . (English, accessed July 27, 2017).
  8. License . (English, accessed July 27, 2018).
  9. releases.llvm.org . September 19, 2019 (accessed July 27, 2018).
  10. a b llvm.org
  11. llvm.org
  12. llvm.org
  13. a b The LLVM Users . llvm.org
  14. Hans-Joachim Baader: LLVM 1.5 released. In: Pro-Linux. May 20, 2005, accessed December 5, 2010 .
  15. llvm.org
  16. a b c LLVM Features . llvm.org
  17. LLVM. aosabook.org
  18. clang: a C language family frontend for LLVM . LLVM; Status: October 18, 2010
  19. LLVM 2.6 release! . ( Memento of the original from January 11, 2012 in the Internet Archive ) Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice. lists.cs.uiuc.edu, October 23, 2009 (English) @1@ 2Template: Webachiv / IABot / lists.cs.uiuc.edu
  20. ^ Expressive Diagnostics . LLVM; Status: November 27, 2009 (English)
  21. ^ The LLDB Debugger Goals . lldb.llvm.org
  22. Chris Lattner: New “lldb” Debugger . blog.llvm.org
  23. dragonegg.llvm.org
  24. vmkit.llvm.org
  25. Cristian Cadar, Daniel Dunbar, Dawson Engler: KLEE: Unassisted and Automatic Generation of High-Coverage Tests for Complex Systems Programs . Stanford University, 2008.
  26. Adam Treat: mkspecs and patches for LLVM compile of Qt4. (No longer available online.) In: Qt4-preview-feedback mailing list. February 19, 2005, archived from the original on October 4, 2011 ; accessed on December 5, 2010 (English). Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice. @1@ 2Template: Webachiv / IABot / lists.trolltech.com
  27. developer.apple.com
  28. Chris Lattner: LLVM 2.6 Release! (No longer available online.) In: llvm-announce mailing list. October 23, 2009, archived from the original on January 11, 2012 ; accessed on December 5, 2010 (English). Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice. @1@ 2Template: Webachiv / IABot / lists.cs.uiuc.edu
  29. Hans-Joachim Baader: LLVM 2.6 released. In: Pro-Linux. October 26, 2009, accessed December 5, 2010 .
  30. mono-project.com
  31. ^ Developing for the Apple iPhone using Flash . ( Memento of the original from December 19, 2009 in the Internet Archive ) Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice. adobe.com @1@ 2Template: Webachiv / IABot / www.adobe.com
  32. [LLVMdev] A cool use of LLVM at Apple: the OpenGL stack . ( Memento of the original from November 4, 2006 in the Internet Archive ) Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice. @1@ 2Template: Webachiv / IABot / lists.cs.uiuc.edu