@@ -213,15 +213,6 @@ class CanonicalizeOSSALifetime final {
213213 // / copies.
214214 bool maximizeLifetime;
215215
216- // / If true and we are processing a value of move_only type, emit a diagnostic
217- // / when-ever we need to insert a copy_value.
218- std::function<void (Operand *)> moveOnlyCopyValueNotification;
219-
220- // / If true and we are processing a value of move_only type, pass back to the
221- // / caller any consuming uses that are going to be used as part of the final
222- // / lifetime boundary in case we need to emit diagnostics.
223- std::function<void (Operand *)> moveOnlyFinalConsumingUse;
224-
225216 // If present, will be used to ensure that the lifetime is not shortened to
226217 // end inside an access scope which it previously enclosed. (Note that ending
227218 // before such an access scope is fine regardless.)
@@ -289,27 +280,10 @@ class CanonicalizeOSSALifetime final {
289280 }
290281 }
291282
292- void maybeNotifyMoveOnlyCopy (Operand *use) {
293- if (!moveOnlyCopyValueNotification)
294- return ;
295- moveOnlyCopyValueNotification (use);
296- }
297-
298- void maybeNotifyFinalConsumingUse (Operand *use) {
299- if (!moveOnlyFinalConsumingUse)
300- return ;
301- moveOnlyFinalConsumingUse (use);
302- }
303-
304- CanonicalizeOSSALifetime (
305- bool pruneDebugMode, bool maximizeLifetime,
306- NonLocalAccessBlockAnalysis *accessBlockAnalysis, DominanceInfo *domTree,
307- InstructionDeleter &deleter,
308- std::function<void (Operand *)> moveOnlyCopyValueNotification = nullptr ,
309- std::function<void (Operand *)> moveOnlyFinalConsumingUse = nullptr )
283+ CanonicalizeOSSALifetime (bool pruneDebugMode, bool maximizeLifetime,
284+ NonLocalAccessBlockAnalysis *accessBlockAnalysis,
285+ DominanceInfo *domTree, InstructionDeleter &deleter)
310286 : pruneDebugMode(pruneDebugMode), maximizeLifetime(maximizeLifetime),
311- moveOnlyCopyValueNotification (moveOnlyCopyValueNotification),
312- moveOnlyFinalConsumingUse(moveOnlyFinalConsumingUse),
313287 accessBlockAnalysis (accessBlockAnalysis), domTree(domTree),
314288 deleter(deleter),
315289 liveness(maximizeLifetime ? &discoveredBlocks : nullptr ) {}
@@ -348,8 +322,52 @@ class CanonicalizeOSSALifetime final {
348322 // / operands.
349323 bool canonicalizeValueLifetime (SILValue def);
350324
325+ // / Compute the liveness information for \p def. But do not do any rewriting
326+ // / or computation of boundaries.
327+ // /
328+ // / The intention is that this is used if one wants to emit diagnostics using
329+ // / the liveness information before doing any rewriting.
330+ bool computeLiveness (SILValue def);
331+
332+ // / Given the already computed liveness boundary for the given def, rewrite
333+ // / copies of def as appropriate.
334+ // /
335+ // / NOTE: It is assumed that one passes the extended boundary from \see
336+ // / computeLiveness.
337+ // /
338+ // / NOTE: It is assumed that one has emitted any diagnostics.
339+ void rewriteLifetimes ();
340+
341+ // / Return the pure original boundary just based off of liveness information
342+ // / without maximizing or extending liveness.
343+ void findOriginalBoundary (PrunedLivenessBoundary &resultingOriginalBoundary);
344+
351345 InstModCallbacks &getCallbacks () { return deleter.getCallbacks (); }
352346
347+ using IsInterestingUser = PrunedLiveness::IsInterestingUser;
348+
349+ // / Helper method that returns the isInterestingUser status of \p user in the
350+ // / passed in Liveness.
351+ // /
352+ // / NOTE: Only call this after calling computeLivenessBoundary or the results
353+ // / will not be initialized.
354+ IsInterestingUser isInterestingUser (SILInstruction *user) const {
355+ return liveness.isInterestingUser (user);
356+ }
357+
358+ using LifetimeEndingUserRange = PrunedLiveness::LifetimeEndingUserRange;
359+ LifetimeEndingUserRange getLifetimeEndingUsers () const {
360+ return liveness.getLifetimeEndingUsers ();
361+ }
362+
363+ using NonLifetimeEndingUserRange = PrunedLiveness::NonLifetimeEndingUserRange;
364+ NonLifetimeEndingUserRange getNonLifetimeEndingUsers () const {
365+ return liveness.getNonLifetimeEndingUsers ();
366+ }
367+
368+ using UserRange = PrunedLiveness::ConstUserRange;
369+ UserRange getUsers () const { return liveness.getAllUsers (); }
370+
353371private:
354372 void recordDebugValue (DebugValueInst *dvi) { debugValues.insert (dvi); }
355373
@@ -362,8 +380,6 @@ class CanonicalizeOSSALifetime final {
362380
363381 void extendLivenessThroughOverlappingAccess ();
364382
365- void findOriginalBoundary (PrunedLivenessBoundary &boundary);
366-
367383 void findExtendedBoundary (PrunedLivenessBoundary const &originalBoundary,
368384 PrunedLivenessBoundary &boundary);
369385
0 commit comments