File: simplify_retain_value.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 (186 lines) | stat: -rw-r--r-- 6,527 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
// RUN: %target-sil-opt -enable-experimental-feature MoveOnlyEnumDeinits -enable-sil-verify-all %s -simplification -simplify-instruction=retain_value | %FileCheck %s

// REQUIRES: swift_in_compiler

import Swift
import Builtin

class C {}

enum U {
  init()
  case X
  case Y(Builtin.Int64)
  case Z(C)
}

struct WithDeinit : ~Copyable {
  deinit
}

struct Outer : ~Copyable {
  var wd: WithDeinit
}

enum EnumWithDeinit: ~Copyable {
  case A(Int64)
  case B

  deinit
}

struct TwoEnums {
  var u1: U
  var u2: U
}

struct MyStringObj {
  @_hasStorage var a: UInt64
  @_hasStorage var b: Builtin.BridgeObject
}

struct MyStringGuts {
  @_hasStorage var o: MyStringObj
}

struct MyString {
  @_hasStorage var g: MyStringGuts
}

// CHECK-LABEL: sil @retain_value_test
// CHECK:       bb0([[TRIVIAL_TARGET:%[0-9]+]] : $Builtin.Int8, [[REFCOUNT_TARGET:%[0-9]+]] : $Builtin.NativeObject):
// CHECK-NEXT:    strong_retain [[REFCOUNT_TARGET]] : $Builtin.NativeObject
// CHECK-NEXT:    tuple ([[TRIVIAL_TARGET]] : $Builtin.Int8, [[REFCOUNT_TARGET]] : $Builtin.NativeObject)
// CHECK-NEXT:    return
// CHECK:       } // end sil function 'retain_value_test'
sil @retain_value_test : $@convention(thin) (Builtin.Int8, Builtin.NativeObject) -> (Builtin.Int8, Builtin.NativeObject) {
bb0(%0 : $Builtin.Int8, %1 : $Builtin.NativeObject):
  retain_value %0 : $Builtin.Int8
  retain_value %1 : $Builtin.NativeObject
  %4 = tuple(%0 : $Builtin.Int8, %1 : $Builtin.NativeObject)
  return %4 : $(Builtin.Int8, Builtin.NativeObject)
}

// CHECK-LABEL: sil @dont_remove_struct_with_deinit_field
// CHECK:         retain_value %0
// CHECK:       } // end sil function 'dont_remove_struct_with_deinit_field'
sil @dont_remove_struct_with_deinit_field : $@convention(thin) (Outer) -> () {
bb0(%0 : $Outer):
  retain_value %0 : $Outer
  %2 = tuple ()
  return %2 : $()
}

// CHECK-LABEL: sil @struct_with_two_trivial_enums
// CHECK-NOT:     retain_value
// CHECK:       } // end sil function 'struct_with_two_trivial_enums'
sil @struct_with_two_trivial_enums : $@convention(thin) (Builtin.Int64) -> () {
bb0(%0 : $Builtin.Int64):
  %1 = enum $U, #U.X!enumelt
  %2 = enum $U, #U.Y!enumelt, %0 : $Builtin.Int64
  %3 = struct $TwoEnums (%1 : $U, %2 : $U)
  retain_value %3 : $TwoEnums
  %5 = tuple ()
  return %5 : $()
}

// CHECK-LABEL: sil @struct_with_non_trivial_enums
// CHECK:         retain_value
// CHECK:       } // end sil function 'struct_with_non_trivial_enums'
sil @struct_with_non_trivial_enums : $@convention(thin) (@guaranteed C) -> () {
bb0(%0 : $C):
  %1 = enum $U, #U.X!enumelt
  %2 = enum $U, #U.Z!enumelt, %0 : $C
  %3 = struct $TwoEnums (%1 : $U, %2 : $U)
  retain_value %3 : $TwoEnums
  %5 = tuple ()
  return %5 : $()
}

// CHECK-LABEL: sil @remove_value_to_bridge_object
// CHECK:      bb0(%0 : $UInt64):
// CHECK-NEXT:   tuple
// CHECK-NEXT:   return
// CHECK:      } // end sil function 'remove_value_to_bridge_object'
sil @remove_value_to_bridge_object : $@convention(thin) (UInt64) -> () {
bb0(%0 : $UInt64):
  %1 = integer_literal $Builtin.Int64, -1945555039024054272
  %2 = value_to_bridge_object %1 : $Builtin.Int64
  %3 = struct $MyStringObj (%0 : $UInt64, %2 : $Builtin.BridgeObject)
  %4 = struct $MyStringGuts (%3 : $MyStringObj)
  %5 = struct $MyString (%4 : $MyStringGuts)
  retain_value %5 : $MyString
  %7 = tuple ()
  return %7 : $()
}

