diff options
Diffstat (limited to 'llvm/tools/llvm-reduce/deltas/Delta.cpp')
-rw-r--r-- | llvm/tools/llvm-reduce/deltas/Delta.cpp | 57 |
1 files changed, 22 insertions, 35 deletions
diff --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp index 45dac1769e3..0b5571f74de 100644 --- a/llvm/tools/llvm-reduce/deltas/Delta.cpp +++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp @@ -21,39 +21,26 @@ using namespace llvm; -/// Writes IR code to the given Filepath -static bool writeProgramToFile(StringRef Filepath, int FD, const Module &M) { - ToolOutputFile Out(Filepath, FD); - M.print(Out.os(), /*AnnotationWriter=*/nullptr); - Out.os().close(); - - if (!Out.os().has_error()) { - Out.keep(); - return false; - } - return true; -} - -/// Creates a temporary (and unique) file inside the tmp folder and writes -/// the given module IR. -static SmallString<128> createTmpFile(Module *M, StringRef TmpDir) { - SmallString<128> UniqueFilepath; - int UniqueFD; - - SmallString<128> TmpFilepath; - sys::path::append(TmpFilepath, TmpDir, "tmp-%%%.ll"); +bool IsReduced(Module &M, TestRunner &Test, SmallString<128> &CurrentFilepath) { + // Write Module to tmp file + int FD; std::error_code EC = - sys::fs::createUniqueFile(TmpFilepath, UniqueFD, UniqueFilepath); + sys::fs::createTemporaryFile("llvm-reduce", "ll", FD, CurrentFilepath); if (EC) { errs() << "Error making unique filename: " << EC.message() << "!\n"; exit(1); } - if (writeProgramToFile(UniqueFilepath, UniqueFD, *M)) { - errs() << "Error emitting bitcode to file '" << UniqueFilepath << "'!\n"; + ToolOutputFile Out(CurrentFilepath, FD); + M.print(Out.os(), /*AnnotationWriter=*/nullptr); + Out.os().close(); + if (Out.os().has_error()) { + errs() << "Error emitting bitcode to file '" << CurrentFilepath << "'!\n"; exit(1); } - return UniqueFilepath; + + // Current Chunks aren't interesting + return Test.run(CurrentFilepath); } /// Counts the amount of lines for a given file @@ -108,9 +95,13 @@ void llvm::runDeltaPass( errs() << "\nNothing to reduce\n"; return; } - if (!Test.run(Test.getReducedFilepath())) { - errs() << "\nInput isn't interesting! Verify interesting-ness test\n"; - exit(1); + + if (Module *Program = Test.getProgram()) { + SmallString<128> CurrentFilepath; + if (!IsReduced(*Program, Test, CurrentFilepath)) { + errs() << "\nInput isn't interesting! Verify interesting-ness test\n"; + exit(1); + } } std::vector<Chunk> Chunks = {{1, Targets}}; @@ -138,25 +129,21 @@ void llvm::runDeltaPass( std::unique_ptr<Module> Clone = CloneModule(*Test.getProgram()); // Generate Module with only Targets inside Current Chunks ExtractChunksFromModule(CurrentChunks, Clone.get()); - // Write Module to tmp file - SmallString<128> CurrentFilepath = - createTmpFile(Clone.get(), Test.getTmpDir()); 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)) { + + SmallString<128> CurrentFilepath; + if (!IsReduced(*Clone, Test, CurrentFilepath)) { errs() << "\n"; continue; } UninterestingChunks.insert(Chunks[I]); - Test.setReducedFilepath(CurrentFilepath); ReducedProgram = std::move(Clone); errs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) << "\n"; } |