[Mlir-commits] [mlir] dda15ad - [mlir][spirv] Use MapVector for BlockMergeInfoMap (#169636)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Dec 1 01:43:29 PST 2025
Author: Igor Wodiany
Date: 2025-12-01T09:43:25Z
New Revision: dda15ad0aadf0bf485498e3d5f22e5caf94925e5
URL: https://github.com/llvm/llvm-project/commit/dda15ad0aadf0bf485498e3d5f22e5caf94925e5
DIFF: https://github.com/llvm/llvm-project/commit/dda15ad0aadf0bf485498e3d5f22e5caf94925e5.diff
LOG: [mlir][spirv] Use MapVector for BlockMergeInfoMap (#169636)
This should ensure that the structurizer while loop is deterministic
across runs. Use of `MapVector` addresses the source of the
nondeterminism which is use of a `Block*` as a map key.
fixes #128547
Added:
Modified:
mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
mlir/lib/Target/SPIRV/Deserialization/Deserializer.h
Removed:
################################################################################
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index 252be796488c5..d08e7ecf326ca 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -2923,9 +2923,6 @@ LogicalResult spirv::Deserializer::structurizeControlFlow() {
return failure();
}
- // TODO: This loop is non-deterministic. Iteration order may vary between runs
- // for the same shader as the key to the map is a pointer. See:
- // https://github.com/llvm/llvm-project/issues/128547
while (!blockMergeInfo.empty()) {
Block *headerBlock = blockMergeInfo.begin()->first;
BlockMergeInfo mergeInfo = blockMergeInfo.begin()->second;
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h
index 243e6fd70ae43..6d09d556c4d02 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h
@@ -58,7 +58,9 @@ struct DebugLine {
};
/// Map from a selection/loop's header block to its merge (and continue) target.
-using BlockMergeInfoMap = DenseMap<Block *, BlockMergeInfo>;
+/// Use `MapVector<>` to ensure a deterministic iteration order with a pointer
+/// key.
+using BlockMergeInfoMap = llvm::MapVector<Block *, BlockMergeInfo>;
/// A "deferred struct type" is a struct type with one or more member types not
/// known when the Deserializer first encounters the struct. This happens, for
More information about the Mlir-commits
mailing list