mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Type annotations for instruction operands are omitted, e.g. ``` %3 = struct $S(%1, %2) ``` Operand types are redundant anyway and were only used for sanity checking in the SIL parser. But: operand types _are_ printed if the definition of the operand value was not printed yet. This happens: * if the block with the definition appears after the block where the operand's instruction is located * if a block or instruction is printed in isolation, e.g. in a debugger The old behavior can be restored with `-Xllvm -sil-print-types`. This option is added to many existing test files which check for operand types in their check-lines.
38 lines
1.1 KiB
Swift
38 lines
1.1 KiB
Swift
// RUN: %target-swift-frontend -Xllvm -sil-print-types -emit-sil -verify -Xllvm -sil-print-after=differentiation -o /dev/null 2>&1 %s | %FileCheck %s -check-prefix=CHECK-SIL
|
|
|
|
import _Differentiation
|
|
|
|
struct Test: Differentiable {
|
|
var val1: Float
|
|
var val2: Float
|
|
|
|
@differentiable(reverse)
|
|
mutating func doSomething(input: Float) {
|
|
// CHECK-SIL-LABEL: TestV11doSomething5inputySf_tFTJpSSpSr :
|
|
// Ensure that only two adjoint buffers will be propagated
|
|
// CHECK-SIL: copy_addr %0 to %22 : $*Test.TangentVector
|
|
// CHECK-SIL-NEXT: debug_value
|
|
// CHECK-SIL-NEXT: copy_addr %0 to %18 : $*Test.TangentVector
|
|
// CHECK-SIL-NEXT: switch_enum %1
|
|
self.val1 *= input
|
|
self.val2 *= input
|
|
|
|
if self.val1 > input {
|
|
self.val1 = input
|
|
}
|
|
if self.val2 > input {
|
|
self.val2 = input
|
|
}
|
|
}
|
|
}
|
|
|
|
@differentiable(reverse)
|
|
func wrapper(input: Float, multiplier: Float) -> Float {
|
|
var test = Test(val1: input, val2: input)
|
|
test.doSomething(input: multiplier)
|
|
return test.val1 * test.val2
|
|
}
|
|
|
|
let grad = gradient(at: 2.0, 3.0, of: wrapper)
|
|
print("Grad: \(grad)")
|