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