• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- ModuleSymbolTable.h - symbol table for in-memory IR ------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class represents a symbol table built from in-memory IR. It provides
11 // access to GlobalValues and should only be used if such access is required
12 // (e.g. in the LTO implementation).
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_OBJECT_MODULESYMBOLTABLE_H
17 #define LLVM_OBJECT_MODULESYMBOLTABLE_H
18 
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/PointerUnion.h"
21 #include "llvm/IR/Mangler.h"
22 #include "llvm/Object/SymbolicFile.h"
23 #include "llvm/Support/Allocator.h"
24 #include <cstdint>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 
29 namespace llvm {
30 
31 class GlobalValue;
32 
33 class ModuleSymbolTable {
34 public:
35   using AsmSymbol = std::pair<std::string, uint32_t>;
36   using Symbol = PointerUnion<GlobalValue *, AsmSymbol *>;
37 
38 private:
39   Module *FirstMod = nullptr;
40 
41   SpecificBumpPtrAllocator<AsmSymbol> AsmSymbols;
42   std::vector<Symbol> SymTab;
43   Mangler Mang;
44 
45 public:
symbols()46   ArrayRef<Symbol> symbols() const { return SymTab; }
47   void addModule(Module *M);
48 
49   void printSymbolName(raw_ostream &OS, Symbol S) const;
50   uint32_t getSymbolFlags(Symbol S) const;
51 
52   /// Parse inline ASM and collect the symbols that are defined or referenced in
53   /// the current module.
54   ///
55   /// For each found symbol, call \p AsmSymbol with the name of the symbol found
56   /// and the associated flags.
57   static void CollectAsmSymbols(
58       const Module &M,
59       function_ref<void(StringRef, object::BasicSymbolRef::Flags)> AsmSymbol);
60 
61   /// Parse inline ASM and collect the symvers directives that are defined in
62   /// the current module.
63   ///
64   /// For each found symbol, call \p AsmSymver with the name of the symbol and
65   /// its alias.
66   static void
67   CollectAsmSymvers(const Module &M,
68                     function_ref<void(StringRef, StringRef)> AsmSymver);
69 };
70 
71 } // end namespace llvm
72 
73 #endif // LLVM_OBJECT_MODULESYMBOLTABLE_H
74