[lld] 769057a - [ELF] Change some DenseMap<StringRef, *> to DenseMap<CachedHashStringRef, *>. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 16 21:19:11 PST 2022
Author: Fangrui Song
Date: 2022-01-16T21:19:01-08:00
New Revision: 769057a5d04d61a558dac219b23f54f905d1ef34
URL: https://github.com/llvm/llvm-project/commit/769057a5d04d61a558dac219b23f54f905d1ef34
DIFF: https://github.com/llvm/llvm-project/commit/769057a5d04d61a558dac219b23f54f905d1ef34.diff
LOG: [ELF] Change some DenseMap<StringRef, *> to DenseMap<CachedHashStringRef, *>. NFC
Added:
Modified:
lld/ELF/InputFiles.cpp
lld/ELF/LinkerScript.cpp
lld/ELF/LinkerScript.h
lld/ELF/SymbolTable.h
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 04fa48f63c03..a65b82f73d72 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1460,9 +1460,10 @@ template <class ELFT> void SharedFile::parse() {
}
// DSOs are uniquified not by filename but by soname.
- DenseMap<StringRef, SharedFile *>::iterator it;
+ DenseMap<CachedHashStringRef, SharedFile *>::iterator it;
bool wasInserted;
- std::tie(it, wasInserted) = symtab->soNames.try_emplace(soName, this);
+ std::tie(it, wasInserted) =
+ symtab->soNames.try_emplace(CachedHashStringRef(soName), this);
// If a DSO appears more than once on the command line with and without
// --as-needed, --no-as-needed takes precedence over --as-needed because a
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index fa41f4d5c50e..30bf9abc8faf 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -135,7 +135,7 @@ uint64_t ExprValue::getSectionOffset() const {
OutputSection *LinkerScript::createOutputSection(StringRef name,
StringRef location) {
- OutputSection *&secRef = nameToOutputSection[name];
+ OutputSection *&secRef = nameToOutputSection[CachedHashStringRef(name)];
OutputSection *sec;
if (secRef && secRef->location.empty()) {
// There was a forward reference.
@@ -150,7 +150,7 @@ OutputSection *LinkerScript::createOutputSection(StringRef name,
}
OutputSection *LinkerScript::getOrCreateOutputSection(StringRef name) {
- OutputSection *&cmdRef = nameToOutputSection[name];
+ OutputSection *&cmdRef = nameToOutputSection[CachedHashStringRef(name)];
if (!cmdRef)
cmdRef = make<OutputSection>(name, SHT_PROGBITS, 0);
return cmdRef;
@@ -645,14 +645,16 @@ void LinkerScript::processSectionCommands() {
// Process OVERWRITE_SECTIONS first so that it can overwrite the main script
// or orphans.
- DenseMap<StringRef, OutputSection *> map;
+ DenseMap<CachedHashStringRef, OutputSection *> map;
size_t i = 0;
for (OutputSection *osec : overwriteSections)
- if (process(osec) && !map.try_emplace(osec->name, osec).second)
+ if (process(osec) &&
+ !map.try_emplace(CachedHashStringRef(osec->name), osec).second)
warn("OVERWRITE_SECTIONS specifies duplicate " + osec->name);
for (SectionCommand *&base : sectionCommands)
if (auto *osec = dyn_cast<OutputSection>(base)) {
- if (OutputSection *overwrite = map.lookup(osec->name)) {
+ if (OutputSection *overwrite =
+ map.lookup(CachedHashStringRef(osec->name))) {
log(overwrite->location + " overwrites " + osec->name);
overwrite->sectionIndex = i++;
base = overwrite;
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index c415186f6de9..d2a6f5e9acb1 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -271,7 +271,8 @@ class LinkerScript final {
uint64_t tbssAddr = 0;
};
- llvm::DenseMap<StringRef, OutputSection *> nameToOutputSection;
+ llvm::DenseMap<llvm::CachedHashStringRef, OutputSection *>
+ nameToOutputSection;
void addSymbol(SymbolAssignment *cmd);
void assignSymbol(SymbolAssignment *cmd, bool inSec);
diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h
index fd9fc0735fd5..04c81f642fe0 100644
--- a/lld/ELF/SymbolTable.h
+++ b/lld/ELF/SymbolTable.h
@@ -48,7 +48,7 @@ class SymbolTable {
void handleDynamicList();
// Set of .so files to not link the same shared object file more than once.
- llvm::DenseMap<StringRef, SharedFile *> soNames;
+ llvm::DenseMap<llvm::CachedHashStringRef, SharedFile *> soNames;
// Comdat groups define "link once" sections. If two comdat groups have the
// same name, only one of them is linked, and the other is ignored. This map
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 742ea81fcb57..737863bb4208 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1264,14 +1264,14 @@ static DenseMap<const InputSectionBase *, int> buildSectionOrder() {
// Build a map from symbols to their priorities. Symbols that didn't
// appear in the symbol ordering file have the lowest priority 0.
// All explicitly mentioned symbols have negative (higher) priorities.
- DenseMap<StringRef, SymbolOrderEntry> symbolOrder;
+ DenseMap<CachedHashStringRef, SymbolOrderEntry> symbolOrder;
int priority = -config->symbolOrderingFile.size();
for (StringRef s : config->symbolOrderingFile)
- symbolOrder.insert({s, {priority++, false}});
+ symbolOrder.insert({CachedHashStringRef(s), {priority++, false}});
// Build a map from sections to their priorities.
auto addSym = [&](Symbol &sym) {
- auto it = symbolOrder.find(sym.getName());
+ auto it = symbolOrder.find(CachedHashStringRef(sym.getName()));
if (it == symbolOrder.end())
return;
SymbolOrderEntry &ent = it->second;
@@ -1299,7 +1299,7 @@ static DenseMap<const InputSectionBase *, int> buildSectionOrder() {
if (config->warnSymbolOrdering)
for (auto orderEntry : symbolOrder)
if (!orderEntry.second.present)
- warn("symbol ordering file: no such symbol: " + orderEntry.first);
+ warn("symbol ordering file: no such symbol: " + orderEntry.first.val());
return sectionOrder;
}
@@ -1947,7 +1947,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
for (SharedFile *file : sharedFiles) {
bool allNeededIsKnown =
llvm::all_of(file->dtNeeded, [&](StringRef needed) {
- return symtab->soNames.count(needed);
+ return symtab->soNames.count(CachedHashStringRef(needed));
});
if (!allNeededIsKnown)
continue;
More information about the llvm-commits
mailing list