File: raw_sil_inst_lowering.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 (217 lines) | stat: -rw-r--r-- 11,138 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
215
216
217
// RUN: %target-sil-opt -enable-sil-verify-all %s -raw-sil-inst-lowering | %FileCheck %s

sil_stage raw

import Builtin
import Swift

class SomeClass {}

// CHECK-LABEL: sil [ossa] @non_box_assign_trivial
sil [ossa] @non_box_assign_trivial : $@convention(thin) (@inout Bool, Bool) -> () {
bb0(%0 : $*Bool, %1 : $Bool):
  // This is parsed with having an unknown init kind which is lowered as
  // assign [assign], but since this is trivial it's treated as assign [init].
  //
  // CHECK: store %1 to [trivial] %0 : $*Bool
  assign %1 to %0 : $*Bool

  %9 = tuple ()
  // CHECK: return
  return %9 : $()
}

// CHECK-LABEL: sil [ossa] @non_box_assign
sil [ossa] @non_box_assign : $@convention(thin) (@inout SomeClass, @owned SomeClass) -> () {
bb0(%0 : $*SomeClass, %1 : @owned $SomeClass):
  // This is parsed with having an unknown init kind which is lowered as
  // assign [assign].
  //
  // CHECK: store %1 to [assign] %0 : $*SomeClass
  assign %1 to %0 : $*SomeClass

  %9 = tuple ()
  // CHECK: return
  return %9 : $()
}

// CHECK-LABEL: sil [ossa] @non_box_assign_init
sil [ossa] @non_box_assign_init : $@convention(thin) (@owned SomeClass) -> @out SomeClass {
bb0(%0 : $*SomeClass, %1 : @owned $SomeClass):
  // Explicitly check that assign [init] is treated as store [init]
  //
  // CHECK: store %1 to [init] %0 : $*SomeClass
  assign %1 to [init] %0 : $*SomeClass

  %9 = tuple ()
  // CHECK: return
  return %9 : $()
}

// CHECK-LABEL: sil [ossa] @non_box_assign_reassign
sil [ossa] @non_box_assign_reassign : $@convention(thin) (@inout SomeClass, @owned SomeClass) -> () {
bb0(%0 : $*SomeClass, %1 : @owned $SomeClass):
  // Explicitly check that assign [reassign] is treated as store [assign]
  //
  // CHECK: store %1 to [assign] %0 : $*SomeClass
  assign %1 to [reassign] %0 : $*SomeClass

  %9 = tuple ()
  // CHECK: return
  return %9 : $()
}

// CHECK-LABEL: sil [ossa] @non_box_assign_reinit
sil [ossa] @non_box_assign_reinit : $@convention(thin) (@inout SomeClass, @owned SomeClass) -> () {
bb0(%0 : $*SomeClass, %1 : @owned $SomeClass):
  // Explicitly check that assign [reinit] is treated as load [take], store [init],
  // and dealloc_partial_ref
  //
  // CHECK: [[LOAD:%[0-9]+]] = load [take] %0 : $*SomeClass
  // CHECK-NEXT: store %1 to [init] %0 : $*SomeClass
  // CHECK-NEXT: [[METATYPE:%[0-9]+]] = value_metatype $@thick SomeClass.Type, [[LOAD]] : $SomeClass
  // CHECK-NEXT: dealloc_partial_ref [[LOAD]] : $SomeClass, [[METATYPE]] : $@thick SomeClass.Type
  assign %1 to [reinit] %0 : $*SomeClass

  %9 = tuple ()
  // CHECK: return
  return %9 : $()
}

@propertyWrapper struct Wrapper<T> {
  @_hasStorage var wrappedValue: T
  init(wrappedValue initialValue: T)
}

struct RefStruct {
  @_hasStorage var _wrapped: Wrapper<SomeClass>
}


sil @init_closure : $@convention(thin) (@owned SomeClass) -> @owned Wrapper<SomeClass>
sil @init_closure_indirect : $@convention(thin) (@owned SomeClass) -> @out Wrapper<SomeClass>
sil @set_closure : $@convention(method) (@owned SomeClass, @inout RefStruct) -> ()

