File: cow_opts.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 (202 lines) | stat: -rw-r--r-- 7,306 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
// RUN: %target-sil-opt %s -cow-opts | %FileCheck %s

sil_stage canonical

import Builtin
import Swift
import SwiftShims

final class Buffer {
  @_hasStorage var i: Int { get set }
  init()
}

struct Str {
  @_hasStorage var b: Buffer { get set }
}

struct BufferAndBool {
  @_hasStorage var b: Buffer { get set }
  @_hasStorage var x: Bool { get set }
}

sil @unknown : $@convention(thin) (@guaranteed Buffer) -> ()

// CHECK-LABEL: sil @test_simple
// CHECK:   [[I:%[0-9]+]] = integer_literal $Builtin.Int1, -1
// CHECK:   ({{.*}}, [[B:%[0-9]+]]) = begin_cow_mutation
// CHECK:   [[T:%[0-9]+]] = tuple ({{.*}}, [[I]] : $Builtin.Int1, [[B]] : $Buffer)
// CHECK:   return [[T]]
// CHECK: } // end sil function 'test_simple'
sil @test_simple : $@convention(thin) (@owned Buffer) -> (Int, Builtin.Int1, @owned Buffer) {
bb0(%0 : $Buffer):
  %e = end_cow_mutation %0 : $Buffer
  %addr = ref_element_addr [immutable] %e : $Buffer, #Buffer.i
  debug_value %e : $Buffer, var, name "x"
  %i = load %addr : $*Int
  (%u, %b) = begin_cow_mutation %e : $Buffer
  %t = tuple (%i : $Int, %u : $Builtin.Int1, %b : $Buffer)
  return %t : $(Int, Builtin.Int1, Buffer)
}

// CHECK-LABEL: sil @test_store
// CHECK:   end_cow_mutation
// CHECK:   [[I:%[0-9]+]] = integer_literal $Builtin.Int1, -1
// CHECK:   begin_cow_mutation
// CHECK:   return [[I]]
// CHECK: } // end sil function 'test_store'
sil @test_store : $@convention(thin) (@inout Buffer) -> Builtin.Int1 {
bb0(%0 : $*Buffer):
  %l = load %0 : $*Buffer
  %e = end_cow_mutation %l : $Buffer
  store %e to %0 : $*Buffer
  (%u, %b) = begin_cow_mutation %e : $Buffer
  store %b to %0 : $*Buffer
  return %u : $Builtin.Int1
}

// CHECK-LABEL: sil @test_store_and_load
// CHECK:   end_cow_mutation
// CHECK:   ([[U:%[0-9]+]], {{.*}}) = begin_cow_mutation
// CHECK:   return [[U]]
// CHECK: } // end sil function 'test_store_and_load'
sil @test_store_and_load : $@convention(thin) (@inout Buffer) -> Builtin.Int1 {
bb0(%0 : $*Buffer):
  %l = load %0 : $*Buffer
  %e = end_cow_mutation %l : $Buffer
  store %e to %0 : $*Buffer
  %l2 = load %0 : $*Buffer
  %f = function_ref @unknown : $@convention(thin) (@guaranteed Buffer) -> ()
  apply %f(%l2) : $@convention(thin) (@guaranteed Buffer) -> ()
  (%u, %b) = begin_cow_mutation %e : $Buffer
  store %b to %0 : $*Buffer
  return %u : $Builtin.Int1
}

// CHECK-LABEL: sil @test_store_and_load_outside_liverange
// CHECK:   end_cow_mutation
// CHECK:   [[I:%[0-9]+]] = integer_literal $Builtin.Int1, -1
// CHECK:   begin_cow_mutation
// CHECK:   return [[I]]
// CHECK: } // end sil function 'test_store_and_load_outside_liverange'
sil @test_store_and_load_outside_liverange : $@convention(thin) (@inout Buffer) -> Builtin.Int1 {
bb0(%0 : $*Buffer):
  %l = load %0 : $*Buffer
  %e = end_cow_mutation %l : $Buffer
  store %e to %0 : $*Buffer
  (%u, %b) = begin_cow_mutation %e : $Buffer
  %l2 = load %0 : $*Buffer
  %f = function_ref @unknown : $@convention(thin) (@guaranteed Buffer) -> ()
  apply %f(%l2) : $@convention(thin) (@guaranteed Buffer) -> ()
  store %b to %0 : $*Buffer
  return %u : $Builtin.Int1
}

// CHECK-LABEL: sil @test_loop
// CHECK:   [[I:%[0-9]+]] = integer_literal $Builtin.Int1, -1
// CHECK:   [[B:%[0-9]+]] = end_cow_mutation
// CHECK:   [[T:%[0-9]+]] = tuple ([[I]] : $Builtin.Int1, [[B]] : $Buffer)
// CHECK:   return [[T]]
// CHECK: } // end sil function 'test_loop'
sil @test_loop : $@convention(thin) (@owned Buffer) -> (Builtin.Int1, @owned Buffer) {
bb0(%0 : $Buffer):
  %e = end_cow_mutation %0 : $Buffer
  %s1 = struct $Str (%e: $Buffer)
  br bb1(%s1 : $Str)
bb1(%a : $Str):
  %as = struct_extract %a : $Str, #Str.b
  (%u, %b) = begin_cow_mutation %as : $Buffer
  %e2 = end_cow_mutation %b : $Buffer
  %s2 = struct $Str (%e2: $Buffer)
  cond_br undef, bb1(%s2 : $Str), bb2
bb2:
  %t = tuple (%u : $Builtin.Int1, %e2 : $Buffer)
  return %t : $(Builtin.Int1, Buffer)
}

