AMDGPU: Mark test as XFAIL in expensive_checks builds
[llvm-project.git] / llvm / lib / ExecutionEngine / Orc / Mangling.cpp
blobfdff0e6af7aabf8af11d35eeccb66a71bcbe8d4c
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 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/Mangling.h"
10 #include "llvm/IR/Constants.h"
11 #include "llvm/IR/Mangler.h"
13 #define DEBUG_TYPE "orc"
15 namespace llvm {
16 namespace orc {
18 MangleAndInterner::MangleAndInterner(ExecutionSession &ES, const DataLayout &DL)
19 : ES(ES), DL(DL) {}
21 SymbolStringPtr MangleAndInterner::operator()(StringRef Name) {
22 std::string MangledName;
24 raw_string_ostream MangledNameStream(MangledName);
25 Mangler::getNameWithPrefix(MangledNameStream, Name, DL);
27 return ES.intern(MangledName);
30 void IRSymbolMapper::add(ExecutionSession &ES, const ManglingOptions &MO,
31 ArrayRef<GlobalValue *> GVs,
32 SymbolFlagsMap &SymbolFlags,
33 SymbolNameToDefinitionMap *SymbolToDefinition) {
34 if (GVs.empty())
35 return;
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;
44 if (G->isThreadLocal() && MO.EmulatedTLS) {
45 auto *GV = cast<GlobalVariable>(G);
47 auto Flags = JITSymbolFlags::fromGlobalValue(*GV);
49 auto EmuTLSV = Mangle(("__emutls_v." + GV->getName()).str());
50 SymbolFlags[EmuTLSV] = Flags;
51 if (SymbolToDefinition)
52 (*SymbolToDefinition)[EmuTLSV] = GV;
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();
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;
66 auto EmuTLST = Mangle(("__emutls_t." + GV->getName()).str());
67 SymbolFlags[EmuTLST] = Flags;
68 if (SymbolToDefinition)
69 (*SymbolToDefinition)[EmuTLST] = GV;
71 continue;
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;
82 } // End namespace orc.
83 } // End namespace llvm.