@@ -987,131 +987,6 @@ findMatchingReleases(SILBasicBlock *BB) {
987
987
processMatchingReleases ();
988
988
}
989
989
990
- // ===----------------------------------------------------------------------===//
991
- // Code for Determining Final Releases
992
- // ===----------------------------------------------------------------------===//
993
-
994
- // Propagate liveness backwards from an initial set of blocks in our
995
- // LiveIn set.
996
- static void propagateLiveness (llvm::SmallPtrSetImpl<SILBasicBlock *> &LiveIn,
997
- SILBasicBlock *DefBB) {
998
- // First populate a worklist of predecessors.
999
- llvm::SmallVector<SILBasicBlock *, 64 > Worklist;
1000
- for (auto *BB : LiveIn)
1001
- for (auto Pred : BB->getPredecessorBlocks ())
1002
- Worklist.push_back (Pred);
1003
-
1004
- // Now propagate liveness backwards until we hit the alloc_box.
1005
- while (!Worklist.empty ()) {
1006
- auto *BB = Worklist.pop_back_val ();
1007
-
1008
- // If it's already in the set, then we've already queued and/or
1009
- // processed the predecessors.
1010
- if (BB == DefBB || !LiveIn.insert (BB).second )
1011
- continue ;
1012
-
1013
- for (auto Pred : BB->getPredecessorBlocks ())
1014
- Worklist.push_back (Pred);
1015
- }
1016
- }
1017
-
1018
- // Is any successor of BB in the LiveIn set?
1019
- static bool successorHasLiveIn (SILBasicBlock *BB,
1020
- llvm::SmallPtrSetImpl<SILBasicBlock *> &LiveIn) {
1021
- for (auto &Succ : BB->getSuccessors ())
1022
- if (LiveIn.count (Succ))
1023
- return true ;
1024
-
1025
- return false ;
1026
- }
1027
-
1028
- // Walk backwards in BB looking for the last use of a given
1029
- // value, and add it to the set of release points.
1030
- static bool addLastUse (SILValue V, SILBasicBlock *BB,
1031
- ReleaseTracker &Tracker) {
1032
- for (auto I = BB->rbegin (); I != BB->rend (); ++I) {
1033
- if (Tracker.isUser (&*I)) {
1034
- Tracker.trackLastRelease (&*I);
1035
- return true ;
1036
- }
1037
- }
1038
-
1039
- llvm_unreachable (" BB is expected to have a use of a closure" );
1040
- return false ;
1041
- }
1042
-
1043
- // / TODO: Refactor this code so the decision on whether or not to accept an
1044
- // / instruction.
1045
- bool swift::getFinalReleasesForValue (SILValue V, ReleaseTracker &Tracker) {
1046
- llvm::SmallPtrSet<SILBasicBlock *, 16 > LiveIn;
1047
- llvm::SmallPtrSet<SILBasicBlock *, 16 > UseBlocks;
1048
-
1049
- // First attempt to get the BB where this value resides.
1050
- auto *DefBB = V->getParentBlock ();
1051
- if (!DefBB)
1052
- return false ;
1053
-
1054
- bool seenRelease = false ;
1055
- SILInstruction *OneRelease = nullptr ;
1056
-
1057
- // We'll treat this like a liveness problem where the value is the def. Each
1058
- // block that has a use of the value has the value live-in unless it is the
1059
- // block with the value.
1060
- SmallVector<Operand *, 8 > Uses (V->getUses ());
1061
- while (!Uses.empty ()) {
1062
- auto *Use = Uses.pop_back_val ();
1063
- auto *User = Use->getUser ();
1064
- auto *BB = User->getParent ();
1065
-
1066
- if (Tracker.isUserTransitive (User)) {
1067
- Tracker.trackUser (User);
1068
- auto *CastInst = cast<SingleValueInstruction>(User);
1069
- Uses.append (CastInst->getUses ().begin (), CastInst->getUses ().end ());
1070
- continue ;
1071
- }
1072
-
1073
- if (!Tracker.isUserAcceptable (User))
1074
- return false ;
1075
-
1076
- Tracker.trackUser (User);
1077
-
1078
- if (BB != DefBB)
1079
- LiveIn.insert (BB);
1080
-
1081
- // Also keep track of the blocks with uses.
1082
- UseBlocks.insert (BB);
1083
-
1084
- // Try to speed up the trivial case of single release/dealloc.
1085
- if (isa<StrongReleaseInst>(User) || isa<DeallocBoxInst>(User) ||
1086
- isa<DestroyValueInst>(User) || isa<ReleaseValueInst>(User)) {
1087
- if (!seenRelease)
1088
- OneRelease = User;
1089
- else
1090
- OneRelease = nullptr ;
1091
-
1092
- seenRelease = true ;
1093
- }
1094
- }
1095
-
1096
- // Only a single release/dealloc? We're done!
1097
- if (OneRelease) {
1098
- Tracker.trackLastRelease (OneRelease);
1099
- return true ;
1100
- }
1101
-
1102
- propagateLiveness (LiveIn, DefBB);
1103
-
1104
- // Now examine each block we saw a use in. If it has no successors
1105
- // that are in LiveIn, then the last use in the block is the final
1106
- // release/dealloc.
1107
- for (auto *BB : UseBlocks)
1108
- if (!successorHasLiveIn (BB, LiveIn))
1109
- if (!addLastUse (V, BB, Tracker))
1110
- return false ;
1111
-
1112
- return true ;
1113
- }
1114
-
1115
990
// ===----------------------------------------------------------------------===//
1116
991
// Leaking BB Analysis
1117
992
// ===----------------------------------------------------------------------===//
0 commit comments