forked from OSchip/llvm-project
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. llvm-svn: 231432
This commit is contained in:
parent
b202b27a22
commit
25d5abdb3a
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue