ModuleSymbolTable.h 2.4 KB

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