Skip to content

Commit cc78177

Browse files
[llvm] Use *Map::try_emplace (NFC) (#141190)
try_emplace can default-construct values, so we do not need to do so on our own. Plus, try_emplace(Key) is much simpler/shorter than insert({Key, LongValueType()}).
1 parent 05674b2 commit cc78177

File tree

5 files changed

+8
-9
lines changed

5 files changed

+8
-9
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8371,7 +8371,7 @@ ScalarEvolution::getPredicatedBackedgeTakenInfo(const Loop *L) {
83718371
if (BTI.hasFullInfo())
83728372
return BTI;
83738373

8374-
auto Pair = PredicatedBackedgeTakenCounts.insert({L, BackedgeTakenInfo()});
8374+
auto Pair = PredicatedBackedgeTakenCounts.try_emplace(L);
83758375

83768376
if (!Pair.second)
83778377
return Pair.first->second;
@@ -8390,7 +8390,7 @@ ScalarEvolution::getBackedgeTakenInfo(const Loop *L) {
83908390
// code elsewhere that it shouldn't attempt to request a new
83918391
// backedge-taken count, which could result in infinite recursion.
83928392
std::pair<DenseMap<const Loop *, BackedgeTakenInfo>::iterator, bool> Pair =
8393-
BackedgeTakenCounts.insert({L, BackedgeTakenInfo()});
8393+
BackedgeTakenCounts.try_emplace(L);
83948394
if (!Pair.second)
83958395
return Pair.first->second;
83968396

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ unsigned CodeViewDebug::maybeRecordFile(const DIFile *F) {
234234
CodeViewDebug::InlineSite &
235235
CodeViewDebug::getInlineSite(const DILocation *InlinedAt,
236236
const DISubprogram *Inlinee) {
237-
auto SiteInsertion = CurFn->InlineSites.insert({InlinedAt, InlineSite()});
237+
auto SiteInsertion = CurFn->InlineSites.try_emplace(InlinedAt);
238238
InlineSite *Site = &SiteInsertion.first->second;
239239
if (SiteInsertion.second) {
240240
unsigned ParentFuncId = CurFn->FuncId;
@@ -2743,7 +2743,7 @@ TypeIndex CodeViewDebug::getCompleteTypeIndex(const DIType *Ty) {
27432743
// Check if we've already translated the complete record type.
27442744
// Insert the type with a null TypeIndex to signify that the type is currently
27452745
// being lowered.
2746-
auto InsertResult = CompleteTypeIndices.insert({CTy, TypeIndex()});
2746+
auto InsertResult = CompleteTypeIndices.try_emplace(CTy);
27472747
if (!InsertResult.second)
27482748
return InsertResult.first->second;
27492749

@@ -3005,7 +3005,7 @@ void CodeViewDebug::collectLexicalBlockInfo(
30053005
// Create a new CodeView lexical block for this lexical scope. If we've
30063006
// seen this DILexicalBlock before then the scope tree is malformed and
30073007
// we can handle this gracefully by not processing it a second time.
3008-
auto BlockInsertion = CurFn->LexicalBlocks.insert({DILB, LexicalBlock()});
3008+
auto BlockInsertion = CurFn->LexicalBlocks.try_emplace(DILB);
30093009
if (!BlockInsertion.second)
30103010
return;
30113011

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,8 +1691,7 @@ bool InstrRefBasedLDV::transferDebugInstrRef(MachineInstr &MI,
16911691
// filled in later.
16921692
for (const DbgOp &Op : DbgOps) {
16931693
if (!Op.IsConst)
1694-
if (FoundLocs.insert({Op.ID, TransferTracker::LocationAndQuality()})
1695-
.second)
1694+
if (FoundLocs.try_emplace(Op.ID).second)
16961695
ValuesToFind.push_back(Op.ID);
16971696
}
16981697

llvm/lib/CodeGen/NonRelocatableStringpool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace llvm {
1313

1414
DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) {
15-
auto I = Strings.insert({S, DwarfStringPoolEntry()});
15+
auto I = Strings.try_emplace(S);
1616
auto &Entry = I.first->second;
1717
if (I.second || !Entry.isIndexed()) {
1818
Entry.Index = NumEntries++;

llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2656,7 +2656,7 @@ bool SIInsertWaitcnts::run(MachineFunction &MF) {
26562656
// Keep iterating over the blocks in reverse post order, inserting and
26572657
// updating s_waitcnt where needed, until a fix point is reached.
26582658
for (auto *MBB : ReversePostOrderTraversal<MachineFunction *>(&MF))
2659-
BlockInfos.insert({MBB, BlockInfo()});
2659+
BlockInfos.try_emplace(MBB);
26602660

26612661
std::unique_ptr<WaitcntBrackets> Brackets;
26622662
bool Repeat;

0 commit comments

Comments
 (0)