[lld] r231432 - Optimize resolver by using std::unordered_multimap.
Rui Ueyama
ruiu at google.com
Thu Mar 5 16:22:48 PST 2015
Author: ruiu
Date: Thu Mar 5 18:22:48 2015
New Revision: 231432
URL: http://llvm.org/viewvc/llvm-project?rev=231432&view=rev
Log:
Optimize resolver by using std::unordered_multimap.
_reverseRef is a multimap from atoms to atoms. The map contains
reverse edges of "layout-before" and "group" edges for dead-stripping.
The type of the variable was DenseMap<Atom *, DenseSet<Atom *>>.
This patch changes that to std::unordered_multimap<Atom *, Atom *>.
A DenseMap with a value type of DenseSet was not fast. Inserting 900k
items to the map took about 1.6 seconds on my workstation.
unordered_multimap on the other hand took only 0.6 seconds.
Use of the map also got faster -- originally markLive took 1.3 seconds
in the same test case, and it now took 1.0 seconds. In total we shove
off 1.3 seconds out of 27 seconds in that test case.
Modified:
lld/trunk/include/lld/Core/Resolver.h
lld/trunk/lib/Core/Resolver.cpp
Modified: lld/trunk/include/lld/Core/Resolver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Resolver.h?rev=231432&r1=231431&r2=231432&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Resolver.h (original)
+++ lld/trunk/include/lld/Core/Resolver.h Thu Mar 5 18:22:48 2015
@@ -18,6 +18,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include <set>
+#include <unordered_map>
#include <unordered_set>
#include <vector>
@@ -91,7 +92,7 @@ private:
llvm::DenseSet<const Atom *> _liveAtoms;
llvm::DenseSet<const Atom *> _deadAtoms;
std::unique_ptr<MergedFile> _result;
- llvm::DenseMap<const Atom *, llvm::DenseSet<const Atom *>> _reverseRef;
+ std::unordered_multimap<const Atom *, const Atom *> _reverseRef;
// --start-group and --end-group
std::vector<File *> _files;
Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=231432&r1=231431&r2=231432&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Thu Mar 5 18:22:48 2015
@@ -17,12 +17,14 @@
#include "lld/Core/SharedLibraryFile.h"
#include "lld/Core/SymbolTable.h"
#include "lld/Core/UndefinedAtom.h"
+#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
+#include <utility>
#include <vector>
namespace lld {
@@ -372,8 +374,10 @@ void Resolver::markLive(const Atom *atom
if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom)) {
for (const Reference *ref : *defAtom)
markLive(ref->target());
- for (const Atom *target : _reverseRef.lookup(defAtom))
+ for (auto &p : llvm::make_range(_reverseRef.equal_range(defAtom))) {
+ const Atom *target = p.second;
markLive(target);
+ }
}
}
@@ -399,7 +403,7 @@ void Resolver::deadStripOptimize() {
if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom))
for (const Reference *ref : *defAtom)
if (isBackref(ref))
- _reverseRef[ref->target()].insert(atom);
+ _reverseRef.insert(std::make_pair(ref->target(), atom));
if (const AbsoluteAtom *absAtom = dyn_cast<AbsoluteAtom>(atom))
markLive(absAtom);
}
More information about the llvm-commits
mailing list