Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Overview Of Swiftc
elmetal
December 06, 2019
Programming
1
150
Overview Of Swiftc
elmetal
December 06, 2019
Tweet
Share
More Decks by elmetal
See All by elmetal
「サイボウズ Office」 の iOSアプリをリニューアルした話 / Renewal "Cybozu Office" iOS App
elmetal
0
300
社会人からのスキルアップ戦略
elmetal
0
560
ScrumMasterから見るScrumの姿
elmetal
1
1.5k
kintoneとリモートスクラム
elmetal
1
2k
Other Decks in Programming
See All in Programming
Remote SSHで行うVS Codeリモートホスト開発とトラブルシューティング
smt7174
1
520
Hasura の Relationship と権限管理
karszawa
0
180
42tokyo-born2beroot-review
love42
0
130
PHPDocにおける配列の型定義を少し知る
shimabox
1
140
Gradle build: The time is now
nonews
1
510
Becoming an Android Librarian (Android World Wide 2023 Jan)
skydoves
2
230
そうだ、10Gを引こう
mattenn
0
110
ECテックカンファレンス2023
kspace
1
390
SwiftPMのPlugin入門 / introduction_to_swiftpm_plugin
uhooi
2
110
OSC大阪 パスワード認証は人類には早すぎる ~ IDaaSを使ったソーシャルログインのすすめ ~
authyasan
7
1.5k
ipa-medit: Memory search and patch tool for IPA without Jailbreaking/ipa-medit-bh2022-europe
tkmru
0
130
CDKでValidationする本当の方法 / cdk-validation
gotok365
1
270
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
34
1.5k
Docker and Python
trallard
30
1.9k
No one is an island. Learnings from fostering a developers community.
thoeni
12
1.5k
Stop Working from a Prison Cell
hatefulcrawdad
263
18k
jQuery: Nuts, Bolts and Bling
dougneiner
57
6.6k
Building an army of robots
kneath
301
40k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
236
1.1M
Thoughts on Productivity
jonyablonski
49
2.7k
Designing on Purpose - Digital PM Summit 2013
jponch
108
5.9k
Intergalactic Javascript Robots from Outer Space
tanoku
261
26k
A Modern Web Designer's Workflow
chriscoyier
689
180k
Git: the NoSQL Database
bkeepers
PRO
419
60k
Transcript
0WFSWJFXPG4XJGUD
[email protected]
@
8IZ$PNQJMFS w MFBSOIJHIUFDIOJDBMTLJMMT w NPSFVOEFSTUBOE4XJGUUZQFTZTUFN w GVO
None
SIL SILGen Parse Sema AST IRGen IR LLVM *.o Swift
4XJGU$PNQJMFS https://llvm.org/devmtg/2015-10/slides/GroffLattner-SILHighLevelIR.pdf
1BSTF SIL SILGen Parse Sema AST IRGen IR LLVM *.o
Swift
1BSTF (source_file "1.swift" (top_level_code_decl range=[1.swift:1:1 - line:1:9] (brace_stmt implicit range=[1.swift:1:1
- line:1:9] (pattern_binding_decl range=[1.swift:1:1 - line:1:9] (pattern_named 'a') (integer_literal_expr type='<null>' value=1 builtin_initializer=**NULL** initializer=**NULL**)) )) (var_decl range=[1.swift:1:5 - line:1:5] "a" type='<null type>' let readImpl=stored immutable)) swiftc -dump-parse 1.swift 1.swift let a = 1
4FNB SIL SILGen Parse Sema AST IRGen IR LLVM *.o
Swift
4FNB (source_file "1.swift" (top_level_code_decl range=[1.swift:1:1 - line:1:9] (brace_stmt implicit range=[1.swift:1:1
- line:1:9] (pattern_binding_decl range=[1.swift:1:1 - line:1:9] (pattern_named type='Int' 'a') (integer_literal_expr type='Int' location=1.swift:1:9 range=[1.swift:1:9 - line:1:9] value=1 builtin_initializer=Swift.(file).Int.init(_builtinIntegerLiteral:) initializer=**NULL**)) )) (var_decl range=[1.swift:1:5 - line:1:5] "a" type='Int' interface type='Int' access=internal let readImpl=stored immutable)) swiftc -dump-ast 1.swift 1.swift let a = 1
4*-(FO SIL SILGen Parse Sema AST IRGen IR LLVM *.o
Swift
SIL SILGen Parse Sema AST IRGen IR LLVM *.o Swift
4*-(FO 4*-(FO 4*-0QUJNJ[FS SBX 4*- DBOPOJDBM 4*-
SIL SILGen Parse Sema AST IRGen IR LLVM *.o Swift
4*-(FO 4*-(FO 4*-0QUJNJ[FS SBX 4*- DBOPOJDBM 4*-
sil_stage raw import Builtin import Swift import SwiftShims @_hasStorage @_hasInitialValue
let a: Int { get } // a sil_global hidden [let] @$s4main1aSivp : $Int // main sil [ossa] @main :
[email protected]
(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): alloc_global @$s4main1aSivp // id: %2 %3 = global_addr @$s4main1aSivp : $*Int // user: %8 %4 = integer_literal $Builtin.IntLiteral, 1 // user: %7 %5 = metatype
[email protected]
Int.Type // user: %7 // function_ref Int.init(_builtinIntegerLiteral:) %6 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC :
[email protected]
(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %7 %7 = apply %6(%4, %5) :
[email protected]
(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %8 store %7 to [trivial] %3 : $*Int // id: %8 %9 = integer_literal $Builtin.Int32, 0 // user: %10 %10 = struct $Int32 (%9 : $Builtin.Int32) // user: %11 return %10 : $Int32 // id: %11 } // end sil function 'main' // Int.init(_builtinIntegerLiteral:) sil [transparent] [serialized] @$sSi22_builtinIntegerLiteralSiBI_tcfC :
[email protected]
(method) (Builtin.IntLiteral, @thin Int.Type) -> Int 4*-(FO swiftc -emit-silgen 1.swift 1.swift let a = 1
sil_stage raw import Builtin import Swift import SwiftShims @_hasStorage @_hasInitialValue
let a: Int { get } // a sil_global hidden [let] @$s4main1aSivp : $Int // main sil [ossa] @main :
[email protected]
(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): alloc_global @$s4main1aSivp // id: %2 %3 = global_addr @$s4main1aSivp : $*Int // user: %8 %4 = integer_literal $Builtin.IntLiteral, 1 // user: %7 %5 = metatype
[email protected]
Int.Type // user: %7 // function_ref Int.init(_builtinIntegerLiteral:) %6 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC :
[email protected]
(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %7 %7 = apply %6(%4, %5) :
[email protected]
(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %8 store %7 to [trivial] %3 : $*Int // id: %8 %9 = integer_literal $Builtin.Int32, 0 // user: %10 %10 = struct $Int32 (%9 : $Builtin.Int32) // user: %11 return %10 : $Int32 // id: %11 } // end sil function 'main' // Int.init(_builtinIntegerLiteral:) sil [transparent] [serialized] @$sSi22_builtinIntegerLiteralSiBI_tcfC :
[email protected]
(method) (Builtin.IntLiteral, @thin Int.Type) -> Int 4*-(FO
SIL SILGen Parse Sema AST IRGen IR LLVM *.o Swift
4*-0QUJNJ[FS 4*-(FO 4*-0QUJNJ[FS SBX 4*- DBOPOJDBM 4*-
4*-0QUJNJ[FS sil_stage canonical import Builtin import Swift import SwiftShims @_hasStorage
@_hasInitialValue let a: Int { get } // a sil_global hidden [let] @$s4main1aSivp : $Int // main sil @main :
[email protected]
(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): alloc_global @$s4main1aSivp // id: %2 %3 = global_addr @$s4main1aSivp : $*Int // user: %6 %4 = integer_literal $Builtin.Int64, 1 // user: %5 %5 = struct $Int (%4 : $Builtin.Int64) // user: %6 store %5 to %3 : $*Int // id: %6 %7 = integer_literal $Builtin.Int32, 0 // user: %8 %8 = struct $Int32 (%7 : $Builtin.Int32) // user: %9 return %8 : $Int32 // id: %9 } // end sil function 'main' // Int.init(_builtinIntegerLiteral:) sil public_external [transparent] [serialized] @$sSi22_builtinIntegerLiteralSiBI_tcfC :
[email protected]
(method) (Builtin.IntLiteral, @thin Int.Type) -> Int { // %0 // user: %2 bb0(%0 : $Builtin.IntLiteral, %1 :
[email protected]
Int.Type): %2 = builtin "s_to_s_checked_trunc_IntLiteral_Int64"(%0 : $Builtin.IntLiteral) : $(Builtin.Int64, Builtin.Int1) // user: %3 %3 = tuple_extract %2 : $(Builtin.Int64, Builtin.Int1), 0 // user: %4 %4 = struct $Int (%3 : $Builtin.Int64) // user: %5 return %4 : $Int // id: %5 } // end sil function '$sSi22_builtinIntegerLiteralSiBI_tcfC' swiftc -emit-sil 1.swift 1.swift let a = 1
4*-0QUJNJ[FS sil_stage canonical import Builtin import Swift import SwiftShims @_hasStorage
@_hasInitialValue let a: Int { get } // a sil_global hidden [let] @$s4main1aSivp : $Int // main sil @main :
[email protected]
(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): alloc_global @$s4main1aSivp // id: %2 %3 = global_addr @$s4main1aSivp : $*Int // user: %6 %4 = integer_literal $Builtin.Int64, 1 // user: %5 %5 = struct $Int (%4 : $Builtin.Int64) // user: %6 store %5 to %3 : $*Int // id: %6 %7 = integer_literal $Builtin.Int32, 0 // user: %8 %8 = struct $Int32 (%7 : $Builtin.Int32) // user: %9 return %8 : $Int32 // id: %9 } // end sil function 'main' // Int.init(_builtinIntegerLiteral:) sil public_external [transparent] [serialized] @$sSi22_builtinIntegerLiteralSiBI_tcfC :
[email protected]
(method) (Builtin.IntLiteral, @thin Int.Type) -> Int { // %0 // user: %2 bb0(%0 : $Builtin.IntLiteral, %1 :
[email protected]
Int.Type): %2 = builtin "s_to_s_checked_trunc_IntLiteral_Int64"(%0 : $Builtin.IntLiteral) : $(Builtin.Int64, Builtin.Int1) // user: %3 %3 = tuple_extract %2 : $(Builtin.Int64, Builtin.Int1), 0 // user: %4 %4 = struct $Int (%3 : $Builtin.Int64) // user: %5 return %4 : $Int // id: %5 } // end sil function '$sSi22_builtinIntegerLiteralSiBI_tcfC'
4*-0QUJNJ[FS swiftc -O —emit-sil 1.swift 1.swift let a = 1
sil_stage canonical import Builtin import Swift import SwiftShims @_hasStorage @_hasInitialValue let a: Int { get } // a sil_global hidden [let] @$s4main1aSivp : $Int // main sil @main :
[email protected]
(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): alloc_global @$s4main1aSivp // id: %2 %3 = global_addr @$s4main1aSivp : $*Int // user: %6 %4 = integer_literal $Builtin.Int64, 1 // user: %5 %5 = struct $Int (%4 : $Builtin.Int64) // user: %6 store %5 to %3 : $*Int // id: %6 %7 = integer_literal $Builtin.Int32, 0 // user: %8 %8 = struct $Int32 (%7 : $Builtin.Int32) // user: %9 return %8 : $Int32 // id: %9 } // end sil function 'main'
4*-0QUJNJ[FS sil_stage canonical import Builtin import Swift import SwiftShims @_hasStorage
@_hasInitialValue let a: Int { get } // a sil_global hidden [let] @$s4main1aSivp : $Int // main sil @main :
[email protected]
(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): alloc_global @$s4main1aSivp // id: %2 %3 = global_addr @$s4main1aSivp : $*Int // user: %6 %4 = integer_literal $Builtin.Int64, 1 // user: %5 %5 = struct $Int (%4 : $Builtin.Int64) // user: %6 store %5 to %3 : $*Int // id: %6 %7 = integer_literal $Builtin.Int32, 0 // user: %8 %8 = struct $Int32 (%7 : $Builtin.Int32) // user: %9 return %8 : $Int32 // id: %9 } // end sil function 'main'
*3(FO SIL SILGen Parse Sema AST IRGen IR LLVM *.o
Swift
*3(FO swiftc -emit-ir 1.swift 1.swift let a = 1 ;
ModuleID = '-' source_filename = "-" target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.14.0" %TSi = type <{ i64 }> @"$s4main1aSivp" = hidden global %TSi zeroinitializer, align 8 @"_swift_FORCE_LOAD_$_swiftCompatibility50_$_main" = weak_odr hidden constant void ()* @"_swift_FORCE_LOAD_$_swiftCompatibility50" @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements_$_main" = weak_odr hidden constant void ()* @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements" @__swift_reflection_version = linkonce_odr hidden constant i16 3 @llvm.used = appending global [3 x i8*] [i8* bitcast (void ()** @"_swift_FORCE_LOAD_$_swiftCompatibility50_$_main" to i8*), i8* bitcast (void ()** @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements_$_main" to i8*), i8* bitcast (i16* @__swift_reflection_version to i8*)], section "llvm.metadata", align 8 define i32 @main(i32, i8**) #0 { entry: %2 = bitcast i8** %1 to i8* store i64 1, i64* getelementptr inbounds (%TSi, %TSi* @"$s4main1aSivp", i32 0, i32 0), align 8 ret i32 0 } declare extern_weak void @"_swift_FORCE_LOAD_$_swiftCompatibility50"() declare extern_weak void @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"() attributes #0 = { "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" } !llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} !swift.module.flags = !{!9} !llvm.linker.options = !{!10, !11, !12, !13, !14} !llvm.asan.globals = !{!15} !0 = !{i32 2, !"SDK Version", [2 x i32] [i32 10, i32 15]} !1 = !{i32 1, !"Objective-C Version", i32 2} !2 = !{i32 1, !"Objective-C Image Info Version", i32 0} !3 = !{i32 1, !"Objective-C Image Info Section", !"__DATA,__objc_imageinfo,regular,no_dead_strip"} !4 = !{i32 4, !"Objective-C Garbage Collection", i32 83953408} !5 = !{i32 1, !"Objective-C Class Properties", i32 64} !6 = !{i32 1, !"wchar_size", i32 4} !7 = !{i32 7, !"PIC Level", i32 2} !8 = !{i32 1, !"Swift Version", i32 7} !9 = !{!"standard-library", i1 false} !10 = !{!"-lswiftSwiftOnoneSupport"} !11 = !{!"-lswiftCore"} !12 = !{!"-lobjc"} !13 = !{!"-lswiftCompatibility50"} !14 = !{!"-lswiftCompatibilityDynamicReplacements"} !15 = !{[3 x i8*]* @llvm.used, null, null, i1 false, i1 true}
*3(FO ; ModuleID = '-' source_filename = "-" target datalayout
= "e-m:o-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.14.0" %TSi = type <{ i64 }> @"$s4main1aSivp" = hidden global %TSi zeroinitializer, align 8 @"_swift_FORCE_LOAD_$_swiftCompatibility50_$_main" = weak_odr hidden constant void ()* @"_swift_FORCE_LOAD_$_swiftCompatibility50" @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements_$_main" = weak_odr hidden constant void ()* @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements" @__swift_reflection_version = linkonce_odr hidden constant i16 3 @llvm.used = appending global [3 x i8*] [i8* bitcast (void ()** @"_swift_FORCE_LOAD_$_swiftCompatibility50_$_main" to i8*), i8* bitcast (void ()** @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements_$_main" to i8*), i8* bitcast (i16* @__swift_reflection_version to i8*)], section "llvm.metadata", align 8 define i32 @main(i32, i8**) #0 { entry: %2 = bitcast i8** %1 to i8* store i64 1, i64* getelementptr inbounds (%TSi, %TSi* @"$s4main1aSivp", i32 0, i32 0), align 8 ret i32 0 } declare extern_weak void @"_swift_FORCE_LOAD_$_swiftCompatibility50"() declare extern_weak void @"_swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements"() attributes #0 = { "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sahf,+sse, +sse2,+sse3,+sse4.1,+ssse3,+x87" } !llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8} !swift.module.flags = !{!9} !llvm.linker.options = !{!10, !11, !12, !13, !14} !llvm.asan.globals = !{!15} !0 = !{i32 2, !"SDK Version", [2 x i32] [i32 10, i32 15]} !1 = !{i32 1, !"Objective-C Version", i32 2} !2 = !{i32 1, !"Objective-C Image Info Version", i32 0} !3 = !{i32 1, !"Objective-C Image Info Section", !"__DATA,__objc_imageinfo,regular,no_dead_strip"} !4 = !{i32 4, !"Objective-C Garbage Collection", i32 83953408} !5 = !{i32 1, !"Objective-C Class Properties", i32 64} !6 = !{i32 1, !"wchar_size", i32 4} !7 = !{i32 7, !"PIC Level", i32 2} !8 = !{i32 1, !"Swift Version", i32 7} !9 = !{!"standard-library", i1 false} !10 = !{!"-lswiftSwiftOnoneSupport"} !11 = !{!"-lswiftCore"} !12 = !{!"-lobjc"} !13 = !{!"-lswiftCompatibility50"} !14 = !{!"-lswiftCompatibilityDynamicReplacements"} !15 = !{[3 x i8*]* @llvm.used, null, null, i1 false, i1 true}
--7. SIL SILGen Parse Sema AST IRGen IR LLVM *.o
Swift