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

0 commit comments

Comments
 (0)