@@ -1535,46 +1535,45 @@ class PullbackCloner::Implementation final
1535
1535
builder.emitZeroIntoBuffer (cai->getLoc (), adjDest, IsNotInitialization);
1536
1536
}
1537
1537
1538
- // / Handle `copy_value` instruction.
1538
+ // / Handle any ownership instruction that deals with values: copy_value,
1539
+ // / move_value, begin_borrow.
1539
1540
// / Original: y = copy_value x
1540
1541
// / Adjoint: adj[x] += adj[y]
1541
- void visitCopyValueInst (CopyValueInst *cvi) {
1542
- auto *bb = cvi->getParent ();
1543
- switch (getTangentValueCategory (cvi)) {
1542
+ void visitValueOwnershipInst (SingleValueInstruction *svi) {
1543
+ assert (svi->getNumOperands () == 1 );
1544
+ auto *bb = svi->getParent ();
1545
+ switch (getTangentValueCategory (svi)) {
1544
1546
case SILValueCategory::Object: {
1545
- auto adj = getAdjointValue (bb, cvi );
1546
- addAdjointValue (bb, cvi ->getOperand (), adj, cvi ->getLoc ());
1547
+ auto adj = getAdjointValue (bb, svi );
1548
+ addAdjointValue (bb, svi ->getOperand (0 ), adj, svi ->getLoc ());
1547
1549
break ;
1548
1550
}
1549
1551
case SILValueCategory::Address: {
1550
- auto adjDest = getAdjointBuffer (bb, cvi );
1551
- addToAdjointBuffer (bb, cvi ->getOperand (), adjDest, cvi ->getLoc ());
1552
- builder.emitZeroIntoBuffer (cvi ->getLoc (), adjDest, IsNotInitialization);
1552
+ auto adjDest = getAdjointBuffer (bb, svi );
1553
+ addToAdjointBuffer (bb, svi ->getOperand (0 ), adjDest, svi ->getLoc ());
1554
+ builder.emitZeroIntoBuffer (svi ->getLoc (), adjDest, IsNotInitialization);
1553
1555
break ;
1554
1556
}
1555
1557
}
1556
1558
}
1557
1559
1560
+ // / Handle `copy_value` instruction.
1561
+ // / Original: y = copy_value x
1562
+ // / Adjoint: adj[x] += adj[y]
1563
+ void visitCopyValueInst (CopyValueInst *cvi) { visitValueOwnershipInst (cvi); }
1564
+
1558
1565
// / Handle `begin_borrow` instruction.
1559
1566
// / Original: y = begin_borrow x
1560
1567
// / Adjoint: adj[x] += adj[y]
1561
1568
void visitBeginBorrowInst (BeginBorrowInst *bbi) {
1562
- auto *bb = bbi->getParent ();
1563
- switch (getTangentValueCategory (bbi)) {
1564
- case SILValueCategory::Object: {
1565
- auto adj = getAdjointValue (bb, bbi);
1566
- addAdjointValue (bb, bbi->getOperand (), adj, bbi->getLoc ());
1567
- break ;
1568
- }
1569
- case SILValueCategory::Address: {
1570
- auto adjDest = getAdjointBuffer (bb, bbi);
1571
- addToAdjointBuffer (bb, bbi->getOperand (), adjDest, bbi->getLoc ());
1572
- builder.emitZeroIntoBuffer (bbi->getLoc (), adjDest, IsNotInitialization);
1573
- break ;
1574
- }
1575
- }
1569
+ visitValueOwnershipInst (bbi);
1576
1570
}
1577
1571
1572
+ // / Handle `move_value` instruction.
1573
+ // / Original: y = move_value x
1574
+ // / Adjoint: adj[x] += adj[y]
1575
+ void visitMoveValueInst (MoveValueInst *mvi) { visitValueOwnershipInst (mvi); }
1576
+
1578
1577
// / Handle `begin_access` instruction.
1579
1578
// / Original: y = begin_access x
1580
1579
// / Adjoint: nothing
0 commit comments