@@ -540,11 +540,9 @@ bool PullbackEmitter::runForSemanticMemberGetter() {
540
540
auto *accessor = cast<AccessorDecl>(original.getDeclContext ()->getAsDecl ());
541
541
assert (accessor->getAccessorKind () == AccessorKind::Get);
542
542
543
- auto origExitIt = original.findReturnBB ();
544
- assert (origExitIt != original.end () &&
545
- " Functions without returns must have been diagnosed" );
546
- auto *origExit = &*origExitIt;
547
- builder.setInsertionPoint (pullback.getEntryBlock ());
543
+ auto *origEntry = original.getEntryBlock ();
544
+ auto *pbEntry = pullback.getEntryBlock ();
545
+ builder.setInsertionPoint (pbEntry);
548
546
549
547
// Get getter argument and result values.
550
548
// Getter type: $(Self) -> Result
@@ -582,10 +580,10 @@ bool PullbackEmitter::runForSemanticMemberGetter() {
582
580
// TODO(TF-1255): Simplify using unified adjoint value data structure.
583
581
switch (tangentVectorSILTy.getCategory ()) {
584
582
case SILValueCategory::Object: {
585
- auto adjResult = getAdjointValue (origExit , origResult);
583
+ auto adjResult = getAdjointValue (origEntry , origResult);
586
584
switch (adjResult.getKind ()) {
587
585
case AdjointValueKind::Zero:
588
- addAdjointValue (origExit , origSelf,
586
+ addAdjointValue (origEntry , origSelf,
589
587
makeZeroAdjointValue (tangentVectorSILTy), pbLoc);
590
588
break ;
591
589
case AdjointValueKind::Concrete:
@@ -603,7 +601,7 @@ bool PullbackEmitter::runForSemanticMemberGetter() {
603
601
eltVals.push_back (makeZeroAdjointValue (fieldSILTy));
604
602
}
605
603
}
606
- addAdjointValue (origExit , origSelf,
604
+ addAdjointValue (origEntry , origSelf,
607
605
makeAggregateAdjointValue (tangentVectorSILTy, eltVals),
608
606
pbLoc);
609
607
}
@@ -615,22 +613,24 @@ bool PullbackEmitter::runForSemanticMemberGetter() {
615
613
auto pbIndRes = pullback.getIndirectResults ().front ();
616
614
auto *adjSelf = createFunctionLocalAllocation (
617
615
pbIndRes->getType ().getObjectType (), pbLoc);
618
- setAdjointBuffer (origExit , origSelf, adjSelf);
616
+ setAdjointBuffer (origEntry , origSelf, adjSelf);
619
617
for (auto *field : tangentVectorDecl->getStoredProperties ()) {
620
618
auto *adjSelfElt = builder.createStructElementAddr (pbLoc, adjSelf, field);
621
619
if (field == tanField) {
622
620
// Switch based on the property's value category.
623
621
// TODO(TF-1255): Simplify using unified adjoint value data structure.
624
622
switch (origResult->getType ().getCategory ()) {
625
623
case SILValueCategory::Object: {
626
- auto adjResult = getAdjointValue (origExit , origResult);
624
+ auto adjResult = getAdjointValue (origEntry , origResult);
627
625
auto adjResultValue = materializeAdjointDirect (adjResult, pbLoc);
628
- builder.emitStoreValueOperation (pbLoc, adjResultValue, adjSelfElt,
626
+ auto adjResultValueCopy =
627
+ builder.emitCopyValueOperation (pbLoc, adjResultValue);
628
+ builder.emitStoreValueOperation (pbLoc, adjResultValueCopy, adjSelfElt,
629
629
StoreOwnershipQualifier::Init);
630
630
break ;
631
631
}
632
632
case SILValueCategory::Address: {
633
- auto adjResult = getAdjointBuffer (origExit , origResult);
633
+ auto adjResult = getAdjointBuffer (origEntry , origResult);
634
634
builder.createCopyAddr (pbLoc, adjResult, adjSelfElt, IsTake,
635
635
IsInitialization);
636
636
destroyedLocalAllocations.insert (adjResult);
@@ -657,8 +657,9 @@ bool PullbackEmitter::runForSemanticMemberSetter() {
657
657
auto *accessor = cast<AccessorDecl>(original.getDeclContext ()->getAsDecl ());
658
658
assert (accessor->getAccessorKind () == AccessorKind::Set);
659
659
660
- auto origEntry = original.getEntryBlock ();
661
- builder.setInsertionPoint (pullback.getEntryBlock ());
660
+ auto *origEntry = original.getEntryBlock ();
661
+ auto *pbEntry = pullback.getEntryBlock ();
662
+ builder.setInsertionPoint (pbEntry);
662
663
663
664
// Get setter argument values.
664
665
// Setter type: $(inout Self, Argument) -> ()
@@ -703,6 +704,7 @@ bool PullbackEmitter::runForSemanticMemberSetter() {
703
704
auto adjArg = builder.emitLoadValueOperation (pbLoc, adjSelfElt,
704
705
LoadOwnershipQualifier::Take);
705
706
setAdjointValue (origEntry, origArg, makeConcreteAdjointValue (adjArg));
707
+ blockTemporaries[pbEntry].insert (adjArg);
706
708
break ;
707
709
}
708
710
case SILValueCategory::Address: {
0 commit comments