Skip to content

Commit

Permalink
Merge pull request #78123 from meg-gupta/newflag
Browse files Browse the repository at this point in the history
Add new flag -sil-ownership-verify-all
  • Loading branch information
meg-gupta authored Dec 13, 2024
2 parents 2405db0 + 8b1ecb8 commit 28e33af
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ class SILOptions {
/// Controls whether or not paranoid verification checks are run.
bool VerifyAll = false;

/// Verify ownership after every pass.
bool VerifyOwnershipAll = false;

/// If true, no SIL verification is done at all.
bool VerifyNone = false;

Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,9 @@ def sil_verify_all : Flag<["-"], "sil-verify-all">,

def sil_verify_none : Flag<["-"], "sil-verify-none">,
HelpText<"Completely disable SIL verification">;

def sil_ownership_verify_all : Flag<["-"], "sil-ownership-verify-all">,
HelpText<"Verify ownership after each transform">;

def verify_all_substitution_maps : Flag<["-"], "verify-all-substitution-maps">,
HelpText<"Verify all SubstitutionMaps on construction">;
Expand Down
5 changes: 5 additions & 0 deletions include/swift/SIL/SILFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,11 @@ class SILFunction
/// Verifies the lifetime of memory locations in the function.
void verifyMemoryLifetime(CalleeCache *calleeCache);

/// Verifies ownership of the function.
/// Since we don't have complete lifetimes everywhere, computes DeadEndBlocks
/// and calls verifyOwnership(DeadEndBlocks *deadEndBlocks)
void verifyOwnership() const;

/// Run the SIL ownership verifier to check that all values with ownership
/// have a linear lifetime. Regular OSSA invariants are checked separately in
/// normal SIL verification.
Expand Down
1 change: 1 addition & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2824,6 +2824,7 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,

Opts.VerifyAll |= Args.hasArg(OPT_sil_verify_all);
Opts.VerifyNone |= Args.hasArg(OPT_sil_verify_none);
Opts.VerifyOwnershipAll |= Args.hasArg(OPT_sil_ownership_verify_all);
Opts.DebugSerialization |= Args.hasArg(OPT_sil_debug_serialization);
Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil);
Opts.EmitSortedSIL |= Args.hasArg(OPT_emit_sorted_sil);
Expand Down
6 changes: 6 additions & 0 deletions lib/SIL/Verifier/SILOwnershipVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,12 @@ void SILModule::verifyOwnership() const {
}
}

void SILFunction::verifyOwnership() const {
auto deBlocks =
std::make_unique<DeadEndBlocks>(const_cast<SILFunction *>(this));
verifyOwnership(deBlocks.get());
}

void SILFunction::verifyOwnership(DeadEndBlocks *deadEndBlocks) const {
if (!getModule().getOptions().VerifySILOwnership)
return;
Expand Down
3 changes: 3 additions & 0 deletions lib/SILOptimizer/PassManager/PassManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,9 @@ void SILPassManager::runPassOnFunction(unsigned TransIdx, SILFunction *F) {
F->verify(getAnalysis<BasicCalleeAnalysis>()->getCalleeCache());
verifyAnalyses(F);
runSwiftFunctionVerification(F);
} else if (getOptions().VerifyOwnershipAll &&
(CurrentPassHasInvalidated || SILVerifyWithoutInvalidation)) {
F->verifyOwnership();
} else {
if ((SILVerifyAfterPass.end() != std::find_if(SILVerifyAfterPass.begin(),
SILVerifyAfterPass.end(),
Expand Down

0 comments on commit 28e33af

Please sign in to comment.