@@ -23,6 +23,36 @@ sil_global [let] @gstr : $Str = {
23
23
class B { }
24
24
class E : B { }
25
25
26
+ sil_global hidden [let] @gb : $B
27
+ sil_global hidden [let] @gb2 : $(B, Int64)
28
+
29
+ sil_global private @gb_obj : $B = {
30
+ %initval = object $B ()
31
+ }
32
+
33
+ sil [global_init_once_fn] @init_gb : $@convention(c) () -> () {
34
+ bb0:
35
+ alloc_global @gb
36
+ %1 = global_addr @gb : $*B
37
+ %2 = global_value @gb_obj : $B
38
+ store %2 to %1 : $*B
39
+ %6 = tuple ()
40
+ return %6 : $()
41
+ }
42
+
43
+ sil [global_init_once_fn] @init_gb2 : $@convention(c) () -> () {
44
+ bb0:
45
+ alloc_global @gb2
46
+ %1 = global_addr @gb2 : $*(B, Int64)
47
+ %2 = global_value @gb_obj : $B
48
+ %3 = integer_literal $Builtin.Int64, 10
49
+ %4 = struct $Int64 (%3 : $Builtin.Int64)
50
+ %5 = tuple (%2 : $B, %4 : $Int64)
51
+ store %5 to %1 : $*(B, Int64)
52
+ %6 = tuple ()
53
+ return %6 : $()
54
+ }
55
+
26
56
sil [global_init] @gstr_addressor : $@convention(thin) () -> Builtin.RawPointer {
27
57
bb0:
28
58
%0 = global_addr @gstr : $*Str
96
126
return %3 : $Int64
97
127
}
98
128
129
+ // CHECK-LABEL: sil @load_global_object :
130
+ // CHECK: %1 = global_value @gb_obj
131
+ // CHECK-NEXT: return %1
132
+ // CHECK: } // end sil function 'load_global_object'
133
+ sil @load_global_object : $@convention(thin) (Builtin.RawPointer) -> @owned B {
134
+ bb0(%0 : $Builtin.RawPointer):
135
+ %1 = function_ref @init_gb : $@convention(c) () -> ()
136
+ %2 = builtin "once"(%0 : $Builtin.RawPointer, %1 : $@convention(c) () -> ()) : $Builtin.SILToken
137
+ %3 = global_addr @gb : $*B depends_on %2
138
+ %4 = load %3 : $*B
139
+ return %4 : $B
140
+ }
141
+
142
+ // CHECK-LABEL: sil @load_global_object_keep_once :
143
+ // CHECK: %2 = builtin "once"
144
+ // CHECK: %3 = global_value @gb_obj
145
+ // CHECK: fix_lifetime
146
+ // CHECK: return %3
147
+ // CHECK: } // end sil function 'load_global_object_keep_once'
148
+ sil @load_global_object_keep_once : $@convention(thin) (Builtin.RawPointer) -> @owned B {
149
+ bb0(%0 : $Builtin.RawPointer):
150
+ %1 = function_ref @init_gb : $@convention(c) () -> ()
151
+ %2 = builtin "once"(%0 : $Builtin.RawPointer, %1 : $@convention(c) () -> ()) : $Builtin.SILToken
152
+ %3 = global_addr @gb : $*B depends_on %2
153
+ %4 = load %3 : $*B
154
+ %5 = global_addr @gb : $*B depends_on %2
155
+ fix_lifetime %5 : $*B
156
+ return %4 : $B
157
+ }
158
+
159
+ // CHECK-LABEL: sil @load_global_object_from_tuple :
160
+ // CHECK: %1 = global_value @gb_obj
161
+ // CHECK-NEXT: return %1
162
+ // CHECK: } // end sil function 'load_global_object_from_tuple'
163
+ sil @load_global_object_from_tuple : $@convention(thin) (Builtin.RawPointer) -> @owned B {
164
+ bb0(%0 : $Builtin.RawPointer):
165
+ %1 = function_ref @init_gb2 : $@convention(c) () -> ()
166
+ %2 = builtin "once"(%0 : $Builtin.RawPointer, %1 : $@convention(c) () -> ()) : $Builtin.SILToken
167
+ %3 = global_addr @gb2 : $*(B, Int64) depends_on %2
168
+ %4 = tuple_element_addr %3 : $*(B, Int64), 0
169
+ %5 = load %4 : $*B
170
+ return %5 : $B
171
+ }
172
+
173
+ // CHECK-LABEL: sil @load_global_tuple :
174
+ // CHECK: %1 = global_value @gb_obj
175
+ // CHECK: [[T:%.*]] = tuple (%1 : $B, {{%.*}} : $Int64)
176
+ // CHECK-NEXT: return [[T]]
177
+ // CHECK: } // end sil function 'load_global_tuple'
178
+ sil @load_global_tuple : $@convention(thin) (Builtin.RawPointer) -> @owned (B, Int64) {
179
+ bb0(%0 : $Builtin.RawPointer):
180
+ %1 = function_ref @init_gb2 : $@convention(c) () -> ()
181
+ %2 = builtin "once"(%0 : $Builtin.RawPointer, %1 : $@convention(c) () -> ()) : $Builtin.SILToken
182
+ %3 = global_addr @gb2 : $*(B, Int64) depends_on %2
183
+ %4 = load %3 : $*(B, Int64)
184
+ return %4 : $(B, Int64)
185
+ }
186
+
99
187
// CHECK-LABEL: sil @load_first_char_from_string_literal
100
188
// CHECK: bb0:
101
189
// CHECK-NEXT: %0 = integer_literal $Builtin.Int8, 97
0 commit comments