forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradient_inst.sil
63 lines (53 loc) · 3.15 KB
/
gradient_inst.sil
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
// RUN: %target-sil-opt -sil-print-all %s | %FileCheck %s
sil_stage raw
import Swift
sil @foo : $@convention(thin) (Float, Float) -> Float {
bb0(%0 : @trivial $Float, %1 : @trivial $Float):
return undef : $Float
}
// CHECK-LABEL: sil @foo : $@convention(thin) (Float, Float) -> Float {
// CHECK-NEXT: bb0(%0 : @trivial $Float, %1 : @trivial $Float):
// CHECK-NEXT: return undef : $Float
// CHECK-NEXT: }
sil @dfoo : $@convention(thin) (Float, Float) -> (Float, Float) {
bb0(%0 : @trivial $Float, %1 : @trivial $Float):
%2 = function_ref @foo : $@convention(thin) (Float, Float) -> Float
%3 = gradient [source 0] [wrt 0, 1] %2 : $@convention(thin) (Float, Float) -> Float
%4 = apply %3(%0, %1) : $@convention(thin) (Float, Float) -> (Float, Float)
return %4 : $(Float, Float)
}
// CHECK-LABEL: sil @dfoo : $@convention(thin) (Float, Float) -> (Float, Float) {
// CHECK: bb0(%0 : @trivial $Float, %1 : @trivial $Float):
// CHECK: %2 = function_ref @foo : $@convention(thin) (Float, Float) -> Float
// CHECK-NEXT: %3 = gradient [source 0] [wrt 0, 1] %2 : $@convention(thin) (Float, Float) -> Float
// CHECK-NEXT: %4 = apply %3(%0, %1) : $@convention(thin) (Float, Float) -> (Float, Float)
// CHECK-NEXT: return %4 : $(Float, Float)
// CHECK-NEXT: }
sil @dfoo_seedable : $@convention(thin) (Float, Float, Float) -> (Float, Float) {
bb0(%0 : @trivial $Float, %1 : @trivial $Float, %2 : @trivial $Float):
%3 = function_ref @foo : $@convention(thin) (Float, Float) -> Float
%4 = gradient [source 0] [wrt 0, 1] [seedable] %3 : $@convention(thin) (Float, Float) -> Float
%5 = apply %4(%0, %1, %2) : $@convention(thin) (Float, Float, Float) -> (Float, Float)
return %5 : $(Float, Float)
}
// CHECK-LABEL: sil @dfoo_seedable : $@convention(thin) (Float, Float, Float) -> (Float, Float) {
// CHECK: bb0(%0 : @trivial $Float, %1 : @trivial $Float, %2 : @trivial $Float):
// CHECK: %3 = function_ref @foo : $@convention(thin) (Float, Float) -> Float
// CHECK-NEXT: %4 = gradient [source 0] [wrt 0, 1] [seedable] %3 : $@convention(thin) (Float, Float) -> Float
// CHECK-NEXT: %5 = apply %4(%0, %1, %2) : $@convention(thin) (Float, Float, Float) -> (Float, Float)
// CHECK-NEXT: return %5 : $(Float, Float)
// CHECK-NEXT: }
sil @dfoo_preserving_result : $@convention(thin) (Float, Float) -> (Float, Float, Float) {
bb0(%0 : @trivial $Float, %1 : @trivial $Float):
%2 = function_ref @foo : $@convention(thin) (Float, Float) -> Float
%3 = gradient [source 0] [wrt 0, 1] [preserving_result] %2 : $@convention(thin) (Float, Float) -> Float
%4 = apply %3(%0, %1) : $@convention(thin) (Float, Float) -> (Float, Float, Float)
return %4 : $(Float, Float, Float)
}
// CHECK_LABEL: sil @dfoo_preserving_result : $@convention(thin) (Float, Float) -> (Float, Float, Float) {
// CHECK: bb0(%0 : @trivial $Float, %1 : @trivial $Float):
// CHECK: %2 = function_ref @foo : $@convention(thin) (Float, Float) -> Float
// CHECK-NEXT: %3 = gradient [source 0] [wrt 0, 1] [preserving_result] %2 : $@convention(thin) (Float, Float) -> Float
// CHECK-NEXT: %4 = apply %3(%0, %1) : $@convention(thin) (Float, Float) -> (Float, Float, Float)
// CHECK-NEXT: return %4 : $(Float, Float, Float)
// CHECK-NEXT: }