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
|
// RUN: %target-sil-opt %s -alloc-vector-lowering -enable-experimental-feature FixedArrays | %FileCheck %s
// REQUIRES: swift_in_compiler
sil_stage canonical
import Builtin
import Swift
@_moveOnly public struct FixedArray<T> {
@_hasStorage let buffer: UnsafeMutablePointer<T> { get }
@_hasStorage public let capacity: Int64 { get }
@_hasStorage internal var _count: Int64 { get set }
public struct _Literal {
@_hasStorage let array: [T] { get }
typealias ArrayLiteralElement = T
}
}
sil_global @global_fixed_array : $FixedArray<Int64>
sil_global @global_fixed_array2 : $UnsafeMutablePointer<Int64>
// CHECK-LABEL: sil_global private @global_init_with_array_initializationTv_ : $Int64 = {
// CHECK-NEXT: %0 = integer_literal $Builtin.Int64, 1
// CHECK-NEXT: %1 = struct $Int64 (%0 : $Builtin.Int64)
// CHECK-NEXT: %2 = integer_literal $Builtin.Int64, 2
// CHECK-NEXT: %3 = struct $Int64 (%2 : $Builtin.Int64)
// CHECK-NEXT: %initval = vector (%1 : $Int64, %3 : $Int64)
// CHECK-LABEL: sil_global private @global_init_uninitializedTv_ : $Int64 = {
// CHECK-NEXT: %0 = integer_literal $Builtin.Word, 10
// CHECK-NEXT: %initval = alloc_vector $Int64, %0 : $Builtin.Word
sil [_semantics "array.uninitialized_intrinsic"] @alloc_uninitialized_array : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
sil [_semantics "array.finalize_intrinsic"] @finalize_array : $@convention(thin) <Element> (@owned Array<Element>) -> @owned Array<Element>
sil [_semantics "array.get_count"] @array_count : $@convention(method) <τ_0_0> (@guaranteed Array<τ_0_0>) -> Int64
sil [_semantics "array.copy_into_vector"] @array_copy_into_vector : $@convention(method) <Element> (UnsafeMutablePointer<Element>, @guaranteed Array<Element>) -> ()
// CHECK-LABEL: sil [ossa] @stack_allocated :
// CHECK: [[C:%.*]] = integer_literal $Builtin.Word, 10
// CHECK: [[V:%.*]] = alloc_vector $Int64, [[C]]
// CHECK: bb1:
// CHECK: dealloc_stack {{.*}} : $*Builtin.RawPointer
// CHECK: dealloc_stack [[V]] : $*Int64
// CHECK: bb2:
// CHECK: dealloc_stack {{.*}} : $*Builtin.RawPointer
// CHECK: dealloc_stack [[V]] : $*Int64
// CHECK: bb3:
// CHECK: } // end sil function 'stack_allocated'
sil [ossa] @stack_allocated : $@convention(thin) () -> () {
%8 = integer_literal $Builtin.Word, 10
%9 = metatype $@thin Int64.Type
%10 = builtin "allocVector"<Int64>(%9 : $@thin Int64.Type, %8 : $Builtin.Word) : $Builtin.RawPointer
%11 = alloc_stack $Builtin.RawPointer
store %10 to [trivial] %11 : $*Builtin.RawPointer
cond_br undef, bb1, bb2
bb1:
dealloc_stack %11 : $*Builtin.RawPointer
br bb3
bb2:
dealloc_stack %11 : $*Builtin.RawPointer
br bb3
bb3:
%r = tuple()
return %r : $()
}
// CHECK-LABEL: sil [global_init_once_fn] [ossa] @global_init_with_array_initialization :
// CHECK: [[G:%.*]] = global_addr @global_init_with_array_initializationTv_
// CHECK: [[P:%.*]] = address_to_pointer [[G]]
// CHECK: [[UMP:%.*]] = struct $UnsafeMutablePointer<Int64> ([[P]] : $Builtin.RawPointer)
// CHECK: [[BA:%.*]] = struct_element_addr {{%.*}} : $*FixedArray<Int64>, #FixedArray.buffer
// CHECK: store [[UMP]] to [trivial] [[BA]]
// CHECK: } // end sil function 'global_init_with_array_initialization'
sil [global_init_once_fn] [ossa] @global_init_with_array_initialization : $@convention(thin) () -> () {
bb0:
alloc_global @global_fixed_array
%2 = global_addr @global_fixed_array : $*FixedArray<Int64>
%3 = integer_literal $Builtin.Word, 2
%4 = function_ref @alloc_uninitialized_array : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
%5 = apply %4<Int64>(%3) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
(%6, %7) = destructure_tuple %5 : $(Array<Int64>, Builtin.RawPointer)
%8 = mark_dependence %7 : $Builtin.RawPointer on %6 : $Array<Int64>
%9 = pointer_to_address %8 : $Builtin.RawPointer to [strict] $*Int64
%10 = integer_literal $Builtin.Int64, 1
%11 = struct $Int64 (%10 : $Builtin.Int64)
store %11 to [trivial] %9 : $*Int64
%13 = integer_literal $Builtin.Word, 1
%14 = index_addr %9 : $*Int64, %13 : $Builtin.Word
%15 = integer_literal $Builtin.Int64, 2
%16 = struct $Int64 (%15 : $Builtin.Int64)
store %16 to [trivial] %14 : $*Int64
%23 = function_ref @finalize_array : $@convention(thin) <τ_0_0> (@owned Array<τ_0_0>) -> @owned Array<τ_0_0>
%24 = apply %23<Int64>(%6) : $@convention(thin) <τ_0_0> (@owned Array<τ_0_0>) -> @owned Array<τ_0_0>
%25 = copy_value %24 : $Array<Int64>
%34 = struct $FixedArray<Int64>._Literal (%25 : $Array<Int64>)
destroy_value %34 : $FixedArray<Int64>._Literal
%36 = alloc_stack [lexical] $FixedArray<Int64>
%37 = function_ref @array_count : $@convention(method) <τ_0_0> (@guaranteed Array<τ_0_0>) -> Int64
%38 = apply %37<Int64>(%24) : $@convention(method) <τ_0_0> (@guaranteed Array<τ_0_0>) -> Int64
%39 = begin_access [modify] [static] %36 : $*FixedArray<Int64>
%40 = struct_element_addr %39 : $*FixedArray<Int64>, #FixedArray._count
store %38 to [trivial] %40 : $*Int64
end_access %39 : $*FixedArray<Int64>
%43 = begin_access [modify] [static] %36 : $*FixedArray<Int64>
%44 = struct_element_addr %43 : $*FixedArray<Int64>, #FixedArray.capacity
store %38 to [trivial] %44 : $*Int64
end_access %43 : $*FixedArray<Int64>
%47 = begin_borrow %24 : $Array<Int64>
%48 = function_ref @array_count : $@convention(method) <τ_0_0> (@guaranteed Array<τ_0_0>) -> Int64
%49 = apply %48<Int64>(%47) : $@convention(method) <τ_0_0> (@guaranteed Array<τ_0_0>) -> Int64
%50 = struct_extract %49 : $Int64, #Int64._value
%52 = metatype $@thin Int64.Type
%53 = builtin "allocVector"<Int64>(%52 : $@thin Int64.Type, %50 : $Builtin.Int64) : $Builtin.RawPointer
%54 = struct $UnsafeMutablePointer<Int64> (%53 : $Builtin.RawPointer)
%55 = function_ref @array_copy_into_vector : $@convention(method) <τ_0_0> (UnsafeMutablePointer<τ_0_0>, @guaranteed Array<τ_0_0>) -> ()
%56 = apply %55<Int64>(%54, %47) : $@convention(method) <τ_0_0> (UnsafeMutablePointer<τ_0_0>, @guaranteed Array<τ_0_0>) -> ()
end_borrow %47 : $Array<Int64>
%58 = begin_access [modify] [static] %36 : $*FixedArray<Int64>
%59 = struct_element_addr %58 : $*FixedArray<Int64>, #FixedArray.buffer
store %54 to [trivial] %59 : $*UnsafeMutablePointer<Int64>
end_access %58 : $*FixedArray<Int64>
%62 = load [take] %36 : $*FixedArray<Int64>
destroy_value %24 : $Array<Int64>
dealloc_stack %36 : $*FixedArray<Int64>
store %62 to [init] %2 : $*FixedArray<Int64>
%67 = tuple ()
return %67 : $()
}
// CHECK-LABEL: sil [global_init_once_fn] [ossa] @global_init_uninitialized :
// CHECK: [[A:%.*]] = alloc_stack $UnsafeMutablePointer<Int64>
// CHECK: [[G:%.*]] = global_addr @global_init_uninitializedTv_
// CHECK: [[P:%.*]] = address_to_pointer [[G]]
// CHECK: [[UMP:%.*]] = struct $UnsafeMutablePointer<Int64> ([[P]] : $Builtin.RawPointer)
// CHECK: store [[UMP]] to [trivial] [[A]]
// CHECK: } // end sil function 'global_init_uninitialized'
sil [global_init_once_fn] [ossa] @global_init_uninitialized : $@convention(thin) () -> () {
bb0:
alloc_global @global_fixed_array2
%2 = global_addr @global_fixed_array2 : $*UnsafeMutablePointer<Int64>
%5 = alloc_stack $UnsafeMutablePointer<Int64>
%10 = integer_literal $Builtin.Word, 10
%11 = metatype $@thin Int64.Type
%12 = builtin "allocVector"<Int64>(%11 : $@thin Int64.Type, %10 : $Builtin.Word) : $Builtin.RawPointer
%13 = struct $UnsafeMutablePointer<Int64> (%12 : $Builtin.RawPointer)
store %13 to [trivial] %5 : $*UnsafeMutablePointer<Int64>
%24 = load [trivial] %5 : $*UnsafeMutablePointer<Int64>
dealloc_stack %5 : $*UnsafeMutablePointer<Int64>
store %24 to [trivial] %2 : $*UnsafeMutablePointer<Int64>
%27 = tuple ()
return %27 : $()
}
|