File: basic.sil

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (214 lines) | stat: -rw-r--r-- 9,811 bytes parent folder | download
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
214
// First parse this and then emit a *.sib. Then read in the *.sib, then recreate
// RUN: %empty-directory(%t)
// RUN: %target-sil-opt %s -emit-sib -o %t/tmp.sib -module-name borrow
// RUN: %target-sil-opt %t/tmp.sib -o %t/tmp.2.sib -module-name borrow
// RUN: %target-sil-opt %t/tmp.2.sib -module-name borrow -emit-sorted-sil | %FileCheck %s

import Builtin

class TestArrayStorage {
  @_hasStorage var count: Int32
  init()
}

struct TestArray2 {
  var storage : TestArrayStorage
  var someValue : Int32
  var storage2 : TestArrayStorage
}

struct Int32 {
  var x: Builtin.Int32
}

struct EmptyStruct {}

@_moveOnly struct MoveOnlyStruct {
  @_hasStorage var i: Int32
  deinit
}

// CHECK-LABEL: sil @async_test : $@convention(thin) @async
sil @async_test : $@async () -> () {
bb0:
  %0 = tuple ()
  return %0 : $()
}

sil [ossa] @strong_copy_unmanaged_value_test : $@convention(thin) (@sil_unmanaged Builtin.NativeObject) -> @owned Builtin.NativeObject {
bb0(%0 : $@sil_unmanaged Builtin.NativeObject):
  %1 = strong_copy_unmanaged_value %0 : $@sil_unmanaged Builtin.NativeObject
  return %1 : $Builtin.NativeObject
}

sil [ossa] @test_destructure_struct_tuple : $@convention(thin) (@owned (Builtin.NativeObject, Builtin.Int32), @owned TestArray2) -> @owned (Builtin.NativeObject, Builtin.Int32, TestArrayStorage, Int32, TestArrayStorage) {
bb0(%0 : @owned $(Builtin.NativeObject, Builtin.Int32), %1 : @owned $TestArray2):
  (%2, %3) = destructure_tuple %0 : $(Builtin.NativeObject, Builtin.Int32)
  (%4, %5, %6) = destructure_struct %1 : $TestArray2
  %7 = tuple(%2 : $Builtin.NativeObject, %3 : $Builtin.Int32, %4 : $TestArrayStorage, %5 : $Int32, %6 : $TestArrayStorage)
  return %7 : $(Builtin.NativeObject, Builtin.Int32, TestArrayStorage, Int32, TestArrayStorage)
}

// CHECK-LABEL: sil [ossa] @test_drop_deinit :
// CHECK:         %1 = drop_deinit %0 : $MoveOnlyStruct
// CHECK-LABEL: } // end sil function 'test_drop_deinit'
sil [ossa] @test_drop_deinit : $@convention(thin) (@owned MoveOnlyStruct) -> () {
bb0(%0 : @owned $MoveOnlyStruct):
  %1 = drop_deinit %0 : $MoveOnlyStruct
  destroy_value %1 : $MoveOnlyStruct
  %3 = tuple ()
  return %3 : $()
}

sil @test_empty_destructure : $@convention(thin) () -> () {
bb0:
  %0 = struct $EmptyStruct()
  () = destructure_struct %0 : $EmptyStruct
  %1 = tuple()
  () = destructure_tuple %1 : $()
  return %1 : $()
}

// CHECK-LABEL: sil [serialized] [ossa] @test_end_lifetime : $@convention(thin) (@owned Builtin.NativeObject) -> () {
// CHECK: end_lifetime {{%.*}} : $Builtin.NativeObject
sil [serialized] [ossa] @test_end_lifetime : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
  end_lifetime %0 : $Builtin.NativeObject
  return undef : $()
}

// CHECK-LABEL: sil [lazy_getter] @test_lazy_getter
sil [lazy_getter] @test_lazy_getter : $@convention(thin) () -> () {
bb0:
  %0 = tuple ()
  return %0 : $()
}