// CHECK-LABEL: sil @test_cond_br_condition
// CHECK:   [[I:%[0-9]+]] = integer_literal $Builtin.Int1, -1
// CHECK:   ({{.*}}, [[B:%[0-9]+]]) = begin_cow_mutation
// CHECK:   [[T:%[0-9]+]] = tuple ([[I]] : $Builtin.Int1, [[B]] : $Buffer)
// CHECK:   return [[T]]
// CHECK: } // end sil function 'test_cond_br_condition'
sil @test_cond_br_condition : $@convention(thin) (@owned Buffer, Bool) -> (Builtin.Int1, @owned Buffer) {
bb0(%0 : $Buffer, %1 : $Bool):
  %e = end_cow_mutation %0 : $Buffer
  %s1 = struct $BufferAndBool (%e: $Buffer, %1 : $Bool)
  %x = struct_extract %s1 : $BufferAndBool, #BufferAndBool.x
  %c = struct_extract %x : $Bool, #Bool._value
  cond_br %c, bb1, bb2
bb1:
  br bb3
bb2:
  br bb3
bb3:
  (%u, %b) = begin_cow_mutation %e : $Buffer
  %t = tuple (%u : $Builtin.Int1, %b : $Buffer)
  return %t : $(Builtin.Int1, Buffer)
}

// CHECK-LABEL: sil @not_all_incoming_values_are_end_cow_mutation
// CHECK:   ([[U:%[0-9]+]], {{.*}}) = begin_cow_mutation
// CHECK:   [[B:%[0-9]+]] = end_cow_mutation
// CHECK:   [[T:%[0-9]+]] = tuple ([[U]] : $Builtin.Int1, [[B]] : $Buffer)
// CHECK:   return [[T]]
// CHECK: } // end sil function 'not_all_incoming_values_are_end_cow_mutation'
sil @not_all_incoming_values_are_end_cow_mutation : $@convention(thin) (@owned Buffer) -> (Builtin.Int1, @owned Buffer) {
bb0(%0 : $Buffer):
  %s1 = struct $Str (%0: $Buffer)
  br bb1(%s1 : $Str)
bb1(%a : $Str):
  %as = struct_extract %a : $Str, #Str.b
  (%u, %b) = begin_cow_mutation %as : $Buffer
  %e2 = end_cow_mutation %b : $Buffer
  %s2 = struct $Str (%e2: $Buffer)
  cond_br undef, bb1(%s2 : $Str), bb2
bb2:
  %t = tuple (%u : $Builtin.Int1, %e2 : $Buffer)
  return %t : $(Builtin.Int1, Buffer)
}

// CHECK-LABEL: sil @test_escape_in_loop
// CHECK:   ([[U:%[0-9]+]], {{.*}}) = begin_cow_mutation
// CHECK:   [[B:%[0-9]+]] = end_cow_mutation
// CHECK:   [[T:%[0-9]+]] = tuple ([[U]] : $Builtin.Int1, [[B]] : $Buffer)
// CHECK:   return [[T]]
// CHECK: } // end sil function 'test_escape_in_loop'
sil @test_escape_in_loop : $@convention(thin) (@owned Buffer) -> (Builtin.Int1, @owned Buffer) {
bb0(%0 : $Buffer):
  %f = function_ref @unknown : $@convention(thin) (@guaranteed Buffer) -> ()
  %e = end_cow_mutation %0 : $Buffer
  br bb1(%e : $Buffer)
bb1(%a : $Buffer):
  (%u, %b) = begin_cow_mutation %a : $Buffer
  %e2 = end_cow_mutation %b : $Buffer
  apply %f(%e2) : $@convention(thin) (@guaranteed Buffer) -> ()
  cond_br undef, bb1(%e2 : $Buffer), bb2
bb2:
  %t = tuple (%u : $Builtin.Int1, %e2 : $Buffer)
  return %t : $(Builtin.Int1, Buffer)
}

// CHECK-LABEL: sil @test_escape_outside_loop
// CHECK:   [[I:%[0-9]+]] = integer_literal $Builtin.Int1, -1
// CHECK:   [[B:%[0-9]+]] = end_cow_mutation
// CHECK:   [[T:%[0-9]+]] = tuple ([[I]] : $Builtin.Int1, [[B]] : $Buffer)
// CHECK:   return [[T]]
// CHECK: } // end sil function 'test_escape_outside_loop'
sil @test_escape_outside_loop : $@convention(thin) (@owned Buffer) -> (Builtin.Int1, @owned Buffer) {
bb0(%0 : $Buffer):
  %f = function_ref @unknown : $@convention(thin) (@guaranteed Buffer) -> ()
  %e = end_cow_mutation %0 : $Buffer
  br bb1(%e : $Buffer)
bb1(%a : $Buffer):
  (%u, %b) = begin_cow_mutation %a : $Buffer
  %e2 = end_cow_mutation %b : $Buffer
  cond_br undef, bb1(%e2 : $Buffer), bb2
bb2:
  apply %f(%e2) : $@convention(thin) (@guaranteed Buffer) -> ()
  %t = tuple (%u : $Builtin.Int1, %e2 : $Buffer)
  return %t : $(Builtin.Int1, Buffer)
}