Skip to content

Commit

Permalink
[mlir] Avoid repeated map lookups (NFC) (llvm#113122)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata authored Oct 21, 2024
1 parent 1bf1e92 commit af6e188
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit af6e188

Please sign in to comment.