The LLVM Compiler Framework and Infrastructure Tutorial

The LLVM Compiler Infrastructure (http://llvm.cs. uiuc.edu) is a robust system that is well suited for a wide variety of research and development work. This brief paper introduces the LLVM system and provides pointers to more extensive documentation, complementing the tutorial presented at LCPC. 1 Brief Overview and Goals The LLVM Compiler Infrastructure [2] is a language and target-independent compiler system, designed for both static and dynamic compilation. LLVM (Low Level Virtual Machine) can be used to build both traditional optimizing compilers for high performance programming languages as well as compiler-based tools such as Just-In-Time (JIT) translators, profilers, binary translators, memory sandboxing tools, static analysis tools, and others. A major goal of the LLVM development community is to provide a fast, robust, and well-documented core framework to support high-quality compilers and tools. A second major goal is to develop a broad community of contributors to ensure that the software continues to grow and be relevant, and to maintain its robustness and quality. A third goal is to provide a flexible infrastructure for new compiler development and research. 2 Key LLVM Design Features The LLVM system has three main components: the LLVM Virtual Instruction Set, a collection of reusable libraries for analysis, transformation and code generation; and tools built from these libraries. The LLVM framework is characterized by a clean, simple, and modular design, which allows new users to understand the representation, write new analyses, transformations, and tools easily. The LLVM Virtual Instruction Set is the common intermediate representation shared by all of the LLVM subsystems. It is a simple, mid-level, threeaddress code representation that is designed to be both language-independent and target-independent [1]. The instruction set provides explicit control-flow graphs, explicit dataflow information (in SSA form), and a mid-level, language R. Eigenmann et al. (Eds.): LCPC 2004, LNCS 3602, pp. 15–16, 2005. c © Springer-Verlag Berlin Heidelberg 2005 16 C. Lattner and V. Adve independent type system. The type system is rich enough to support sophisticated, language-independent compiler techniques, including pointer analysis, dependence analysis, and interprocedural dataflow analyses, and transformations based on them. Exactly the same instruction set is used both as a persistent, external representation for compiled code and as the internal representation for all mid-level compiler passes. Making this representation persistent enables all LLVM passes to be used at compile-time, link-time, load-time, run-time, and “idle-time” (between program runs). The key design features and the innovative aspects of the code representation are are described in a paper [2], and the complete instruction set is described in an online reference manual [1]. The LLVM source base mostly consists of modular and reusable libraries. These components include analyses and optimizations, native code generators, JIT compiler support, profile-guided feedback, etc. These compiler components reduce the cost and difficulty of building compilers for new platforms, new source languages, and for building new kinds of tools (debuggers, profilers, etc). The LLVM system also includes several complete tools built from these components, including an ANSI-conforming C/C++ compiler (which uses the GNU Compiler Collection (GCC) parsers). The C/C++ compiler applies a large number of module-level (compile-time) and cross-module (link-time) optimizations. Other LLVM tools include programs to manipulate the IR (e.g. convert between ASCII and binary formats, extract functions from a program, etc), a modular optimizer (which can run any LLVM optimization on an program, driven from the command line), automated compiler debugging tools, and others.