LLVM 24.0.0git
Mangling.cpp
Go to the documentation of this file.
1//===----------- Mangling.cpp -- Name Mangling Utilities for ORC ----------===//
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
10#include "llvm/ADT/StringRef.h"
11#include "llvm/IR/Constants.h"
12
13#define DEBUG_TYPE "orc"
14
15namespace llvm::orc {
16
19 SymbolFlagsMap &SymbolFlags,
20 SymbolNameToDefinitionMap *SymbolToDefinition) {
21 if (GVs.empty())
22 return;
23
24 MangleAndInterner Mangle(ES, GVs[0]->getDataLayout());
25 for (auto *G : GVs) {
26 assert(G && "GVs cannot contain null elements");
27 if (!G->hasName() || G->isDeclaration() || G->hasLocalLinkage() ||
28 G->hasAvailableExternallyLinkage() || G->hasAppendingLinkage())
29 continue;
30
31 if (G->isThreadLocal() && MO.EmulatedTLS) {
32 auto *GV = cast<GlobalVariable>(G);
33
34 auto Flags = JITSymbolFlags::fromGlobalValue(*GV);
35
36 auto EmuTLSV = Mangle(("__emutls_v." + GV->getName()).str());
37 SymbolFlags[EmuTLSV] = Flags;
38 if (SymbolToDefinition)
39 (*SymbolToDefinition)[EmuTLSV] = GV;
40
41 // If this GV has a non-zero initializer we'll need to emit an
42 // __emutls.t symbol too.
43 if (GV->hasInitializer()) {
44 const auto *InitVal = GV->getInitializer();
45
46 // Skip zero-initializers.
47 if (isa<ConstantAggregateZero>(InitVal))
48 continue;
49 const auto *InitIntValue = dyn_cast<ConstantInt>(InitVal);
50 if (InitIntValue && InitIntValue->isZero())
51 continue;
52
53 auto EmuTLST = Mangle(("__emutls_t." + GV->getName()).str());
54 SymbolFlags[EmuTLST] = Flags;
55 if (SymbolToDefinition)
56 (*SymbolToDefinition)[EmuTLST] = GV;
57 }
58 continue;
59 }
60
61 // Otherwise we just need a normal linker mangling.
62 auto MangledName = Mangle(G->getName());
63 SymbolFlags[MangledName] = JITSymbolFlags::fromGlobalValue(*G);
64 if (SymbolToDefinition)
65 (*SymbolToDefinition)[MangledName] = G;
66 }
67}
68
69} // namespace llvm::orc
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
#define G(x, y, z)
Definition MD5.cpp:55
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
static LLVM_ABI JITSymbolFlags fromGlobalValue(const GlobalValue &GV)
Construct a JITSymbolFlags value based on the flags of the given global value.
Definition JITSymbol.cpp:22
An ExecutionSession represents a running JIT program.
Definition Core.h:1111
static LLVM_ABI void add(ExecutionSession &ES, const ManglingOptions &MO, ArrayRef< GlobalValue * > GVs, SymbolFlagsMap &SymbolFlags, SymbolNameToDefinitionMap *SymbolToDefinition=nullptr)
Add mangled symbols for the given GlobalValues to SymbolFlags.
Definition Mangling.cpp:17
std::map< SymbolStringPtr, GlobalValue * > SymbolNameToDefinitionMap
Definition Mangling.h:67
Mangles symbol names then uniques them in the context of an ExecutionSession.
Definition Mangling.h:28
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559