@@ -554,6 +554,18 @@ collectStackClosureLifetimeEnds(SmallVectorImpl<SILInstruction *> &lifetimeEnds,
554
554
}
555
555
}
556
556
557
+ static bool lookThroughMarkDependenceChainForValue (MarkDependenceInst *mark,
558
+ PartialApplyInst *pai) {
559
+ if (mark->getValue () == pai) {
560
+ return true ;
561
+ }
562
+ auto *markChain = dyn_cast<MarkDependenceInst>(mark->getValue ());
563
+ if (!markChain) {
564
+ return false ;
565
+ }
566
+ return lookThroughMarkDependenceChainForValue (markChain, pai);
567
+ }
568
+
557
569
// / Rewrite a partial_apply convert_escape_to_noescape sequence with a single
558
570
// / apply/try_apply user to a partial_apply [stack] terminated with a
559
571
// / dealloc_stack placed after the apply.
@@ -735,7 +747,6 @@ static SILValue tryRewriteToPartialApplyStack(
735
747
unsigned appliedArgStartIdx =
736
748
newPA->getOrigCalleeType ()->getNumParameters () - newPA->getNumArguments ();
737
749
738
- MarkDependenceInst *markDepChain = nullptr ;
739
750
for (unsigned i : indices (newPA->getArgumentOperands ())) {
740
751
auto &arg = newPA->getArgumentOperands ()[i];
741
752
SILValue copy = arg.get ();
@@ -789,31 +800,19 @@ static SILValue tryRewriteToPartialApplyStack(
789
800
// %md = mark_dependence %pai on %0
790
801
// %md2 = mark_dependence %md on %1
791
802
// to tie all of those operands together on the same partial_apply.
792
- //
793
- // FIXME: Should we not be chaining like this and just emit independent
794
- // mark_dependence?
795
- if (markDepChain && mark->getValue () == markDepChain) {
796
- markDep = mark;
797
- markDepChain = mark;
798
- continue ;
799
- }
800
803
801
- // If we're marking dependence of the current partial_apply on this
802
- // stack slot, that 's fine .
803
- if (mark-> getValue () != newPA
804
- || mark->getBase () != stack) {
804
+ // Check if we're marking dependence on this stack slot for the current
805
+ // partial_apply or it 's chain of mark_dependences .
806
+ if (! lookThroughMarkDependenceChainForValue (mark, newPA) ||
807
+ mark->getBase () != stack) {
805
808
LLVM_DEBUG (llvm::dbgs () << " -- had unexpected mark_dependence use\n " ;
806
809
use->getUser ()->print (llvm::dbgs ());
807
810
llvm::dbgs () << " \n " );
808
-
811
+ initialization = nullptr ;
809
812
break ;
810
813
}
811
814
markDep = mark;
812
815
813
- if (!markDepChain) {
814
- markDepChain = mark;
815
- }
816
-
817
816
continue ;
818
817
}
819
818
0 commit comments