1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[Reduce] Rewrite runDeltaPass() workloop: do reduce a single and/or last target

Summary:
If there was a single target to begin with, because a single target
can only occupy a single chunk, we couldn't increase granularity.
and would immediately give up.

Likewise, if we had multiple targets, if by the end we'd end up with
a single target, we wouldn't finish reducing it, it would always
end up being "interesting"

Reviewers: dblaikie, nickdesaulniers, diegotf

Reviewed By: dblaikie

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D84318
This commit is contained in:
Roman Lebedev 2020-07-23 10:51:09 +03:00
parent 06c5334dbc
commit 67198bc6db
3 changed files with 32 additions and 28 deletions

View File

@ -3,7 +3,7 @@
define i32 @t(i32 %a0, i32 %a1, i32 %a2) {
; CHECK-ALL-LABEL: @t
; CHECK-FINAL: (i32 %a0) {
; CHECK-FINAL: () {
;
; CHECK-INTERESTINGNESS: ret i32
; CHECK-FINAL: ret i32 undef

View File

@ -3,7 +3,7 @@
define i32 @t(i32 %a0) {
; CHECK-ALL-LABEL: @t
; CHECK-FINAL: (i32 %a0) {
; CHECK-FINAL: () {
;
; CHECK-INTERESTINGNESS: ret i32
; CHECK-FINAL: ret i32 42

View File

@ -105,26 +105,28 @@ void llvm::runDeltaPass(
}
}
std::vector<Chunk> Chunks = {{1, Targets}};
std::set<Chunk> UninterestingChunks;
std::vector<Chunk> ChunksStillConsideredInteresting = {{1, Targets}};
std::unique_ptr<Module> ReducedProgram;
if (!increaseGranularity(Chunks)) {
errs() << "\nAlready at minimum size. Cannot reduce anymore.\n";
return;
}
bool FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity;
do {
UninterestingChunks = {};
for (int I = Chunks.size() - 1; I >= 0; --I) {
FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity = false;
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;
for (auto C : Chunks)
if (!UninterestingChunks.count(C) && C != Chunks[I])
CurrentChunks.push_back(C);
if (CurrentChunks.empty())
continue;
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<Module> Clone = CloneModule(*Test.getProgram());
@ -132,28 +134,30 @@ void llvm::runDeltaPass(
ExtractChunksFromModule(CurrentChunks, Clone.get());
errs() << "Ignoring: ";
Chunks[I].print();
for (auto C : UninterestingChunks)
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";
continue;
}
UninterestingChunks.insert(Chunks[I]);
FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity = true;
UninterestingChunks.insert(ChunkToCheckForUninterestingness);
ReducedProgram = std::move(Clone);
errs() << " **** SUCCESS | lines: " << getLines(CurrentFilepath) << "\n";
}
// Delete uninteresting chunks
erase_if(Chunks, [&UninterestingChunks](const Chunk &C) {
return UninterestingChunks.count(C);
});
} while (!UninterestingChunks.empty() || increaseGranularity(Chunks));
erase_if(ChunksStillConsideredInteresting,
[&UninterestingChunks](const Chunk &C) {
return UninterestingChunks.count(C);
});
} while (!ChunksStillConsideredInteresting.empty() &&
(FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity ||
increaseGranularity(ChunksStillConsideredInteresting)));
// If we reduced the testcase replace it
if (ReducedProgram)