Slide 1

Slide 1 text

0WFSWJFXPG4XJGUD !FM@NFUBM@

Slide 2

Slide 2 text

8IZ$PNQJMFS w MFBSOIJHIUFDIOJDBMTLJMMT w NPSFVOEFSTUBOE4XJGUUZQFTZTUFN w GVO

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

SIL SILGen Parse Sema AST IRGen IR LLVM *.o Swift 4XJGU$PNQJMFS https://llvm.org/devmtg/2015-10/slides/GroffLattner-SILHighLevelIR.pdf

Slide 5

Slide 5 text

1BSTF SIL SILGen Parse Sema AST IRGen IR LLVM *.o Swift

Slide 6

Slide 6 text

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='' value=1 builtin_initializer=**NULL** initializer=**NULL**)) )) (var_decl range=[1.swift:1:5 - line:1:5] "a" type='' let readImpl=stored immutable)) swiftc -dump-parse 1.swift 1.swift let a = 1

Slide 7

Slide 7 text

4FNB SIL SILGen Parse Sema AST IRGen IR LLVM *.o Swift

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

4*-(FO SIL SILGen Parse Sema AST IRGen IR LLVM *.o Swift

Slide 10

Slide 10 text

SIL SILGen Parse Sema AST IRGen IR LLVM *.o Swift 4*-(FO 4*-(FO 4*-0QUJNJ[FS SBX 4*- DBOPOJDBM 4*-

Slide 11

Slide 11 text

SIL SILGen Parse Sema AST IRGen IR LLVM *.o Swift 4*-(FO 4*-(FO 4*-0QUJNJ[FS SBX 4*- DBOPOJDBM 4*-

Slide 12

Slide 12 text

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 : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): alloc_global @$s4main1aSivp // id: %2 %3 = global_addr @$s4main1aSivp : $*Int // user: %8 %4 = integer_literal $Builtin.IntLiteral, 1 // user: %7 %5 = metatype $@thin Int.Type // user: %7 // function_ref Int.init(_builtinIntegerLiteral:) %6 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %7 %7 = apply %6(%4, %5) : $@convention(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 : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int 4*-(FO swiftc -emit-silgen 1.swift 1.swift let a = 1

Slide 13

Slide 13 text

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 : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): alloc_global @$s4main1aSivp // id: %2 %3 = global_addr @$s4main1aSivp : $*Int // user: %8 %4 = integer_literal $Builtin.IntLiteral, 1 // user: %7 %5 = metatype $@thin Int.Type // user: %7 // function_ref Int.init(_builtinIntegerLiteral:) %6 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %7 %7 = apply %6(%4, %5) : $@convention(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 : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int 4*-(FO

Slide 14

Slide 14 text

SIL SILGen Parse Sema AST IRGen IR LLVM *.o Swift 4*-0QUJNJ[FS 4*-(FO 4*-0QUJNJ[FS SBX 4*- DBOPOJDBM 4*-

Slide 15

Slide 15 text

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 : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): 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 : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int { // %0 // user: %2 bb0(%0 : $Builtin.IntLiteral, %1 : $@thin 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

Slide 16

Slide 16 text

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 : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): 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 : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int { // %0 // user: %2 bb0(%0 : $Builtin.IntLiteral, %1 : $@thin 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'

Slide 17

Slide 17 text

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 : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): 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'

Slide 18

Slide 18 text

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 : $@convention(c) (Int32, UnsafeMutablePointer>>) -> Int32 { bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>>): 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'

Slide 19

Slide 19 text

*3(FO SIL SILGen Parse Sema AST IRGen IR LLVM *.o Swift

Slide 20

Slide 20 text

*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}

Slide 21

Slide 21 text

*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}

Slide 22

Slide 22 text

--7. SIL SILGen Parse Sema AST IRGen IR LLVM *.o Swift