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 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 "llvm/Support/Compiler.h" 24 #include <cstdint> 25 #include <string> 26 #include <utility> 27 #include <vector> 28 29 namespace llvm { 30 31 class GlobalValue; 32 class Module; 33 34 class ModuleSymbolTable { 35 public: 36 using AsmSymbol = std::pair<std::string, uint32_t>; 37 using Symbol = PointerUnion<GlobalValue *, AsmSymbol *>; 38 39 private: 40 Module *FirstMod = nullptr; 41 42 SpecificBumpPtrAllocator<AsmSymbol> AsmSymbols; 43 std::vector<Symbol> SymTab; 44 Mangler Mang; 45 46 public: symbols()47 ArrayRef<Symbol> symbols() const { return SymTab; } 48 LLVM_ABI void addModule(Module *M); 49 50 LLVM_ABI void printSymbolName(raw_ostream &OS, Symbol S) const; 51 LLVM_ABI uint32_t getSymbolFlags(Symbol S) const; 52 53 /// Parse inline ASM and collect the symbols that are defined or referenced in 54 /// the current module. 55 /// 56 /// For each found symbol, call \p AsmSymbol with the name of the symbol found 57 /// and the associated flags. 58 LLVM_ABI static void CollectAsmSymbols( 59 const Module &M, 60 function_ref<void(StringRef, object::BasicSymbolRef::Flags)> AsmSymbol); 61 62 /// Parse inline ASM and collect the symvers directives that are defined in 63 /// the current module. 64 /// 65 /// For each found symbol, call \p AsmSymver with the name of the symbol and 66 /// its alias. 67 LLVM_ABI static void 68 CollectAsmSymvers(const Module &M, 69 function_ref<void(StringRef, StringRef)> AsmSymver); 70 }; 71 72 } // end namespace llvm 73 74 #endif // LLVM_OBJECT_MODULESYMBOLTABLE_H 75