// CHECK-LABEL: sil [ossa] @test_movevalue_parsing : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Builtin.NativeObject {
// CHECK: bb0([[REGISTER_0:%[^,]+]] :
// CHECK-NEXT: [[REGISTER_1:%[^,]+]] = move_value [[REGISTER_0]]
// CHECK-NEXT: [[REGISTER_2:%[^,]+]] = move_value [allows_diagnostics] [[REGISTER_1]]
// CHECK-NEXT: [[REGISTER_3:%[^,]+]] = move_value [lexical] [[REGISTER_2]]
// CHECK-NEXT: [[REGISTER_4:%[^,]+]] = move_value [allows_diagnostics] [lexical] [[REGISTER_3]]
// CHECK-NEXT: [[REGISTER_5:%[^,]+]] = move_value [allows_diagnostics] [lexical] [[REGISTER_4]]
// CHECK-NEXT: [[REGISTER_6:%[^,]+]] = move_value [var_decl] [[REGISTER_5]]
// CHECK-NEXT: return [[REGISTER_6]]
// CHECK-NEXT: } // end sil function 'test_movevalue_parsing'
sil [ossa] @test_movevalue_parsing : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Builtin.NativeObject {
bb0(%0 : @owned $Builtin.NativeObject):
  %1 = move_value %0 : $Builtin.NativeObject
  %2 = move_value [allows_diagnostics] %1 : $Builtin.NativeObject
  %3 = move_value [lexical] %2 : $Builtin.NativeObject
  %4 = move_value [allows_diagnostics] [lexical] %3 : $Builtin.NativeObject
  %5 = move_value [lexical] [allows_diagnostics] %4 : $Builtin.NativeObject
  %6 = move_value [var_decl] %5 : $Builtin.NativeObject
  return %6 : $Builtin.NativeObject
}

// CHECK-LABEL: sil [no_allocation] [ossa] @test_no_allocation : $@convention(thin) () -> () {
sil [no_allocation] [ossa] @test_no_allocation : $@convention(thin) () -> () {
bb0:
  %1 = tuple ()
  return %1 : $()
}

// CHECK-LABEL: sil [no_locks] [ossa] @test_no_locks : $@convention(thin) () -> () {
sil [no_locks] [ossa] @test_no_locks : $@convention(thin) () -> () {
bb0:
  %1 = tuple ()
  return %1 : $()
}

// CHECK-LABEL: sil [ossa] @test_pointer_to_address : $@convention(thin) (Builtin.RawPointer, Builtin.Int64) -> () {
// CHECK:   pointer_to_address %0 : $Builtin.RawPointer to [strict] $*Builtin.Int64
// CHECK:   pointer_to_address %0 : $Builtin.RawPointer to [invariant] $*Builtin.Int64
// CHECK:   pointer_to_address %0 : $Builtin.RawPointer to [align=1] $*Builtin.Int64
// CHECK:   pointer_to_address %0 : $Builtin.RawPointer to [strict] [align=8] $*Builtin.Int64
// CHECK:   pointer_to_address %0 : $Builtin.RawPointer to [align=4294967296] $*Builtin.Int64
sil [ossa] @test_pointer_to_address : $@convention(thin) (Builtin.RawPointer, Builtin.Int64) -> () {
bb0(%0 : $Builtin.RawPointer, %1 : $Builtin.Int64):
  %3 = pointer_to_address %0 : $Builtin.RawPointer to $*Builtin.Int64
  store %1 to [trivial] %3 : $*Builtin.Int64
  %5 = pointer_to_address %0 : $Builtin.RawPointer to [strict] $*Builtin.Int64
  store %1 to [trivial] %5 : $*Builtin.Int64
  %7 = pointer_to_address %0 : $Builtin.RawPointer to [invariant] $*Builtin.Int64
  store %1 to [trivial] %7 : $*Builtin.Int64
  %9 = pointer_to_address %0 : $Builtin.RawPointer to [align=1] $*Builtin.Int64
  store %1 to [trivial] %9 : $*Builtin.Int64
  %11 = pointer_to_address %0 : $Builtin.RawPointer to [strict] [align=8] $*Builtin.Int64
  store %1 to [trivial] %11 : $*Builtin.Int64
  %13 = pointer_to_address %0 : $Builtin.RawPointer to [align=4294967296] $*Builtin.Int64
  store %1 to [trivial] %13 : $*Builtin.Int64
  %28 = tuple ()
  return %28 : $()
}

// CHECK-LABEL: sil [serialized] [ossa] @test_subst_function_type : $@convention(thin) (@guaranteed @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in τ_0_0, @in τ_0_1) -> () for <Builtin.Int32, Builtin.Int64>) -> ()
sil [serialized] [ossa] @test_subst_function_type : $@convention(thin) (@guaranteed @callee_guaranteed @substituted <A, B> (@in A, @in B) -> () for <Builtin.Int32, Builtin.Int64>) -> () {
entry(%0 : @guaranteed $@callee_guaranteed @substituted <C, D> (@in C, @in D) -> () for <Builtin.Int32, Builtin.Int64>):
  return undef : $()
}

