|
93 | 93 | #ifndef SWIFT_SILOPTIMIZER_UTILS_CANONICALOSSALIFETIME_H
|
94 | 94 | #define SWIFT_SILOPTIMIZER_UTILS_CANONICALOSSALIFETIME_H
|
95 | 95 |
|
| 96 | +#include "swift/Basic/DAGNodeWorklist.h" |
96 | 97 | #include "swift/Basic/SmallPtrSetVector.h"
|
97 | 98 | #include "swift/SIL/SILInstruction.h"
|
98 | 99 | #include "swift/SILOptimizer/Analysis/DominanceAnalysis.h"
|
@@ -220,50 +221,6 @@ class CanonicalOSSAConsumeInfo {
|
220 | 221 | SWIFT_ASSERT_ONLY_DECL(void dump() const LLVM_ATTRIBUTE_USED);
|
221 | 222 | };
|
222 | 223 |
|
223 |
| -// Worklist of pointer-like things that have an invalid default value. Avoid |
224 |
| -// revisiting nodes--suitable for DAGs, but pops finished nodes without |
225 |
| -// preserving them in the vector. |
226 |
| -// |
227 |
| -// The primary API has two methods: intialize() and pop(). Others are provided |
228 |
| -// for flexibility. |
229 |
| -// |
230 |
| -// TODO: make this a better utility. |
231 |
| -template <typename T, unsigned SmallSize> struct PtrWorklist { |
232 |
| - SmallPtrSet<T, SmallSize> ptrVisited; |
233 |
| - SmallVector<T, SmallSize> ptrVector; |
234 |
| - |
235 |
| - PtrWorklist() = default; |
236 |
| - |
237 |
| - PtrWorklist(const PtrWorklist &) = delete; |
238 |
| - |
239 |
| - void initialize(T t) { |
240 |
| - clear(); |
241 |
| - insert(t); |
242 |
| - } |
243 |
| - |
244 |
| - template <typename R> void initializeRange(R &&range) { |
245 |
| - clear(); |
246 |
| - ptrVisited.insert(range.begin(), range.end()); |
247 |
| - ptrVector.append(range.begin(), range.end()); |
248 |
| - } |
249 |
| - |
250 |
| - T pop() { return empty() ? T() : ptrVector.pop_back_val(); } |
251 |
| - |
252 |
| - bool empty() const { return ptrVector.empty(); } |
253 |
| - |
254 |
| - unsigned size() const { return ptrVector.size(); } |
255 |
| - |
256 |
| - void clear() { |
257 |
| - ptrVector.clear(); |
258 |
| - ptrVisited.clear(); |
259 |
| - } |
260 |
| - |
261 |
| - void insert(T t) { |
262 |
| - if (ptrVisited.insert(t).second) |
263 |
| - ptrVector.push_back(t); |
264 |
| - } |
265 |
| -}; |
266 |
| - |
267 | 224 | /// Canonicalize OSSA lifetimes.
|
268 | 225 | ///
|
269 | 226 | /// Allows the allocation of analysis state to be reused across calls to
|
@@ -315,11 +272,11 @@ class CanonicalizeOSSALifetime {
|
315 | 272 | /// outisde the pruned liveness at the time it is discovered.
|
316 | 273 | llvm::SmallPtrSet<DebugValueInst *, 8> debugValues;
|
317 | 274 |
|
318 |
| - /// Reuse a general visited set for def-use traversal. |
319 |
| - PtrWorklist<SILValue, 8> defUseWorklist; |
| 275 | + /// Visited set for general def-use traversal that prevents revisiting values. |
| 276 | + DAGNodeWorklist<SILValue, 8> defUseWorklist; |
320 | 277 |
|
321 |
| - /// Reuse a general worklist for CFG traversal. |
322 |
| - PtrWorklist<SILBasicBlock *, 8> blockWorklist; |
| 278 | + /// Visited set general CFG traversal that prevents revisiting blocks. |
| 279 | + DAGNodeWorklist<SILBasicBlock *, 8> blockWorklist; |
323 | 280 |
|
324 | 281 | /// Pruned liveness for the extended live range including copies. For this
|
325 | 282 | /// purpose, only consuming instructions are considered "lifetime
|
|
0 commit comments