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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
// RUN: %target-sil-opt -enable-sil-verify-all -array-count-propagation %s | %FileCheck %s
sil_stage canonical
import Builtin
import Swift
struct MyInt {
@_hasStorage var _value: Builtin.Int64
}
struct MyBool {}
struct _MyBridgeStorage {
@_hasStorage var rawValue : Builtin.BridgeObject
}
struct _MyArrayBuffer<T> {
@_hasStorage var _storage : _MyBridgeStorage
}
struct MyArray<T> {
@_hasStorage var _buffer : _MyArrayBuffer<T>
}
sil @swift_bufferAllocate : $@convention(thin)() -> @owned AnyObject
sil [_semantics "array.uninitialized"] @adoptStorage : $@convention(thin) (@owned AnyObject, MyInt, @thin MyArray<MyInt>.Type) -> @owned (MyArray<MyInt>, UnsafeMutablePointer<MyInt>)
sil [_semantics "array.get_count"] @getCount : $@convention(method) (@guaranteed MyArray<MyInt>) -> MyInt
sil [_semantics "array.get_element"] @getElement : $@convention(method) (MyInt, MyBool, @guaranteed MyArray<MyInt>) -> @out MyInt
sil [_semantics "array.uninitialized"] @allocateUninitialized : $@convention(thin) (MyInt, @thin MyArray<MyInt>.Type) -> @owned (MyArray<MyInt>, UnsafeMutablePointer<MyInt>)
sil [_semantics "array.finalize_intrinsic"] @finalize : $@convention(thin) (@owned MyArray<MyInt>) -> @owned MyArray<MyInt>
sil [_semantics "array.init"] @initRepeatedValueCount : $@convention(thin) (@in MyInt, MyInt, @thin MyArray<MyInt>.Type) -> @owned MyArray<MyInt>
sil [_semantics "array.init"] @initEmpty : $@convention(thin) (@thin MyArray<MyInt>.Type) -> @owned MyArray<MyInt>
// CHECK-LABEL: sil @test_adoptStorage
// CHECK: [[COUNTVAL:%.*]] = integer_literal $Builtin.Int64, 3
// CHECK: [[COUNT:%.*]] = struct $MyInt ([[COUNTVAL]]
// CHECK: [[GETCOUNTFUN:%.*]] = function_ref @getCount
// CHECK-NOT: apply [[GETCOUNTFUN]]
// CHECK: return [[COUNT]]
sil @test_adoptStorage : $@convention(thin) () -> MyInt {
bb0:
%0 = integer_literal $Builtin.Int64, 3
%1 = function_ref @swift_bufferAllocate : $@convention(thin) () -> @owned AnyObject
%2 = apply %1() : $@convention(thin) () -> @owned AnyObject
%3 = struct $MyInt(%0 : $Builtin.Int64)
%4 = metatype $@thin MyArray<MyInt>.Type
%5 = function_ref @adoptStorage : $@convention(thin) (@owned AnyObject, MyInt, @thin MyArray<MyInt>.Type) -> @owned (MyArray<MyInt>, UnsafeMutablePointer<MyInt>)
%6 = apply %5(%2, %3, %4) : $@convention(thin) (@owned AnyObject, MyInt, @thin MyArray<MyInt>.Type) -> @owned (MyArray<MyInt>, UnsafeMutablePointer<MyInt>)
%7 = tuple_extract %6 : $(MyArray<MyInt>, UnsafeMutablePointer<MyInt>), 0
%8a = tuple_extract %6 : $(MyArray<MyInt>, UnsafeMutablePointer<MyInt>), 1
%8 = mark_dependence %8a : $UnsafeMutablePointer<MyInt> on %7 : $MyArray<MyInt>
debug_value %7 : $MyArray<MyInt>
%f = function_ref @finalize : $@convention(thin) (@owned MyArray<MyInt>) -> @owned MyArray<MyInt>
%a = apply %f(%7) : $@convention(thin) (@owned MyArray<MyInt>) -> @owned MyArray<MyInt>
%9 = function_ref @getCount : $@convention(method) (@guaranteed MyArray<MyInt>) -> MyInt
%10 = apply %9(%a) : $@convention(method) (@guaranteed MyArray<MyInt>) -> MyInt
%12 = struct_extract %a : $MyArray<MyInt>, #MyArray._buffer
%13 = struct_extract %12 : $_MyArrayBuffer<MyInt>, #_MyArrayBuffer._storage
%14 = struct_extract %13 : $_MyBridgeStorage, #_MyBridgeStorage.rawValue
strong_release %14 : $Builtin.BridgeObject
return %10 : $MyInt
}
// CHECK-LABEL: sil @test_allocateUninitialized
// CHECK: [[COUNTVAL:%.*]] = integer_literal $Builtin.Int64, 3
// CHECK: [[COUNT:%.*]] = struct $MyInt ([[COUNTVAL]]
// CHECK: [[GETCOUNTFUN:%.*]] = function_ref @getCount
// CHECK-NOT: apply [[GETCOUNTFUN]]
// CHECK: return [[COUNT]]
sil @test_allocateUninitialized : $@convention(thin) () -> MyInt {
bb0:
%0 = integer_literal $Builtin.Int64, 3
%3 = struct $MyInt(%0 : $Builtin.Int64)
%4 = metatype $@thin MyArray<MyInt>.Type
%5 = function_ref @allocateUninitialized : $@convention(thin) (MyInt, @thin MyArray<MyInt>.Type) -> @owned (MyArray<MyInt>, UnsafeMutablePointer<MyInt>)
%6 = apply %5(%3, %4) : $@convention(thin) (MyInt, @thin MyArray<MyInt>.Type) -> @owned (MyArray<MyInt>, UnsafeMutablePointer<MyInt>)
%7 = tuple_extract %6 : $(MyArray<MyInt>, UnsafeMutablePointer<MyInt>), 0
%8a = tuple_extract %6 : $(MyArray<MyInt>, UnsafeMutablePointer<MyInt>), 1
%8 = mark_dependence %8a : $UnsafeMutablePointer<MyInt> on %7 : $MyArray<MyInt>
debug_value %7 : $MyArray<MyInt>
%9 = function_ref @getCount : $@convention(method) (@guaranteed MyArray<MyInt>) -> MyInt
%10 = apply %9(%7) : $@convention(method) (@guaranteed MyArray<MyInt>) -> MyInt
%12 = struct_extract %7 : $MyArray<MyInt>, #MyArray._buffer
%13 = struct_extract %12 : $_MyArrayBuffer<MyInt>, #_MyArrayBuffer._storage
%14 = struct_extract %13 : $_MyBridgeStorage, #_MyBridgeStorage.rawValue
%15 = function_ref @getElement : $@convention(method) (MyInt, MyBool, @guaranteed MyArray<MyInt>) -> @out MyInt
%16 = alloc_stack $MyInt
%17 = struct $MyBool()
%18 = apply %15(%16, %3, %17, %7) : $@convention(method) (MyInt, MyBool, @guaranteed MyArray<MyInt>) -> @out MyInt
strong_release %14 : $Builtin.BridgeObject
dealloc_stack %16 : $*MyInt
return %10 : $MyInt
}
// CHECK-LABEL: sil @test_initRepeatedValueCount
// CHECK: [[COUNTVAL:%.*]] = integer_literal $Builtin.Int64, 3
// CHECK: [[COUNT:%.*]] = struct $MyInt ([[COUNTVAL]]
// CHECK: [[GETCOUNTFUN:%.*]] = function_ref @getCount
// CHECK-NOT: apply [[GETCOUNTFUN]]
// CHECK: return [[COUNT]]
sil @test_initRepeatedValueCount : $@convention(thin) () -> MyInt {
bb0:
%0 = integer_literal $Builtin.Int64, 3
%1 = alloc_stack $MyInt
%3 = struct $MyInt(%0 : $Builtin.Int64)
store %3 to %1: $*MyInt
%4 = metatype $@thin MyArray<MyInt>.Type
%5 = function_ref @initRepeatedValueCount : $@convention(thin) (@in MyInt, MyInt, @thin MyArray<MyInt>.Type) -> @owned MyArray<MyInt>
%6 = apply %5(%1, %3, %4) : $@convention(thin) (@in MyInt, MyInt, @thin MyArray<MyInt>.Type) -> @owned MyArray<MyInt>
debug_value %6 : $MyArray<MyInt>
%9 = function_ref @getCount : $@convention(method) (@guaranteed MyArray<MyInt>) -> MyInt
%10 = apply %9(%6) : $@convention(method) (@guaranteed MyArray<MyInt>) -> MyInt
%12 = struct_extract %6 : $MyArray<MyInt>, #MyArray._buffer
%13 = struct_extract %12 : $_MyArrayBuffer<MyInt>, #_MyArrayBuffer._storage
%14 = struct_extract %13 : $_MyBridgeStorage, #_MyBridgeStorage.rawValue
%15 = function_ref @getElement : $@convention(method) (MyInt, MyBool, @guaranteed MyArray<MyInt>) -> @out MyInt
%16 = alloc_stack $MyInt
%17 = struct $MyBool()
%18 = apply %15(%16, %3, %17, %6) : $@convention(method) (MyInt, MyBool, @guaranteed MyArray<MyInt>) -> @out MyInt
strong_release %14 : $Builtin.BridgeObject
dealloc_stack %16 : $*MyInt
dealloc_stack %1 : $*MyInt
return %10 : $MyInt
}
// CHECK-LABEL: sil @test_escape
// CHECK: [[GETCOUNTFUN:%.*]] = function_ref @getCount
// CHECK: [[RESULT:%.*]] = apply [[GETCOUNTFUN]]
// CHECK: return [[RESULT]]
sil @test_escape : $@convention(thin) () -> MyInt {
bb0:
%0 = integer_literal $Builtin.Int64, 3
%15 = alloc_stack $MyArray<MyInt>
%1 = function_ref @swift_bufferAllocate : $@convention(thin) () -> @owned AnyObject
%2 = apply %1() : $@convention(thin) () -> @owned AnyObject
%3 = struct $MyInt(%0 : $Builtin.Int64)
%4 = metatype $@thin MyArray<MyInt>.Type
%5 = function_ref @adoptStorage : $@convention(thin) (@owned AnyObject, MyInt, @thin MyArray<MyInt>.Type) -> @owned (MyArray<MyInt>, UnsafeMutablePointer<MyInt>)
%6 = apply %5(%2, %3, %4) : $@convention(thin) (@owned AnyObject, MyInt, @thin MyArray<MyInt>.Type) -> @owned (MyArray<MyInt>, UnsafeMutablePointer<MyInt>)
%7 = tuple_extract %6 : $(MyArray<MyInt>, UnsafeMutablePointer<MyInt>), 0
%8a = tuple_extract %6 : $(MyArray<MyInt>, UnsafeMutablePointer<MyInt>), 1
%8 = mark_dependence %8a : $UnsafeMutablePointer<MyInt> on %7 : $MyArray<MyInt>
store %7 to %15 : $*MyArray<MyInt>
debug_value %7 : $MyArray<MyInt>
%9 = function_ref @getCount : $@convention(method) (@guaranteed MyArray<MyInt>) -> MyInt
%10 = apply %9(%7) : $@convention(method) (@guaranteed MyArray<MyInt>) -> MyInt
%12 = struct_extract %7 : $MyArray<MyInt>, #MyArray._buffer
%13 = struct_extract %12 : $_MyArrayBuffer<MyInt>, #_MyArrayBuffer._storage
%14 = struct_extract %13 : $_MyBridgeStorage, #_MyBridgeStorage.rawValue
strong_release %14 : $Builtin.BridgeObject
dealloc_stack %15 : $*MyArray<MyInt>
return %10 : $MyInt
}
// CHECK-LABEL: sil @test_mayWrite
// CHECK: [[GETCOUNTFUN:%.*]] = function_ref @getCount
// CHECK: [[RESULT:%.*]] = apply [[GETCOUNTFUN]]
// CHECK: return [[RESULT]]
sil @mayWrite : $@convention(thin) (@guaranteed MyArray<MyInt>) -> ()
sil @test_mayWrite : $@convention(thin) () -> MyInt {
bb0:
%0 = integer_literal $Builtin.Int64, 3
%1 = function_ref @swift_bufferAllocate : $@convention(thin) () -> @owned AnyObject
%2 = apply %1() : $@convention(thin) () -> @owned AnyObject
%3 = struct $MyInt(%0 : $Builtin.Int64)
%4 = metatype $@thin MyArray<MyInt>.Type
%5 = function_ref @adoptStorage : $@convention(thin) (@owned AnyObject, MyInt, @thin MyArray<MyInt>.Type) -> @owned (MyArray<MyInt>, UnsafeMutablePointer<MyInt>)
%6 = apply %5(%2, %3, %4) : $@convention(thin) (@owned AnyObject, MyInt, @thin MyArray<MyInt>.Type) -> @owned (MyArray<MyInt>, UnsafeMutablePointer<MyInt>)
%7 = tuple_extract %6 : $(MyArray<MyInt>, UnsafeMutablePointer<MyInt>), 0
%8a = tuple_extract %6 : $(MyArray<MyInt>, UnsafeMutablePointer<MyInt>), 1
%8 = mark_dependence %8a : $UnsafeMutablePointer<MyInt> on %7 : $MyArray<MyInt>
debug_value %7 : $MyArray<MyInt>
%15 = function_ref @mayWrite : $@convention(thin) (@guaranteed MyArray<MyInt>) -> ()
%16 = apply %15(%7) : $@convention(thin) (@guaranteed MyArray<MyInt>) -> ()
%9 = function_ref @getCount : $@convention(method) (@guaranteed MyArray<MyInt>) -> MyInt
%10 = apply %9(%7) : $@convention(method) (@guaranteed MyArray<MyInt>) -> MyInt
%12 = struct_extract %7 : $MyArray<MyInt>, #MyArray._buffer
%13 = struct_extract %12 : $_MyArrayBuffer<MyInt>, #_MyArrayBuffer._storage
%14 = struct_extract %13 : $_MyBridgeStorage, #_MyBridgeStorage.rawValue
strong_release %14 : $Builtin.BridgeObject
return %10 : $MyInt
}
// We don't handle empty array allocations yet.
// CHECK-LABEL: sil @test_initEmpty
// CHECK: [[GETCOUNTFUN:%.*]] = function_ref @getCount
// CHECK: [[RESULT:%.*]] = apply [[GETCOUNTFUN]]
// CHECK: return [[RESULT]]
sil @test_initEmpty : $@convention(thin) () -> MyInt {
bb0:
%4 = metatype $@thin MyArray<MyInt>.Type
%5 = function_ref @initEmpty : $@convention(thin) (@thin MyArray<MyInt>.Type) -> @owned MyArray<MyInt>
%6 = apply %5(%4) : $@convention(thin) (@thin MyArray<MyInt>.Type) -> @owned MyArray<MyInt>
debug_value %6 : $MyArray<MyInt>
%9 = function_ref @getCount : $@convention(method) (@guaranteed MyArray<MyInt>) -> MyInt
%10 = apply %9(%6) : $@convention(method) (@guaranteed MyArray<MyInt>) -> MyInt
%12 = struct_extract %6 : $MyArray<MyInt>, #MyArray._buffer
%13 = struct_extract %12 : $_MyArrayBuffer<MyInt>, #_MyArrayBuffer._storage
%14 = struct_extract %13 : $_MyBridgeStorage, #_MyBridgeStorage.rawValue
strong_release %14 : $Builtin.BridgeObject
return %10 : $MyInt
}
|