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
|
// Test round-trip parsing/printing.
// RUN: %target-sil-opt %s | %target-sil-opt -emit-sorted-sil | %FileCheck --check-prefix=ROUNDTRIP %s
// Test round-trip serialization/deserialization.
// RUN: %empty-directory(%t)
// RUN: %target-sil-opt %s -emit-sib -o %t/tmp.sib -module-name main
// RUN: %target-sil-opt %t/tmp.sib -o %t/tmp.sil -module-name main
// https://github.com/apple/swift/issues/54526
// Workaround because import declarations are not preserved in .sib files.
// RUN: sed -e 's/import Swift$/import Swift; import _Differentiation/' %t/tmp.sil > %t/tmp_fixed.sil
// RUN: %target-sil-opt %t/tmp_fixed.sil -module-name main -emit-sorted-sil | %FileCheck --check-prefix=ROUNDTRIP %s
// IRGen test.
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck --check-prefix=IRGEN %s
// `shell` is required only to run `sed` as a
// https://github.com/apple/swift/issues/54526 workaround.
// REQUIRES: shell
sil_stage raw
import Builtin
import Swift
import SwiftShims
import _Differentiation
// Test SIL differentiability witness for bodiless original function, with defined jvp/vjp.
sil @externalFn1 : $@convention(thin) (Float) -> Float
sil @AD__externalFn1__jvp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) {
bb0(%0 : $Float):
return undef : $(Float, @callee_guaranteed (Float) -> Float)
}
sil @AD__externalFn1__vjp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) {
bb0(%0 : $Float):
return undef : $(Float, @callee_guaranteed (Float) -> Float)
}
sil_differentiability_witness [reverse] [parameters 0] [results 0] @externalFn1 : $@convention(thin) (Float) -> Float {
jvp: @AD__externalFn1__jvp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
vjp: @AD__externalFn1__vjp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
}
// ROUNDTRIP-LABEL: // differentiability witness for externalFn1
// ROUNDTRIP: sil_differentiability_witness{{( public_external)?}} [reverse] [parameters 0] [results 0] @externalFn1 : $@convention(thin) (Float) -> Float {
// ROUNDTRIP: jvp: @AD__externalFn1__jvp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
// ROUNDTRIP: vjp: @AD__externalFn1__vjp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
// ROUNDTRIP: }
// IRGEN-LABEL: @externalFn1WJrSpSr ={{( protected)?}} global { ptr, ptr } {
// IRGEN-SAME: @AD__externalFn1__jvp_src_0_wrt_0
// IRGEN-SAME: @AD__externalFn1__vjp_src_0_wrt_0
// IRGEN-SAME: }
// Test SIL differentiability witness for bodiless original function, with bodiless jvp/vjp.
sil @externalFn2 : $@convention(thin) (Float) -> Float
sil @AD__externalFn2__jvp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
sil @AD__externalFn2__vjp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
sil_differentiability_witness [reverse] [parameters 0] [results 0] @externalFn2 : $@convention(thin) (Float) -> Float {
jvp: @AD__externalFn2__jvp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
vjp: @AD__externalFn2__vjp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
}
// ROUNDTRIP-LABEL: // differentiability witness for externalFn2
// ROUNDTRIP: sil_differentiability_witness{{( public_external)?}} [reverse] [parameters 0] [results 0] @externalFn2 : $@convention(thin) (Float) -> Float {
// ROUNDTRIP: jvp: @AD__externalFn2__jvp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
// ROUNDTRIP: vjp: @AD__externalFn2__vjp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
// ROUNDTRIP: }
// IRGEN-LABEL: @externalFn2WJrSpSr ={{( protected)?}} global { ptr, ptr } {
// IRGEN-SAME: @AD__externalFn2__jvp_src_0_wrt_0
// IRGEN-SAME: @AD__externalFn2__vjp_src_0_wrt_0
// IRGEN-SAME: }
// Test SIL differentiability witness declaration.
sil @externalFn3 : $@convention(thin) (Float) -> Float
sil_differentiability_witness [reverse] [parameters 0] [results 0] @externalFn3 : $@convention(thin) (Float) -> Float
// ROUNDTRIP-LABEL: // differentiability witness for externalFn3
// ROUNDTRIP: sil_differentiability_witness{{( public_external)?}} [reverse] [parameters 0] [results 0] @externalFn3 : $@convention(thin) (Float) -> Float{{[^{]*$}}
// IRGEN-NOT: @AD__externalFn3{{.*}}={{.*}}{ ptr, ptr }
// Test public non-generic function.
// SIL differentiability witness:
// - Has public linkage (implicit).
// - Has no `where` clause.
sil [ossa] @foo : $@convention(thin) (Float) -> Float {
bb0(%0 : $Float):
return %0 : $Float
}
sil @AD__foo__jvp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) {
bb0(%0 : $Float):
return undef : $(Float, @callee_guaranteed (Float) -> Float)
}
sil @AD__foo__vjp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) {
bb0(%0 : $Float):
return undef : $(Float, @callee_guaranteed (Float) -> Float)
}
sil_differentiability_witness [reverse] [parameters 0] [results 0] @foo : $@convention(thin) (Float) -> Float {
jvp: @AD__foo__jvp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
vjp: @AD__foo__vjp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
}
// ROUNDTRIP-LABEL: // differentiability witness for foo
// ROUNDTRIP: sil_differentiability_witness{{( public_external)?}} [reverse] [parameters 0] [results 0] @foo : $@convention(thin) (Float) -> Float {
// ROUNDTRIP: jvp: @AD__foo__jvp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
// ROUNDTRIP: vjp: @AD__foo__vjp_src_0_wrt_0 : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float)
// ROUNDTRIP: }
// IRGEN-LABEL: @fooWJrSpSr ={{( protected)?}} global { ptr, ptr } {
// IRGEN-SAME: @AD__foo__jvp_src_0_wrt_0
// IRGEN-SAME: @AD__foo__vjp_src_0_wrt_0
// IRGEN-SAME: }
// Test internal generic function.
// SIL differentiability witness:
// - Has hidden linkage.
// - Has `where` clause.
sil hidden [ossa] @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T {
bb0(%0 : $*T, %1 : $*T, %2 : $Float):
copy_addr %1 to [init] %0 : $*T
%void = tuple ()
return %void : $()
}
sil hidden @AD__generic__jvp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, Float) -> @out τ_0_0.TangentVector) {
bb0(%0 : $*τ_0_0, %1 : $*τ_0_0, %2 : $Float):
return undef : $@callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, Float) -> @out τ_0_0.TangentVector
}
sil hidden @AD__generic__vjp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, Float)) {
bb0(%0 : $*τ_0_0, %1 : $*τ_0_0, %2 : $Float):
return undef : $@callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, Float)
}
sil_differentiability_witness hidden [reverse] [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : Differentiable> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T {
jvp: @AD__generic__jvp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, Float) -> @out τ_0_0.TangentVector)
vjp: @AD__generic__vjp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, Float))
}
// ROUNDTRIP-LABEL: // differentiability witness for generic
// ROUNDTRIP: sil_differentiability_witness {{(hidden)|(hidden_external)}} [reverse] [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : Differentiable> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T {
// ROUNDTRIP: jvp: @AD__generic__jvp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector, Float) -> @out τ_0_0.TangentVector)
// ROUNDTRIP: vjp: @AD__generic__vjp_src_0_wrt_0_1 : $@convention(thin) <τ_0_0 where τ_0_0 : Differentiable> (@in_guaranteed τ_0_0, Float) -> (@out τ_0_0, @owned @callee_guaranteed (@in_guaranteed τ_0_0.TangentVector) -> (@out τ_0_0.TangentVector, Float))
// ROUNDTRIP: }
// IRGEN: @generic16_Differentiation14DifferentiableRzlWJrSSpSr = hidden global { ptr, ptr } {
// IRGEN-SAME: @AD__generic__jvp_src_0_wrt_0_1
// IRGEN-SAME: @AD__generic__vjp_src_0_wrt_0_1
// IRGEN-SAME: }
|