// CHECK-LABEL: sil [ossa] @assign_by_wrapper_initialization_direct
// CHECK:   [[E:%[0-9]+]] = struct_element_addr
// CHECK:   [[C:%[0-9]+]] = function_ref @init_closure
// CHECK:   [[P:%[0-9]+]] = partial_apply [callee_guaranteed] [[C]]()
// CHECK-NOT: partial_apply
// CHECK:   [[R:%[0-9]+]] = apply [[P]](%0)
// CHECK:   store [[R]] to [init] [[E]]
// CHECK: } // end sil function 'assign_by_wrapper_initialization_direct'
sil [ossa] @assign_by_wrapper_initialization_direct : $@convention(method) (@owned SomeClass) -> @owned RefStruct {
bb0(%0 : @owned $SomeClass):
  %1 = alloc_stack $RefStruct
  %7 = struct_element_addr %1 : $*RefStruct, #RefStruct._wrapped
  %8 = function_ref @init_closure : $@convention(thin) (@owned SomeClass) -> @owned Wrapper<SomeClass>
  %9 = partial_apply [callee_guaranteed] %8() : $@convention(thin) (@owned SomeClass) -> @owned Wrapper<SomeClass>
  %10 = function_ref @set_closure : $@convention(method) (@owned SomeClass, @inout RefStruct) -> ()
  %11 = partial_apply [callee_guaranteed] %10(%1) : $@convention(method) (@owned SomeClass, @inout RefStruct) -> ()
  assign_by_wrapper %0 : $SomeClass to [init] %7 : $*Wrapper<SomeClass>, init %9 : $@callee_guaranteed (@owned SomeClass) -> @owned Wrapper<SomeClass>, set %11 : $@callee_guaranteed (@owned SomeClass) -> ()
  destroy_value %11 : $@callee_guaranteed (@owned SomeClass) -> ()
  destroy_value %9 : $@callee_guaranteed (@owned SomeClass) -> @owned Wrapper<SomeClass>
  %16 = load [take] %1 : $*RefStruct
  dealloc_stack %1 : $*RefStruct
  return %16 : $RefStruct
}

// CHECK-LABEL: sil [ossa] @assign_by_wrapper_initialization_indirect
// CHECK:   [[E:%[0-9]+]] = struct_element_addr
// CHECK:   [[C:%[0-9]+]] = function_ref @init_closure_indirect
// CHECK:   [[P:%[0-9]+]] = partial_apply [callee_guaranteed] [[C]]()
// CHECK-NOT: partial_apply
// CHECK-NOT: destroy_addr
// CHECK:   [[R:%[0-9]+]] = apply [[P]]([[E]], %0)
// CHECK: } // end sil function 'assign_by_wrapper_initialization_indirect'
sil [ossa] @assign_by_wrapper_initialization_indirect : $@convention(method) (@owned SomeClass) -> @owned RefStruct {
bb0(%0 : @owned $SomeClass):
  %1 = alloc_stack $RefStruct
  %7 = struct_element_addr %1 : $*RefStruct, #RefStruct._wrapped
  %8 = function_ref @init_closure_indirect : $@convention(thin) (@owned SomeClass) -> @out Wrapper<SomeClass>
  %9 = partial_apply [callee_guaranteed] %8() : $@convention(thin) (@owned SomeClass) -> @out Wrapper<SomeClass>
  %10 = function_ref @set_closure : $@convention(method) (@owned SomeClass, @inout RefStruct) -> ()
  %11 = partial_apply [callee_guaranteed] %10(%1) : $@convention(method) (@owned SomeClass, @inout RefStruct) -> ()
  assign_by_wrapper %0 : $SomeClass to [init] %7 : $*Wrapper<SomeClass>, init %9 : $@callee_guaranteed (@owned SomeClass) -> @out Wrapper<SomeClass>, set %11 : $@callee_guaranteed (@owned SomeClass) -> ()
  destroy_value %11 : $@callee_guaranteed (@owned SomeClass) -> ()
  destroy_value %9 : $@callee_guaranteed (@owned SomeClass) -> @out Wrapper<SomeClass>
  %16 = load [take] %1 : $*RefStruct
  dealloc_stack %1 : $*RefStruct
  return %16 : $RefStruct
}

// CHECK-LABEL: sil [ossa] @assign_by_wrapper_assign_direct
// CHECK:   [[E:%[0-9]+]] = struct_element_addr
// CHECK:   [[C:%[0-9]+]] = function_ref @init_closure
// CHECK:   [[P:%[0-9]+]] = partial_apply [callee_guaranteed] [[C]]()
// CHECK-NOT: partial_apply
// CHECK:   [[R:%[0-9]+]] = apply [[P]](%0)
// CHECK:   store [[R]] to [assign] [[E]]
// CHECK: } // end sil function 'assign_by_wrapper_assign_direct'
sil [ossa] @assign_by_wrapper_assign_direct : $@convention(method) (@owned SomeClass, @owned Wrapper<SomeClass>) -> @owned RefStruct {
bb0(%0 : @owned $SomeClass, %1 : @owned $Wrapper<SomeClass>):
  %2 = alloc_stack $RefStruct
  %7 = struct_element_addr %2 : $*RefStruct, #RefStruct._wrapped
  store %1 to [init] %7 : $*Wrapper<SomeClass>
  %8 = function_ref @init_closure : $@convention(thin) (@owned SomeClass) -> @owned Wrapper<SomeClass>
  %9 = partial_apply [callee_guaranteed] %8() : $@convention(thin) (@owned SomeClass) -> @owned Wrapper<SomeClass>
  %10 = function_ref @set_closure : $@convention(method) (@owned SomeClass, @inout RefStruct) -> ()
  %11 = partial_apply [callee_guaranteed] %10(%2) : $@convention(method) (@owned SomeClass, @inout RefStruct) -> ()
  assign_by_wrapper %0 : $SomeClass to [assign] %7 : $*Wrapper<SomeClass>, init %9 : $@callee_guaranteed (@owned SomeClass) -> @owned Wrapper<SomeClass>, set %11 : $@callee_guaranteed (@owned SomeClass) -> ()
  destroy_value %11 : $@callee_guaranteed (@owned SomeClass) -> ()
  destroy_value %9 : $@callee_guaranteed (@owned SomeClass) -> @owned Wrapper<SomeClass>
  %16 = load [take] %2 : $*RefStruct
  dealloc_stack %2 : $*RefStruct
  return %16 : $RefStruct
}

