Skip to content

Commit b3b8a09

Browse files
[mlir] Use *Map::try_emplace (NFC) (#143341)
- try_emplace(Key) is shorter than insert({Key, nullptr}). - try_emplace performs value initialization without value parameters. - We overwrite values on successful insertion anyway.
1 parent 9396663 commit b3b8a09

File tree

6 files changed

+8
-9
lines changed

6 files changed

+8
-9
lines changed

mlir/include/mlir/Debug/BreakpointManagers/TagBreakpointManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class TagBreakpointManager
4848
/// If a breakpoint already exists for the given tag, return the existing
4949
/// instance.
5050
TagBreakpoint *addBreakpoint(StringRef tag) {
51-
auto result = breakpoints.insert({tag, nullptr});
51+
auto result = breakpoints.try_emplace(tag);
5252
auto &it = result.first;
5353
if (result.second)
5454
it->second = std::make_unique<TagBreakpoint>(tag.str());

mlir/lib/Bytecode/Writer/IRNumbering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void IRNumberingState::computeGlobalNumberingState(Operation *rootOp) {
308308
}
309309

310310
void IRNumberingState::number(Attribute attr) {
311-
auto it = attrs.insert({attr, nullptr});
311+
auto it = attrs.try_emplace(attr);
312312
if (!it.second) {
313313
++it.first->second->refCount;
314314
return;
@@ -475,7 +475,7 @@ void IRNumberingState::number(OperationName opName) {
475475
}
476476

477477
void IRNumberingState::number(Type type) {
478-
auto it = types.insert({type, nullptr});
478+
auto it = types.try_emplace(type);
479479
if (!it.second) {
480480
++it.first->second->refCount;
481481
return;

mlir/lib/IR/MLIRContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ OperationName::OperationName(StringRef name, MLIRContext *context) {
810810
// Acquire a writer-lock so that we can safely create the new instance.
811811
ScopedWriterLock lock(ctxImpl.operationInfoMutex, isMultithreadingEnabled);
812812

813-
auto it = ctxImpl.operations.insert({name, nullptr});
813+
auto it = ctxImpl.operations.try_emplace(name);
814814
if (it.second) {
815815
auto nameAttr = StringAttr::get(context, name);
816816
it.first->second = std::make_unique<UnregisteredOpModel>(

mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ LoopAnnotationTranslation::translateLoopAnnotation(LoopAnnotationAttr attr,
280280
llvm::MDNode *
281281
LoopAnnotationTranslation::getAccessGroup(AccessGroupAttr accessGroupAttr) {
282282
auto [result, inserted] =
283-
accessGroupMetadataMapping.insert({accessGroupAttr, nullptr});
283+
accessGroupMetadataMapping.try_emplace(accessGroupAttr);
284284
if (inserted)
285285
result->second = llvm::MDNode::getDistinct(llvmModule.getContext(), {});
286286
return result->second;

mlir/lib/Transforms/Utils/CFGToSCF.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,7 @@ class ReturnLikeExitCombiner {
427427
/// region with an instance of `returnLikeOp`s kind.
428428
void combineExit(Operation *returnLikeOp,
429429
function_ref<Value(unsigned)> getSwitchValue) {
430-
auto [iter, inserted] =
431-
returnLikeToCombinedExit.insert({returnLikeOp, nullptr});
430+
auto [iter, inserted] = returnLikeToCombinedExit.try_emplace(returnLikeOp);
432431
if (!inserted && iter->first == returnLikeOp)
433432
return;
434433

@@ -1284,7 +1283,7 @@ FailureOr<bool> mlir::transformCFGToSCF(Region &region,
12841283

12851284
DenseMap<Type, Value> typedUndefCache;
12861285
auto getUndefValue = [&](Type type) {
1287-
auto [iter, inserted] = typedUndefCache.insert({type, nullptr});
1286+
auto [iter, inserted] = typedUndefCache.try_emplace(type);
12881287
if (!inserted)
12891288
return iter->second;
12901289

mlir/lib/Transforms/Utils/Inliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void walkReferencedSymbolNodes(
4545

4646
Operation *symbolTableOp = op->getParentOp();
4747
for (const SymbolTable::SymbolUse &use : *symbolUses) {
48-
auto refIt = resolvedRefs.insert({use.getSymbolRef(), nullptr});
48+
auto refIt = resolvedRefs.try_emplace(use.getSymbolRef());
4949
CallGraphNode *&node = refIt.first->second;
5050

5151
// If this is the first instance of this reference, try to resolve a

0 commit comments

Comments
 (0)