summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-reduce
diff options
context:
space:
mode:
authorDiego Trevino Ferrer <diegof30@gmail.com>2019-08-15 22:39:43 +0000
committerDiego Trevino Ferrer <diegof30@gmail.com>2019-08-15 22:39:43 +0000
commitc26892538e84a56d0985486b273c2cfb77611292 (patch)
tree391c61e9df03b3ca350eec1a68af5c215c9c21cf /llvm/tools/llvm-reduce
parentf64dcdea6da47c47be055b33f77fb161f8d2e29e (diff)
downloadbcm5719-llvm-c26892538e84a56d0985486b273c2cfb77611292.tar.gz
bcm5719-llvm-c26892538e84a56d0985486b273c2cfb77611292.zip
[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
Diffstat (limited to 'llvm/tools/llvm-reduce')
-rw-r--r--llvm/tools/llvm-reduce/TestRunner.cpp2
-rw-r--r--llvm/tools/llvm-reduce/deltas/Delta.cpp48
-rw-r--r--llvm/tools/llvm-reduce/deltas/Delta.h6
-rw-r--r--llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp12
-rw-r--r--llvm/tools/llvm-reduce/llvm-reduce.cpp25
5 files changed, 44 insertions, 49 deletions
diff --git a/llvm/tools/llvm-reduce/TestRunner.cpp b/llvm/tools/llvm-reduce/TestRunner.cpp
index 09548a63e69..2fd01abfd47 100644
--- a/llvm/tools/llvm-reduce/TestRunner.cpp
+++ b/llvm/tools/llvm-reduce/TestRunner.cpp
@@ -49,7 +49,7 @@ int TestRunner::run(StringRef Filename) {
if (Result < 0) {
Error E = make_error<StringError>("Error running interesting-ness test\n",
inconvertibleErrorCode());
- outs() << toString(std::move(E));
+ errs() << toString(std::move(E));
exit(1);
}
diff --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp
index d33c8e39bf3..68a9272b88d 100644
--- a/llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp
@@ -50,23 +50,6 @@ static SmallString<128> createTmpFile(Module *M, StringRef TmpDir) {
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
static unsigned getLines(StringRef Filepath) {
unsigned Lines = 0;
@@ -82,7 +65,7 @@ static unsigned getLines(StringRef Filepath) {
/// Splits Chunks in half and prints them.
/// If unable to split (when chunk size is 1) returns false.
static bool increaseGranularity(std::vector<Chunk> &Chunks) {
- outs() << "Increasing granularity...";
+ errs() << "Increasing granularity...";
std::vector<Chunk> NewChunks;
bool SplitOne = false;
@@ -98,8 +81,12 @@ static bool increaseGranularity(std::vector<Chunk> &Chunks) {
}
if (SplitOne) {
Chunks = NewChunks;
- outs() << "Success! New Chunks:\n";
- printChunks(Chunks);
+ errs() << "Success! New Chunks:\n";
+ for (auto C : Chunks) {
+ errs() << '\t';
+ C.print();
+ errs() << '\n';
+ }
}
return SplitOne;
}
@@ -112,11 +99,11 @@ void llvm::runDeltaPass(
std::function<void(const std::vector<Chunk> &, Module *)>
ExtractChunksFromModule) {
if (!Targets) {
- outs() << "\nNothing to reduce\n";
+ errs() << "\nNothing to reduce\n";
return;
}
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);
}
@@ -125,7 +112,7 @@ void llvm::runDeltaPass(
std::unique_ptr<Module> ReducedProgram;
if (!increaseGranularity(Chunks)) {
- outs() << "\nAlready at minimum size. Cannot reduce anymore.\n";
+ errs() << "\nAlready at minimum size. Cannot reduce anymore.\n";
return;
}
@@ -149,20 +136,23 @@ void llvm::runDeltaPass(
SmallString<128> CurrentFilepath =
createTmpFile(Clone.get(), Test.getTmpDir());
- outs() << "Testing with: ";
- printChunks(CurrentChunks, /*Oneline=*/true);
- outs() << " | " << sys::path::filename(CurrentFilepath);
+ errs() << "Ignoring: ";
+ Chunks[I].print();
+ for (auto C : UninterestingChunks)
+ C.print();
+
+ errs() << " | " << sys::path::filename(CurrentFilepath);
// Current Chunks aren't interesting
if (!Test.run(CurrentFilepath)) {
- outs() << "\n";
+ errs() << "\n";
continue;
}
UninterestingChunks.insert(Chunks[I]);
Test.setReducedFilepath(CurrentFilepath);
ReducedProgram = std::move(Clone);
- outs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) << "\n";
+ errs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) << "\n";
}
// Delete uninteresting chunks
erase_if(Chunks, [&UninterestingChunks](const Chunk &C) {
@@ -174,5 +164,5 @@ void llvm::runDeltaPass(
// If we reduced the testcase replace it
if (ReducedProgram)
Test.setProgram(std::move(ReducedProgram));
- outs() << "Couldn't increase anymore.\n";
+ errs() << "Couldn't increase anymore.\n";
} \ No newline at end of file
diff --git a/llvm/tools/llvm-reduce/deltas/Delta.h b/llvm/tools/llvm-reduce/deltas/Delta.h
index 8597adb56b5..d4217872333 100644
--- a/llvm/tools/llvm-reduce/deltas/Delta.h
+++ b/llvm/tools/llvm-reduce/deltas/Delta.h
@@ -36,10 +36,10 @@ struct Chunk {
bool contains(unsigned Index) const { return Index >= begin && Index <= end; }
void print() const {
- outs() << "[" << begin;
+ errs() << "[" << begin;
if (end - begin != 0)
- outs() << "," << end;
- outs() << "]";
+ errs() << "," << end;
+ errs() << "]";
}
/// Operator when populating CurrentChunks in Generic Delta Pass
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
index 52777bed640..90937d5476c 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
@@ -54,19 +54,19 @@ static void extractFunctionsFromModule(const std::vector<Chunk> &ChunksToKeep,
/// respective name & index
static unsigned countFunctions(Module *Program) {
// TODO: Silence index with --quiet flag
- outs() << "----------------------------\n";
- outs() << "Function Index Reference:\n";
+ errs() << "----------------------------\n";
+ errs() << "Function Index Reference:\n";
unsigned FunctionCount = 0;
for (auto &F : *Program)
- outs() << "\t" << ++FunctionCount << ": " << F.getName() << "\n";
+ errs() << "\t" << ++FunctionCount << ": " << F.getName() << "\n";
- outs() << "----------------------------\n";
+ errs() << "----------------------------\n";
return FunctionCount;
}
void llvm::reduceFunctionsDeltaPass(TestRunner &Test) {
- outs() << "*** Reducing Functions...\n";
+ errs() << "*** Reducing Functions...\n";
unsigned Functions = countFunctions(Test.getProgram());
runDeltaPass(Test, Functions, extractFunctionsFromModule);
- outs() << "----------------------------\n";
+ errs() << "----------------------------\n";
} \ No newline at end of file
diff --git a/llvm/tools/llvm-reduce/llvm-reduce.cpp b/llvm/tools/llvm-reduce/llvm-reduce.cpp
index 23c98b5e935..ec82ecbe7c7 100644
--- a/llvm/tools/llvm-reduce/llvm-reduce.cpp
+++ b/llvm/tools/llvm-reduce/llvm-reduce.cpp
@@ -89,17 +89,22 @@ int main(int argc, char **argv) {
StringRef ReducedFilename = sys::path::filename(Tester.getReducedFilepath());
if (ReducedFilename == sys::path::filename(InputFilename)) {
- outs() << "\nCouldnt reduce input :/\n";
+ errs() << "\nCouldnt reduce input :/\n";
} else {
- if (ReplaceInput) // In-place
- OutputFilename = InputFilename.c_str();
- else if (OutputFilename.empty())
- OutputFilename = "reduced.ll";
- else
- OutputFilename += ".ll";
-
- sys::fs::copy_file(Tester.getReducedFilepath(), OutputFilename);
- outs() << "\nDone reducing! Reduced IR to file: " << OutputFilename << "\n";
+ // 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";
+ else
+ OutputFilename += ".ll";
+
+ sys::fs::copy_file(Tester.getReducedFilepath(), OutputFilename);
+ errs() << "\nDone reducing! Reduced testcase: " << OutputFilename << "\n";
+ }
}
return 0;
OpenPOWER on IntegriCloud