diff options
author | Dhruv Chawla <dhruv263.dc@gmail.com> | 2023-09-15 17:49:31 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-15 17:49:31 +0530 |
commit | ff9ae3f49d69c0c37e2fd009e7b7b239bfa5ece2 (patch) | |
tree | df44ff7740a7f3c64050124a536709abb953e9e1 /llvm/lib/Object/IRSymtab.cpp | |
parent | 24a082878f7baec3651de56d54e5aa2b75a21b5f (diff) | |
download | llvm-ff9ae3f49d69c0c37e2fd009e7b7b239bfa5ece2.zip llvm-ff9ae3f49d69c0c37e2fd009e7b7b239bfa5ece2.tar.gz llvm-ff9ae3f49d69c0c37e2fd009e7b7b239bfa5ece2.tar.bz2 |
[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.
Diffstat (limited to 'llvm/lib/Object/IRSymtab.cpp')
-rw-r--r-- | llvm/lib/Object/IRSymtab.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp index 14db7a1..18fc2e4 100644 --- a/llvm/lib/Object/IRSymtab.cpp +++ b/llvm/lib/Object/IRSymtab.cpp @@ -215,6 +215,11 @@ Expected<int> Builder::getComdatIndex(const Comdat *C, const Module *M) { return P.first->second; } +static DenseSet<StringRef> buildPreservedSymbolsSet() { + return DenseSet<StringRef>(std::begin(PreservedSymbols), + std::end(PreservedSymbols)); +} + Error Builder::addSymbol(const ModuleSymbolTable &Msymtab, const SmallPtrSet<GlobalValue *, 4> &Used, ModuleSymbolTable::Symbol Msym) { @@ -270,7 +275,9 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab, setStr(Sym.IRName, GV->getName()); - bool IsPreservedSymbol = llvm::is_contained(PreservedSymbols, GV->getName()); + static const DenseSet<StringRef> PreservedSymbolsSet = + buildPreservedSymbolsSet(); + bool IsPreservedSymbol = PreservedSymbolsSet.contains(GV->getName()); if (Used.count(GV) || IsPreservedSymbol) Sym.Flags |= 1 << storage::Symbol::FB_used; |