diff --git a/llvm/tools/llvm-reduce/TestRunner.cpp b/llvm/tools/llvm-reduce/TestRunner.cpp --- a/llvm/tools/llvm-reduce/TestRunner.cpp +++ b/llvm/tools/llvm-reduce/TestRunner.cpp @@ -8,7 +8,7 @@ #include "TestRunner.h" #include "ReducerWorkItem.h" -#include "llvm/CodeGen/MachineFunction.h" +#include "deltas/Utils.h" using namespace llvm; @@ -33,9 +33,15 @@ ProgramArgs.push_back(Filename); std::string ErrMsg; - int Result = sys::ExecuteAndWait( - TestName, ProgramArgs, /*Env=*/None, /*Redirects=*/None, - /*SecondsToWait=*/0, /*MemoryLimit=*/0, &ErrMsg); + SmallVector, 3> Redirects; + Optional Empty = StringRef(); + if (!Verbose) { + for (int i = 0; i < 3; ++i) + Redirects.push_back(Empty); + } + int Result = + sys::ExecuteAndWait(TestName, ProgramArgs, /*Env=*/None, Redirects, + /*SecondsToWait=*/0, /*MemoryLimit=*/0, &ErrMsg); if (Result < 0) { Error E = make_error("Error running interesting-ness test: " + diff --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp --- a/llvm/tools/llvm-reduce/deltas/Delta.cpp +++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp @@ -14,9 +14,10 @@ #include "Delta.h" #include "ReducerWorkItem.h" +#include "Utils.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/Analysis/ModuleSummaryAnalysis.h" +#include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/Bitcode/BitcodeWriter.h" #include "llvm/CodeGen/MachineFunction.h" @@ -118,7 +119,8 @@ /// Splits Chunks in half and prints them. /// If unable to split (when chunk size is 1) returns false. static bool increaseGranularity(std::vector &Chunks) { - errs() << "Increasing granularity..."; + if (Verbose) + errs() << "Increasing granularity..."; std::vector NewChunks; bool SplitOne = false; @@ -134,11 +136,13 @@ } if (SplitOne) { Chunks = NewChunks; - errs() << "Success! New Chunks:\n"; - for (auto C : Chunks) { - errs() << '\t'; - C.print(); - errs() << '\n'; + if (Verbose) { + errs() << "Success! New Chunks:\n"; + for (auto C : Chunks) { + errs() << '\t'; + C.print(); + errs() << '\n'; + } } } return SplitOne; @@ -177,20 +181,26 @@ Clone->print(errs()); exit(1); } - errs() << " **** WARNING | reduction resulted in invalid module, " - "skipping\n"; + if (Verbose) { + errs() << " **** WARNING | reduction resulted in invalid module, " + "skipping\n"; + } return nullptr; } - errs() << "Ignoring: "; - ChunkToCheckForUninterestingness.print(); - for (const Chunk &C : UninterestingChunks) - C.print(); + if (Verbose) { + errs() << "Ignoring: "; + ChunkToCheckForUninterestingness.print(); + for (const Chunk &C : UninterestingChunks) + C.print(); + errs() << "\n"; + } SmallString<128> CurrentFilepath; if (!isReduced(*Clone, Test, CurrentFilepath)) { // Program became non-reduced, so this chunk appears to be interesting. - errs() << "\n"; + if (Verbose) + errs() << "\n"; return nullptr; } return Clone; @@ -263,7 +273,8 @@ #endif } if (!Targets) { - errs() << "\nNothing to reduce\n"; + if (Verbose) + errs() << "\nNothing to reduce\n"; return; } @@ -382,7 +393,9 @@ FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity = true; UninterestingChunks.insert(ChunkToCheckForUninterestingness); ReducedProgram = std::move(Result); - errs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) << "\n"; + if (Verbose) + errs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) + << "\n"; writeOutput(*ReducedProgram, "Saved new best reduction to "); } // Delete uninteresting chunks @@ -397,5 +410,6 @@ // If we reduced the testcase replace it if (ReducedProgram) Test.setProgram(std::move(ReducedProgram)); - errs() << "Couldn't increase anymore.\n"; + if (Verbose) + errs() << "Couldn't increase anymore.\n"; } diff --git a/llvm/tools/llvm-reduce/deltas/Utils.h b/llvm/tools/llvm-reduce/deltas/Utils.h --- a/llvm/tools/llvm-reduce/deltas/Utils.h +++ b/llvm/tools/llvm-reduce/deltas/Utils.h @@ -15,9 +15,12 @@ #include "llvm/IR/Function.h" #include "llvm/IR/Value.h" +#include "llvm/Support/CommandLine.h" namespace llvm { +extern cl::opt Verbose; + Value *getDefaultValue(Type *T); bool hasAliasUse(Function &F); diff --git a/llvm/tools/llvm-reduce/deltas/Utils.cpp b/llvm/tools/llvm-reduce/deltas/Utils.cpp --- a/llvm/tools/llvm-reduce/deltas/Utils.cpp +++ b/llvm/tools/llvm-reduce/deltas/Utils.cpp @@ -16,6 +16,12 @@ using namespace llvm; +extern cl::OptionCategory LLVMReduceOptions; + +cl::opt llvm::Verbose("verbose", + cl::desc("Print extra debugging information"), + cl::init(false), cl::cat(LLVMReduceOptions)); + Value *llvm::getDefaultValue(Type *T) { return T->isVoidTy() ? PoisonValue::get(T) : Constant::getNullValue(T); }