Skip to content

Commit 89308de

Browse files
[llvm] Value-initialize values with *Map::try_emplace (NFC) (#141522)
try_emplace value-initializes values, so we do not need to pass nullptr to try_emplace when the value types are raw pointers or std::unique_ptr<T>.
1 parent a0c33e5 commit 89308de

File tree

18 files changed

+26
-31
lines changed

18 files changed

+26
-31
lines changed

llvm/include/llvm/CodeGen/DebugHandlerBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ class DebugHandlerBase : public AsmPrinterHandler {
101101

102102
/// Ensure that a label will be emitted before MI.
103103
void requestLabelBeforeInsn(const MachineInstr *MI) {
104-
LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
104+
LabelsBeforeInsn.try_emplace(MI);
105105
}
106106

107107
/// Ensure that a label will be emitted after MI.
108108
void requestLabelAfterInsn(const MachineInstr *MI) {
109-
LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
109+
LabelsAfterInsn.try_emplace(MI);
110110
}
111111

112112
virtual void beginFunctionImpl(const MachineFunction *MF) = 0;

llvm/include/llvm/SandboxIR/Context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class Context {
253253
Type *getType(llvm::Type *LLVMTy) {
254254
if (LLVMTy == nullptr)
255255
return nullptr;
256-
auto Pair = LLVMTypeToTypeMap.insert({LLVMTy, nullptr});
256+
auto Pair = LLVMTypeToTypeMap.try_emplace(LLVMTy);
257257
auto It = Pair.first;
258258
if (Pair.second)
259259
It->second = std::unique_ptr<Type, TypeDeleter>(new Type(LLVMTy, *this));

llvm/include/llvm/Transforms/Instrumentation/CFGMST.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,13 @@ template <class Edge, class BBInfo> class CFGMST {
305305
uint32_t Index = BBInfos.size();
306306
auto Iter = BBInfos.end();
307307
bool Inserted;
308-
std::tie(Iter, Inserted) = BBInfos.insert(std::make_pair(Src, nullptr));
308+
std::tie(Iter, Inserted) = BBInfos.try_emplace(Src);
309309
if (Inserted) {
310310
// Newly inserted, update the real info.
311311
Iter->second = std::make_unique<BBInfo>(Index);
312312
Index++;
313313
}
314-
std::tie(Iter, Inserted) = BBInfos.insert(std::make_pair(Dest, nullptr));
314+
std::tie(Iter, Inserted) = BBInfos.try_emplace(Dest);
315315
if (Inserted)
316316
// Newly inserted, update the real info.
317317
Iter->second = std::make_unique<BBInfo>(Index);

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ bool EarliestEscapeAnalysis::isNotCapturedBefore(const Value *Object,
216216
if (!isIdentifiedFunctionLocal(Object))
217217
return false;
218218

219-
auto Iter = EarliestEscapes.insert({Object, nullptr});
219+
auto Iter = EarliestEscapes.try_emplace(Object);
220220
if (Iter.second) {
221221
Instruction *EarliestCapture = FindEarliestCapture(
222222
Object, *const_cast<Function *>(DT.getRoot()->getParent()),

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2979,7 +2979,7 @@ void LoopAccessInfo::print(raw_ostream &OS, unsigned Depth) const {
29792979
}
29802980

29812981
const LoopAccessInfo &LoopAccessInfoManager::getInfo(Loop &L) {
2982-
const auto &[It, Inserted] = LoopAccessInfoMap.insert({&L, nullptr});
2982+
const auto &[It, Inserted] = LoopAccessInfoMap.try_emplace(&L);
29832983

29842984
if (Inserted)
29852985
It->second =

llvm/lib/Analysis/MemorySSA.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,15 +1277,15 @@ MemorySSA::~MemorySSA() {
12771277
}
12781278

12791279
MemorySSA::AccessList *MemorySSA::getOrCreateAccessList(const BasicBlock *BB) {
1280-
auto Res = PerBlockAccesses.insert(std::make_pair(BB, nullptr));
1280+
auto Res = PerBlockAccesses.try_emplace(BB);
12811281

12821282
if (Res.second)
12831283
Res.first->second = std::make_unique<AccessList>();
12841284
return Res.first->second.get();
12851285
}
12861286

12871287
MemorySSA::DefsList *MemorySSA::getOrCreateDefsList(const BasicBlock *BB) {
1288-
auto Res = PerBlockDefs.insert(std::make_pair(BB, nullptr));
1288+
auto Res = PerBlockDefs.try_emplace(BB);
12891289

12901290
if (Res.second)
12911291
Res.first->second = std::make_unique<DefsList>();

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4470,7 +4470,7 @@ GCMetadataPrinter *AsmPrinter::getOrCreateGCPrinter(GCStrategy &S) {
44704470
if (!S.usesMetadata())
44714471
return nullptr;
44724472

4473-
auto [GCPI, Inserted] = GCMetadataPrinters.insert({&S, nullptr});
4473+
auto [GCPI, Inserted] = GCMetadataPrinters.try_emplace(&S);
44744474
if (!Inserted)
44754475
return GCPI->second.get();
44764476

llvm/lib/CodeGen/MIRParser/MIParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ PerFunctionMIParsingState::PerFunctionMIParsingState(MachineFunction &MF,
326326
}
327327

328328
VRegInfo &PerFunctionMIParsingState::getVRegInfo(Register Num) {
329-
auto I = VRegInfos.insert(std::make_pair(Num, nullptr));
329+
auto I = VRegInfos.try_emplace(Num);
330330
if (I.second) {
331331
MachineRegisterInfo &MRI = MF.getRegInfo();
332332
VRegInfo *Info = new (Allocator) VRegInfo;
@@ -339,7 +339,7 @@ VRegInfo &PerFunctionMIParsingState::getVRegInfo(Register Num) {
339339
VRegInfo &PerFunctionMIParsingState::getVRegInfoNamed(StringRef RegName) {
340340
assert(RegName != "" && "Expected named reg.");
341341

342-
auto I = VRegInfosNamed.insert(std::make_pair(RegName.str(), nullptr));
342+
auto I = VRegInfosNamed.try_emplace(RegName.str());
343343
if (I.second) {
344344
VRegInfo *Info = new (Allocator) VRegInfo;
345345
Info->VReg = MF.getRegInfo().createIncompleteVirtualRegister(RegName);

llvm/lib/IR/Constants.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,9 +2876,7 @@ Constant *ConstantDataSequential::getImpl(StringRef Elements, Type *Ty) {
28762876

28772877
// Do a lookup to see if we have already formed one of these.
28782878
auto &Slot =
2879-
*Ty->getContext()
2880-
.pImpl->CDSConstants.insert(std::make_pair(Elements, nullptr))
2881-
.first;
2879+
*Ty->getContext().pImpl->CDSConstants.try_emplace(Elements).first;
28822880

28832881
// The bucket can point to a linked list of different CDS's that have the same
28842882
// body but different types. For example, 0,0,0,1 could be a 4 element array

llvm/lib/Object/ELF.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,7 @@ ELFFile<ELFT>::getSectionAndRelocations(
965965
continue;
966966
}
967967
if (*DoesSectionMatch) {
968-
if (SecToRelocMap.insert(std::make_pair(&Sec, (const Elf_Shdr *)nullptr))
969-
.second)
968+
if (SecToRelocMap.try_emplace(&Sec).second)
970969
continue;
971970
}
972971

llvm/lib/SandboxIR/Context.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Value *Context::registerValue(std::unique_ptr<Value> &&VPtr) {
5454
}
5555

5656
Value *Context::getOrCreateValueInternal(llvm::Value *LLVMV, llvm::User *U) {
57-
auto Pair = LLVMValueToValueMap.insert({LLVMV, nullptr});
57+
auto Pair = LLVMValueToValueMap.try_emplace(LLVMV);
5858
auto It = Pair.first;
5959
if (!Pair.second)
6060
return It->second.get();
@@ -432,7 +432,7 @@ Value *Context::getOrCreateValueInternal(llvm::Value *LLVMV, llvm::User *U) {
432432
}
433433

434434
Argument *Context::getOrCreateArgument(llvm::Argument *LLVMArg) {
435-
auto Pair = LLVMValueToValueMap.insert({LLVMArg, nullptr});
435+
auto Pair = LLVMValueToValueMap.try_emplace(LLVMArg);
436436
auto It = Pair.first;
437437
if (Pair.second) {
438438
It->second = std::unique_ptr<Argument>(new Argument(LLVMArg, *this));
@@ -652,7 +652,7 @@ Module *Context::getModule(llvm::Module *LLVMM) const {
652652
}
653653

654654
Module *Context::getOrCreateModule(llvm::Module *LLVMM) {
655-
auto Pair = LLVMModuleToModuleMap.insert({LLVMM, nullptr});
655+
auto Pair = LLVMModuleToModuleMap.try_emplace(LLVMM);
656656
auto It = Pair.first;
657657
if (!Pair.second)
658658
return It->second.get();

llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ bool FixFunctionBitcasts::runOnModule(Module &M) {
270270
Function *F = UseFunc.second;
271271
FunctionType *Ty = CB->getFunctionType();
272272

273-
auto Pair = Wrappers.insert(std::make_pair(std::make_pair(F, Ty), nullptr));
273+
auto Pair = Wrappers.try_emplace(std::make_pair(F, Ty));
274274
if (Pair.second)
275275
Pair.first->second = createWrapper(F, Ty);
276276

llvm/lib/TextAPI/RecordsSlice.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ GlobalRecord *RecordsSlice::addGlobal(StringRef Name, RecordLinkage Linkage,
179179
Flags |= SymbolFlags::Data;
180180

181181
Name = copyString(Name);
182-
auto Result = Globals.insert({Name, nullptr});
182+
auto Result = Globals.try_emplace(Name);
183183
if (Result.second)
184184
Result.first->second =
185185
std::make_unique<GlobalRecord>(Name, Linkage, Flags, GV, Inlined);
@@ -194,7 +194,7 @@ ObjCInterfaceRecord *RecordsSlice::addObjCInterface(StringRef Name,
194194
RecordLinkage Linkage,
195195
ObjCIFSymbolKind SymType) {
196196
Name = copyString(Name);
197-
auto Result = Classes.insert({Name, nullptr});
197+
auto Result = Classes.try_emplace(Name);
198198
if (Result.second)
199199
Result.first->second =
200200
std::make_unique<ObjCInterfaceRecord>(Name, Linkage, SymType);
@@ -228,8 +228,7 @@ ObjCCategoryRecord *RecordsSlice::addObjCCategory(StringRef ClassToExtend,
228228
ClassToExtend = copyString(ClassToExtend);
229229

230230
// Add owning record first into record slice.
231-
auto Result =
232-
Categories.insert({std::make_pair(ClassToExtend, Category), nullptr});
231+
auto Result = Categories.try_emplace(std::make_pair(ClassToExtend, Category));
233232
if (Result.second)
234233
Result.first->second =
235234
std::make_unique<ObjCCategoryRecord>(ClassToExtend, Category);

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
11151115
bool FoundSrcAgg = false;
11161116
for (BasicBlock *Pred : Preds) {
11171117
std::pair<decltype(SourceAggregates)::iterator, bool> IV =
1118-
SourceAggregates.insert({Pred, nullptr});
1118+
SourceAggregates.try_emplace(Pred);
11191119
// Did we already evaluate this predecessor?
11201120
if (!IV.second)
11211121
continue;

llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5880,7 +5880,7 @@ void LSRInstance::RewriteForPHI(PHINode *PN, const LSRUse &LU,
58805880
}
58815881

58825882
std::pair<DenseMap<BasicBlock *, Value *>::iterator, bool> Pair =
5883-
Inserted.insert(std::make_pair(BB, static_cast<Value *>(nullptr)));
5883+
Inserted.try_emplace(BB);
58845884
if (!Pair.second)
58855885
PN->setIncomingValue(i, Pair.first->second);
58865886
else {

llvm/lib/Transforms/Scalar/NewGVN.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2383,7 +2383,7 @@ void NewGVN::performCongruenceFinding(Instruction *I, const Expression *E) {
23832383
EClass = TOPClass;
23842384
}
23852385
if (!EClass) {
2386-
auto lookupResult = ExpressionToClass.insert({E, nullptr});
2386+
auto lookupResult = ExpressionToClass.try_emplace(E);
23872387

23882388
// If it's not in the value table, create a new congruence class.
23892389
if (lookupResult.second) {

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ static const Loop *PickMostRelevantLoop(const Loop *A, const Loop *B,
434434
/// expression, according to PickMostRelevantLoop.
435435
const Loop *SCEVExpander::getRelevantLoop(const SCEV *S) {
436436
// Test whether we've already computed the most relevant loop for this SCEV.
437-
auto Pair = RelevantLoops.insert(std::make_pair(S, nullptr));
437+
auto Pair = RelevantLoops.try_emplace(S);
438438
if (!Pair.second)
439439
return Pair.first->second;
440440

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,8 +1820,7 @@ void VPlanTransforms::truncateToMinimalBitwidths(
18201820
if (OpSizeInBits == NewResSizeInBits)
18211821
continue;
18221822
assert(OpSizeInBits > NewResSizeInBits && "nothing to truncate");
1823-
auto [ProcessedIter, IterIsEmpty] =
1824-
ProcessedTruncs.insert({Op, nullptr});
1823+
auto [ProcessedIter, IterIsEmpty] = ProcessedTruncs.try_emplace(Op);
18251824
VPWidenCastRecipe *NewOp =
18261825
IterIsEmpty
18271826
? new VPWidenCastRecipe(Instruction::Trunc, Op, NewResTy)

0 commit comments

Comments
 (0)