[llvm] f041204 - llvm-reduce: Stop checking workitem is interesting before each pass
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 28 16:39:18 PDT 2022
Author: Matt Arsenault
Date: 2022-10-28T16:39:09-07:00
New Revision: f041204ec896a24d19f44b9095660ab8559ebbc7
URL: https://github.com/llvm/llvm-project/commit/f041204ec896a24d19f44b9095660ab8559ebbc7
DIFF: https://github.com/llvm/llvm-project/commit/f041204ec896a24d19f44b9095660ab8559ebbc7.diff
LOG: llvm-reduce: Stop checking workitem is interesting before each pass
Each delta pass run should have guaranteed the output is still
interesting, so it should be pointless to recheck this each
iteration. I have many issues that take multiple minutes
to reproduce, so this ends up being a huge waste of time.
Also, remove broken line counting. This never worked, since
getLines was failing to open the temporary file which was just
deleted.
Added:
Modified:
llvm/tools/llvm-reduce/deltas/Delta.cpp
llvm/tools/llvm-reduce/llvm-reduce.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp
index 736e62361c546..c29c8af3e25d8 100644
--- a/llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp
@@ -67,8 +67,8 @@ void writeBitcode(ReducerWorkItem &M, raw_ostream &OutStream);
void readBitcode(ReducerWorkItem &M, MemoryBufferRef Data, LLVMContext &Ctx,
const char *ToolName);
-bool isReduced(ReducerWorkItem &M, TestRunner &Test,
- SmallString<128> &CurrentFilepath) {
+bool isReduced(ReducerWorkItem &M, TestRunner &Test) {
+ SmallString<128> CurrentFilepath;
// Write ReducerWorkItem to tmp file
int FD;
std::error_code EC = sys::fs::createTemporaryFile(
@@ -104,18 +104,6 @@ bool isReduced(ReducerWorkItem &M, TestRunner &Test,
return Test.run(CurrentFilepath);
}
-/// Counts the amount of lines for a given file
-static int getLines(StringRef Filepath) {
- int Lines = 0;
- std::string CurrLine;
- std::ifstream FileStream{std::string(Filepath)};
-
- while (std::getline(FileStream, CurrLine))
- ++Lines;
-
- return Lines;
-}
-
/// 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) {
@@ -195,8 +183,7 @@ CheckChunk(Chunk &ChunkToCheckForUninterestingness,
errs() << "\n";
}
- SmallString<128> CurrentFilepath;
- if (!isReduced(*Clone, Test, CurrentFilepath)) {
+ if (!isReduced(*Clone, Test)) {
// Program became non-reduced, so this chunk appears to be interesting.
if (Verbose)
errs() << "\n";
@@ -239,12 +226,6 @@ void llvm::runDeltaPass(TestRunner &Test, ReductionFunc ExtractChunksFromModule,
"input module is broken before making changes");
errs() << "*** " << Message << "...\n";
- SmallString<128> CurrentFilepath;
- if (!isReduced(Test.getProgram(), Test, CurrentFilepath)) {
- errs() << "\nInput isn't interesting! Verify interesting-ness test\n";
- exit(1);
- }
-
int Targets;
{
// Count the number of chunks by counting the number of calls to
@@ -257,7 +238,7 @@ void llvm::runDeltaPass(TestRunner &Test, ReductionFunc ExtractChunksFromModule,
assert(!verifyReducerWorkItem(Test.getProgram(), &errs()) &&
"input module is broken after counting chunks");
- assert(isReduced(Test.getProgram(), Test, CurrentFilepath) &&
+ assert(isReduced(Test.getProgram(), Test) &&
"input module no longer interesting after counting chunks");
#ifndef NDEBUG
@@ -393,10 +374,9 @@ void llvm::runDeltaPass(TestRunner &Test, ReductionFunc ExtractChunksFromModule,
FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity = true;
UninterestingChunks.insert(ChunkToCheckForUninterestingness);
ReducedProgram = std::move(Result);
- if (Verbose)
- errs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath)
- << "\n";
- writeOutput(*ReducedProgram, "Saved new best reduction to ");
+
+ // FIXME: Report meaningful progress info
+ writeOutput(*ReducedProgram, " **** SUCCESS | 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 13c6edc64e238..5cadaa73a682d 100644
--- a/llvm/tools/llvm-reduce/llvm-reduce.cpp
+++ b/llvm/tools/llvm-reduce/llvm-reduce.cpp
@@ -92,6 +92,8 @@ static cl::opt<int>
static codegen::RegisterCodeGenFlags CGF;
+bool isReduced(ReducerWorkItem &M, TestRunner &Test);
+
void writeOutput(ReducerWorkItem &M, StringRef Message) {
if (ReplaceInput) // In-place
OutputFilename = InputFilename.c_str();
@@ -182,6 +184,15 @@ int main(int Argc, char **Argv) {
TestRunner Tester(TestFilename, TestArguments, std::move(OriginalProgram),
std::move(TM), Argv[0]);
+ // This parses and writes out the testcase into a temporary file copy for the
+ // test, rather than evaluating the source IR directly. This is for the
+ // convenience of lit tests; the stripped out comments may have broken the
+ // interestingness checks.
+ if (!isReduced(Tester.getProgram(), Tester)) {
+ errs() << "\nInput isn't interesting! Verify interesting-ness test\n";
+ return 1;
+ }
+
// Try to reduce code
runDeltaPasses(Tester, MaxPassIterations);
More information about the llvm-commits
mailing list