[Mlir-commits] [mlir] e1286d9 - [mlir] Deterministic containers in BytecodeWriter (#187819)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Mar 22 16:15:24 PDT 2026
Author: Colin He
Date: 2026-03-22T16:15:17-07:00
New Revision: e1286d963eeba241e2b1b67f3b1e716dfab83d95
URL: https://github.com/llvm/llvm-project/commit/e1286d963eeba241e2b1b67f3b1e716dfab83d95
DIFF: https://github.com/llvm/llvm-project/commit/e1286d963eeba241e2b1b67f3b1e716dfab83d95.diff
LOG: [mlir] Deterministic containers in BytecodeWriter (#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.
Added:
Modified:
mlir/lib/Bytecode/Writer/BytecodeWriter.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp b/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp
index a04e3c3e3f177..e32f8730f7d71 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;
+ llvm::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