Skip to content

Commit 010c1cd

Browse files
committed
Convert OME into a function transform
1 parent 6d600b4 commit 010c1cd

File tree

1 file changed

+36
-39
lines changed

1 file changed

+36
-39
lines changed

lib/SILOptimizer/Mandatory/OwnershipModelEliminator.cpp

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ static void prepareSILFunctionForOptimization(ModuleDecl *, SILFunction *F) {
370370

371371
namespace {
372372

373-
struct OwnershipModelEliminator : SILModuleTransform {
373+
struct OwnershipModelEliminator : SILFunctionTransform {
374374
bool SkipTransparent;
375375
bool SkipStdlibModule;
376376

@@ -379,53 +379,50 @@ struct OwnershipModelEliminator : SILModuleTransform {
379379

380380
void run() override {
381381
if (DumpBefore.size()) {
382-
getModule()->dump(DumpBefore.c_str());
382+
getFunction()->dump(DumpBefore.c_str());
383383
}
384384

385-
auto &Mod = *getModule();
385+
auto *F = getFunction();
386+
auto &Mod = getFunction()->getModule();
386387

387388
// If we are supposed to skip the stdlib module and we are in the stdlib
388389
// module bail.
389390
if (SkipStdlibModule && Mod.isStdlibModule()) {
390391
return;
391392
}
392393

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-
}
423-
424-
if (stripOwnership(F)) {
425-
auto InvalidKind =
426-
SILAnalysis::InvalidationKind::BranchesAndInstructions;
427-
invalidateAnalysis(&F, InvalidKind);
428-
}
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+
}
422+
423+
if (stripOwnership(*F)) {
424+
auto InvalidKind = SILAnalysis::InvalidationKind::BranchesAndInstructions;
425+
invalidateAnalysis(InvalidKind);
429426
}
430427

431428
// If we were asked to strip transparent, we are at the beginning of the

0 commit comments

Comments
 (0)