32
32
#include " mlir/IR/RegionKindInterface.h"
33
33
#include " mlir/IR/Threading.h"
34
34
#include " llvm/ADT/DenseMapInfoVariant.h"
35
+ #include " llvm/ADT/PointerIntPair.h"
35
36
#include " llvm/ADT/StringMap.h"
36
37
#include " llvm/Support/FormatVariadic.h"
37
38
#include " llvm/Support/PrettyStackTrace.h"
@@ -55,6 +56,7 @@ class OperationVerifier {
55
56
56
57
private:
57
58
using WorkItem = llvm::PointerUnion<Operation *, Block *>;
59
+ using WorkItemEntry = llvm::PointerIntPair<WorkItem, 1 , bool >;
58
60
59
61
// / This verifier uses a DFS of the tree of operations/blocks. The method
60
62
// / verifyOnEntrance is invoked when we visit a node for the first time, i.e.
@@ -267,35 +269,38 @@ LogicalResult OperationVerifier::verifyOnExit(Operation &op) {
267
269
// / Such ops are collected separately and verified inside
268
270
// / verifyBlockPostChildren.
269
271
LogicalResult OperationVerifier::verifyOperation (Operation &op) {
270
- SmallVector<WorkItem> worklist{{&op}};
271
- SmallPtrSet<WorkItem, 8 > seen;
272
+ SmallVector<WorkItemEntry> worklist{{&op, false }};
272
273
while (!worklist.empty ()) {
273
- WorkItem top = worklist.back ();
274
+ WorkItemEntry & top = worklist.back ();
274
275
275
276
auto visit = [](auto &&visitor, WorkItem w) {
276
277
if (w.is <Operation *>())
277
278
return visitor (w.get <Operation *>());
278
279
return visitor (w.get <Block *>());
279
280
};
280
281
281
- const bool isExit = !seen.insert (top).second ;
282
+ const bool isExit = top.getInt ();
283
+ top.setInt (true );
284
+ auto item = top.getPointer ();
285
+
282
286
// 2nd visit of this work item ("exit").
283
287
if (isExit) {
284
- worklist. pop_back ();
285
- if ( failed ( visit (
286
- [ this ]( auto *workItem) { return verifyOnExit (*workItem); }, top )))
288
+ if ( failed (
289
+ visit ([ this ]( auto *workItem) { return verifyOnExit (*workItem); },
290
+ item )))
287
291
return failure ();
292
+ worklist.pop_back ();
288
293
continue ;
289
294
}
290
295
291
296
// 1st visit of this work item ("entrance").
292
297
if (failed (visit (
293
298
[this ](auto *workItem) { return verifyOnEntrance (*workItem); },
294
- top )))
299
+ item )))
295
300
return failure ();
296
301
297
- if (top .is <Block *>()) {
298
- Block ¤tBlock = *top .get <Block *>();
302
+ if (item .is <Block *>()) {
303
+ Block ¤tBlock = *item .get <Block *>();
299
304
// Skip "isolated from above operations".
300
305
for (Operation &o : llvm::reverse (currentBlock)) {
301
306
if (o.getNumRegions () == 0 ||
@@ -305,7 +310,7 @@ LogicalResult OperationVerifier::verifyOperation(Operation &op) {
305
310
continue ;
306
311
}
307
312
308
- Operation ¤tOp = *top .get <Operation *>();
313
+ Operation ¤tOp = *item .get <Operation *>();
309
314
if (verifyRecursively)
310
315
for (Region ®ion : llvm::reverse (currentOp.getRegions ()))
311
316
for (Block &block : llvm::reverse (region))
0 commit comments