|
43 | 43 | /// return sin(x)
|
44 | 44 | /// }
|
45 | 45 | ///
|
46 |
| -/// //============== Before optimization ==============// |
| 46 | +/// //============== Before closure specialization ==============// |
47 | 47 | /// // VJP of `foo`. Returns the original result and the Pullback of `foo`.
|
48 | 48 | /// sil @vjp_foo: $(Float) -> (originalResult: Float, pullback: (Float) -> Float) {
|
49 | 49 | /// bb0(%0: $Float):
|
50 |
| -/// // vjp_sin returns the original result `sin(x)`, and the pullback of sin, `pb_sin`. |
51 |
| -/// // `pb_sin` is a closure. |
52 |
| -/// %(originalResult, pb_sin) = apply @vjp_sin(%0): $(Float) -> (Float, (Float) -> Float) |
53 |
| -/// |
| 50 | +/// // __Inlined__ `vjp_sin`: It is important for all intermediate VJPs to have |
| 51 | +/// // been inlined in `vjp_foo`, otherwise `vjp_foo` will not be able to determine |
| 52 | +/// // that `pb_foo` is closing over other closures and no specialization will happen. |
| 53 | +/// \ |
| 54 | +/// %originalResult = apply @sin(%0): $(Float) -> Float \__ Inlined `vjp_sin` |
| 55 | +/// %partially_applied_pb_sin = partial_apply pb_sin(%0): $(Float) -> Float / |
| 56 | +/// / |
| 57 | +/// |
54 | 58 | /// %pb_foo = function_ref @pb_foo: $@convention(thin) (Float, (Float) -> Float) -> Float
|
55 |
| -/// %partially_applied_pb_foo = partial_apply %pb_foo(%pb_sin): $(Float, (Float) -> Float) -> Float |
| 59 | +/// %partially_applied_pb_foo = partial_apply %pb_foo(%partially_applied_pb_sin): $(Float, (Float) -> Float) -> Float |
56 | 60 | ///
|
57 | 61 | /// return (%originalResult, %partially_applied_pb_foo)
|
58 | 62 | /// }
|
|
72 | 76 | /// return %derivative_of_sin: Float
|
73 | 77 | /// }
|
74 | 78 | ///
|
75 |
| -/// //============== After optimization ==============// |
| 79 | +/// //============== After closure specialization ==============// |
76 | 80 | /// sil @vjp_foo: $(Float) -> (originalResult: Float, pullback: (Float) -> Float) {
|
77 | 81 | /// bb0(%0: $Float):
|
78 |
| -/// %1 = apply @sin(%0): $(Float) -> Float |
| 82 | +/// %originalResult = apply @sin(%0): $(Float) -> Float |
79 | 83 | ///
|
80 | 84 | /// // Before the optimization, pullback of `foo` used to take a closure for computing
|
81 | 85 | /// // pullback of `sin`. Now, the specialized pullback of `foo` takes the arguments that
|
|
84 | 88 | /// %specialized_pb_foo = function_ref @specialized_pb_foo: $@convention(thin) (Float, Float) -> Float
|
85 | 89 | /// %partially_applied_pb_foo = partial_apply %specialized_pb_foo(%0): $(Float, Float) -> Float
|
86 | 90 | ///
|
87 |
| -/// return (%1, %partially_applied_pb_foo) |
| 91 | +/// return (%originalResult, %partially_applied_pb_foo) |
88 | 92 | /// }
|
89 | 93 | ///
|
90 | 94 | /// sil @specialized_pb_foo: $(Float, Float) -> Float {
|
@@ -384,8 +388,8 @@ private func handleApplies(for rootClosure: SingleValueInstruction, callSiteMap:
|
384 | 388 | continue
|
385 | 389 | }
|
386 | 390 |
|
387 |
| - // If the callee uses a dynamic Self, we cannot specialize it, since the resulting specialization might longer have |
388 |
| - // 'self' as the last parameter. |
| 391 | + // If the callee uses a dynamic Self, we cannot specialize it, since the resulting specialization might no longer |
| 392 | + // have 'self' as the last parameter. |
389 | 393 | //
|
390 | 394 | // TODO: We could fix this by inserting new arguments more carefully, or changing how we model dynamic Self
|
391 | 395 | // altogether.
|
|
0 commit comments