Skip to content

[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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Bytecode/Writer/IRNumbering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/IR/MLIRContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions mlir/lib/Transforms/Utils/CFGToSCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

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;

Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Transforms/Utils/Inliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading