Add an option to completely disable SIL verification.

This is useful to disable SIL verification in an assert build of the compiler.
This commit is contained in:
Erik Eckstein
2020-04-10 13:00:44 +02:00
parent d73686a5b5
commit 6da902ef8b
4 changed files with 28 additions and 21 deletions

View File

@@ -73,6 +73,9 @@ public:
/// Controls whether or not paranoid verification checks are run.
bool VerifyAll = false;
/// If true, no SIL verification is done at all.
bool VerifyNone = false;
/// Are we debugging sil serialization.
bool DebugSerialization = false;

View File

@@ -550,6 +550,9 @@ def sil_merge_partial_modules : Flag<["-"], "sil-merge-partial-modules">,
def sil_verify_all : Flag<["-"], "sil-verify-all">,
HelpText<"Verify SIL after each transform">;
def sil_verify_none : Flag<["-"], "sil-verify-none">,
HelpText<"Completely disable SIL verification">;
def verify_all_substitution_maps : Flag<["-"], "verify-all-substitution-maps">,
HelpText<"Verify all SubstitutionMaps on construction">;

View File

@@ -984,6 +984,7 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
Opts.DisableSILPerfOptimizations |= Args.hasArg(OPT_disable_sil_perf_optzns);
Opts.CrossModuleOptimization |= Args.hasArg(OPT_CrossModuleOptimization);
Opts.VerifyAll |= Args.hasArg(OPT_sil_verify_all);
Opts.VerifyNone |= Args.hasArg(OPT_sil_verify_none);
Opts.DebugSerialization |= Args.hasArg(OPT_sil_debug_serialization);
Opts.EmitVerboseSIL |= Args.hasArg(OPT_emit_verbose_sil);
Opts.EmitSortedSIL |= Args.hasArg(OPT_emit_sorted_sil);

View File

@@ -5232,13 +5232,20 @@ public:
// Out of Line Verifier Run Functions
//===----------------------------------------------------------------------===//
static bool verificationEnabled(const SILModule &M) {
#ifdef NDEBUG
if (!M.getOptions().VerifyAll)
return false;
#endif
return !M.getOptions().VerifyNone;
}
/// verify - Run the SIL verifier to make sure that the SILFunction follows
/// invariants.
void SILFunction::verify(bool SingleFunction) const {
#ifdef NDEBUG
if (!getModule().getOptions().VerifyAll)
if (!verificationEnabled(getModule()))
return;
#endif
// Please put all checks in visitSILFunction in SILVerifier, not here. This
// ensures that the pretty stack trace in the verifier is included with the
// back trace when the verifier crashes.
@@ -5246,19 +5253,16 @@ void SILFunction::verify(bool SingleFunction) const {
}
void SILFunction::verifyCriticalEdges() const {
#ifdef NDEBUG
if (!getModule().getOptions().VerifyAll)
if (!verificationEnabled(getModule()))
return;
#endif
SILVerifier(*this, /*SingleFunction=*/true).verifyBranches(this);
}
/// Verify that a property descriptor follows invariants.
void SILProperty::verify(const SILModule &M) const {
#ifdef NDEBUG
if (!M.getOptions().VerifyAll)
if (!verificationEnabled(M))
return;
#endif
auto *decl = getDecl();
auto *dc = decl->getInnermostDeclContext();
@@ -5310,10 +5314,9 @@ void SILProperty::verify(const SILModule &M) const {
/// Verify that a vtable follows invariants.
void SILVTable::verify(const SILModule &M) const {
#ifdef NDEBUG
if (!M.getOptions().VerifyAll)
if (!verificationEnabled(M))
return;
#endif
for (auto &entry : getEntries()) {
// All vtable entries must be decls in a class context.
assert(entry.Method.hasDecl() && "vtable entry is not a decl");
@@ -5361,10 +5364,9 @@ void SILVTable::verify(const SILModule &M) const {
/// Verify that a witness table follows invariants.
void SILWitnessTable::verify(const SILModule &M) const {
#ifdef NDEBUG
if (!M.getOptions().VerifyAll)
if (!verificationEnabled(M))
return;
#endif
if (isDeclaration())
assert(getEntries().empty() &&
"A witness table declaration should not have any entries.");
@@ -5414,10 +5416,9 @@ void SILDefaultWitnessTable::verify(const SILModule &M) const {
/// Verify that a global variable follows invariants.
void SILGlobalVariable::verify() const {
#ifdef NDEBUG
if (!getModule().getOptions().VerifyAll)
if (!verificationEnabled(getModule()))
return;
#endif
assert(getLoweredType().isObject()
&& "global variable cannot have address type");
@@ -5439,10 +5440,9 @@ void SILGlobalVariable::verify() const {
/// Verify the module.
void SILModule::verify() const {
#ifdef NDEBUG
if (!getOptions().VerifyAll)
if (!verificationEnabled(*this))
return;
#endif
// Uniquing set to catch symbol name collisions.
llvm::DenseSet<StringRef> symbolNames;