Skip to content

Instantly share code, notes, and snippets.

@koher

koher/main.sil Secret

Last active December 4, 2020 12:30
Show Gist options
  • Save koher/505316030ec52ce395e05fe0ae4828fb to your computer and use it in GitHub Desktop.
Save koher/505316030ec52ce395e05fe0ae4828fb to your computer and use it in GitHub Desktop.
sil_stage raw
import Builtin
import Swift
import SwiftShims
func copies(a: inout [[Int]], x: Int, y: Int)
func noCopies(a: inout [[Int]], x: Int, y: Int)
@_hasStorage @_hasInitialValue var a: [[Int]] { get set }
// a
sil_global hidden @$s5main41aSaySaySiGGvp : $Array<Array<Int>>
// main
sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
alloc_global @$s5main41aSaySaySiGGvp // id: %2
%3 = global_addr @$s5main41aSaySaySiGGvp : $*Array<Array<Int>> // users: %43, %31, %22
%4 = integer_literal $Builtin.Word, 1 // user: %6
// function_ref _allocateUninitializedArray<A>(_:)
%5 = function_ref @$ss27_allocateUninitializedArrayySayxG_BptBwlF : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer) // user: %6
%6 = apply %5<Array<Int>>(%4) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer) // user: %7
(%7, %8) = destructure_tuple %6 : $(Array<Array<Int>>, Builtin.RawPointer) // users: %22, %9
%9 = pointer_to_address %8 : $Builtin.RawPointer to [strict] $*Array<Int> // user: %21
%10 = integer_literal $Builtin.Word, 1 // user: %12
// function_ref _allocateUninitializedArray<A>(_:)
%11 = function_ref @$ss27_allocateUninitializedArrayySayxG_BptBwlF : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer) // user: %12
%12 = apply %11<Int>(%10) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer) // user: %13
(%13, %14) = destructure_tuple %12 : $(Array<Int>, Builtin.RawPointer) // users: %21, %15
%15 = pointer_to_address %14 : $Builtin.RawPointer to [strict] $*Int // user: %20
%16 = integer_literal $Builtin.IntLiteral, 0 // user: %19
%17 = metatype $@thin Int.Type // user: %19
// function_ref Int.init(_builtinIntegerLiteral:)
%18 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %19
%19 = apply %18(%16, %17) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %20
store %19 to [trivial] %15 : $*Int // id: %20
store %13 to [init] %9 : $*Array<Int> // id: %21
store %7 to [init] %3 : $*Array<Array<Int>> // id: %22
%23 = integer_literal $Builtin.IntLiteral, 0 // user: %26
%24 = metatype $@thin Int.Type // user: %26
// function_ref Int.init(_builtinIntegerLiteral:)
%25 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %26
%26 = apply %25(%23, %24) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %33
%27 = integer_literal $Builtin.IntLiteral, 0 // user: %30
%28 = metatype $@thin Int.Type // user: %30
// function_ref Int.init(_builtinIntegerLiteral:)
%29 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %30
%30 = apply %29(%27, %28) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %33
%31 = begin_access [modify] [dynamic] %3 : $*Array<Array<Int>> // users: %34, %33
// function_ref copies(a:x:y:)
%32 = function_ref @$s5main46copies1a1x1yySaySaySiGGz_S2itF : $@convention(thin) (@inout Array<Array<Int>>, Int, Int) -> () // user: %33
%33 = apply %32(%31, %26, %30) : $@convention(thin) (@inout Array<Array<Int>>, Int, Int) -> ()
end_access %31 : $*Array<Array<Int>> // id: %34
%35 = integer_literal $Builtin.IntLiteral, 0 // user: %38
%36 = metatype $@thin Int.Type // user: %38
// function_ref Int.init(_builtinIntegerLiteral:)
%37 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %38
%38 = apply %37(%35, %36) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %45
%39 = integer_literal $Builtin.IntLiteral, 0 // user: %42
%40 = metatype $@thin Int.Type // user: %42
// function_ref Int.init(_builtinIntegerLiteral:)
%41 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %42
%42 = apply %41(%39, %40) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %45
%43 = begin_access [modify] [dynamic] %3 : $*Array<Array<Int>> // users: %46, %45
// function_ref noCopies(a:x:y:)
%44 = function_ref @$s5main48noCopies1a1x1yySaySaySiGGz_S2itF : $@convention(thin) (@inout Array<Array<Int>>, Int, Int) -> () // user: %45
%45 = apply %44(%43, %38, %42) : $@convention(thin) (@inout Array<Array<Int>>, Int, Int) -> ()
end_access %43 : $*Array<Array<Int>> // id: %46
%47 = integer_literal $Builtin.Int32, 0 // user: %48
%48 = struct $Int32 (%47 : $Builtin.Int32) // user: %49
return %48 : $Int32 // id: %49
} // end sil function 'main'
// copies(a:x:y:)
sil hidden [ossa] @$s5main46copies1a1x1yySaySaySiGGz_S2itF : $@convention(thin) (@inout Array<Array<Int>>, Int, Int) -> () {
// %0 "a" // users: %20, %6, %3
// %1 "x" // users: %25, %16, %4
// %2 "y" // users: %22, %10, %5
bb0(%0 : $*Array<Array<Int>>, %1 : $Int, %2 : $Int):
debug_value_addr %0 : $*Array<Array<Int>>, var, name "a", argno 1 // id: %3
debug_value %1 : $Int, let, name "x", argno 2 // id: %4
debug_value %2 : $Int, let, name "y", argno 3 // id: %5
%6 = begin_access [read] [unknown] %0 : $*Array<Array<Int>> // users: %19, %7
%7 = load_borrow %6 : $*Array<Array<Int>> // users: %12, %10
%8 = alloc_stack $Array<Int> // users: %33, %11, %10
// function_ref Array.subscript.getter
%9 = function_ref @$sSayxSicig : $@convention(method) <τ_0_0> (Int, @guaranteed Array<τ_0_0>) -> @out τ_0_0 // user: %10
%10 = apply %9<[Int]>(%8, %2, %7) : $@convention(method) <τ_0_0> (Int, @guaranteed Array<τ_0_0>) -> @out τ_0_0
%11 = load [take] %8 : $*Array<Int> // users: %32, %13
end_borrow %7 : $Array<Array<Int>> // id: %12
%13 = begin_borrow %11 : $Array<Int> // users: %18, %16
%14 = alloc_stack $Int // users: %31, %17, %16
// function_ref Array.subscript.getter
%15 = function_ref @$sSayxSicig : $@convention(method) <τ_0_0> (Int, @guaranteed Array<τ_0_0>) -> @out τ_0_0 // user: %16
%16 = apply %15<Int>(%14, %1, %13) : $@convention(method) <τ_0_0> (Int, @guaranteed Array<τ_0_0>) -> @out τ_0_0
%17 = load [trivial] %14 : $*Int // user: %27
end_borrow %13 : $Array<Int> // id: %18
end_access %6 : $*Array<Array<Int>> // id: %19
%20 = begin_access [modify] [unknown] %0 : $*Array<Array<Int>> // users: %30, %22
// function_ref Array.subscript.modify
%21 = function_ref @$sSayxSiciM : $@yield_once @convention(method) <τ_0_0> (Int, @inout Array<τ_0_0>) -> @yields @inout τ_0_0 // user: %22
(%22, %23) = begin_apply %21<[Int]>(%2, %20) : $@yield_once @convention(method) <τ_0_0> (Int, @inout Array<τ_0_0>) -> @yields @inout τ_0_0 // users: %25, %29
// function_ref Array.subscript.modify
%24 = function_ref @$sSayxSiciM : $@yield_once @convention(method) <τ_0_0> (Int, @inout Array<τ_0_0>) -> @yields @inout τ_0_0 // user: %25
(%25, %26) = begin_apply %24<Int>(%1, %22) : $@yield_once @convention(method) <τ_0_0> (Int, @inout Array<τ_0_0>) -> @yields @inout τ_0_0 // users: %27, %28
assign %17 to %25 : $*Int // id: %27
end_apply %26 // id: %28
end_apply %23 // id: %29
end_access %20 : $*Array<Array<Int>> // id: %30
dealloc_stack %14 : $*Int // id: %31
destroy_value %11 : $Array<Int> // id: %32
dealloc_stack %8 : $*Array<Int> // id: %33
%34 = tuple () // user: %35
return %34 : $() // id: %35
} // end sil function '$s5main46copies1a1x1yySaySaySiGGz_S2itF'
// Array.subscript.getter
sil [serialized] @$sSayxSicig : $@convention(method) <τ_0_0> (Int, @guaranteed Array<τ_0_0>) -> @out τ_0_0
// Array.subscript.modify
sil [serialized] @$sSayxSiciM : $@yield_once @convention(method) <τ_0_0> (Int, @inout Array<τ_0_0>) -> @yields @inout τ_0_0
// noCopies(a:x:y:)
sil hidden [ossa] @$s5main48noCopies1a1x1yySaySaySiGGz_S2itF : $@convention(thin) (@inout Array<Array<Int>>, Int, Int) -> () {
// %0 "a" // users: %24, %6, %3
// %1 "x" // users: %29, %16, %4
// %2 "y" // users: %26, %10, %5
bb0(%0 : $*Array<Array<Int>>, %1 : $Int, %2 : $Int):
debug_value_addr %0 : $*Array<Array<Int>>, var, name "a", argno 1 // id: %3
debug_value %1 : $Int, let, name "x", argno 2 // id: %4
debug_value %2 : $Int, let, name "y", argno 3 // id: %5
%6 = begin_access [read] [unknown] %0 : $*Array<Array<Int>> // users: %20, %7
%7 = load_borrow %6 : $*Array<Array<Int>> // users: %12, %10
%8 = alloc_stack $Array<Int> // users: %23, %11, %10
// function_ref Array.subscript.getter
%9 = function_ref @$sSayxSicig : $@convention(method) <τ_0_0> (Int, @guaranteed Array<τ_0_0>) -> @out τ_0_0 // user: %10
%10 = apply %9<[Int]>(%8, %2, %7) : $@convention(method) <τ_0_0> (Int, @guaranteed Array<τ_0_0>) -> @out τ_0_0
%11 = load [take] %8 : $*Array<Int> // users: %22, %13
end_borrow %7 : $Array<Array<Int>> // id: %12
%13 = begin_borrow %11 : $Array<Int> // users: %19, %16
%14 = alloc_stack $Int // users: %21, %17, %16
// function_ref Array.subscript.getter
%15 = function_ref @$sSayxSicig : $@convention(method) <τ_0_0> (Int, @guaranteed Array<τ_0_0>) -> @out τ_0_0 // user: %16
%16 = apply %15<Int>(%14, %1, %13) : $@convention(method) <τ_0_0> (Int, @guaranteed Array<τ_0_0>) -> @out τ_0_0
%17 = load [trivial] %14 : $*Int // users: %31, %18
debug_value %17 : $Int, let, name "t" // id: %18
end_borrow %13 : $Array<Int> // id: %19
end_access %6 : $*Array<Array<Int>> // id: %20
dealloc_stack %14 : $*Int // id: %21
destroy_value %11 : $Array<Int> // id: %22
dealloc_stack %8 : $*Array<Int> // id: %23
%24 = begin_access [modify] [unknown] %0 : $*Array<Array<Int>> // users: %34, %26
// function_ref Array.subscript.modify
%25 = function_ref @$sSayxSiciM : $@yield_once @convention(method) <τ_0_0> (Int, @inout Array<τ_0_0>) -> @yields @inout τ_0_0 // user: %26
(%26, %27) = begin_apply %25<[Int]>(%2, %24) : $@yield_once @convention(method) <τ_0_0> (Int, @inout Array<τ_0_0>) -> @yields @inout τ_0_0 // users: %29, %33
// function_ref Array.subscript.modify
%28 = function_ref @$sSayxSiciM : $@yield_once @convention(method) <τ_0_0> (Int, @inout Array<τ_0_0>) -> @yields @inout τ_0_0 // user: %29
(%29, %30) = begin_apply %28<Int>(%1, %26) : $@yield_once @convention(method) <τ_0_0> (Int, @inout Array<τ_0_0>) -> @yields @inout τ_0_0 // users: %31, %32
assign %17 to %29 : $*Int // id: %31
end_apply %30 // id: %32
end_apply %27 // id: %33
end_access %24 : $*Array<Array<Int>> // id: %34
%35 = tuple () // user: %36
return %35 : $() // id: %36
} // end sil function '$s5main48noCopies1a1x1yySaySaySiGGz_S2itF'
// _allocateUninitializedArray<A>(_:)
sil [serialized] [always_inline] [_semantics "array.uninitialized_intrinsic"] @$ss27_allocateUninitializedArrayySayxG_BptBwlF : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
// Int.init(_builtinIntegerLiteral:)
sil [transparent] [serialized] @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
// Mappings from '#fileID' to '#filePath':
// 'main4/main4.swift' => 'main4.swift'
func copies(a: inout [[Int]], x: Int, y: Int) {
a[y][x] = a[y][x]
}
func noCopies(a: inout [[Int]], x: Int, y: Int) {
let t = a[y][x]
a[y][x] = t
}
var a = [[0]]
copies(a: &a, x: 0, y: 0)
noCopies(a: &a, x: 0, y: 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment