Skip to content

[BPF] Avoid repeated map lookups (NFC) #113247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions llvm/lib/Target/BPF/BTFDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
}

Expand Down
Loading