blob: 4c582fbcda81107a97c1cec3b5555cb4156263bc [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- ModuleSymbolTable.h - symbol table for in-memory IR ------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8//
9// This class represents a symbol table built from in-memory IR. It provides
10// access to GlobalValues and should only be used if such access is required
11// (e.g. in the LTO implementation).
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_OBJECT_MODULESYMBOLTABLE_H
16#define LLVM_OBJECT_MODULESYMBOLTABLE_H
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/PointerUnion.h"
20#include "llvm/IR/Mangler.h"
21#include "llvm/Object/SymbolicFile.h"
22#include "llvm/Support/Allocator.h"
23#include <cstdint>
24#include <string>
25#include <utility>
26#include <vector>
27
28namespace llvm {
29
30class GlobalValue;
31
32class ModuleSymbolTable {
33public:
34 using AsmSymbol = std::pair<std::string, uint32_t>;
35 using Symbol = PointerUnion<GlobalValue *, AsmSymbol *>;
36
37private:
38 Module *FirstMod = nullptr;
39
40 SpecificBumpPtrAllocator<AsmSymbol> AsmSymbols;
41 std::vector<Symbol> SymTab;
42 Mangler Mang;
43
44public:
45 ArrayRef<Symbol> symbols() const { return SymTab; }
46 void addModule(Module *M);
47
48 void printSymbolName(raw_ostream &OS, Symbol S) const;
49 uint32_t getSymbolFlags(Symbol S) const;
50
51 /// Parse inline ASM and collect the symbols that are defined or referenced in
52 /// the current module.
53 ///
54 /// For each found symbol, call \p AsmSymbol with the name of the symbol found
55 /// and the associated flags.
56 static void CollectAsmSymbols(
57 const Module &M,
58 function_ref<void(StringRef, object::BasicSymbolRef::Flags)> AsmSymbol);
Andrew Scullcdfcccc2018-10-05 20:58:37 +010059
60 /// Parse inline ASM and collect the symvers directives that are defined in
61 /// the current module.
62 ///
63 /// For each found symbol, call \p AsmSymver with the name of the symbol and
64 /// its alias.
65 static void
66 CollectAsmSymvers(const Module &M,
67 function_ref<void(StringRef, StringRef)> AsmSymver);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010068};
69
70} // end namespace llvm
71
72#endif // LLVM_OBJECT_MODULESYMBOLTABLE_H