@@ -370,7 +370,7 @@ static void prepareSILFunctionForOptimization(ModuleDecl *, SILFunction *F) {
370
370
371
371
namespace {
372
372
373
- struct OwnershipModelEliminator : SILFunctionTransform {
373
+ struct OwnershipModelEliminator : SILModuleTransform {
374
374
bool SkipTransparent;
375
375
bool SkipStdlibModule;
376
376
@@ -379,50 +379,53 @@ struct OwnershipModelEliminator : SILFunctionTransform {
379
379
380
380
void run () override {
381
381
if (DumpBefore.size ()) {
382
- getFunction ()->dump (DumpBefore.c_str ());
382
+ getModule ()->dump (DumpBefore.c_str ());
383
383
}
384
384
385
- auto *F = getFunction ();
386
- auto &Mod = getFunction ()->getModule ();
385
+ auto &Mod = *getModule ();
387
386
388
387
// If we are supposed to skip the stdlib module and we are in the stdlib
389
388
// module bail.
390
389
if (SkipStdlibModule && Mod.isStdlibModule ()) {
391
390
return ;
392
391
}
393
392
394
- if (!F->hasOwnership ())
395
- return ;
396
-
397
- // If we were asked to not strip ownership from transparent functions in
398
- // /our/ module, return.
399
- if (SkipTransparent && F->isTransparent ())
400
- return ;
401
-
402
- // Verify here to make sure ownership is correct before we strip.
403
- {
404
- // Add a pretty stack trace entry to tell users who see a verification
405
- // failure triggered by this verification check that they need to re-run
406
- // with -sil-verify-all to actually find the pass that introduced the
407
- // verification error.
408
- //
409
- // DISCUSSION: This occurs due to the crash from the verification
410
- // failure happening in the pass itself. This causes us to dump the
411
- // SILFunction and emit a msg that this pass (OME) is the culprit. This
412
- // is generally correct for most passes, but not for OME since we are
413
- // verifying before we have even modified the function to ensure that
414
- // all ownership invariants have been respected before we lower
415
- // ownership from the function.
416
- llvm::PrettyStackTraceString silVerifyAllMsgOnFailure (
417
- " Found verification error when verifying before lowering "
418
- " ownership. Please re-run with -sil-verify-all to identify the "
419
- " actual pass that introduced the verification error." );
420
- F->verify ();
421
- }
393
+ for (auto &F : Mod) {
394
+ // If F does not have ownership, skip it. We have no further work to do.
395
+ if (!F.hasOwnership ())
396
+ continue ;
397
+
398
+ // If we were asked to not strip ownership from transparent functions in
399
+ // /our/ module, continue.
400
+ if (SkipTransparent && F.isTransparent ())
401
+ continue ;
402
+
403
+ // Verify here to make sure ownership is correct before we strip.
404
+ {
405
+ // Add a pretty stack trace entry to tell users who see a verification
406
+ // failure triggered by this verification check that they need to re-run
407
+ // with -sil-verify-all to actually find the pass that introduced the
408
+ // verification error.
409
+ //
410
+ // DISCUSSION: This occurs due to the crash from the verification
411
+ // failure happening in the pass itself. This causes us to dump the
412
+ // SILFunction and emit a msg that this pass (OME) is the culprit. This
413
+ // is generally correct for most passes, but not for OME since we are
414
+ // verifying before we have even modified the function to ensure that
415
+ // all ownership invariants have been respected before we lower
416
+ // ownership from the function.
417
+ llvm::PrettyStackTraceString silVerifyAllMsgOnFailure (
418
+ " Found verification error when verifying before lowering "
419
+ " ownership. Please re-run with -sil-verify-all to identify the "
420
+ " actual pass that introduced the verification error." );
421
+ F.verify ();
422
+ }
422
423
423
- if (stripOwnership (*F)) {
424
- auto InvalidKind = SILAnalysis::InvalidationKind::BranchesAndInstructions;
425
- invalidateAnalysis (InvalidKind);
424
+ if (stripOwnership (F)) {
425
+ auto InvalidKind =
426
+ SILAnalysis::InvalidationKind::BranchesAndInstructions;
427
+ invalidateAnalysis (&F, InvalidKind);
428
+ }
426
429
}
427
430
428
431
// If we were asked to strip transparent, we are at the beginning of the
@@ -432,19 +435,12 @@ struct OwnershipModelEliminator : SILFunctionTransform {
432
435
FunctionBodyDeserializationNotificationHandler;
433
436
std::unique_ptr<DeserializationNotificationHandler> ptr;
434
437
if (SkipTransparent) {
435
- if (!Mod.hasRegisteredDeserializationNotificationHandlerForNonTransparentFuncOME ()) {
436
- ptr.reset (new NotificationHandlerTy (
437
- prepareNonTransparentSILFunctionForOptimization));
438
- Mod.registerDeserializationNotificationHandler (std::move (ptr));
439
- Mod.setRegisteredDeserializationNotificationHandlerForNonTransparentFuncOME ();
440
- }
438
+ ptr.reset (new NotificationHandlerTy (
439
+ prepareNonTransparentSILFunctionForOptimization));
441
440
} else {
442
- if (!Mod.hasRegisteredDeserializationNotificationHandlerForAllFuncOME ()) {
443
- ptr.reset (new NotificationHandlerTy (prepareSILFunctionForOptimization));
444
- Mod.registerDeserializationNotificationHandler (std::move (ptr));
445
- Mod.setRegisteredDeserializationNotificationHandlerForAllFuncOME ();
446
- }
441
+ ptr.reset (new NotificationHandlerTy (prepareSILFunctionForOptimization));
447
442
}
443
+ Mod.registerDeserializationNotificationHandler (std::move (ptr));
448
444
}
449
445
};
450
446
0 commit comments