What Is LLVM? and a Status Update

Total Page:16

File Type:pdf, Size:1020Kb

What Is LLVM? and a Status Update What is LLVM? And a Status Update. Approved for public release Hal Finkel Leadership Computing Facility Argonne National Laboratory Clang, LLVM, etc. ✔ LLVM is a liberally-licensed(*) infrastructure for creating compilers, other toolchain components, and JIT compilation engines. ✔ Clang is a modern C++ frontend for LLVM ✔ LLVM and Clang will play significant roles in exascale computing systems! (*) Now under the Apache 2 license with the LLVM Exception LLVM/Clang is both a research platform and a production-quality compiler. 2 A role in exascale? Current/Future HPC vendors are already involved (plus many others)... Apple + Google Intel (Many millions invested annually) + many others (Qualcomm, Sony, Microsoft, Facebook, Ericcson, etc.) ARM LLVM IBM Cray NVIDIA (and PGI) Academia, Labs, etc. AMD 3 What is LLVM: LLVM is a multi-architecture infrastructure for constructing compilers and other toolchain components. LLVM is not a “low-level virtual machine”! LLVM IR Architecture-independent simplification Architecture-aware optimization (e.g. vectorization) Assembly printing, binary generation, or JIT execution Backends (Type legalization, instruction selection, register allocation, etc.) 4 What is Clang: LLVM IR Clang is a C++ frontend for LLVM... Code generation Parsing and C++ Source semantic analysis (C++14, C11, etc.) Static analysis ● For basic compilation, Clang works just like gcc – using clang instead of gcc, or clang++ instead of g++, in your makefile will likely “just work.” ● Clang has a scalable LTO, check out: https://clang.llvm.org/docs/ThinLTO.html 5 The core LLVM compiler-infrastructure components are one of the subprojects in the LLVM project. These components are also referred to as “LLVM.” 6 What About Flang? ● Started as a collaboration between DOE and NVIDIA/PGI. Now also involves ARM and other vendors. ● Public discussions on making Flang (f18+runtimes) part of LLVM going well. ● Two development paths: f18 – A new Flang based frontend on PGI’s written in existing modern C++. frontend (in C). Fortran Parsing, Production runtime semantic ready including library and analysis, etc. OpenMP vectorized under active support. math- function development. library. LLVM Project 7 What About MLIR? ● MLIR is now part of the LLVM project. ● MLIR is a "multi-level IR", originaly developed as part of the TensorFlow project. ● It is a kind of framework for producing particular IRs (along with a nice way to specify peephole optimizations for them, translations between them, etc.) ● MLIR is being used for Flang 8 Upcoming LLVM Status... ● Relicensing well underway. ● Moved to github (might also move issue tracking, etc. soon). ● Version 9.0.1 has been released. EuroLLVM 9 What’s Working Well ● Involvement: ● Features: LLVM has become well known for an important set of features: ● A well-defined IR allows use by a lot of different languages (C, C++, Fortran, Julia, Rust, Python (e.g., via Numba), Swift, ML frameworks (e.g., TensorFlow/XLA, PyTorch/Glow), and many others. ● A backend infrastructure allowing the efficient creation of backends for new hardware. ● A state-of-the-art C++ frontend, CUDA support, scalabale LTO, sanitizers and other debugging capabilities, and more. ● High code-quality standards. 10 MPI-specifc warning messages These are not really MPI specific, but uses the “type safety” attributes inspired by this use case: int MPI_Send(void *buf, int count, MPI_Datatype datatype) __attribute__(( pointer_with_type_tag(mpi,1,3) )); … #define MPI_DATATYPE_NULL ((MPI_Datatype) 0xa0000000) #define MPI_FLOAT ((MPI_Datatype) 0xa0000001) … static const MPI_Datatype mpich_mpi_datatype_null __attribute__(( type_tag_for_datatype(mpi,void,must_be_null) )) = 0xa0000000; static const MPI_Datatype mpich_mpi_float __attribute__(( type_tag_for_datatype(mpi,float) )) = 0xa0000001; See Clang's test/Sema/warn-type-safety-mpi-hdf5.c, test/Sema/warn-type-safety.c and test/Sema/warn-type-safety.cpp for more examples, 11 and: http://clang.llvm.org/docs/AttributeReference.html#type-safety-checking Sanitizers The sanitizers (some now also supported by GCC) – Instrumentation-based debugging ● Checks get compiled in (and optimized along with the rest of the code) – Execution speed an order of magnitude or more faster than Valgrind ● You need to choose which checks to run at compile time: ● Address sanitizer: -fsanitize=address – Checks for out-of-bounds memory access, use after free, etc.: http://clang.llvm.org/docs/AddressSanitizer.html ● Leak sanitizer: Checks for memory leaks; really part of the address sanitizer, but can be enabled in a mode just to detect leaks with -fsanitize=leak: http://clang.llvm.org/docs/LeakSanitizer.html ● Memory sanitizer: -fsanitize=memory – Checks for use of uninitialized memory: http://clang.llvm.org/docs/MemorySanitizer.html ● Thread sanitizer: -fsanitize=thread – Checks for race conditions: http://clang.llvm.org/docs/ThreadSanitizer.html ● Undefined-behavior sanitizer: -fsanitize=undefined – Checks for the execution of undefined behavior: http://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html ● Efficiency sanitizer [Recent development]: -fsanitize=efficiency-cache-frag, -fsanitize=efficiency-working- set (-fsanitize=efficiency-all to get both) And there's more, check out http://clang.llvm.org/docs/ and Clang's include/clang/Basic/Sanitizers.def for more information. 12 Clang Can Compile CUDA! ● CUDA is the language used to compile code for NVIDIA GPUs. ● Support now also developed by AMD as part of their HIP project. $ clang++ axpy.cu -o axpy --cuda-gpu-arch=<GPU arch> For example: --cuda-gpu-arch=sm_35 When compiling, you may also need to pass --cuda-path=/path/to/cuda if you didn’t install the CUDA SDK into /usr/local/cuda (or a few other “standard” locations). For more information, see: http://llvm.org/docs/CompileCudaWithLLVM.html Clang's CUDA aims to provide better support for modern C++ than NVIDIA's nvcc. 13 Many Derived Vendor Products Upstream LLVM Code Base Add optimizations Add optimizations Add optimizations and other features. and other features. and other features. Package and Ship Package and Ship Package and Ship Product Product Product Vendor C Vendor A Vendor B 14 On Interacting with Open-Source LLVM When compilers are open source: ● DOE Staff, collaborators, contractors, etc. can directly contribute features and bug fixes. ● And we can review code to keep quality high (and keep the open source community healthy). ● We can enhance user productivity by delivering new features and bug fixes to our users quickly… ● This critically depends on testing! CI/testing system with large Facilities Vendor(s) amount of DOE + applications and libraries Happy users! open-source with correctness tests! LLVM DOE/ECP’s CI effort is important here! Staff, collaborators, contractors, etc. Bug fixes (and simple features) deployed to users in days (not weeks or months)! 15 Flang Approved for public release Alexis Perry–Holby (Los Alamos National Laboratory) Patrick McCormick (Los Alamos National Laboratory) Douglas Miles(NVIDIA) Stephen Scalpone (NVIDIA) Hal Finkel (Argonne National Laboratory) David Bernholdt (Oak Ridge National Laboratory) Brian Friesen (Lawrence Berkeley National Laboratory) Feb. 6th, 2020 Flang – Current Status • Working on upstreaming Flang (F18) codebase to LLVM’s main monorepo – Crucial to the long-term success of the project – Identified items are worked on collaboratively by the community • Technical work scope details: – Working on resolution of type-bound generics and operators – Completed support of forward references to derived types – Implemented logical expression lowering – Began character expression lowering – Created an expression lowering test framework – Continued work on DO loop semantic checks, especially where zeroes are not allowed – Continued work on FIR definition 2 Flang – Path to Merging into the LLVM Monorepo • CMake changes to support in-tree building – PR coming soon • Style changes that take us closer to LLVM – Clang format changes to bring Flang more in line with LLVM (PR #945) – Rationalization of public/private headers (merged PR #943) – Renaming of files from .cc to .cpp (merge PR #958) • Making more general use of LLVM APIs and data structures – Discussion of detailed list of changes is ongoing on flang-dev mailing list • Port testing to use LLVM tools (lit and FileCheck) – PR #941 ports the test suite to lit – Separate discussions of various custom scripts are ongoing The LLVM Compiler Infrastructure • Build compiler support – Need plan for improving public buildbot coverage and moving in a direction to allow ECP-centric coverage to be addressed 3 Flang – Growing Community The LLVM Compiler Infrastructure 4 Flang – Project Timeline • Schedule is currently driven by phases of the compiler (parsing, semantic analysis, lowering, etc.) • Schedule priority is on getting infrastructure complete for a functionally correct, sequential compiler – it does not necessarily reflect the steps required for full LLVM adoption. – Additional efforts working on foundational pieces (shared with Clang) for OpenMP support (i.e. OpenMP IR Builder) • Fortran-centric optimizations, including runtime library, will follow in a series of releases timed with an early release within ECP and then a drop into LLVM’s 6-month release cycle Note: Current community design discussions are considering two MLIR dialects here. One for Fortran-centric constructs and a second for OpenMP. AMD Semantic Parse Lower to FIR Analysis FIR Analysis & LLVM (Fortran 2018) (Fortran 2018) Lower to LLVM
Recommended publications
  • The LLVM Instruction Set and Compilation Strategy
    The LLVM Instruction Set and Compilation Strategy Chris Lattner Vikram Adve University of Illinois at Urbana-Champaign lattner,vadve ¡ @cs.uiuc.edu Abstract This document introduces the LLVM compiler infrastructure and instruction set, a simple approach that enables sophisticated code transformations at link time, runtime, and in the field. It is a pragmatic approach to compilation, interfering with programmers and tools as little as possible, while still retaining extensive high-level information from source-level compilers for later stages of an application’s lifetime. We describe the LLVM instruction set, the design of the LLVM system, and some of its key components. 1 Introduction Modern programming languages and software practices aim to support more reliable, flexible, and powerful software applications, increase programmer productivity, and provide higher level semantic information to the compiler. Un- fortunately, traditional approaches to compilation either fail to extract sufficient performance from the program (by not using interprocedural analysis or profile information) or interfere with the build process substantially (by requiring build scripts to be modified for either profiling or interprocedural optimization). Furthermore, they do not support optimization either at runtime or after an application has been installed at an end-user’s site, when the most relevant information about actual usage patterns would be available. The LLVM Compilation Strategy is designed to enable effective multi-stage optimization (at compile-time, link-time, runtime, and offline) and more effective profile-driven optimization, and to do so without changes to the traditional build process or programmer intervention. LLVM (Low Level Virtual Machine) is a compilation strategy that uses a low-level virtual instruction set with rich type information as a common code representation for all phases of compilation.
    [Show full text]
  • A DSL for Resource Checking Using Finite State Automaton-Driven Symbolic Execution Code
    Open Comput. Sci. 2021; 11:107–115 Research Article Endre Fülöp and Norbert Pataki* A DSL for Resource Checking Using Finite State Automaton-Driven Symbolic Execution https://doi.org/10.1515/comp-2020-0120 code. Compilers validate the syntactic elements, referred Received Mar 31, 2020; accepted May 28, 2020 variables, called functions to name a few. However, many problems may remain undiscovered. Abstract: Static analysis is an essential way to find code Static analysis is a widely-used method which is by smells and bugs. It checks the source code without exe- definition the act of uncovering properties and reasoning cution and no test cases are required, therefore its cost is about software without observing its runtime behaviour, lower than testing. Moreover, static analysis can help in restricting the scope of tools to those which operate on the software engineering comprehensively, since static anal- source representation, the code written in a single or mul- ysis can be used for the validation of code conventions, tiple programming languages. While most static analysis for measuring software complexity and for executing code methods are designed to detect anomalies (called bugs) in refactorings as well. Symbolic execution is a static analy- software code, the methods they employ are varied [1]. One sis method where the variables (e.g. input data) are inter- major difference is the level of abstraction at which the preted with symbolic values. code is represented [2]. Because static analysis is closely Clang Static Analyzer is a powerful symbolic execution related to the compilation of the code, the formats used engine based on the Clang compiler infrastructure that to represent the different abstractions are not unique to can be used with C, C++ and Objective-C.
    [Show full text]
  • SMT-Based Refutation of Spurious Bug Reports in the Clang Static Analyzer
    SMT-Based Refutation of Spurious Bug Reports in the Clang Static Analyzer Mikhail R. Gadelha∗, Enrico Steffinlongo∗, Lucas C. Cordeiroy, Bernd Fischerz, and Denis A. Nicole∗ ∗University of Southampton, UK. yUniversity of Manchester, UK. zStellenbosch University, South Africa. Abstract—We describe and evaluate a bug refutation extension bit in a is one, and (a & 1) ˆ 1 inverts the last bit in a. for the Clang Static Analyzer (CSA) that addresses the limi- The analyzer, however, produces the following (spurious) bug tations of the existing built-in constraint solver. In particular, report when analyzing the program: we complement CSA’s existing heuristics that remove spurious bug reports. We encode the path constraints produced by CSA as Satisfiability Modulo Theories (SMT) problems, use SMT main.c:4:12: warning: Dereference of null solvers to precisely check them for satisfiability, and remove pointer (loaded from variable ’z’) bug reports whose associated path constraints are unsatisfi- return *z; able. Our refutation extension refutes spurious bug reports in ˆ˜ 8 out of 12 widely used open-source applications; on aver- age, it refutes ca. 7% of all bug reports, and never refutes 1 warning generated. any true bug report. It incurs only negligible performance overheads, and on average adds 1.2% to the runtime of the The null pointer dereference reported here means that CSA full Clang/LLVM toolchain. A demonstration is available at claims to nevertheless have found a path where the dereference https://www.youtube.com/watch?v=ylW5iRYNsGA. of z is reachable. Such spurious bug reports are in practice common; in our I.
    [Show full text]
  • CUDA Flux: a Lightweight Instruction Profiler for CUDA Applications
    CUDA Flux: A Lightweight Instruction Profiler for CUDA Applications Lorenz Braun Holger Froning¨ Institute of Computer Engineering Institute of Computer Engineering Heidelberg University Heidelberg University Heidelberg, Germany Heidelberg, Germany [email protected] [email protected] Abstract—GPUs are powerful, massively parallel processors, hardware, it lacks verbosity when it comes to analyzing the which require a vast amount of thread parallelism to keep their different types of instructions executed. This problem is aggra- thousands of execution units busy, and to tolerate latency when vated by the recently frequent introduction of new instructions, accessing its high-throughput memory system. Understanding the behavior of massively threaded GPU programs can be for instance floating point operations with reduced precision difficult, even though recent GPUs provide an abundance of or special function operations including Tensor Cores for ma- hardware performance counters, which collect statistics about chine learning. Similarly, information on the use of vectorized certain events. Profiling tools that assist the user in such analysis operations is often lost. Characterizing workloads on PTX for their GPUs, like NVIDIA’s nvprof and cupti, are state-of- level is desirable as PTX allows us to determine the exact types the-art. However, instrumentation based on reading hardware performance counters can be slow, in particular when the number of the instructions a kernel executes. On the contrary, nvprof of metrics is large. Furthermore, the results can be inaccurate as metrics are based on a lower-level representation called SASS. instructions are grouped to match the available set of hardware Still, even if there was an exact mapping, some information on counters.
    [Show full text]
  • Implementing Continuation Based Language in LLVM and Clang
    Implementing Continuation based language in LLVM and Clang Kaito TOKUMORI Shinji KONO University of the Ryukyus University of the Ryukyus Email: [email protected] Email: [email protected] Abstract—The programming paradigm which use data seg- 1 __code f(Allocate allocate){ 2 allocate.size = 0; ments and code segments are proposed. This paradigm uses 3 goto g(allocate); Continuation based C (CbC), which a slight modified C language. 4 } 5 Code segments are units of calculation and Data segments are 6 // data segment definition sets of typed data. We use these segments as units of computation 7 // (generated automatically) 8 union Data { and meta computation. In this paper we show the implementation 9 struct Allocate { of CbC on LLVM and Clang 3.7. 10 long size; 11 } allocate; 12 }; I. A PRACTICAL CONTINUATION BASED LANGUAGE TABLE I The proposed units of programming are named code seg- CBCEXAMPLE ments and data segments. Code segments are units of calcu- lation which have no state. Data segments are sets of typed data. Code segments are connected to data segments by a meta data segment called a context. After the execution of a code have input data segments and output data segments. Data segment and its context, the next code segment (continuation) segments have two kind of dependency with code segments. is executed. First, Code segments access the contents of data segments Continuation based C (CbC) [1], hereafter referred to as using field names. So data segments should have the named CbC, is a slight modified C which supports code segments.
    [Show full text]
  • Compiling and Makefiles
    Compiling C Programs Makefiles Compiling and Makefiles 2501ICT/7421ICTNathan René Hexel School of Information and Communication Technology Griffith University Semester 1, 2012 René Hexel Compiling and Makefiles Compiling C Programs Makefiles Outline 1 Compiling C Programs 2 Makefiles Using the make Utility Makefiles for Objective-C Code Makefiles for C++ Code René Hexel Compiling and Makefiles Compiling C Programs Makefiles Compiling C Programs Integrated Development Environment (IDE) Eclipse, XCode, Visual C++, Project Center, . Compiles programs at the press of a button (like BlueJ) Often difficult to customise Very rarely support multiple platforms and languages Command Line Requires manual invocation Requires knowledge of command line parameters Can be tedious for large projects Cross-platform and -language compilers (e.g. clang) Makefiles Combine the best of both worlds Recompile a complex project with a simple make command René Hexel Compiling and Makefiles Compiling C Programs Makefiles Getting a Command Line Interface Via Dwarf ssh dwarf.ict.griffith.edu.au using putty (Windows) Via a local Terminal Mac OS X: e.g. Applications / Utilities / Terminal.app Linux: e.g. through the Gnome program menu Windows: e.g. Start / Programs / Programming Tools / GNUstep / Shell ) Enter commands to compile your program Hit Return (or Enter) after every command! René Hexel Compiling and Makefiles Compiling C Programs Makefiles Compiling a C program using clang or gcc Once on the command line change to the directory (folder) your program is in cd /my/example/directory
    [Show full text]
  • ENCM 335 Fall 2018: Command-Line C Programming on Macos
    page 1 of 4 ENCM 335 Fall 2018: Command-line C programming on macOS Steve Norman Department of Electrical & Computer Engineering University of Calgary September 2018 Introduction This document is intended to help students who would like to do ENCM 335 C pro- gramming on an Apple Mac laptop or desktop computer. A note about software versions The information in this document was prepared using the latest versions of macOS Sierra version 10.12.6 and Xcode 9.2, the latest version of Xcode available for that version of macOS. Things should work for you if you have other but fairly recent versions of macOS and Xcode. If you have versions that are several years old, though you may experience difficulties that I'm not able to help with. Essential Software There are several key applications needed to do command-line C programming on a Mac. Web browser I assume you all know how to use a web browser to find course documents, so I won't say anything more about web browsers here. Finder Finder is the tool built in to macOS for browsing folders and files. It really helps if you're fluent with its features. Terminal You'll need Terminal to enter commands and look at output of commands. To start it up, look in Utilities, which is a folder within the Applications folder. It probably makes sense to drag the icon for Terminal to the macOS Dock, so that you can launch it quickly. macOS Terminal runs the same bash shell that runs in Cygwin Terminal, so commands like cd, ls, mkdir, and so on, are all available on your Mac.
    [Show full text]
  • Compiling Linux with LLVM
    Open Source Open Possibilities Compiling Linux with LLVM Presented by: Mark Charlebois Presentation Date: 06/07/2012 PAGE 1 Open Source Open Possibilities Agenda Why would I want to use Clang to compile Linux? Status updates: cross compiling for ARM with Clang building Linux kernel with Clang running Linux compiled with Clang To do list PAGE 2 Open Source Open Possibilities Open Source Open Possibilities Why Would I Want to Use Clang to Compile Linux? PAGE 3 Open Source Open Possibilities Better Diagnostics $ gcc-4.2 -fsyntax-only t.c t.c:7: error: invalid operands to binary + (have 'int' and 'struct A') $ clang -fsyntax-only t.c t.c:7:39: error: invalid operands to binary expression ('int' and 'struct A') return y + func(y ? ((SomeA.X + 40) + SomeA) / 42 + SomeA.X : SomeA.X); ~~~~~~~~~~~~~~ ^ ~~~~~ See http://clang.llvm.org/diagnostics.html for more examples GCC extensions: all extensions are explicitly recognized as such and marked with extension diagnostics, which can be mapped to warnings, errors, or just ignored. Google builds their products also with Clang just for the better debug output Rich diagnostic output enables auto-generation of patches PAGE 4 Open Source Open Possibilities Fix-it Hints "Fix-it" hints provide advice for fixing small, localized problems in source code. $ clang t.c t.c:5:28: warning: use of GNU old-style field designator extension struct point origin = { x: 0.0, y: 0.0 }; ~~ ^ .x = t.c:5:36: warning: use of GNU old-style field designator extension struct point origin = { x: 0.0, y: 0.0 }; ~~ ^ .y = PAGE 5
    [Show full text]
  • Code Transformation and Analysis Using Clang and LLVM Static and Dynamic Analysis
    Code transformation and analysis using Clang and LLVM Static and Dynamic Analysis Hal Finkel1 and G´abor Horv´ath2 Computer Science Summer School 2017 1 Argonne National Laboratory 2 Ericsson and E¨otv¨osLor´adUniversity Table of contents 1. Introduction 2. Static Analysis with Clang 3. Instrumentation and More 1 Introduction Space of Techniques During this set of lectures we'll cover a space of techniques for the analysis and transformation of code using LLVM. Each of these techniques have overlapping areas of applicability: Static Analysis LLVM Instrumentation Source Transformation 2 Space of Techniques When to use source-to-source transformation: • When you need to use the instrumented code with multiple compilers. • When you intend for the instrumentation to become a permanent part of the code base. You'll end up being concerned with the textual formatting of the instrumentation if humans also need to maintain or enhance this same code. 3 Space of Techniques When to use Clang's static analysis: • When the analysis can be performed on an AST representation. • When you'd like to maintain a strong connection to the original source code. • When false negatives are acceptable (i.e. it is okay if you miss problems). https://clang-analyzer.llvm.org/ 4 Space of Techniques When to use IR instrumentation: • When the necessary conditions can be (or can only be) detected at runtime (often in conjunction with a specialized runtime library). • When you require stronger coverage guarantees than static analysis. • When you'd like to reduce the cost of the instrumentation by running optimizations before the instrumentation is inserted, after the instrumentation is inserted, or both.
    [Show full text]
  • Sham: a DSL for Fast Dsls
    Sham: A DSL for Fast DSLs Rajan Waliaa, Chung-chieh Shana, and Sam Tobin-Hochstadta a Indiana University, Bloomington, United States Abstract Domain-specific languages (DSLs) are touted as both easy to embed in programs and easy to optimize. Yet these goals are often in tension. Embedded or internal DSLs fit naturally with a host language, while inheriting the host’s performance characteristics. External DSLs can use external optimizers and languages but sit apart from the host. We present Sham, a toolkit designed to enable internal DSLs with high performance. Sham provides a domain-specific language (embedded in Racket) for implementing other high-performance DSLs, with transparent compilation to assembly code at runtime. Sham is well suited as both a compilation target for other embedded DSLs and for transparently replacing DSL support code with faster versions. Sham provides seamless inter-operation with its host language without requiring any additional effort from its users. Sham also provides a framework for defining language syntax which implements Sham’s own language interface as well. We validate Sham’s design on a series of case studies, ranging from Krishnamurthi’s classic automata DSL to a sound synthesis DSL and a probabilistic programming language. All of these are existing DSLs where we replaced the backend using Sham, resulting in major performance gains. We present an example-driven description of how Sham can smoothly enhance an existing DSL into a high-performance one. When compared to existing approaches for implementing high-performance DSLs, Sham’s design aims for both simplicity and programmer control. This makes it easier to port our techniques to other languages and frameworks, or borrow Sham’s innovations “à la carte” without adopting the whole approach.
    [Show full text]
  • Introduction to LLVM (Low Level Virtual Machine)
    Introduction to LLVM (Low Level Virtual Machine) Fons Rademakers CERN What is the LLVM Project? • Collection of compiler technology components ■ Not a traditional “Virtual Machine” ■ Language independent optimizer and code generator ■ LLVM-GCC front-end ■ Clang front-end ■ Just-In-Time compiler • Open source project with many contributors ■ Industry, research groups, individuals ■ See http://llvm.org/Users.html • Everything is Open Source, and BSD Licensed! (except GCC) • For more see: http://llvm.org/ 2 LLVM as an Open-Source Project • Abridged project history ■ Dec. 2000: Started as a research project at University of Illinois ■ Oct. 2003: Open Source LLVM 1.0 release ■ June 2005: Apple hires project lead Chris Lattner ■ June 2008: LLVM GCC 4.2 ships in Apple Xcode 3.1 ■ Feb. 2009: LLVM 2.5 3 Why New Compilers? • Existing Open Source C Compilers have Stagnated! • How? ■ Based on decades old code generation technology ■ No modern techniques like cross-file optimization and JIT codegen ■ Aging code bases: difficult to learn, hard to change substantially ■ Can’t be reused in other applications ■ Keep getting slower with every release 4 LLVM Vision and Approach • Build a set of modular compiler components: ■ Reduces the time & cost to construct a particular compiler ■ Components are shared across different compilers ■ Allows choice of the right component for the job ■ Focus on compile and execution times ■ All components written in C++, ported to many platforms 5 First Product - LLVM-GCC 4.2 • C, C++, Objective C, Objective C++, Ada and Fortran • Same GCC command line options • Supports almost all GCC language features and extensions • Supports many targets, including X86, X86-64, PowerPC, etc.
    [Show full text]
  • Polymorphisation: Improving Rust Compilation Times Through
    Polymorphisation: Improving Rust compilation times through intelligent monomorphisation David Wood (2198230W) April 15, 2020 MSci Software Engineering with Work Placement (40 Credits) ABSTRACT In addition, Rust's compilation model is different from Rust is a new systems programming language, designed to other programming languages. In C++, the compilation unit is a single file, whereas Rust's compilation unit is a provide memory safety while maintaining high performance. 1 One of the major priorities for the Rust compiler team is crate . While compilation times of entire C++ and entire to improve compilation times, which is regularly requested Rust projects are generally comparable, modification of a by users of the language. Rust's high compilation times are single C++ file requires far less recompilation than modifi- a result of many expensive compile-time analyses, a com- cation of a single Rust file. In recent years, implementation pilation model with large compilation units (thus requiring of incremental compilation into rustc has improved recom- incremental compilation techniques), use of LLVM to gen- pilation times after small modifications to code. erate machine code, and the language's monomorphisation Rust generates machine code using LLVM, a collection of strategy. This paper presents a code size optimisation, im- modular and reusable compiler and toolchain technologies. plemented in rustc, to reduce compilation times by intelli- At LLVM's core is a language-independent optimiser, and gently reducing monomorphisation through \polymorphisa- code-generation support for multiple processors. Languages tion" - identifying where functions could remain polymor- including Rust, Swift, Julia and C/C++ have compilers us- phic and producing fewer monomorphisations.
    [Show full text]