@@ -657,15 +657,23 @@ class ReleaseBlockState : public BlockState {
657657
658658// / ReleaseCodeMotionContext - Context to perform release code motion.
659659class ReleaseCodeMotionContext : public CodeMotionContext {
660- // / All the release block state for all the basic blocks in the function.
660+ SILFunctionTransform *parentTransform;
661+
662+ // / All the release block state for all the basic blocks in the function.
661663 BasicBlockData<ReleaseBlockState> BlockStates;
662664
665+ InstructionSet releaseInstructions;
666+
663667 // / We are not moving epilogue releases.
664668 bool FreezeEpilogueReleases;
665669
666670 // / The epilogue release matcher we are currently using.
667671 ConsumedArgToEpilogueReleaseMatcher &ERM;
668672
673+ bool isRelease (SILInstruction *inst) const {
674+ return releaseInstructions.contains (inst);
675+ }
676+
669677 // / Return true if the instruction blocks the Ptr to be moved further.
670678 bool mayBlockCodeMotion (SILInstruction *II, SILValue Ptr) override {
671679 // NOTE: If more checks are to be added, place the most expensive in the end.
@@ -677,7 +685,7 @@ class ReleaseCodeMotionContext : public CodeMotionContext {
677685 return true ;
678686 // Identical RC root blocks code motion, we will be able to move this release
679687 // further once we move the blocking release.
680- if (isReleaseInstruction (II) && getRCRoot (II) == Ptr) {
688+ if (isRelease (II) && getRCRoot (II) == Ptr) {
681689 LLVM_DEBUG (if (printCtx) llvm::dbgs ()
682690 << " Release " << Ptr << " at matching release " << *II);
683691 return true ;
@@ -698,19 +706,23 @@ class ReleaseCodeMotionContext : public CodeMotionContext {
698706 if (&*I->getParent ()->begin () == I)
699707 return nullptr ;
700708 auto Prev = &*std::prev (SILBasicBlock::iterator (I));
701- if (isReleaseInstruction (Prev) && getRCRoot (Prev) == Root)
709+ if (isRelease (Prev) && getRCRoot (Prev) == Root)
702710 return Prev;
703711 return nullptr ;
704712 }
705713
706714public:
707715 // / Constructor.
708- ReleaseCodeMotionContext (llvm::SpecificBumpPtrAllocator<BlockState> &BPA,
716+ ReleaseCodeMotionContext (SILFunctionTransform *parentTransform,
717+ llvm::SpecificBumpPtrAllocator<BlockState> &BPA,
709718 SILFunction *F, PostOrderFunctionInfo *PO,
710719 AliasAnalysis *AA, RCIdentityFunctionInfo *RCFI,
711720 bool FreezeEpilogueReleases,
712721 ConsumedArgToEpilogueReleaseMatcher &ERM)
713- : CodeMotionContext(BPA, F, PO, AA, RCFI), BlockStates(F),
722+ : CodeMotionContext(BPA, F, PO, AA, RCFI),
723+ parentTransform (parentTransform),
724+ BlockStates(F),
725+ releaseInstructions(F),
714726 FreezeEpilogueReleases(FreezeEpilogueReleases), ERM(ERM) {}
715727
716728 // / virtual destructor.
@@ -781,6 +793,9 @@ void ReleaseCodeMotionContext::initializeCodeMotionDataFlow() {
781793 // Do not try to enumerate if we are not hoisting epilogue releases.
782794 if (FreezeEpilogueReleases && ERM.isEpilogueRelease (&II))
783795 continue ;
796+ if (!parentTransform->continueWithNextSubpassRun (&II))
797+ continue ;
798+ releaseInstructions.insert (&II);
784799 SILValue Root = getRCRoot (&II);
785800 RCInstructions.insert (&II);
786801 if (RCRootIndex.find (Root) != RCRootIndex.end ())
@@ -831,7 +846,7 @@ void ReleaseCodeMotionContext::initializeCodeMotionBBMaxSet() {
831846 // NOTE: this is a conservative approximation, because some releases may be
832847 // blocked before it reaches this block.
833848 for (auto II = BB->rbegin (), IE = BB->rend (); II != IE; ++II) {
834- if (!isReleaseInstruction (&*II))
849+ if (!isRelease (&*II))
835850 continue ;
836851 State.BBMaxSet .set (RCRootIndex[getRCRoot (&*II)]);
837852 }
@@ -859,7 +874,7 @@ void ReleaseCodeMotionContext::computeCodeMotionGenKillSet() {
859874 continue ;
860875
861876 // If this is a release instruction, it also generates.
862- if (isReleaseInstruction (&*I)) {
877+ if (isRelease (&*I)) {
863878 unsigned idx = RCRootIndex[getRCRoot (&*I)];
864879 State.BBGenSet .set (idx);
865880 assert (State.BBKillSet .test (idx) && " Killset computed incorrectly" );
@@ -1049,7 +1064,7 @@ void ReleaseCodeMotionContext::computeCodeMotionInsertPoints() {
10491064 continue ;
10501065
10511066 // This release generates.
1052- if (isReleaseInstruction (&*I)) {
1067+ if (isRelease (&*I)) {
10531068 S.BBSetOut .set (RCRootIndex[getRCRoot (&*I)]);
10541069 }
10551070 }
@@ -1201,7 +1216,7 @@ class ARCCodeMotion : public SILFunctionTransform {
12011216 Conv,
12021217 ConsumedArgToEpilogueReleaseMatcher::ExitKind::Return);
12031218
1204- ReleaseCodeMotionContext RelCM (BPA, F, PO, AA, RCFI,
1219+ ReleaseCodeMotionContext RelCM (this , BPA, F, PO, AA, RCFI,
12051220 FreezeEpilogueReleases, ERM);
12061221 // Run release hoisting.
12071222 InstChanged |= RelCM.run ();
0 commit comments