[llvm] [BPF] Avoid repeated map lookups (NFC) (PR #113247)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 21 19:11:00 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/113247
None
>From ebf8e997db16faa32239e32948d272facd2a5b28 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 21 Oct 2024 06:55:15 -0700
Subject: [PATCH] [BPF] Avoid repeated map lookups (NFC)
---
llvm/lib/Target/BPF/BTFDebug.cpp | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp
index 9d6dee13ca97a9..a14e9db5f7500d 100644
--- a/llvm/lib/Target/BPF/BTFDebug.cpp
+++ b/llvm/lib/Target/BPF/BTFDebug.cpp
@@ -1499,17 +1499,15 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) {
continue;
// Find or create a DataSec
- if (DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
- DataSecEntries[std::string(SecName)] =
- std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
- }
+ auto [It, Inserted] = DataSecEntries.try_emplace(std::string(SecName));
+ if (Inserted)
+ It->second = std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
// Calculate symbol size
const DataLayout &DL = Global.getDataLayout();
uint32_t Size = DL.getTypeAllocSize(Global.getValueType());
- DataSecEntries[std::string(SecName)]->addDataSecEntry(VarId,
- Asm->getSymbol(&Global), Size);
+ It->second->addDataSecEntry(VarId, Asm->getSymbol(&Global), Size);
if (Global.hasInitializer())
processGlobalInitializer(Global.getInitializer());
@@ -1609,14 +1607,12 @@ void BTFDebug::processFuncPrototypes(const Function *F) {
if (F->hasSection()) {
StringRef SecName = F->getSection();
- if (DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
- DataSecEntries[std::string(SecName)] =
- std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
- }
+ auto [It, Inserted] = DataSecEntries.try_emplace(std::string(SecName));
+ if (Inserted)
+ It->second = std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
// We really don't know func size, set it to 0.
- DataSecEntries[std::string(SecName)]->addDataSecEntry(FuncId,
- Asm->getSymbol(F), 0);
+ It->second->addDataSecEntry(FuncId, Asm->getSymbol(F), 0);
}
}
More information about the llvm-commits
mailing list