LLVM — A Compilation Framework for Lifelong Program Analysis & Transformation
"LLVM: A Compilation Framework for Lifelong Program Analysis & Transformation", Chris Lattner and Vikram Adve.
Proceedings of the 2004 International Symposium on Code Generation and Optimization (CGO'04), Palo Alto, California, Mar. 2004.
Transformation Chris Lattner, Vikram Adve; Unversity of Illinois at Urbana-Champaign 2004 International Symposium on Code Generation and Optimization (CGO’04) [ Shao-Chung Chen ] VIPLab Group Meeting / Feb. 01, 2013 Dept. of Computer Science and Information E., NTNU
• compile-time, link-time, install-time, run-time, idle-time • aggressive interprocedural optimizations • gather & exploit end-user profile information • optimize to the user’s hardware • constraints • cannot interfere with the build process • must support multiple source-languages • must integrate with legacy systems and compnents
for analysis & optimization throughout lifetime • offline native code generation • generate high-quality code statically • profiling & optimization in the field • adapt to the end-user’s usage patterns (profile info) • language independence • no runtime, object model, or exception semantics • uniform whole-program optimization • optimization across language and runtime
typed) representation • type information: important high-level analysis • code representation is truly language neutral • offline and runtime native code generation • LLVM contributions (from 2004) • novel features for language independence • typed pointer arithmetic, exception mechanisms • novel capabilities • first to support all 5 capabilities for livelong optimization
• primitives — void, bool, float, ushort, opaque, ... • derived — pointer, array, structure, function • no high-level types, type-system is language netural • source language types are lowered (to low-level) • e.g. T& — T* • e.g. class T : S { int x; } — { S, int } • type system allows arbitrary casts • expressing non-type-safe language, like C • type information in LLVM representation will be checked
address • &A->field_1 — getelementptr {int, int}* A, uint 1 • &B[i] — getelementptr [10 x int]* B, long i • key feature for several high-level analyses • field information for field-sensitive alias analysis • array subscript information for dependence analysis
exceptions • don’t specify exception semantics (C, C++, Java) • critical for language independence • provides two simple instructions • invoke — call to a function needing an exception handler • unwind — unwind stack frames until reaching an invoke • supports general stack unwinding • setjmp/longjmp implemented as “exceptions” • full C++ exception handling model is implemented • sufficient for: C, C++, Java, C#, OCaml, ...
code representation • LLVM to LLVM optimizations can happen at any time • offline native code generation • generate high-quality machine code, retaining LLVM • profiling & optimization in the field • runtime & offline profile-driven optimizers • language independence • low-level instruction set & type with transparent runtime • uniform whole-program optimization • optimize across source-language boundries
• oh, yes! • how big are programs in LLVM? • almost the same size to x86 binary programs • how reliable is the type information? • is it useful for anything? • yes, it enables optimization (even for C codes) • structure reorganization • how fast is the optimizer? • is it suitable for runtime & interprocedural optimization? • yes, much faster than GCC with -O3
as machine code, yet support high-level optimization • new abstraction of exceptions • type-safe pointer arithmetic for high-level analysis/ optimization • novel capabilities • first to provide all 5 capabilities • practical
• optimizer and JIT codegen for the Hydra Language • alchemy C/C++ Compiler for ActionScript Virtual Machine • Apple Inc. • Xcode 3.2+ (latest version is 4.2) • Mac OS X 10.7 & iOS 5+, all built with clang & llvm-gcc • Intel • OpenCL • NVIDIA • OpenCL runtime compiler (clang + llvm-gcc) • REAL Software • optimizer & codegen for RBScript & REAL Studio Compiler
standard GCC command line options • supports almost all GCC language features & exts • x86, x86-64, PowerPC, ... • extremely compatible with GCC 4.2 • drop-in replacement