24
24
#include " swift/SILAnalysis/AliasAnalysis.h"
25
25
#include " swift/SILAnalysis/PostOrderAnalysis.h"
26
26
#include " swift/SILAnalysis/RCIdentityAnalysis.h"
27
+ #include " swift/SILAnalysis/ProgramTerminationAnalysis.h"
27
28
#include " swift/SILPasses/Transforms.h"
28
29
#include " swift/SILPasses/Utils/Local.h"
29
30
#include " llvm/ADT/Optional.h"
@@ -806,9 +807,9 @@ static bool tryToSinkRefCountAcrossSelectEnum(CondBranchInst *CondBr,
806
807
807
808
static bool tryToSinkRefCountInst (SILBasicBlock::iterator T,
808
809
SILBasicBlock::iterator I,
809
- bool CanSinkToSuccessors,
810
- AliasAnalysis *AA ,
811
- RCIdentityFunctionInfo *RCIA ) {
810
+ bool CanSinkToSuccessors, AliasAnalysis *AA,
811
+ RCIdentityFunctionInfo *RCIA ,
812
+ ProgramTerminationFunctionInfo *PTFI ) {
812
813
// The following methods should only be attempted if we can sink to our
813
814
// successor.
814
815
if (CanSinkToSuccessors) {
@@ -856,7 +857,7 @@ static bool tryToSinkRefCountInst(SILBasicBlock::iterator T,
856
857
for (auto &Succ : T->getParent ()->getSuccessors ()) {
857
858
SILBasicBlock *SuccBB = Succ.getBB ();
858
859
859
- if (isARCInertTrapBB (SuccBB))
860
+ if (PTFI-> isProgramTerminatingBlock (SuccBB))
860
861
continue ;
861
862
862
863
Builder.setInsertionPoint (&*SuccBB->begin ());
@@ -985,7 +986,8 @@ static bool hoistDecrementsToPredecessors(SILBasicBlock *BB, AliasAnalysis *AA,
985
986
// / Try sink a retain as far as possible. This is either to sucessor BBs,
986
987
// / or as far down the current BB as possible
987
988
static bool sinkRefCountIncrement (SILBasicBlock *BB, AliasAnalysis *AA,
988
- RCIdentityFunctionInfo *RCIA) {
989
+ RCIdentityFunctionInfo *RCIA,
990
+ ProgramTerminationFunctionInfo *PTFI) {
989
991
990
992
// Make sure that each one of our successors only has one predecessor,
991
993
// us.
@@ -1019,12 +1021,12 @@ static bool sinkRefCountIncrement(SILBasicBlock *BB, AliasAnalysis *AA,
1019
1021
// 2. If there are such decrements, move the retain right before that
1020
1022
// decrement.
1021
1023
Changed |= tryToSinkRefCountInst (S->getIterator (), Inst->getIterator (),
1022
- CanSinkToSuccessor, AA, RCIA);
1024
+ CanSinkToSuccessor, AA, RCIA, PTFI );
1023
1025
}
1024
1026
1025
1027
// Handle the first instruction in the BB.
1026
- Changed |=
1027
- tryToSinkRefCountInst (S-> getIterator (), SI, CanSinkToSuccessor, AA, RCIA);
1028
+ Changed |= tryToSinkRefCountInst (S-> getIterator (), SI, CanSinkToSuccessor, AA,
1029
+ RCIA, PTFI );
1028
1030
return Changed;
1029
1031
}
1030
1032
@@ -1669,7 +1671,9 @@ sinkIncrementsOutOfSwitchRegions(AliasAnalysis *AA,
1669
1671
1670
1672
static bool processFunction (SILFunction *F, AliasAnalysis *AA,
1671
1673
PostOrderFunctionInfo *PO,
1672
- RCIdentityFunctionInfo *RCIA, bool HoistReleases) {
1674
+ RCIdentityFunctionInfo *RCIA,
1675
+ ProgramTerminationFunctionInfo *PTFI,
1676
+ bool HoistReleases) {
1673
1677
1674
1678
bool Changed = false ;
1675
1679
@@ -1720,7 +1724,7 @@ static bool processFunction(SILFunction *F, AliasAnalysis *AA,
1720
1724
Changed |= State.process ();
1721
1725
1722
1726
// Finally we try to sink retain instructions from this BB to the next BB.
1723
- Changed |= sinkRefCountIncrement (State.getBB (), AA, RCIA);
1727
+ Changed |= sinkRefCountIncrement (State.getBB (), AA, RCIA, PTFI );
1724
1728
1725
1729
// And hoist decrements to predecessors. This is beneficial if we can then
1726
1730
// match them up with an increment in some of the predecessors.
@@ -1745,11 +1749,12 @@ class SILCodeMotion : public SILFunctionTransform {
1745
1749
auto *AA = getAnalysis<AliasAnalysis>();
1746
1750
auto *PO = getAnalysis<PostOrderAnalysis>()->get (F);
1747
1751
auto *RCIA = getAnalysis<RCIdentityAnalysis>()->get (getFunction ());
1752
+ auto *PTFI = getAnalysis<ProgramTerminationAnalysis>()->get (getFunction ());
1748
1753
1749
1754
DEBUG (llvm::dbgs () << " ***** CodeMotion on function: " << F->getName () <<
1750
1755
" *****\n " );
1751
1756
1752
- if (processFunction (F, AA, PO, RCIA, HoistReleases))
1757
+ if (processFunction (F, AA, PO, RCIA, PTFI, HoistReleases))
1753
1758
invalidateAnalysis (SILAnalysis::InvalidationKind::Instructions);
1754
1759
}
1755
1760
0 commit comments