Last active
January 2, 2017 14:36
-
-
Save hamishknight/a369243158e875e5ea9d1a6e22212802 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For the code: | |
struct Foo { | |
var foo = 0 | |
var bar = 1 | |
} | |
var f = Foo() | |
f.foo = 7 | |
// The relevant SIL that is generated (from xcrun swiftc -emit-sil main.swift | xcrun swift-demangle > main.silgen): | |
// create new Foo instance | |
alloc_global @main.f : main.Foo, loc "main.swift":14:5, scope 1 // id: %11 | |
%12 = global_addr @main.f : main.Foo : $*Foo, loc "main.swift":14:5, scope 1 // users: %19, %16 | |
// function_ref Foo.init() -> Foo | |
%13 = function_ref @main.Foo.init () -> main.Foo : $@convention(method) (@thin Foo.Type) -> Foo, loc "main.swift":14:9, scope 1 // user: %15 | |
%14 = metatype $@thin Foo.Type, loc "main.swift":14:9, scope 1 // user: %15 | |
%15 = apply %13(%14) : $@convention(method) (@thin Foo.Type) -> Foo, loc "main.swift":14:13, scope 1 // user: %16 | |
store %15 to %12 : $*Foo, loc "main.swift":14:13, scope 1 // id: %16 | |
// f.foo = 7... | |
// create new integer literal 7 | |
%17 = integer_literal $Builtin.Int64, 7, loc "main.swift":15:9, scope 1 // user: %18 | |
// create new Int out of the integer literal | |
%18 = struct $Int (%17 : $Builtin.Int64), loc "main.swift":15:9, scope 1 // user: %20 | |
// get the address of the property 'foo' in the Foo instance. | |
%19 = struct_element_addr %12 : $*Foo, #Foo.foo, loc "main.swift":15:7, scope 1 // user: %20 | |
// store the new Int at that address | |
store %18 to %19 : $*Int, loc "main.swift":15:7, scope 1 // id: %20 | |
// Full SIL generated: | |
sil_stage canonical | |
import Builtin | |
import Swift | |
import SwiftShims | |
// f | |
sil_global hidden @main.f : main.Foo : $Foo | |
// static CommandLine._argc | |
sil_global [fragile] @static Swift.CommandLine._argc : Swift.Int32 : $Int32 | |
// globalinit_33_FD9A49A256BEB6AF7C48013347ADC3BA_token4 | |
sil_global private_external [fragile] @globalinit_33_FD9A49A256BEB6AF7C48013347ADC3BA_token4 : $Builtin.Word | |
// static CommandLine._unsafeArgv | |
sil_global [fragile] @static Swift.CommandLine._unsafeArgv : Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>?> : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>> | |
sil_scope 1 { parent @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 } | |
// main | |
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { | |
// %0 // user: %3 | |
// %1 // user: %9 | |
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): | |
%2 = global_addr @static Swift.CommandLine._argc : Swift.Int32 : $*Int32, scope 1 // user: %3 | |
store %0 to %2 : $*Int32, scope 1 // id: %3 | |
%4 = global_addr @globalinit_33_FD9A49A256BEB6AF7C48013347ADC3BA_token4 : $*Builtin.Word, scope 1 // user: %5 | |
%5 = address_to_pointer %4 : $*Builtin.Word to $Builtin.RawPointer, scope 1 // user: %7 | |
// function_ref globalinit_33_FD9A49A256BEB6AF7C48013347ADC3BA_func4 | |
%6 = function_ref @globalinit_33_FD9A49A256BEB6AF7C48013347ADC3BA_func4 : $@convention(thin) () -> (), scope 1 // user: %7 | |
%7 = builtin "once"(%5 : $Builtin.RawPointer, %6 : $@convention(thin) () -> ()) : $(), scope 1 | |
%8 = global_addr @static Swift.CommandLine._unsafeArgv : Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>?> : $*UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>, scope 1 // user: %9 | |
store %1 to %8 : $*UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>, scope 1 // id: %9 | |
%10 = tuple (), scope 1 | |
// create new Foo instance | |
alloc_global @main.f : main.Foo, loc "main.swift":14:5, scope 1 // id: %11 | |
%12 = global_addr @main.f : main.Foo : $*Foo, loc "main.swift":14:5, scope 1 // users: %19, %16 | |
// function_ref Foo.init() -> Foo | |
%13 = function_ref @main.Foo.init () -> main.Foo : $@convention(method) (@thin Foo.Type) -> Foo, loc "main.swift":14:9, scope 1 // user: %15 | |
%14 = metatype $@thin Foo.Type, loc "main.swift":14:9, scope 1 // user: %15 | |
%15 = apply %13(%14) : $@convention(method) (@thin Foo.Type) -> Foo, loc "main.swift":14:13, scope 1 // user: %16 | |
store %15 to %12 : $*Foo, loc "main.swift":14:13, scope 1 // id: %16 | |
// f.foo = 7... | |
// create new integer literal 7 | |
%17 = integer_literal $Builtin.Int64, 7, loc "main.swift":15:9, scope 1 // user: %18 | |
// create new Int out of the integer literal | |
%18 = struct $Int (%17 : $Builtin.Int64), loc "main.swift":15:9, scope 1 // user: %20 | |
// get the address of the property 'foo' in the Foo instance. | |
%19 = struct_element_addr %12 : $*Foo, #Foo.foo, loc "main.swift":15:7, scope 1 // user: %20 | |
// store the new Int at that address | |
store %18 to %19 : $*Int, loc "main.swift":15:7, scope 1 // id: %20 | |
%21 = integer_literal $Builtin.Int32, 0, scope 1 // user: %22 | |
%22 = struct $Int32 (%21 : $Builtin.Int32), scope 1 // user: %23 | |
return %22 : $Int32, scope 1 // id: %23 | |
} | |
sil_scope 2 { parent @Swift._stdlib_didEnterMain (argc : Swift.Int32, argv : Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>?>) -> () : $@convention(thin) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> () } | |
// _stdlib_didEnterMain(argc : Int32, argv : UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>) -> () | |
sil public_external [transparent] [fragile] @Swift._stdlib_didEnterMain (argc : Swift.Int32, argv : Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>?>) -> () : $@convention(thin) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> () { | |
// %0 // users: %5, %2 | |
// %1 // users: %11, %3 | |
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): | |
debug_value %0 : $Int32, scope 2 // id: %2 | |
debug_value %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>, scope 2 // id: %3 | |
%4 = global_addr @static Swift.CommandLine._argc : Swift.Int32 : $*Int32, scope 2 // user: %5 | |
store %0 to %4 : $*Int32, scope 2 // id: %5 | |
%6 = global_addr @globalinit_33_FD9A49A256BEB6AF7C48013347ADC3BA_token4 : $*Builtin.Word, scope 2 // user: %7 | |
%7 = address_to_pointer %6 : $*Builtin.Word to $Builtin.RawPointer, scope 2 // user: %9 | |
// function_ref globalinit_33_FD9A49A256BEB6AF7C48013347ADC3BA_func4 | |
%8 = function_ref @globalinit_33_FD9A49A256BEB6AF7C48013347ADC3BA_func4 : $@convention(thin) () -> (), scope 2 // user: %9 | |
%9 = builtin "once"(%7 : $Builtin.RawPointer, %8 : $@convention(thin) () -> ()) : $(), scope 2 | |
%10 = global_addr @static Swift.CommandLine._unsafeArgv : Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>?> : $*UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>, scope 2 // user: %11 | |
store %1 to %10 : $*UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>, scope 2 // id: %11 | |
%12 = tuple (), scope 2 // user: %13 | |
return %12 : $(), scope 2 // id: %13 | |
} | |
sil_scope 3 { loc "main.swift":10:9 parent @main.Foo.foo.getter : Swift.Int : $@convention(method) (Foo) -> Int } | |
sil_scope 4 { loc "main.swift":10:9 parent 3 } | |
// Foo.foo.getter | |
sil hidden [transparent] @main.Foo.foo.getter : Swift.Int : $@convention(method) (Foo) -> Int { | |
// %0 // users: %2, %1 | |
bb0(%0 : $Foo): | |
debug_value %0 : $Foo, let, name "self", argno 1, loc "main.swift":10:9, scope 3 // id: %1 | |
%2 = struct_extract %0 : $Foo, #Foo.foo, scope 4 // user: %3 | |
return %2 : $Int, loc "main.swift":10:9, scope 4 // id: %3 | |
} | |
sil_scope 5 { loc "main.swift":10:9 parent @main.Foo.foo.setter : Swift.Int : $@convention(method) (Int, @inout Foo) -> () } | |
sil_scope 6 { loc "main.swift":10:9 parent 5 } | |
// Foo.foo.setter | |
sil hidden [transparent] @main.Foo.foo.setter : Swift.Int : $@convention(method) (Int, @inout Foo) -> () { | |
// %0 // users: %5, %3 | |
// %1 // users: %2, %4 | |
bb0(%0 : $Int, %1 : $*Foo): | |
debug_value_addr %1 : $*Foo, var, name "self", argno 2, loc "main.swift":10:9, scope 5 // id: %2 | |
debug_value %0 : $Int, let, name "value", argno 1, loc "main.swift":10:9, scope 5 // id: %3 | |
%4 = struct_element_addr %1 : $*Foo, #Foo.foo, scope 6 // user: %5 | |
store %0 to %4 : $*Int, scope 6 // id: %5 | |
%6 = tuple (), loc "main.swift":10:9, scope 6 // user: %7 | |
return %6 : $(), loc "main.swift":10:9, scope 6 // id: %7 | |
} | |
sil_scope 7 { loc "main.swift":10:9 parent @main.Foo.foo.materializeForSet : Swift.Int : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout Foo) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>) } | |
// Foo.foo.materializeForSet | |
sil hidden [transparent] @main.Foo.foo.materializeForSet : Swift.Int : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout Foo) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>) { | |
// %2 // user: %3 | |
bb0(%0 : $Builtin.RawPointer, %1 : $*Builtin.UnsafeValueBuffer, %2 : $*Foo): | |
%3 = struct_element_addr %2 : $*Foo, #Foo.foo, scope 7 // user: %4 | |
%4 = address_to_pointer %3 : $*Int to $Builtin.RawPointer, scope 7 // user: %6 | |
%5 = enum $Optional<Builtin.RawPointer>, #Optional.none!enumelt, scope 7 // user: %6 | |
%6 = tuple (%4 : $Builtin.RawPointer, %5 : $Optional<Builtin.RawPointer>), scope 7 // user: %7 | |
return %6 : $(Builtin.RawPointer, Optional<Builtin.RawPointer>), scope 7 // id: %7 | |
} | |
sil_scope 8 { loc "main.swift":11:9 parent @main.Foo.bar.getter : Swift.Int : $@convention(method) (Foo) -> Int } | |
sil_scope 9 { loc "main.swift":11:9 parent 8 } | |
// Foo.bar.getter | |
sil hidden [transparent] @main.Foo.bar.getter : Swift.Int : $@convention(method) (Foo) -> Int { | |
// %0 // users: %2, %1 | |
bb0(%0 : $Foo): | |
debug_value %0 : $Foo, let, name "self", argno 1, loc "main.swift":11:9, scope 8 // id: %1 | |
%2 = struct_extract %0 : $Foo, #Foo.bar, scope 9 // user: %3 | |
return %2 : $Int, loc "main.swift":11:9, scope 9 // id: %3 | |
} | |
sil_scope 10 { loc "main.swift":11:9 parent @main.Foo.bar.setter : Swift.Int : $@convention(method) (Int, @inout Foo) -> () } | |
sil_scope 11 { loc "main.swift":11:9 parent 10 } | |
// Foo.bar.setter | |
sil hidden [transparent] @main.Foo.bar.setter : Swift.Int : $@convention(method) (Int, @inout Foo) -> () { | |
// %0 // users: %5, %3 | |
// %1 // users: %2, %4 | |
bb0(%0 : $Int, %1 : $*Foo): | |
debug_value_addr %1 : $*Foo, var, name "self", argno 2, loc "main.swift":11:9, scope 10 // id: %2 | |
debug_value %0 : $Int, let, name "value", argno 1, loc "main.swift":11:9, scope 10 // id: %3 | |
%4 = struct_element_addr %1 : $*Foo, #Foo.bar, scope 11 // user: %5 | |
store %0 to %4 : $*Int, scope 11 // id: %5 | |
%6 = tuple (), loc "main.swift":11:9, scope 11 // user: %7 | |
return %6 : $(), loc "main.swift":11:9, scope 11 // id: %7 | |
} | |
sil_scope 12 { loc "main.swift":11:9 parent @main.Foo.bar.materializeForSet : Swift.Int : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout Foo) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>) } | |
// Foo.bar.materializeForSet | |
sil hidden [transparent] @main.Foo.bar.materializeForSet : Swift.Int : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout Foo) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>) { | |
// %2 // user: %3 | |
bb0(%0 : $Builtin.RawPointer, %1 : $*Builtin.UnsafeValueBuffer, %2 : $*Foo): | |
%3 = struct_element_addr %2 : $*Foo, #Foo.bar, scope 12 // user: %4 | |
%4 = address_to_pointer %3 : $*Int to $Builtin.RawPointer, scope 12 // user: %6 | |
%5 = enum $Optional<Builtin.RawPointer>, #Optional.none!enumelt, scope 12 // user: %6 | |
%6 = tuple (%4 : $Builtin.RawPointer, %5 : $Optional<Builtin.RawPointer>), scope 12 // user: %7 | |
return %6 : $(Builtin.RawPointer, Optional<Builtin.RawPointer>), scope 12 // id: %7 | |
} | |
sil_scope 13 { loc "main.swift":9:8 parent @main.Foo.init (foo : Swift.Int, bar : Swift.Int) -> main.Foo : $@convention(method) (Int, Int, @thin Foo.Type) -> Foo } | |
// Foo.init(foo : Int, bar : Int) -> Foo | |
sil hidden @main.Foo.init (foo : Swift.Int, bar : Swift.Int) -> main.Foo : $@convention(method) (Int, Int, @thin Foo.Type) -> Foo { | |
// %0 // user: %3 | |
// %1 // user: %3 | |
bb0(%0 : $Int, %1 : $Int, %2 : $@thin Foo.Type): | |
%3 = struct $Foo (%0 : $Int, %1 : $Int), scope 13 // user: %4 | |
return %3 : $Foo, scope 13 // id: %4 | |
} | |
sil_scope 14 { loc "main.swift":9:8 parent @main.Foo.init () -> main.Foo : $@convention(method) (@thin Foo.Type) -> Foo } | |
sil_scope 15 { parent 14 } | |
// Foo.init() -> Foo | |
sil hidden @main.Foo.init () -> main.Foo : $@convention(method) (@thin Foo.Type) -> Foo { | |
bb0(%0 : $@thin Foo.Type): | |
%1 = alloc_stack $Foo, var, name "self", argno 1, loc "main.swift":9:8, scope 14 // users: %4, %8, %11 | |
%2 = integer_literal $Builtin.Int64, 0, loc "main.swift":10:15, scope 14 // user: %3 | |
%3 = struct $Int (%2 : $Builtin.Int64), loc "main.swift":10:15, scope 14 // users: %10, %5 | |
%4 = struct_element_addr %1 : $*Foo, #Foo.foo, loc "main.swift":10:9, scope 14 // user: %5 | |
store %3 to %4 : $*Int, loc "main.swift":10:9, scope 14 // id: %5 | |
%6 = integer_literal $Builtin.Int64, 1, loc "main.swift":11:15, scope 14 // user: %7 | |
%7 = struct $Int (%6 : $Builtin.Int64), loc "main.swift":11:15, scope 14 // users: %10, %9 | |
%8 = struct_element_addr %1 : $*Foo, #Foo.bar, loc "main.swift":11:9, scope 14 // user: %9 | |
store %7 to %8 : $*Int, loc "main.swift":11:9, scope 14 // id: %9 | |
%10 = struct $Foo (%3 : $Int, %7 : $Int), loc "main.swift":9:8, scope 15 // user: %12 | |
dealloc_stack %1 : $*Foo, loc "main.swift":9:8, scope 15 // id: %11 | |
return %10 : $Foo, loc "main.swift":9:8, scope 15 // id: %12 | |
} | |
sil_scope 16 { parent @Swift.Int.init (_builtinIntegerLiteral : Builtin.Int2048) -> Swift.Int : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int } | |
// Int.init(_builtinIntegerLiteral : Builtin.Int2048) -> Int | |
sil public_external [transparent] [fragile] @Swift.Int.init (_builtinIntegerLiteral : Builtin.Int2048) -> Swift.Int : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int { | |
// %0 // users: %3, %2 | |
bb0(%0 : $Builtin.Int2048, %1 : $@thin Int.Type): | |
debug_value %0 : $Builtin.Int2048, scope 16 // id: %2 | |
%3 = builtin "s_to_s_checked_trunc_Int2048_Int64"(%0 : $Builtin.Int2048) : $(Builtin.Int64, Builtin.Int1), scope 16 // user: %4 | |
%4 = tuple_extract %3 : $(Builtin.Int64, Builtin.Int1), 0, scope 16 // user: %5 | |
%5 = struct $Int (%4 : $Builtin.Int64), scope 16 // user: %6 | |
return %5 : $Int, scope 16 // id: %6 | |
} | |
// globalinit_33_FD9A49A256BEB6AF7C48013347ADC3BA_func4 | |
sil private_external [fragile] @globalinit_33_FD9A49A256BEB6AF7C48013347ADC3BA_func4 : $@convention(thin) () -> () | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment