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/MemoryBuffer.h"
20
21namespace llvm {
22namespace orc {
23
24/// Mangles symbol names then uniques them in the context of an
25/// ExecutionSession.
26class MangleAndInterner {
27public:
28 MangleAndInterner(ExecutionSession &ES, const DataLayout &DL);
29 SymbolStringPtr operator()(StringRef Name);
30
31private:
32 ExecutionSession &ES;
33 const DataLayout &DL;
34};
35
36/// Maps IR global values to their linker symbol names / flags.
37///
38/// This utility can be used when adding new IR globals in the JIT.
39class IRSymbolMapper {
40public:
41 struct ManglingOptions {
42 bool EmulatedTLS = false;
43 };
44
45 using SymbolNameToDefinitionMap = std::map<SymbolStringPtr, GlobalValue *>;
46
47 /// Add mangled symbols for the given GlobalValues to SymbolFlags.
48 /// If a SymbolToDefinitionMap pointer is supplied then it will be populated
49 /// with Name-to-GlobalValue* mappings. Note that this mapping is not
50 /// necessarily one-to-one: thread-local GlobalValues, for example, may
51 /// produce more than one symbol, in which case the map will contain duplicate
52 /// values.
53 static void add(ExecutionSession &ES, const ManglingOptions &MO,
54 ArrayRef<GlobalValue *> GVs, SymbolFlagsMap &SymbolFlags,
55 SymbolNameToDefinitionMap *SymbolToDefinition = nullptr);
56};
57
58/// Returns a SymbolFlagsMap for the object file represented by the given
59/// buffer, or an error if the buffer does not contain a valid object file.
60Expected<std::pair<SymbolFlagsMap, SymbolStringPtr>>
61getObjectSymbolInfo(ExecutionSession &ES, MemoryBufferRef ObjBuffer);
62
63} // End namespace orc
64} // End namespace llvm
65
66#endif // LLVM_EXECUTIONENGINE_ORC_MANGLING_H
67