1 //===------ Mangling.h -- Name Mangling Utilities for ORC -------*- 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 // Name mangling utilities for ORC. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_EXECUTIONENGINE_ORC_MANGLING_H 14 #define LLVM_EXECUTIONENGINE_ORC_MANGLING_H 15 16 #include "llvm/ExecutionEngine/Orc/Core.h" 17 #include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h" 18 #include "llvm/IR/Module.h" 19 #include "llvm/Support/Compiler.h" 20 #include "llvm/Support/MemoryBuffer.h" 21 22 namespace llvm { 23 namespace orc { 24 25 /// Mangles symbol names then uniques them in the context of an 26 /// ExecutionSession. 27 class MangleAndInterner { 28 public: 29 LLVM_ABI MangleAndInterner(ExecutionSession &ES, const DataLayout &DL); 30 LLVM_ABI SymbolStringPtr operator()(StringRef Name); 31 32 private: 33 ExecutionSession &ES; 34 const DataLayout &DL; 35 }; 36 37 /// Maps IR global values to their linker symbol names / flags. 38 /// 39 /// This utility can be used when adding new IR globals in the JIT. 40 class IRSymbolMapper { 41 public: 42 struct ManglingOptions { 43 bool EmulatedTLS = false; 44 }; 45 46 using SymbolNameToDefinitionMap = std::map<SymbolStringPtr, GlobalValue *>; 47 48 /// Add mangled symbols for the given GlobalValues to SymbolFlags. 49 /// If a SymbolToDefinitionMap pointer is supplied then it will be populated 50 /// with Name-to-GlobalValue* mappings. Note that this mapping is not 51 /// necessarily one-to-one: thread-local GlobalValues, for example, may 52 /// produce more than one symbol, in which case the map will contain duplicate 53 /// values. 54 LLVM_ABI static void 55 add(ExecutionSession &ES, const ManglingOptions &MO, 56 ArrayRef<GlobalValue *> GVs, SymbolFlagsMap &SymbolFlags, 57 SymbolNameToDefinitionMap *SymbolToDefinition = nullptr); 58 }; 59 60 } // End namespace orc 61 } // End namespace llvm 62 63 #endif // LLVM_EXECUTIONENGINE_ORC_MANGLING_H 64