KEMBAR78
Build Programming Language Runtime with LLVM | PDF
Build Programming Language
     Runtime with LLVM



Jim Huang ( é»ƒę•¬ē¾¤ )
Developer & Co-founder, 0xlab
                                       jserv@0xlab.org

                                @ 1500 / March 27, 2011
150010 = 05DC16
• OSDC !
   • Open Source Developer Conference
   • 0x05DC
• About 0xlab
   • The meaning of open
   • 0x1ab16 = 42710 → 2009/04/27
• About me
   • http://about.me/jserv
  • ęœ€å¤§ēš„å°ˆé•·å°±ę˜ÆåŸ¹é¤Ščˆˆč¶£
Rights to copy
                                                                    © Copyright 2011 0xlab
                                                                           http://0xlab.org/
                                                                            contact@0xlab.org
Attribution – ShareAlike 3.0
You 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 work
Under 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: http://creativecommons.org/licenses/by-sa/3.0/legalcode
å§Šå¦¹č­°ēØ‹ļ¼š
                             ć€ˆēŖ®å¾—åŖå‰©äø‹ Compiler 怉
                                  OSDC.tw 2009
http://www.slideshare.net/jserv/what-can-compilers-do-for-us
å§Šå¦¹č­°ēØ‹ļ¼š
                                   ć€ˆčŗ«éØŽ LLVM , éŽäø‰é—œļ¼š
                               ę·ŗč«‡ē·Øč­Æå™ØęŠ€č”“ēš„å¶„ę–°ę‡‰ē”Øć€‰
                                              TOSSUG 2009
            http://www.slideshare.net/jserv/llvm-introduction

                                           å§Šå¦¹č­°ēØ‹ļ¼š
     怈 Applied Computer Science Concepts in Android 怉
                                    å°å¤§č³‡čØŠē³» 2010
http://www.slideshare.net/jserv/applied-computer-science-concepts-in-android


                                           å§Šå¦¹č­°ēØ‹ļ¼š
怈 from Source to Binary -- How GNU Toolchain Works 怉
                  č‡ŗåŒ—ē§‘ęŠ€å¤§å­øč³‡čØŠå·„ēØ‹ę‰€ 2011/03/31
ęē¶±   (1) Compilers on Rails ēš„ę™‚ä»£
     (2) ęŽ¢ē“¢ LLVM
     (3) ēØ‹å¼čŖžčØ€ēš„č®Šé· (Low-Level 觀點 )
       傳統 -> å‹•ę…‹ -> 移動運算
     (4) LLVM 實例
Compilers on Rails ēš„ę™‚ä»£
Compilers on Rails ēš„ę™‚ä»£

[ č©žå½™ ] on the rails: ę­£åøøé‹č”Œ ; åœØę­£åøøč»Œé“
[ å•Ÿē™¼ ] Ruby on Rails:
 (1) convention over configuration
 (2) less software
 (3) programmer happiness ultimately leads to better productivity
éš±č—åœØęˆ‘å€‘čŗ«é‚Šēš„ 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)
å‚³ēµ±ēš„ Compiler 流程
 Source Code           Assembly Code        Runnable Code




Compiler   Assembler    Loader     System        User




           Intermediate Code       Binary Code              DATA

IR (Intermediate Representation) åÆčŖŖę˜Æ Compiler ēš„åæƒč‡Ÿ

LLVM = Low Level Virtual Machine
仄 color space č½‰ę›ä¾†čŖŖļ¼ŒåŸ·č”Œ
                     仄 color space č½‰ę›ä¾†čŖŖļ¼ŒåŸ·č”Œ
   Specialize ęŠ€å·§     ę™‚ęœŸå¾—č² ę“”å¤§é‡äø”ē¹ē‘£ēš„é‹ē®—ļ¼Œ
                     ę™‚ęœŸå¾—č² ę“”å¤§é‡äø”ē¹ē‘£ēš„é‹ē®—ļ¼Œ
                     如 BGRA 444R→ RGBA 8888
                     如 BGRA 444R→ RGBA 8888




Speedup 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)
Compiler é ˜å°ŽęŠ€č”“ēš„ę™‚ä»£
    • é‹ē®—ęØ”å¼å·²å¤§å¹…ę”¹č§€
    • Framework-driven
    • SIMD/vectorization, Cell, SMP/multi-core
    • č™›ę“¬åŒ– (Virtualization) ęŠ€č”“ēš„ę™‚ä»£
        → ę›“å¤šå…ƒć€ę›“å®‰å…Øć€ę›“ęœ‰ę•ˆēŽ‡åœ°ä½æē”Øē”¬é«”
    • č³‡čØŠęŠ€č”“ēš„é›œäŗ¤ (cross-over)
    • LLVM ēš„å¤§äø€ēµ±å®é”˜



ę”ˆä¾‹ļ¼š
Portable Native Client, OpenCL (GPGPU)
åˆ°č™•éƒ½ęœ‰ VM
Java Virtual Machine (JVM)   Tamarin (ActionScript)
.NET Common Language         Valgrind (C++)
  Runtime (CLR)
                             Lua
Smalltalk
                             TrueType
Squeak
                             Dalvik
Parrot (Perl 6)
                             Adobe Flash (AVM2)
Python
                             p-code (USCD Pascal)
YARV (Ruby 1.9)
                             Zend
Rubinius

                                                      13
