diff --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp index c23d70145b69dd..02ff46dbe2d154 100644 --- a/llvm/tools/llvm-reduce/deltas/Delta.cpp +++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp @@ -21,6 +21,8 @@ using namespace llvm; +void writeOutput(llvm::Module *M, llvm::StringRef Message); + bool IsReduced(Module &M, TestRunner &Test, SmallString<128> &CurrentFilepath) { // Write Module to tmp file int FD; @@ -149,6 +151,7 @@ void llvm::runDeltaPass( UninterestingChunks.insert(ChunkToCheckForUninterestingness); ReducedProgram = std::move(Clone); errs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) << "\n"; + writeOutput(ReducedProgram.get(), "Saved new best reduction to "); } // Delete uninteresting chunks erase_if(ChunksStillConsideredInteresting, diff --git a/llvm/tools/llvm-reduce/llvm-reduce.cpp b/llvm/tools/llvm-reduce/llvm-reduce.cpp index 9dd8aa4a938e70..376826b8b9e7bf 100644 --- a/llvm/tools/llvm-reduce/llvm-reduce.cpp +++ b/llvm/tools/llvm-reduce/llvm-reduce.cpp @@ -80,6 +80,22 @@ static std::unique_ptr parseInputFile(StringRef Filename, return Result; } +void writeOutput(Module *M, StringRef Message) { + if (ReplaceInput) // In-place + OutputFilename = InputFilename.c_str(); + else if (OutputFilename.empty() || OutputFilename == "-") + OutputFilename = "reduced.ll"; + + std::error_code EC; + raw_fd_ostream Out(OutputFilename, EC); + if (EC) { + errs() << "Error opening output file: " << EC.message() << "!\n"; + exit(1); + } + M->print(Out, /*AnnotationWriter=*/nullptr); + errs() << Message << OutputFilename << "\n"; +} + int main(int argc, char **argv) { InitLLVM X(argc, argv); @@ -102,21 +118,8 @@ int main(int argc, char **argv) { // Print reduced file to STDOUT if (OutputFilename == "-") Tester.getProgram()->print(outs(), nullptr); - else { - if (ReplaceInput) // In-place - OutputFilename = InputFilename.c_str(); - else if (OutputFilename.empty()) - OutputFilename = "reduced.ll"; - - std::error_code EC; - raw_fd_ostream Out(OutputFilename, EC); - if (EC) { - errs() << "Error opening output file: " << EC.message() << "!\n"; - exit(1); - } - Tester.getProgram()->print(Out, /*AnnotationWriter=*/nullptr); - errs() << "\nDone reducing! Reduced testcase: " << OutputFilename << "\n"; - } + else + writeOutput(Tester.getProgram(), "\nDone reducing! Reduced testcase: "); } return 0;