1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
// RUN: %target-sil-opt -enable-sil-verify-all=true %s | %target-sil-opt -enable-sil-verify-all=true | %FileCheck %s
import Builtin
import Swift
// CHECK-LABEL: sil @test1 :
// CHECK: [[INDEX:%.*]] = dynamic_pack_index {{%.*}} of $Pack{repeat each T}
// CHECK: {{%.*}} = open_pack_element [[INDEX]] of <each U> at <Pack{repeat each T}>, shape $each U, uuid "01234567-89AB-CDEF-0123-000000000000"
sil @test1 : $<each T> () -> () {
bb0:
%intIndex = integer_literal $Builtin.Word, 0
%index = dynamic_pack_index %intIndex of $Pack{repeat each T}
%0 = open_pack_element %index of <each U> at <Pack{repeat each T}>, shape $each U, uuid "01234567-89AB-CDEF-0123-000000000000"
%ret = tuple ()
return %ret : $()
}
// CHECK-LABEL: sil @test2 :
// CHECK: [[INDEX:%.*]] = scalar_pack_index 0 of $Pack{Int, repeat each T}
// CHECK: {{%.*}} = open_pack_element [[INDEX]] of <each U> at <Pack{Int, repeat each T}>, shape $each U, uuid "01234567-89AB-CDEF-0123-000000000001"
sil @test2 : $<each T> () -> () {
bb0:
%index = scalar_pack_index 0 of $Pack{Int, repeat each T}
%0 = open_pack_element %index of <each U> at <Pack{Int, repeat each T}>, shape $each U, uuid "01234567-89AB-CDEF-0123-000000000001"
%ret = tuple ()
return %ret : $()
}
// CHECK-LABEL: sil @test3 :
// CHECK: [[INNER_INDEX:%.*]] = dynamic_pack_index {{%.*}} of $Pack{repeat each T}
// CHECK: [[INDEX:%.*]] = pack_pack_index 1, [[INNER_INDEX]] of $Pack{Int, repeat each T}
// CHECK: {{%.*}} = open_pack_element [[INDEX]] of <each U> at <Pack{Int, repeat each T}>, shape $each U, uuid "01234567-89AB-CDEF-0123-000000000002"
// CHECK: metatype $@thick (@pack_element("01234567-89AB-CDEF-0123-000000000002") each U).Type
sil @test3 : $<each T> () -> () {
bb0:
%intIndex = integer_literal $Builtin.Word, 0
%innerIndex = dynamic_pack_index %intIndex of $Pack{repeat each T}
%index = pack_pack_index 1, %innerIndex of $Pack{Int, repeat each T}
%0 = open_pack_element %index of <each U> at <Pack{Int, repeat each T}>, shape $each U, uuid "01234567-89AB-CDEF-0123-000000000002"
%metatype = metatype $@thick (@pack_element("01234567-89AB-CDEF-0123-000000000002") each U).Type
%ret = tuple ()
return %ret : $()
}
// CHECK-LABEL: sil @test4 :
// CHECK: [[PACK1:%.*]] = alloc_pack $Pack{Int, repeat each T}
// CHECK: [[PACK2:%.*]] = alloc_pack $Pack{repeat each T, repeat Optional<each T>}
// CHECK: dealloc_pack [[PACK2]] : $*Pack{repeat each T, repeat Optional<each T>}
// CHECK: dealloc_pack [[PACK1]] : $*Pack{Int, repeat each T}
sil @test4 : $<each T> () -> () {
bb0:
%pack1 = alloc_pack $Pack{Int, repeat each T}
%pack2 = alloc_pack $Pack{repeat each T, repeat Optional<each T>}
dealloc_pack %pack2 : $*Pack{repeat each T, repeat Optional<each T>}
dealloc_pack %pack1 : $*Pack{Int, repeat each T}
%ret = tuple ()
return %ret : $()
}
// CHECK-LABEL: sil @test5 :
// CHECK: [[PACK:%.*]] = alloc_pack $Pack{Int, repeat each T}
// CHECK: [[INDEX:%.*]] = dynamic_pack_index %0 of $Pack{Int, repeat each T}
// CHECK: [[ADDR:%.*]] = alloc_stack $@pack_element("01234567-89AB-CDEF-0123-000000000003") each U
// CHECK: pack_element_set [[ADDR]] : $*@pack_element("01234567-89AB-CDEF-0123-000000000003") each U into [[INDEX]] of [[PACK]] : $*Pack{Int, repeat each T}
// CHECK: pack_element_get [[INDEX]] of [[PACK]] : $*Pack{Int, repeat each T} as $*@pack_element("01234567-89AB-CDEF-0123-000000000003") each U
sil @test5 : $<each T> (Builtin.Word) -> () {
bb0(%i : $Builtin.Word):
%pack1 = alloc_pack $Pack{Int, repeat each T}
%index = dynamic_pack_index %i of $Pack{Int, repeat each T}
%0 = open_pack_element %index of <each U> at <Pack{Int, repeat each T}>, shape $each U, uuid "01234567-89AB-CDEF-0123-000000000003"
%addr = alloc_stack $@pack_element("01234567-89AB-CDEF-0123-000000000003") U
pack_element_set %addr : $*@pack_element("01234567-89AB-CDEF-0123-000000000003") each U into %index of %pack1 : $*Pack{Int, repeat each T}
%addr2 = pack_element_get %index of %pack1 : $*Pack{Int, repeat each T} as $*@pack_element("01234567-89AB-CDEF-0123-000000000003") each U
dealloc_stack %addr : $*@pack_element("01234567-89AB-CDEF-0123-000000000003") each U
dealloc_pack %pack1 : $*Pack{Int, repeat each T}
%ret = tuple ()
return %ret : $()
}
// CHECK-LABEL: sil @test6
// CHECK: [[INDEX:%.*]] = dynamic_pack_index
// CHECK: tuple_pack_element_addr [[INDEX]] of %0 : $*(String, repeat each T, Int) as $*@pack_element("01234567-89AB-CDEF-0123-000000000004") each U
sil @test6 : $<each T> (@inout (String, repeat each T, Int), Builtin.Word) -> () {
bb0(%tuple : $*(String, repeat each T, Int), %i : $Builtin.Word):
%index = dynamic_pack_index %i of $Pack{Float, repeat each T, Float}
%0 = open_pack_element %index of <each U> at <Pack{String, repeat each T, Int}>, shape $each U, uuid "01234567-89AB-CDEF-0123-000000000004"
%elt = tuple_pack_element_addr %index of %tuple : $*(String, repeat each T, Int) as $*@pack_element("01234567-89AB-CDEF-0123-000000000004") each U
%ret = tuple ()
return %ret : $()
}
// CHECK-LABEBL: sil @test7
// CHECK: [[LEN:%.*]] = pack_length $Pack{(), (), ()}
// CHECK: return [[LEN]] : $Builtin.Word
sil @test7 : $() -> Builtin.Word {
bb0:
%0 = pack_length $Pack{Int, Float, String}
return %0 : $Builtin.Word
}
|