Skip to content

Commit ff9ae3f

Browse files
authored
[IRSymtab] Replace linear time lookup with DenseSet (#66376)
There is an inefficiency in the IRSymtab Builder where it does a lookup of PreservedSymbols when calling addSymbol. This lookup is linear in time, so it tends to be quite slow. Replacing it with DenseSet gives a 0.1% speedup: https://llvm-compile-time-tracker.com/compare.php?from=02d27eac0f3f470a93635fc98ae990bf2a9809ed&to=62b09786fff4d53aa0c75b64aea48de241e4a856&stat=instructions:u This change is quite similar to https://reviews.llvm.org/D157951.
1 parent 24a0828 commit ff9ae3f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

llvm/lib/Object/IRSymtab.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ Expected<int> Builder::getComdatIndex(const Comdat *C, const Module *M) {
215215
return P.first->second;
216216
}
217217

218+
static DenseSet<StringRef> buildPreservedSymbolsSet() {
219+
return DenseSet<StringRef>(std::begin(PreservedSymbols),
220+
std::end(PreservedSymbols));
221+
}
222+
218223
Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
219224
const SmallPtrSet<GlobalValue *, 4> &Used,
220225
ModuleSymbolTable::Symbol Msym) {
@@ -270,7 +275,9 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
270275

271276
setStr(Sym.IRName, GV->getName());
272277

273-
bool IsPreservedSymbol = llvm::is_contained(PreservedSymbols, GV->getName());
278+
static const DenseSet<StringRef> PreservedSymbolsSet =
279+
buildPreservedSymbolsSet();
280+
bool IsPreservedSymbol = PreservedSymbolsSet.contains(GV->getName());
274281

275282
if (Used.count(GV) || IsPreservedSymbol)
276283
Sym.Flags |= 1 << storage::Symbol::FB_used;

0 commit comments

Comments
 (0)