Index: llvm/tools/llvm-reduce/deltas/Delta.cpp =================================================================== --- llvm/tools/llvm-reduce/deltas/Delta.cpp +++ llvm/tools/llvm-reduce/deltas/Delta.cpp @@ -67,8 +67,8 @@ 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( @@ -109,18 +109,6 @@ 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 &Chunks) { @@ -200,8 +188,7 @@ 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"; @@ -244,12 +231,6 @@ "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 @@ -262,7 +243,7 @@ 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 @@ -398,10 +379,9 @@ 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, Index: llvm/tools/llvm-reduce/llvm-reduce.cpp =================================================================== --- llvm/tools/llvm-reduce/llvm-reduce.cpp +++ llvm/tools/llvm-reduce/llvm-reduce.cpp @@ -92,6 +92,8 @@ 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 @@ 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);