[llvm] a153a32 - [BPF] Avoid repeated map lookups (NFC) (#112123)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 13 07:36:24 PDT 2024
Author: Kazu Hirata
Date: 2024-10-13T07:36:21-07:00
New Revision: a153a3215562a7676d84411191541fe275444f7b
URL: https://github.com/llvm/llvm-project/commit/a153a3215562a7676d84411191541fe275444f7b
DIFF: https://github.com/llvm/llvm-project/commit/a153a3215562a7676d84411191541fe275444f7b.diff
LOG: [BPF] Avoid repeated map lookups (NFC) (#112123)
Added:
Modified:
llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
index 7921518166f97d..39f38259a193b4 100644
--- a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
+++ b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
@@ -221,10 +221,9 @@ bool BPFAbstractMemberAccess::run(Function &F) {
void BPFAbstractMemberAccess::ResetMetadata(struct CallInfo &CInfo) {
if (auto Ty = dyn_cast<DICompositeType>(CInfo.Metadata)) {
- if (AnonRecords.find(Ty) != AnonRecords.end()) {
- if (AnonRecords[Ty] != nullptr)
- CInfo.Metadata = AnonRecords[Ty];
- }
+ auto It = AnonRecords.find(Ty);
+ if (It != AnonRecords.end() && It->second != nullptr)
+ CInfo.Metadata = It->second;
}
}
@@ -234,18 +233,12 @@ void BPFAbstractMemberAccess::CheckCompositeType(DIDerivedType *ParentTy,
ParentTy->getTag() != dwarf::DW_TAG_typedef)
return;
- if (AnonRecords.find(CTy) == AnonRecords.end()) {
- AnonRecords[CTy] = ParentTy;
- return;
- }
-
+ auto [It, Inserted] = AnonRecords.try_emplace(CTy, ParentTy);
// Two or more typedef's may point to the same anon record.
// If this is the case, set the typedef DIType to be nullptr
// to indicate the duplication case.
- DIDerivedType *CurrTy = AnonRecords[CTy];
- if (CurrTy == ParentTy)
- return;
- AnonRecords[CTy] = nullptr;
+ if (!Inserted && It->second != ParentTy)
+ It->second = nullptr;
}
void BPFAbstractMemberAccess::CheckDerivedType(DIDerivedType *ParentTy,
More information about the llvm-commits
mailing list