@@ -134,6 +134,12 @@ class ConsumedResultToEpilogueRetainMatcher {
134
134
// and handle exploded retain_value later.
135
135
RetainList EpilogueRetainInsts;
136
136
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);
137
143
public:
138
144
// / Finds matching releases in the return block of the function \p F.
139
145
ConsumedResultToEpilogueRetainMatcher (RCIdentityFunctionInfo *RCFI,
@@ -165,11 +171,6 @@ class ConsumedResultToEpilogueRetainMatcher {
165
171
unsigned size () const { return EpilogueRetainInsts.size (); }
166
172
167
173
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);
173
174
};
174
175
175
176
// / A class that attempts to match owned arguments and corresponding epilogue
@@ -197,8 +198,17 @@ class ConsumedArgToEpilogueReleaseMatcher {
197
198
bool isRedundantRelease (ReleaseList Insts, SILValue Base, SILValue Derived);
198
199
199
200
// / 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 ();
202
212
203
213
public:
204
214
// / Finds matching releases in the return block of the function \p F.
@@ -211,11 +221,17 @@ class ConsumedArgToEpilogueReleaseMatcher {
211
221
212
222
bool hasBlock () const { return HasBlock; }
213
223
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
+
214
230
SILInstruction *getSingleReleaseForArgument (SILArgument *Arg) {
215
231
auto I = ArgInstMap.find (Arg);
216
232
if (I == ArgInstMap.end ())
217
233
return nullptr ;
218
- if (I-> second . size () > 1 )
234
+ if (! isSingleRelease (Arg) )
219
235
return nullptr ;
220
236
return *I->second .begin ();
221
237
}
0 commit comments