@@ -170,16 +170,11 @@ namespace {
170
170
/// back and when processing we pop off of the back.
171
171
///
172
172
/// The worklist will not contain duplicates but may contain null entries
173
- /// due to nodes being deleted from the underlying DAG.
173
+ /// due to nodes being deleted from the underlying DAG. For fast lookup and
174
+ /// deduplication, the index of the node in this vector is stored in the
175
+ /// node in SDNode::CombinerWorklistIndex.
174
176
SmallVector<SDNode *, 64> Worklist;
175
177
176
- /// Mapping from an SDNode to its position on the worklist.
177
- ///
178
- /// This is used to find and remove nodes from the worklist (by nulling
179
- /// them) when they are deleted from the underlying DAG. It relies on
180
- /// stable indices of nodes within the worklist.
181
- DenseMap<SDNode *, unsigned> WorklistMap;
182
-
183
178
/// This records all nodes attempted to be added to the worklist since we
184
179
/// considered a new worklist entry. As we keep do not add duplicate nodes
185
180
/// in the worklist, this is different from the tail of the worklist.
@@ -238,10 +233,9 @@ namespace {
238
233
}
239
234
240
235
if (N) {
241
- bool GoodWorklistEntry = WorklistMap.erase(N);
242
- (void)GoodWorklistEntry;
243
- assert(GoodWorklistEntry &&
236
+ assert(N->getCombinerWorklistIndex() >= 0 &&
244
237
"Found a worklist entry without a corresponding map entry!");
238
+ N->setCombinerWorklistIndex(-1);
245
239
}
246
240
return N;
247
241
}
@@ -285,8 +279,10 @@ namespace {
285
279
if (IsCandidateForPruning)
286
280
ConsiderForPruning(N);
287
281
288
- if (WorklistMap.insert(std::make_pair(N, Worklist.size())).second)
282
+ if (N->getCombinerWorklistIndex() == -1) {
283
+ N->setCombinerWorklistIndex(Worklist.size());
289
284
Worklist.push_back(N);
285
+ }
290
286
}
291
287
292
288
/// Remove all instances of N from the worklist.
@@ -295,13 +291,13 @@ namespace {
295
291
PruningList.remove(N);
296
292
StoreRootCountMap.erase(N);
297
293
298
- auto It = WorklistMap.find(N );
299
- if (It == WorklistMap.end() )
294
+ int WorklistIndex = N->getCombinerWorklistIndex( );
295
+ if (WorklistIndex == -1 )
300
296
return; // Not in the worklist.
301
297
302
298
// Null out the entry rather than erasing it to avoid a linear operation.
303
- Worklist[It->second ] = nullptr;
304
- WorklistMap.erase(It );
299
+ Worklist[WorklistIndex ] = nullptr;
300
+ N->setCombinerWorklistIndex(-1 );
305
301
}
306
302
307
303
void deleteAndRecombine(SDNode *N);
0 commit comments