Skip to content

Commit 2085f9b

Browse files
committed
[arc] Wire up ProgramTerminationAnalysis into SILCodeMotion.
1 parent ff3df20 commit 2085f9b

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

lib/SILPasses/Scalar/SILCodeMotion.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/SILAnalysis/AliasAnalysis.h"
2525
#include "swift/SILAnalysis/PostOrderAnalysis.h"
2626
#include "swift/SILAnalysis/RCIdentityAnalysis.h"
27+
#include "swift/SILAnalysis/ProgramTerminationAnalysis.h"
2728
#include "swift/SILPasses/Transforms.h"
2829
#include "swift/SILPasses/Utils/Local.h"
2930
#include "llvm/ADT/Optional.h"
@@ -806,9 +807,9 @@ static bool tryToSinkRefCountAcrossSelectEnum(CondBranchInst *CondBr,
806807

807808
static bool tryToSinkRefCountInst(SILBasicBlock::iterator T,
808809
SILBasicBlock::iterator I,
809-
bool CanSinkToSuccessors,
810-
AliasAnalysis *AA,
811-
RCIdentityFunctionInfo *RCIA) {
810+
bool CanSinkToSuccessors, AliasAnalysis *AA,
811+
RCIdentityFunctionInfo *RCIA,
812+
ProgramTerminationFunctionInfo *PTFI) {
812813
// The following methods should only be attempted if we can sink to our
813814
// successor.
814815
if (CanSinkToSuccessors) {
@@ -856,7 +857,7 @@ static bool tryToSinkRefCountInst(SILBasicBlock::iterator T,
856857
for (auto &Succ : T->getParent()->getSuccessors()) {
857858
SILBasicBlock *SuccBB = Succ.getBB();
858859

859-
if (isARCInertTrapBB(SuccBB))
860+
if (PTFI->isProgramTerminatingBlock(SuccBB))
860861
continue;
861862

862863
Builder.setInsertionPoint(&*SuccBB->begin());
@@ -985,7 +986,8 @@ static bool hoistDecrementsToPredecessors(SILBasicBlock *BB, AliasAnalysis *AA,
985986
/// Try sink a retain as far as possible. This is either to sucessor BBs,
986987
/// or as far down the current BB as possible
987988
static bool sinkRefCountIncrement(SILBasicBlock *BB, AliasAnalysis *AA,
988-
RCIdentityFunctionInfo *RCIA) {
989+
RCIdentityFunctionInfo *RCIA,
990+
ProgramTerminationFunctionInfo *PTFI) {
989991

990992
// Make sure that each one of our successors only has one predecessor,
991993
// us.
@@ -1019,12 +1021,12 @@ static bool sinkRefCountIncrement(SILBasicBlock *BB, AliasAnalysis *AA,
10191021
// 2. If there are such decrements, move the retain right before that
10201022
// decrement.
10211023
Changed |= tryToSinkRefCountInst(S->getIterator(), Inst->getIterator(),
1022-
CanSinkToSuccessor, AA, RCIA);
1024+
CanSinkToSuccessor, AA, RCIA, PTFI);
10231025
}
10241026

10251027
// 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);
10281030
return Changed;
10291031
}
10301032

@@ -1669,7 +1671,9 @@ sinkIncrementsOutOfSwitchRegions(AliasAnalysis *AA,
16691671

16701672
static bool processFunction(SILFunction *F, AliasAnalysis *AA,
16711673
PostOrderFunctionInfo *PO,
1672-
RCIdentityFunctionInfo *RCIA, bool HoistReleases) {
1674+
RCIdentityFunctionInfo *RCIA,
1675+
ProgramTerminationFunctionInfo *PTFI,
1676+
bool HoistReleases) {
16731677

16741678
bool Changed = false;
16751679

@@ -1720,7 +1724,7 @@ static bool processFunction(SILFunction *F, AliasAnalysis *AA,
17201724
Changed |= State.process();
17211725

17221726
// 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);
17241728

17251729
// And hoist decrements to predecessors. This is beneficial if we can then
17261730
// match them up with an increment in some of the predecessors.
@@ -1745,11 +1749,12 @@ class SILCodeMotion : public SILFunctionTransform {
17451749
auto *AA = getAnalysis<AliasAnalysis>();
17461750
auto *PO = getAnalysis<PostOrderAnalysis>()->get(F);
17471751
auto *RCIA = getAnalysis<RCIdentityAnalysis>()->get(getFunction());
1752+
auto *PTFI = getAnalysis<ProgramTerminationAnalysis>()->get(getFunction());
17481753

17491754
DEBUG(llvm::dbgs() << "***** CodeMotion on function: " << F->getName() <<
17501755
" *****\n");
17511756

1752-
if (processFunction(F, AA, PO, RCIA, HoistReleases))
1757+
if (processFunction(F, AA, PO, RCIA, PTFI, HoistReleases))
17531758
invalidateAnalysis(SILAnalysis::InvalidationKind::Instructions);
17541759
}
17551760

0 commit comments

Comments
 (0)