LLVM åÆä½œē‚ŗäøŠčæ°ēš„ē·Øč­Æå™Øę‡‰ē”Øēš„ę ¹åŸŗ
ęŽ¢ē“¢ LLVM
LLVM
• Low-Level VM → bit-code
• å®Œę•“ēš„ē·Øč­Æå™ØåŸŗē¤Žå»ŗčØ­
   • åÆé‡ē”Øēš„ć€ē”Øä»„å»ŗę§‹ē·Øč­Æå™Øēš„č»Ÿé«”å…ƒä»¶
   • å…čØ±ę›“åæ«ę›“å®Œę•“ēš„ę‰“é€ ę–°ēš„ē·Øč­Æå™Ø
   • static compiler, JIT, trace-based optimizer, …
• é–‹ę”¾ēš„ē·Øč­Æå™Øę”†ęž¶
   • å¤šēØ®ēØ‹å¼čŖžčØ€ę”Æę“
   • é«˜å½ˆę€§ēš„č‡Ŗē”±č»Ÿé«”ęŽˆę¬ŠęØ”å¼ (BSD License)
   • ę“»čŗēš„é–‹ē™¼ (50% 開發者來自 Apple Inc.)
   • č±åÆŒēš„ē·Øč­Æč¼øå‡ŗļ¼š C, ARM, x86, PowerPC, …
č±åÆŒēš„å·„å…·é›†
Assemblers, automatic debugger, linker, code
generator, compiler driver, modular optimizer, …
Eric Schmidt 是 UNIX lex å…±åŒä½œč€…
Eric Schmidt 是 UNIX lex å…±åŒä½œč€…
GCC vs. LLVM
GCC                                      LLVM
C, C++, Obj-C, Fortran, Java, Ada, ...   C, C++, Obj-C
x86, ARM, MIPS, PowerPC, …

binutils (ld as)                         BSD-Style License

                                         JIT/Interpreter




Compiler Driver
Frontend   LLVM IR   Backend
Frontend   LLVM IR   Backend
CodeMark åƒč€ƒę•øę“š
 Pentium4 3.0GHz Ubuntu: -Os -O3 -fast

 size: kbytes
10000                                                                                                                             40



9000      LLVM                                      GCC                                      Intel CC                             35


8000
                                                                                                                                  30

7000

                                                                                                                                  25
6000


5000                                                                                                                              20



4000
                                                                                                                                  15


3000
                                                                                                                                  10

2000

                                                                                                                                  5
1000


   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
ēœ‹čµ·ä¾†ļ¼Œ LLVM ę•ˆčƒ½é‚„äøę˜Æęœ€å„½ļ¼Œ
  é‚£ē‚ŗä½•ęˆ‘å€‘é‚„č¦é—œę³Øļ¼Ÿ
LLVM äøåŖę˜Æå€‹å…·å·„ę„­å¼·åŗ¦ēš„ē·Øč­Æå™Ø
ē¾Žå¦™ēš„ LLVM + Clang
Clang: LLVM ēš„ēØ‹å¼čŖžčØ€å‰ē«Æ

 C                                 x86 機械碼

                 Clang
C++       $ clang main.c mod.c     ARM 機械碼




Obj-C


               Clang driver

           libClang           ld

           libLLVM            as
Clang 與 LLVM ēš„é—œčÆ
         libClang                   libLLVM
 [C]                BitCode
main.c              main.bc
                                                      x86 ēµ„čŖž
                                                       main.s
 [C]     Source →   BitCode                Code
                              Optimizer
mod.c     BitCode   mod.bc                Generator
Clang åŠŸčƒ½ē¤ŗę„
 [C]                         libClang               BitCode
main.c                                              main.bc
            lex
                                        codegen
 [C]                   AST                          BitCode
mod.c                                               mod.bc
          parse
                                        Analysis
                    Serialize/
         semantics Deserialize
                                 Checker Indexer




                   AST         AST                 IDE ę•“åˆ
                  main.ast    mod.ast    輸出 / č§£ęž    (Xcode)
BitCode + Optimizer
                                                  LTO: Link-Time Optimization
                                                  LTO: Link-Time Optimization
BitCode
main.bc                          Inter-precedual
                    BitCode
                     Linker
BitCode
                               Analysis Transforms
mod.bc    BitCode                                     BitCode        BitCode
           parser                                      writer       main.lto.bc
                    BitCode
                               Analysis Transforms




                        BitCode       BitCode
                       main.opt.bc   mod.opt.bc
LLVM Code Generation
                                         libLLVM

 BitCode                                              Machine
main.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


                                                                          ARM.td
                                                                          InstrInfo
                                                                          Register
                          Instruction   Instruction             X86.td
                                                                         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
先從 Hello World 開始
       • å®Œę•“ēš„ Compiler Driver
              $Ā clangĀ hello.cĀ Ā­oĀ hello
       • ē”Ÿęˆ IR
              $Ā clangĀ Ā­O3Ā Ā­emitĀ­llvmĀ hello.cĀ Ā­cĀ Ā­oĀ hello.bc
       • 仄 Just-In-Time compiler ęØ”å¼åŸ·č”Œ BitCode
              $Ā lliĀ hello.bc




Getting Started with the LLVM System
Getting Started with the LLVM System
http://llvm.org/docs/GettingStarted.html
http://llvm.org/docs/GettingStarted.html
#includeĀ <stdio.h>
 #includeĀ <stdio.h>
 intĀ main(intĀ argc,Ā charĀ *argv[])
 intĀ main(intĀ argc,Ā charĀ *argv[])
 {
 {
    printf("HelloĀ world!n");
    printf("HelloĀ world!n");
    returnĀ 0;
    returnĀ 0;
 }
 }


      函式 printf() å¾Œę–¹åƒ…ęœ‰äø€å€‹
      函式 printf() å¾Œę–¹åƒ…ęœ‰äø€å€‹                  • åēµ„č­Æ BitCode
      å­—äø²åƒę•øļ¼Œå‰ē«Æé čØ­å°‡å…¶
      å­—äø²åƒę•øļ¼Œå‰ē«Æé čØ­å°‡å…¶
          č½‰ę›ē‚ŗ puts()                          $Ā llvmĀ­disĀ <Ā hello.bc
           č½‰ę›ē‚ŗ puts()

