Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

SIL for First Time Leaners LT

1,235 views

Published on

try! Swift Tokyo 2018

Published in: Technology
  • Be the first to comment

SIL for First Time Leaners LT

  1. 1. SIL for First Time Learners SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  2. 2. Hi, I'm Yusuke @kitasuke SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  3. 3. Why SIL?  SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  4. 4. Why SIL? SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  5. 5. Why SIL? • Better idea of Swift type system SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  6. 6. Why SIL? • Better idea of Swift type system • Optimizations magic !✨ SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  7. 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. 8. SIL   SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  9. 9. Swift Intermediate Language SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  10. 10. SIL is a language specific Intermediate Representation SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  11. 11. Swift Compiler SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  12. 12. Swift Compiler SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  13. 13. Swift Compiler SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  14. 14. What SIL looks like? SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  15. 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. 16. Emit SIL $swiftc -emit-sil sample.swift -o sample.sil SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  17. 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. 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. 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. 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. 21. sample.swift func number() -> Int { return 1 } SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  22. 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. 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. 24. Optimizations !✨ SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  25. 25. Optimization flag • -Onone • -O • -Ounchecked • -Osize New! SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  26. 26. Summary SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  27. 27. Summary • Somehow understandable SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  28. 28. Summary • Somehow understandable • Better idea of how Swift Compiler works SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018
  29. 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. 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. 31. Thank you! SIL for First Time Learners, Yusuke Kita (@kitasuke), try! Swift Tokyo 2018

×