// CHECK-LABEL: sil [ossa] @assign_by_wrapper_assign_indirect
// CHECK:   [[E:%[0-9]+]] = struct_element_addr
// CHECK:   [[C:%[0-9]+]] = function_ref @init_closure_indirect
// CHECK:   [[P:%[0-9]+]] = partial_apply [callee_guaranteed] [[C]]()
// CHECK-NOT: partial_apply
// CHECK:   destroy_addr [[E]]
// CHECK:   [[R:%[0-9]+]] = apply [[P]]([[E]], %0)
// CHECK: } // end sil function 'assign_by_wrapper_assign_indirect'
sil [ossa] @assign_by_wrapper_assign_indirect : $@convention(method) (@owned SomeClass, @owned Wrapper<SomeClass>) -> @owned RefStruct {
bb0(%0 : @owned $SomeClass, %1 : @owned $Wrapper<SomeClass>):
  %2 = alloc_stack $RefStruct
  %7 = struct_element_addr %2 : $*RefStruct, #RefStruct._wrapped
  store %1 to [init] %7 : $*Wrapper<SomeClass>
  %8 = function_ref @init_closure_indirect : $@convention(thin) (@owned SomeClass) -> @out Wrapper<SomeClass>
  %9 = partial_apply [callee_guaranteed] %8() : $@convention(thin) (@owned SomeClass) -> @out Wrapper<SomeClass>
  %10 = function_ref @set_closure : $@convention(method) (@owned SomeClass, @inout RefStruct) -> ()
  %11 = partial_apply [callee_guaranteed] %10(%2) : $@convention(method) (@owned SomeClass, @inout RefStruct) -> ()
  assign_by_wrapper %0 : $SomeClass to [assign] %7 : $*Wrapper<SomeClass>, init %9 : $@callee_guaranteed (@owned SomeClass) -> @out Wrapper<SomeClass>, set %11 : $@callee_guaranteed (@owned SomeClass) -> ()
  destroy_value %11 : $@callee_guaranteed (@owned SomeClass) -> ()
  destroy_value %9 : $@callee_guaranteed (@owned SomeClass) -> @out Wrapper<SomeClass>
  %16 = load [take] %2 : $*RefStruct
  dealloc_stack %2 : $*RefStruct
  return %16 : $RefStruct
}

// CHECK-LABEL: sil [ossa] @assign_by_wrapper_assign_wrapped_value
// CHECK:   [[A:%[0-9]+]] = alloc_stack $RefStruct
// CHECK:   [[E:%[0-9]+]] = struct_element_addr
// CHECK-NOT: partial_apply
// CHECK:   [[C:%[0-9]+]] = function_ref @set_closure
// CHECK:   [[P:%[0-9]+]] = partial_apply [callee_guaranteed] [[C]]([[A]])
// CHECK:   apply [[P]](%0)
// CHECK: } // end sil function 'assign_by_wrapper_assign_wrapped_value'
sil [ossa] @assign_by_wrapper_assign_wrapped_value : $@convention(method) (@owned SomeClass, @owned RefStruct) -> @owned RefStruct {
bb0(%0 : @owned $SomeClass, %1 : @owned $RefStruct):
  %2 = alloc_stack $RefStruct
  store %1 to [init] %2 : $*RefStruct
  %7 = struct_element_addr %2 : $*RefStruct, #RefStruct._wrapped
  %8 = function_ref @init_closure : $@convention(thin) (@owned SomeClass) -> @owned Wrapper<SomeClass>
  %9 = partial_apply [callee_guaranteed] %8() : $@convention(thin) (@owned SomeClass) -> @owned Wrapper<SomeClass>
  %10 = function_ref @set_closure : $@convention(method) (@owned SomeClass, @inout RefStruct) -> ()
  %11 = partial_apply [callee_guaranteed] %10(%2) : $@convention(method) (@owned SomeClass, @inout RefStruct) -> ()
  assign_by_wrapper %0 : $SomeClass to [assign_wrapped_value] %7 : $*Wrapper<SomeClass>, init %9 : $@callee_guaranteed (@owned SomeClass) -> @owned Wrapper<SomeClass>, set %11 : $@callee_guaranteed (@owned SomeClass) -> ()
  destroy_value %11 : $@callee_guaranteed (@owned SomeClass) -> ()
  destroy_value %9 : $@callee_guaranteed (@owned SomeClass) -> @owned Wrapper<SomeClass>
  %16 = load [take] %2 : $*RefStruct
  dealloc_stack %2 : $*RefStruct
  return %16 : $RefStruct
}