@@ -657,15 +657,23 @@ class ReleaseBlockState : public BlockState {
657
657
658
658
// / ReleaseCodeMotionContext - Context to perform release code motion.
659
659
class 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.
661
663
BasicBlockData<ReleaseBlockState> BlockStates;
662
664
665
+ InstructionSet releaseInstructions;
666
+
663
667
// / We are not moving epilogue releases.
664
668
bool FreezeEpilogueReleases;
665
669
666
670
// / The epilogue release matcher we are currently using.
667
671
ConsumedArgToEpilogueReleaseMatcher &ERM;
668
672
673
+ bool isRelease (SILInstruction *inst) const {
674
+ return releaseInstructions.contains (inst);
675
+ }
676
+
669
677
// / Return true if the instruction blocks the Ptr to be moved further.
670
678
bool mayBlockCodeMotion (SILInstruction *II, SILValue Ptr) override {
671
679
// NOTE: If more checks are to be added, place the most expensive in the end.
@@ -677,7 +685,7 @@ class ReleaseCodeMotionContext : public CodeMotionContext {
677
685
return true ;
678
686
// Identical RC root blocks code motion, we will be able to move this release
679
687
// further once we move the blocking release.
680
- if (isReleaseInstruction (II) && getRCRoot (II) == Ptr) {
688
+ if (isRelease (II) && getRCRoot (II) == Ptr) {
681
689
LLVM_DEBUG (if (printCtx) llvm::dbgs ()
682
690
<< " Release " << Ptr << " at matching release " << *II);
683
691
return true ;
@@ -698,19 +706,23 @@ class ReleaseCodeMotionContext : public CodeMotionContext {
698
706
if (&*I->getParent ()->begin () == I)
699
707
return nullptr ;
700
708
auto Prev = &*std::prev (SILBasicBlock::iterator (I));
701
- if (isReleaseInstruction (Prev) && getRCRoot (Prev) == Root)
709
+ if (isRelease (Prev) && getRCRoot (Prev) == Root)
702
710
return Prev;
703
711
return nullptr ;
704
712
}
705
713
706
714
public:
707
715
// / Constructor.
708
- ReleaseCodeMotionContext (llvm::SpecificBumpPtrAllocator<BlockState> &BPA,
716
+ ReleaseCodeMotionContext (SILFunctionTransform *parentTransform,
717
+ llvm::SpecificBumpPtrAllocator<BlockState> &BPA,
709
718
SILFunction *F, PostOrderFunctionInfo *PO,
710
719
AliasAnalysis *AA, RCIdentityFunctionInfo *RCFI,
711
720
bool FreezeEpilogueReleases,
712
721
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),
714
726
FreezeEpilogueReleases(FreezeEpilogueReleases), ERM(ERM) {}
715
727
716
728
// / virtual destructor.
@@ -781,6 +793,9 @@ void ReleaseCodeMotionContext::initializeCodeMotionDataFlow() {
781
793
// Do not try to enumerate if we are not hoisting epilogue releases.
782
794
if (FreezeEpilogueReleases && ERM.isEpilogueRelease (&II))
783
795
continue ;
796
+ if (!parentTransform->continueWithNextSubpassRun (&II))
797
+ continue ;
798
+ releaseInstructions.insert (&II);
784
799
SILValue Root = getRCRoot (&II);
785
800
RCInstructions.insert (&II);
786
801
if (RCRootIndex.find (Root) != RCRootIndex.end ())
@@ -831,7 +846,7 @@ void ReleaseCodeMotionContext::initializeCodeMotionBBMaxSet() {
831
846
// NOTE: this is a conservative approximation, because some releases may be
832
847
// blocked before it reaches this block.
833
848
for (auto II = BB->rbegin (), IE = BB->rend (); II != IE; ++II) {
834
- if (!isReleaseInstruction (&*II))
849
+ if (!isRelease (&*II))
835
850
continue ;
836
851
State.BBMaxSet .set (RCRootIndex[getRCRoot (&*II)]);
837
852
}
@@ -859,7 +874,7 @@ void ReleaseCodeMotionContext::computeCodeMotionGenKillSet() {
859
874
continue ;
860
875
861
876
// If this is a release instruction, it also generates.
862
- if (isReleaseInstruction (&*I)) {
877
+ if (isRelease (&*I)) {
863
878
unsigned idx = RCRootIndex[getRCRoot (&*I)];
864
879
State.BBGenSet .set (idx);
865
880
assert (State.BBKillSet .test (idx) && " Killset computed incorrectly" );
@@ -1049,7 +1064,7 @@ void ReleaseCodeMotionContext::computeCodeMotionInsertPoints() {
1049
1064
continue ;
1050
1065
1051
1066
// This release generates.
1052
- if (isReleaseInstruction (&*I)) {
1067
+ if (isRelease (&*I)) {
1053
1068
S.BBSetOut .set (RCRootIndex[getRCRoot (&*I)]);
1054
1069
}
1055
1070
}
@@ -1201,7 +1216,7 @@ class ARCCodeMotion : public SILFunctionTransform {
1201
1216
Conv,
1202
1217
ConsumedArgToEpilogueReleaseMatcher::ExitKind::Return);
1203
1218
1204
- ReleaseCodeMotionContext RelCM (BPA, F, PO, AA, RCFI,
1219
+ ReleaseCodeMotionContext RelCM (this , BPA, F, PO, AA, RCFI,
1205
1220
FreezeEpilogueReleases, ERM);
1206
1221
// Run release hoisting.
1207
1222
InstChanged |= RelCM.run ();
0 commit comments