LLVM 17.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/IR/Constants.h"
11#include "llvm/IR/Mangler.h"
12#include "llvm/Support/Debug.h"
13
14#define DEBUG_TYPE "orc"
15
16namespace llvm {
17namespace orc {
18
20 : ES(ES), DL(DL) {}
21
23 std::string MangledName;
24 {
25 raw_string_ostream MangledNameStream(MangledName);
26 Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
27 }
28 return ES.intern(MangledName);
29}
30
33 SymbolFlagsMap &SymbolFlags,
34 SymbolNameToDefinitionMap *SymbolToDefinition) {
35 if (GVs.empty())
36 return;
37
38 MangleAndInterner Mangle(ES, GVs[0]->getParent()->getDataLayout());
39 for (auto *G : GVs) {
40 assert(G && "GVs cannot contain null elements");
41 if (!G->hasName() || G->isDeclaration() || G->hasLocalLinkage() ||
42 G->hasAvailableExternallyLinkage() || G->hasAppendingLinkage())
43 continue;
44
45 if (G->isThreadLocal() && MO.EmulatedTLS) {
46 auto *GV = cast<GlobalVariable>(G);
47
48 auto Flags = JITSymbolFlags::fromGlobalValue(*GV);
49
50 auto EmuTLSV = Mangle(("__emutls_v." + GV->getName()).str());
51 SymbolFlags[EmuTLSV] = Flags;
52 if (SymbolToDefinition)
53 (*SymbolToDefinition)[EmuTLSV] = GV;
54
55 // If this GV has a non-zero initializer we'll need to emit an
56 // __emutls.t symbol too.
57 if (GV->hasInitializer()) {
58 const auto *InitVal = GV->getInitializer();
59
60 // Skip zero-initializers.
61 if (isa<ConstantAggregateZero>(InitVal))
62 continue;
63 const auto *InitIntValue = dyn_cast<ConstantInt>(InitVal);
64 if (InitIntValue && InitIntValue->isZero())
65 continue;
66
67 auto EmuTLST = Mangle(("__emutls_t." + GV->getName()).str());
68 SymbolFlags[EmuTLST] = Flags;
69 if (SymbolToDefinition)
70 (*SymbolToDefinition)[EmuTLST] = GV;
71 }
72 continue;
73 }
74
75 // Otherwise we just need a normal linker mangling.
76 auto MangledName = Mangle(G->getName());
77 SymbolFlags[MangledName] = JITSymbolFlags::fromGlobalValue(*G);
78 if (SymbolToDefinition)
79 (*SymbolToDefinition)[MangledName] = G;
80 }
81}
82
83} // End namespace orc.
84} // End namespace llvm.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::string Name
#define G(x, y, z)
Definition: MD5.cpp:56
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:158
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:114
static JITSymbolFlags fromGlobalValue(const GlobalValue &GV)
Construct a JITSymbolFlags value based on the flags of the given global value.
Definition: JITSymbol.cpp:22
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
Definition: Mangler.cpp:119
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
An ExecutionSession represents a running JIT program.
Definition: Core.h:1373
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
Definition: Core.h:1424
static 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:31
std::map< SymbolStringPtr, GlobalValue * > SymbolNameToDefinitionMap
Definition: Mangling.h:45
Mangles symbol names then uniques them in the context of an ExecutionSession.
Definition: Mangling.h:26
SymbolStringPtr operator()(StringRef Name)
Definition: Mangling.cpp:22
MangleAndInterner(ExecutionSession &ES, const DataLayout &DL)
Definition: Mangling.cpp:19
Pointer to a pooled string representing a symbol name.
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:642
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18