-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] Use *Map::try_emplace (NFC) #143341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_20250608_try_emplace_default_mlir
Jun 9, 2025
Merged
[mlir] Use *Map::try_emplace (NFC) #143341
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_20250608_try_emplace_default_mlir
Jun 9, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
kazutakahirata
commented
Jun 9, 2025
- try_emplace(Key) is shorter than insert({Key, nullptr}).
- try_emplace performs value initialization without value parameters.
- We overwrite values on successful insertion anyway.
- try_emplace(Key) is shorter than insert({Key, nullptr}). - try_emplace performs value initialization without value parameters. - We overwrite values on successful insertion anyway.
@llvm/pr-subscribers-mlir-llvm @llvm/pr-subscribers-mlir Author: Kazu Hirata (kazutakahirata) Changes
Full diff: https://github.com/llvm/llvm-project/pull/143341.diff 6 Files Affected:
diff --git a/mlir/include/mlir/Debug/BreakpointManagers/TagBreakpointManager.h b/mlir/include/mlir/Debug/BreakpointManagers/TagBreakpointManager.h
index 85fdb9a63286a..af138da84e028 100644
--- a/mlir/include/mlir/Debug/BreakpointManagers/TagBreakpointManager.h
+++ b/mlir/include/mlir/Debug/BreakpointManagers/TagBreakpointManager.h
@@ -48,7 +48,7 @@ class TagBreakpointManager
/// If a breakpoint already exists for the given tag, return the existing
/// instance.
TagBreakpoint *addBreakpoint(StringRef tag) {
- auto result = breakpoints.insert({tag, nullptr});
+ auto result = breakpoints.try_emplace(tag);
auto &it = result.first;
if (result.second)
it->second = std::make_unique<TagBreakpoint>(tag.str());
diff --git a/mlir/lib/Bytecode/Writer/IRNumbering.cpp b/mlir/lib/Bytecode/Writer/IRNumbering.cpp
index 1bc02e1721573..8e8e7148ee70e 100644
--- a/mlir/lib/Bytecode/Writer/IRNumbering.cpp
+++ b/mlir/lib/Bytecode/Writer/IRNumbering.cpp
@@ -308,7 +308,7 @@ void IRNumberingState::computeGlobalNumberingState(Operation *rootOp) {
}
void IRNumberingState::number(Attribute attr) {
- auto it = attrs.insert({attr, nullptr});
+ auto it = attrs.try_emplace(attr);
if (!it.second) {
++it.first->second->refCount;
return;
@@ -475,7 +475,7 @@ void IRNumberingState::number(OperationName opName) {
}
void IRNumberingState::number(Type type) {
- auto it = types.insert({type, nullptr});
+ auto it = types.try_emplace(type);
if (!it.second) {
++it.first->second->refCount;
return;
diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
index 2ab6b6189b438..ce5e63a32dc72 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -810,7 +810,7 @@ OperationName::OperationName(StringRef name, MLIRContext *context) {
// Acquire a writer-lock so that we can safely create the new instance.
ScopedWriterLock lock(ctxImpl.operationInfoMutex, isMultithreadingEnabled);
- auto it = ctxImpl.operations.insert({name, nullptr});
+ auto it = ctxImpl.operations.try_emplace(name);
if (it.second) {
auto nameAttr = StringAttr::get(context, name);
it.first->second = std::make_unique<UnregisteredOpModel>(
diff --git a/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp b/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp
index 1dde457b5c34f..54ae01c77c445 100644
--- a/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp
@@ -280,7 +280,7 @@ LoopAnnotationTranslation::translateLoopAnnotation(LoopAnnotationAttr attr,
llvm::MDNode *
LoopAnnotationTranslation::getAccessGroup(AccessGroupAttr accessGroupAttr) {
auto [result, inserted] =
- accessGroupMetadataMapping.insert({accessGroupAttr, nullptr});
+ accessGroupMetadataMapping.try_emplace(accessGroupAttr);
if (inserted)
result->second = llvm::MDNode::getDistinct(llvmModule.getContext(), {});
return result->second;
diff --git a/mlir/lib/Transforms/Utils/CFGToSCF.cpp b/mlir/lib/Transforms/Utils/CFGToSCF.cpp
index eefdf1d4e393a..de380fc325f55 100644
--- a/mlir/lib/Transforms/Utils/CFGToSCF.cpp
+++ b/mlir/lib/Transforms/Utils/CFGToSCF.cpp
@@ -427,8 +427,7 @@ class ReturnLikeExitCombiner {
/// region with an instance of `returnLikeOp`s kind.
void combineExit(Operation *returnLikeOp,
function_ref<Value(unsigned)> getSwitchValue) {
- auto [iter, inserted] =
- returnLikeToCombinedExit.insert({returnLikeOp, nullptr});
+ auto [iter, inserted] = returnLikeToCombinedExit.try_emplace(returnLikeOp);
if (!inserted && iter->first == returnLikeOp)
return;
@@ -1284,7 +1283,7 @@ FailureOr<bool> mlir::transformCFGToSCF(Region ®ion,
DenseMap<Type, Value> typedUndefCache;
auto getUndefValue = [&](Type type) {
- auto [iter, inserted] = typedUndefCache.insert({type, nullptr});
+ auto [iter, inserted] = typedUndefCache.try_emplace(type);
if (!inserted)
return iter->second;
diff --git a/mlir/lib/Transforms/Utils/Inliner.cpp b/mlir/lib/Transforms/Utils/Inliner.cpp
index 54b5c788a3526..ae34c4ad49e24 100644
--- a/mlir/lib/Transforms/Utils/Inliner.cpp
+++ b/mlir/lib/Transforms/Utils/Inliner.cpp
@@ -45,7 +45,7 @@ static void walkReferencedSymbolNodes(
Operation *symbolTableOp = op->getParentOp();
for (const SymbolTable::SymbolUse &use : *symbolUses) {
- auto refIt = resolvedRefs.insert({use.getSymbolRef(), nullptr});
+ auto refIt = resolvedRefs.try_emplace(use.getSymbolRef());
CallGraphNode *&node = refIt.first->second;
// If this is the first instance of this reference, try to resolve a
|
tgymnich
approved these changes
Jun 9, 2025
rorth
pushed a commit
to rorth/llvm-project
that referenced
this pull request
Jun 11, 2025
- try_emplace(Key) is shorter than insert({Key, nullptr}). - try_emplace performs value initialization without value parameters. - We overwrite values on successful insertion anyway.
DhruvSrivastavaX
pushed a commit
to DhruvSrivastavaX/lldb-for-aix
that referenced
this pull request
Jun 12, 2025
- try_emplace(Key) is shorter than insert({Key, nullptr}). - try_emplace performs value initialization without value parameters. - We overwrite values on successful insertion anyway.
tomtor
pushed a commit
to tomtor/llvm-project
that referenced
this pull request
Jun 14, 2025
- try_emplace(Key) is shorter than insert({Key, nullptr}). - try_emplace performs value initialization without value parameters. - We overwrite values on successful insertion anyway.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.