1
1
// Pullback generation tests written in SIL for features
2
2
// that may not be directly supported by the Swift frontend
3
3
4
- // RUN: %target-sil-opt --differentiation -debug-only=differentiation - emit-sorted-sil %s 2>&1 | %FileCheck %s
4
+ // RUN: %target-sil-opt --differentiation -emit-sorted-sil %s 2>&1 | %FileCheck %s
5
5
6
6
//===----------------------------------------------------------------------===//
7
7
// Pullback generation - `struct_extract`
@@ -57,27 +57,31 @@ bb0(%0 : @guaranteed $Y):
57
57
return %2 : $X
58
58
}
59
59
60
- // CHECK-LABEL: [ORIG] %1 = struct_extract %0 : $Y, #Y.a // user: %2
61
- // CHECK: [ADJ] Emitted in pullback (pb bb0 ):
62
- // CHECK: %1 = alloc_stack $Y // users: {{.*}}
63
- // CHECK: %2 = witness_method $Y, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %4
64
- // CHECK: %3 = metatype $@thick Y.Type // user: %4
65
- // CHECK: %4 = apply %2<Y>(%1, %3) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
60
+ // CHECK-LABEL: sil private [ossa] @$function_with_struct_extract_1TJpSpSr : $@convention(thin) (@guaranteed X) -> @owned Y {
61
+ // CHECK: bb0(%0 : @guaranteed $X ):
62
+ // CHECK: %1 = alloc_stack $Y // users: {{.*}}
63
+ // CHECK: %2 = witness_method $Y, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %4
64
+ // CHECK: %3 = metatype $@thick Y.Type // user: %4
65
+ // CHECK: %4 = apply %2<Y>(%1, %3) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
66
66
67
67
// Since input parameter $0 has non-owned ownership semantics, it
68
68
// needs to be copied before a lifetime-ending use.
69
- // CHECK: %5 = copy_value %0 : $X // user: %7
70
-
71
- // CHECK: %6 = alloc_stack $X // users: {{.*}}
72
- // CHECK: store %5 to [init] %6 : $*X // id: %7
73
- // CHECK: %8 = struct_element_addr %1 : $*Y, #Y.a // user: %11
74
- // CHECK: %9 = witness_method $X, #AdditiveArithmetic."+=" : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %11
75
- // CHECK: %10 = metatype $@thick X.Type // user: %11
76
- // CHECK: %11 = apply %9<X>(%8, %6, %10) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
77
- // CHECK: %12 = load [take] %1 : $*Y
78
- // CHECK: destroy_addr %6 : $*X // id: %13
79
- // CHECK: dealloc_stack %6 : $*X // id: %14
80
- // CHECK: dealloc_stack %1 : $*Y // id: %15
69
+ // CHECK: %5 = copy_value %0 : $X // user: %7
70
+
71
+ // CHECK: %6 = alloc_stack $X // users: {{.*}}
72
+ // CHECK: store %5 to [init] %6 : $*X // id: %7
73
+ // CHECK: %8 = struct_element_addr %1 : $*Y, #Y.a // user: %11
74
+ // CHECK: %9 = witness_method $X, #AdditiveArithmetic."+=" : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %11
75
+ // CHECK: %10 = metatype $@thick X.Type // user: %11
76
+ // CHECK: %11 = apply %9<X>(%8, %6, %10) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
77
+ // CHECK: %12 = load [take] %1 : $*Y // users: {{.*}}
78
+ // CHECK: destroy_addr %6 : $*X // id: %13
79
+ // CHECK: dealloc_stack %6 : $*X // id: %14
80
+ // CHECK: dealloc_stack %1 : $*Y // id: %15
81
+ // CHECK: %16 = copy_value %12 : $Y // user: %18
82
+ // CHECK: destroy_value %12 : $Y // id: %17
83
+ // CHECK: return %16 : $Y // id: %18
84
+ // CHECK: } // end sil function '$function_with_struct_extract_1TJpSpSr'
81
85
82
86
//===----------------------------------------------------------------------===//
83
87
// Pullback generation - `tuple_extract`
@@ -94,27 +98,30 @@ bb0(%0 : $(Float, Float)):
94
98
return %1 : $Float
95
99
}
96
100
97
- // CHECK-LABEL: [ORIG] %1 = tuple_extract %0 : $(Float, Float), 0 // user: %2
98
- // CHECK: [ADJ] Emitted in pullback (pb bb0):
99
- // CHECK: %1 = alloc_stack $(Float, Float) // users: {{.*}}
100
- // CHECK: %2 = tuple_element_addr %1 : $*(Float, Float), 0 // user: %5
101
- // CHECK: %3 = witness_method $Float, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %5
102
- // CHECK: %4 = metatype $@thick Float.Type // user: %5
103
- // CHECK: %5 = apply %3<Float>(%2, %4) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
104
- // CHECK: %6 = tuple_element_addr %1 : $*(Float, Float), 1 // user: %9
105
- // CHECK: %7 = witness_method $Float, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %9
106
- // CHECK: %8 = metatype $@thick Float.Type // user: %9
107
- // CHECK: %9 = apply %7<Float>(%6, %8) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
108
- // CHECK: %10 = alloc_stack $Float // users: {{.*}}
109
- // CHECK: store %0 to [trivial] %10 : $*Float // id: %11
110
- // CHECK: %12 = tuple_element_addr %1 : $*(Float, Float), 0 // user: %15
111
- // CHECK: %13 = witness_method $Float, #AdditiveArithmetic."+=" : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %15
112
- // CHECK: %14 = metatype $@thick Float.Type // user: %15
113
- // CHECK: %15 = apply %13<Float>(%12, %10, %14) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
114
- // CHECK: %16 = load [trivial] %1 : $*(Float, Float)
115
- // CHECK: destroy_addr %10 : $*Float // id: %17
116
- // CHECK: dealloc_stack %10 : $*Float // id: %18
117
- // CHECK: dealloc_stack %1 : $*(Float, Float) // id: %19
101
+
102
+ // CHECK-LABEL: sil private [ossa] @function_with_tuple_extract_1TJpSpSr : $@convention(thin) (Float) -> (Float, Float) {
103
+ // CHECK: bb0(%0 : $Float):
104
+ // CHECK: %1 = alloc_stack $(Float, Float) // users: {{.*}}
105
+ // CHECK: %2 = tuple_element_addr %1 : $*(Float, Float), 0 // user: %5
106
+ // CHECK: %3 = witness_method $Float, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %5
107
+ // CHECK: %4 = metatype $@thick Float.Type // user: %5
108
+ // CHECK: %5 = apply %3<Float>(%2, %4) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
109
+ // CHECK: %6 = tuple_element_addr %1 : $*(Float, Float), 1 // user: %9
110
+ // CHECK: %7 = witness_method $Float, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %9
111
+ // CHECK: %8 = metatype $@thick Float.Type // user: %9
112
+ // CHECK: %9 = apply %7<Float>(%6, %8) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
113
+ // CHECK: %10 = alloc_stack $Float // users: {{.*}}
114
+ // CHECK: store %0 to [trivial] %10 : $*Float // id: %11
115
+ // CHECK: %12 = tuple_element_addr %1 : $*(Float, Float), 0 // user: %15
116
+ // CHECK: %13 = witness_method $Float, #AdditiveArithmetic."+=" : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %15
117
+ // CHECK: %14 = metatype $@thick Float.Type // user: %15
118
+ // CHECK: %15 = apply %13<Float>(%12, %10, %14) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
119
+ // CHECK: %16 = load [trivial] %1 : $*(Float, Float) // user: %20
120
+ // CHECK: destroy_addr %10 : $*Float // id: %17
121
+ // CHECK: dealloc_stack %10 : $*Float // id: %18
122
+ // CHECK: dealloc_stack %1 : $*(Float, Float) // id: %19
123
+ // CHECK: return %16 : $(Float, Float) // id: %20
124
+ // CHECK: } // end sil function 'function_with_tuple_extract_1TJpSpSr'
118
125
119
126
//===----------------------------------------------------------------------===//
120
127
// Pullback generation - `tuple_extract`
@@ -131,25 +138,30 @@ bb0(%0 : @guaranteed $(X, X)):
131
138
return %2 : $X
132
139
}
133
140
134
- // CHECK-LABEL: [ORIG] %1 = tuple_extract %0 : $(X, X), 0 // user: %2
135
- // CHECK: [ADJ] Emitted in pullback (pb bb0):
136
- // CHECK: %1 = alloc_stack $(X, X) // users: {{.*}}
137
- // CHECK: %2 = tuple_element_addr %1 : $*(X, X), 0 // user: %5
138
- // CHECK: %3 = witness_method $X, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %5
139
- // CHECK: %4 = metatype $@thick X.Type // user: %5
140
- // CHECK: %5 = apply %3<X>(%2, %4) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
141
- // CHECK: %6 = tuple_element_addr %1 : $*(X, X), 1 // user: %9
142
- // CHECK: %7 = witness_method $X, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %9
143
- // CHECK: %8 = metatype $@thick X.Type // user: %9
144
- // CHECK: %9 = apply %7<X>(%6, %8) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
145
- // CHECK: %10 = copy_value %0 : $X // user: %12
146
- // CHECK: %11 = alloc_stack $X // users: {{.*}}
147
- // CHECK: store %10 to [init] %11 : $*X // id: %12
148
- // CHECK: %13 = tuple_element_addr %1 : $*(X, X), 0 // user: %16
149
- // CHECK: %14 = witness_method $X, #AdditiveArithmetic."+=" : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %16
150
- // CHECK: %15 = metatype $@thick X.Type // user: %16
151
- // CHECK: %16 = apply %14<X>(%13, %11, %15) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
152
- // CHECK: %17 = load [take] %1 : $*(X, X)
153
- // CHECK: destroy_addr %11 : $*X // id: %18
154
- // CHECK: dealloc_stack %11 : $*X // id: %19
155
- // CHECK: dealloc_stack %1 : $*(X, X) // id: %20
141
+ // CHECK-LABEL: sil private [ossa] @function_with_tuple_extract_2TJpSpSr : $@convention(thin) (@guaranteed X) -> @owned (X, X) {
142
+ // CHECK: bb0(%0 : @guaranteed $X):
143
+ // CHECK: %1 = alloc_stack $(X, X) // users: {{.*}}
144
+ // CHECK: %2 = tuple_element_addr %1 : $*(X, X), 0 // user: %5
145
+ // CHECK: %3 = witness_method $X, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %5
146
+ // CHECK: %4 = metatype $@thick X.Type // user: %5
147
+ // CHECK: %5 = apply %3<X>(%2, %4) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
148
+ // CHECK: %6 = tuple_element_addr %1 : $*(X, X), 1 // user: %9
149
+ // CHECK: %7 = witness_method $X, #AdditiveArithmetic.zero!getter : <Self where Self : AdditiveArithmetic> (Self.Type) -> () -> Self : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0 // user: %9
150
+ // CHECK: %8 = metatype $@thick X.Type // user: %9
151
+ // CHECK: %9 = apply %7<X>(%6, %8) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@thick τ_0_0.Type) -> @out τ_0_0
152
+ // CHECK: %10 = copy_value %0 : $X // user: %12
153
+ // CHECK: %11 = alloc_stack $X // users: {{.*}}
154
+ // CHECK: store %10 to [init] %11 : $*X // id: %12
155
+ // CHECK: %13 = tuple_element_addr %1 : $*(X, X), 0 // user: %16
156
+ // CHECK: %14 = witness_method $X, #AdditiveArithmetic."+=" : <Self where Self : AdditiveArithmetic> (Self.Type) -> (inout Self, Self) -> () : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> () // user: %16
157
+ // CHECK: %15 = metatype $@thick X.Type // user: %16
158
+ // CHECK: %16 = apply %14<X>(%13, %11, %15) : $@convention(witness_method: AdditiveArithmetic) <τ_0_0 where τ_0_0 : AdditiveArithmetic> (@inout τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> ()
159
+ // CHECK: %17 = load [take] %1 : $*(X, X) // users: {{.*}}
160
+ // CHECK: destroy_addr %11 : $*X // id: %18
161
+ // CHECK: dealloc_stack %11 : $*X // id: %19
162
+ // CHECK: dealloc_stack %1 : $*(X, X) // id: %20
163
+ // CHECK: %21 = copy_value %17 : $(X, X) // user: %23
164
+ // CHECK: destroy_value %17 : $(X, X) // id: %22
165
+ // CHECK: return %21 : $(X, X) // id: %23
166
+ // CHECK: } // end sil function 'function_with_tuple_extract_2TJpSpSr'
167
+
0 commit comments