[Mlir-commits] [mlir] 43c35e8 - [mlir] Simplify calls to *Map::{insert, try_emplace} (NFC) (#143729)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jun 11 12:50:38 PDT 2025
Author: Kazu Hirata
Date: 2025-06-11T12:50:35-07:00
New Revision: 43c35e858ccae05d69151ccf9712a725aae37b52
URL: https://github.com/llvm/llvm-project/commit/43c35e858ccae05d69151ccf9712a725aae37b52
DIFF: https://github.com/llvm/llvm-project/commit/43c35e858ccae05d69151ccf9712a725aae37b52.diff
LOG: [mlir] Simplify calls to *Map::{insert,try_emplace} (NFC) (#143729)
This patch simplifies code by removing the values from
insert/try_emplace. Note that default values inserted by try_emplace
are immediately overrideen in all these cases.
Added:
Modified:
mlir/lib/IR/AsmPrinter.cpp
mlir/lib/IR/SymbolTable.cpp
mlir/lib/Transforms/Utils/CFGToSCF.cpp
Removed:
################################################################################
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index fc1806900c0aa..c7cc6a02ad208 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -1146,8 +1146,7 @@ template <typename T, typename... PrintArgs>
std::pair<size_t, size_t> AliasInitializer::visitImpl(
T value, llvm::MapVector<const void *, InProgressAliasInfo> &aliases,
bool canBeDeferred, PrintArgs &&...printArgs) {
- auto [it, inserted] =
- aliases.insert({value.getAsOpaquePointer(), InProgressAliasInfo()});
+ auto [it, inserted] = aliases.try_emplace(value.getAsOpaquePointer());
size_t aliasIndex = std::distance(aliases.begin(), it);
if (!inserted) {
// Make sure that the alias isn't deferred if we don't permit it.
diff --git a/mlir/lib/IR/SymbolTable.cpp b/mlir/lib/IR/SymbolTable.cpp
index 075a0ba15d7cd..aaa4d5617eb4f 100644
--- a/mlir/lib/IR/SymbolTable.cpp
+++ b/mlir/lib/IR/SymbolTable.cpp
@@ -1100,7 +1100,7 @@ void SymbolUserMap::replaceAllUsesWith(Operation *symbol,
if (newSymbol != symbol) {
// Transfer over the users to the new symbol. The reference to the old one
// is fetched again as the iterator is invalidated during the insertion.
- auto newIt = symbolToUsers.try_emplace(newSymbol, SetVector<Operation *>{});
+ auto newIt = symbolToUsers.try_emplace(newSymbol);
auto oldIt = symbolToUsers.find(symbol);
assert(oldIt != symbolToUsers.end() && "missing old users list");
if (newIt.second)
diff --git a/mlir/lib/Transforms/Utils/CFGToSCF.cpp b/mlir/lib/Transforms/Utils/CFGToSCF.cpp
index de380fc325f55..7c1781044d2a2 100644
--- a/mlir/lib/Transforms/Utils/CFGToSCF.cpp
+++ b/mlir/lib/Transforms/Utils/CFGToSCF.cpp
@@ -709,7 +709,7 @@ transformToReduceLoop(Block *loopHeader, Block *exitBlock,
llvm::SmallDenseMap<Block *, bool> dominanceCache;
// Returns true if `loopBlock` dominates `block`.
auto loopBlockDominates = [&](Block *block) {
- auto [iter, inserted] = dominanceCache.insert({block, false});
+ auto [iter, inserted] = dominanceCache.try_emplace(block);
if (!inserted)
return iter->second;
iter->second = dominanceInfo.dominates(loopBlock, block);
More information about the Mlir-commits
mailing list