[Debugify] Add a quiet mode to suppress warnings
Suppressing warning output and module dumps significantly speeds up
fuzzing with `opt -debugify-each`.
llvm-svn: 334117
diff --git a/llvm/test/DebugInfo/debugify-each.ll b/llvm/test/DebugInfo/debugify-each.ll
index 8d5eb46..e290b94 100644
--- a/llvm/test/DebugInfo/debugify-each.ll
+++ b/llvm/test/DebugInfo/debugify-each.ll
@@ -13,6 +13,9 @@
; Verify that debugify each can be safely used with piping
; RUN: opt -debugify-each -O1 < %s | opt -O2 -o /dev/null
+; Check that the quiet mode emits no messages.
+; RUN: opt -disable-output -debugify-quiet -debugify-each -O1 < %s 2>&1 | count 0
+
; Check that stripped textual IR compares equal before and after applying
; debugify.
; RUN: opt -O1 < %s -S -o - | \
diff --git a/llvm/tools/opt/Debugify.cpp b/llvm/tools/opt/Debugify.cpp
index f12eabf..5ed3de3 100644
--- a/llvm/tools/opt/Debugify.cpp
+++ b/llvm/tools/opt/Debugify.cpp
@@ -35,6 +35,11 @@
namespace {
+cl::opt<bool> Quiet("debugify-quiet",
+ cl::desc("Suppress verbose debugify output"));
+
+raw_ostream &dbg() { return Quiet ? nulls() : errs(); }
+
bool isFunctionSkipped(Function &F) {
return F.isDeclaration() || !F.hasExactDefinition();
}
@@ -57,7 +62,7 @@
StringRef Banner) {
// Skip modules with debug info.
if (M.getNamedMetadata("llvm.dbg.cu")) {
- errs() << Banner << "Skipping module with debug info\n";
+ dbg() << Banner << "Skipping module with debug info\n";
return false;
}
@@ -159,7 +164,7 @@
// Skip modules without debugify metadata.
NamedMDNode *NMD = M.getNamedMetadata("llvm.debugify");
if (!NMD) {
- errs() << Banner << "Skipping module without debugify metadata\n";
+ dbg() << Banner << "Skipping module without debugify metadata\n";
return false;
}
@@ -190,10 +195,10 @@
continue;
}
- errs() << "ERROR: Instruction with empty DebugLoc in function ";
- errs() << F.getName() << " --";
- I.print(errs());
- errs() << "\n";
+ dbg() << "ERROR: Instruction with empty DebugLoc in function ";
+ dbg() << F.getName() << " --";
+ I.print(dbg());
+ dbg() << "\n";
HasErrors = true;
}
@@ -212,20 +217,16 @@
// Print the results.
for (unsigned Idx : MissingLines.set_bits())
- errs() << "WARNING: Missing line " << Idx + 1 << "\n";
+ dbg() << "WARNING: Missing line " << Idx + 1 << "\n";
for (unsigned Idx : MissingVars.set_bits())
- errs() << "ERROR: Missing variable " << Idx + 1 << "\n";
+ dbg() << "ERROR: Missing variable " << Idx + 1 << "\n";
HasErrors |= MissingVars.count() > 0;
- errs() << Banner;
+ dbg() << Banner;
if (!NameOfWrappedPass.empty())
- errs() << " [" << NameOfWrappedPass << "]";
- errs() << ": " << (HasErrors ? "FAIL" : "PASS") << '\n';
- if (HasErrors) {
- errs() << "Module IR Dump\n";
- M.print(errs(), nullptr, false);
- }
+ dbg() << " [" << NameOfWrappedPass << "]";
+ dbg() << ": " << (HasErrors ? "FAIL" : "PASS") << '\n';
// Strip the Debugify Metadata if required.
if (Strip) {