// CHECK-LABEL: sil [serialized] [ossa] @test_subst_function_type_generic_context : $@convention(thin) <X, Y> (@guaranteed @callee_guaranteed @substituted <τ_0_0, τ_0_1> (@in τ_0_0, @in τ_0_1) -> () for <X, Y>) -> ()
sil [serialized] [ossa] @test_subst_function_type_generic_context : $@convention(thin) <X, Y> (@guaranteed @callee_guaranteed @substituted <A, B> (@in A, @in B) -> () for <X, Y>) -> () {
entry(%0 : @guaranteed $@callee_guaranteed @substituted <C, D> (@in C, @in D) -> () for <X, Y>):
  return undef : $()
}

// CHECK-LABEL: sil [serialized] [ossa] @test_unchecked_ownership_conversion : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
// CHECK: unchecked_ownership_conversion {{%.*}} : $Builtin.NativeObject, @guaranteed to @owned
sil [serialized] [ossa] @test_unchecked_ownership_conversion : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
bb0(%0 : @guaranteed $Builtin.NativeObject):
  %1 = unchecked_ownership_conversion %0 : $Builtin.NativeObject, @guaranteed to @owned
  destroy_value %1 : $Builtin.NativeObject
  return undef : $()
}

// CHECK-LABEL: sil @throwError : $@convention(thin) <τ_0_0, τ_0_1> (Builtin.Int64, @in τ_0_0) -> (@out τ_0_1, @error_indirect τ_0_0)
// CHECK: copy_addr [take] %3 to [init] %1 : $*τ_0_0
// CHECK: throw %1 : $*τ_0_0
sil @throwError : $@convention(thin) <τ_0_0, τ_0_1> (Builtin.Int64, @in τ_0_0) -> (@error_indirect τ_0_0, @out τ_0_1) {
bb0(%0: $*τ_0_1, %1: $*τ_0_0, %2 : $Builtin.Int64, %3 : $*τ_0_0):
  copy_addr [take] %3 to [init] %1 : $*τ_0_0
  throw %1 : $*τ_0_0
}

// CHECK: sil @throwError_unowned : $@convention(thin) (Builtin.Int64) -> @error_unowned Builtin.Int64 {
// CHECK: bb0(%0 : $Builtin.Int64):
// CHECK:  throw %0 : $Builtin.Int64
sil @throwError_unowned : $@convention(thin) (Builtin.Int64) -> @error_unowned Builtin.Int64 {
bb0(%0 : $Builtin.Int64):
  throw %0 : $Builtin.Int64
}

// CHECK: sil @try_apply : $@convention(thin) <T, V> (@in T) -> @out V
// CHECK: bb0(%0 : $*V, %1 : $*T):
// CHECK:   %2 = alloc_stack $T
// CHECK:   %3 = integer_literal $Builtin.Int64, 0
// CHECK:   %4 = function_ref @throwError : $@convention(thin) <τ_0_0, τ_0_1> (Builtin.Int64, @in τ_0_0) -> (@out τ_0_1, @error_indirect τ_0_0)
// CHECK:   try_apply %4<T, V>(%0, %2, %3, %1) : $@convention(thin) <τ_0_0, τ_0_1> (Builtin.Int64, @in τ_0_0) -> (@out τ_0_1, @error_indirect τ_0_0), normal bb2, error bb1
// CHECK: bb1:
// CHECK:   destroy_addr %2 : $*T
// CHECK:   br bb3
// CHECK: bb2(%8 : $()):
// CHECK:   br bb3

sil @try_apply : $@convention(thin) <T, V> (@in T) -> @out V {
bb0(%0 : $*V, %1: $*T):
  %2 = alloc_stack $T
  %3 = integer_literal $Builtin.Int64, 0
  %4 = function_ref @throwError : $@convention(thin) <T, V> (Builtin.Int64, @in T) -> (@error_indirect T, @out V)
  try_apply %4<T, V>(%0, %2, %3, %1) : $@convention(thin) <T, V> (Builtin.Int64, @in T) -> (@error_indirect T, @out V), normal bb1, error bb2

bb1(%5 : $()):
  br bb3

bb2:
  destroy_addr %2 : $*T
  br bb3

bb3:
  dealloc_stack %2 : $*T
  %6 = tuple ()
  return %6 : $()
}