// CHECK-LABEL: sil @sil_copyvalue_of_enum
// CHECK:       bb0([[TYPE_ARG:%[0-9]+]] : $@thin U.Type, [[CLASS_ARG:%[0-9]+]] : $C):
// CHECK-NEXT:    enum $U, #U.X!enumelt
// CHECK-NEXT:    integer_literal $Builtin.Int64, 32
// CHECK-NEXT:    enum $U, #U.Y!enumelt, {{%[0-9]+}} : $Builtin.Int64
// CHECK-NEXT:    [[INVALID_CASE:%[0-9]+]] = enum $U, #U.Z!enumelt, {{%[0-9]+}} : $C
// CHECK-NEXT:    strong_retain [[CLASS_ARG]] : $C
// CHECK-NEXT:    tuple ({{%[0-9]+}} : $U, {{%[0-9]+}} : $U, [[INVALID_CASE]] : $U)
// CHECK-NEXT:    return
// CHECK:       } // end sil function 'sil_copyvalue_of_enum'
sil @sil_copyvalue_of_enum : $@convention(thin) (@thin U.Type, C) -> (U, U, U) {
bb0(%0 : $@thin U.Type, %1 : $C):
  %2 = enum $U, #U.X!enumelt
  retain_value %2 : $U
  %3 = integer_literal $Builtin.Int64, 32
  %4 = enum $U, #U.Y!enumelt, %3 : $Builtin.Int64
  retain_value %4 : $U
  %5 = enum $U, #U.Z!enumelt, %1 : $C
  retain_value %5 : $U
  %6 = tuple(%2 : $U, %4 : $U, %5 : $U)
  return %6 : $(U, U, U)
}

// CHECK-LABEL: sil @dont_replace_payload_of_enum_with_deinit
// CHECK:         %1 = enum
// CHECK:         retain_value %1
// CHECK:       } // end sil function 'dont_replace_payload_of_enum_with_deinit'
sil @dont_replace_payload_of_enum_with_deinit : $@convention(thin) (Int64) -> () {
bb0(%0 : $Int64):
  %1 = enum $EnumWithDeinit, #EnumWithDeinit.A!enumelt, %0 : $Int64
  retain_value %1 : $EnumWithDeinit
  %3 = tuple ()
  return %3 : $()
}

// CHECK-LABEL: sil @release_then_retain_peephole
// CHECK:       bb0
// CHECK-NOT:     retain_value
// CHECK-NOT:     release_value
// CHECK-NEXT:    return
// CHECK:       } // end sil function 'release_then_retain_peephole'
sil @release_then_retain_peephole : $@convention(thin) (Optional<Builtin.NativeObject>) -> Optional<Builtin.NativeObject> {
bb0(%0 : $Optional<Builtin.NativeObject>):
  release_value %0 : $Optional<Builtin.NativeObject>
  retain_value %0 : $Optional<Builtin.NativeObject>
  return %0 : $Optional<Builtin.NativeObject>
}

// CHECK-LABEL: sil @ref_ops_of_enum_is_equivalent_to_ref_ops_of_payload : $@convention(thin) (Builtin.NativeObject) -> Optional<Builtin.NativeObject> {
// CHECK:       bb0
// CHECK-NEXT:    enum
// CHECK-NEXT:    strong_retain %0
// CHECK-NEXT:    return
// CHECK:       } // end sil function 'ref_ops_of_enum_is_equivalent_to_ref_ops_of_payload'
sil @ref_ops_of_enum_is_equivalent_to_ref_ops_of_payload : $@convention(thin) (Builtin.NativeObject) -> Optional<Builtin.NativeObject> {
bb0(%0 : $Builtin.NativeObject):
  %1 = enum $Optional<Builtin.NativeObject>, #Optional.some!enumelt, %0 : $Builtin.NativeObject
  retain_value %1 : $Optional<Builtin.NativeObject>
  return %1 : $Optional<Builtin.NativeObject>
}

// CHECK-LABEL: sil @lower_retainrelease_value_of_unowned_to_unowned_retainrelease :
// CHECK:         unowned_retain
// CHECK:       } // end sil function 'lower_retainrelease_value_of_unowned_to_unowned_retainrelease'
sil @lower_retainrelease_value_of_unowned_to_unowned_retainrelease : $@convention(thin) (@owned @sil_unowned C) -> @owned @sil_unowned C {
bb0(%0 : $@sil_unowned C):
  retain_value %0 : $@sil_unowned C
  return %0 : $@sil_unowned C
}