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 checks if name is in symbol table and if so atom is not
51 bool isDefined(StringRef sym);
53 /// @brief returns atom in symbol table for specified name (or nullptr)
54 const Atom *findByName(StringRef sym);
56 /// @brief returns vector of remaining UndefinedAtoms
57 std::vector<const UndefinedAtom *> undefines();
59 /// returns vector of tentative definitions
60 std::vector<StringRef> tentativeDefinitions();
62 /// @brief add atom to replacement table
63 void addReplacement(const Atom *replaced, const Atom *replacement);
65 /// @brief if atom has been coalesced away, return replacement, else return atom
66 const Atom *replacement(const Atom *);
68 /// @brief if atom has been coalesced away, return true
69 bool isCoalescedAway(const Atom *);
72 typedef llvm::DenseMap<const Atom *, const Atom *> AtomToAtom;
74 struct StringRefMappingInfo {
75 static StringRef getEmptyKey() { return StringRef(); }
76 static StringRef getTombstoneKey() { return StringRef(" ", 1); }
77 static unsigned getHashValue(StringRef const val) {
78 return llvm::HashString(val);
80 static bool isEqual(StringRef const lhs, StringRef const rhs) {
81 return lhs.equals(rhs);
84 typedef llvm::DenseMap<StringRef, const Atom *,
85 StringRefMappingInfo> NameToAtom;
87 struct AtomMappingInfo {
88 static const DefinedAtom * getEmptyKey() { return nullptr; }
89 static const DefinedAtom * getTombstoneKey() { return (DefinedAtom*)(-1); }
90 static unsigned getHashValue(const DefinedAtom * const Val);
91 static bool isEqual(const DefinedAtom * const LHS,
92 const DefinedAtom * const RHS);
94 typedef llvm::DenseSet<const DefinedAtom*, AtomMappingInfo> AtomContentSet;
96 bool addByName(const Atom &);
97 bool addByContent(const DefinedAtom &);
99 AtomToAtom _replacedAtoms;
100 NameToAtom _nameTable;
101 AtomContentSet _contentTable;
106 #endif // LLD_CORE_SYMBOL_TABLE_H