[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.
This commit is contained in:
Colin He 2026-03-22 16:15:17 -07:00 committed by GitHub
parent 98f84f9bf2
commit e1286d963e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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.