The document discusses LLVM and its use in building programming language compilers and runtimes. It provides an overview of LLVM, including its core components like its intermediate representation (IR), optimizations, and code generation capabilities. It also discusses how LLVM is used in various applications like Android, browsers, and graphics processing. Examples are given of using Clang and LLVM to compile and run a simple C program.
Introduction to the presentation on building programming languages using LLVM. 0xlab's background and purpose of the presentation.
Overview of sister talks discussing compilers and applied computer science, showing the speaker's involvement in related events.
Discussion on the era of compilers with a focus on LLVM and its advantages in various computing tasks and architectures.
Highlights of LLVM as a low-level framework for various technologies, detailed workflow of how LLVM operates, and its integration with different programming languages.
Introduction of Clang as a frontend for LLVM, demonstrating its functionality in parsing and generating code efficiently.
Explores the vast potential of LLVM beyond traditional compilation, including its role in runtime environments.
Explores how programming languages have evolved over time, focusing on the challenges and opportunities presented by using VMs.
A detailed look at using LLVM to build a runtime for the Brainfuck programming language, showcasing practical applications of LLVM.
Build Programming Language
Runtime with LLVM
Jim Huang ( é»ę¬ē¾¤ )
Developer & Co-founder, 0xlab
jserv@0xlab.org
@ 1500 / March 27, 2011
2.
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
⢠ę大ēå°é·å°±ęÆå¹é¤čč¶£
å å¾ 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
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
ēØå¼čŖčØēč®é· ( ä½éč§é»)
⢠č·ę„ē”貓賤ļ¼ēØå¼čŖčØęÆęåŗä¾č§£ę±ŗäŗŗé”é¢čØē
åé”ä¹ēØ 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 仄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
45.
JVM vs. JavaLanguage 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
ę¶ę§ę¼ 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