LLVM: lib/IR/Mangler.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
24
25using namespace llvm;
26
27namespace {
28enum ManglerPrefixTy {
29 Default,
30 Private,
31 LinkerPrivate
32};
33}
34
36 ManglerPrefixTy PrefixTy,
40 assert(.empty() && "getNameWithPrefix requires non-empty name");
41
42
43
44 if (Name[0] == '\1') {
46 return;
47 }
48
49 if (DL.doNotMangleLeadingQuestionMark() && Name[0] == '?')
50 Prefix = '\0';
51
52 if (PrefixTy == Private)
53 OS << DL.getPrivateGlobalPrefix();
54 else if (PrefixTy == LinkerPrivate)
55 OS << DL.getLinkerPrivateGlobalPrefix();
56
57 if (Prefix != '\0')
58 OS << Prefix;
59
60
62}
63
66 ManglerPrefixTy PrefixTy) {
67 char Prefix = DL.getGlobalPrefix();
69}
70
74}
75
79 char Prefix = DL.getGlobalPrefix();
81}
82
84 switch (CC) {
88 return true;
89 default:
90 return false;
91 }
92}
93
94
95
98
99 unsigned ArgWords = 0;
100
101 const unsigned PtrSize = DL.getPointerSize();
102
103 for (const Argument &A : F->args()) {
104
105
106 if (A.hasStructRetAttr())
107 continue;
108
109
110 uint64_t AllocSize = A.hasPassPointeeByValueCopyAttr() ?
111 A.getPassPointeeByValueCopySize(DL) :
112 DL.getTypeAllocSize(A.getType());
113
114
115 ArgWords += alignTo(AllocSize, PtrSize);
116 }
117
118 OS << '@' << ArgWords;
119}
120
122 bool CannotUsePrivateLabel) const {
123 ManglerPrefixTy PrefixTy = Default;
124 assert(GV != nullptr && "Invalid Global Value");
126 if (CannotUsePrivateLabel)
127 PrefixTy = LinkerPrivate;
128 else
129 PrefixTy = Private;
130 }
131
134
135
136 unsigned &ID = AnonGlobalIDs[GV];
137 if (ID == 0)
138 ID = AnonGlobalIDs.size();
139
140
142 return;
143 }
144
146 char Prefix = DL.getGlobalPrefix();
147
148
149
151
152
153
154 if (Name.starts_with("\01") ||
155 (DL.doNotMangleLeadingQuestionMark() && Name.starts_with("?")))
156 MSFunc = nullptr;
157
160 if (.hasMicrosoftFastStdCallMangling() &&
162 MSFunc = nullptr;
163 if (MSFunc) {
165 Prefix = '@';
167 Prefix = '\0';
168 }
169
171
172 if (!MSFunc)
173 return;
174
175
176
177
179 OS << '@';
182
186}
187
190 bool CannotUsePrivateLabel) const {
193}
194
195
197 return isAlnum(C) || C == '_' || C == '@' || C == '#';
198}
199
201 if (Name.empty())
202 return false;
203
204
205
208 return false;
209 }
210
211 return true;
212}
213
217
218 if (TT.isWindowsMSVCEnvironment())
219 OS << " /EXPORT:";
220 else
221 OS << " -export:";
222
224 if (NeedQuotes)
225 OS << "\"";
226 if (TT.isWindowsGNUEnvironment() || TT.isWindowsCygwinEnvironment()) {
227 std::string Flag;
232 OS << Flag.substr(1);
233 else
234 OS << Flag;
235 } else {
237 }
238 if (TT.isWindowsArm64EC()) {
239
240
241
242
243
244 if (std::optionalstd::string demangledName =
246 OS << ",EXPORTAS," << *demangledName;
247 }
248 if (NeedQuotes)
249 OS << "\"";
250
252 if (TT.isWindowsMSVCEnvironment())
253 OS << ",DATA";
254 else
255 OS << ",data";
256 }
257 }
259
260 OS << " -exclude-symbols:";
261
263 if (NeedQuotes)
264 OS << "\"";
265
266 std::string Flag;
271 OS << Flag.substr(1);
272 else
273 OS << Flag;
274
275 if (NeedQuotes)
276 OS << "\"";
277 }
278}
279
282 if (.isWindowsMSVCEnvironment())
283 return;
284
285 OS << " /INCLUDE:";
287 if (NeedQuotes)
288 OS << "\"";
289 M.getNameWithPrefix(OS, GV, false);
290 if (NeedQuotes)
291 OS << "\"";
292}
293
295 if (Name[0] != '?') {
296
297
298 if (Name[0] == '#')
299 return std::nullopt;
300 return std::optionalstd::string(("#" + Name).str());
301 }
302
303
304 if (Name.contains("$$h"))
305 return std::nullopt;
306
307
309 if (!InsertIdx)
310 return std::nullopt;
311
312 return std::optionalstd::string(
313 (Name.substr(0, *InsertIdx) + "$$h" + Name.substr(*InsertIdx)).str());
314}
315
316std::optionalstd::string
318
319 if (Name[0] == '#')
320 return std::optionalstd::string(Name.substr(1));
321 if (Name[0] != '?')
322 return std::nullopt;
323
324
325 std::pair<StringRef, StringRef> Pair = Name.split("$$h");
326 if (Pair.second.empty())
327 return std::nullopt;
328 return std::optionalstd::string((Pair.first + Pair.second).str());
329}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Module.h This file contains the declarations for the Module class.
static bool canBeUnquotedInDirective(char C)
static void getNameWithPrefixImpl(raw_ostream &OS, const Twine &GVName, ManglerPrefixTy PrefixTy, const DataLayout &DL, char Prefix)
static void addByteCountSuffix(raw_ostream &OS, const Function *F, const DataLayout &DL)
Microsoft fastcall and stdcall functions require a suffix on their name indicating the number of word...
static bool hasByteCountSuffix(CallingConv::ID CC)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
This class represents an incoming formal argument to a Function.
A parsed version of the target data layout string in and methods for querying it.
char getGlobalPrefix() const
Class to represent function types.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
bool hasStructRetAttr() const
Determine if the function returns a structure through first or second pointer argument.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
bool hasPrivateLinkage() const
bool hasHiddenVisibility() const
bool hasDLLExportStorageClass() const
const GlobalObject * getAliaseeObject() const
const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Type * getValueType() const
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
bool isFunctionTy() const
True if this is an instance of FunctionType.
StringRef getName() const
Return a constant reference to the value's name.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
@ X86_StdCall
stdcall is mostly used by the Win32 API.
@ X86_VectorCall
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
@ C
The default llvm calling convention, compatible with C.
@ X86_FastCall
'fast' analog of X86_StdCall.
This is an optimization pass for GlobalISel generic memory operations.
std::optional< std::string > getArm64ECMangledFunctionName(StringRef Name)
Returns the ARM64EC mangled function name unless the input is already mangled.
std::optional< std::string > getArm64ECDemangledFunctionName(StringRef Name)
Returns the ARM64EC demangled function name, unless the input is not mangled.
std::optional< size_t > getArm64ECInsertionPointInMangledName(std::string_view MangledName)
void emitLinkerFlagsForUsedCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &T, Mangler &M)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
void emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &TT, Mangler &Mangler)
@ Default
The result values are uniform if and only if all operands are uniform.