@@ -116,6 +116,58 @@ static bool increaseGranularity(std::vector<Chunk> &Chunks) {
116
116
}
117
117
return SplitOne;
118
118
}
119
+ // Check if \p ChunkToCheckForUninterestingness is interesting. Returns the
120
+ // modified module if the chunk resulted in a reduction.
121
+ template <typename T>
122
+ static std::unique_ptr<ReducerWorkItem>
123
+ CheckChunk (Chunk &ChunkToCheckForUninterestingness, TestRunner &Test,
124
+ function_ref<void (Oracle &, T &)> ExtractChunksFromModule,
125
+ std::set<Chunk> &UninterestingChunks,
126
+ std::vector<Chunk> &ChunksStillConsideredInteresting) {
127
+ // Take all of ChunksStillConsideredInteresting chunks, except those we've
128
+ // already deemed uninteresting (UninterestingChunks) but didn't remove
129
+ // from ChunksStillConsideredInteresting yet, and additionally ignore
130
+ // ChunkToCheckForUninterestingness chunk.
131
+ std::vector<Chunk> CurrentChunks;
132
+ CurrentChunks.reserve (ChunksStillConsideredInteresting.size () -
133
+ UninterestingChunks.size () - 1 );
134
+ copy_if (ChunksStillConsideredInteresting, std::back_inserter (CurrentChunks),
135
+ [&](const Chunk &C) {
136
+ return !UninterestingChunks.count (C) &&
137
+ C != ChunkToCheckForUninterestingness;
138
+ });
139
+
140
+ // Clone module before hacking it up..
141
+ std::unique_ptr<ReducerWorkItem> Clone =
142
+ cloneReducerWorkItem (Test.getProgram ());
143
+ // Generate Module with only Targets inside Current Chunks
144
+ Oracle O (CurrentChunks);
145
+ ExtractChunksFromModule (O, *Clone);
146
+
147
+ // Some reductions may result in invalid IR. Skip such reductions.
148
+ if (verifyReducerWorkItem (*Clone, &errs ())) {
149
+ if (AbortOnInvalidReduction) {
150
+ errs () << " Invalid reduction\n " ;
151
+ exit (1 );
152
+ }
153
+ errs () << " **** WARNING | reduction resulted in invalid module, "
154
+ " skipping\n " ;
155
+ return nullptr ;
156
+ }
157
+
158
+ errs () << " Ignoring: " ;
159
+ ChunkToCheckForUninterestingness.print ();
160
+ for (const Chunk &C : UninterestingChunks)
161
+ C.print ();
162
+
163
+ SmallString<128 > CurrentFilepath;
164
+ if (!isReduced (*Clone, Test, CurrentFilepath)) {
165
+ // Program became non-reduced, so this chunk appears to be interesting.
166
+ errs () << " \n " ;
167
+ return nullptr ;
168
+ }
169
+ return Clone;
170
+ }
119
171
120
172
// / Runs the Delta Debugging algorithm, splits the code into chunks and
121
173
// / reduces the amount of chunks that are considered interesting by the
@@ -162,52 +214,15 @@ void runDeltaPassInt(
162
214
std::set<Chunk> UninterestingChunks;
163
215
for (Chunk &ChunkToCheckForUninterestingness :
164
216
reverse (ChunksStillConsideredInteresting)) {
165
- // Take all of ChunksStillConsideredInteresting chunks, except those we've
166
- // already deemed uninteresting (UninterestingChunks) but didn't remove
167
- // from ChunksStillConsideredInteresting yet, and additionally ignore
168
- // ChunkToCheckForUninterestingness chunk.
169
- std::vector<Chunk> CurrentChunks;
170
- CurrentChunks.reserve (ChunksStillConsideredInteresting.size () -
171
- UninterestingChunks.size () - 1 );
172
- copy_if (ChunksStillConsideredInteresting,
173
- std::back_inserter (CurrentChunks), [&](const Chunk &C) {
174
- return !UninterestingChunks.count (C) &&
175
- C != ChunkToCheckForUninterestingness;
176
- });
177
-
178
- // Clone module before hacking it up..
179
- std::unique_ptr<ReducerWorkItem> Clone =
180
- cloneReducerWorkItem (Test.getProgram ());
181
- // Generate Module with only Targets inside Current Chunks
182
- Oracle O (CurrentChunks);
183
- ExtractChunksFromModule (O, *Clone);
184
-
185
- // Some reductions may result in invalid IR. Skip such reductions.
186
- if (verifyReducerWorkItem (*Clone, &errs ())) {
187
- if (AbortOnInvalidReduction) {
188
- errs () << " Invalid reduction\n " ;
189
- exit (1 );
190
- }
191
- errs () << " **** WARNING | reduction resulted in invalid module, "
192
- " skipping\n " ;
193
- continue ;
194
- }
195
-
196
- errs () << " Ignoring: " ;
197
- ChunkToCheckForUninterestingness.print ();
198
- for (const Chunk &C : UninterestingChunks)
199
- C.print ();
200
-
201
- SmallString<128 > CurrentFilepath;
202
- if (!isReduced (*Clone, Test, CurrentFilepath)) {
203
- // Program became non-reduced, so this chunk appears to be interesting.
204
- errs () << " \n " ;
217
+ std::unique_ptr<ReducerWorkItem> Result = CheckChunk (
218
+ ChunkToCheckForUninterestingness, Test, ExtractChunksFromModule,
219
+ UninterestingChunks, ChunksStillConsideredInteresting);
220
+ if (!Result)
205
221
continue ;
206
- }
207
222
208
223
FoundAtLeastOneNewUninterestingChunkWithCurrentGranularity = true ;
209
224
UninterestingChunks.insert (ChunkToCheckForUninterestingness);
210
- ReducedProgram = std::move (Clone );
225
+ ReducedProgram = std::move (Result );
211
226
errs () << " **** SUCCESS | lines: " << getLines (CurrentFilepath) << " \n " ;
212
227
writeOutput (*ReducedProgram, " Saved new best reduction to " );
213
228
}
0 commit comments