Skip to content

Commit fbfd327

Browse files
Dwight Guthaeubanks
authored andcommitted
[llvm-reduce] Add flag to start at finer granularity
Sometimes if llvm-reduce is interrupted in the middle of a delta pass on a large file, it can take quite some time for the tool to start actually doing new work if it is restarted again on the partially-reduced file. A lot of time ends up being spent testing large chunks when these large chunks are very unlikely to actually pass the interestingness test. In cases like this, the tool will complete faster if the starting granularity is reduced to a finer amount. Thus, we introduce a command line flag that automatically divides the chunks into smaller subsets a fixed, user-specified number of times prior to beginning the core loop. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D112651
1 parent c296609 commit fbfd327

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; Test that llvm-reduce produces the same output when starting at a higher granularity level.
2+
;
3+
; RUN: llvm-reduce --delta-passes=functions,instructions --starting-granularity-level=2 --test FileCheck --test-arg --check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
4+
; RUN: cat %t | FileCheck -implicit-check-not=uninteresting --check-prefixes=CHECK-ALL,CHECK-FINAL %s
5+
6+
define i32 @uninteresting1() {
7+
entry:
8+
ret i32 0
9+
}
10+
11+
; CHECK-ALL-LABEL: interesting()
12+
define i32 @interesting() {
13+
entry:
14+
; CHECK-INTERESTINGNESS: call i32 @interesting()
15+
%call2 = call i32 @interesting()
16+
%call = call i32 @uninteresting1()
17+
ret i32 5
18+
}
19+
20+
; CHECK-FINAL-NEXT: entry:
21+
; CHECK-FINAL-NEXT: %call2 = call i32 @interesting()
22+
; CHECK-FINAL-NEXT: ret i32 5
23+
; CHECK-FINAL-NEXT: }
24+
25+
define i32 @uninteresting2() {
26+
entry:
27+
ret i32 0
28+
}
29+
30+
declare void @uninteresting3()

llvm/tools/llvm-reduce/deltas/Delta.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ static cl::opt<bool> AbortOnInvalidReduction(
2727
"abort-on-invalid-reduction",
2828
cl::desc("Abort if any reduction results in invalid IR"));
2929

30+
static cl::opt<unsigned int> StartingGranularityLevel(
31+
"starting-granularity-level",
32+
cl::desc("Number of times to divide chunks prior to first test"));
33+
3034
void writeOutput(ReducerWorkItem &M, llvm::StringRef Message);
3135

3236
bool isReduced(ReducerWorkItem &M, TestRunner &Test,
@@ -118,6 +122,10 @@ void runDeltaPassInt(
118122
std::vector<Chunk> ChunksStillConsideredInteresting = {{1, Targets}};
119123
std::unique_ptr<ReducerWorkItem> ReducedProgram;
120124

125+
for (unsigned int Level = 0; Level < StartingGranularityLevel; Level++) {
126+
increaseGranularity(ChunksStillConsideredInteresting);
127+
}
128+
121129
bool FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity;
122130
do {
123131
FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity = false;

0 commit comments

Comments
 (0)