ModuleSymbolTable.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //===- ModuleSymbolTable.h - symbol table for in-memory IR ------*- C++ -*-===//
  2. //
  3. // 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
  6. //
  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. #ifndef LLVM_OBJECT_MODULESYMBOLTABLE_H
  15. #define LLVM_OBJECT_MODULESYMBOLTABLE_H
  16. #include "llvm/ADT/ArrayRef.h"
  17. #include "llvm/ADT/PointerUnion.h"
  18. #include "llvm/IR/Mangler.h"
  19. #include "llvm/Object/SymbolicFile.h"
  20. #include "llvm/Support/Allocator.h"
  21. #include <cstdint>
  22. #include <string>
  23. #include <utility>
  24. #include <vector>
  25. namespace llvm {
  26. class GlobalValue;
  27. class Module;
  28. class ModuleSymbolTable {
  29. public:
  30. using AsmSymbol = std::pair<std::string, uint32_t>;
  31. using Symbol = PointerUnion<GlobalValue *, AsmSymbol *>;
  32. private:
  33. Module *FirstMod = nullptr;
  34. SpecificBumpPtrAllocator<AsmSymbol> AsmSymbols;
  35. std::vector<Symbol> SymTab;
  36. Mangler Mang;
  37. public:
  38. ArrayRef<Symbol> symbols() const { return SymTab; }
  39. void addModule(Module *M);
  40. void printSymbolName(raw_ostream &OS, Symbol S) const;
  41. uint32_t getSymbolFlags(Symbol S) const;
  42. /// Parse inline ASM and collect the symbols that are defined or referenced in
  43. /// the current module.
  44. ///
  45. /// For each found symbol, call \p AsmSymbol with the name of the symbol found
  46. /// and the associated flags.
  47. static void CollectAsmSymbols(
  48. const Module &M,
  49. function_ref<void(StringRef, object::BasicSymbolRef::Flags)> AsmSymbol);
  50. /// Parse inline ASM and collect the symvers directives that are defined in
  51. /// the current module.
  52. ///
  53. /// For each found symbol, call \p AsmSymver with the name of the symbol and
  54. /// its alias.
  55. static void
  56. CollectAsmSymvers(const Module &M,
  57. function_ref<void(StringRef, StringRef)> AsmSymver);
  58. };
  59. } // end namespace llvm
  60. #endif // LLVM_OBJECT_MODULESYMBOLTABLE_H