100
100
#include " swift/Basic/SmallPtrSetVector.h"
101
101
#include " swift/SIL/PrunedLiveness.h"
102
102
#include " swift/SIL/SILInstruction.h"
103
+ #include " swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h"
103
104
#include " swift/SILOptimizer/Analysis/DominanceAnalysis.h"
104
105
#include " swift/SILOptimizer/Analysis/NonLocalAccessBlockAnalysis.h"
105
106
#include " swift/SILOptimizer/Utils/InstructionDeleter.h"
@@ -247,6 +248,8 @@ class CanonicalizeOSSALifetime final {
247
248
// extendLivenessThroughOverlappingAccess is invoked.
248
249
NonLocalAccessBlocks *accessBlocks = nullptr ;
249
250
251
+ DeadEndBlocksAnalysis *deadEndBlocksAnalysis;
252
+
250
253
DominanceInfo *domTree = nullptr ;
251
254
252
255
BasicCalleeAnalysis *calleeAnalysis;
@@ -326,27 +329,22 @@ class CanonicalizeOSSALifetime final {
326
329
}
327
330
};
328
331
329
- CanonicalizeOSSALifetime (PruneDebugInsts_t pruneDebugMode,
330
- MaximizeLifetime_t maximizeLifetime,
331
- SILFunction *function,
332
- NonLocalAccessBlockAnalysis *accessBlockAnalysis,
333
- DominanceInfo *domTree,
334
- BasicCalleeAnalysis *calleeAnalysis,
335
- InstructionDeleter &deleter)
332
+ CanonicalizeOSSALifetime (
333
+ PruneDebugInsts_t pruneDebugMode, MaximizeLifetime_t maximizeLifetime,
334
+ SILFunction *function, NonLocalAccessBlockAnalysis *accessBlockAnalysis,
335
+ DeadEndBlocksAnalysis *deadEndBlocksAnalysis, DominanceInfo *domTree,
336
+ BasicCalleeAnalysis *calleeAnalysis, InstructionDeleter &deleter)
336
337
: pruneDebugMode(pruneDebugMode), maximizeLifetime(maximizeLifetime),
337
- accessBlockAnalysis(accessBlockAnalysis), domTree(domTree),
338
+ accessBlockAnalysis(accessBlockAnalysis),
339
+ deadEndBlocksAnalysis(deadEndBlocksAnalysis), domTree(domTree),
338
340
calleeAnalysis(calleeAnalysis), deleter(deleter) {}
339
341
340
342
SILValue getCurrentDef () const { return currentDef; }
341
343
342
344
void initializeLiveness (SILValue def,
343
345
ArrayRef<SILInstruction *> lexicalLifetimeEnds) {
344
346
assert (consumingBlocks.empty () && debugValues.empty ());
345
- // Clear the cached analysis pointer just in case the client invalidates the
346
- // analysis, freeing its memory.
347
- accessBlocks = nullptr ;
348
- consumes.clear ();
349
- destroys.clear ();
347
+ clear ();
350
348
351
349
currentDef = def;
352
350
currentLexicalLifetimeEnds = lexicalLifetimeEnds;
@@ -358,9 +356,18 @@ class CanonicalizeOSSALifetime final {
358
356
}
359
357
360
358
void clear () {
359
+ // Clear the access blocks analysis pointer in case the client invalidates
360
+ // the analysis. If the client did, the analysis will be recomputed in
361
+ // extendLivenessThroughOverlappingAccess; if it didn't, the analysis
362
+ // pointer will just be set back to its old value when the analysis' cache
363
+ // is consulted in extendLivenessThroughOverlappingAccess.
364
+ accessBlocks = nullptr ;
365
+
361
366
consumingBlocks.clear ();
362
367
debugValues.clear ();
363
368
discoveredBlocks.clear ();
369
+ consumes.clear ();
370
+ destroys.clear ();
364
371
}
365
372
366
373
// / Top-Level API: rewrites copies and destroys within \p def's extended
@@ -472,7 +479,7 @@ class CanonicalizeOSSALifetime final {
472
479
void findExtendedBoundary (PrunedLivenessBoundary const &originalBoundary,
473
480
PrunedLivenessBoundary &boundary);
474
481
475
- void findDestroysOutsideBoundary (SmallVectorImpl<SILInstruction *> &destroys );
482
+ void extendLivenessToDeadEnds ( );
476
483
void extendLivenessToDeinitBarriers ();
477
484
478
485
void extendUnconsumedLiveness (PrunedLivenessBoundary const &boundary);
@@ -481,9 +488,10 @@ class CanonicalizeOSSALifetime final {
481
488
llvm::function_ref<void (SILInstruction *, PrunedLiveness::LifetimeEnding)>
482
489
visitor);
483
490
484
- void insertDestroysOnBoundary (PrunedLivenessBoundary const &boundary);
491
+ void insertDestroysOnBoundary (PrunedLivenessBoundary const &boundary,
492
+ SmallVectorImpl<DestroyValueInst *> &destroys);
485
493
486
- void rewriteCopies ();
494
+ void rewriteCopies (SmallVectorImpl<DestroyValueInst *> const &destroys );
487
495
};
488
496
489
497
} // end namespace swift
0 commit comments