Ā Ā ;Ā ModuleIDĀ =Ā '<stdin>'
Ā Ā ;Ā ModuleIDĀ =Ā '<stdin>'
Ā Ā targetĀ datalayoutĀ =Ā "eĀ­p:32:32:32Ā­...
Ā Ā targetĀ datalayoutĀ =Ā "eĀ­p:32:32:32Ā­...
Ā Ā targetĀ tripleĀ =Ā "i386Ā­pcĀ­linuxĀ­gnu"
Ā Ā targetĀ tripleĀ =Ā "i386Ā­pcĀ­linuxĀ­gnu"

Ā Ā @strĀ =Ā internalĀ constantĀ [13Ā xĀ i8]Ā c"HelloĀ world!00"
Ā Ā @strĀ =Ā internalĀ constantĀ [13Ā xĀ i8]Ā c"HelloĀ world!00"

Ā Ā defineĀ i32Ā @main(i32Ā %argc,Ā i8**Ā nocaptureĀ %argv)Ā nounwindĀ {
Ā Ā defineĀ i32Ā @main(i32Ā %argc,Ā i8**Ā nocaptureĀ %argv)Ā nounwindĀ {
Ā Ā entry:
Ā Ā entry:
Ā Ā Ā Ā %putsĀ =Ā tailĀ callĀ i32Ā @puts(i8*Ā getelementptrĀ inboundsĀ ([13Ā xĀ i8]*Ā @str,Ā i32Ā 0,Ā i32Ā 0))
Ā Ā Ā Ā %putsĀ =Ā tailĀ callĀ i32Ā @puts(i8*Ā getelementptrĀ inboundsĀ ([13Ā xĀ i8]*Ā @str,Ā i32Ā 0,Ā i32Ā 0))
Ā Ā Ā Ā retĀ i32Ā 0
Ā Ā Ā Ā retĀ i32Ā 0
Ā Ā }
Ā Ā }

Ā Ā DeclareĀ i32Ā @puts(i8*Ā nocapture)Ā nounwind
Ā Ā DeclareĀ i32Ā @puts(i8*Ā nocapture)Ā nounwind

        • 輸出 x86 å¾Œē«Æēµ„åˆčŖžčØ€
               $Ā llcĀ hello.bcĀ Ā­oĀ hello.s
