Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
iOS エンジニアのための LLVM Optimiazation
Search
Toshihiro Morimoto
November 29, 2014
Technology
2
1.5k
iOS エンジニアのための LLVM Optimiazation
横浜へなちょこiOS勉強会#34.1 での発表資料です
Toshihiro Morimoto
November 29, 2014
Tweet
Share
More Decks by Toshihiro Morimoto
See All by Toshihiro Morimoto
Xcode8 で開発はどうかわったのか
dealforest
10
5.8k
魅せるデバッグ技術
dealforest
4
1.5k
LLDB の世界からみた Swift
dealforest
4
4.9k
Xcode で快適なデバッグライフを追い求める
dealforest
29
22k
Intrducing debug in WWDC2016
dealforest
3
750
swift build と Xcode での Build の違い
dealforest
3
2k
RIP Xcode Plugin 🙏
dealforest
0
4.7k
Introducing Xcode Editor Extension
dealforest
2
4.5k
Introducing Anglerfish
dealforest
2
3.2k
Other Decks in Technology
See All in Technology
[AWS JAPAN 生成AIハッカソン] Dialog の紹介
yoshimi0227
0
150
事業者間調整の行間を読む 調整の具体事例
sugiim
0
1.5k
Shift-from-React-to-Vue
calm1205
3
1.3k
わたしとトラックポイント / TrackPoint tips
masahirokawahara
1
240
Automated Promptingを目指すその前に / Before we can aim for Automated Prompting
rkaga
0
110
生成AIと知識グラフの相互利用に基づく文書解析
koujikozaki
1
140
CyberAgent 生成AI Deep Dive with Amazon Web Services / genai-aws
cyberagentdevelopers
PRO
1
480
AWS CDKでデータリストアの運用、どのように設計する?~Aurora・EFSの実践事例を紹介~/aws-cdk-data-restore-aurora-efs
mhrtech
4
660
マネジメント視点でのre:Invent参加 ~もしCEOがre:Inventに行ったら~
kojiasai
0
470
【技術書典17】OpenFOAM(自宅で極める流体解析)2次元円柱まわりの流れ
kamakiri1225
0
220
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
27
12k
AWS CodePipelineでコンテナアプリをデプロイした際に、古いイメージを自動で削除する
smt7174
1
110
Featured
See All Featured
Designing for Performance
lara
604
68k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Learning to Love Humans: Emotional Interface Design
aarron
272
40k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Agile that works and the tools we love
rasmusluckow
327
21k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Measuring & Analyzing Core Web Vitals
bluesmoon
1
41
Designing Experiences People Love
moore
138
23k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
7
150
Code Review Best Practice
trishagee
64
17k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.6k
Transcript
iOS ΤϯδχΞͷͨΊͷ LLVM Optimiazation 2014/11/29 ԣͳͪΐ͜iOSษڧձ#34.1 @dealforest Toshihro Morimoto
ࣗݾհ http://about.me/dealforest ! ! iOS App / Web Application(perl, ruby)
@dealforest Toshihro Morimoto
Έͳ͞Μ ͜Μͳܦݧ͋Γ·ͤΜ͔ʁ
Debug ϏϧυͰ͔֬͠ೝͤͣ ৹ࠪʹͩͯ͠͠·ͬͨ͜ͱ
͍͟ϦϦʔε͞ΕΔͱ...
ʊਓਓਓਓਓਓਓਓʊ ʼɹಥવͷ Crashɹʻ ʉY^Y^Y^Y^Y^Y^Yʉ
ͳͥͦΜͳ͜ͱ͕͓͖Δͷ͔ʁ
LLVM ͷ࠷దԽʹΑΓ ͜ͷΑ͏ͳ͜ͱ͕ ى͖ͯ͠·͏έʔε͕͋Γ·͢
LLVM ͷ࠷దԽԿΛ͍ͯ͠Δͷ͔ʁ
όΠφϦαΠζΛখͨ͘͞͠Γ ॲཧΛߴԽͨ͠Γ͠·͢ (༰ઃఆʹΑͬͯมΘΓ·͢)
ͪΌΜͱ Release ϏϧυͰ ςετ͠Ζͬͯݴ͑ ͦ͏ͳΜͰ͚͢ͲͶɻɻɻɻ
Ͳ͏ͯ͠࠷దԽͰ Crash ͢ΔΑ͏ʹ ͳͬͯ͠·ͬͨͷ͔
࠷దԽͰԿ͕ߦΘΕ͍ͯΔͷ͔
ࠓճͦΕΛௐͯΈ·ͨ͠
ҙࣄ߲ ༻ޠ / ༻๏ڞʹؒҧ͍͕͋ΔՄೳੑ͕ ͋Γ·͢ͷͰ͔͋͠Βͣ
ͦͦͲ͜Ͱઃఆ͢Δͷʁ
Build Settings
࠷దԽͷछྨ • O0 : ࠷͘ίϯύΠϧग़དྷɺ࠷σόοΨϒϧͳίʔυΛ ੜ͢Δɻ࠷దԽͳ͠ • O1 : جຊతͳ࠷దԽΛ࣮ߦ͢Δ
• O2 : ΄ͱΜͲͯ͢ͷ࠷దԽΛ࣮ߦ͢Δ • O3 : O2 ͱࣅ͍ͯΔ͕ίϯύΠϧʹΑΓ͕͔͔࣌ؒΓ αΠζ͕େ͖͘ͳΔɻ͔͠͠ੑೳͷྑ͍ίʔυΛੜ͢Δ • Os : O2ͷ࠷దԽʹՃ͑ͯίʔυαΠζΛ͑Δ • Ofast : نΛҰ෦ແࢹͨ͠࠷దԽΛߦ͏Α͏ͳͷͰΘͳ͍΄͏ ͕͍͍Ͱ͢ɻ by Compiler-Level Optimizations
͍·͍ͪϐϯͱ͖·ͤΜͶ
Ξότ͗͢Δ…
͜ΕΛΔͨΊʹ LLVM ͷਂΛ ͔ͳ͍ͱ͍͚·ͤΜͰͨ͠
ͱ͍ͬͯ LLVM ͷ֓೦ࣗମ͕ γϯϓϧͰͱ͔ͯΓ͍͢ʂ
ͦͦ LLVM ͬͯԿʁ
LLVM
LLVM LLVM ͱɺίϯύΠϧ࣌ɺϦϯΫ࣌ɺ࣮ߦ࣌ͳͲ ͋ΒΏΔ࣌ͰϓϩάϥϜΛ࠷దԽ͢ΔΑ͏ઃܭ ͞ΕͨɺҙͷϓϩάϥϛϯάݴޠʹରԠՄೳͳ ίϯύΠϥج൫Ͱ͋ΔɻॳɺLLVM ͷ໊শͷ༝ དྷɺLow Level Virtual
Machine (ਫ४Ծػց) ͷུͰ͋Δͱ͍͕ͯͨ͠ɺݱࡏɺԿͷ಄จࣈͰ ͳ͍ͱ͍ͯ͠Δɻ by Wikipekia
LLVM - Phase- by LLVM and NVVM
LLVM - Phase- • Front-end • Middle-end • Back-end
LLVM - Phase Front-end - • ࣈ۟ղੳ • ߏจղੳ •
தؒίʔυ(LLVM IR)࡞
LLVM - Phase Middle-end - தؒίʔυͷ࠷దԽΛ͠ɺ ࠷దԽ͞ΕͨதؒίʔυΛग़ྗ͢Δ
LLVM - Phase Back-end - ࠷దԽ͞Εͨதؒίʔυ͔Βλʔήοτʹ ߹ΘͤͨίʔυΛग़ྗ͢Δ ಛఆͷ CPU ͷωΠςΟϒίʔυͱ͔
Javascript ͱ͔
;Ή;Ή
ࠓճ࠷దԽͷ͜ͱΛΓ͍ͨͷͰ Middle-end ΛௐΕΑͦ͞͏Ͱ͢Ͷ
Middle-end(LLVM optimiser) Λ ௐ͍ͯ͘ͱ Pass ͱ͍͏Έʹ ͍͖͖ͭ·͢
Pass Middle-end Ͱ࠷దԽ͢ΔॲཧΛ͍ͯ͠Δ LLVM IR ͷίʔυΛରʹɺͦͷ༰Λղ ੳ͠ɺ࠷దԽɺ໋ྩͷஔͳͲΛߦ͏ͨ ΊͷϑϨʔϜϫʔΫ
ͭ·ΓͲΜͳ Pass ͕࣮ߦ͞Ε͍ͯΔ͔Λ ௐΕͲΜͳ࠷దԽ͕ߦΘΕ͍ͯΔ͔͕ ͔Δͱ͍͏Θ͚Ͱ͢Ͷ
ڥߏங $ brew install llvm ! `/usr/local/Cellar/llvm/3.5.0/bin/opt` ͱ࣮ߦ͢ Δͷ͕ΊΜͲ͍͘͞߹ `brew
link llvm` Λ࣮ߦ͢Δ
ௐࠪϑϩʔ 1. ࠷దԽͳ͠ͷ .o ϑΝΠϧΛ࡞͢Δઃ ఆΛௐΔ 2. ͦͷઃఆΛ༻͍ͯதؒίʔυ(LLVM IR)Λ ࡞
3. ֤࠷దԽΛ࣮ߦͯ͠ϑΝΠϧʹग़ྗ 4. diff ΛͱΓ Pass ͷࠩΛௐΔ
࠷దԽͳ͠ͷ .o ϑΝΠϧΛ ࡞͢ΔઃఆΛௐΔ xcodebuild build -configuration Debug
தؒίʔυ(LLVM IR)Λ࡞ • ઌ΄ͲௐͨઃఆΛར༻ • `-S -emit-llvm` ΦϓγϣϯΛՃͯ͠த ؒίʔυΛग़ྗ •
`-o` ͷΛมߋͯ͠தؒίʔυͷग़ྗઌ Λมߋ(.o -> .ll)
֤࠷దԽΛ࣮ߦͯ͠ϑΝΠϧʹग़ྗ $ /usr/local/Cellar/llvm/3.5.0/bin/opt \ -debug-pass=Structure \ -O1 [தؒίʔυ].ll > /dev/null
! ඞཁͳใඪ४Τϥʔग़ྗʹදࣔ͞ΕΔ
֤࠷దԽΛ࣮ߦͯ͠ϑΝΠϧʹग़ྗ
ݟʹ͍͘ͷͰ gist ʹ·ͱΊ·ͨ͠ https://gist.github.com/dealforest/ 718df40a09d8e27758c7
ͦͦ Debug ࣌ Os Ε͍͍Μ͡Ό...
! ͱࢥ͚ͬͨͲɺίϯύΠϧ͕͔͔࣌ؒΔͷͱɺC, C++ ͷίʔυͰ BreakPoint Λֻ͚ͨΓ͢Δͱશ͘ ݟҧ͍ͳߦͰఀࢭͨ͠Γ͠·͢ ͳͷͰ։ൃαΠΫϧʹӨڹ͕Ͱͯ͠·͏ͷͰ O0 ͕
࠾༻͞Ε͍ͯΔͱΘ͚Ͱ͢Ͷɻೲಘ @niwatako ͞Μᐌ͘ɺObjective-C ͰͣΕΔΒ͍͠ Ͱ͢
·ͱΊ ࠷దԽࢥͬͯΔҎ্ʹ৭ʑ͍ͬͯ͡ΔͷͰͪΌ Μͱ֬ೝ͠·͠ΐ͏ Ή͠Ζ֬ೝ͔ͯ͠Β͡Όͳ͍ͱɺ৹ࠪʹͩͤͳ͍ εΩʔϜΛͭ͘Δ͜ͱ͕େࣄ
http://www.amazon.co.jp/dp/4883379310/
͓·͚ Xcode6 ͔ΒՃ͞Εͨ Profile Guided Optimization(PGO) ͱ͍͏࠷దԽ͕͋Δ ؆୯ʹ͍͏ͱɺ༻සͷߴ͍ॱʹίʔυϨΠΞ τΛ࠷దԽ͢ΔΒ͍͠ ͘ͳΔΑʂ
͓·͚ Xcode6 ͔ΒՃ͞Εͨ࠷దԽ Profile Guided Optimization(PGO) ͕͋Δ ؆୯ʹ͍͏ͱΑ͘͏ॱ൪ʹίʔυϨΠΞτΛ ࠷దԽ͢ΔΒ͍͠ ͘ͳΔΑʂ
͓·͚ ৄ͘͠ʮ What's New in LLVMʯΛΈ͍ͯͩ͘͞
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