From bdf8c7b72bc1cac09a9840357b8da966a0f3c152 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Wed, 6 Jun 2018 19:05:41 +0000 Subject: [PATCH] [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 --- test/DebugInfo/debugify-each.ll | 3 +++ tools/opt/Debugify.cpp | 31 ++++++++++++++++--------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/test/DebugInfo/debugify-each.ll b/test/DebugInfo/debugify-each.ll index 8d5eb46361e..e290b948cc7 100644 --- a/test/DebugInfo/debugify-each.ll +++ b/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/tools/opt/Debugify.cpp b/tools/opt/Debugify.cpp index f12eabfa895..5ed3de3622b 100644 --- a/tools/opt/Debugify.cpp +++ b/tools/opt/Debugify.cpp @@ -35,6 +35,11 @@ using namespace llvm; namespace { +cl::opt 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 @@ bool applyDebugifyMetadata(Module &M, 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 @@ bool checkDebugifyMetadata(Module &M, // 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 @@ bool checkDebugifyMetadata(Module &M, 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 @@ bool checkDebugifyMetadata(Module &M, // 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) {