Build Programming Language Runtime with LLVM

  • Published on

  • View

  • Download

Embed Size (px)

DESCRIPTION 2009 Compiler -- LLVM Compiler Infrastructure /


  • 1. Build Programming Language Runtime with LLVMJim Huang ( )Developer & Co-founder, 0xlab @ 1500 / March 27, 2011
  • 2. Build Programming Language Runtime with LLVMJim Huang ( )Developer & Co-founder, 0xlab @ 1500 (?!) / March 27, 2011
  • 3. 150010 = 05DC16 OSDC ! Open Source Developer Conference 0x05DC About 0xlab The meaning of open 0x1ab16 = 42710 2009/04/27 About me
  • 4. Rights to copy Copyright 2011 0xlab contact@0xlab.orgAttribution ShareAlike 3.0You are free Corrections, suggestions, contributions and translations are welcome! to copy, distribute, display, and perform the work to make derivative works Latest update:March 27, 2011 to make commercial use of the workUnder the following conditions Attribution. You must give the original author credit. Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of these conditions can be waived if you get permission from the copyright holder.Your fair use and other rights are in no way affected by the above.License text:
  • 5. Compiler 2009
  • 6. LLVM , TOSSUG 2009 Applied Computer Science Concepts in Android 2010 from Source to Binary -- How GNU Toolchain Works 2011/03/31
  • 7. (1) Compilers on Rails (2) LLVM (3) (Low-Level ) -> -> (4) LLVM
  • 8. Compilers on Rails
  • 9. Compilers on Rails [ ] on the rails: ; [ ] Ruby on Rails: (1) convention over configuration (2) less software (3) programmer happiness ultimately leads to better productivity
  • 10. Compiler Java / .Net ( +Just-In-Time compiler) Mozilla/Firefox (ActionMonkey/Tamarin) WebKit (SquirrelFish) Google Chrome (V8 engine) Web JSP/Servlet, SilverLight/.Net Java ME, Android, iPhone, Portable Native Client Adobe PixelBender, Shader 3D Gallium3D / OpenGL / Direct3D / RenderScript (Android)
  • 11. Compiler Source Code Assembly Code Runnable CodeCompiler Assembler Loader System User Intermediate Code Binary Code DATAIR (Intermediate Representation) Compiler LLVM = Low Level Virtual Machine
  • 12. color space color space Specialize BGRA 444R RGBA 8888 BGRA 444R RGBA 8888Speedup depends on src/dest format: Speedup depends on src/dest format: 5.4x speedup average, 19.3x speedup max 5.4x speedup average, 19.3x speedup max(13.3MB/s to 257.7MB/s) (13.3MB/s to 257.7MB/s)
  • 13. Compiler Framework-driven SIMD/vectorization, Cell, SMP/multi-core (Virtualization) (cross-over) LLVM Portable Native Client, OpenCL (GPGPU)
  • 14. VMJava Virtual Machine (JVM) Tamarin (ActionScript).NET Common Language Valgrind (C++) Runtime (CLR) LuaSmalltalk TrueTypeSqueak DalvikParrot (Perl 6) Adobe Flash (AVM2)Python p-code (USCD Pascal)YARV (Ruby 1.9) ZendRubinius 14LLVM
  • 15. LLVM
  • 16. LLVM Low-Level VM bit-code static compiler, JIT, trace-based optimizer, (BSD License) (50% Apple Inc.) C, ARM, x86, PowerPC,
  • 17. Assemblers, automatic debugger, linker, codegenerator, compiler driver, modular optimizer, Eric Schmidt UNIX lex Eric Schmidt UNIX lex
  • 18. GCC vs. LLVMGCC LLVMC, C++, Obj-C, Fortran, Java, Ada, ... C, C++, Obj-Cx86, ARM, MIPS, PowerPC, binutils (ld as) BSD-Style License JIT/InterpreterCompiler Driver
  • 19. Frontend LLVM IR Backend
  • 20. Frontend LLVM IR Backend
  • 21. CodeMark Pentium4 3.0GHz Ubuntu: -Os -O3 -fast size: kbytes10000 409000 LLVM GCC Intel CC 358000 307000 2560005000 204000 153000 102000 51000 0 0 clang-2.8 Os clang-2.6 O3 clang-2.8 fast gcc-4.4.3 Os gcc-4.4.3 O3 gcc-4.4.3 fast icc-12 Os icc-12 O3 icc-12 fast
  • 22. LLVM
  • 23. LLVM + Clang
  • 24. Clang: LLVM C x86 ClangC++ $clangmain.cmod.c ARM Obj-C Clang driver libClang ld libLLVM as
  • 25. Clang LLVM libClang libLLVM [C] BitCodemain.c main.bc x86 main.s [C] Source BitCode Code Optimizermod.c BitCode mod.bc Generator
  • 26. Clang [C] libClang BitCodemain.c main.bc lex codegen [C] AST BitCodemod.c mod.bc parse Analysis Serialize/ semantics Deserialize Checker Indexer AST AST IDE main.ast mod.ast / (Xcode)
  • 27. BitCode + Optimizer LTO: Link-Time Optimization LTO: Link-Time OptimizationBitCodemain.bc Inter-precedual BitCode LinkerBitCode Analysis Transformsmod.bc BitCode BitCode BitCode parser writer main.lto.bc BitCode Analysis Transforms BitCode BitCode main.opt.bc mod.opt.bc
  • 28. LLVM Code Generation libLLVM BitCode Machinemain.lto.bc Analysis x86 BitCode Machine main.s BitCode parser Instr Machine Asm Transforms Emitter Execution Transform Transform Register Engine CodeGen Machine SDNode Allocation InterPreter Instr InstrInfo Register Instruction Instruction Subtarget [C++] Selection Scheduler InstrInfo Frame Register main.cpp [C] Lowering x86 Subtarget CallbackUtils main.c SDNode CallingConv Frame Transforms Lowering Selection DAG CallingConv Selection DAG
  • 29. Hello World Compiler Driver $clanghello.cohello IR $clangO3emitllvmhello.ccohello.bc Just-In-Time compiler BitCode $llihello.bcGetting Started with the LLVM SystemGetting Started with the LLVM System
  • 30. #include #include intmain(intargc,char*argv[]) intmain(intargc,char*argv[]) { { printf("Helloworld!n"); printf("Helloworld!n")...