File: differentiability_witness_function_inst.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 (108 lines) | stat: -rw-r--r-- 7,668 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
// Round-trip parsing/printing test.

// RUN: %target-sil-opt %s | %FileCheck %s

// Round-trip serialization-deserialization test.

// 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 %s

// IRGen test.

// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=Simplification -emit-ir %s | %FileCheck %s --check-prefix=IRGEN --check-prefix %target-cpu
// NOTE: `%target-cpu`-specific FileCheck lines exist because lowered function types in LLVM IR differ between architectures.

// `shell` is required only to run `sed` as a
// https://github.com/apple/swift/issues/54526 workaround.
// REQUIRES: shell

sil_stage raw

import Swift
import Builtin

import _Differentiation

sil_differentiability_witness [reverse] [parameters 0] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float

sil_differentiability_witness [reverse] [parameters 0 1] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float

sil_differentiability_witness [reverse] [parameters 0] [results 0] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)

sil_differentiability_witness [reverse] [parameters 0 1] [results 0 1] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)

sil_differentiability_witness [reverse] [parameters 0] [results 0] <T where T : Differentiable> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T

sil_differentiability_witness [reverse] [parameters 0 1] [results 0] <T where T : Differentiable> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T

sil_differentiability_witness [reverse] [parameters 0 1] [results 0] <T where T : Differentiable, T == T.TangentVector> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T

sil_differentiability_witness [reverse] [parameters 0 1] [results 0] <T where T : Differentiable, T: AdditiveArithmetic> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T

sil @foo : $@convention(thin) (Float, Float, Float) -> Float

sil @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)

sil @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T

sil @genericreq : $@convention(thin) <T : FloatingPoint> (@in_guaranteed T, Float) -> @out T

sil @test_derivative_witnesses : $@convention(thin) () -> () {
bb0:
  %foo_jvp_wrt_0 = differentiability_witness_function [jvp] [reverse] [parameters 0] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float
  %foo_vjp_wrt_0_1 = differentiability_witness_function [vjp] [reverse] [parameters 0 1] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float

  // Test multiple results.
  %bar_jvp_wrt_0_results_0 = differentiability_witness_function [jvp] [reverse] [parameters 0] [results 0] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)
  %bar_vjp_wrt_0_1_results_0_1 = differentiability_witness_function [vjp] [reverse] [parameters 0 1] [results 0 1] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)

  // Test generic requirements.
  %generic_jvp_wrt_0 = differentiability_witness_function [jvp] [reverse] [parameters 0] [results 0] <T : Differentiable> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T
  %generic_vjp_wrt_0_1 = differentiability_witness_function [vjp] [reverse] [parameters 0 1] [results 0] <T : Differentiable & AdditiveArithmetic> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T

  // Test "dependent" generic requirements: `T == T.TangentVector` depends on `T: Differentiable`.
  %generic_vjp_wrt_0_1_dependent_req = differentiability_witness_function [vjp] [reverse] [parameters 0 1] [results 0] <T where T: Differentiable, T == T.TangentVector> @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T

  return undef : $()
}

// CHECK-LABEL: sil @test_derivative_witnesses : $@convention(thin) () -> () {
// CHECK: bb0:
// CHECK:   {{%.*}} = differentiability_witness_function [jvp] [reverse] [parameters 0] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float
// CHECK:   {{%.*}} = differentiability_witness_function [vjp] [reverse] [parameters 0 1] [results 0] @foo : $@convention(thin) (Float, Float, Float) -> Float
// CHECK:   {{%.*}} = differentiability_witness_function [jvp] [reverse] [parameters 0] [results 0] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)
// CHECK:   {{%.*}} = differentiability_witness_function [vjp] [reverse] [parameters 0 1] [results 0 1] @bar : $@convention(thin) (Float, Float, Float) -> (Float, Float)
// CHECK:   {{%.*}} = differentiability_witness_function [jvp] [reverse] [parameters 0] [results 0] <τ_0_0 where τ_0_0 : Differentiable> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0
// CHECK:   {{%.*}} = differentiability_witness_function [vjp] [reverse] [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : AdditiveArithmetic, τ_0_0 : Differentiable> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0
// CHECK:   {{%.*}} = differentiability_witness_function [vjp] [reverse] [parameters 0 1] [results 0] <τ_0_0 where τ_0_0 : Differentiable, τ_0_0 == τ_0_0.TangentVector> @generic : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0, Float) -> @out τ_0_0
// CHECK: }

// IRGEN: @fooWJrSUUpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT:[0-9]+]]
// IRGEN: @fooWJrSSUpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT]]
// IRGEN: @barWJrSUUpSUr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT]]
// IRGEN: @barWJrSSUpSSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT]]
// IRGEN: @generic16_Differentiation14DifferentiableRzlWJrSUpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT]]
// IRGEN: @generics18AdditiveArithmeticRz16_Differentiation14DifferentiableRzlWJrSSpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT]]
// IRGEN: @generic16_Differentiation14DifferentiableRz13TangentVector{{.*}}WJrSSpSr = external global %swift.differentiability_witness, align [[PTR_ALIGNMENT]]

// IRGEN-LABEL: define {{.*}} @test_derivative_witnesses()

// IRGEN: [[PTR1:%.*]] = load ptr, ptr @fooWJrSUUpSr, align [[PTR_ALIGNMENT]]

// IRGEN: [[PTR2:%.*]] = load ptr, ptr getelementptr inbounds (%swift.differentiability_witness, ptr @fooWJrSSUpSr, i32 0, i32 1), align [[PTR_ALIGNMENT]]

// IRGEN: [[PTR3:%.*]] = load ptr, ptr @barWJrSUUpSUr, align [[PTR_ALIGNMENT]]

// IRGEN: [[PTR4:%.*]] = load ptr, ptr getelementptr inbounds (%swift.differentiability_witness, ptr @barWJrSSUpSSr, i32 0, i32 1), align [[PTR_ALIGNMENT]]

// IRGEN: [[PTR5:%.*]] = load ptr, ptr @generic16_Differentiation14DifferentiableRzlWJrSUpSr, align [[PTR_ALIGNMENT]]

// IRGEN: [[PTR6:%.*]] = load ptr, ptr getelementptr inbounds (%swift.differentiability_witness, ptr @generics18AdditiveArithmeticRz16_Differentiation14DifferentiableRzlWJrSSpSr, i32 0, i32 1), align [[PTR_ALIGNMENT]]

// IRGEN: [[PTR7:%.*]] = load ptr, ptr getelementptr inbounds (%swift.differentiability_witness, ptr @generic16_Differentiation14DifferentiableRz13TangentVector{{.*}}WJrSSpSr, i32 0, i32 1), align [[PTR_ALIGNMENT]]