LLVMやっていってる

011714704c4a925e542d426d4cdaa4e3?s=47 giginet
January 29, 2019

 LLVMやっていってる

011714704c4a925e542d426d4cdaa4e3?s=128

giginet

January 29, 2019
Tweet

Transcript

  1. ୭ • @giginet(Twi+er/GitHub) • ๺ւಓവؗࢢग़਎ • 2009/4 ๺ւಓେֶ޻ֶ෦ • 2013/4

    ๺ւಓେֶେֶӃɹ৘ใՊֶݚڀՊ • 2015/4 ΫοΫύουגࣜձࣾ৽ଔೖࣾ • ϞόΠϧج൫෦ͰiOSͷج൫։ൃ͍ͯ͠·͢ • झຯ͸ήʔϜ։ൃͰ͢ • ֶੜ࣌୅ͷࢥ͍ग़ɿ೑νϟʔɺδϯύɺ࣌ؗ 1
  2. OSSϝϯςφ΍ͬͯΔ • fastlane • Carthage ࡞ͬͨ΍ͭ • giginet/xcprofiler • giginet/Crossroad

    • cookpad/Puree-Swi9 2
  3. ࠷ۙڵຯͷ͋Δٕज़ 3

  4. LLVM 4

  5. LLVMͱ͸ • ίϯύΠϥج൫ • ݱࡏͷίϯύΠϥ͸શͯΛ࣮૷͢Δʹ͸ෳࡶ͗͢ΔͷͰɺػց ޠͷੜ੒΍࠷దԽͳͲΛڞ௨Խͯ͠࡞ΕΔΑ͏ʹͨ͠࢓૊Έ • ݱࡏɺଟ͘ͷݴޠͷίϯύΠϥ͸LLVM্Ͱߏங͞Ε͍ͯΔ 5

  6. Θ͍Θ͍swi$c 6

  7. 1. ιʔείʔυΛύʔεͯ͠ߏจ໦(AST)ʹม׵ 2. AST͔ΒLLVM IRΛੜ੒ 3. Ṗͷٕज़ʹΑΓόΠφϦ͕ੜ੒͞ΕΔ 7

  8. LLVM IR • LLVM Intermediate Representa2on(தؒදݱ) • ࠷ऴతʹ͜ͷܗࣜʹग़ྗ͢Δ͜ͱͰɺLLVMΛ༻͍ͯόΠφϦ͕ੜ੒Ͱ͖Δ • ଟ͘ͷݴޠͷίϯύΠϥ͕LLVM

    IRΛੜ੒͢ΔLLVM Frontendͱ࣮ͯ͠૷͞Ε͍ͯΔ 8
  9. #include <stdio.h> int main(void) { printf("Hello World"); return 0; }

    $ clang -S -emit-llvm hello.c 9
  10. ; ModuleID = 'hello.c' source_filename = "hello.c" target datalayout =

    "e-m:o-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.14.0" @.str = private unnamed_addr constant [12 x i8] c"Hello World\00", align 1 ; Function Attrs: noinline nounwind optnone ssp uwtable define i32 @main() #0 { %1 = alloca i32, align 4 store i32 0, i32* %1, align 4 %2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0)) ret i32 0 } declare i32 @printf(i8*, ...) #1 !llvm.module.flags = !{!0, !1} !llvm.ident = !{!2} !0 = !{i32 1, !"wchar_size", i32 4} !1 = !{i32 7, !"PIC Level", i32 2} !2 = !{!"Apple LLVM version 10.0.0 (clang-1000.11.45.5)"} 10
  11. LLVMͷษڧ๏ • LLVM Tutorial • h/ps:/ /llvm.org/docs/tutorial/ • C++ͰՍۭͷؔ਺ܕݴޠͷίϯύΠϥΛ࣮૷͢Δ 11

  12. Kaleidoscope def test(x) 1+2+x; 12

  13. define double @test(double %x) { entry: %addtmp = fadd double

    2.000000e+00, 1.000000e+00 %addtmp1 = fadd double %addtmp, %x ret double %addtmp1 } 13
  14. ࢀߟॻ੶ • ͖ͭͶ͞ΜͰ΋Θ͔ΔLLVM • LLVM Cookbook 14

  15. Swi$ίϯύΠϥΠϯλʔϯ΍Γ·͢ʂʂʂ • 3/28 @ ΫοΫύου • Ԡืड෇தʂʂʂ h"ps:/ /internship.cookpad.com/2019/spring/ 15

  16. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ @giginet 16