1 //===- Core/SymbolTable.h - Main Symbol Table -----------------------------===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLD_CORE_SYMBOL_TABLE_H
11 #define LLD_CORE_SYMBOL_TABLE_H
13 #include "lld/Core/LLVM.h"
14 #include "llvm/ADT/DenseSet.h"
15 #include "llvm/ADT/StringExtras.h"
26 class ResolverOptions;
27 class SharedLibraryAtom;
30 /// \brief The SymbolTable class is responsible for coalescing atoms.
32 /// All atoms coalescable by-name or by-content should be added.
33 /// The method replacement() can be used to find the replacement atom
34 /// if an atom has been coalesced away.
37 /// @brief add atom to symbol table
38 bool add(const DefinedAtom &);
40 /// @brief add atom to symbol table
41 bool add(const UndefinedAtom &);
43 /// @brief add atom to symbol table
44 bool add(const SharedLibraryAtom &);
46 /// @brief add atom to symbol table
47 bool add(const AbsoluteAtom &);
49 /// @brief returns atom in symbol table for specified name (or nullptr)
50 const Atom *findByName(StringRef sym);
52 /// @brief returns vector of remaining UndefinedAtoms
53 std::vector<const UndefinedAtom *> undefines();
55 /// @brief if atom has been coalesced away, return replacement, else return atom
56 const Atom *replacement(const Atom *);
58 /// @brief if atom has been coalesced away, return true
59 bool isCoalescedAway(const Atom *);
62 typedef llvm::DenseMap<const Atom *, const Atom *> AtomToAtom;
64 struct StringRefMappingInfo {
65 static StringRef getEmptyKey() { return StringRef(); }
66 static StringRef getTombstoneKey() { return StringRef(" ", 1); }
67 static unsigned getHashValue(StringRef const val) {
68 return llvm::HashString(val);
70 static bool isEqual(StringRef const lhs, StringRef const rhs) {
71 return lhs.equals(rhs);
74 typedef llvm::DenseMap<StringRef, const Atom *,
75 StringRefMappingInfo> NameToAtom;
77 struct AtomMappingInfo {
78 static const DefinedAtom * getEmptyKey() { return nullptr; }
79 static const DefinedAtom * getTombstoneKey() { return (DefinedAtom*)(-1); }
80 static unsigned getHashValue(const DefinedAtom * const Val);
81 static bool isEqual(const DefinedAtom * const LHS,
82 const DefinedAtom * const RHS);
84 typedef llvm::DenseSet<const DefinedAtom*, AtomMappingInfo> AtomContentSet;
86 bool addByName(const Atom &);
87 bool addByContent(const DefinedAtom &);
89 AtomToAtom _replacedAtoms;
90 NameToAtom _nameTable;
91 AtomContentSet _contentTable;
96 #endif // LLD_CORE_SYMBOL_TABLE_H