[Bugpoint redesign] Output option can now print to STDOUT

Summary:
This also changes all the outs() statements to errs() so the output and
progress streams don't get mixed.

This has been added because D64176 had flaky tests, which I believe were because the reduced file was being catted into `FileCheck`, instead of being pass from STDOUT directly.

Reviewers: chandlerc, dblaikie, xbolva00

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D66314

llvm-svn: 369060
This commit is contained in:
Diego Trevino Ferrer 2019-08-15 22:39:43 +00:00
parent f64dcdea6d
commit c26892538e
6 changed files with 44 additions and 50 deletions

View File

@ -1,8 +1,7 @@
; Test that llvm-reduce can remove uninteresting functions as well as ; Test that llvm-reduce can remove uninteresting functions as well as
; their InstCalls. ; their InstCalls.
; ;
; RUN: llvm-reduce --test %p/Inputs/remove-funcs.py %s ; RUN: llvm-reduce --test %p/Inputs/remove-funcs.py %s -o - | FileCheck %s
; RUN: cat reduced.ll | FileCheck %s
; REQUIRES: plugins, shell ; REQUIRES: plugins, shell
; CHECK-NOT: uninteresting1() ; CHECK-NOT: uninteresting1()

View File

@ -49,7 +49,7 @@ int TestRunner::run(StringRef Filename) {
if (Result < 0) { if (Result < 0) {
Error E = make_error<StringError>("Error running interesting-ness test\n", Error E = make_error<StringError>("Error running interesting-ness test\n",
inconvertibleErrorCode()); inconvertibleErrorCode());
outs() << toString(std::move(E)); errs() << toString(std::move(E));
exit(1); exit(1);
} }

View File

@ -50,23 +50,6 @@ static SmallString<128> createTmpFile(Module *M, StringRef TmpDir) {
return UniqueFilepath; return UniqueFilepath;
} }
/// Prints the Chunk Indexes with the following format: [start, end], if
/// chunk is at minimum size (1), then it just displays [start].
static void printChunks(std::vector<Chunk> Chunks, bool Oneline = false) {
if (Chunks.empty()) {
outs() << "No Chunks";
return;
}
for (auto C : Chunks) {
if (!Oneline)
outs() << '\t';
C.print();
if (!Oneline)
outs() << '\n';
}
}
/// Counts the amount of lines for a given file /// Counts the amount of lines for a given file
static unsigned getLines(StringRef Filepath) { static unsigned getLines(StringRef Filepath) {
unsigned Lines = 0; unsigned Lines = 0;
@ -82,7 +65,7 @@ static unsigned getLines(StringRef Filepath) {
/// Splits Chunks in half and prints them. /// Splits Chunks in half and prints them.
/// If unable to split (when chunk size is 1) returns false. /// If unable to split (when chunk size is 1) returns false.
static bool increaseGranularity(std::vector<Chunk> &Chunks) { static bool increaseGranularity(std::vector<Chunk> &Chunks) {
outs() << "Increasing granularity..."; errs() << "Increasing granularity...";
std::vector<Chunk> NewChunks; std::vector<Chunk> NewChunks;
bool SplitOne = false; bool SplitOne = false;
@ -98,8 +81,12 @@ static bool increaseGranularity(std::vector<Chunk> &Chunks) {
} }
if (SplitOne) { if (SplitOne) {
Chunks = NewChunks; Chunks = NewChunks;
outs() << "Success! New Chunks:\n"; errs() << "Success! New Chunks:\n";
printChunks(Chunks); for (auto C : Chunks) {
errs() << '\t';
C.print();
errs() << '\n';
}
} }
return SplitOne; return SplitOne;
} }
@ -112,11 +99,11 @@ void llvm::runDeltaPass(
std::function<void(const std::vector<Chunk> &, Module *)> std::function<void(const std::vector<Chunk> &, Module *)>
ExtractChunksFromModule) { ExtractChunksFromModule) {
if (!Targets) { if (!Targets) {
outs() << "\nNothing to reduce\n"; errs() << "\nNothing to reduce\n";
return; return;
} }
if (!Test.run(Test.getReducedFilepath())) { if (!Test.run(Test.getReducedFilepath())) {
outs() << "\nInput isn't interesting! Verify interesting-ness test\n"; errs() << "\nInput isn't interesting! Verify interesting-ness test\n";
exit(1); exit(1);
} }
@ -125,7 +112,7 @@ void llvm::runDeltaPass(
std::unique_ptr<Module> ReducedProgram; std::unique_ptr<Module> ReducedProgram;
if (!increaseGranularity(Chunks)) { if (!increaseGranularity(Chunks)) {
outs() << "\nAlready at minimum size. Cannot reduce anymore.\n"; errs() << "\nAlready at minimum size. Cannot reduce anymore.\n";
return; return;
} }
@ -149,20 +136,23 @@ void llvm::runDeltaPass(
SmallString<128> CurrentFilepath = SmallString<128> CurrentFilepath =
createTmpFile(Clone.get(), Test.getTmpDir()); createTmpFile(Clone.get(), Test.getTmpDir());
outs() << "Testing with: "; errs() << "Ignoring: ";
printChunks(CurrentChunks, /*Oneline=*/true); Chunks[I].print();
outs() << " | " << sys::path::filename(CurrentFilepath); for (auto C : UninterestingChunks)
C.print();
errs() << " | " << sys::path::filename(CurrentFilepath);
// Current Chunks aren't interesting // Current Chunks aren't interesting
if (!Test.run(CurrentFilepath)) { if (!Test.run(CurrentFilepath)) {
outs() << "\n"; errs() << "\n";
continue; continue;
} }
UninterestingChunks.insert(Chunks[I]); UninterestingChunks.insert(Chunks[I]);
Test.setReducedFilepath(CurrentFilepath); Test.setReducedFilepath(CurrentFilepath);
ReducedProgram = std::move(Clone); ReducedProgram = std::move(Clone);
outs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) << "\n"; errs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) << "\n";
} }
// Delete uninteresting chunks // Delete uninteresting chunks
erase_if(Chunks, [&UninterestingChunks](const Chunk &C) { erase_if(Chunks, [&UninterestingChunks](const Chunk &C) {
@ -174,5 +164,5 @@ void llvm::runDeltaPass(
// If we reduced the testcase replace it // If we reduced the testcase replace it
if (ReducedProgram) if (ReducedProgram)
Test.setProgram(std::move(ReducedProgram)); Test.setProgram(std::move(ReducedProgram));
outs() << "Couldn't increase anymore.\n"; errs() << "Couldn't increase anymore.\n";
} }

View File

@ -36,10 +36,10 @@ struct Chunk {
bool contains(unsigned Index) const { return Index >= begin && Index <= end; } bool contains(unsigned Index) const { return Index >= begin && Index <= end; }
void print() const { void print() const {
outs() << "[" << begin; errs() << "[" << begin;
if (end - begin != 0) if (end - begin != 0)
outs() << "," << end; errs() << "," << end;
outs() << "]"; errs() << "]";
} }
/// Operator when populating CurrentChunks in Generic Delta Pass /// Operator when populating CurrentChunks in Generic Delta Pass

View File

@ -54,19 +54,19 @@ static void extractFunctionsFromModule(const std::vector<Chunk> &ChunksToKeep,
/// respective name & index /// respective name & index
static unsigned countFunctions(Module *Program) { static unsigned countFunctions(Module *Program) {
// TODO: Silence index with --quiet flag // TODO: Silence index with --quiet flag
outs() << "----------------------------\n"; errs() << "----------------------------\n";
outs() << "Function Index Reference:\n"; errs() << "Function Index Reference:\n";
unsigned FunctionCount = 0; unsigned FunctionCount = 0;
for (auto &F : *Program) for (auto &F : *Program)
outs() << "\t" << ++FunctionCount << ": " << F.getName() << "\n"; errs() << "\t" << ++FunctionCount << ": " << F.getName() << "\n";
outs() << "----------------------------\n"; errs() << "----------------------------\n";
return FunctionCount; return FunctionCount;
} }
void llvm::reduceFunctionsDeltaPass(TestRunner &Test) { void llvm::reduceFunctionsDeltaPass(TestRunner &Test) {
outs() << "*** Reducing Functions...\n"; errs() << "*** Reducing Functions...\n";
unsigned Functions = countFunctions(Test.getProgram()); unsigned Functions = countFunctions(Test.getProgram());
runDeltaPass(Test, Functions, extractFunctionsFromModule); runDeltaPass(Test, Functions, extractFunctionsFromModule);
outs() << "----------------------------\n"; errs() << "----------------------------\n";
} }

View File

@ -89,17 +89,22 @@ int main(int argc, char **argv) {
StringRef ReducedFilename = sys::path::filename(Tester.getReducedFilepath()); StringRef ReducedFilename = sys::path::filename(Tester.getReducedFilepath());
if (ReducedFilename == sys::path::filename(InputFilename)) { if (ReducedFilename == sys::path::filename(InputFilename)) {
outs() << "\nCouldnt reduce input :/\n"; errs() << "\nCouldnt reduce input :/\n";
} else { } else {
if (ReplaceInput) // In-place // Print reduced file to STDOUT
OutputFilename = InputFilename.c_str(); if (OutputFilename == "-")
else if (OutputFilename.empty()) Tester.getProgram()->print(outs(), nullptr);
OutputFilename = "reduced.ll"; else {
else if (ReplaceInput) // In-place
OutputFilename += ".ll"; OutputFilename = InputFilename.c_str();
else if (OutputFilename.empty())
OutputFilename = "reduced.ll";
else
OutputFilename += ".ll";
sys::fs::copy_file(Tester.getReducedFilepath(), OutputFilename); sys::fs::copy_file(Tester.getReducedFilepath(), OutputFilename);
outs() << "\nDone reducing! Reduced IR to file: " << OutputFilename << "\n"; errs() << "\nDone reducing! Reduced testcase: " << OutputFilename << "\n";
}
} }
return 0; return 0;