SlideShare a Scribd company logo
1 of 31
Download to read offline
SIL for First Time
Learners
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Hi, I'm Yusuke
@kitasuke
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Why SIL? 
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Why SIL?
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Why SIL?
• Better idea of Swift type system
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Why SIL?
• Better idea of Swift type system
• Optimizations magic !✨
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Why SIL?
• Better idea of Swift type system
• Optimizations magic !✨
• Just for fun!
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
SIL  
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Swift
Intermediate
Language
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
SIL is a language
specific Intermediate
Representation
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Swift Compiler
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Swift Compiler
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Swift Compiler
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
What SIL looks like?
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
sample.swift
func number() -> Int {
let x: Int
x = 1
return x
}
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Emit SIL
$swiftc -emit-sil sample.swift -o sample.sil
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
sample.sil
sil hidden @_T06sample6numberSiyF : $@convention(thin) () -> Int {
bb0:
%0 = alloc_stack $Int, let, name "x"
%1 = integer_literal $Builtin.Int64, 1
%2 = struct $Int (%1 : $Builtin.Int64)
store %2 to %0 : $*Int
dealloc_stack %0 : $*Int
return %2 : $Int
}
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Emit SIL with -O
$swiftc -emit-sil -O sample.swift -o sample.sil
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
sample.sil with -O
sil hidden @_T06sample6numberSiyF : $@convention(thin) () -> Int {
bb0:
%0 = integer_literal $Builtin.Int64, 1
%1 = struct $Int (%0 : $Builtin.Int64)
return %1 : $Int
}
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
sample.swift
func number() -> Int {
let x: Int
x = 1
return x
}
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
sample.swift
func number() -> Int {
return 1
}
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Diff
sil hidden @_T06sample6numberSiyF : $@convention(thin) () -> Int {
bb0:
%0 = alloc_stack $Int, let, name "x"
%1 = integer_literal $Builtin.Int64, 1
%2 = struct $Int (%1 : $Builtin.Int64)
store %2 to %0 : $*Int
dealloc_stack %0 : $*Int
return %2 : $Int
}
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
sample.sil with -O
sil hidden @_T06sample6numberSiyF : $@convention(thin) () -> Int {
bb0:
%0 = integer_literal $Builtin.Int64, 1
%1 = struct $Int (%0 : $Builtin.Int64)
return %1 : $Int
}
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Optimizations !✨
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Optimization flag
• -Onone
• -O
• -Ounchecked
• -Osize New!
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Summary
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Summary
• Somehow understandable
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Summary
• Somehow understandable
• Better idea of how Swift Compiler works
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Summary
• Somehow understandable
• Better idea of how Swift Compiler works
• Definitely worth learning!
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
References
• swift/docs/SIL.rst
• Swift's High-Level IR: A Case Study of Complementing LLVM
IR with Language-Specific Optimization
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
Thank you!
SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018

More Related Content

More from Yusuke Kita

