1 Samsung Open Source Group Where is LLVM being used today? Tilmann Scheller Senior LLVM Compiler Engineer [email protected] Samsung Open Source Group Samsung Research UK FOSDEM 2016 Brussels, Belgium, January 30 – 31, 2016
1Samsung Open Source Group
Where is LLVM being used today?
Tilmann SchellerSenior LLVM Compiler Engineer
Samsung Open Source GroupSamsung Research UK
FOSDEM 2016Brussels, Belgium, January 30 – 31, 2016
2Samsung Open Source Group
Overview
● Introduction
● LLVM Overview
● Projects
● Summary
3Samsung Open Source Group
Introduction
4Samsung Open Source Group
What is LLVM?
● Mature, production-quality compiler framework
● Modular architecture
● Heavily optimizing static and dynamic compiler
● Supports all major architectures (x86, ARM, MIPS, PowerPC, …)
● Powerful link-time optimizations (LTO)
● Permissive license (BSD-like)
5Samsung Open Source Group
Which companies are contributing?
®
6Samsung Open Source Group
History
● Started as Chris Lattner's Master's Thesis at UIUC
● LLVM 1.0 released in October 2003
● LLVM 3.8 about to be released
● Today: LLVM + Clang together 2.5 million LOC of C++ code
7Samsung Open Source Group
LLVM sub-projects
● Clang
C/C++/Objective C frontend and static analyzer
● LLDB
Next generation debugger leveraging the LLVM libraries, e.g. the Clang expression parser
● lld
Framework for creating linkers, will make Clang independent of the system linker in the future
● Polly
Polyhedral optimizer for LLVM, e.g. high-level loop optimizations and data-locality optimizations
8Samsung Open Source Group
LLVM Overview
9Samsung Open Source Group
LLVM
● LLVM IR (Intermediate Representation)
● Scalar optimizations
● Interprocedural optimizations
● Auto-vectorizer (BB, Loop and SLP)
● Profile-guided optimizations
10Samsung Open Source Group
Compiler architecture
C Frontend
C++ Frontend
Fortran Frontend
Optimizer
x86 Backend
ARM Backend
MIPS Backend
11Samsung Open Source Group
Compilation steps
● Many steps involved in the translation from C source code to machine code:
– Frontend:
● Lexing, Parsing, AST construction● Translation to LLVM IR
– Middle-end
● Target-independent optimizations (Analyses & Transformations)
– Backend:
● Translation into a DAG● Instruction selection: Pattern matching on the DAG● Instruction scheduling: Assigning an order of execution● Register allocation: Trying to reduce memory traffic
12Samsung Open Source Group
Clang
● Goals:
– Fast compile time
– Low memory usage
– GCC compatibility
– Expressive diagnostics
● Several tools built on top of Clang:
– Clang static analyzer
– clang-format, clang-modernize, clang-tidy
13Samsung Open Source Group
Projects
14Samsung Open Source Group
Traditional C/C++ Toolchain
● Apple iOS/OS X SDK
● Android NDK
● Tizen SDK
● Sony PS4 SDK
● Qualcomm Snapdragon LLVM Compiler for Android
15Samsung Open Source Group
Programming languages
● Swift
● Haskell: GHC, LHC, UHC
● Ruby: Rubinius, RubyMotion
● Python: Pyston
● Common Lisp: Clasp
● D: LDC
● Go: llgo
16Samsung Open Source Group
Programming languages
● Standard ML: MLton, SML#, Ex-SML
● Rust
● Julia
● Pure
● Ravi
17Samsung Open Source Group
Language Runtime Systems
● VMKit (unmaintained)
● LLILC - LLVM-based .NET MSIL compiler
● Mono
● OpenJDK
18Samsung Open Source Group
GPU
● LLVMpipe (software rasterizer)
● CUDA
● GLSL (LunarGLASS)
● AMDGPU open source drivers
● SPIR
● Majority of OpenCL implementations based on
Clang/LLVM
19Samsung Open Source Group
Web
● PNaCl
● WebKit FTL JIT
● Emscripten
● WebAssembly
20Samsung Open Source Group
Sanitizers
● AddressSanitizers
● MemorySanitizer
● ThreadSanitizer
● LeakSanitizer
● SAFECode
21Samsung Open Source Group
Integrated Development Environments
● Xcode
● KDevelop
● CodeLite
● Qt Creator
● Geany
22Samsung Open Source Group
Source code navigation
● Doxygen
● Woboq Code Browser
● YouCompleteMe - Code completion for Vim
● clang-tags
● clang-ctags
● clang_complete - Code completion for Vim
● rtags - Indexer for C/C++ with Emacs integration
23Samsung Open Source Group
Out of tree LLVM backends
● RISC-V
● OpenRISC 1000
● VideoCore IV (VPU/QPU)
● LatticeMico32
● AAP
24Samsung Open Source Group
Binary translation
● llvm-qemu
● Dagger
● McSema
● libcpu
● Fracture
● SkyEye
25Samsung Open Source Group
Symbolic Execution/Formal Verification
● KLEE
● S2E
● K framework with formal semantics for LLVM IR
26Samsung Open Source Group
Linux/FreeBSD
● Debian experimenting with Clang as an additional compiler (94.1% of ~22k packages successfully build with Clang 3.6)
● LLVMLinux
● OpenMandriva Lx
● FreeBSD
27Samsung Open Source Group
Misc
● Emacs fork using the LLVM JIT for Elisp byte code execution :)
● Cling - C++ interpreter
● CodeChecker - Web frontend for the Clang static analyzer
● include-what-you-use
● clang-closure
● Numba
28Samsung Open Source Group
Summary
29Samsung Open Source Group
Summary
● Wide range of different projects
● New frontends being written constantly
● Great compiler infrastructure
● Fast C/C++ compiler with expressive diagnostics
30Samsung Open Source Group
Give it a try!
● Visit llvm.org
● Distributions with Clang/LLVM packages:
– Fedora
– Debian/Ubuntu
– openSUSE
– Arch Linux
– ...and many more
Thank you.
31Samsung Open Source Group
32Samsung Open Source Group
Contact Information:
Tilmann [email protected]
Samsung Open Source GroupSamsung Research UK