LLVM 24.0.0git
BuildLibCalls.cpp
Go to the documentation of this file.
1//===- BuildLibCalls.cpp - Utility builder for libcalls -------------------===//
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 implements some functions that will create standard C libcalls.
10//
11//===----------------------------------------------------------------------===//
12
15#include "llvm/ADT/Statistic.h"
18#include "llvm/IR/Argument.h"
19#include "llvm/IR/CallingConv.h"
20#include "llvm/IR/Constants.h"
21#include "llvm/IR/DataLayout.h"
23#include "llvm/IR/Function.h"
24#include "llvm/IR/IRBuilder.h"
25#include "llvm/IR/Module.h"
26#include "llvm/IR/Type.h"
28#include <optional>
29
30using namespace llvm;
31
32#define DEBUG_TYPE "build-libcalls"
33
34//- Infer Attributes ---------------------------------------------------------//
35
36STATISTIC(NumReadNone, "Number of functions inferred as readnone");
37STATISTIC(NumReadOnly, "Number of functions inferred as readonly");
38STATISTIC(NumWriteOnly, "Number of functions inferred as writeonly");
39STATISTIC(NumArgMemOnly, "Number of functions inferred as argmemonly");
40STATISTIC(NumWriteErrnoMemOnly,
41 "Number of functions inferred as memory(errnomem: write)");
42STATISTIC(NumInaccessibleMemOrArgMemOnly,
43 "Number of functions inferred as inaccessiblemem_or_argmemonly");
44STATISTIC(NumInaccessibleMemOrErrnoMemOnly,
45 "Number of functions inferred as memory(inaccessiblemem: readwrite, "
46 "errnomem: write)");
47STATISTIC(NumInaccessibleMemOrArgMemOrErrnoMemOnly,
48 "Number of functions inferred as memory(argmem: readwrite, "
49 "inaccessiblemem: readwrite, errnomem: write)");
51 NumWriteArgumentMemOrErrnoMemOnly,
52 "Number of functions inferred as memory(argmem: write, errnomem: write)");
53STATISTIC(NumNoUnwind, "Number of functions inferred as nounwind");
54STATISTIC(NumNoCallback, "Number of functions inferred as nocallback");
55STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture");
56STATISTIC(NumWriteOnlyArg, "Number of arguments inferred as writeonly");
57STATISTIC(NumReadOnlyArg, "Number of arguments inferred as readonly");
58STATISTIC(NumNoAlias, "Number of function returns inferred as noalias");
59STATISTIC(NumNoUndef, "Number of function returns inferred as noundef returns");
60STATISTIC(NumReturnedArg, "Number of arguments inferred as returned");
61STATISTIC(NumWillReturn, "Number of functions inferred as willreturn");
62STATISTIC(NumCold, "Number of functions inferred as cold");
63STATISTIC(NumNoReturn, "Number of functions inferred as no return");
64STATISTIC(NumNoSync, "Number of functions inferred as nosync");
65
67 if (F.doesNotAccessMemory())
68 return false;
69 F.setDoesNotAccessMemory();
70 ++NumReadNone;
71 return true;
72}
73
74static bool setIsCold(Function &F) {
75 if (F.hasFnAttribute(Attribute::Cold))
76 return false;
77 F.addFnAttr(Attribute::Cold);
78 ++NumCold;
79 return true;
80}
81
82static bool setNoReturn(Function &F) {
83 if (F.hasFnAttribute(Attribute::NoReturn))
84 return false;
85 F.addFnAttr(Attribute::NoReturn);
86 ++NumNoReturn;
87 return true;
88}
89
91 MemoryEffects OrigME = F.getMemoryEffects();
92 MemoryEffects NewME = OrigME & ME;
93 if (OrigME == NewME)
94 return false;
95 F.setMemoryEffects(NewME);
96 return true;
97}
98
101 return false;
102 ++NumReadOnly;
103 return true;
104}
105
108 return false;
109 ++NumWriteOnly;
110 return true;
111}
112
115 return false;
116 ++NumArgMemOnly;
117 return true;
118}
119
122 return false;
123 ++NumInaccessibleMemOrArgMemOnly;
124 return true;
125}
126
130 return false;
131 ++NumInaccessibleMemOrErrnoMemOnly;
132 return true;
133}
134
138 return false;
139 ++NumInaccessibleMemOrArgMemOrErrnoMemOnly;
140 return true;
141}
142
145 return false;
146 ++NumWriteErrnoMemOnly;
147 return true;
148}
149
153 return false;
154 ++NumWriteArgumentMemOrErrnoMemOnly;
155 return true;
156}
157
159 if (F.doesNotThrow())
160 return false;
161 F.setDoesNotThrow();
162 ++NumNoUnwind;
163 return true;
164}
165
167 if (F.hasFnAttribute(Attribute::NoCallback))
168 return false;
169 F.addFnAttr(Attribute::NoCallback);
170 ++NumNoCallback;
171 return true;
172}
173
175 if (F.hasRetAttribute(Attribute::NoAlias))
176 return false;
177 F.addRetAttr(Attribute::NoAlias);
178 ++NumNoAlias;
179 return true;
180}
181
182static bool setDoesNotCapture(Function &F, unsigned ArgNo) {
183 if (F.hasParamAttribute(ArgNo, Attribute::Captures))
184 return false;
185 F.addParamAttr(ArgNo, Attribute::getWithCaptureInfo(F.getContext(),
187 ++NumNoCapture;
188 return true;
189}
190
191static bool setDoesNotAlias(Function &F, unsigned ArgNo) {
192 if (F.hasParamAttribute(ArgNo, Attribute::NoAlias))
193 return false;
194 F.addParamAttr(ArgNo, Attribute::NoAlias);
195 ++NumNoAlias;
196 return true;
197}
198
199static bool setDoesNotSync(Function &F) {
200 if (F.hasFnAttribute(Attribute::NoSync))
201 return false;
202 F.addFnAttr(Attribute::NoSync);
203 ++NumNoSync;
204 return true;
205}
206
207static bool setOnlyReadsMemory(Function &F, unsigned ArgNo) {
208 if (F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
209 return false;
210 F.addParamAttr(ArgNo, Attribute::ReadOnly);
211 ++NumReadOnlyArg;
212 return true;
213}
214
215static bool setOnlyWritesMemory(Function &F, unsigned ArgNo) {
216 if (F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
217 return false;
218 F.addParamAttr(ArgNo, Attribute::WriteOnly);
219 ++NumWriteOnlyArg;
220 return true;
221}
222
223static bool setRetNoUndef(Function &F) {
224 if (!F.getReturnType()->isVoidTy() &&
225 !F.hasRetAttribute(Attribute::NoUndef)) {
226 F.addRetAttr(Attribute::NoUndef);
227 ++NumNoUndef;
228 return true;
229 }
230 return false;
231}
232
233static bool setArgsNoUndef(Function &F) {
234 bool Changed = false;
235 for (unsigned ArgNo = 0; ArgNo < F.arg_size(); ++ArgNo) {
236 if (!F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
237 F.addParamAttr(ArgNo, Attribute::NoUndef);
238 ++NumNoUndef;
239 Changed = true;
240 }
241 }
242 return Changed;
243}
244
245static bool setArgNoUndef(Function &F, unsigned ArgNo) {
246 if (F.hasParamAttribute(ArgNo, Attribute::NoUndef))
247 return false;
248 F.addParamAttr(ArgNo, Attribute::NoUndef);
249 ++NumNoUndef;
250 return true;
251}
252
254 bool UndefAdded = false;
255 UndefAdded |= setRetNoUndef(F);
256 UndefAdded |= setArgsNoUndef(F);
257 return UndefAdded;
258}
259
260static bool setReturnedArg(Function &F, unsigned ArgNo) {
261 if (F.hasParamAttribute(ArgNo, Attribute::Returned))
262 return false;
263 F.addParamAttr(ArgNo, Attribute::Returned);
264 ++NumReturnedArg;
265 return true;
266}
267
268static bool setNonLazyBind(Function &F) {
269 if (F.hasFnAttribute(Attribute::NonLazyBind))
270 return false;
271 F.addFnAttr(Attribute::NonLazyBind);
272 return true;
273}
274
276 if (F.hasFnAttribute(Attribute::NoFree))
277 return false;
278 F.addFnAttr(Attribute::NoFree);
279 return true;
280}
281
282static bool setWillReturn(Function &F) {
283 if (F.hasFnAttribute(Attribute::WillReturn))
284 return false;
285 F.addFnAttr(Attribute::WillReturn);
286 ++NumWillReturn;
287 return true;
288}
289
290static bool setAlignedAllocParam(Function &F, unsigned ArgNo) {
291 if (F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
292 return false;
293 F.addParamAttr(ArgNo, Attribute::AllocAlign);
294 return true;
295}
296
297static bool setAllocatedPointerParam(Function &F, unsigned ArgNo) {
298 if (F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
299 return false;
300 F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
301 return true;
302}
303
304static bool setAllocSize(Function &F, unsigned ElemSizeArg,
305 std::optional<unsigned> NumElemsArg) {
306 if (F.hasFnAttribute(Attribute::AllocSize))
307 return false;
308 F.addFnAttr(Attribute::getWithAllocSizeArgs(F.getContext(), ElemSizeArg,
309 NumElemsArg));
310 return true;
311}
312
313static bool setAllocFamily(Function &F, StringRef Family) {
314 if (F.hasFnAttribute("alloc-family"))
315 return false;
316 F.addFnAttr("alloc-family", Family);
317 return true;
318}
319
321 if (F.hasFnAttribute(Attribute::AllocKind))
322 return false;
323 F.addFnAttr(
324 Attribute::get(F.getContext(), Attribute::AllocKind, uint64_t(K)));
325 return true;
326}
327
329 const TargetLibraryInfo &TLI) {
330 Function *F = M->getFunction(Name);
331 if (!F)
332 return false;
333 return inferNonMandatoryLibFuncAttrs(*F, TLI);
334}
335
337 const TargetLibraryInfo &TLI) {
338 LibFunc TheLibFunc = TLI.getLibFunc(F);
339 if (!TLI.has(TheLibFunc))
340 return false;
341
342 bool Changed = false;
343
344 if (F.getParent() != nullptr && F.getParent()->getRtLibUseGOT())
346
347 switch (TheLibFunc) {
348 case LibFunc_nan:
349 case LibFunc_nanf:
350 case LibFunc_nanl:
351 case LibFunc_strlen:
352 case LibFunc_strnlen:
353 case LibFunc_wcslen:
361 break;
362 case LibFunc_strchr:
363 case LibFunc_strrchr:
370 break;
371 case LibFunc_strtol:
372 case LibFunc_strtod:
373 case LibFunc_strtof:
374 case LibFunc_strtoul:
375 case LibFunc_strtoll:
376 case LibFunc_strtold:
377 case LibFunc_strtoull:
383 break;
384 case LibFunc_strcat:
385 case LibFunc_strncat:
390 Changed |= setReturnedArg(F, 0);
396 break;
397 case LibFunc_strcpy:
398 case LibFunc_strncpy:
399 Changed |= setReturnedArg(F, 0);
400 [[fallthrough]];
401 case LibFunc_stpcpy:
402 case LibFunc_stpncpy:
413 break;
414 case LibFunc_strxfrm:
421 break;
422 case LibFunc_strcmp: // 0,1
423 case LibFunc_strspn: // 0,1
424 case LibFunc_strncmp: // 0,1
425 case LibFunc_strcspn: // 0,1
434 break;
435 case LibFunc_strcoll:
436 case LibFunc_strcasecmp: // 0,1
437 case LibFunc_strncasecmp: //
438 // Those functions may depend on the locale, which may be accessed through
439 // global memory.
446 break;
447 case LibFunc_strstr:
448 case LibFunc_strpbrk:
456 break;
457 case LibFunc_strtok:
458 case LibFunc_strtok_r:
464 break;
465 case LibFunc_scanf:
470 break;
471 case LibFunc_setbuf:
472 case LibFunc_setvbuf:
476 break;
477 case LibFunc_strndup:
478 Changed |= setArgNoUndef(F, 1);
479 [[fallthrough]];
480 case LibFunc_strdup:
481 Changed |= setAllocFamily(F, "malloc");
488 break;
489 case LibFunc_stat:
490 case LibFunc_statvfs:
496 break;
497 case LibFunc_sscanf:
504 break;
505 case LibFunc_sprintf:
513 break;
514 case LibFunc_snprintf:
522 break;
523 case LibFunc_setitimer:
530 break;
531 case LibFunc_system:
532 // May throw; "system" is a valid pthread cancellation point.
536 break;
537 case LibFunc_posix_memalign:
544 break;
545 case LibFunc_aligned_alloc:
547 Changed |= setAllocSize(F, 1, std::nullopt);
549 [[fallthrough]];
550 case LibFunc_valloc:
551 case LibFunc_malloc:
552 case LibFunc_vec_malloc:
553 Changed |= setAllocSize(F, 0, std::nullopt);
554 [[fallthrough]];
555 case LibFunc_pvalloc:
556 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_malloc ? "vec_malloc"
557 : "malloc");
564 break;
565 case LibFunc_memcmp:
574 break;
575 case LibFunc_memchr:
576 case LibFunc_memrchr:
583 break;
584 case LibFunc_modf:
585 case LibFunc_modff:
586 case LibFunc_modfl:
594 break;
595 case LibFunc_memcpy:
601 Changed |= setReturnedArg(F, 0);
607 break;
608 case LibFunc_memmove:
613 Changed |= setReturnedArg(F, 0);
618 break;
619 case LibFunc_mempcpy:
620 case LibFunc_memccpy:
622 [[fallthrough]];
623 case LibFunc_memcpy_chk:
633 break;
634 case LibFunc_memalign:
635 Changed |= setAllocFamily(F, "malloc");
638 Changed |= setAllocSize(F, 1, std::nullopt);
645 break;
646 case LibFunc_mkdir:
651 break;
652 case LibFunc_mktime:
657 break;
658 case LibFunc_realloc:
659 case LibFunc_reallocf:
660 case LibFunc_vec_realloc:
662 F, TheLibFunc == LibFunc_vec_realloc ? "vec_malloc" : "malloc");
665 Changed |= setAllocSize(F, 1, std::nullopt);
672 Changed |= setArgNoUndef(F, 1);
673 break;
674 case LibFunc_reallocarray:
675 Changed |= setAllocFamily(F, "malloc");
678 Changed |= setAllocSize(F, 1, 2);
685 Changed |= setArgNoUndef(F, 1);
686 Changed |= setArgNoUndef(F, 2);
687 break;
688 case LibFunc_read:
689 // May throw; "read" is a valid pthread cancellation point.
692 break;
693 case LibFunc_rewind:
697 break;
698 case LibFunc_rmdir:
699 case LibFunc_remove:
700 case LibFunc_realpath:
705 break;
706 case LibFunc_rename:
713 break;
714 case LibFunc_readlink:
720 break;
721 case LibFunc_write:
722 // May throw; "write" is a valid pthread cancellation point.
726 break;
727 case LibFunc_bcopy:
737 break;
738 case LibFunc_bcmp:
747 break;
748 case LibFunc_bzero:
756 break;
757 case LibFunc_calloc:
758 case LibFunc_vec_calloc:
759 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_calloc ? "vec_malloc"
760 : "malloc");
762 Changed |= setAllocSize(F, 0, 1);
768 break;
769 case LibFunc_chmod:
770 case LibFunc_chown:
775 break;
776 case LibFunc_ctermid:
777 case LibFunc_clearerr:
778 case LibFunc_closedir:
782 break;
783 case LibFunc_atoi:
784 case LibFunc_atol:
785 case LibFunc_atof:
786 case LibFunc_atoll:
793 break;
794 case LibFunc_access:
799 break;
800 case LibFunc_fopen:
808 break;
809 case LibFunc_fdopen:
815 break;
816 case LibFunc_feof:
820 break;
821 case LibFunc_free:
822 case LibFunc_vec_free:
823 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_free ? "vec_malloc"
824 : "malloc");
832 break;
833 case LibFunc_fseek:
834 case LibFunc_ftell:
835 case LibFunc_fgetc:
836 case LibFunc_fgetc_unlocked:
837 case LibFunc_fseeko:
838 case LibFunc_ftello:
839 case LibFunc_fileno:
840 case LibFunc_fflush:
841 case LibFunc_fclose:
842 case LibFunc_fsetpos:
843 case LibFunc_flockfile:
844 case LibFunc_funlockfile:
845 case LibFunc_ftrylockfile:
849 break;
850 case LibFunc_ferror:
855 break;
856 case LibFunc_fputc:
857 case LibFunc_fputc_unlocked:
858 case LibFunc_fstat:
862 break;
863 case LibFunc_frexp:
864 case LibFunc_frexpf:
865 case LibFunc_frexpl:
873 break;
874 case LibFunc_fstatvfs:
878 break;
879 case LibFunc_fgets:
880 case LibFunc_fgets_unlocked:
885 break;
886 case LibFunc_fread:
887 case LibFunc_fread_unlocked:
893 break;
894 case LibFunc_fwrite:
895 case LibFunc_fwrite_unlocked:
901 break;
902 case LibFunc_fputs:
903 case LibFunc_fputs_unlocked:
909 break;
910 case LibFunc_fscanf:
911 case LibFunc_fprintf:
917 break;
918 case LibFunc_fgetpos:
923 break;
924 case LibFunc_getc:
928 break;
929 case LibFunc_getlogin_r:
933 break;
934 case LibFunc_getc_unlocked:
938 break;
939 case LibFunc_getenv:
944 break;
945 case LibFunc_gets:
946 case LibFunc_getchar:
947 case LibFunc_getchar_unlocked:
950 break;
951 case LibFunc_getitimer:
955 break;
956 case LibFunc_getpwnam:
961 break;
962 case LibFunc_ungetc:
966 break;
967 case LibFunc_uname:
971 break;
972 case LibFunc_unlink:
977 break;
978 case LibFunc_unsetenv:
983 break;
984 case LibFunc_utime:
985 case LibFunc_utimes:
992 break;
993 case LibFunc_putc:
994 case LibFunc_putc_unlocked:
998 break;
999 case LibFunc_puts:
1000 case LibFunc_printf:
1001 case LibFunc_perror:
1006 break;
1007 case LibFunc_pread:
1008 // May throw; "pread" is a valid pthread cancellation point.
1011 break;
1012 case LibFunc_pwrite:
1013 // May throw; "pwrite" is a valid pthread cancellation point.
1017 break;
1018 case LibFunc_putchar:
1019 case LibFunc_putchar_unlocked:
1022 break;
1023 case LibFunc_popen:
1031 break;
1032 case LibFunc_pclose:
1036 break;
1037 case LibFunc_vscanf:
1042 break;
1043 case LibFunc_vsscanf:
1050 break;
1051 case LibFunc_vfscanf:
1057 break;
1058 case LibFunc_vprintf:
1063 break;
1064 case LibFunc_vfprintf:
1065 case LibFunc_vsprintf:
1071 break;
1072 case LibFunc_vsnprintf:
1078 break;
1079 case LibFunc_open:
1080 // May throw; "open" is a valid pthread cancellation point.
1084 break;
1085 case LibFunc_opendir:
1091 break;
1092 case LibFunc_tmpfile:
1096 break;
1097 case LibFunc_times:
1101 break;
1102 case LibFunc_htonl:
1103 case LibFunc_htons:
1104 case LibFunc_ntohl:
1105 case LibFunc_ntohs:
1109 break;
1110 case LibFunc_lstat:
1116 break;
1117 case LibFunc_lchown:
1122 break;
1123 case LibFunc_qsort:
1124 // May throw/callback; places call through function pointer.
1125 // Cannot give undef pointer/size
1128 break;
1129 case LibFunc_dunder_strndup:
1130 Changed |= setArgNoUndef(F, 1);
1131 [[fallthrough]];
1132 case LibFunc_dunder_strdup:
1138 break;
1139 case LibFunc_dunder_strtok_r:
1144 break;
1145 case LibFunc_under_IO_getc:
1149 break;
1150 case LibFunc_under_IO_putc:
1154 break;
1155 case LibFunc_dunder_isoc99_scanf:
1160 break;
1161 case LibFunc_stat64:
1162 case LibFunc_lstat64:
1163 case LibFunc_statvfs64:
1169 break;
1170 case LibFunc_dunder_isoc99_sscanf:
1177 break;
1178 case LibFunc_fopen64:
1186 break;
1187 case LibFunc_fseeko64:
1188 case LibFunc_ftello64:
1192 break;
1193 case LibFunc_tmpfile64:
1197 break;
1198 case LibFunc_fstat64:
1199 case LibFunc_fstatvfs64:
1203 break;
1204 case LibFunc_open64:
1205 // May throw; "open" is a valid pthread cancellation point.
1209 break;
1210 case LibFunc_gettimeofday:
1211 // Currently some platforms have the restrict keyword on the arguments to
1212 // gettimeofday. To be conservative, do not add noalias to gettimeofday's
1213 // arguments.
1218 break;
1219 case LibFunc_memset_pattern4:
1220 case LibFunc_memset_pattern8:
1221 case LibFunc_memset_pattern16:
1225 [[fallthrough]];
1226 case LibFunc_memset:
1228 [[fallthrough]];
1229 case LibFunc_memset_chk:
1235 break;
1236 case LibFunc_abort:
1237 Changed |= setIsCold(F);
1238 Changed |= setNoReturn(F);
1240 break;
1241 case LibFunc_terminate:
1242 // May callback; terminate_handler may be called
1243 Changed |= setIsCold(F);
1244 Changed |= setNoReturn(F);
1245 break;
1246 case LibFunc_cxa_throw:
1247 Changed |= setIsCold(F);
1248 Changed |= setNoReturn(F);
1249 // Don't add `nofree` on `__cxa_throw`
1250 return Changed;
1251 // int __nvvm_reflect(const char *)
1252 case LibFunc_nvvm_reflect:
1256 break;
1257 case LibFunc_acos:
1258 case LibFunc_acosf:
1259 case LibFunc_acosh:
1260 case LibFunc_acoshf:
1261 case LibFunc_acoshl:
1262 case LibFunc_acosl:
1263 case LibFunc_asin:
1264 case LibFunc_asinf:
1265 case LibFunc_asinh:
1266 case LibFunc_asinhf:
1267 case LibFunc_asinhl:
1268 case LibFunc_asinl:
1269 case LibFunc_atan:
1270 case LibFunc_atan2:
1271 case LibFunc_atan2f:
1272 case LibFunc_atan2l:
1273 case LibFunc_atanf:
1274 case LibFunc_atanh:
1275 case LibFunc_atanhf:
1276 case LibFunc_atanhl:
1277 case LibFunc_atanl:
1278 case LibFunc_cos:
1279 case LibFunc_cosh:
1280 case LibFunc_coshf:
1281 case LibFunc_coshl:
1282 case LibFunc_cosf:
1283 case LibFunc_cosl:
1284 case LibFunc_cospi:
1285 case LibFunc_cospif:
1286 case LibFunc_erf:
1287 case LibFunc_erff:
1288 case LibFunc_erfl:
1289 case LibFunc_tgamma:
1290 case LibFunc_tgammaf:
1291 case LibFunc_tgammal:
1292 case LibFunc_exp:
1293 case LibFunc_expf:
1294 case LibFunc_expl:
1295 case LibFunc_exp2:
1296 case LibFunc_exp2f:
1297 case LibFunc_exp2l:
1298 case LibFunc_expm1:
1299 case LibFunc_expm1f:
1300 case LibFunc_expm1l:
1301 case LibFunc_fdim:
1302 case LibFunc_fdiml:
1303 case LibFunc_fdimf:
1304 case LibFunc_fmod:
1305 case LibFunc_fmodf:
1306 case LibFunc_fmodl:
1307 case LibFunc_hypot:
1308 case LibFunc_hypotf:
1309 case LibFunc_hypotl:
1310 case LibFunc_ldexp:
1311 case LibFunc_ldexpf:
1312 case LibFunc_ldexpl:
1313 case LibFunc_log:
1314 case LibFunc_log10:
1315 case LibFunc_log10f:
1316 case LibFunc_log10l:
1317 case LibFunc_log1p:
1318 case LibFunc_log1pf:
1319 case LibFunc_log1pl:
1320 case LibFunc_log2:
1321 case LibFunc_log2f:
1322 case LibFunc_log2l:
1323 case LibFunc_logb:
1324 case LibFunc_logbf:
1325 case LibFunc_logbl:
1326 case LibFunc_ilogb:
1327 case LibFunc_ilogbf:
1328 case LibFunc_ilogbl:
1329 case LibFunc_logf:
1330 case LibFunc_logl:
1331 case LibFunc_nextafter:
1332 case LibFunc_nextafterf:
1333 case LibFunc_nextafterl:
1334 case LibFunc_nexttoward:
1335 case LibFunc_nexttowardf:
1336 case LibFunc_nexttowardl:
1337 case LibFunc_pow:
1338 case LibFunc_powf:
1339 case LibFunc_powl:
1340 case LibFunc_remainder:
1341 case LibFunc_remainderf:
1342 case LibFunc_remainderl:
1343 case LibFunc_rint:
1344 case LibFunc_rintf:
1345 case LibFunc_rintl:
1346 case LibFunc_scalbln:
1347 case LibFunc_scalblnf:
1348 case LibFunc_scalblnl:
1349 case LibFunc_scalbn:
1350 case LibFunc_scalbnf:
1351 case LibFunc_scalbnl:
1352 case LibFunc_sin:
1353 case LibFunc_sincospif_stret:
1354 case LibFunc_sinf:
1355 case LibFunc_sinh:
1356 case LibFunc_sinhf:
1357 case LibFunc_sinhl:
1358 case LibFunc_sinl:
1359 case LibFunc_sinpi:
1360 case LibFunc_sinpif:
1361 case LibFunc_sqrt:
1362 case LibFunc_sqrtf:
1363 case LibFunc_sqrtl:
1364 case LibFunc_tan:
1365 case LibFunc_tanf:
1366 case LibFunc_tanh:
1367 case LibFunc_tanhf:
1368 case LibFunc_tanhl:
1369 case LibFunc_tanl:
1376 break;
1377 case LibFunc_abs:
1378 case LibFunc_cbrt:
1379 case LibFunc_cbrtf:
1380 case LibFunc_cbrtl:
1381 case LibFunc_copysign:
1382 case LibFunc_copysignf:
1383 case LibFunc_copysignl:
1384 case LibFunc_ceil:
1385 case LibFunc_ceilf:
1386 case LibFunc_ceill:
1387 case LibFunc_fabs:
1388 case LibFunc_fabsf:
1389 case LibFunc_fabsl:
1390 case LibFunc_ffs:
1391 case LibFunc_ffsl:
1392 case LibFunc_ffsll:
1393 case LibFunc_floor:
1394 case LibFunc_floorf:
1395 case LibFunc_floorl:
1396 case LibFunc_fls:
1397 case LibFunc_flsl:
1398 case LibFunc_flsll:
1399 case LibFunc_fmax:
1400 case LibFunc_fmaxf:
1401 case LibFunc_fmaxl:
1402 case LibFunc_fmin:
1403 case LibFunc_fminf:
1404 case LibFunc_fminl:
1405 case LibFunc_fmaximum_num:
1406 case LibFunc_fmaximum_numf:
1407 case LibFunc_fmaximum_numl:
1408 case LibFunc_fminimum_num:
1409 case LibFunc_fminimum_numf:
1410 case LibFunc_fminimum_numl:
1411 case LibFunc_labs:
1412 case LibFunc_llabs:
1413 case LibFunc_nearbyint:
1414 case LibFunc_nearbyintf:
1415 case LibFunc_nearbyintl:
1416 case LibFunc_round:
1417 case LibFunc_roundf:
1418 case LibFunc_roundl:
1419 case LibFunc_roundeven:
1420 case LibFunc_roundevenf:
1421 case LibFunc_roundevenl:
1422 case LibFunc_toascii:
1423 case LibFunc_trunc:
1424 case LibFunc_truncf:
1425 case LibFunc_truncl:
1427 [[fallthrough]];
1428 case LibFunc_isascii:
1429 case LibFunc_isdigit:
1434 break;
1435 case LibFunc_sincos:
1436 case LibFunc_sincosf:
1437 case LibFunc_sincosl:
1440 [[fallthrough]];
1441 case LibFunc_remquo:
1442 case LibFunc_remquof:
1443 case LibFunc_remquol:
1452 break;
1453 default:
1454 // FIXME: It'd be really nice to cover all the library functions we're
1455 // aware of here.
1456 break;
1457 }
1458 // We have to do this step after AllocKind has been inferred on functions so
1459 // we can reliably identify free-like and realloc-like functions.
1460 if (!isLibFreeFunction(&F, TheLibFunc) && !isReallocLikeFn(&F))
1462 return Changed;
1463}
1464
1465static void setArgExtAttr(Function &F, unsigned ArgNo,
1466 const TargetLibraryInfo &TLI, bool Signed = true) {
1467 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Param(Signed);
1468 if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr))
1469 F.addParamAttr(ArgNo, ExtAttr);
1470}
1471
1473 const TargetLibraryInfo &TLI, bool Signed = true) {
1474 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Return(Signed);
1475 if (ExtAttr != Attribute::None && !F.hasRetAttribute(ExtAttr))
1476 F.addRetAttr(ExtAttr);
1477}
1478
1479// Modeled after X86TargetLowering::markLibCallAttributes.
1481 if (!F->arg_size() || F->isVarArg())
1482 return;
1483
1484 const CallingConv::ID CC = F->getCallingConv();
1485 if (CC != CallingConv::C && CC != CallingConv::X86_StdCall)
1486 return;
1487
1488 const Module *M = F->getParent();
1489 unsigned N = M->getNumberRegisterParameters();
1490 if (!N)
1491 return;
1492
1493 const DataLayout &DL = M->getDataLayout();
1494
1495 for (Argument &A : F->args()) {
1496 Type *T = A.getType();
1497 if (!T->isIntOrPtrTy())
1498 continue;
1499
1500 const TypeSize &TS = DL.getTypeAllocSize(T);
1501 if (TS > 8)
1502 continue;
1503
1504 assert(TS <= 4 && "Need to account for parameters larger than word size");
1505 const unsigned NumRegs = TS > 4 ? 2 : 1;
1506 if (N < NumRegs)
1507 return;
1508
1509 N -= NumRegs;
1510 F->addParamAttr(A.getArgNo(), Attribute::InReg);
1511 }
1512}
1513
1515 LibFunc TheLibFunc, FunctionType *T,
1517 assert(TLI.has(TheLibFunc) &&
1518 "Creating call to non-existing library function.");
1519 StringRef Name = TLI.getName(TheLibFunc);
1520 FunctionCallee C = M->getOrInsertFunction(Name, T, AttributeList);
1521
1522 // Make sure any mandatory argument attributes are added.
1523
1524 // Any outgoing i32 argument should be handled with setArgExtAttr() which
1525 // will add an extension attribute if the target ABI requires it. Adding
1526 // argument extensions is typically done by the front end but when an
1527 // optimizer is building a library call on its own it has to take care of
1528 // this. Each such generated function must be handled here with sign or
1529 // zero extensions as needed. F is retreived with cast<> because we demand
1530 // of the caller to have called isLibFuncEmittable() first.
1531 Function *F = cast<Function>(C.getCallee());
1532 assert(F->getFunctionType() == T && "Function type does not match.");
1533 switch (TheLibFunc) {
1534 case LibFunc_fputc:
1535 case LibFunc_putchar:
1536 setArgExtAttr(*F, 0, TLI);
1537 break;
1538 case LibFunc_ldexp:
1539 case LibFunc_ldexpf:
1540 case LibFunc_ldexpl:
1541 case LibFunc_memchr:
1542 case LibFunc_memrchr:
1543 case LibFunc_strchr:
1544 setArgExtAttr(*F, 1, TLI);
1545 break;
1546 case LibFunc_memccpy:
1547 setArgExtAttr(*F, 2, TLI);
1548 break;
1549
1550 // These are functions that are known to not need any argument extension
1551 // on any target: A size_t argument (which may be an i32 on some targets)
1552 // should not trigger the assert below.
1553 case LibFunc_bcmp:
1554 setRetExtAttr(*F, TLI);
1555 break;
1556 case LibFunc_calloc:
1557 case LibFunc_fwrite:
1558 case LibFunc_malloc:
1559 case LibFunc_memcmp:
1560 case LibFunc_memcpy_chk:
1561 case LibFunc_mempcpy:
1562 case LibFunc_memset_pattern16:
1563 case LibFunc_snprintf:
1564 case LibFunc_stpncpy:
1565 case LibFunc_strlcat:
1566 case LibFunc_strlcpy:
1567 case LibFunc_strncat:
1568 case LibFunc_strncmp:
1569 case LibFunc_strncpy:
1570 case LibFunc_vsnprintf:
1571 break;
1572
1573 default:
1574#ifndef NDEBUG
1575 for (unsigned i = 0; i < T->getNumParams(); i++)
1576 assert(!isa<IntegerType>(T->getParamType(i)) &&
1577 "Unhandled integer argument.");
1578#endif
1579 break;
1580 }
1581
1583
1584 return C;
1585}
1586
1588 LibFunc TheLibFunc, FunctionType *T) {
1589 return getOrInsertLibFunc(M, TLI, TheLibFunc, T, AttributeList());
1590}
1591
1593 LibFunc TheLibFunc) {
1594 StringRef FuncName = TLI->getName(TheLibFunc);
1595 if (!TLI->has(TheLibFunc))
1596 return false;
1597
1598 // Check if the Module already has a GlobalValue with the same name, in
1599 // which case it must be a Function with the expected type.
1600 if (GlobalValue *GV = M->getNamedValue(FuncName)) {
1601 if (auto *F = dyn_cast<Function>(GV))
1602 return TLI->isValidProtoForLibFunc(*F->getFunctionType(), TheLibFunc, *M);
1603 return false;
1604 }
1605
1606 return true;
1607}
1608
1610 StringRef Name) {
1611 return isLibFuncEmittable(M, TLI, TLI->getLibFunc(Name));
1612}
1613
1614bool llvm::hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty,
1615 LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
1616 switch (Ty->getTypeID()) {
1617 case Type::HalfTyID:
1618 return false;
1619 case Type::FloatTyID:
1620 return isLibFuncEmittable(M, TLI, FloatFn);
1621 case Type::DoubleTyID:
1622 return isLibFuncEmittable(M, TLI, DoubleFn);
1623 default:
1624 return isLibFuncEmittable(M, TLI, LongDoubleFn);
1625 }
1626}
1627
1629 Type *Ty, LibFunc DoubleFn, LibFunc FloatFn,
1630 LibFunc LongDoubleFn, LibFunc &TheLibFunc) {
1631 assert(hasFloatFn(M, TLI, Ty, DoubleFn, FloatFn, LongDoubleFn) &&
1632 "Cannot get name for unavailable function!");
1633
1634 switch (Ty->getTypeID()) {
1635 case Type::HalfTyID:
1636 llvm_unreachable("No name for HalfTy!");
1637 case Type::FloatTyID:
1638 TheLibFunc = FloatFn;
1639 return TLI->getName(FloatFn);
1640 case Type::DoubleTyID:
1641 TheLibFunc = DoubleFn;
1642 return TLI->getName(DoubleFn);
1643 default:
1644 TheLibFunc = LongDoubleFn;
1645 return TLI->getName(LongDoubleFn);
1646 }
1647}
1648
1649//- Emit LibCalls ------------------------------------------------------------//
1650
1652 return B.getIntNTy(TLI->getIntSize());
1653}
1654
1656 const Module *M = B.GetInsertBlock()->getModule();
1657 return B.getIntNTy(TLI->getSizeTSize(*M));
1658}
1659
1660static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
1661 ArrayRef<Type *> ParamTypes,
1663 const TargetLibraryInfo *TLI,
1664 bool IsVaArgs = false) {
1665 Module *M = B.GetInsertBlock()->getModule();
1666 if (!isLibFuncEmittable(M, TLI, TheLibFunc))
1667 return nullptr;
1668
1669 StringRef FuncName = TLI->getName(TheLibFunc);
1670 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1671 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, FuncType);
1672 inferNonMandatoryLibFuncAttrs(M, FuncName, *TLI);
1673 CallInst *CI = B.CreateCall(Callee, Operands, FuncName);
1674 if (const Function *F =
1675 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1676 CI->setCallingConv(F->getCallingConv());
1677 return CI;
1678}
1679
1681 const TargetLibraryInfo *TLI) {
1682 Type *CharPtrTy = B.getPtrTy();
1683 Type *SizeTTy = getSizeTTy(B, TLI);
1684 return emitLibCall(LibFunc_strlen, SizeTTy, CharPtrTy, Ptr, B, TLI);
1685}
1686
1688 const TargetLibraryInfo *TLI) {
1689 assert(Ptr && Ptr->getType()->isPointerTy() &&
1690 "Argument to wcslen intrinsic must be a pointer.");
1691 Type *PtrTy = B.getPtrTy();
1692 Type *SizeTTy = getSizeTTy(B, TLI);
1693 return emitLibCall(LibFunc_wcslen, SizeTTy, PtrTy, Ptr, B, TLI);
1694}
1695
1697 const TargetLibraryInfo *TLI) {
1698 Type *CharPtrTy = B.getPtrTy();
1699 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy, Ptr, B, TLI);
1700}
1701
1703 const TargetLibraryInfo *TLI) {
1704 Type *CharPtrTy = B.getPtrTy();
1705 Type *IntTy = getIntTy(B, TLI);
1706 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1707 {Ptr, ConstantInt::get(IntTy, (unsigned char)C)}, B, TLI);
1708}
1709
1711 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1712 Type *CharPtrTy = B.getPtrTy();
1713 Type *IntTy = getIntTy(B, TLI);
1714 Type *SizeTTy = getSizeTTy(B, TLI);
1715 return emitLibCall(
1716 LibFunc_strncmp, IntTy,
1717 {CharPtrTy, CharPtrTy, SizeTTy},
1718 {Ptr1, Ptr2, Len}, B, TLI);
1719}
1720
1722 const TargetLibraryInfo *TLI) {
1723 Type *CharPtrTy = Dst->getType();
1724 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1725 {Dst, Src}, B, TLI);
1726}
1727
1729 const TargetLibraryInfo *TLI) {
1730 Type *CharPtrTy = B.getPtrTy();
1731 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1732 {Dst, Src}, B, TLI);
1733}
1734
1736 const TargetLibraryInfo *TLI) {
1737 Type *CharPtrTy = B.getPtrTy();
1738 Type *SizeTTy = getSizeTTy(B, TLI);
1739 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1740 {Dst, Src, Len}, B, TLI);
1741}
1742
1744 const TargetLibraryInfo *TLI) {
1745 Type *CharPtrTy = B.getPtrTy();
1746 Type *SizeTTy = getSizeTTy(B, TLI);
1747 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1748 {Dst, Src, Len}, B, TLI);
1749}
1750
1751Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
1752 IRBuilderBase &B, const DataLayout &DL,
1753 const TargetLibraryInfo *TLI) {
1754 Module *M = B.GetInsertBlock()->getModule();
1755 if (!isLibFuncEmittable(M, TLI, LibFunc_memcpy_chk))
1756 return nullptr;
1757
1758 AttributeList AS;
1759 AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
1760 Attribute::NoUnwind);
1761 Type *VoidPtrTy = B.getPtrTy();
1762 Type *SizeTTy = getSizeTTy(B, TLI);
1763 FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
1764 AttributeList::get(M->getContext(), AS), VoidPtrTy,
1765 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1766 CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1767 if (const Function *F =
1769 CI->setCallingConv(F->getCallingConv());
1770 return CI;
1771}
1772
1774 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1775 Type *VoidPtrTy = B.getPtrTy();
1776 Type *SizeTTy = getSizeTTy(B, TLI);
1777 return emitLibCall(LibFunc_mempcpy, VoidPtrTy,
1778 {VoidPtrTy, VoidPtrTy, SizeTTy},
1779 {Dst, Src, Len}, B, TLI);
1780}
1781
1783 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1784 Type *VoidPtrTy = B.getPtrTy();
1785 Type *IntTy = getIntTy(B, TLI);
1786 Type *SizeTTy = getSizeTTy(B, TLI);
1787 return emitLibCall(LibFunc_memchr, VoidPtrTy,
1788 {VoidPtrTy, IntTy, SizeTTy},
1789 {Ptr, Val, Len}, B, TLI);
1790}
1791
1793 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1794 Type *VoidPtrTy = B.getPtrTy();
1795 Type *IntTy = getIntTy(B, TLI);
1796 Type *SizeTTy = getSizeTTy(B, TLI);
1797 return emitLibCall(LibFunc_memrchr, VoidPtrTy,
1798 {VoidPtrTy, IntTy, SizeTTy},
1799 {Ptr, Val, Len}, B, TLI);
1800}
1801
1803 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1804 Type *VoidPtrTy = B.getPtrTy();
1805 Type *IntTy = getIntTy(B, TLI);
1806 Type *SizeTTy = getSizeTTy(B, TLI);
1807 return emitLibCall(LibFunc_memcmp, IntTy,
1808 {VoidPtrTy, VoidPtrTy, SizeTTy},
1809 {Ptr1, Ptr2, Len}, B, TLI);
1810}
1811
1813 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1814 Type *VoidPtrTy = B.getPtrTy();
1815 Type *IntTy = getIntTy(B, TLI);
1816 Type *SizeTTy = getSizeTTy(B, TLI);
1817 return emitLibCall(LibFunc_bcmp, IntTy,
1818 {VoidPtrTy, VoidPtrTy, SizeTTy},
1819 {Ptr1, Ptr2, Len}, B, TLI);
1820}
1821
1822Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
1823 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1824 Type *VoidPtrTy = B.getPtrTy();
1825 Type *IntTy = getIntTy(B, TLI);
1826 Type *SizeTTy = getSizeTTy(B, TLI);
1827 return emitLibCall(LibFunc_memccpy, VoidPtrTy,
1828 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1829 {Ptr1, Ptr2, Val, Len}, B, TLI);
1830}
1831
1833 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1834 const TargetLibraryInfo *TLI) {
1835 Type *CharPtrTy = B.getPtrTy();
1836 Type *IntTy = getIntTy(B, TLI);
1837 Type *SizeTTy = getSizeTTy(B, TLI);
1838 SmallVector<Value *, 8> Args{Dest, Size, Fmt};
1839 llvm::append_range(Args, VariadicArgs);
1840 return emitLibCall(LibFunc_snprintf, IntTy,
1841 {CharPtrTy, SizeTTy, CharPtrTy},
1842 Args, B, TLI, /*IsVaArgs=*/true);
1843}
1844
1846 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1847 const TargetLibraryInfo *TLI) {
1848 Type *CharPtrTy = B.getPtrTy();
1849 Type *IntTy = getIntTy(B, TLI);
1850 SmallVector<Value *, 8> Args{Dest, Fmt};
1851 llvm::append_range(Args, VariadicArgs);
1852 return emitLibCall(LibFunc_sprintf, IntTy,
1853 {CharPtrTy, CharPtrTy}, Args, B, TLI,
1854 /*IsVaArgs=*/true);
1855}
1856
1858 const TargetLibraryInfo *TLI) {
1859 Type *CharPtrTy = B.getPtrTy();
1860 return emitLibCall(LibFunc_strcat, CharPtrTy,
1861 {CharPtrTy, CharPtrTy},
1862 {Dest, Src}, B, TLI);
1863}
1864
1866 const TargetLibraryInfo *TLI) {
1867 Type *CharPtrTy = B.getPtrTy();
1868 Type *SizeTTy = getSizeTTy(B, TLI);
1869 return emitLibCall(LibFunc_strlcpy, SizeTTy,
1870 {CharPtrTy, CharPtrTy, SizeTTy},
1871 {Dest, Src, Size}, B, TLI);
1872}
1873
1875 const TargetLibraryInfo *TLI) {
1876 Type *CharPtrTy = B.getPtrTy();
1877 Type *SizeTTy = getSizeTTy(B, TLI);
1878 return emitLibCall(LibFunc_strlcat, SizeTTy,
1879 {CharPtrTy, CharPtrTy, SizeTTy},
1880 {Dest, Src, Size}, B, TLI);
1881}
1882
1884 const TargetLibraryInfo *TLI) {
1885 Type *CharPtrTy = B.getPtrTy();
1886 Type *SizeTTy = getSizeTTy(B, TLI);
1887 return emitLibCall(LibFunc_strncat, CharPtrTy,
1888 {CharPtrTy, CharPtrTy, SizeTTy},
1889 {Dest, Src, Size}, B, TLI);
1890}
1891
1893 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1894 Type *CharPtrTy = B.getPtrTy();
1895 Type *IntTy = getIntTy(B, TLI);
1896 Type *SizeTTy = getSizeTTy(B, TLI);
1897 return emitLibCall(
1898 LibFunc_vsnprintf, IntTy,
1899 {CharPtrTy, SizeTTy, CharPtrTy, VAList->getType()},
1900 {Dest, Size, Fmt, VAList}, B, TLI);
1901}
1902
1904 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1905 Type *CharPtrTy = B.getPtrTy();
1906 Type *IntTy = getIntTy(B, TLI);
1907 return emitLibCall(LibFunc_vsprintf, IntTy,
1908 {CharPtrTy, CharPtrTy, VAList->getType()},
1909 {Dest, Fmt, VAList}, B, TLI);
1910}
1911
1912/// Append a suffix to the function name according to the type of 'Op'.
1914 SmallString<20> &NameBuffer) {
1915 if (!Op->getType()->isDoubleTy()) {
1916 NameBuffer += Name;
1917
1918 if (Op->getType()->isFloatTy())
1919 NameBuffer += 'f';
1920 else
1921 NameBuffer += 'l';
1922
1923 Name = NameBuffer;
1924 }
1925}
1926
1927static Value *emitUnaryFloatFnCallHelper(Value *Op, LibFunc TheLibFunc,
1928 StringRef Name, IRBuilderBase &B,
1929 const AttributeList &Attrs,
1930 const TargetLibraryInfo *TLI) {
1931 assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
1932
1933 Module *M = B.GetInsertBlock()->getModule();
1934 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op->getType(),
1935 Op->getType());
1936 CallInst *CI = B.CreateCall(Callee, Op, Name);
1937
1938 // The incoming attribute set may have come from a speculatable intrinsic, but
1939 // is being replaced with a library call which is not allowed to be
1940 // speculatable.
1941 CI->setAttributes(
1942 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1943 if (const Function *F =
1944 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1945 CI->setCallingConv(F->getCallingConv());
1946
1947 return CI;
1948}
1949
1951 StringRef Name, IRBuilderBase &B,
1952 const AttributeList &Attrs) {
1953 SmallString<20> NameBuffer;
1954 appendTypeSuffix(Op, Name, NameBuffer);
1955
1956 return emitUnaryFloatFnCallHelper(Op, TLI->getLibFunc(Name), Name, B, Attrs,
1957 TLI);
1958}
1959
1961 LibFunc DoubleFn, LibFunc FloatFn,
1962 LibFunc LongDoubleFn, IRBuilderBase &B,
1963 const AttributeList &Attrs) {
1964 // Get the name of the function according to TLI.
1965 Module *M = B.GetInsertBlock()->getModule();
1966 LibFunc TheLibFunc;
1967 StringRef Name = getFloatFn(M, TLI, Op->getType(), DoubleFn, FloatFn,
1968 LongDoubleFn, TheLibFunc);
1969
1970 return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1971}
1972
1974 LibFunc TheLibFunc,
1975 StringRef Name, IRBuilderBase &B,
1976 const AttributeList &Attrs,
1977 const TargetLibraryInfo *TLI) {
1978 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1979
1980 Module *M = B.GetInsertBlock()->getModule();
1981 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op1->getType(),
1982 Op1->getType(), Op2->getType());
1983 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
1984 CallInst *CI = B.CreateCall(Callee, { Op1, Op2 }, Name);
1985
1986 // The incoming attribute set may have come from a speculatable intrinsic, but
1987 // is being replaced with a library call which is not allowed to be
1988 // speculatable.
1989 CI->setAttributes(
1990 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1991 if (const Function *F =
1992 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1993 CI->setCallingConv(F->getCallingConv());
1994
1995 return CI;
1996}
1997
1999 const TargetLibraryInfo *TLI,
2000 StringRef Name, IRBuilderBase &B,
2001 const AttributeList &Attrs) {
2002 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
2003
2004 SmallString<20> NameBuffer;
2005 appendTypeSuffix(Op1, Name, NameBuffer);
2006
2007 return emitBinaryFloatFnCallHelper(Op1, Op2, TLI->getLibFunc(Name), Name, B,
2008 Attrs, TLI);
2009}
2010
2012 const TargetLibraryInfo *TLI,
2013 LibFunc DoubleFn, LibFunc FloatFn,
2014 LibFunc LongDoubleFn, IRBuilderBase &B,
2015 const AttributeList &Attrs) {
2016 // Get the name of the function according to TLI.
2017 Module *M = B.GetInsertBlock()->getModule();
2018 LibFunc TheLibFunc;
2019 StringRef Name = getFloatFn(M, TLI, Op1->getType(), DoubleFn, FloatFn,
2020 LongDoubleFn, TheLibFunc);
2021
2022 return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
2023}
2024
2025// Emit a call to putchar(int) with Char as the argument. Char must have
2026// the same precision as int, which need not be 32 bits.
2028 const TargetLibraryInfo *TLI) {
2029 Type *IntTy = getIntTy(B, TLI);
2030 return emitLibCall(LibFunc_putchar, IntTy, IntTy, Char, B, TLI);
2031}
2032
2034 const TargetLibraryInfo *TLI) {
2035 Type *IntTy = getIntTy(B, TLI);
2036 return emitLibCall(LibFunc_puts, IntTy, B.getPtrTy(), Str, B, TLI);
2037}
2038
2040 const TargetLibraryInfo *TLI) {
2041 Type *IntTy = getIntTy(B, TLI);
2042 return emitLibCall(LibFunc_fputc, IntTy, {IntTy, File->getType()},
2043 {Char, File}, B, TLI);
2044}
2045
2047 const TargetLibraryInfo *TLI) {
2048 Type *IntTy = getIntTy(B, TLI);
2049 return emitLibCall(LibFunc_fputs, IntTy, {B.getPtrTy(), File->getType()},
2050 {Str, File}, B, TLI);
2051}
2052
2054 const DataLayout &DL, const TargetLibraryInfo *TLI) {
2055 Type *SizeTTy = getSizeTTy(B, TLI);
2056 return emitLibCall(LibFunc_fwrite, SizeTTy,
2057 {B.getPtrTy(), SizeTTy, SizeTTy, File->getType()},
2058 {Ptr, Size, ConstantInt::get(SizeTTy, 1), File}, B, TLI);
2059}
2060
2062 const TargetLibraryInfo *TLI) {
2063 Type *SizeTTy = getSizeTTy(B, TLI);
2064 return emitLibCall(LibFunc_malloc, B.getPtrTy(), SizeTTy, Num, B, TLI);
2065}
2066
2068 const TargetLibraryInfo &TLI, unsigned AddrSpace) {
2069 Type *SizeTTy = getSizeTTy(B, &TLI);
2070 return emitLibCall(LibFunc_calloc, B.getPtrTy(AddrSpace), {SizeTTy, SizeTTy},
2071 {Num, Size}, B, &TLI);
2072}
2073
2075 const TargetLibraryInfo *TLI,
2076 LibFunc SizeFeedbackNewFunc,
2077 Value *HotCold) {
2078 Module *M = B.GetInsertBlock()->getModule();
2079 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2080 return nullptr;
2081
2082 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2083
2084 // __sized_ptr_t struct return type { void*, size_t }
2085 StructType *SizedPtrT =
2086 StructType::get(M->getContext(), {B.getPtrTy(), Num->getType()});
2087 FunctionCallee Func =
2088 M->getOrInsertFunction(Name, SizedPtrT, Num->getType(), B.getInt8Ty());
2089 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2090 CallInst *CI = B.CreateCall(Func, {Num, HotCold}, "sized_ptr");
2091
2092 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2093 CI->setCallingConv(F->getCallingConv());
2094
2095 return CI;
2096}
2097
2100 const TargetLibraryInfo *TLI,
2101 LibFunc SizeFeedbackNewFunc,
2102 Value *HotCold) {
2103 Module *M = B.GetInsertBlock()->getModule();
2104 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2105 return nullptr;
2106
2107 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2108
2109 // __sized_ptr_t struct return type { void*, size_t }
2110 StructType *SizedPtrT =
2111 StructType::get(M->getContext(), {B.getPtrTy(), Num->getType()});
2112 FunctionCallee Func = M->getOrInsertFunction(Name, SizedPtrT, Num->getType(),
2113 Align->getType(), B.getInt8Ty());
2114 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2115 CallInst *CI = B.CreateCall(Func, {Num, Align, HotCold}, "sized_ptr");
2116
2117 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2118 CI->setCallingConv(F->getCallingConv());
2119
2120 return CI;
2121}
2122
2124 const TargetLibraryInfo *TLI, LibFunc NewFunc,
2125 Value *HotCold) {
2126 Module *M = B.GetInsertBlock()->getModule();
2127 if (!isLibFuncEmittable(M, TLI, NewFunc))
2128 return nullptr;
2129
2130 StringRef Name = TLI->getName(NewFunc);
2131 FunctionCallee Func =
2132 M->getOrInsertFunction(Name, B.getPtrTy(), Num->getType(), B.getInt8Ty());
2133 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2134 CallInst *CI = B.CreateCall(Func, {Num, HotCold}, Name);
2135
2136 if (const Function *F =
2137 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2138 CI->setCallingConv(F->getCallingConv());
2139
2140 return CI;
2141}
2142
2144 const TargetLibraryInfo *TLI,
2145 LibFunc NewFunc, Value *HotCold) {
2146 Module *M = B.GetInsertBlock()->getModule();
2147 if (!isLibFuncEmittable(M, TLI, NewFunc))
2148 return nullptr;
2149
2150 StringRef Name = TLI->getName(NewFunc);
2151 FunctionCallee Func = M->getOrInsertFunction(
2152 Name, B.getPtrTy(), Num->getType(), NoThrow->getType(), B.getInt8Ty());
2153 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2154 CallInst *CI = B.CreateCall(Func, {Num, NoThrow, HotCold}, Name);
2155
2156 if (const Function *F =
2157 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2158 CI->setCallingConv(F->getCallingConv());
2159
2160 return CI;
2161}
2162
2164 const TargetLibraryInfo *TLI,
2165 LibFunc NewFunc, Value *HotCold) {
2166 Module *M = B.GetInsertBlock()->getModule();
2167 if (!isLibFuncEmittable(M, TLI, NewFunc))
2168 return nullptr;
2169
2170 StringRef Name = TLI->getName(NewFunc);
2171 FunctionCallee Func = M->getOrInsertFunction(
2172 Name, B.getPtrTy(), Num->getType(), Align->getType(), B.getInt8Ty());
2173 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2174 CallInst *CI = B.CreateCall(Func, {Num, Align, HotCold}, Name);
2175
2176 if (const Function *F =
2177 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2178 CI->setCallingConv(F->getCallingConv());
2179
2180 return CI;
2181}
2182
2184 Value *NoThrow, IRBuilderBase &B,
2185 const TargetLibraryInfo *TLI,
2186 LibFunc NewFunc, Value *HotCold) {
2187 Module *M = B.GetInsertBlock()->getModule();
2188 if (!isLibFuncEmittable(M, TLI, NewFunc))
2189 return nullptr;
2190
2191 StringRef Name = TLI->getName(NewFunc);
2192 FunctionCallee Func = M->getOrInsertFunction(
2193 Name, B.getPtrTy(), Num->getType(), Align->getType(), NoThrow->getType(),
2194 B.getInt8Ty());
2195 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2196 CallInst *CI = B.CreateCall(Func, {Num, Align, NoThrow, HotCold}, Name);
2197
2198 if (const Function *F =
2199 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2200 CI->setCallingConv(F->getCallingConv());
2201
2202 return CI;
2203}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool setRetNoUndef(Function &F)
static bool setOnlyAccessesInaccessibleMemOrArgMemOrErrnoMem(Function &F)
static void appendTypeSuffix(Value *Op, StringRef &Name, SmallString< 20 > &NameBuffer)
Append a suffix to the function name according to the type of 'Op'.
static bool setDoesNotSync(Function &F)
static bool setDoesNotAlias(Function &F, unsigned ArgNo)
static bool setDoesNotAccessMemory(Function &F)
static bool setOnlyAccessesInaccessibleMemOrErrnoMem(Function &F)
static bool setOnlyWritesArgMemOrErrnoMem(Function &F)
static bool setArgsNoUndef(Function &F)
static IntegerType * getSizeTTy(IRBuilderBase &B, const TargetLibraryInfo *TLI)
static Value * emitUnaryFloatFnCallHelper(Value *Op, LibFunc TheLibFunc, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs, const TargetLibraryInfo *TLI)
static bool setAllocatedPointerParam(Function &F, unsigned ArgNo)
static void setRetExtAttr(Function &F, const TargetLibraryInfo &TLI, bool Signed=true)
static bool setMemoryEffects(Function &F, MemoryEffects ME)
static Value * emitLibCall(LibFunc TheLibFunc, Type *ReturnType, ArrayRef< Type * > ParamTypes, ArrayRef< Value * > Operands, IRBuilderBase &B, const TargetLibraryInfo *TLI, bool IsVaArgs=false)
static bool setNonLazyBind(Function &F)
static bool setIsCold(Function &F)
static bool setOnlyAccessesInaccessibleMemOrArgMem(Function &F)
static bool setAllocSize(Function &F, unsigned ElemSizeArg, std::optional< unsigned > NumElemsArg)
static bool setAlignedAllocParam(Function &F, unsigned ArgNo)
static bool setRetAndArgsNoUndef(Function &F)
static bool setRetDoesNotAlias(Function &F)
static bool setReturnedArg(Function &F, unsigned ArgNo)
static Value * emitBinaryFloatFnCallHelper(Value *Op1, Value *Op2, LibFunc TheLibFunc, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs, const TargetLibraryInfo *TLI)
static bool setOnlyWritesErrnoMemory(Function &F)
static bool setDoesNotCapture(Function &F, unsigned ArgNo)
static bool setDoesNotThrow(Function &F)
static bool setWillReturn(Function &F)
static bool setAllocKind(Function &F, AllocFnKind K)
static bool setNoReturn(Function &F)
static IntegerType * getIntTy(IRBuilderBase &B, const TargetLibraryInfo *TLI)
static bool setAllocFamily(Function &F, StringRef Family)
static bool setArgNoUndef(Function &F, unsigned ArgNo)
static bool setDoesNotCallback(Function &F)
static void setArgExtAttr(Function &F, unsigned ArgNo, const TargetLibraryInfo &TLI, bool Signed=true)
static bool setOnlyAccessesArgMemory(Function &F)
static bool setOnlyWritesMemory(Function &F)
static bool setOnlyReadsMemory(Function &F)
static bool setDoesNotFreeMemory(Function &F)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define T
SI Fold Operands
This file defines the SmallString class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static LLVM_ABI Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:125
@ None
No attributes have been set.
Definition Attributes.h:127
static LLVM_ABI Attribute getWithCaptureInfo(LLVMContext &Context, CaptureInfo CI)
void setCallingConv(CallingConv::ID CC)
void setAttributes(AttributeList A)
Set the attributes for this call.
This class represents a function call, abstracting a target machine's calling convention.
static CaptureInfo none()
Create CaptureInfo that does not capture any components of the pointer.
Definition ModRef.h:427
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Class to represent function types.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
Class to represent integer types.
static MemoryEffectsBase readOnly()
Definition ModRef.h:133
static MemoryEffectsBase inaccessibleOrArgOrErrnoMemOnly(ModRefInfo InaccessibleOrArgMR=ModRefInfo::ModRef, ModRefInfo ErrnoMR=ModRefInfo::ModRef)
Definition ModRef.h:186
static MemoryEffectsBase argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:143
static MemoryEffectsBase errnoMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:154
static MemoryEffectsBase writeOnly()
Definition ModRef.h:138
static MemoryEffectsBase inaccessibleOrArgMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:166
static MemoryEffectsBase argumentOrErrnoMemOnly(ModRefInfo ArgMR=ModRefInfo::ModRef, ModRefInfo ErrnoMR=ModRefInfo::ModRef)
Definition ModRef.h:198
static MemoryEffectsBase inaccessibleOrErrnoMemOnly(ModRefInfo InaccessibleMR=ModRefInfo::ModRef, ModRefInfo ErrnoMR=ModRefInfo::ModRef)
Definition ModRef.h:176
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition Type.cpp:467
Provides information about what library functions are available for the current target.
bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F, const Module &M) const
Return true if the function type FTy is valid for the library function F, regardless of whether the f...
bool has(LibFunc F) const
Tests whether a library function is available.
unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
StringRef getName(LibFunc F) const
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
LibFunc getLibFunc(StringRef funcName) const
Searches for a particular function name.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
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
@ DoubleTyID
64-bit floating point type
Definition Type.h:60
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition Value.cpp:712
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ X86_StdCall
stdcall is mostly used by the Win32 API.
Definition CallingConv.h:99
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI Value * emitUnaryFloatFnCall(Value *Op, const TargetLibraryInfo *TLI, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
LLVM_ABI Value * emitStrChr(Value *Ptr, char C, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strchr function to the builder, for the specified pointer and character.
LLVM_ABI Value * emitPutChar(Value *Char, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the putchar function. This assumes that Char is an 'int'.
LLVM_ABI Value * emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the __memcpy_chk function to the builder.
LLVM_ABI Value * emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strncpy function to the builder, for the specified pointer arguments and length.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
AllocFnKind
Definition Attributes.h:54
LLVM_ABI Value * emitSPrintf(Value *Dest, Value *Fmt, ArrayRef< Value * > VariadicArgs, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the sprintf function.
LLVM_ABI Value * emitMemRChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memrchr function, analogously to emitMemChr.
LLVM_ABI Value * emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcat function.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2224
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
Definition ModRef.h:356
LLVM_ABI Value * emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
LLVM_ABI bool hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Check whether the overloaded floating point function corresponding to Ty is available.
LLVM_ABI bool inferNonMandatoryLibFuncAttrs(Module *M, StringRef Name, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
LLVM_ABI bool isLibFreeFunction(const Function *F, const LibFunc TLIFn)
isLibFreeFunction - Returns true if the function is a builtin free()
LLVM_ABI Value * emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
LLVM_ABI Value * emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strncat function.
LLVM_ABI bool isLibFuncEmittable(const Module *M, const TargetLibraryInfo *TLI, LibFunc TheLibFunc)
Check whether the library function is available on target and also that it in the current Module is a...
LLVM_ABI Value * emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsnprintf function.
LLVM_ABI Value * emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strncmp function to the builder.
LLVM_ABI Value * emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memcmp function.
LLVM_ABI Value * emitBinaryFloatFnCall(Value *Op1, Value *Op2, const TargetLibraryInfo *TLI, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the binary function named 'Name' (e.g.
LLVM_ABI Value * emitFPutS(Value *Str, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
LLVM_ABI Value * emitStrDup(Value *Ptr, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strdup function to the builder, for the specified pointer.
LLVM_ABI Value * emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
LLVM_ABI Value * emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
LLVM_ABI Value * emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the bcmp function.
LLVM_ABI void markRegisterParameterAttributes(Function *F)
LLVM_ABI StringRef getFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn, LibFunc &TheLibFunc)
Get the name of the overloaded floating point function corresponding to Ty.
LLVM_ABI FunctionCallee getOrInsertLibFunc(Module *M, const TargetLibraryInfo &TLI, LibFunc TheLibFunc, FunctionType *T, AttributeList AttributeList)
Calls getOrInsertFunction() and then makes sure to add mandatory argument attributes.
LLVM_ABI Value * emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strlen function to the builder, for the specified pointer.
LLVM_ABI Value * emitFPutC(Value *Char, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
LLVM_ABI Value * emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the stpncpy function to the builder, for the specified pointer arguments and length.
LLVM_ABI Value * emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcat function.
LLVM_ABI Value * emitCalloc(Value *Num, Value *Size, IRBuilderBase &B, const TargetLibraryInfo &TLI, unsigned AddrSpace)
Emit a call to the calloc function.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ABI Value * emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsprintf function.
LLVM_ABI bool isReallocLikeFn(const Function *F)
Tests if a function is a call or invoke to a library function that reallocates memory (e....
LLVM_ABI Value * emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite function.
LLVM_ABI Value * emitSNPrintf(Value *Dest, Value *Size, Value *Fmt, ArrayRef< Value * > Args, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the snprintf function.
@ ModRef
The access may reference and may modify the value stored in memory.
Definition ModRef.h:36
@ Mod
The access may modify the value stored in memory.
Definition ModRef.h:34
LLVM_ABI Value * emitHotColdSizeReturningNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
LLVM_ABI Value * emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the stpcpy function to the builder, for the specified pointer arguments.
DWARFExpression::Operation Op
LLVM_ABI Value * emitWcsLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the wcslen function to the builder, for the specified pointer.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI Value * emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
LLVM_ABI Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
LLVM_ABI Value * emitPutS(Value *Str, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
LLVM_ABI Value * emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the memccpy function.
LLVM_ABI Value * emitHotColdNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold)
Emit a call to the hot/cold operator new function.
LLVM_ABI Value * emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcpy function.
LLVM_ABI Value * emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcpy function to the builder, for the specified pointer arguments.
LLVM_ABI Value * emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the mempcpy function.
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39