Coverage Report

Created: 2017-09-19 22:28

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/lld/include/lld/Core/SymbolTable.h
Line
Count
Source
1
//===- Core/SymbolTable.h - Main Symbol Table -----------------------------===//
2
//
3
//                             The LLVM Linker
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLD_CORE_SYMBOL_TABLE_H
11
#define LLD_CORE_SYMBOL_TABLE_H
12
13
#include "lld/Core/LLVM.h"
14
#include "llvm/ADT/DenseSet.h"
15
#include "llvm/ADT/StringExtras.h"
16
#include <cstring>
17
#include <map>
18
#include <vector>
19
20
namespace lld {
21
22
class AbsoluteAtom;
23
class Atom;
24
class DefinedAtom;
25
class LinkingContext;
26
class ResolverOptions;
27
class SharedLibraryAtom;
28
class UndefinedAtom;
29
30
/// \brief The SymbolTable class is responsible for coalescing atoms.
31
///
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.
35
class SymbolTable {
36
public:
37
  /// @brief add atom to symbol table
38
  bool add(const DefinedAtom &);
39
40
  /// @brief add atom to symbol table
41
  bool add(const UndefinedAtom &);
42
43
  /// @brief add atom to symbol table
44
  bool add(const SharedLibraryAtom &);
45
46
  /// @brief add atom to symbol table
47
  bool add(const AbsoluteAtom &);
48
49
  /// @brief returns atom in symbol table for specified name (or nullptr)
50
  const Atom *findByName(StringRef sym);
51
52
  /// @brief returns vector of remaining UndefinedAtoms
53
  std::vector<const UndefinedAtom *> undefines();
54
55
  /// @brief if atom has been coalesced away, return replacement, else return atom
56
  const Atom *replacement(const Atom *);
57
58
  /// @brief if atom has been coalesced away, return true
59
  bool isCoalescedAway(const Atom *);
60
61
private:
62
  typedef llvm::DenseMap<const Atom *, const Atom *> AtomToAtom;
63
64
  struct StringRefMappingInfo {
65
3.82k
    static StringRef getEmptyKey() { return StringRef(); }
66
2.98k
    static StringRef getTombstoneKey() { return StringRef(" ", 1); }
67
1.99k
    static unsigned getHashValue(StringRef const val) {
68
1.99k
      return llvm::HashString(val);
69
1.99k
    }
70
25.8k
    static bool isEqual(StringRef const lhs, StringRef const rhs) {
71
25.8k
      return lhs.equals(rhs);
72
25.8k
    }
73
  };
74
  typedef llvm::DenseMap<StringRef, const Atom *,
75
                                           StringRefMappingInfo> NameToAtom;
76
77
  struct AtomMappingInfo {
78
438
    static const DefinedAtom * getEmptyKey() { return nullptr; }
79
184
    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);
83
  };
84
  typedef llvm::DenseSet<const DefinedAtom*, AtomMappingInfo> AtomContentSet;
85
86
  bool addByName(const Atom &);
87
  bool addByContent(const DefinedAtom &);
88
89
  AtomToAtom _replacedAtoms;
90
  NameToAtom _nameTable;
91
  AtomContentSet _contentTable;
92
};
93
94
} // namespace lld
95
96
#endif // LLD_CORE_SYMBOL_TABLE_H