LLVM 24.0.0git
AMDGPULibFunc.cpp
Go to the documentation of this file.
1//===-- AMDGPULibFunc.cpp -------------------------------------------------===//
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//
9// This file contains utility functions to work with Itanium mangled names
10//
11//===----------------------------------------------------------------------===//
12
13#include "AMDGPULibFunc.h"
14#include "AMDGPU.h"
16#include "llvm/ADT/StringMap.h"
19#include "llvm/IR/Function.h"
20#include "llvm/IR/Module.h"
23#include "llvm/Support/ModRef.h"
25
26using namespace llvm;
27
29 "amdgpu-enable-ocl-mangling-mismatch-workaround", cl::init(true),
31 cl::desc("Enable the workaround for OCL name mangling mismatch."));
32
33namespace {
34
35enum EManglingParam {
36 E_NONE,
37 EX_EVENT,
38 EX_FLOAT4,
39 EX_INTV4,
40 EX_RESERVEDID,
41 EX_SAMPLER,
42 EX_SIZET,
43 EX_UINT,
44 EX_UINTV4,
45 E_ANY,
46 E_CONSTPTR_ANY,
47 E_CONSTPTR_SWAPGL,
48 E_COPY,
49 E_IMAGECOORDS,
50 E_POINTEE,
51 E_SETBASE_I32,
52 E_SETBASE_U32,
53 E_MAKEBASE_UNS,
54 E_V16_OF_POINTEE,
55 E_V2_OF_POINTEE,
56 E_V3_OF_POINTEE,
57 E_V4_OF_POINTEE,
58 E_V8_OF_POINTEE,
59 E_VLTLPTR_ANY,
60};
61
62struct ManglingRule {
63 const char *Name;
64 unsigned char Lead[2];
65 unsigned char Param[5];
66
67 int maxLeadIndex() const { return (std::max)(Lead[0], Lead[1]); }
68
69 unsigned getNumArgs() const;
70
71 static StringMap<int> buildManglingRulesMap();
72};
73
74// Information about library functions with unmangled names.
75class UnmangledFuncInfo {
76 const char *Name;
77 unsigned NumArgs;
78
79 // Table for all lib functions with unmangled names.
80 static const UnmangledFuncInfo Table[];
81
82 // Number of entries in Table.
83 static const unsigned TableSize;
84
85 static StringMap<unsigned> buildNameMap();
86
87public:
88 using ID = AMDGPULibFunc::EFuncId;
89 constexpr UnmangledFuncInfo(const char *_Name, unsigned _NumArgs)
90 : Name(_Name), NumArgs(_NumArgs) {}
91 // Get index to Table by function name.
92 static bool lookup(StringRef Name, ID &Id);
93 static unsigned toIndex(ID Id) {
94 assert(static_cast<unsigned>(Id) >
95 static_cast<unsigned>(AMDGPULibFunc::EI_LAST_MANGLED) &&
96 "Invalid unmangled library function");
97 return static_cast<unsigned>(Id) - 1 -
98 static_cast<unsigned>(AMDGPULibFunc::EI_LAST_MANGLED);
99 }
100 static ID toFuncId(unsigned Index) {
101 assert(Index < TableSize &&
102 "Invalid unmangled library function");
103 return static_cast<ID>(
104 Index + 1 + static_cast<unsigned>(AMDGPULibFunc::EI_LAST_MANGLED));
105 }
106 static unsigned getNumArgs(ID Id) { return Table[toIndex(Id)].NumArgs; }
107};
108
109unsigned ManglingRule::getNumArgs() const {
110 unsigned I=0;
111 while (I < (sizeof Param/sizeof Param[0]) && Param[I]) ++I;
112 return I;
113}
114
115// This table describes function formal argument type rules. The order of rules
116// corresponds to the EFuncId enum at AMDGPULibFunc.h
117//
118// "<func name>", { <leads> }, { <param rules> }
119// where:
120// <leads> - list of integers that are one-based indexes of formal argument
121// used to mangle a function name. Other argument types are derived from types
122// of these 'leads'. The order of integers in this list correspond to the
123// order in which these arguments are mangled in the EDG mangling scheme. The
124// same order should be preserved for arguments in the AMDGPULibFunc structure
125// when it is used for mangling. For example:
126// { "vstorea_half", {3,1}, {E_ANY,EX_SIZET,E_ANY}},
127// will be mangled in EDG scheme as vstorea_half_<3dparam>_<1stparam>
128// When mangling from code use:
129// AMDGPULibFunc insc;
130// insc.param[0] = ... // describe 3rd parameter
131// insc.param[1] = ... // describe 1rd parameter
132//
133// <param rules> - list of rules used to derive all of the function formal
134// argument types. EX_ prefixed are simple types, other derived from the
135// latest 'lead' argument type in the order of encoding from first to last.
136// E_ANY - use prev lead type, E_CONSTPTR_ANY - make const pointer out of
137// prev lead type, etc. see ParamIterator::getNextParam() for details.
138
139static constexpr ManglingRule manglingRules[] = {
140{ "", {0}, {0} },
141{ "abs" , {1}, {E_ANY}},
142{ "abs_diff" , {1}, {E_ANY,E_COPY}},
143{ "acos" , {1}, {E_ANY}},
144{ "acosh" , {1}, {E_ANY}},
145{ "acospi" , {1}, {E_ANY}},
146{ "add_sat" , {1}, {E_ANY,E_COPY}},
147{ "all" , {1}, {E_ANY}},
148{ "any" , {1}, {E_ANY}},
149{ "asin" , {1}, {E_ANY}},
150{ "asinh" , {1}, {E_ANY}},
151{ "asinpi" , {1}, {E_ANY}},
152{ "async_work_group_copy" , {1}, {E_ANY,E_CONSTPTR_SWAPGL,EX_SIZET,EX_EVENT}},
153{ "async_work_group_strided_copy" , {1}, {E_ANY,E_CONSTPTR_SWAPGL,EX_SIZET,EX_SIZET,EX_EVENT}},
154{ "atan" , {1}, {E_ANY}},
155{ "atan2" , {1}, {E_ANY,E_COPY}},
156{ "atan2pi" , {1}, {E_ANY,E_COPY}},
157{ "atanh" , {1}, {E_ANY}},
158{ "atanpi" , {1}, {E_ANY}},
159{ "atomic_add" , {1}, {E_VLTLPTR_ANY,E_POINTEE}},
160{ "atomic_and" , {1}, {E_VLTLPTR_ANY,E_POINTEE}},
161{ "atomic_cmpxchg" , {1}, {E_VLTLPTR_ANY,E_POINTEE,E_POINTEE}},
162{ "atomic_dec" , {1}, {E_VLTLPTR_ANY}},
163{ "atomic_inc" , {1}, {E_VLTLPTR_ANY}},
164{ "atomic_max" , {1}, {E_VLTLPTR_ANY,E_POINTEE}},
165{ "atomic_min" , {1}, {E_VLTLPTR_ANY,E_POINTEE}},
166{ "atomic_or" , {1}, {E_VLTLPTR_ANY,E_POINTEE}},
167{ "atomic_sub" , {1}, {E_VLTLPTR_ANY,E_POINTEE}},
168{ "atomic_xchg" , {1}, {E_VLTLPTR_ANY,E_POINTEE}},
169{ "atomic_xor" , {1}, {E_VLTLPTR_ANY,E_POINTEE}},
170{ "bitselect" , {1}, {E_ANY,E_COPY,E_COPY}},
171{ "cbrt" , {1}, {E_ANY}},
172{ "ceil" , {1}, {E_ANY}},
173{ "clamp" , {1}, {E_ANY,E_COPY,E_COPY}},
174{ "clz" , {1}, {E_ANY}},
175{ "commit_read_pipe" , {1}, {E_ANY,EX_RESERVEDID}},
176{ "commit_write_pipe" , {1}, {E_ANY,EX_RESERVEDID}},
177{ "copysign" , {1}, {E_ANY,E_COPY}},
178{ "cos" , {1}, {E_ANY}},
179{ "cosh" , {1}, {E_ANY}},
180{ "cospi" , {1}, {E_ANY}},
181{ "cross" , {1}, {E_ANY,E_COPY}},
182{ "ctz" , {1}, {E_ANY}},
183{ "degrees" , {1}, {E_ANY}},
184{ "distance" , {1}, {E_ANY,E_COPY}},
185{ "divide" , {1}, {E_ANY,E_COPY}},
186{ "dot" , {1}, {E_ANY,E_COPY}},
187{ "erf" , {1}, {E_ANY}},
188{ "erfc" , {1}, {E_ANY}},
189{ "exp" , {1}, {E_ANY}},
190{ "exp10" , {1}, {E_ANY}},
191{ "exp2" , {1}, {E_ANY}},
192{ "expm1" , {1}, {E_ANY}},
193{ "fabs" , {1}, {E_ANY}},
194{ "fast_distance" , {1}, {E_ANY,E_COPY}},
195{ "fast_length" , {1}, {E_ANY}},
196{ "fast_normalize" , {1}, {E_ANY}},
197{ "fdim" , {1}, {E_ANY,E_COPY}},
198{ "floor" , {1}, {E_ANY}},
199{ "fma" , {1}, {E_ANY,E_COPY,E_COPY}},
200{ "fmax" , {1}, {E_ANY,E_COPY}},
201{ "fmin" , {1}, {E_ANY,E_COPY}},
202{ "fmod" , {1}, {E_ANY,E_COPY}},
203{ "fract" , {2}, {E_POINTEE,E_ANY}},
204{ "frexp" , {1,2}, {E_ANY,E_ANY}},
205{ "get_image_array_size" , {1}, {E_ANY}},
206{ "get_image_channel_data_type" , {1}, {E_ANY}},
207{ "get_image_channel_order" , {1}, {E_ANY}},
208{ "get_image_dim" , {1}, {E_ANY}},
209{ "get_image_height" , {1}, {E_ANY}},
210{ "get_image_width" , {1}, {E_ANY}},
211{ "get_pipe_max_packets" , {1}, {E_ANY}},
212{ "get_pipe_num_packets" , {1}, {E_ANY}},
213{ "hadd" , {1}, {E_ANY,E_COPY}},
214{ "hypot" , {1}, {E_ANY,E_COPY}},
215{ "ilogb" , {1}, {E_ANY}},
216{ "isequal" , {1}, {E_ANY,E_COPY}},
217{ "isfinite" , {1}, {E_ANY}},
218{ "isgreater" , {1}, {E_ANY,E_COPY}},
219{ "isgreaterequal" , {1}, {E_ANY,E_COPY}},
220{ "isinf" , {1}, {E_ANY}},
221{ "isless" , {1}, {E_ANY,E_COPY}},
222{ "islessequal" , {1}, {E_ANY,E_COPY}},
223{ "islessgreater" , {1}, {E_ANY,E_COPY}},
224{ "isnan" , {1}, {E_ANY}},
225{ "isnormal" , {1}, {E_ANY}},
226{ "isnotequal" , {1}, {E_ANY,E_COPY}},
227{ "isordered" , {1}, {E_ANY,E_COPY}},
228{ "isunordered" , {1}, {E_ANY,E_COPY}},
229{ "ldexp" , {1}, {E_ANY,E_SETBASE_I32}},
230{ "length" , {1}, {E_ANY}},
231{ "lgamma" , {1}, {E_ANY}},
232{ "lgamma_r" , {1,2}, {E_ANY,E_ANY}},
233{ "log" , {1}, {E_ANY}},
234{ "log10" , {1}, {E_ANY}},
235{ "log1p" , {1}, {E_ANY}},
236{ "log2" , {1}, {E_ANY}},
237{ "logb" , {1}, {E_ANY}},
238{ "mad" , {1}, {E_ANY,E_COPY,E_COPY}},
239{ "mad24" , {1}, {E_ANY,E_COPY,E_COPY}},
240{ "mad_hi" , {1}, {E_ANY,E_COPY,E_COPY}},
241{ "mad_sat" , {1}, {E_ANY,E_COPY,E_COPY}},
242{ "max" , {1}, {E_ANY,E_COPY}},
243{ "maxmag" , {1}, {E_ANY,E_COPY}},
244{ "min" , {1}, {E_ANY,E_COPY}},
245{ "minmag" , {1}, {E_ANY,E_COPY}},
246{ "mix" , {1}, {E_ANY,E_COPY,E_COPY}},
247{ "modf" , {2}, {E_POINTEE,E_ANY}},
248{ "mul24" , {1}, {E_ANY,E_COPY}},
249{ "mul_hi" , {1}, {E_ANY,E_COPY}},
250{ "nan" , {1}, {E_ANY}},
251{ "nextafter" , {1}, {E_ANY,E_COPY}},
252{ "normalize" , {1}, {E_ANY}},
253{ "popcount" , {1}, {E_ANY}},
254{ "pow" , {1}, {E_ANY,E_COPY}},
255{ "__pow_fast" , {1}, {E_ANY,E_COPY}},
256{ "pown" , {1}, {E_ANY,E_SETBASE_I32}},
257{ "__pown_fast" , {1}, {E_ANY,E_SETBASE_I32}},
258{ "powr" , {1}, {E_ANY,E_COPY}},
259{ "__powr_fast" , {1}, {E_ANY,E_COPY}},
260{ "prefetch" , {1}, {E_CONSTPTR_ANY,EX_SIZET}},
261{ "radians" , {1}, {E_ANY}},
262{ "recip" , {1}, {E_ANY}},
263{ "remainder" , {1}, {E_ANY,E_COPY}},
264{ "remquo" , {1,3}, {E_ANY,E_COPY,E_ANY}},
265{ "reserve_read_pipe" , {1}, {E_ANY,EX_UINT}},
266{ "reserve_write_pipe" , {1}, {E_ANY,EX_UINT}},
267{ "rhadd" , {1}, {E_ANY,E_COPY}},
268{ "rint" , {1}, {E_ANY}},
269{ "rootn" , {1}, {E_ANY,E_SETBASE_I32}},
270{ "__rootn_fast" , {1}, {E_ANY,E_SETBASE_I32}},
271{ "rotate" , {1}, {E_ANY,E_COPY}},
272{ "round" , {1}, {E_ANY}},
273{ "rsqrt" , {1}, {E_ANY}},
274{ "select" , {1,3}, {E_ANY,E_COPY,E_ANY}},
275{ "shuffle" , {1,2}, {E_ANY,E_ANY}},
276{ "shuffle2" , {1,3}, {E_ANY,E_COPY,E_ANY}},
277{ "sign" , {1}, {E_ANY}},
278{ "signbit" , {1}, {E_ANY}},
279{ "sin" , {1}, {E_ANY}},
280{ "sincos" , {2}, {E_POINTEE,E_ANY}},
281{ "sinh" , {1}, {E_ANY}},
282{ "sinpi" , {1}, {E_ANY}},
283{ "smoothstep" , {1}, {E_ANY,E_COPY,E_COPY}},
284{ "sqrt" , {1}, {E_ANY}},
285{ "step" , {1}, {E_ANY,E_COPY}},
286{ "sub_group_broadcast" , {1}, {E_ANY,EX_UINT}},
287{ "sub_group_commit_read_pipe" , {1}, {E_ANY,EX_RESERVEDID}},
288{ "sub_group_commit_write_pipe" , {1}, {E_ANY,EX_RESERVEDID}},
289{ "sub_group_reduce_add" , {1}, {E_ANY}},
290{ "sub_group_reduce_max" , {1}, {E_ANY}},
291{ "sub_group_reduce_min" , {1}, {E_ANY}},
292{ "sub_group_reserve_read_pipe" , {1}, {E_ANY,EX_UINT}},
293{ "sub_group_reserve_write_pipe" , {1}, {E_ANY,EX_UINT}},
294{ "sub_group_scan_exclusive_add" , {1}, {E_ANY}},
295{ "sub_group_scan_exclusive_max" , {1}, {E_ANY}},
296{ "sub_group_scan_exclusive_min" , {1}, {E_ANY}},
297{ "sub_group_scan_inclusive_add" , {1}, {E_ANY}},
298{ "sub_group_scan_inclusive_max" , {1}, {E_ANY}},
299{ "sub_group_scan_inclusive_min" , {1}, {E_ANY}},
300{ "sub_sat" , {1}, {E_ANY,E_COPY}},
301{ "tan" , {1}, {E_ANY}},
302{ "tanh" , {1}, {E_ANY}},
303{ "tanpi" , {1}, {E_ANY}},
304{ "tgamma" , {1}, {E_ANY}},
305{ "trunc" , {1}, {E_ANY}},
306{ "upsample" , {1}, {E_ANY,E_MAKEBASE_UNS}},
307{ "vec_step" , {1}, {E_ANY}},
308{ "vstore" , {3}, {E_POINTEE,EX_SIZET,E_ANY}},
309{ "vstore16" , {3}, {E_V16_OF_POINTEE,EX_SIZET,E_ANY}},
310{ "vstore2" , {3}, {E_V2_OF_POINTEE,EX_SIZET,E_ANY}},
311{ "vstore3" , {3}, {E_V3_OF_POINTEE,EX_SIZET,E_ANY}},
312{ "vstore4" , {3}, {E_V4_OF_POINTEE,EX_SIZET,E_ANY}},
313{ "vstore8" , {3}, {E_V8_OF_POINTEE,EX_SIZET,E_ANY}},
314{ "work_group_commit_read_pipe" , {1}, {E_ANY,EX_RESERVEDID}},
315{ "work_group_commit_write_pipe" , {1}, {E_ANY,EX_RESERVEDID}},
316{ "work_group_reduce_add" , {1}, {E_ANY}},
317{ "work_group_reduce_max" , {1}, {E_ANY}},
318{ "work_group_reduce_min" , {1}, {E_ANY}},
319{ "work_group_reserve_read_pipe" , {1}, {E_ANY,EX_UINT}},
320{ "work_group_reserve_write_pipe" , {1}, {E_ANY,EX_UINT}},
321{ "work_group_scan_exclusive_add" , {1}, {E_ANY}},
322{ "work_group_scan_exclusive_max" , {1}, {E_ANY}},
323{ "work_group_scan_exclusive_min" , {1}, {E_ANY}},
324{ "work_group_scan_inclusive_add" , {1}, {E_ANY}},
325{ "work_group_scan_inclusive_max" , {1}, {E_ANY}},
326{ "work_group_scan_inclusive_min" , {1}, {E_ANY}},
327{ "write_imagef" , {1}, {E_ANY,E_IMAGECOORDS,EX_FLOAT4}},
328{ "write_imagei" , {1}, {E_ANY,E_IMAGECOORDS,EX_INTV4}},
329{ "write_imageui" , {1}, {E_ANY,E_IMAGECOORDS,EX_UINTV4}},
330{ "ncos" , {1}, {E_ANY} },
331{ "nexp2" , {1}, {E_ANY} },
332{ "nfma" , {1}, {E_ANY, E_COPY, E_COPY} },
333{ "nlog2" , {1}, {E_ANY} },
334{ "nrcp" , {1}, {E_ANY} },
335{ "nrsqrt" , {1}, {E_ANY} },
336{ "nsin" , {1}, {E_ANY} },
337{ "nsqrt" , {1}, {E_ANY} },
338{ "ftz" , {1}, {E_ANY} },
339{ "fldexp" , {1}, {E_ANY, EX_UINT} },
340{ "class" , {1}, {E_ANY, EX_UINT} },
341{ "rcbrt" , {1}, {E_ANY} },
342};
343
344// Library functions with unmangled name.
345const UnmangledFuncInfo UnmangledFuncInfo::Table[] = {
346 {"__read_pipe_2", 4},
347 {"__read_pipe_4", 6},
348 {"__write_pipe_2", 4},
349 {"__write_pipe_4", 6},
350};
351
352const unsigned UnmangledFuncInfo::TableSize =
353 std::size(UnmangledFuncInfo::Table);
354
355static AMDGPULibFunc::Param getRetType(AMDGPULibFunc::EFuncId id,
356 const AMDGPULibFunc::Param (&Leads)[2]) {
357 AMDGPULibFunc::Param Res = Leads[0];
358 // TBD - This switch may require to be extended for other intrinsics
359 switch (id) {
360 case AMDGPULibFunc::EI_SINCOS:
361 Res.PtrKind = AMDGPULibFunc::BYVALUE;
362 break;
363 default:
364 break;
365 }
366 return Res;
367}
368
369class ParamIterator {
370 const AMDGPULibFunc::Param (&Leads)[2];
371 const ManglingRule& Rule;
372 int Index = 0;
373public:
374 ParamIterator(const AMDGPULibFunc::Param (&leads)[2],
375 const ManglingRule& rule)
376 : Leads(leads), Rule(rule) {}
377
378 AMDGPULibFunc::Param getNextParam();
379};
380
381AMDGPULibFunc::Param ParamIterator::getNextParam() {
382 AMDGPULibFunc::Param P;
383 if (Index >= int(sizeof Rule.Param/sizeof Rule.Param[0])) return P;
384
385 const char R = Rule.Param[Index];
386 switch (R) {
387 case E_NONE: break;
388 case EX_UINT:
389 P.ArgType = AMDGPULibFunc::U32; break;
390 case EX_INTV4:
391 P.ArgType = AMDGPULibFunc::I32; P.VectorSize = 4; break;
392 case EX_UINTV4:
393 P.ArgType = AMDGPULibFunc::U32; P.VectorSize = 4; break;
394 case EX_FLOAT4:
395 P.ArgType = AMDGPULibFunc::F32; P.VectorSize = 4; break;
396 case EX_SIZET:
397 P.ArgType = AMDGPULibFunc::U64; break;
398 case EX_EVENT:
399 P.ArgType = AMDGPULibFunc::EVENT; break;
400 case EX_SAMPLER:
401 P.ArgType = AMDGPULibFunc::SAMPLER; break;
402 case EX_RESERVEDID: break; // TBD
403 default:
404 if (Index == (Rule.Lead[1] - 1)) P = Leads[1];
405 else P = Leads[0];
406
407 switch (R) {
408 case E_ANY:
409 case E_COPY: break;
410
411 case E_POINTEE:
412 P.PtrKind = AMDGPULibFunc::BYVALUE; break;
413 case E_V2_OF_POINTEE:
414 P.VectorSize = 2; P.PtrKind = AMDGPULibFunc::BYVALUE; break;
415 case E_V3_OF_POINTEE:
416 P.VectorSize = 3; P.PtrKind = AMDGPULibFunc::BYVALUE; break;
417 case E_V4_OF_POINTEE:
418 P.VectorSize = 4; P.PtrKind = AMDGPULibFunc::BYVALUE; break;
419 case E_V8_OF_POINTEE:
420 P.VectorSize = 8; P.PtrKind = AMDGPULibFunc::BYVALUE; break;
421 case E_V16_OF_POINTEE:
422 P.VectorSize = 16; P.PtrKind = AMDGPULibFunc::BYVALUE; break;
423 case E_CONSTPTR_ANY:
424 P.PtrKind |= AMDGPULibFunc::CONST; break;
425 case E_VLTLPTR_ANY:
426 P.PtrKind |= AMDGPULibFunc::VOLATILE; break;
427 case E_SETBASE_I32:
428 P.ArgType = AMDGPULibFunc::I32; break;
429 case E_SETBASE_U32:
430 P.ArgType = AMDGPULibFunc::U32; break;
431
432 case E_MAKEBASE_UNS:
433 P.ArgType &= ~AMDGPULibFunc::BASE_TYPE_MASK;
434 P.ArgType |= AMDGPULibFunc::UINT;
435 break;
436
437 case E_IMAGECOORDS:
438 switch (P.ArgType) {
439 case AMDGPULibFunc::IMG1DA: P.VectorSize = 2; break;
440 case AMDGPULibFunc::IMG1DB: P.VectorSize = 1; break;
441 case AMDGPULibFunc::IMG2DA: P.VectorSize = 4; break;
442 case AMDGPULibFunc::IMG1D: P.VectorSize = 1; break;
443 case AMDGPULibFunc::IMG2D: P.VectorSize = 2; break;
444 case AMDGPULibFunc::IMG3D: P.VectorSize = 4; break;
445 }
446 P.PtrKind = AMDGPULibFunc::BYVALUE;
447 P.ArgType = AMDGPULibFunc::I32;
448 break;
449
450 case E_CONSTPTR_SWAPGL: {
451 unsigned AS = AMDGPULibFunc::getAddrSpaceFromEPtrKind(P.PtrKind);
452 switch (AS) {
455 }
456 P.PtrKind = AMDGPULibFunc::getEPtrKindFromAddrSpace(AS);
457 P.PtrKind |= AMDGPULibFunc::CONST;
458 break;
459 }
460
461 default:
462 llvm_unreachable("Unhandled param rule");
463 }
464 }
465 ++Index;
466 return P;
467}
468
469inline static void drop_front(StringRef& str, size_t n = 1) {
470 str = str.drop_front(n);
471}
472
473static bool eatTerm(StringRef& mangledName, const char c) {
474 if (mangledName.front() == c) {
475 drop_front(mangledName);
476 return true;
477 }
478 return false;
479}
480
481template <size_t N>
482static bool eatTerm(StringRef& mangledName, const char (&str)[N]) {
483 if (mangledName.starts_with(StringRef(str, N - 1))) {
484 drop_front(mangledName, N-1);
485 return true;
486 }
487 return false;
488}
489
490static int eatNumber(StringRef& s) {
491 size_t const savedSize = s.size();
492 int n = 0;
493 while (!s.empty() && isDigit(s.front())) {
494 n = n*10 + s.front() - '0';
495 drop_front(s);
496 }
497 return s.size() < savedSize ? n : -1;
498}
499
500static StringRef eatLengthPrefixedName(StringRef& mangledName) {
501 int const Len = eatNumber(mangledName);
502 if (Len <= 0 || static_cast<size_t>(Len) > mangledName.size())
503 return StringRef();
504 StringRef Res = mangledName.substr(0, Len);
505 drop_front(mangledName, Len);
506 return Res;
507}
508
509} // end anonymous namespace
510
512 FuncId = EI_NONE;
513 FKind = NOPFX;
514 Leads[0].reset();
515 Leads[1].reset();
516 Name.clear();
517}
518
523
525 EFuncId id, const AMDGPUMangledLibFunc &copyFrom) {
526 FuncId = id;
527 FKind = copyFrom.FKind;
528 Leads[0] = copyFrom.Leads[0];
529 Leads[1] = copyFrom.Leads[1];
530}
531
533 bool SignedInts) {
534 FuncId = id;
535 unsigned NumArgs = FT->getNumParams();
536 if (NumArgs >= 1)
537 Leads[0] = Param::getFromTy(FT->getParamType(0), SignedInts);
538 if (NumArgs >= 2)
539 Leads[1] = Param::getFromTy(FT->getParamType(1), SignedInts);
540}
541
542///////////////////////////////////////////////////////////////////////////////
543// Demangling
544
545static int parseVecSize(StringRef& mangledName) {
546 size_t const Len = eatNumber(mangledName);
547 switch (Len) {
548 case 2: case 3: case 4: case 8: case 16:
549 return Len;
550 default:
551 break;
552 }
553 return 1;
554}
555
557 std::pair<StringRef, StringRef> const P = mangledName.split('_');
560 .Case("native", AMDGPULibFunc::NATIVE)
561 .Case("half" , AMDGPULibFunc::HALF)
563
564 if (Pfx != AMDGPULibFunc::NOPFX)
565 mangledName = P.second;
566
567 return Pfx;
568}
569
570StringMap<int> ManglingRule::buildManglingRulesMap() {
571 StringMap<int> Map(std::size(manglingRules));
572 int Id = 0;
573 for (auto Rule : manglingRules)
574 Map.insert({Rule.Name, Id++});
575 return Map;
576}
577
578bool AMDGPUMangledLibFunc::parseUnmangledName(StringRef FullName) {
579 static const StringMap<int> manglingRulesMap =
580 ManglingRule::buildManglingRulesMap();
581 FuncId = static_cast<EFuncId>(manglingRulesMap.lookup(FullName));
582 return FuncId != EI_NONE;
583}
584
585///////////////////////////////////////////////////////////////////////////////
586// Itanium Demangling
587
588namespace {
589struct ItaniumParamParser {
590 AMDGPULibFunc::Param Prev;
591 bool parseItaniumParam(StringRef& param, AMDGPULibFunc::Param &res);
592};
593} // namespace
594
595bool ItaniumParamParser::parseItaniumParam(StringRef& param,
596 AMDGPULibFunc::Param &res) {
597 res.reset();
598 if (param.empty()) return false;
599
600 // parse pointer prefix
601 if (eatTerm(param, 'P')) {
602 if (eatTerm(param, 'K')) res.PtrKind |= AMDGPULibFunc::CONST;
603 if (eatTerm(param, 'V')) res.PtrKind |= AMDGPULibFunc::VOLATILE;
604 unsigned AS;
605 if (!eatTerm(param, "U3AS")) {
606 AS = 0;
607 } else {
608 AS = param.front() - '0';
609 drop_front(param, 1);
610 }
612 } else {
613 res.PtrKind = AMDGPULibFunc::BYVALUE;
614 }
615
616 // parse vector size
617 if (eatTerm(param,"Dv")) {
618 res.VectorSize = parseVecSize(param);
619 if (res.VectorSize==1 || !eatTerm(param, '_')) return false;
620 }
621
622 // parse type
623 char const TC = param.front();
624 if (isDigit(TC)) {
625 res.ArgType =
626 StringSwitch<AMDGPULibFunc::EType>(eatLengthPrefixedName(param))
627 .StartsWith("ocl_image1d_array", AMDGPULibFunc::IMG1DA)
628 .StartsWith("ocl_image1d_buffer", AMDGPULibFunc::IMG1DB)
629 .StartsWith("ocl_image2d_array", AMDGPULibFunc::IMG2DA)
630 .StartsWith("ocl_image1d", AMDGPULibFunc::IMG1D)
631 .StartsWith("ocl_image2d", AMDGPULibFunc::IMG2D)
632 .StartsWith("ocl_image3d", AMDGPULibFunc::IMG3D)
633 .Case("ocl_event", AMDGPULibFunc::DUMMY)
634 .Case("ocl_sampler", AMDGPULibFunc::DUMMY)
635 .Default(AMDGPULibFunc::DUMMY);
636 } else {
637 drop_front(param);
638 switch (TC) {
639 case 'h': res.ArgType = AMDGPULibFunc::U8; break;
640 case 't': res.ArgType = AMDGPULibFunc::U16; break;
641 case 'j': res.ArgType = AMDGPULibFunc::U32; break;
642 case 'm': res.ArgType = AMDGPULibFunc::U64; break;
643 case 'c': res.ArgType = AMDGPULibFunc::I8; break;
644 case 's': res.ArgType = AMDGPULibFunc::I16; break;
645 case 'i': res.ArgType = AMDGPULibFunc::I32; break;
646 case 'l': res.ArgType = AMDGPULibFunc::I64; break;
647 case 'f': res.ArgType = AMDGPULibFunc::F32; break;
648 case 'd': res.ArgType = AMDGPULibFunc::F64; break;
649 case 'D': if (!eatTerm(param, 'h')) return false;
650 res.ArgType = AMDGPULibFunc::F16; break;
651 case 'S':
652 if (!eatTerm(param, '_')) {
653 eatNumber(param);
654 if (!eatTerm(param, '_')) return false;
655 }
656 res.VectorSize = Prev.VectorSize;
657 res.ArgType = Prev.ArgType;
658 break;
659 default:;
660 }
661 }
662 if (res.ArgType == 0) return false;
663 Prev.VectorSize = res.VectorSize;
664 Prev.ArgType = res.ArgType;
665 return true;
666}
667
669 StringRef Name = eatLengthPrefixedName(mangledName);
671 if (!parseUnmangledName(Name))
672 return false;
673
674 const ManglingRule& Rule = manglingRules[FuncId];
675 ItaniumParamParser Parser;
676 for (int I=0; I < Rule.maxLeadIndex(); ++I) {
677 Param P;
678 if (!Parser.parseItaniumParam(mangledName, P))
679 return false;
680
681 if ((I + 1) == Rule.Lead[0]) Leads[0] = P;
682 if ((I + 1) == Rule.Lead[1]) Leads[1] = P;
683 }
684 return true;
685}
686
688 if (!UnmangledFuncInfo::lookup(Name, FuncId))
689 return false;
690 setName(Name);
691 return true;
692}
693
695 if (FuncName.empty()) {
696 F.Impl = std::unique_ptr<AMDGPULibFuncImpl>();
697 return false;
698 }
699
700 if (eatTerm(FuncName, "_Z"))
701 F.Impl = std::make_unique<AMDGPUMangledLibFunc>();
702 else
703 F.Impl = std::make_unique<AMDGPUUnmangledLibFunc>();
704 if (F.Impl->parseFuncName(FuncName))
705 return true;
706
707 F.Impl = std::unique_ptr<AMDGPULibFuncImpl>();
708 return false;
709}
710
711///////////////////////////////////////////////////////////////////////////////
712// Mangling
713
714template <typename Stream>
715void AMDGPUMangledLibFunc::writeName(Stream &OS) const {
716 const char *Pfx = "";
717 switch (FKind) {
718 case NATIVE: Pfx = "native_"; break;
719 case HALF: Pfx = "half_"; break;
720 default: break;
721 }
722 if (!Name.empty()) {
723 OS << Pfx << Name;
724 } else if (FuncId != EI_NONE) {
725 OS << Pfx;
726 const StringRef& S = manglingRules[FuncId].Name;
727 OS.write(S.data(), S.size());
728 }
729}
730
731std::string AMDGPUMangledLibFunc::mangle() const { return mangleNameItanium(); }
732
733///////////////////////////////////////////////////////////////////////////////
734// Itanium Mangling
735
737 switch (T) {
738 case AMDGPULibFunc::U8: return "h";
739 case AMDGPULibFunc::U16: return "t";
740 case AMDGPULibFunc::U32: return "j";
741 case AMDGPULibFunc::U64: return "m";
742 case AMDGPULibFunc::I8: return "c";
743 case AMDGPULibFunc::I16: return "s";
744 case AMDGPULibFunc::I32: return "i";
745 case AMDGPULibFunc::I64: return "l";
746 case AMDGPULibFunc::F16: return "Dh";
747 case AMDGPULibFunc::F32: return "f";
748 case AMDGPULibFunc::F64: return "d";
749 case AMDGPULibFunc::IMG1DA: return "16ocl_image1darray";
750 case AMDGPULibFunc::IMG1DB: return "17ocl_image1dbuffer";
751 case AMDGPULibFunc::IMG2DA: return "16ocl_image2darray";
752 case AMDGPULibFunc::IMG1D: return "11ocl_image1d";
753 case AMDGPULibFunc::IMG2D: return "11ocl_image2d";
754 case AMDGPULibFunc::IMG3D: return "11ocl_image3d";
755 case AMDGPULibFunc::SAMPLER: return "11ocl_sampler";
756 case AMDGPULibFunc::EVENT: return "9ocl_event";
757 default:
758 llvm_unreachable("Unhandled param type");
759 }
760 return nullptr;
761}
762
763namespace {
764// Itanium mangling ABI says:
765// "5.1.8. Compression
766// ... Each non-terminal in the grammar for which <substitution> appears on the
767// right-hand side is both a source of future substitutions and a candidate
768// for being substituted. There are two exceptions that appear to be
769// substitution candidates from the grammar, but are explicitly excluded:
770// 1. <builtin-type> other than vendor extended types ..."
771
772// For the purpose of functions the following productions make sense for the
773// substitution:
774// <type> ::= <builtin-type>
775// ::= <class-enum-type>
776// ::= <array-type>
777// ::=<CV-qualifiers> <type>
778// ::= P <type> # pointer-to
779// ::= <substitution>
780//
781// Note that while types like images, samplers and events are by the ABI encoded
782// using <class-enum-type> production rule they're not used for substitution
783// because clang consider them as builtin types.
784//
785// DvNN_ type is GCC extension for vectors and is a subject for the
786// substitution.
787
788class ItaniumMangler {
789 SmallVector<AMDGPULibFunc::Param, 10> Str; // list of accumulated substitutions
790 bool UseAddrSpace;
791
792 int findSubst(const AMDGPULibFunc::Param& P) const {
793 for(unsigned I = 0; I < Str.size(); ++I) {
794 const AMDGPULibFunc::Param& T = Str[I];
795 if (P.PtrKind == T.PtrKind &&
796 P.VectorSize == T.VectorSize &&
797 P.ArgType == T.ArgType) {
798 return I;
799 }
800 }
801 return -1;
802 }
803
804 template <typename Stream>
805 bool trySubst(Stream& os, const AMDGPULibFunc::Param& p) {
806 int const subst = findSubst(p);
807 if (subst < 0) return false;
808 // Substitutions are mangled as S(XX)?_ where XX is a hexadecimal number
809 // 0 1 2
810 // S_ S0_ S1_
811 if (subst == 0) os << "S_";
812 else os << 'S' << (subst-1) << '_';
813 return true;
814 }
815
816public:
817 ItaniumMangler(bool useAddrSpace)
818 : UseAddrSpace(useAddrSpace) {}
819
820 template <typename Stream>
821 void operator()(Stream& os, AMDGPULibFunc::Param p) {
822
823 // Itanium mangling ABI 5.1.8. Compression:
824 // Logically, the substitutable components of a mangled name are considered
825 // left-to-right, components before the composite structure of which they
826 // are a part. If a component has been encountered before, it is substituted
827 // as described below. This decision is independent of whether its components
828 // have been substituted, so an implementation may optimize by considering
829 // large structures for substitution before their components. If a component
830 // has not been encountered before, its mangling is identified, and it is
831 // added to a dictionary of substitution candidates. No entity is added to
832 // the dictionary twice.
833 AMDGPULibFunc::Param Ptr;
834
835 if (p.PtrKind) {
836 if (trySubst(os, p)) return;
837 os << 'P';
838 if (p.PtrKind & AMDGPULibFunc::CONST) os << 'K';
839 if (p.PtrKind & AMDGPULibFunc::VOLATILE) os << 'V';
840 unsigned AS = UseAddrSpace
842 : 0;
843 if (EnableOCLManglingMismatchWA || AS != 0)
844 os << "U3AS" << AS;
845 Ptr = p;
846 p.PtrKind = 0;
847 }
848
849 if (p.VectorSize > 1) {
850 if (trySubst(os, p)) goto exit;
851 Str.push_back(p);
852 os << "Dv" << static_cast<unsigned>(p.VectorSize) << '_';
853 }
854
855 os << getItaniumTypeName((AMDGPULibFunc::EType)p.ArgType);
856
857 exit:
858 if (Ptr.ArgType) Str.push_back(Ptr);
859 }
860};
861} // namespace
862
863std::string AMDGPUMangledLibFunc::mangleNameItanium() const {
864 SmallString<128> Buf;
865 raw_svector_ostream S(Buf);
866 SmallString<128> NameBuf;
867 raw_svector_ostream Name(NameBuf);
868 writeName(Name);
869 const StringRef& NameStr = Name.str();
870 S << "_Z" << static_cast<int>(NameStr.size()) << NameStr;
871
872 ItaniumMangler Mangler(true);
873 ParamIterator I(Leads, manglingRules[FuncId]);
874 Param P;
875 while ((P = I.getNextParam()).ArgType != 0)
876 Mangler(S, P);
877 return std::string(S.str());
878}
879
880///////////////////////////////////////////////////////////////////////////////
881// Misc
882
884 bool Signed) {
885 Param P;
887 P.VectorSize = VT->getNumElements();
888 Ty = VT->getElementType();
889 }
890
891 switch (Ty->getTypeID()) {
892 case Type::FloatTyID:
893 P.ArgType = AMDGPULibFunc::F32;
894 break;
895 case Type::DoubleTyID:
896 P.ArgType = AMDGPULibFunc::F64;
897 break;
898 case Type::HalfTyID:
899 P.ArgType = AMDGPULibFunc::F16;
900 break;
902 switch (cast<IntegerType>(Ty)->getBitWidth()) {
903 case 8:
905 break;
906 case 16:
908 break;
909 case 32:
911 break;
912 case 64:
914 break;
915 default:
916 llvm_unreachable("unhandled libcall argument type");
917 }
918
919 break;
920 default:
921 llvm_unreachable("unhandled libcall argument type");
922 }
923
924 return P;
925}
926
928 const AMDGPULibFunc::Param &P,
929 bool UseAddrSpace) {
930 Type *T = nullptr;
931 switch (P.ArgType) {
932 default:
933 return nullptr;
937 break;
941 break;
945 break;
949 break;
952 break;
955 break;
958 break;
959
969 break;
979 return nullptr;
980 }
981 if (P.VectorSize > 1)
982 T = FixedVectorType::get(T, P.VectorSize);
983 if (P.PtrKind != AMDGPULibFunc::BYVALUE)
985 C, UseAddrSpace ? ((P.PtrKind & AMDGPULibFunc::ADDR_SPACE) - 1) : 0);
986 return T;
987}
988
990 LLVMContext& C = M.getContext();
991 std::vector<Type*> Args;
992 ParamIterator I(Leads, manglingRules[FuncId]);
993 Param P;
994 while ((P = I.getNextParam()).ArgType != 0) {
995 Type *ParamTy = getIntrinsicParamType(C, P, true);
996 if (!ParamTy)
997 return nullptr;
998
999 Args.push_back(ParamTy);
1000 }
1001
1002 Type *RetTy = getIntrinsicParamType(C, getRetType(FuncId, Leads), true);
1003 if (!RetTy)
1004 return nullptr;
1005
1006 return FunctionType::get(RetTy, Args, false);
1007}
1008
1010 return manglingRules[FuncId].getNumArgs();
1011}
1012
1014 return UnmangledFuncInfo::getNumArgs(FuncId);
1015}
1016
1018 SmallString<128> Buf;
1019 raw_svector_ostream OS(Buf);
1020 writeName(OS);
1021 return std::string(OS.str());
1022}
1023
1025 const FunctionType *CallTy) const {
1026 const FunctionType *FuncTy = getFunctionType(M);
1027
1028 if (!FuncTy) {
1029 // Give up on mangled functions with unexpected types.
1031 return false;
1032
1033 // FIXME: UnmangledFuncInfo does not have any type information other than
1034 // the number of arguments.
1035 return getNumArgs() == CallTy->getNumParams();
1036 }
1037
1038 // Normally the types should exactly match.
1039 if (FuncTy == CallTy)
1040 return true;
1041
1042 const unsigned NumParams = FuncTy->getNumParams();
1043 if (NumParams != CallTy->getNumParams())
1044 return false;
1045
1046 for (unsigned I = 0; I != NumParams; ++I) {
1047 Type *FuncArgTy = FuncTy->getParamType(I);
1048 Type *CallArgTy = CallTy->getParamType(I);
1049 if (FuncArgTy == CallArgTy)
1050 continue;
1051
1052 // Some cases permit implicit splatting a scalar value to a vector argument.
1053 auto *FuncVecTy = dyn_cast<VectorType>(FuncArgTy);
1054 if (FuncVecTy && FuncVecTy->getElementType() == CallArgTy &&
1056 continue;
1057
1058 return false;
1059 }
1060
1061 return true;
1062}
1063
1065 std::string FuncName = fInfo.mangle();
1067 M->getValueSymbolTable().lookup(FuncName));
1068 if (!F || F->isDeclaration())
1069 return nullptr;
1070
1071 if (F->hasFnAttribute(Attribute::NoBuiltin))
1072 return nullptr;
1073
1074 if (!fInfo.isCompatibleSignature(*M, F->getFunctionType()))
1075 return nullptr;
1076
1077 switch (fInfo.getId()) {
1082 // TODO: Remove this. This is not a real module flag used anywhere. This is
1083 // a bringup hack so this transform is testable prior to the library
1084 // functions existing.
1085 if (!M->getModuleFlag("amdgpu-libcall-have-fast-pow"))
1086 return nullptr;
1087 break;
1088 default:
1089 break;
1090 }
1091
1092 return F;
1093}
1094
1096 const AMDGPULibFunc &fInfo) {
1097 std::string const FuncName = fInfo.mangle();
1099 M->getValueSymbolTable().lookup(FuncName));
1100
1101 if (F) {
1102 if (F->hasFnAttribute(Attribute::NoBuiltin))
1103 return nullptr;
1104 if (!F->isDeclaration() &&
1105 fInfo.isCompatibleSignature(*M, F->getFunctionType()))
1106 return F;
1107 }
1108
1109 FunctionType *FuncTy = fInfo.getFunctionType(*M);
1110 assert(FuncTy);
1111
1112 bool hasPtr = false;
1114 PI = FuncTy->param_begin(),
1115 PE = FuncTy->param_end();
1116 PI != PE; ++PI) {
1117 const Type* argTy = static_cast<const Type*>(*PI);
1118 if (argTy->isPointerTy()) {
1119 hasPtr = true;
1120 break;
1121 }
1122 }
1123
1125 if (hasPtr) {
1126 // Do not set extra attributes for functions with pointer arguments.
1127 C = M->getOrInsertFunction(FuncName, FuncTy);
1128 } else {
1129 AttributeList Attr;
1130 LLVMContext &Ctx = M->getContext();
1131 Attr = Attr.addFnAttribute(
1133 Attr = Attr.addFnAttribute(Ctx, Attribute::NoUnwind);
1134 C = M->getOrInsertFunction(FuncName, FuncTy, Attr);
1135 }
1136
1137 return C;
1138}
1139
1140StringMap<unsigned> UnmangledFuncInfo::buildNameMap() {
1142 for (unsigned I = 0; I != TableSize; ++I)
1143 Map[Table[I].Name] = I;
1144 return Map;
1145}
1146
1147bool UnmangledFuncInfo::lookup(StringRef Name, ID &Id) {
1148 static const StringMap<unsigned> Map = buildNameMap();
1149 auto Loc = Map.find(Name);
1150 if (Loc != Map.end()) {
1151 Id = toFuncId(Loc->second);
1152 return true;
1153 }
1154 Id = AMDGPULibFunc::EI_NONE;
1155 return false;
1156}
1157
1159 if (auto *MF = dyn_cast<AMDGPUMangledLibFunc>(F.Impl.get()))
1160 Impl = std::make_unique<AMDGPUMangledLibFunc>(*MF);
1161 else if (auto *UMF = dyn_cast<AMDGPUUnmangledLibFunc>(F.Impl.get()))
1162 Impl = std::make_unique<AMDGPUUnmangledLibFunc>(*UMF);
1163 else
1164 Impl = std::unique_ptr<AMDGPULibFuncImpl>();
1165}
1166
1168 if (this == &F)
1169 return *this;
1170
1171 this->~AMDGPULibFunc();
1172 new (this) AMDGPULibFunc(F);
1173 return *this;
1174}
1175
1177 assert(AMDGPULibFuncBase::isMangled(Id) && CopyFrom.isMangled() &&
1178 "not supported");
1179 Impl = std::make_unique<AMDGPUMangledLibFunc>(
1180 Id, *cast<AMDGPUMangledLibFunc>(CopyFrom.Impl.get()));
1181}
1182
1184 Impl = std::make_unique<AMDGPUMangledLibFunc>(Id, FT, SignedInts);
1185}
1186
1188 Impl = std::make_unique<AMDGPUUnmangledLibFunc>(Name, FT);
1189}
1190
1191void AMDGPULibFunc::initMangled() {
1192 Impl = std::make_unique<AMDGPUMangledLibFunc>();
1193}
1194
1196 if (!Impl)
1197 initMangled();
1198 return cast<AMDGPUMangledLibFunc>(Impl.get())->Leads;
1199}
1200
1202 return cast<const AMDGPUMangledLibFunc>(Impl.get())->Leads;
1203}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
static cl::opt< bool > EnableOCLManglingMismatchWA("amdgpu-enable-ocl-mangling-mismatch-workaround", cl::init(true), cl::ReallyHidden, cl::desc("Enable the workaround for OCL name mangling mismatch."))
static AMDGPULibFunc::ENamePrefix parseNamePrefix(StringRef &mangledName)
static const char * getItaniumTypeName(AMDGPULibFunc::EType T)
static int parseVecSize(StringRef &mangledName)
static Type * getIntrinsicParamType(LLVMContext &C, const AMDGPULibFunc::Param &P, bool UseAddrSpace)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
Module.h This file contains the declarations for the Module class.
static bool lookup(const GsymReader &GR, GsymDataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
#define P(N)
This file contains some functions that are useful when dealing with strings.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static unsigned getEPtrKindFromAddrSpace(unsigned AS)
static unsigned getAddrSpaceFromEPtrKind(unsigned Kind)
static bool isMangled(EFuncId Id)
void setName(StringRef N)
static Function * getFunction(llvm::Module *M, const AMDGPULibFunc &fInfo)
static bool parse(StringRef MangledName, AMDGPULibFunc &Ptr)
static FunctionCallee getOrInsertFunction(llvm::Module *M, const AMDGPULibFunc &fInfo)
FunctionType * getFunctionType(const Module &M) const
bool isCompatibleSignature(const Module &M, const FunctionType *FuncTy) const
EFuncId getId() const
bool allowsImplicitVectorSplat(int ArgIdx) const
Return true if it's legal to splat a scalar value passed in parameter ArgIdx to a vector argument.
bool isMangled() const
std::string mangle() const
AMDGPULibFunc & operator=(const AMDGPULibFunc &F)
Param * getLeads()
Get leading parameters for mangled lib functions.
unsigned getNumArgs() const
unsigned getNumArgs() const override
bool parseFuncName(StringRef &mangledName) override
std::string getName() const override
Get unmangled name for mangled library function and name for unmangled library function.
FunctionType * getFunctionType(const Module &M) const override
std::string mangle() const override
unsigned getNumArgs() const override
bool parseFuncName(StringRef &Name) override
static LLVM_ABI Attribute getWithMemoryEffects(LLVMContext &Context, MemoryEffects ME)
Class to represent fixed width SIMD vectors.
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:843
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Class to represent function types.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Type::subtype_iterator param_iterator
Type * getParamType(unsigned i) const
Parameter type accessors.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
static MemoryEffectsBase readOnly()
Definition ModRef.h:133
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
Definition Type.cpp:887
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition StringMap.h:250
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:736
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:597
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:258
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition StringRef.h:635
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
char front() const
Get the first character in the string.
Definition StringRef.h:147
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:300
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:299
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:277
@ HalfTyID
16-bit floating point type
Definition Type.h:57
@ FloatTyID
32-bit floating point type
Definition Type.h:59
@ IntegerTyID
Arbitrary bit width integers.
Definition Type.h:71
@ DoubleTyID
64-bit floating point type
Definition Type.h:60
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:297
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
Definition Type.cpp:298
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
Definition Type.cpp:277
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
Definition Type.cpp:276
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Definition Type.cpp:274
A raw_ostream that writes to an SmallVector or SmallString.
StringRef str() const
Return a StringRef for the vector contents.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ LOCAL_ADDRESS
Address space for local memory.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
#define N
static Param getFromTy(Type *Ty, bool Signed)