[llvm] be56ece - [llvm-reduce] Move code to check chunk to function, to enable reuse (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 16 07:39:52 PST 2021
Author: Florian Hahn
Date: 2021-11-16T15:39:13Z
New Revision: be56ece91853a094572a9ba613e1df71880ce683
URL: https://github.com/llvm/llvm-project/commit/be56ece91853a094572a9ba613e1df71880ce683
DIFF: https://github.com/llvm/llvm-project/commit/be56ece91853a094572a9ba613e1df71880ce683.diff
LOG: [llvm-reduce] Move code to check chunk to function, to enable reuse (NFC).
This patch moves the logic to clone and check a new chunk into a new
function, to allow re-use in a follow-up patch that implements parallel
reductions.
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D113856
Added:
Modified:
llvm/tools/llvm-reduce/deltas/Delta.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-reduce/deltas/Delta.cpp b/llvm/tools/llvm-reduce/deltas/Delta.cpp
index 7aa01672a077..f2807b05e0f8 100644
--- a/llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ b/llvm/tools/llvm-reduce/deltas/Delta.cpp
@@ -116,6 +116,58 @@ static bool increaseGranularity(std::vector<Chunk> &Chunks) {
}
return SplitOne;
}
+// Check if \p ChunkToCheckForUninterestingness is interesting. Returns the
+// modified module if the chunk resulted in a reduction.
+template <typename T>
+static std::unique_ptr<ReducerWorkItem>
+CheckChunk(Chunk &ChunkToCheckForUninterestingness, TestRunner &Test,
+ function_ref<void(Oracle &, T &)> ExtractChunksFromModule,
+ std::set<Chunk> &UninterestingChunks,
+ std::vector<Chunk> &ChunksStillConsideredInteresting) {
+ // Take all of ChunksStillConsideredInteresting chunks, except those we've
+ // already deemed uninteresting (UninterestingChunks) but didn't remove
+ // from ChunksStillConsideredInteresting yet, and additionally ignore
+ // ChunkToCheckForUninterestingness chunk.
+ std::vector<Chunk> CurrentChunks;
+ CurrentChunks.reserve(ChunksStillConsideredInteresting.size() -
+ UninterestingChunks.size() - 1);
+ copy_if(ChunksStillConsideredInteresting, std::back_inserter(CurrentChunks),
+ [&](const Chunk &C) {
+ return !UninterestingChunks.count(C) &&
+ C != ChunkToCheckForUninterestingness;
+ });
+
+ // Clone module before hacking it up..
+ std::unique_ptr<ReducerWorkItem> Clone =
+ cloneReducerWorkItem(Test.getProgram());
+ // Generate Module with only Targets inside Current Chunks
+ Oracle O(CurrentChunks);
+ ExtractChunksFromModule(O, *Clone);
+
+ // Some reductions may result in invalid IR. Skip such reductions.
+ if (verifyReducerWorkItem(*Clone, &errs())) {
+ if (AbortOnInvalidReduction) {
+ errs() << "Invalid reduction\n";
+ exit(1);
+ }
+ errs() << " **** WARNING | reduction resulted in invalid module, "
+ "skipping\n";
+ return nullptr;
+ }
+
+ errs() << "Ignoring: ";
+ ChunkToCheckForUninterestingness.print();
+ for (const Chunk &C : UninterestingChunks)
+ C.print();
+
+ SmallString<128> CurrentFilepath;
+ if (!isReduced(*Clone, Test, CurrentFilepath)) {
+ // Program became non-reduced, so this chunk appears to be interesting.
+ errs() << "\n";
+ return nullptr;
+ }
+ return Clone;
+}
/// Runs the Delta Debugging algorithm, splits the code into chunks and
/// reduces the amount of chunks that are considered interesting by the
@@ -162,52 +214,15 @@ void runDeltaPassInt(
std::set<Chunk> UninterestingChunks;
for (Chunk &ChunkToCheckForUninterestingness :
reverse(ChunksStillConsideredInteresting)) {
- // Take all of ChunksStillConsideredInteresting chunks, except those we've
- // already deemed uninteresting (UninterestingChunks) but didn't remove
- // from ChunksStillConsideredInteresting yet, and additionally ignore
- // ChunkToCheckForUninterestingness chunk.
- std::vector<Chunk> CurrentChunks;
- CurrentChunks.reserve(ChunksStillConsideredInteresting.size() -
- UninterestingChunks.size() - 1);
- copy_if(ChunksStillConsideredInteresting,
- std::back_inserter(CurrentChunks), [&](const Chunk &C) {
- return !UninterestingChunks.count(C) &&
- C != ChunkToCheckForUninterestingness;
- });
-
- // Clone module before hacking it up..
- std::unique_ptr<ReducerWorkItem> Clone =
- cloneReducerWorkItem(Test.getProgram());
- // Generate Module with only Targets inside Current Chunks
- Oracle O(CurrentChunks);
- ExtractChunksFromModule(O, *Clone);
-
- // Some reductions may result in invalid IR. Skip such reductions.
- if (verifyReducerWorkItem(*Clone, &errs())) {
- if (AbortOnInvalidReduction) {
- errs() << "Invalid reduction\n";
- exit(1);
- }
- errs() << " **** WARNING | reduction resulted in invalid module, "
- "skipping\n";
- continue;
- }
-
- errs() << "Ignoring: ";
- ChunkToCheckForUninterestingness.print();
- for (const Chunk &C : UninterestingChunks)
- C.print();
-
- SmallString<128> CurrentFilepath;
- if (!isReduced(*Clone, Test, CurrentFilepath)) {
- // Program became non-reduced, so this chunk appears to be interesting.
- errs() << "\n";
+ std::unique_ptr<ReducerWorkItem> Result = CheckChunk(
+ ChunkToCheckForUninterestingness, Test, ExtractChunksFromModule,
+ UninterestingChunks, ChunksStillConsideredInteresting);
+ if (!Result)
continue;
- }
FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity = true;
UninterestingChunks.insert(ChunkToCheckForUninterestingness);
- ReducedProgram = std::move(Clone);
+ ReducedProgram = std::move(Result);
errs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) << "\n";
writeOutput(*ReducedProgram, "Saved new best reduction to ");
}
More information about the llvm-commits
mailing list