LLVM 20.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
13#define DEBUG_TYPE "orc"
14
15namespace llvm {
16namespace orc {
17
19 : ES(ES), DL(DL) {}
20
22 std::string MangledName;
23 {
24 raw_string_ostream MangledNameStream(MangledName);
25 Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
26 }
27 return ES.intern(MangledName);
28}
29
32 SymbolFlagsMap &SymbolFlags,
33 SymbolNameToDefinitionMap *SymbolToDefinition) {
34 if (GVs.empty())
35 return;
36
37 MangleAndInterner Mangle(ES, GVs[0]->getDataLayout());
38 for (auto *G : GVs) {
39 assert(G && "GVs cannot contain null elements");
40 if (!G->hasName() || G->isDeclaration() || G->hasLocalLinkage() ||
41 G->hasAvailableExternallyLinkage() || G->hasAppendingLinkage())
42 continue;
43
44 if (G->isThreadLocal() && MO.EmulatedTLS) {
45 auto *GV = cast<GlobalVariable>(G);
46
47 auto Flags = JITSymbolFlags::fromGlobalValue(*GV);
48
49 auto EmuTLSV = Mangle(("__emutls_v." + GV->getName()).str());
50 SymbolFlags[EmuTLSV] = Flags;
51 if (SymbolToDefinition)
52 (*SymbolToDefinition)[EmuTLSV] = GV;
53
54 // If this GV has a non-zero initializer we'll need to emit an
55 // __emutls.t symbol too.
56 if (GV->hasInitializer()) {
57 const auto *InitVal = GV->getInitializer();
58
59 // Skip zero-initializers.
60 if (isa<ConstantAggregateZero>(InitVal))
61 continue;
62 const auto *InitIntValue = dyn_cast<ConstantInt>(InitVal);
63 if (InitIntValue && InitIntValue->isZero())
64 continue;
65
66 auto EmuTLST = Mangle(("__emutls_t." + GV->getName()).str());
67 SymbolFlags[EmuTLST] = Flags;
68 if (SymbolToDefinition)
69 (*SymbolToDefinition)[EmuTLST] = GV;
70 }
71 continue;
72 }
73
74 // Otherwise we just need a normal linker mangling.
75 auto MangledName = Mangle(G->getName());
76 SymbolFlags[MangledName] = JITSymbolFlags::fromGlobalValue(*G);
77 if (SymbolToDefinition)
78 (*SymbolToDefinition)[MangledName] = G;
79 }
80}
81
82} // End namespace orc.
83} // End namespace llvm.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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:163
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
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:121
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
An ExecutionSession represents a running JIT program.
Definition: Core.h:1339
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
Definition: Core.h:1393
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:30
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:21
MangleAndInterner(ExecutionSession &ES, const DataLayout &DL)
Definition: Mangling.cpp:18
Pointer to a pooled string representing a symbol name.
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:661
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18