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
6k
魅せるデバッグ技術
dealforest
4
1.5k
LLDB の世界からみた Swift
dealforest
4
5k
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
My small contributions - Fujiwara Tech Conference 2025
ijin
0
1.4k
Building Scalable Backend Services with Firebase
wisdommatt
0
110
Amazon Route 53, 待ちに待った TLSAレコードのサポート開始
kenichinakamura
0
170
[IBM TechXchange Dojo]Watson Discoveryとwatsonx.aiでRAGを実現!事例のご紹介+座学②
siyuanzh09
0
110
Accessibility Inspectorを活用した アプリのアクセシビリティ向上方法
hinakko
0
180
2024AWSで個人的にアツかったアップデート
nagisa53
1
110
Evolving Architecture
rainerhahnekamp
3
260
AWS re:Invent 2024 re:Cap Taipei (for Developer): New Launches that facilitate Developer Workflow and Continuous Innovation
dwchiang
0
170
Visual StudioとかIDE関連小ネタ話
kosmosebi
1
380
[IBM TechXchange Dojo]Watson Discoveryとwatsonx.aiでRAGを実現!座学①
siyuanzh09
0
110
2025年のARグラスの潮流
kotauchisunsun
0
800
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
6
54k
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
32
6.4k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
Speed Design
sergeychernyshev
25
740
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
RailsConf 2023
tenderlove
29
970
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Navigating Team Friction
lara
183
15k
YesSQL, Process and Tooling at Scale
rocio
170
14k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.5k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.3k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
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ʯΛΈ͍ͯͩ͘͞
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