[Mlir-commits] [mlir] [MLIR][NFC] Drop sentinel leftovers from DenseMapInfo<Remark> (PR #224612)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Sep 18 05:07:33 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-core

Author: Henrich Lauko (xlauko)

<details>
<summary>Changes</summary>

`DenseMap` no longer uses sentinel keys, and the `getEmptyKey` and `getTombstoneKey` members of `DenseMapInfo<Remark>` were removed in #<!-- -->200633 and #<!-- -->201991. Two leftovers stayed behind: the `"<EMPTY_KEY>"` comparison at the top of `isEqual`, and the static dummy `MLIRContext` that used to back the sentinel remarks.

The comparison is not only dead weight. A remark literally named `<EMPTY_KEY>` compares unequal to any other remark, including one with a matching hash, which breaks the hash and equality contract. This change removes both leftovers and adds a comment stating what the specialization compares: location, remark name, combined category name and kind.

No behaviour change for any remark with a normal name. Existing Remark unit tests and `mlir/test/Pass/remark-final.mlir` cover the specialization through `RemarkEmittingPolicyFinal`.

Assisted-by: Claude Code (Claude Fable 5.1). I read and reviewed the change before opening it.


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


1 Files Affected:

- (modified) mlir/include/mlir/IR/Remarks.h (+2-17) 


``````````diff
diff --git a/mlir/include/mlir/IR/Remarks.h b/mlir/include/mlir/IR/Remarks.h
index 81073efa4e0263..c2408e0c0bc5e2 100644
--- a/mlir/include/mlir/IR/Remarks.h
+++ b/mlir/include/mlir/IR/Remarks.h
@@ -760,20 +760,11 @@ LogicalResult enableOptimizationRemarks(
 
 } // namespace mlir::remark
 
-// DenseMapInfo specialization for Remark
+/// Two remarks are the same for RemarkEmittingPolicyFinal when they have the
+/// same location, remark name, combined category name and kind.
 namespace llvm {
 template <>
 struct DenseMapInfo<mlir::remark::detail::Remark> {
-  static constexpr StringRef kEmptyKey = "<EMPTY_KEY>";
-
-  /// Helper to provide a static dummy context for sentinel keys.
-  static mlir::MLIRContext *getStaticDummyContext() {
-    static mlir::MLIRContext dummyContext;
-    return &dummyContext;
-  }
-
-  /// Create an empty remark
-  /// Compute the hash value of the remark
   static unsigned getHashValue(const mlir::remark::detail::Remark &remark) {
     return llvm::hash_combine(
         remark.getLocation().getAsOpaquePointer(),
@@ -784,12 +775,6 @@ struct DenseMapInfo<mlir::remark::detail::Remark> {
 
   static bool isEqual(const mlir::remark::detail::Remark &lhs,
                       const mlir::remark::detail::Remark &rhs) {
-    // Check for empty keys first.
-    if (lhs.getRemarkName() == kEmptyKey || rhs.getRemarkName() == kEmptyKey) {
-      return lhs.getRemarkName() == rhs.getRemarkName();
-    }
-
-    // For regular remarks, compare key identifying fields
     return lhs.getLocation() == rhs.getLocation() &&
            lhs.getRemarkName() == rhs.getRemarkName() &&
            lhs.getCombinedCategoryName() == rhs.getCombinedCategoryName() &&

``````````

</details>


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


More information about the Mlir-commits mailing list