@@ -530,9 +530,6 @@ void SILPassManager::runPassOnFunction(unsigned TransIdx, SILFunction *F) {
530
530
forcePrecomputeAnalyses (F);
531
531
}
532
532
533
- assert (changeNotifications == SILAnalysis::InvalidationKind::Nothing
534
- && " change notifications not cleared" );
535
-
536
533
llvm::sys::TimePoint<> startTime = std::chrono::system_clock::now ();
537
534
std::chrono::nanoseconds duration (0 );
538
535
@@ -553,24 +550,21 @@ void SILPassManager::runPassOnFunction(unsigned TransIdx, SILFunction *F) {
553
550
// Run it!
554
551
SFT->run ();
555
552
556
- if (CurrentPassHasInvalidated ||
557
- changeNotifications != SILAnalysis::InvalidationKind::Nothing) {
553
+ swiftPassInvocation.finishedFunctionPassRun ();
554
+
555
+ if (CurrentPassHasInvalidated) {
558
556
// Pause time measurement while invalidating analysis and restoring the snapshot.
559
557
duration += (std::chrono::system_clock::now () - startTime);
560
558
561
559
if (runIdx < numRepeats - 1 ) {
562
560
invalidateAnalysis (F, SILAnalysis::InvalidationKind::Everything);
563
561
F->restoreFromSnapshot (SnapshotID);
564
- } else if (changeNotifications != SILAnalysis::InvalidationKind::Nothing) {
565
- invalidateAnalysis (F, changeNotifications);
566
562
}
567
- changeNotifications = SILAnalysis::InvalidationKind::Nothing;
568
563
569
564
// Continue time measurement (including flushing deleted instructions).
570
565
startTime = std::chrono::system_clock::now ();
571
566
}
572
567
Mod->flushDeletedInsts ();
573
- swiftPassInvocation.finishedFunctionPassRun ();
574
568
}
575
569
576
570
duration += (std::chrono::system_clock::now () - startTime);
@@ -1289,9 +1283,9 @@ void SwiftPassInvocation::startModulePassRun(SILModuleTransform *transform) {
1289
1283
}
1290
1284
1291
1285
void SwiftPassInvocation::startFunctionPassRun (SILFunctionTransform *transform) {
1292
- assert (!this ->function && !this ->transform && " a pass is already running" );
1293
- this ->function = transform->getFunction ();
1286
+ assert (!this ->transform && " a pass is already running" );
1294
1287
this ->transform = transform;
1288
+ beginTransformFunction (transform->getFunction ());
1295
1289
}
1296
1290
1297
1291
void SwiftPassInvocation::startInstructionPassRun (SILInstruction *inst) {
@@ -1302,13 +1296,15 @@ void SwiftPassInvocation::startInstructionPassRun(SILInstruction *inst) {
1302
1296
void SwiftPassInvocation::finishedModulePassRun () {
1303
1297
endPassRunChecks ();
1304
1298
assert (!function && transform && " not running a pass" );
1299
+ assert (changeNotifications == SILAnalysis::InvalidationKind::Nothing
1300
+ && " unhandled change notifications at end of module pass" );
1305
1301
transform = nullptr ;
1306
1302
}
1307
1303
1308
1304
void SwiftPassInvocation::finishedFunctionPassRun () {
1309
1305
endPassRunChecks ();
1310
- assert (function && transform && " not running a pass " );
1311
- function = nullptr ;
1306
+ endTransformFunction ( );
1307
+ assert (allocatedSlabs. empty () && " StackList is leaking slabs " ) ;
1312
1308
transform = nullptr ;
1313
1309
}
1314
1310
@@ -1322,6 +1318,24 @@ void SwiftPassInvocation::endPassRunChecks() {
1322
1318
assert (numNodeSetsAllocated == 0 && " Not all NodeSets deallocated" );
1323
1319
}
1324
1320
1321
+ void SwiftPassInvocation::beginTransformFunction (SILFunction *function) {
1322
+ assert (!this ->function && transform && " not running a pass" );
1323
+ assert (changeNotifications == SILAnalysis::InvalidationKind::Nothing
1324
+ && " change notifications not cleared" );
1325
+ this ->function = function;
1326
+ }
1327
+
1328
+ void SwiftPassInvocation::endTransformFunction () {
1329
+ assert (function && transform && " not running a pass" );
1330
+ if (changeNotifications != SILAnalysis::InvalidationKind::Nothing) {
1331
+ passManager->invalidateAnalysis (function, changeNotifications);
1332
+ changeNotifications = SILAnalysis::InvalidationKind::Nothing;
1333
+ }
1334
+ function = nullptr ;
1335
+ assert (numBlockSetsAllocated == 0 && " Not all BasicBlockSets deallocated" );
1336
+ assert (numNodeSetsAllocated == 0 && " Not all NodeSets deallocated" );
1337
+ }
1338
+
1325
1339
// ===----------------------------------------------------------------------===//
1326
1340
// Swift Bridging
1327
1341
// ===----------------------------------------------------------------------===//
0 commit comments