LLVM in Google Android 3.0 SDK
$Ā cdĀ androidĀ­sdkĀ­linux_x86/platformĀ­tools
$Ā ./llvmĀ­rsĀ­ccĀ Ā­Ā­version
LowĀ LevelĀ VirtualĀ MachineĀ (http://llvm.org/):
Ā Ā llvmĀ versionĀ 2.8svn
Ā Ā OptimizedĀ build.
Ā Ā BuiltĀ FebĀ 16Ā 2011Ā (19:26:29).
Ā Ā Host:Ā i386Ā­unknownĀ­linux
Ā Ā HostĀ CPU:Ā penryn                 Android SDK (3.0 = API version 11)
                                   Android SDK (3.0 = API version 11)
                                   http://developer.android.com/sdk/
                                   http://developer.android.com/sdk/
Ā Ā RegisteredĀ Targets:
Ā Ā Ā Ā armĀ Ā Ā Ā Ā­Ā ARM
Ā Ā Ā Ā thumbĀ Ā Ā­Ā Thumb
Ā Ā Ā Ā x86Ā Ā Ā Ā Ā­Ā 32Ā­bitĀ X86:Ā PentiumĀ­ProĀ andĀ above
Ā Ā Ā Ā x86Ā­64Ā Ā­Ā 64Ā­bitĀ X86:Ā EM64TĀ andĀ AMD64
$Ā ./llvmĀ­rsĀ­ccĀ Ā­Ā­help
OVERVIEW:Ā RenderScriptĀ sourceĀ compiler
                                                                31
LLVM in Google Android 3.0 SDK
    $Ā ./llvmĀ­rsĀ­ccĀ Ā­Ā­help
    OVERVIEW:Ā RenderScriptĀ sourceĀ compiler
    USAGE:Ā llvmĀ­rsĀ­ccĀ [options]Ā <inputs>
•   OPTIONS:
    Ā Ā Ā­IĀ <directory>Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā AddĀ directoryĀ toĀ includeĀ searchĀ path
    Ā Ā Ā­additionalĀ­depĀ­targetĀ <value>
    Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā AdditionalĀ targetsĀ toĀ showĀ upĀ inĀ dependenciesĀ output
    Ā Ā Ā­allowĀ­rsĀ­prefixĀ Ā Ā Ā Ā Ā Ā Ā AllowĀ userĀ­definedĀ functionĀ prefixedĀ withĀ 'rs'
    Ā Ā Ā­bitcodeĀ­storageĀ <value>
    Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā <value>Ā shouldĀ beĀ 'ar'Ā orĀ 'jc'
    Ā Ā Ā­emitĀ­asmĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā EmitĀ targetĀ assemblyĀ files
    Ā Ā Ā­emitĀ­bcĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā BuildĀ ASTsĀ thenĀ convertĀ toĀ LLVM,Ā emitĀ .bcĀ file
    Ā Ā Ā­emitĀ­llvmĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā BuildĀ ASTsĀ thenĀ convertĀ toĀ LLVM,Ā emitĀ .llĀ file
    Ā Ā Ā­emitĀ­nothingĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā BuildĀ ASTsĀ thenĀ convertĀ toĀ LLVM,Ā butĀ emitĀ nothing
    Ā Ā Ā­helpĀ Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā PrintĀ thisĀ helpĀ text
    Ā Ā Ā­javaĀ­reflectionĀ­packageĀ­nameĀ <value>
    Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā SpecifyĀ theĀ packageĀ nameĀ thatĀ reflectedĀ JavaĀ filesĀ belongĀ to
    Ā Ā Ā­javaĀ­reflectionĀ­pathĀ­baseĀ <directory>
    Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā BaseĀ directoryĀ forĀ outputĀ reflectedĀ JavaĀ files
                                                                                             32
測試 SDK 內建範例 RenderScript
androidĀ­sdkĀ­linux_x86/platformĀ­tools$Ā ./llvmĀ­rsĀ­ccĀ 
Ā Ā ../samples/androidĀ­11/Ā 
RenderScript/HelloWorld/src/com/android/rs/helloworld/helloworld.rsĀ 
Ā Ā Ā­IĀ ../platforms/androidĀ­11/renderscript/includeĀ 
Ā Ā Ā­IĀ ../platforms/androidĀ­11/renderscript/clangĀ­include
                                   //Ā helloworld.rs
                                   //Ā helloworld.rs
                                   //Ā ThisĀ isĀ invokedĀ automatically
                                   //Ā ThisĀ isĀ invokedĀ automatically
                                   //Ā whenĀ theĀ scriptĀ isĀ created
                                   //Ā whenĀ theĀ scriptĀ isĀ created
                                   voidĀ init()Ā {
                                   voidĀ init()Ā {
                                   Ā Ā Ā Ā gTouchXĀ =Ā 50.0f;
                                   Ā Ā Ā Ā gTouchXĀ =Ā 50.0f;
                                   Ā Ā Ā Ā gTouchYĀ =Ā 50.0f;
                                   Ā Ā Ā Ā gTouchYĀ =Ā 50.0f;
                                   }
                                   }

llvmĀ­disĀ <Ā helloworld.bc

@gTouchXĀ =Ā commonĀ globalĀ i32Ā 0,Ā alignĀ 4
@gTouchXĀ =Ā commonĀ globalĀ i32Ā 0,Ā alignĀ 4
@gTouchYĀ =Ā commonĀ globalĀ i32Ā 0,Ā alignĀ 4
@gTouchYĀ =Ā commonĀ globalĀ i32Ā 0,Ā alignĀ 4

defineĀ voidĀ @init()Ā nounwindĀ {
defineĀ voidĀ @init()Ā nounwindĀ {
Ā Ā storeĀ i32Ā 50,Ā i32*Ā @gTouchX,Ā alignĀ 4
Ā Ā storeĀ i32Ā 50,Ā i32*Ā @gTouchX,Ā alignĀ 4
Ā Ā storeĀ i32Ā 50,Ā i32*Ā @gTouchY,Ā alignĀ 4
Ā Ā storeĀ i32Ā 50,Ā i32*Ā @gTouchY,Ā alignĀ 4
Ā Ā retĀ void                                                              33
Ā Ā retĀ void
}
}
LLVM ēµ¦äŗˆē„”é™åÆčƒ½

C/C++/       libClang      AST
Obj-C


           BitCode


            LibLLVM
            Optimizer

                 BitCode



Arch.td      libLLVM       xxx.s
          CodeGenerator
ęä¾› IDE ēš„ęØ”ēµ„åŒ–
                                   ęœ‰äŗ† AST å¾Œļ¼Œå³åÆé‡å°
                 éœę…‹ē·Øč­Æč§£ęžå™Ø
åÆē”ØčØ±å¤šēØ‹å¼čŖžčØ€                           čŖžčØ€ē‰¹ę€§ļ¼Œåšå‡ŗē‰¹å®šēš„ę‡‰ē”Ø
撰寫 BitCode ē”Ÿęˆ
器 ( å‰ē«Æē·Øč­Æå™Ø )
      C/C++/           libClang
ļ¼Œå¦‚ PerlObj-C
        module                            AST


                    BitCode
      å…¶ä»–čŖžčØ€                         ē³»ēµ±å„ŖåŒ–č™•ē†
                      LibLLVM
                      Optimizer         ä½œē‚ŗå…¶ä»–čŖžčØ€ēš„
                                        Source-to-source
 ē‰¹å®šēš„å¾Œē«Æęž¶ę§‹ć€‚                               č½‰ę›å™Ø
 åÆä»„ę˜Æē”¬é«”ęˆ–č»Ÿé«”                            å…¶ä»–čŖžčØ€
                         BitCode


     Arch.td              LibLLVM        xxx.s
                        CodeGenerator
åÆå¢žę·»å…¶ä»–ęØ”ēµ„ļ¼Œå¦‚
Polyhedral optimization           é‡å°å¾Œē«Æē”¬é«”ēš„ Selection DAG
Xcode                     OpenCL Compiler
OpenCL →
Haskell →
Clay → C/C++/              libClang                  AST
        Obj-C
Crack →
                                          StrengthReduction
                        BitCode           Profile-gen/use
       å…¶ä»–čŖžčØ€
                                          AliasAnalysis
                          LibLLVM
                          Optimizer                →       JavaScript
 FPGA;
                                                   →       Java ByteCode
 GPGPU                                         å…¶ä»–čŖžčØ€
                                BitCode            →       CLI
                                                   →       PTX

      Arch.td             LibLLVM              regaloc=Pazzle|Graph
                                                     xxx.s
                        CodeGenerator          ObjectCodeEmitter
                Polly
將 LLVM ę‡‰ē”ØåœØéžē·Øč­Æå™Øé ˜åŸŸ
LLVM åŠ›ļ¼š
ć€Œäøę˜Æē‚ŗäŗ†å–ę‚…ē”¬é«”č€ŒåÆ«ē·Øč­Æå™Øļ¼Œč€Œē‚ŗč‡Ŗå·±åÆ«ē·Øč­Æå™Øć€
 • LLVM + Gallium3D: Mixing a Compiler With a
   Graphics Framework
   • http://people.freedesktop.org/~marcheu/fosdem09-g3dllvm.pdf


 • Runtime Code Generation for Huffman Decoders
    • ā€œThe speedup improvement is 23.2% at
      average and ranges from 32.2% to 14.2%.ā€
     http://solar.cslab.ece.ntua.gr/~kkourt/papers/huff-jit-report.pdf


 • A method for JIT’ing algorithms and data
   structures with LLVM
    • ā€œFor small AVL Trees (with less than ~3.000
      nodes), we can get an average performance
      of 26% over traditional methodā€
   • http://pyevolve.sourceforge.net/wordpress/?p=914
ēØ‹å¼čŖžčØ€ēš„č®Šé·
(Low-Level 觀點 )
ēØ‹å¼čŖžčØ€ēš„č®Šé· ( ä½ŽéšŽč§€é»ž )
       • č·ę„­ē„”č²“č³¤ļ¼ŒēØ‹å¼čŖžčØ€ę˜Æęå‡ŗä¾†č§£ę±ŗäŗŗé”žé¢č‡Øēš„
         å•é”Œä¹‹ē”Ø             System Bus

                                       DMA        CPU              DSP

CPU       DMA
          DSP      Memory

                                      Memory
Interconnection network (BUS)                      Bridge
                                     controller
 DSP      Dedicated I/O
             IP
                                Peripherals

                                                  Peripheral Bus
               Programming Language
Indirection
 ā€œAll problems in computer
 science can be solved by
 another level of indirection."
      ~ Butler Lampson, 1972 ~
• UNIX v6 (1976) ęä¾›ä»„ C čŖžčØ€é‡åÆ«ēš„ä½œę„­ē³»ēµ±
• éœ€ę±‚é©…ä½æēš„ē™¼å±•ęØ”å¼
  • 數學 / 巄程 → Lisp → Lisp machine (?)
  • č»Ÿé«”å·„ēØ‹ → Smalltalk
  • ē¶²éš›ē¶²č·Æ → Java
éŠęˆ²ē”¢ę„­é©…ä½æ Programming Language
      1972 Pong ( 甬體 )

      1980 Zork ( é«˜éšŽē›“č­ÆčŖžčØ€ )


      1993 DOOM (C)

      1998 Unreal (C++, Java-style scripting)


      2005-6 Xbox 360, PlayStation 3
      with 6-8 hardware threads

      2009 Next console generation.
      Unification of the CPU, GPU.
      Massive multi-core, data parallelism, etc.
ä»Šę—„ēš„ Indirection 仄 VM å½¢å¼å­˜åœØ
Charles Oliver Nutter (JRuby)
    ā€œBuilding a Multilanguage VMā€ (2009)
    • Today, it is silly for a compiler to target actual hardware
       • Much more effective to target a VM
       • Writing a native compiler is lots more work!
    • Languages need runtime support
       • C runtime is tiny and portable (and wimpy)
       • More sophisticated language runtimes need
          • Memory management
          • Security
          • Reflection
          • Concurrency control
          • Libraries
          • Tools (debuggers, profilers, etc)
    • Many of these features are baked into VMs
JVM vs. Java Language vs. Ruby
              Java language        Ruby language


                    Checked exceptions     Open classes
                    Generics               Dynamic typing
                    Enums                  'eval'
JVM 特徵              Overloading            Closures
                    Constructor chaining   Mixins
                    Program analysis       Rich set of literals
                    Primitive types+ops    Primitive types+ops
Primitive types+ops
                    Object model           Object model
Object model
                    Memory model           Memory model
Memory model
                    Dynamic linking        Dynamic linking
Dynamic linking
                    Access control         Access control
Access control
                    GC                     GC
GC
                    Unicode                Unicode
Unicode                                                        45
在 JVM 上實做 Ruby čŖžčØ€ (JRuby)
       • å„½č™•ļ¼š
         • åˆ©ē”Øę—¢ęœ‰ JVM åœØå¹³å°å„ŖåŒ–ēš„ę•ˆčƒ½čˆ‡å½ˆę€§
         • å­˜å–č±åÆŒēš„ Java 資源
       • é›£č™•ļ¼š
         • Dynamic typing č®“å·²ęœ‰å„ŖåŒ–ęŠ€č”“č®Šå¾—é›£ä»„ē™¼ę®
         • JRuby åæ…é ˆē¶­č­·č‡Ŗå·±ēš„ type system
            • Reflection overhead
         • ē„”ę³•ä»„ęœ‰ę•ˆēŽ‡äø”å„å…Øēš„ę–¹å¼ä¾†åÆ¦åš Ruby
           ā€evalā€
The Da Vinci Machine Project
The Da Vinci Machine Project
http://openjdk.java.net/projects/mlvm/
http://openjdk.java.net/projects/mlvm/   46
OpenJDK Multi-language VM
OpenJDK Multi-language VM
在 LLVM 上實做 Ruby čŖžčØ€
• é–‹ę”¾åÆ¦åšļ¼š
  • MacRuby : http://www.macruby.org/
  • Rubinius : http://rubini.us/
• č‹„å……åˆ†å°ę‡‰åˆ° LLVM ēš„čØ­čØˆļ¼Œę‡‰åÆē™¼ę®č‹„å¹²ę•ˆčƒ½
  ēš„ę”¹å–„čˆ‡ runtime support
  • Out-source'd JIT Runtime
  • Why MacRuby Matters (Present & Future)
   http://programmingzen.com/2009/03/29/why-macruby-matters/




                                                               47
48
http://programmingzen.com/images/macruby-large-chart.png
LLVM čˆ‡ēØ‹å¼čŖžčØ€åÆ¦åš
•   LLVM 在 bitcode å±¤é¢å³č€ƒę…®åˆ°å‹•ę…‹čŖžčØ€ēš„éœ€ę±‚
•   VMKit: Java, .Net
•   å…čØ±å¤šå€‹éšŽę®µēš„å„ŖåŒ– : profiler, offline optimizing
•   ęä¾› Accurate Garbage Collection
•   åœØē§»å‹•č£ē½®äøŠēš„ JIT compiler
     • [RenderScript] Android 3.0: 實做 code
       cache ļ¼Œč©¦åœ–é™ä½Žē·Øč­Æēš„ęˆęœ¬
     • ē›®å‰ LLVM ēš„ę•ˆčƒ½ä»ē„”ę³•č¶•äøŠč‹„å¹²ē‰¹č£½ēš„
       VM ć€‚ę”ˆä¾‹ļ¼š IcedTea/Shark, Dalvik

                                         49
Build Programming Language
     Runtime with LLVM 實例
Brainfuck
• Brainfuck ę˜ÆēØ®ę„µē‚ŗē²¾ē°”ēš„ēØ‹å¼čŖžčØ€ļ¼Œē”± Urban
  Müller ē™¼å±•ć€‚ē•¶åˆēš„ē›®ęØ™ē‚ŗęå‡ŗäø€ēØ®ē°”å–®ēš„ć€åÆ
  ē”Øęœ€å°ēš„ē·Øč­Æå™Øä¾†åÆ¦ē¾ć€ē¬¦åˆ Turing complete
  ēš„ēØ‹å¼
• Brainfuck åƒ…ęœ‰å…«å€‹ęŒ‡ä»¤ļ¼Œå…¶äø­å…©å€‹ę˜Æ I/O 動作




                             51
Brainfuck
• å°ę‡‰åˆ° C čŖžčØ€ļ¼šč‹„ char *p ęŒ‡å‘čØ˜ę†¶é«”å€å”Šēš„
  話, Brainfuck čŖžčØ€ēš„å…«å€‹ęŒ‡ä»¤åÆå°ē…§ē‚ŗä»„äø‹ļ¼š
• Brainfuck      C
  >Ā              ++p;
  <Ā              Ā­Ā­p;
  +Ā              ++*p;
  Ā­Ā              Ā­Ā­*p;
  .Ā              putchar(*p);
  ,Ā              *pĀ =Ā getchar();
  [Ā              whileĀ (*p)Ā {
  ]Ā              }               52
Brainfuck
• Brainfuck čŖžčØ€
  +++++[Ā­]          Brainfuck   C

• ē­‰åƒ¹ę–¼ C čŖžčØ€          >Ā           ++p;
                    <Ā           Ā­Ā­p;
  *p+=5;            +Ā           ++*p;
  while(*pĀ !=Ā 0){   Ā­Ā           Ā­Ā­*p;
                    .Ā           putchar(*p);
  Ā Ā Ā Ā *pĀ­Ā­;         ,Ā           *pĀ =Ā getchar();
  }                 [Ā           whileĀ (*p)Ā {
                    ]Ā           }




                                               53
#includeĀ <stdio.h>
#includeĀ <stdio.h>
voidĀ foo(charĀ c)Ā {Ā putchar(c);Ā }
voidĀ foo(charĀ c)Ā {Ā putchar(c);Ā }


defineĀ voidĀ @foo(i8Ā signextĀ %c)Ā nounwindĀ {
defineĀ voidĀ @foo(i8Ā signextĀ %c)Ā nounwindĀ {
Ā Ā %1Ā =Ā allocaĀ i8,Ā alignĀ 1Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā ;Ā <i8*>Ā [#uses=2]
Ā Ā %1Ā =Ā allocaĀ i8,Ā alignĀ 1Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā ;Ā <i8*>Ā [#uses=2]
Ā Ā storeĀ i8Ā %c,Ā i8*Ā %1
Ā Ā storeĀ i8Ā %c,Ā i8*Ā %1
Ā Ā %2Ā =Ā loadĀ i8*Ā %1Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā ;Ā <i8>Ā [#uses=1]
Ā Ā %2Ā =Ā loadĀ i8*Ā %1Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā ;Ā <i8>Ā [#uses=1]
Ā Ā %3Ā =Ā sextĀ i8Ā %2Ā toĀ i32Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā ;Ā <i32>Ā [#uses=1]
Ā Ā %3Ā =Ā sextĀ i8Ā %2Ā toĀ i32Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā ;Ā <i32>Ā [#uses=1]
Ā Ā %4Ā =Ā callĀ i32Ā @putchar(i32Ā %3)Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā ;Ā <i32>Ā [#uses=0]
Ā Ā %4Ā =Ā callĀ i32Ā @putchar(i32Ā %3)Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā ;Ā <i32>Ā [#uses=0]
Ā Ā retĀ void
Ā Ā retĀ void
}
}

declareĀ i32Ā @putchar(i32)
declareĀ i32Ā @putchar(i32)


Ā Ā Ā //Ā declareĀ i32Ā @putchar(i32)
Ā Ā Ā Function*Ā putcharĀ =Ā cast<Function>(
Ā Ā Ā Ā Ā Ā Ā moduleĀ­>getOrInsertFunction(
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā "putchar",Ā voidType,Ā cellType,Ā NULL));
Ā Ā Ā putcharĀ­>setCallingConv(CallingConv::C);


                                                                 54
                         å‘¼å«åŗ•å±¤ē³»ēµ± libc ēš„ putchar 函式
Function*Ā makeFunc(Module*Ā module,
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā constĀ char*Ā source,
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā intĀ tapeSizeĀ =Ā 400)Ā {
Ā Ā ...
Ā Ā //Ā declareĀ i32Ā @getchar()
Ā Ā Function*Ā getcharĀ =Ā cast<Function>(
Ā Ā Ā Ā Ā moduleĀ­>getOrInsertFunction("getchar",Ā cellType,Ā NULL));
Ā Ā getcharĀ­>setCallingConv(CallingConv::C);
Ā Ā 
Ā Ā //Ā declareĀ i32Ā @putchar(i32)
Ā Ā Function*Ā putcharĀ =Ā cast<Function>(
Ā Ā Ā Ā Ā moduleĀ­>getOrInsertFunction("putchar",
Ā Ā Ā Ā Ā Ā voidType,Ā cellType,Ā NULL));
Ā Ā putcharĀ­>setCallingConv(CallingConv::C);

Ā Ā //Ā ContructĀ voidĀ main(char*Ā tape)
Ā Ā Function*Ā mainĀ =Ā cast<Function>(
Ā Ā Ā Ā Ā moduleĀ­>getOrInsertFunction(ā€œmain",Ā voidType,Ā NULL));
Ā Ā mainĀ­>setCallingConv(CallingConv::C);
Ā Ā ...
                                                           55
               http://0xlab.org/~jserv/llvm/bf-llvm.cpp
Function*Ā makeFunc(Module*Ā module,
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā constĀ char*Ā source,
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā intĀ tapeSizeĀ =Ā 400)Ā {
Ā Ā ...
Ā Ā Value*Ā zeroĀ =Ā ConstantInt::get(cellType,Ā 0);
Ā Ā Value*Ā oneĀ =Ā ConstantInt::get(cellType,Ā 1);
Ā Ā Value*Ā minOneĀ =Ā ConstantInt::get(cellType,Ā Ā­1);
Ā Ā ...
                    在 LLVM IR äø­ļ¼Œé å…ˆč‹„å¹²å®šē¾©ēš„åøøę•ø
                    zero = 0, one =1, minOne = -1
Ā Ā BasicBlock*Ā blockĀ =
Ā Ā Ā Ā Ā Ā BasicBlock::Create(getGlobalContext(),Ā "code",Ā main);
Ā Ā std::stack<bfLoopInfo>Ā loops;
Ā Ā IRBuilder<>Ā codeIR(block);
Ā Ā ValueĀ *headĀ =Ā codeIR.CreateAlloca(cellType,Ā 
Ā Ā Ā Ā Ā Ā ConstantInt::get(indexType,Ā tapeSize));
Ā Ā ValueĀ *itĀ =Ā head;                             建立 LLVM IR
Ā Ā forĀ (intĀ iĀ =Ā 0;Ā iĀ <Ā tapeSize;Ā i++)Ā {
Ā Ā Ā Ā codeIR.CreateStore(zero,Ā it);
Ā Ā Ā Ā itĀ =Ā codeIR.CreateGEP(it,Ā one);                       56
Ā Ā }
Function*Ā makeFunc(Module*Ā module,
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā constĀ char*Ā source,
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā intĀ tapeSizeĀ =Ā 400)Ā {
Ā Ā ...
Ā Ā while(*source)Ā {
Ā Ā Ā Ā IRBuilder<>Ā builder(block); 將 brainfuck č½‰ęˆ LLVM IR
Ā Ā Ā Ā switch(*source++)Ā {
Ā Ā Ā Ā Ā Ā caseĀ '>':
Ā Ā Ā Ā Ā Ā Ā Ā headĀ =Ā builder.CreateGEP(head,Ā one);
Ā Ā Ā Ā Ā Ā Ā Ā break;
Ā Ā Ā Ā Ā Ā caseĀ '<':
Ā Ā Ā Ā Ā Ā Ā Ā headĀ =Ā builder.CreateGEP(head,Ā minOne);
Ā Ā Ā Ā Ā Ā Ā Ā break;
Ā Ā Ā Ā Ā Ā caseĀ '+':Ā {
Ā Ā Ā Ā Ā Ā Ā Ā ValueĀ *headValueĀ =Ā builder.CreateLoad(head);
Ā Ā Ā Ā Ā Ā Ā Ā ValueĀ *resultĀ =
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā builder.CreateAdd(headValue,Ā one);
Ā Ā Ā Ā Ā Ā Ā Ā builder.CreateStore(result,Ā head);
Ā Ā Ā Ā Ā Ā Ā Ā break;
Ā Ā Ā Ā Ā Ā }                                           57
Ā Ā Ā Ā Ā Ā ...
Function*Ā makeFunc(Module*Ā module,
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā constĀ char*Ā source,
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā intĀ tapeSizeĀ =Ā 400)Ā {
Ā Ā Ā Ā Ā Ā ...
Ā Ā Ā Ā Ā Ā caseĀ 'Ā­':Ā {
Ā Ā Ā Ā Ā Ā Ā Ā ValueĀ *headValueĀ =Ā builder.CreateLoad(head);
Ā Ā Ā Ā Ā Ā Ā Ā ValueĀ *resultĀ =
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā builder.CreateSub(headValue,Ā one);
Ā Ā Ā Ā Ā Ā Ā Ā builder.CreateStore(result,Ā head);
Ā Ā Ā Ā Ā Ā Ā Ā break;
Ā Ā Ā Ā Ā Ā }
Ā Ā Ā Ā Ā Ā caseĀ '.':Ā {
Ā Ā Ā Ā Ā Ā Ā Ā Value*Ā outputĀ =Ā builder.CreateLoad(head);
Ā Ā Ā Ā Ā Ā Ā Ā builder.CreateCall(putchar,Ā output);
Ā Ā Ā Ā Ā Ā Ā Ā break;
Ā Ā Ā Ā Ā Ā }                     ēØę—©ęŗ–å‚™ēš„ putchar 函式
Ā Ā Ā Ā Ā Ā ...


                                                 58
Function*Ā makeFunc(Module*Ā module,
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā constĀ char*Ā source,
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā intĀ tapeSizeĀ =Ā 400)Ā {
Ā Ā ...
Ā Ā //Ā CloseĀ theĀ function
Ā Ā IRBuilder<>Ā builder(block);
Ā Ā builder.CreateRetVoid();
Ā Ā returnĀ main;
}

intĀ main(intĀ argc,Ā char*Ā argv[])Ā {
Ā Ā ...
Ā Ā //Ā SetupĀ aĀ moduleĀ andĀ engineĀ forĀ JITĀ­ing
Ā Ā std::stringĀ error;
Ā Ā InitializeNativeTarget();
Ā Ā Module*Ā moduleĀ =Ā newĀ Module("bfcode",Ā getGlobalContext());
Ā Ā ExecutionEngineĀ *engineĀ =Ā EngineBuilder(module)
Ā Ā Ā Ā .setErrorStr(&error)
Ā Ā Ā Ā .setOptLevel(CodeGenOpt::Aggressive)
Ā Ā Ā Ā .create();                                              59
                  é–‹å•Ÿé€²éšŽå„ŖåŒ–ēš„ ExecutionEngine (JIT)
FunctionĀ *makeFunc(ModuleĀ *module,
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā constĀ charĀ *source,
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā intĀ tapeSizeĀ =Ā 400)Ā {
Ā Ā ...
}

intĀ main(intĀ argc,Ā char*Ā argv[])Ā {
Ā Ā ...
Ā Ā //Ā CompileĀ theĀ BrainfuckĀ toĀ IR
Ā Ā std::coutĀ <<Ā "Parsing..."Ā <<Ā std::flush;
Ā Ā Function*Ā funcĀ =Ā makeFunc(module,Ā source.c_str());

Ā Ā //Ā RunĀ optimizationĀ passes
Ā Ā std::coutĀ <<Ā "Optimizing..."Ā <<Ā std::flush;
Ā Ā FunctionPassManagerĀ pm(module);
Ā Ā pm.add(newĀ TargetData(
Ā Ā Ā Ā Ā Ā *(engineĀ­>getTargetData())));
Ā Ā pm.add(createVerifierPass());
Ā Ā pm.run(*func);
Ā Ā ...                                            60
                       讓 LLVM äø²čµ·ę•“å€‹ē·Øč­Æå™Øęž¶ę§‹
intĀ main(intĀ argc,Ā char*Ā argv[])Ā {
Ā Ā ...
Ā Ā //Ā Compile
Ā Ā std::coutĀ <<Ā "Compiling..."Ā <<Ā std::flush;
Ā Ā voidĀ (*bf)()Ā =Ā (voidĀ (*)())
Ā Ā Ā Ā Ā Ā engineĀ­>getPointerToFunction(func);
Ā Ā std::coutĀ <<Ā "Ā done"Ā <<Ā std::endl;
Ā 
Ā Ā //Ā andĀ run!               讓 function pointer ęŒ‡å‘ē¶“ē”± JIT
Ā Ā bf();                     ē·Øč­ÆéŽēš„ę©Ÿę¢°ē¢¼

Ā Ā returnĀ 0;
}




                                                     61
ęž¶ę§‹ę–¼ LLVM ēš„ēØ‹å¼čŖžčØ€åÆ¦åš (1)
• Unladen Swallow (Google): faster Python
 $ ./perf.py -r -b call_simple --args "-j always," 
            ../q2/python ../q3/python
  • Min: 1.618273 -> 0.908331: 78.16% faster
  • Avg: 1.632256 -> 0.924890: 76.48% faster
    http://code.google.com/p/unladen-swallow

• GHC/Haskell's LLVM codegen
  • 3x faster in some cases
    http://donsbot.wordpress.com/2010/02/21/
    smoking-fast-haskell-code-using-ghcs-new-llvm-codegen/

• LLVM-Lua : JIT/static Lua compiler
  • http://code.google.com/p/llvm-lua/
                                                             62
ęž¶ę§‹ę–¼ LLVM ēš„ēØ‹å¼čŖžčØ€åÆ¦åš (2)
• IcedTea Version of Sun's OpenJDK (RedHat)
   • Zero: processor-independent layer that allows
     OpenJDK to build and run using any processor
   • Shark: Zero's JIT compiler: uses LLVM to provide
     native code generation without introducing
     processor-dependent code.
     http://icedtea.classpath.org
• Emscripten
   • LLVM-to-JavaScript compiler
   • It takes LLVM bitcode and compiles that into
     JavaScript, which can be run on the web (or
     anywhere else JavaScript can run).
     http://code.google.com/p/emscripten/
                                                    63
http://0xlab.org

Build Programming Language Runtime with LLVM