[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipeline[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipelineYusuke Kita
 
Creating your own Bitrise step
Creating your own Bitrise stepCreating your own Bitrise step
Creating your own Bitrise stepYusuke Kita
 
Introducing swift-format
Introducing swift-formatIntroducing swift-format
Introducing swift-formatYusuke Kita
 
Unidirectional Data Flow Through SwiftUI
Unidirectional Data Flow Through SwiftUIUnidirectional Data Flow Through SwiftUI
Unidirectional Data Flow Through SwiftUIYusuke Kita
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in goYusuke Kita
 
Writing an interpreter in swift
Writing an interpreter in swiftWriting an interpreter in swift
Writing an interpreter in swiftYusuke Kita
 
How to try! Swift
How to try! SwiftHow to try! Swift
How to try! SwiftYusuke Kita
 
SIL for the first time
SIL for the first timeSIL for the first time
SIL for the first timeYusuke Kita
 
Introducing protobuf in Swift
Introducing protobuf in SwiftIntroducing protobuf in Swift
Introducing protobuf in SwiftYusuke Kita
 
Type-safe Web APIs with Protocol Buffers in Swift at AltConf
Type-safe Web APIs with Protocol Buffers in Swift at AltConfType-safe Web APIs with Protocol Buffers in Swift at AltConf
Type-safe Web APIs with Protocol Buffers in Swift at AltConfYusuke Kita
 
Type-safe Web APIs with Protocol Buffers in Swift at iOSCon
Type-safe Web APIs with Protocol Buffers in Swift at iOSConType-safe Web APIs with Protocol Buffers in Swift at iOSCon
Type-safe Web APIs with Protocol Buffers in Swift at iOSConYusuke Kita
 
SwiftCoreとFoundationを読んでみた
SwiftCoreとFoundationを読んでみたSwiftCoreとFoundationを読んでみた
SwiftCoreとFoundationを読んでみたYusuke Kita
 
Search APIs & Universal Links
Search APIs & Universal LinksSearch APIs & Universal Links
Search APIs & Universal LinksYusuke Kita
 
Introducing Cardio
Introducing CardioIntroducing Cardio
Introducing CardioYusuke Kita
 
Command Line Tool in swift
Command Line Tool in swiftCommand Line Tool in swift
Command Line Tool in swiftYusuke Kita
 
WWDCのチケット外れてもSFに行った方が良い理由
WWDCのチケット外れてもSFに行った方が良い理由WWDCのチケット外れてもSFに行った方が良い理由
WWDCのチケット外れてもSFに行った方が良い理由Yusuke Kita
 
Search APIs in Spotlight and Safari
Search APIs in Spotlight and SafariSearch APIs in Spotlight and Safari
Search APIs in Spotlight and SafariYusuke Kita
 
Protocol in Swift
Protocol in SwiftProtocol in Swift
Protocol in SwiftYusuke Kita
 

More from Yusuke Kita (20)

[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipeline[Deprecated] Integrating libSyntax into the compiler pipeline
[Deprecated] Integrating libSyntax into the compiler pipeline
 
Creating your own Bitrise step
Creating your own Bitrise stepCreating your own Bitrise step
Creating your own Bitrise step
 
Introducing swift-format
Introducing swift-formatIntroducing swift-format
Introducing swift-format
 
Unidirectional Data Flow Through SwiftUI
Unidirectional Data Flow Through SwiftUIUnidirectional Data Flow Through SwiftUI
Unidirectional Data Flow Through SwiftUI
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in go
 
Writing an interpreter in swift
Writing an interpreter in swiftWriting an interpreter in swift
Writing an interpreter in swift
 
var, let in SIL
var, let in SILvar, let in SIL
var, let in SIL
 
How to try! Swift
How to try! SwiftHow to try! Swift
How to try! Swift
 
SIL for the first time
SIL for the first timeSIL for the first time
SIL for the first time
 
Introducing protobuf in Swift
Introducing protobuf in SwiftIntroducing protobuf in Swift
Introducing protobuf in Swift
 
Type-safe Web APIs with Protocol Buffers in Swift at AltConf
Type-safe Web APIs with Protocol Buffers in Swift at AltConfType-safe Web APIs with Protocol Buffers in Swift at AltConf
Type-safe Web APIs with Protocol Buffers in Swift at AltConf
 
Type-safe Web APIs with Protocol Buffers in Swift at iOSCon
Type-safe Web APIs with Protocol Buffers in Swift at iOSConType-safe Web APIs with Protocol Buffers in Swift at iOSCon
Type-safe Web APIs with Protocol Buffers in Swift at iOSCon
 
Swift core
Swift coreSwift core
Swift core
 
SwiftCoreとFoundationを読んでみた
SwiftCoreとFoundationを読んでみたSwiftCoreとFoundationを読んでみた
SwiftCoreとFoundationを読んでみた
 
Search APIs & Universal Links
Search APIs & Universal LinksSearch APIs & Universal Links
Search APIs & Universal Links
 
Introducing Cardio
Introducing CardioIntroducing Cardio
Introducing Cardio
 
Command Line Tool in swift
Command Line Tool in swiftCommand Line Tool in swift
Command Line Tool in swift
 
WWDCのチケット外れてもSFに行った方が良い理由
WWDCのチケット外れてもSFに行った方が良い理由WWDCのチケット外れてもSFに行った方が良い理由
WWDCのチケット外れてもSFに行った方が良い理由
 
Search APIs in Spotlight and Safari
Search APIs in Spotlight and SafariSearch APIs in Spotlight and Safari
Search APIs in Spotlight and Safari
 
Protocol in Swift
Protocol in SwiftProtocol in Swift
Protocol in Swift
 

Recently uploaded

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingThe Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingSelcen Ozturkcan
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Recently uploaded (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingThe Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

SIL for First Time Leaners LT

  • 1. SIL for First Time Learners SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 2. Hi, I'm Yusuke @kitasuke SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 3. Why SIL?  SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 4. Why SIL? SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 5. Why SIL? • Better idea of Swift type system SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 6. Why SIL? • Better idea of Swift type system • Optimizations magic !✨ SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 7. Why SIL? • Better idea of Swift type system • Optimizations magic !✨ • Just for fun! SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 8. SIL   SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 9. Swift Intermediate Language SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 10. SIL is a language specific Intermediate Representation SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 11. Swift Compiler SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 12. Swift Compiler SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 13. Swift Compiler SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 14. What SIL looks like? SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 15. sample.swift func number() -> Int { let x: Int x = 1 return x } SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 16. Emit SIL $swiftc -emit-sil sample.swift -o sample.sil SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 17. sample.sil sil hidden @_T06sample6numberSiyF : $@convention(thin) () -> Int { bb0: %0 = alloc_stack $Int, let, name "x" %1 = integer_literal $Builtin.Int64, 1 %2 = struct $Int (%1 : $Builtin.Int64) store %2 to %0 : $*Int dealloc_stack %0 : $*Int return %2 : $Int } SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 18. Emit SIL with -O $swiftc -emit-sil -O sample.swift -o sample.sil SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 19. sample.sil with -O sil hidden @_T06sample6numberSiyF : $@convention(thin) () -> Int { bb0: %0 = integer_literal $Builtin.Int64, 1 %1 = struct $Int (%0 : $Builtin.Int64) return %1 : $Int } SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 20. sample.swift func number() -> Int { let x: Int x = 1 return x } SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 21. sample.swift func number() -> Int { return 1 } SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 22. Diff sil hidden @_T06sample6numberSiyF : $@convention(thin) () -> Int { bb0: %0 = alloc_stack $Int, let, name "x" %1 = integer_literal $Builtin.Int64, 1 %2 = struct $Int (%1 : $Builtin.Int64) store %2 to %0 : $*Int dealloc_stack %0 : $*Int return %2 : $Int } SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 23. sample.sil with -O sil hidden @_T06sample6numberSiyF : $@convention(thin) () -> Int { bb0: %0 = integer_literal $Builtin.Int64, 1 %1 = struct $Int (%0 : $Builtin.Int64) return %1 : $Int } SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 24. Optimizations !✨ SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 25. Optimization flag • -Onone • -O • -Ounchecked • -Osize New! SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 26. Summary SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 27. Summary • Somehow understandable SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 28. Summary • Somehow understandable • Better idea of how Swift Compiler works SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 29. Summary • Somehow understandable • Better idea of how Swift Compiler works • Definitely worth learning! SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 30. References • swift/docs/SIL.rst • Swift's High-Level IR: A Case Study of Complementing LLVM IR with Language-Specific Optimization SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  • 31. Thank you! SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018