diff --git a/mlir/lib/TableGen/Operator.cpp b/mlir/lib/TableGen/Operator.cpp --- a/mlir/lib/TableGen/Operator.cpp +++ b/mlir/lib/TableGen/Operator.cpp @@ -498,29 +498,33 @@ } // Propagate inferredness until a fixed point. - std::list worklist; + std::vector worklist; for (ResultTypeInference &infer : inference) if (!infer.inferred) worklist.push_back(&infer); bool changed; do { changed = false; - // This is `llvm::make_early_inc_range` but keeps the iterator for erasing. - for (auto earlyIncIt = worklist.begin(), cur = earlyIncIt; - cur = earlyIncIt++, cur != worklist.end();) { + for (auto cur = worklist.begin(); cur != worklist.end();) { ResultTypeInference &infer = **cur; - for (auto &[idx, source] : llvm::enumerate(infer.sources)) { - assert(InferredResultType::isResultIndex(source.getIndex())); - if (inference[InferredResultType::unmapResultIndex(source.getIndex())] - .inferred) { - changed = true; - infer.inferred = true; - // Make this the only source for the result. This breaks any cycles. - infer.sources.assign(1, source); - worklist.erase(cur); - break; - } + + InferredResultType *iter = + llvm::find_if(infer.sources, [&](const InferredResultType &source) { + assert(InferredResultType::isResultIndex(source.getIndex())); + return inference[InferredResultType::unmapResultIndex( + source.getIndex())] + .inferred; + }); + if (iter == infer.sources.end()) { + ++cur; + continue; } + + changed = true; + infer.inferred = true; + // Make this the only source for the result. This breaks any cycles. + infer.sources.assign(1, *iter); + cur = worklist.erase(cur); } } while (changed);