[Mlir-commits] [mlir] [mlir] Deterministic containers in BytecodeWriter (PR #187819)
Colin He
llvmlistbot at llvm.org
Fri Mar 20 16:03:15 PDT 2026
https://github.com/CPlusMinus2000 created https://github.com/llvm/llvm-project/pull/187819
Iteration over use lists in writeUseListOrders is non-deterministic as a result of using a DenseMap. Replacing with a Vector-backed `MapVector` restores deterministic behaviour.
>From 5c9bb3158c6f200e09361dda5d3ac5d2ee139c1d Mon Sep 17 00:00:00 2001
From: Colin He <hcolin88 at gmail.com>
Date: Fri, 20 Mar 2026 15:43:07 -0700
Subject: [PATCH] [mlir] Deterministic containers in BytecodeWriter
---
mlir/lib/Bytecode/Writer/BytecodeWriter.cpp | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp b/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp
index a04e3c3e3f177..6061d2adcbcec 100644
--- a/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp
+++ b/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp
@@ -1094,7 +1094,7 @@ void BytecodeWriter::writeUseListOrders(EncodingEmitter &emitter,
uint8_t &opEncodingMask,
ValueRange range) {
// Loop over the results and store the use-list order per result index.
- DenseMap<unsigned, llvm::SmallVector<unsigned>> map;
+ MapVector<unsigned, llvm::SmallVector<unsigned>> map;
for (auto item : llvm::enumerate(range)) {
auto value = item.value();
// No need to store a custom use-list order if the result does not have
@@ -1147,10 +1147,7 @@ void BytecodeWriter::writeUseListOrders(EncodingEmitter &emitter,
emitter.emitVarInt(map.size(), "custom use-list size");
}
- for (const auto &item : map) {
- auto resultIdx = item.getFirst();
- auto useListOrder = item.getSecond();
-
+ for (const auto &[resultIdx, useListOrder] : map) {
// Compute the number of uses that are actually shuffled. If those are less
// than half of the total uses, encoding the index pair `(src, dst)` is more
// space efficient.
More information about the Mlir-commits
mailing list