LLVM Workshop Osaka Umeda, Japan
Upcoming SlideShare
Loading in...5
×
 

LLVM Workshop Osaka Umeda, Japan

on

  • 3,814 views

LLVM in 20 minutes

LLVM in 20 minutes

Statistics

Views

Total Views
3,814
Views on SlideShare
3,803
Embed Views
11

Actions

Likes
5
Downloads
35
Comments
0

2 Embeds 11

http://www.slideshare.net 10
http://webcache.googleusercontent.com 1

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    LLVM Workshop Osaka Umeda, Japan LLVM Workshop Osaka Umeda, Japan Presentation Transcript

    • LLVM 2009 1 15 ( )
    • LLVM Tatsuhiro Ujihisa
    • LLVM The Low Level Virtual Machine (LLVM) is a compiler infrastructure, written in C++, which is designed for compile- time, link-time, run-time, and "idle-time" optimization of programs written in arbitrary programming languages. LLVM was originally developed as a research infrastructure at the University of Illinois at Urbana-Champaign to investigate dynamic compilation techniques for static and dynamic programming languages... http://en.wikipedia.org/wiki/Low_Level_Virtual_Machine
    • In short, C JVM gcc ( ) ( )
    • C C→ → → $ vim a.c $ gcc a.c -S -o a.s $ gcc a.s -o a $ ./a
    • LLVM (1) C → LLVM → LLVM → $ vim a.c $ llvm-gcc a.c -S -o a.ll $ llvm-as a.ll -o a.bc $ lli a.bc
    • LLVM (2) C → LLVM → LLVM → → $ vim a.c $ llvm-gcc a.c -S -o a.ll $ llvm-as a.ll -o a.bc $ llc a.bc -o a $ ./a
    • LLVM (3) LLVM → LLVM → $ vim a.ll $ llvm-as a.ll -o a.bc $ lli a.bc
    • LLVM (4) LLVM → LLVM → → $ vim a.ll $ llvm-as a.ll -o a.bc $ opt a.bc -o a2.bc $ lli a2.bc
    • LLVM (5) LLVM → LLVM → → → $ vim a.ll $ llvm-as a.ll -o a.bc $ opt -O3 a.bc -o a2.bc $ opt -O3 a2.bc -o a3.bc $ lli a3.bc
    • LLVM $ llvm-as a.ll -o a.bc $ opt -O3 a.bc -o a2.bc $ opt -O3 a2.bc -o a3.bc $ llvm-dis a3.bc -o a3.ll $ vim a3.ll
    • llvm-as: LLVM (.ll) LLVM (.bc) lli: LLVM (.bc) opt: LLVM (.bc) LLVM (.bc) llvm-dis: llvm-as llvm-gcc: C (.c) LLVM (.ll)
    • LLVM Hello, world! Hello, world! @str = internal constant [14 x i8] c"Hello, world!00" declare i32 @puts(i8*) define i32 @main() { call i32 @puts( i8* getelementptr ([14 x i8]* @str, i32 ret i32 0 }
    • LLVM ( ) C
    • Vim quickrun LLVM .ll <Space>r llvm-as lli
    • LLVM LLVM OK (C OK) LLVM Mac, Linux, Windows
    • LLVM ( ) C (llvm-gcc) Perl Python (pypy) Ruby (Rubinius, MacRuby, etc) Haskell Brainf**k ... LLVM
    • LLVM Pure ( ) Haskell sudo port install pure
    • LLVM LLVM LLVM
    • ( ) LLVM (MacRuby) ( svn up)
    • ! Brainf**k → LLVM BFC: Brainf**k Compiler git clone git://github.com/ujihisa/bfc.git vim bfc/bfc.rb
    • :+ +: /* C */ /* char *h */ ++*h; LLVM !→ OK
    • (bfc.rb ) when '+' a = tc += 1; b = tc += 1; c = tc += 1; d = tc += 1 "%tmp#{a} = load i32* %i, align 4n" << "%tmp#{b} = getelementptr [1024 x i8]* %h, i32 0, i32 % "%tmp#{c} = load i8* %tmp#{b}, align 1n" << "%tmp#{d} = add i8 1, %tmp#{c}n" << "store i8 %tmp#{d}, i8* %tmp#{b}, align 1n" 1. 2. 3. 4. 1
    • $ cat helloworld.bf $ cat helloworld.bf | ruby bfc.rb --llvm > helloworld.ll $ llvm-as helloworld.ll > helloworld.bc $ opt -O3 helloworld.bc # $ lli helloworld.bc Hello, world! $ ruby bfc.rb --llvm helloworld.bf --run
    • : BFC: Brainf**k Compilers http://ujihisa.blogspot.com/2009/12/bfc- brainfk-compilers.html LLVM For Starters http://ujihisa.blogspot.com/2009/12/llvm- for-starters.html Let's Try LLVM http://ujihisa.blogspot.com/2009/12/let- try-llvm.html
    • nil try-llvm.html