Skip to content

Commit a153a32

Browse files
[BPF] Avoid repeated map lookups (NFC) (llvm#112123)
1 parent d1620c1 commit a153a32

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,9 @@ bool BPFAbstractMemberAccess::run(Function &F) {
221221

222222
void BPFAbstractMemberAccess::ResetMetadata(struct CallInfo &CInfo) {
223223
if (auto Ty = dyn_cast<DICompositeType>(CInfo.Metadata)) {
224-
if (AnonRecords.find(Ty) != AnonRecords.end()) {
225-
if (AnonRecords[Ty] != nullptr)
226-
CInfo.Metadata = AnonRecords[Ty];
227-
}
224+
auto It = AnonRecords.find(Ty);
225+
if (It != AnonRecords.end() && It->second != nullptr)
226+
CInfo.Metadata = It->second;
228227
}
229228
}
230229

@@ -234,18 +233,12 @@ void BPFAbstractMemberAccess::CheckCompositeType(DIDerivedType *ParentTy,
234233
ParentTy->getTag() != dwarf::DW_TAG_typedef)
235234
return;
236235

237-
if (AnonRecords.find(CTy) == AnonRecords.end()) {
238-
AnonRecords[CTy] = ParentTy;
239-
return;
240-
}
241-
236+
auto [It, Inserted] = AnonRecords.try_emplace(CTy, ParentTy);
242237
// Two or more typedef's may point to the same anon record.
243238
// If this is the case, set the typedef DIType to be nullptr
244239
// to indicate the duplication case.
245-
DIDerivedType *CurrTy = AnonRecords[CTy];
246-
if (CurrTy == ParentTy)
247-
return;
248-
AnonRecords[CTy] = nullptr;
240+
if (!Inserted && It->second != ParentTy)
241+
It->second = nullptr;
249242
}
250243

251244
void BPFAbstractMemberAccess::CheckDerivedType(DIDerivedType *ParentTy,

0 commit comments

Comments
 (0)