@@ -370,7 +370,7 @@ static void prepareSILFunctionForOptimization(ModuleDecl *, SILFunction *F) {
370370
371371namespace {
372372
373- struct OwnershipModelEliminator : SILFunctionTransform {
373+ struct OwnershipModelEliminator : SILModuleTransform {
374374 bool SkipTransparent;
375375 bool SkipStdlibModule;
376376
@@ -379,50 +379,53 @@ struct OwnershipModelEliminator : SILFunctionTransform {
379379
380380 void run () override {
381381 if (DumpBefore.size ()) {
382- getFunction ()->dump (DumpBefore.c_str ());
382+ getModule ()->dump (DumpBefore.c_str ());
383383 }
384384
385- auto *F = getFunction ();
386- auto &Mod = getFunction ()->getModule ();
385+ auto &Mod = *getModule ();
387386
388387 // If we are supposed to skip the stdlib module and we are in the stdlib
389388 // module bail.
390389 if (SkipStdlibModule && Mod.isStdlibModule ()) {
391390 return ;
392391 }
393392
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+ }
422423
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+ }
426429 }
427430
428431 // If we were asked to strip transparent, we are at the beginning of the
@@ -432,19 +435,12 @@ struct OwnershipModelEliminator : SILFunctionTransform {
432435 FunctionBodyDeserializationNotificationHandler;
433436 std::unique_ptr<DeserializationNotificationHandler> ptr;
434437 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));
441440 } 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));
447442 }
443+ Mod.registerDeserializationNotificationHandler (std::move (ptr));
448444 }
449445};
450446
0 commit comments