You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[AutoDiff] Move Differentiation before OwnershipModelEliminator. (swiftlang#26157)
Moves Differentiation before OwnershipModelEliminator. Now Differentiation happens right after DefiniteInitialization.
## Changes
### Activity analysis
* Propagate usefulness and variedness through `store_borrow` instructions.
* Fix a bug where standard usefulness does not get propagated if the instruction goes through the `mayReadFromMemory()` case. Remove special handling `mayReadFromMemory()` and propagate usefulness through all buffer operands instead.
* Handle `destructure_tuple` instead of `tuple_extract` in array literal initialization pattern matcher.
### `autodiff_function` canonicalization
* Rewrite argument cloning logic as `copyParameterArgumentsForApply`, used in `reapplyFunctionConversions` and the curry thunk cloning logic in `ADContext::promoteToDifferentiableFunction`.
### VJPEmitter
* Each `@guaranteed` trampoline argument needs to have a lifetime-ending use past its destination argument's lifetime-ending uses, so we keep track of these pairs of arguments in `trampolinedGuaranteedPhiArguments` and emit `end_borrow`s when function cloning is finished.
* Create trampoline blocks for `cond_br` instructions to conform to ownership rules.
### PullbackEmitter
* Make pullback struct arguments have `@owned` ownership, for both function arguments and phi arguments.
* Make all other phi arguments also have `@owned` ownership.
* Note: Linear maps get evaluated linearly, so all values should get consumed immediately when a pullback is called. This is not the case yet since pullback functions have `@guaranteed` arguments. We should change this in the future so that all calls to pullbacks consume their arguments. ([TF-761](https://bugs.swift.org/browse/TF-761))
* Emit a `switch_enum` even if there is only one successor. It no longer triggers any verification failure.
• Remove the [TF-585](https://bugs.swift.org/browse/TF-585) workaround (emitting a `fix_lifetime` on boxed enums) since the crasher in AllocBoxToStack is no longer reproducible.
* Handle `destructure_tuple` instead of `tuple_extract` in array literal initialization adjoint emission logic.
* Add pullback emission visitors for `destructure_tuple`, `load_borrow`, `store_borrow`, `copy_value`, and `begin_borrow`.
Resolves [TF-709](https://bugs.swift.org/browse/TF-709) and [TF-585](https://bugs.swift.org/browse/TF-585). Also improves some source locations in diagnostics since the differentiation transform runs on a higher-level IR.
0 commit comments