[Mlir-commits] [mlir] [mlir] Avoid repeated map lookups (NFC) (PR #113074)

Kazu Hirata llvmlistbot at llvm.org
Sun Oct 20 08:50:50 PDT 2024


https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/113074

>From 516b43a1221b7b712dfbd91e79f2d1ce470e9315 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 19 Oct 2024 15:20:58 -0700
Subject: [PATCH 1/2] [mlir] Avoid repeated map lookups (NFC)

---
 mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
index 7b1b1f383e6343..c6e66ddbc7af9a 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
@@ -1160,9 +1160,8 @@ bool mlir::sparse_tensor::isBlockSparsity(AffineMap dimToLvl) {
     } else if (auto dimOp = dyn_cast<AffineDimExpr>(result)) {
       auto pos = dimOp.getPosition();
       // Expect dim to be unset.
-      if (coeffientMap.find(pos) != coeffientMap.end())
+      if (!coeffientMap.try_emplace(pos).second)
         return false;
-      coeffientMap[pos] = 0;
     } else {
       return false;
     }

>From a7d81b2bb8703a8bafeb0a46894164bccb5f6cdf Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 20 Oct 2024 08:48:20 -0700
Subject: [PATCH 2/2] Specify the value explicitly.

---
 mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
index c6e66ddbc7af9a..32e1dcbc2cce28 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
@@ -1160,7 +1160,7 @@ bool mlir::sparse_tensor::isBlockSparsity(AffineMap dimToLvl) {
     } else if (auto dimOp = dyn_cast<AffineDimExpr>(result)) {
       auto pos = dimOp.getPosition();
       // Expect dim to be unset.
-      if (!coeffientMap.try_emplace(pos).second)
+      if (!coeffientMap.try_emplace(pos, 0).second)
         return false;
     } else {
       return false;



More information about the Mlir-commits mailing list