[Mlir-commits] [mlir] af6e188 - [mlir] Avoid repeated map lookups (NFC) (#113122)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Oct 21 06:52:27 PDT 2024
Author: Kazu Hirata
Date: 2024-10-21T06:52:24-07:00
New Revision: af6e1881e0791ac1ee611b62a3d12d9fb03ca142
URL: https://github.com/llvm/llvm-project/commit/af6e1881e0791ac1ee611b62a3d12d9fb03ca142
DIFF: https://github.com/llvm/llvm-project/commit/af6e1881e0791ac1ee611b62a3d12d9fb03ca142.diff
LOG: [mlir] Avoid repeated map lookups (NFC) (#113122)
Added:
Modified:
mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
index 32e1dcbc2cce28..9854cfcc279b57 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
@@ -1142,16 +1142,18 @@ bool mlir::sparse_tensor::isBlockSparsity(AffineMap dimToLvl) {
auto pos = dimOp.getPosition();
if (binOp.getKind() == AffineExprKind::FloorDiv) {
// Expect only one floordiv for each dimension.
- if (coeffientMap.find(pos) != coeffientMap.end())
+ auto [it, inserted] = coeffientMap.try_emplace(pos);
+ if (!inserted)
return false;
// Record coefficient of the floordiv.
- coeffientMap[pos] = conOp.getValue();
+ it->second = conOp.getValue();
} else if (binOp.getKind() == AffineExprKind::Mod) {
// Expect floordiv before mod.
- if (coeffientMap.find(pos) == coeffientMap.end())
+ auto it = coeffientMap.find(pos);
+ if (it == coeffientMap.end())
return false;
// Expect mod to have the same coefficient as floordiv.
- if (conOp.getValue() != coeffientMap[pos])
+ if (conOp.getValue() != it->second)
return false;
hasBlock = true;
} else {
More information about the Mlir-commits
mailing list