Skip to content

Commit 7ff5156

Browse files
committed
Merge pull request swiftlang#1827 from trentxintong/FSO
Minor refactor in Epilogue Retain/Release matchers
2 parents c41ec5b + 9a020c8 commit 7ff5156

File tree

2 files changed

+166
-110
lines changed

2 files changed

+166
-110
lines changed

include/swift/SILOptimizer/Analysis/ARCAnalysis.h

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ class ConsumedResultToEpilogueRetainMatcher {
134134
// and handle exploded retain_value later.
135135
RetainList EpilogueRetainInsts;
136136

137+
/// Return true if all the successors of the EpilogueRetainInsts do not have
138+
/// a retain.
139+
bool isTransistiveSuccessorsRetainFree(llvm::DenseSet<SILBasicBlock *> BBs);
140+
141+
/// Finds matching releases in the provided block \p BB.
142+
RetainKindValue findMatchingRetainsInBasicBlock(SILBasicBlock *BB, SILValue V);
137143
public:
138144
/// Finds matching releases in the return block of the function \p F.
139145
ConsumedResultToEpilogueRetainMatcher(RCIdentityFunctionInfo *RCFI,
@@ -165,11 +171,6 @@ class ConsumedResultToEpilogueRetainMatcher {
165171
unsigned size() const { return EpilogueRetainInsts.size(); }
166172

167173
iterator_range<iterator> getRange() { return swift::make_range(begin(), end()); }
168-
169-
170-
private:
171-
/// Finds matching releases in the provided block \p BB.
172-
RetainKindValue findMatchingRetainsInner(SILBasicBlock *BB, SILValue V);
173174
};
174175

175176
/// A class that attempts to match owned arguments and corresponding epilogue
@@ -197,8 +198,17 @@ class ConsumedArgToEpilogueReleaseMatcher {
197198
bool isRedundantRelease(ReleaseList Insts, SILValue Base, SILValue Derived);
198199

199200
/// Return true if we have a release instruction for all the reference
200-
/// semantics part of \p Base.
201-
bool releaseAllNonTrivials(ReleaseList Insts, SILValue Base);
201+
/// semantics part of \p Argument.
202+
bool releaseArgument(ReleaseList Insts, SILValue Argument);
203+
204+
/// Walk the basic block and find all the releases that match to function
205+
/// arguments.
206+
void collectMatchingReleases(SILBasicBlock *BB);
207+
208+
/// For every argument in the function, check to see whether all epilogue
209+
/// releases are found. Clear all releases for the argument if not all
210+
/// epilogue releases are found.
211+
void processMatchingReleases();
202212

203213
public:
204214
/// Finds matching releases in the return block of the function \p F.
@@ -211,11 +221,17 @@ class ConsumedArgToEpilogueReleaseMatcher {
211221

212222
bool hasBlock() const { return HasBlock; }
213223

224+
bool isSingleRelease(SILArgument *Arg) const {
225+
auto Iter = ArgInstMap.find(Arg);
226+
assert(Iter != ArgInstMap.end() && "Failed to get release list for argument");
227+
return Iter->second.size() == 1;
228+
}
229+
214230
SILInstruction *getSingleReleaseForArgument(SILArgument *Arg) {
215231
auto I = ArgInstMap.find(Arg);
216232
if (I == ArgInstMap.end())
217233
return nullptr;
218-
if (I->second.size() > 1)
234+
if (!isSingleRelease(Arg))
219235
return nullptr;
220236
return *I->second.begin();
221237
}

0 commit comments

Comments
 (0)