[Mlir-commits] [mlir] [mlir][DataLayout] Keep consistent input/output order (PR #135185)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Apr 10 07:22:37 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: None (darkbuck)

<details>
<summary>Changes</summary>

- Use 'MapVector' instead of 'DenseMap' to keep a consistent order when importing/printing entries to prevent run-by-run differences.

---
Full diff: https://github.com/llvm/llvm-project/pull/135185.diff


2 Files Affected:

- (modified) mlir/lib/Dialect/DLTI/DLTI.cpp (+9-9) 
- (modified) mlir/lib/Target/LLVMIR/DataLayoutImporter.h (+3-2) 


``````````diff
diff --git a/mlir/lib/Dialect/DLTI/DLTI.cpp b/mlir/lib/Dialect/DLTI/DLTI.cpp
index 206d9f43a44a4..00cbd32708f1e 100644
--- a/mlir/lib/Dialect/DLTI/DLTI.cpp
+++ b/mlir/lib/Dialect/DLTI/DLTI.cpp
@@ -14,8 +14,8 @@
 #include "mlir/IR/BuiltinTypes.h"
 #include "mlir/IR/Dialect.h"
 #include "mlir/IR/DialectImplementation.h"
-#include "llvm/ADT/TypeSwitch.h"
 
+#include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/TypeSwitch.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/MathExtras.h"
@@ -293,16 +293,16 @@ overwriteDuplicateEntries(SmallVectorImpl<DataLayoutEntryInterface> &oldEntries,
 /// Combines a data layout spec into the given lists of entries organized by
 /// type class and identifier, overwriting them if necessary. Fails to combine
 /// if the two entries with identical keys are not compatible.
-static LogicalResult
-combineOneSpec(DataLayoutSpecInterface spec,
-               DenseMap<TypeID, DataLayoutEntryList> &entriesForType,
-               DenseMap<StringAttr, DataLayoutEntryInterface> &entriesForID) {
+static LogicalResult combineOneSpec(
+    DataLayoutSpecInterface spec,
+    llvm::MapVector<TypeID, DataLayoutEntryList> &entriesForType,
+    llvm::MapVector<StringAttr, DataLayoutEntryInterface> &entriesForID) {
   // A missing spec should be fine.
   if (!spec)
     return success();
 
-  DenseMap<TypeID, DataLayoutEntryList> newEntriesForType;
-  DenseMap<StringAttr, DataLayoutEntryInterface> newEntriesForID;
+  llvm::MapVector<TypeID, DataLayoutEntryList> newEntriesForType;
+  llvm::MapVector<StringAttr, DataLayoutEntryInterface> newEntriesForID;
   spec.bucketEntriesByType(newEntriesForType, newEntriesForID);
 
   // Combine non-Type DL entries first so they are visible to the
@@ -362,8 +362,8 @@ DataLayoutSpecAttr::combineWith(ArrayRef<DataLayoutSpecInterface> specs) const {
     return {};
 
   // Combine all specs in order, with `this` being the last one.
-  DenseMap<TypeID, DataLayoutEntryList> entriesForType;
-  DenseMap<StringAttr, DataLayoutEntryInterface> entriesForID;
+  llvm::MapVector<TypeID, DataLayoutEntryList> entriesForType;
+  llvm::MapVector<StringAttr, DataLayoutEntryInterface> entriesForID;
   for (DataLayoutSpecInterface spec : specs)
     if (failed(combineOneSpec(spec, entriesForType, entriesForID)))
       return nullptr;
diff --git a/mlir/lib/Target/LLVMIR/DataLayoutImporter.h b/mlir/lib/Target/LLVMIR/DataLayoutImporter.h
index 206c8dd486adb..491ff65f17a41 100644
--- a/mlir/lib/Target/LLVMIR/DataLayoutImporter.h
+++ b/mlir/lib/Target/LLVMIR/DataLayoutImporter.h
@@ -17,6 +17,7 @@
 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
 #include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/Interfaces/DataLayoutInterfaces.h"
+#include "llvm/ADT/MapVector.h"
 
 namespace llvm {
 class StringRef;
@@ -110,8 +111,8 @@ class DataLayoutImporter {
   std::string layoutStr = {};
   StringRef lastToken = {};
   SmallVector<StringRef> unhandledTokens;
-  DenseMap<StringAttr, DataLayoutEntryInterface> keyEntries;
-  DenseMap<TypeAttr, DataLayoutEntryInterface> typeEntries;
+  llvm::MapVector<StringAttr, DataLayoutEntryInterface> keyEntries;
+  llvm::MapVector<TypeAttr, DataLayoutEntryInterface> typeEntries;
   MLIRContext *context;
   DataLayoutSpecInterface dataLayout;
 };

``````````

</details>


https://github.com/llvm/llvm-project/pull/135185


More information about the Mlir-commits mailing list