diff --git a/llvm/include/llvm/CodeGen/DebugHandlerBase.h b/llvm/include/llvm/CodeGen/DebugHandlerBase.h index 3da7ea5f31231..2849497f9a43e 100644 --- a/llvm/include/llvm/CodeGen/DebugHandlerBase.h +++ b/llvm/include/llvm/CodeGen/DebugHandlerBase.h @@ -101,12 +101,12 @@ class DebugHandlerBase : public AsmPrinterHandler { /// Ensure that a label will be emitted before MI. void requestLabelBeforeInsn(const MachineInstr *MI) { - LabelsBeforeInsn.insert(std::make_pair(MI, nullptr)); + LabelsBeforeInsn.try_emplace(MI); } /// Ensure that a label will be emitted after MI. void requestLabelAfterInsn(const MachineInstr *MI) { - LabelsAfterInsn.insert(std::make_pair(MI, nullptr)); + LabelsAfterInsn.try_emplace(MI); } virtual void beginFunctionImpl(const MachineFunction *MF) = 0; diff --git a/llvm/include/llvm/SandboxIR/Context.h b/llvm/include/llvm/SandboxIR/Context.h index 974b3f15968fc..a8a21b0db855e 100644 --- a/llvm/include/llvm/SandboxIR/Context.h +++ b/llvm/include/llvm/SandboxIR/Context.h @@ -253,7 +253,7 @@ class Context { Type *getType(llvm::Type *LLVMTy) { if (LLVMTy == nullptr) return nullptr; - auto Pair = LLVMTypeToTypeMap.insert({LLVMTy, nullptr}); + auto Pair = LLVMTypeToTypeMap.try_emplace(LLVMTy); auto It = Pair.first; if (Pair.second) It->second = std::unique_ptr(new Type(LLVMTy, *this)); diff --git a/llvm/include/llvm/Transforms/Instrumentation/CFGMST.h b/llvm/include/llvm/Transforms/Instrumentation/CFGMST.h index f6bf045f7de2c..6b93b6cb83b4e 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/CFGMST.h +++ b/llvm/include/llvm/Transforms/Instrumentation/CFGMST.h @@ -305,13 +305,13 @@ template class CFGMST { uint32_t Index = BBInfos.size(); auto Iter = BBInfos.end(); bool Inserted; - std::tie(Iter, Inserted) = BBInfos.insert(std::make_pair(Src, nullptr)); + std::tie(Iter, Inserted) = BBInfos.try_emplace(Src); if (Inserted) { // Newly inserted, update the real info. Iter->second = std::make_unique(Index); Index++; } - std::tie(Iter, Inserted) = BBInfos.insert(std::make_pair(Dest, nullptr)); + std::tie(Iter, Inserted) = BBInfos.try_emplace(Dest); if (Inserted) // Newly inserted, update the real info. Iter->second = std::make_unique(Index); diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index 30222b87ea467..bcc9a71917aaf 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -216,7 +216,7 @@ bool EarliestEscapeAnalysis::isNotCapturedBefore(const Value *Object, if (!isIdentifiedFunctionLocal(Object)) return false; - auto Iter = EarliestEscapes.insert({Object, nullptr}); + auto Iter = EarliestEscapes.try_emplace(Object); if (Iter.second) { Instruction *EarliestCapture = FindEarliestCapture( Object, *const_cast(DT.getRoot()->getParent()), diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp index 755a6ac317e8d..f377da3926b26 100644 --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -2979,7 +2979,7 @@ void LoopAccessInfo::print(raw_ostream &OS, unsigned Depth) const { } const LoopAccessInfo &LoopAccessInfoManager::getInfo(Loop &L) { - const auto &[It, Inserted] = LoopAccessInfoMap.insert({&L, nullptr}); + const auto &[It, Inserted] = LoopAccessInfoMap.try_emplace(&L); if (Inserted) It->second = diff --git a/llvm/lib/Analysis/MemorySSA.cpp b/llvm/lib/Analysis/MemorySSA.cpp index 9f8979a9043dc..ab373386da579 100644 --- a/llvm/lib/Analysis/MemorySSA.cpp +++ b/llvm/lib/Analysis/MemorySSA.cpp @@ -1277,7 +1277,7 @@ MemorySSA::~MemorySSA() { } MemorySSA::AccessList *MemorySSA::getOrCreateAccessList(const BasicBlock *BB) { - auto Res = PerBlockAccesses.insert(std::make_pair(BB, nullptr)); + auto Res = PerBlockAccesses.try_emplace(BB); if (Res.second) Res.first->second = std::make_unique(); @@ -1285,7 +1285,7 @@ MemorySSA::AccessList *MemorySSA::getOrCreateAccessList(const BasicBlock *BB) { } MemorySSA::DefsList *MemorySSA::getOrCreateDefsList(const BasicBlock *BB) { - auto Res = PerBlockDefs.insert(std::make_pair(BB, nullptr)); + auto Res = PerBlockDefs.try_emplace(BB); if (Res.second) Res.first->second = std::make_unique(); diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 4aaa96c81bbc1..1322973cb92de 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -4470,7 +4470,7 @@ GCMetadataPrinter *AsmPrinter::getOrCreateGCPrinter(GCStrategy &S) { if (!S.usesMetadata()) return nullptr; - auto [GCPI, Inserted] = GCMetadataPrinters.insert({&S, nullptr}); + auto [GCPI, Inserted] = GCMetadataPrinters.try_emplace(&S); if (!Inserted) return GCPI->second.get(); diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index cbdeacda3eb87..3a364d5ff0d20 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -326,7 +326,7 @@ PerFunctionMIParsingState::PerFunctionMIParsingState(MachineFunction &MF, } VRegInfo &PerFunctionMIParsingState::getVRegInfo(Register Num) { - auto I = VRegInfos.insert(std::make_pair(Num, nullptr)); + auto I = VRegInfos.try_emplace(Num); if (I.second) { MachineRegisterInfo &MRI = MF.getRegInfo(); VRegInfo *Info = new (Allocator) VRegInfo; @@ -339,7 +339,7 @@ VRegInfo &PerFunctionMIParsingState::getVRegInfo(Register Num) { VRegInfo &PerFunctionMIParsingState::getVRegInfoNamed(StringRef RegName) { assert(RegName != "" && "Expected named reg."); - auto I = VRegInfosNamed.insert(std::make_pair(RegName.str(), nullptr)); + auto I = VRegInfosNamed.try_emplace(RegName.str()); if (I.second) { VRegInfo *Info = new (Allocator) VRegInfo; Info->VReg = MF.getRegInfo().createIncompleteVirtualRegister(RegName); diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index d7c847e541052..b2087d3651143 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -2876,9 +2876,7 @@ Constant *ConstantDataSequential::getImpl(StringRef Elements, Type *Ty) { // Do a lookup to see if we have already formed one of these. auto &Slot = - *Ty->getContext() - .pImpl->CDSConstants.insert(std::make_pair(Elements, nullptr)) - .first; + *Ty->getContext().pImpl->CDSConstants.try_emplace(Elements).first; // The bucket can point to a linked list of different CDS's that have the same // body but different types. For example, 0,0,0,1 could be a 4 element array diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp index bf42c92a242a1..dfc8acb0e4542 100644 --- a/llvm/lib/Object/ELF.cpp +++ b/llvm/lib/Object/ELF.cpp @@ -965,8 +965,7 @@ ELFFile::getSectionAndRelocations( continue; } if (*DoesSectionMatch) { - if (SecToRelocMap.insert(std::make_pair(&Sec, (const Elf_Shdr *)nullptr)) - .second) + if (SecToRelocMap.try_emplace(&Sec).second) continue; } diff --git a/llvm/lib/SandboxIR/Context.cpp b/llvm/lib/SandboxIR/Context.cpp index fe67f9ef73fb6..fe34037d7dc49 100644 --- a/llvm/lib/SandboxIR/Context.cpp +++ b/llvm/lib/SandboxIR/Context.cpp @@ -54,7 +54,7 @@ Value *Context::registerValue(std::unique_ptr &&VPtr) { } Value *Context::getOrCreateValueInternal(llvm::Value *LLVMV, llvm::User *U) { - auto Pair = LLVMValueToValueMap.insert({LLVMV, nullptr}); + auto Pair = LLVMValueToValueMap.try_emplace(LLVMV); auto It = Pair.first; if (!Pair.second) return It->second.get(); @@ -432,7 +432,7 @@ Value *Context::getOrCreateValueInternal(llvm::Value *LLVMV, llvm::User *U) { } Argument *Context::getOrCreateArgument(llvm::Argument *LLVMArg) { - auto Pair = LLVMValueToValueMap.insert({LLVMArg, nullptr}); + auto Pair = LLVMValueToValueMap.try_emplace(LLVMArg); auto It = Pair.first; if (Pair.second) { It->second = std::unique_ptr(new Argument(LLVMArg, *this)); @@ -652,7 +652,7 @@ Module *Context::getModule(llvm::Module *LLVMM) const { } Module *Context::getOrCreateModule(llvm::Module *LLVMM) { - auto Pair = LLVMModuleToModuleMap.insert({LLVMM, nullptr}); + auto Pair = LLVMModuleToModuleMap.try_emplace(LLVMM); auto It = Pair.first; if (!Pair.second) return It->second.get(); diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp index 4fe1df0ab3e42..37a34573bb339 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp @@ -270,7 +270,7 @@ bool FixFunctionBitcasts::runOnModule(Module &M) { Function *F = UseFunc.second; FunctionType *Ty = CB->getFunctionType(); - auto Pair = Wrappers.insert(std::make_pair(std::make_pair(F, Ty), nullptr)); + auto Pair = Wrappers.try_emplace(std::make_pair(F, Ty)); if (Pair.second) Pair.first->second = createWrapper(F, Ty); diff --git a/llvm/lib/TextAPI/RecordsSlice.cpp b/llvm/lib/TextAPI/RecordsSlice.cpp index 04c48eaa628ea..1500b8752115a 100644 --- a/llvm/lib/TextAPI/RecordsSlice.cpp +++ b/llvm/lib/TextAPI/RecordsSlice.cpp @@ -179,7 +179,7 @@ GlobalRecord *RecordsSlice::addGlobal(StringRef Name, RecordLinkage Linkage, Flags |= SymbolFlags::Data; Name = copyString(Name); - auto Result = Globals.insert({Name, nullptr}); + auto Result = Globals.try_emplace(Name); if (Result.second) Result.first->second = std::make_unique(Name, Linkage, Flags, GV, Inlined); @@ -194,7 +194,7 @@ ObjCInterfaceRecord *RecordsSlice::addObjCInterface(StringRef Name, RecordLinkage Linkage, ObjCIFSymbolKind SymType) { Name = copyString(Name); - auto Result = Classes.insert({Name, nullptr}); + auto Result = Classes.try_emplace(Name); if (Result.second) Result.first->second = std::make_unique(Name, Linkage, SymType); @@ -228,8 +228,7 @@ ObjCCategoryRecord *RecordsSlice::addObjCCategory(StringRef ClassToExtend, ClassToExtend = copyString(ClassToExtend); // Add owning record first into record slice. - auto Result = - Categories.insert({std::make_pair(ClassToExtend, Category), nullptr}); + auto Result = Categories.try_emplace(std::make_pair(ClassToExtend, Category)); if (Result.second) Result.first->second = std::make_unique(ClassToExtend, Category); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp index 900946e9b335b..116b862228417 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -1115,7 +1115,7 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse( bool FoundSrcAgg = false; for (BasicBlock *Pred : Preds) { std::pair IV = - SourceAggregates.insert({Pred, nullptr}); + SourceAggregates.try_emplace(Pred); // Did we already evaluate this predecessor? if (!IV.second) continue; diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 6c18bc9f77297..afac49ad03ba4 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -5880,7 +5880,7 @@ void LSRInstance::RewriteForPHI(PHINode *PN, const LSRUse &LU, } std::pair::iterator, bool> Pair = - Inserted.insert(std::make_pair(BB, static_cast(nullptr))); + Inserted.try_emplace(BB); if (!Pair.second) PN->setIncomingValue(i, Pair.first->second); else { diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp index 0a0ea65a1f036..85bd8ef1f09a8 100644 --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -2383,7 +2383,7 @@ void NewGVN::performCongruenceFinding(Instruction *I, const Expression *E) { EClass = TOPClass; } if (!EClass) { - auto lookupResult = ExpressionToClass.insert({E, nullptr}); + auto lookupResult = ExpressionToClass.try_emplace(E); // If it's not in the value table, create a new congruence class. if (lookupResult.second) { diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index fb5e73727b2ef..88d2eca36ca51 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -434,7 +434,7 @@ static const Loop *PickMostRelevantLoop(const Loop *A, const Loop *B, /// expression, according to PickMostRelevantLoop. const Loop *SCEVExpander::getRelevantLoop(const SCEV *S) { // Test whether we've already computed the most relevant loop for this SCEV. - auto Pair = RelevantLoops.insert(std::make_pair(S, nullptr)); + auto Pair = RelevantLoops.try_emplace(S); if (!Pair.second) return Pair.first->second; diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index d3f15eafb0214..6c382549ee099 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -1820,8 +1820,7 @@ void VPlanTransforms::truncateToMinimalBitwidths( if (OpSizeInBits == NewResSizeInBits) continue; assert(OpSizeInBits > NewResSizeInBits && "nothing to truncate"); - auto [ProcessedIter, IterIsEmpty] = - ProcessedTruncs.insert({Op, nullptr}); + auto [ProcessedIter, IterIsEmpty] = ProcessedTruncs.try_emplace(Op); VPWidenCastRecipe *NewOp = IterIsEmpty ? new VPWidenCastRecipe(Instruction::Trunc, Op, NewResTy)