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.9k
魅せるデバッグ技術
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.3k
Other Decks in Technology
See All in Technology
.NET 9 のパフォーマンス改善
nenonaninu
0
1k
サーバレスアプリ開発者向けアップデートをキャッチアップしてきた #AWSreInvent #regrowth_fuk
drumnistnakano
0
200
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
2
110
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
170
終了の危機にあった15年続くWebサービスを全力で存続させる - phpcon2024
yositosi
17
14k
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
270
祝!Iceberg祭開幕!re:Invent 2024データレイク関連アップデート10分総ざらい
kniino
3
310
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
210
Wantedly での Datadog 活用事例
bgpat
1
520
PHP ユーザのための OpenTelemetry 入門 / phpcon2024-opentelemetry
shin1x1
1
270
Amazon SageMaker Unified Studio(Preview)、Lakehouse と Amazon S3 Tables
ishikawa_satoru
0
160
Featured
See All Featured
Designing for humans not robots
tammielis
250
25k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
450
4 Signs Your Business is Dying
shpigford
181
21k
Unsuck your backbone
ammeep
669
57k
Practical Orchestrator
shlominoach
186
10k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Why Our Code Smells
bkeepers
PRO
335
57k
Making the Leap to Tech Lead
cromwellryan
133
9k
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ʯΛΈ͍ͯͩ͘͞
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