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_sinf:
1354 case LibFunc_sinh:
1355 case LibFunc_sinhf:
1356 case LibFunc_sinhl:
1357 case LibFunc_sinl:
1358 case LibFunc_sinpi:
1359 case LibFunc_sinpif:
1360 case LibFunc_sqrt:
1361 case LibFunc_sqrtf:
1362 case LibFunc_sqrtl:
1363 case LibFunc_tan:
1364 case LibFunc_tanf:
1365 case LibFunc_tanh:
1366 case LibFunc_tanhf:
1367 case LibFunc_tanhl:
1368 case LibFunc_tanl:
1375 break;
1376 case LibFunc_abs:
1377 case LibFunc_cbrt:
1378 case LibFunc_cbrtf:
1379 case LibFunc_cbrtl:
1380 case LibFunc_copysign:
1381 case LibFunc_copysignf:
1382 case LibFunc_copysignl:
1383 case LibFunc_ceil:
1384 case LibFunc_ceilf:
1385 case LibFunc_ceill:
1386 case LibFunc_fabs:
1387 case LibFunc_fabsf:
1388 case LibFunc_fabsl:
1389 case LibFunc_ffs:
1390 case LibFunc_ffsl:
1391 case LibFunc_ffsll:
1392 case LibFunc_floor:
1393 case LibFunc_floorf:
1394 case LibFunc_floorl:
1395 case LibFunc_fls:
1396 case LibFunc_flsl:
1397 case LibFunc_flsll:
1398 case LibFunc_fmax:
1399 case LibFunc_fmaxf:
1400 case LibFunc_fmaxl:
1401 case LibFunc_fmin:
1402 case LibFunc_fminf:
1403 case LibFunc_fminl:
1404 case LibFunc_fmaximum_num:
1405 case LibFunc_fmaximum_numf:
1406 case LibFunc_fmaximum_numl:
1407 case LibFunc_fminimum_num:
1408 case LibFunc_fminimum_numf:
1409 case LibFunc_fminimum_numl:
1410 case LibFunc_labs:
1411 case LibFunc_llabs:
1412 case LibFunc_nearbyint:
1413 case LibFunc_nearbyintf:
1414 case LibFunc_nearbyintl:
1415 case LibFunc_round:
1416 case LibFunc_roundf:
1417 case LibFunc_roundl:
1418 case LibFunc_roundeven:
1419 case LibFunc_roundevenf:
1420 case LibFunc_roundevenl:
1421 case LibFunc_sincos_stret:
1422 case LibFunc_sincosf_stret:
1423 case LibFunc_sincospi_stret:
1424 case LibFunc_sincospif_stret:
1425 case LibFunc_toascii:
1426 case LibFunc_trunc:
1427 case LibFunc_truncf:
1428 case LibFunc_truncl:
1430 [[fallthrough]];
1431 case LibFunc_isascii:
1432 case LibFunc_isdigit:
1437 break;
1438 case LibFunc_sincos:
1439 case LibFunc_sincosf:
1440 case LibFunc_sincosl:
1443 [[fallthrough]];
1444 case LibFunc_remquo:
1445 case LibFunc_remquof:
1446 case LibFunc_remquol:
1455 break;
1456 default:
1457 // FIXME: It'd be really nice to cover all the library functions we're
1458 // aware of here.
1459 break;
1460 }
1461 // We have to do this step after AllocKind has been inferred on functions so
1462 // we can reliably identify free-like and realloc-like functions.
1463 if (!isLibFreeFunction(&F, TheLibFunc) && !isReallocLikeFn(&F))
1465 return Changed;
1466}
1467
1468static void setI8ArgExtAttr(Function &F, unsigned ArgNo,
1469 const TargetLibraryInfo &TLI, bool Signed = true) {
1471 if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr))
1472 F.addParamAttr(ArgNo, ExtAttr);
1473}
1474
1475static void setArgExtAttr(Function &F, unsigned ArgNo,
1476 const TargetLibraryInfo &TLI, bool Signed = true) {
1477 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Param(Signed);
1478 if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr))
1479 F.addParamAttr(ArgNo, ExtAttr);
1480}
1481
1483 const TargetLibraryInfo &TLI, bool Signed = true) {
1484 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Return(Signed);
1485 if (ExtAttr != Attribute::None && !F.hasRetAttribute(ExtAttr))
1486 F.addRetAttr(ExtAttr);
1487}
1488
1489// Modeled after X86TargetLowering::markLibCallAttributes.
1491 if (!F->arg_size() || F->isVarArg())
1492 return;
1493
1494 const CallingConv::ID CC = F->getCallingConv();
1496 return;
1497
1498 const Module *M = F->getParent();
1499 unsigned N = M->getNumberRegisterParameters();
1500 if (!N)
1501 return;
1502
1503 const DataLayout &DL = M->getDataLayout();
1504
1505 for (Argument &A : F->args()) {
1506 Type *T = A.getType();
1507 if (!T->isIntOrPtrTy())
1508 continue;
1509
1510 const TypeSize &TS = DL.getTypeAllocSize(T);
1511 if (TS > 8)
1512 continue;
1513
1514 assert(TS <= 4 && "Need to account for parameters larger than word size");
1515 const unsigned NumRegs = TS > 4 ? 2 : 1;
1516 if (N < NumRegs)
1517 return;
1518
1519 N -= NumRegs;
1520 F->addParamAttr(A.getArgNo(), Attribute::InReg);
1521 }
1522}
1523
1525 LibFunc TheLibFunc, FunctionType *T,
1527 assert(TLI.has(TheLibFunc) &&
1528 "Creating call to non-existing library function.");
1529 StringRef Name = TLI.getName(TheLibFunc);
1530 FunctionCallee C = M->getOrInsertFunction(Name, T, AttributeList);
1531
1532 // Make sure any mandatory argument attributes are added.
1533
1534 // Any outgoing i32 argument should be handled with setArgExtAttr() which
1535 // will add an extension attribute if the target ABI requires it. Adding
1536 // argument extensions is typically done by the front end but when an
1537 // optimizer is building a library call on its own it has to take care of
1538 // this. Each such generated function must be handled here with sign or
1539 // zero extensions as needed. F is retreived with cast<> because we demand
1540 // of the caller to have called isLibFuncEmittable() first.
1541 Function *F = cast<Function>(C.getCallee());
1542 assert(F->getFunctionType() == T && "Function type does not match.");
1543 switch (TheLibFunc) {
1544 case LibFunc_fputc:
1545 case LibFunc_putchar:
1546 setArgExtAttr(*F, 0, TLI);
1547 break;
1548 case LibFunc_ldexp:
1549 case LibFunc_ldexpf:
1550 case LibFunc_ldexpl:
1551 case LibFunc_memchr:
1552 case LibFunc_memrchr:
1553 case LibFunc_strchr:
1554 setArgExtAttr(*F, 1, TLI);
1555 break;
1556 case LibFunc_memccpy:
1557 setArgExtAttr(*F, 2, TLI);
1558 break;
1559
1560 // The last argument of the hot-cold operator new variants is an i8
1561 // __hot_cold_t hint.
1562 case LibFunc_Znwm12__hot_cold_t:
1563 case LibFunc_Znam12__hot_cold_t:
1564 case LibFunc_size_returning_new_hot_cold:
1565 setI8ArgExtAttr(*F, 1, TLI, /*Signed=*/false);
1566 break;
1567 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
1568 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
1569 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
1570 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
1571 case LibFunc_size_returning_new_aligned_hot_cold:
1572 setI8ArgExtAttr(*F, 2, TLI, /*Signed=*/false);
1573 break;
1574 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1575 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1576 setI8ArgExtAttr(*F, 3, TLI, /*Signed=*/false);
1577 break;
1578
1579 // These are functions that are known to not need any argument extension
1580 // on any target: A size_t argument (which may be an i32 on some targets)
1581 // should not trigger the assert below.
1582 case LibFunc_bcmp:
1583 setRetExtAttr(*F, TLI);
1584 break;
1585 case LibFunc_calloc:
1586 case LibFunc_fwrite:
1587 case LibFunc_malloc:
1588 case LibFunc_memcmp:
1589 case LibFunc_memcpy_chk:
1590 case LibFunc_mempcpy:
1591 case LibFunc_memset_pattern16:
1592 case LibFunc_snprintf:
1593 case LibFunc_stpncpy:
1594 case LibFunc_strlcat:
1595 case LibFunc_strlcpy:
1596 case LibFunc_strncat:
1597 case LibFunc_strncmp:
1598 case LibFunc_strncpy:
1599 case LibFunc_vsnprintf:
1600 break;
1601
1602 default:
1603#ifndef NDEBUG
1604 for (unsigned i = 0; i < T->getNumParams(); i++)
1605 assert(!isa<IntegerType>(T->getParamType(i)) &&
1606 "Unhandled integer argument.");
1607#endif
1608 break;
1609 }
1610
1612
1613 return C;
1614}
1615
1617 LibFunc TheLibFunc, FunctionType *T) {
1618 return getOrInsertLibFunc(M, TLI, TheLibFunc, T, AttributeList());
1619}
1620
1622 LibFunc TheLibFunc) {
1623 StringRef FuncName = TLI->getName(TheLibFunc);
1624 if (!TLI->has(TheLibFunc))
1625 return false;
1626
1627 // Check if the Module already has a GlobalValue with the same name, in
1628 // which case it must be a Function with the expected type.
1629 if (GlobalValue *GV = M->getNamedValue(FuncName)) {
1630 if (auto *F = dyn_cast<Function>(GV))
1631 return TLI->isValidProtoForLibFunc(*F->getFunctionType(), TheLibFunc, *M);
1632 return false;
1633 }
1634
1635 return true;
1636}
1637
1639 StringRef Name) {
1640 return isLibFuncEmittable(M, TLI, TLI->getLibFunc(Name));
1641}
1642
1643bool llvm::hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty,
1644 LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
1645 switch (Ty->getTypeID()) {
1646 case Type::HalfTyID:
1647 return false;
1648 case Type::FloatTyID:
1649 return isLibFuncEmittable(M, TLI, FloatFn);
1650 case Type::DoubleTyID:
1651 return isLibFuncEmittable(M, TLI, DoubleFn);
1652 default:
1653 return isLibFuncEmittable(M, TLI, LongDoubleFn);
1654 }
1655}
1656
1658 Type *Ty, LibFunc DoubleFn, LibFunc FloatFn,
1659 LibFunc LongDoubleFn, LibFunc &TheLibFunc) {
1660 assert(hasFloatFn(M, TLI, Ty, DoubleFn, FloatFn, LongDoubleFn) &&
1661 "Cannot get name for unavailable function!");
1662
1663 switch (Ty->getTypeID()) {
1664 case Type::HalfTyID:
1665 llvm_unreachable("No name for HalfTy!");
1666 case Type::FloatTyID:
1667 TheLibFunc = FloatFn;
1668 return TLI->getName(FloatFn);
1669 case Type::DoubleTyID:
1670 TheLibFunc = DoubleFn;
1671 return TLI->getName(DoubleFn);
1672 default:
1673 TheLibFunc = LongDoubleFn;
1674 return TLI->getName(LongDoubleFn);
1675 }
1676}
1677
1678//- Emit LibCalls ------------------------------------------------------------//
1679
1681 return B.getIntNTy(TLI->getIntSize());
1682}
1683
1685 const Module *M = B.getModule();
1686 return B.getIntNTy(TLI->getSizeTSize(*M));
1687}
1688
1689static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
1690 ArrayRef<Type *> ParamTypes,
1692 const TargetLibraryInfo *TLI,
1693 bool IsVaArgs = false) {
1694 Module *M = B.getModule();
1695 if (!isLibFuncEmittable(M, TLI, TheLibFunc))
1696 return nullptr;
1697
1698 StringRef FuncName = TLI->getName(TheLibFunc);
1699 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1700 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, FuncType);
1701 inferNonMandatoryLibFuncAttrs(M, FuncName, *TLI);
1702 CallInst *CI = B.CreateCall(Callee, Operands, FuncName);
1703 if (const Function *F =
1704 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1705 CI->setCallingConv(F->getCallingConv());
1706 return CI;
1707}
1708
1710 const TargetLibraryInfo *TLI) {
1711 Type *CharPtrTy = B.getPtrTy();
1712 Type *SizeTTy = getSizeTTy(B, TLI);
1713 return emitLibCall(LibFunc_strlen, SizeTTy, CharPtrTy, Ptr, B, TLI);
1714}
1715
1717 const TargetLibraryInfo *TLI) {
1718 assert(Ptr && Ptr->getType()->isPointerTy() &&
1719 "Argument to wcslen intrinsic must be a pointer.");
1720 Type *PtrTy = B.getPtrTy();
1721 Type *SizeTTy = getSizeTTy(B, TLI);
1722 return emitLibCall(LibFunc_wcslen, SizeTTy, PtrTy, Ptr, B, TLI);
1723}
1724
1726 const TargetLibraryInfo *TLI) {
1727 Type *CharPtrTy = B.getPtrTy();
1728 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy, Ptr, B, TLI);
1729}
1730
1732 const TargetLibraryInfo *TLI) {
1733 Type *CharPtrTy = B.getPtrTy();
1734 Type *IntTy = getIntTy(B, TLI);
1735 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1736 {Ptr, ConstantInt::get(IntTy, (unsigned char)C)}, B, TLI);
1737}
1738
1740 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1741 Type *CharPtrTy = B.getPtrTy();
1742 Type *IntTy = getIntTy(B, TLI);
1743 Type *SizeTTy = getSizeTTy(B, TLI);
1744 return emitLibCall(
1745 LibFunc_strncmp, IntTy,
1746 {CharPtrTy, CharPtrTy, SizeTTy},
1747 {Ptr1, Ptr2, Len}, B, TLI);
1748}
1749
1751 const TargetLibraryInfo *TLI) {
1752 Type *CharPtrTy = Dst->getType();
1753 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1754 {Dst, Src}, B, TLI);
1755}
1756
1758 const TargetLibraryInfo *TLI) {
1759 Type *CharPtrTy = B.getPtrTy();
1760 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1761 {Dst, Src}, B, TLI);
1762}
1763
1765 const TargetLibraryInfo *TLI) {
1766 Type *CharPtrTy = B.getPtrTy();
1767 Type *SizeTTy = getSizeTTy(B, TLI);
1768 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1769 {Dst, Src, Len}, B, TLI);
1770}
1771
1773 const TargetLibraryInfo *TLI) {
1774 Type *CharPtrTy = B.getPtrTy();
1775 Type *SizeTTy = getSizeTTy(B, TLI);
1776 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1777 {Dst, Src, Len}, B, TLI);
1778}
1779
1780Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
1781 IRBuilderBase &B, const DataLayout &DL,
1782 const TargetLibraryInfo *TLI) {
1783 Module *M = B.getModule();
1784 if (!isLibFuncEmittable(M, TLI, LibFunc_memcpy_chk))
1785 return nullptr;
1786
1787 AttributeList AS;
1788 AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
1789 Attribute::NoUnwind);
1790 Type *VoidPtrTy = B.getPtrTy();
1791 Type *SizeTTy = getSizeTTy(B, TLI);
1792 FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
1793 AttributeList::get(M->getContext(), AS), VoidPtrTy,
1794 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1795 CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1796 if (const Function *F =
1798 CI->setCallingConv(F->getCallingConv());
1799 return CI;
1800}
1801
1803 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1804 Type *VoidPtrTy = B.getPtrTy();
1805 Type *SizeTTy = getSizeTTy(B, TLI);
1806 return emitLibCall(LibFunc_mempcpy, VoidPtrTy,
1807 {VoidPtrTy, VoidPtrTy, SizeTTy},
1808 {Dst, Src, Len}, B, TLI);
1809}
1810
1812 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1813 Type *VoidPtrTy = B.getPtrTy();
1814 Type *IntTy = getIntTy(B, TLI);
1815 Type *SizeTTy = getSizeTTy(B, TLI);
1816 return emitLibCall(LibFunc_memchr, VoidPtrTy,
1817 {VoidPtrTy, IntTy, SizeTTy},
1818 {Ptr, Val, Len}, B, TLI);
1819}
1820
1822 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1823 Type *VoidPtrTy = B.getPtrTy();
1824 Type *IntTy = getIntTy(B, TLI);
1825 Type *SizeTTy = getSizeTTy(B, TLI);
1826 return emitLibCall(LibFunc_memrchr, VoidPtrTy,
1827 {VoidPtrTy, IntTy, SizeTTy},
1828 {Ptr, Val, Len}, B, TLI);
1829}
1830
1832 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1833 Type *VoidPtrTy = B.getPtrTy();
1834 Type *IntTy = getIntTy(B, TLI);
1835 Type *SizeTTy = getSizeTTy(B, TLI);
1836 return emitLibCall(LibFunc_memcmp, IntTy,
1837 {VoidPtrTy, VoidPtrTy, SizeTTy},
1838 {Ptr1, Ptr2, Len}, B, TLI);
1839}
1840
1842 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1843 Type *VoidPtrTy = B.getPtrTy();
1844 Type *IntTy = getIntTy(B, TLI);
1845 Type *SizeTTy = getSizeTTy(B, TLI);
1846 return emitLibCall(LibFunc_bcmp, IntTy,
1847 {VoidPtrTy, VoidPtrTy, SizeTTy},
1848 {Ptr1, Ptr2, Len}, B, TLI);
1849}
1850
1851Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
1852 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1853 Type *VoidPtrTy = B.getPtrTy();
1854 Type *IntTy = getIntTy(B, TLI);
1855 Type *SizeTTy = getSizeTTy(B, TLI);
1856 return emitLibCall(LibFunc_memccpy, VoidPtrTy,
1857 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1858 {Ptr1, Ptr2, Val, Len}, B, TLI);
1859}
1860
1862 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1863 const TargetLibraryInfo *TLI) {
1864 Type *CharPtrTy = B.getPtrTy();
1865 Type *IntTy = getIntTy(B, TLI);
1866 Type *SizeTTy = getSizeTTy(B, TLI);
1867 SmallVector<Value *, 8> Args{Dest, Size, Fmt};
1868 llvm::append_range(Args, VariadicArgs);
1869 return emitLibCall(LibFunc_snprintf, IntTy,
1870 {CharPtrTy, SizeTTy, CharPtrTy},
1871 Args, B, TLI, /*IsVaArgs=*/true);
1872}
1873
1875 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1876 const TargetLibraryInfo *TLI) {
1877 Type *CharPtrTy = B.getPtrTy();
1878 Type *IntTy = getIntTy(B, TLI);
1879 SmallVector<Value *, 8> Args{Dest, Fmt};
1880 llvm::append_range(Args, VariadicArgs);
1881 return emitLibCall(LibFunc_sprintf, IntTy,
1882 {CharPtrTy, CharPtrTy}, Args, B, TLI,
1883 /*IsVaArgs=*/true);
1884}
1885
1887 const TargetLibraryInfo *TLI) {
1888 Type *CharPtrTy = B.getPtrTy();
1889 return emitLibCall(LibFunc_strcat, CharPtrTy,
1890 {CharPtrTy, CharPtrTy},
1891 {Dest, Src}, B, TLI);
1892}
1893
1895 const TargetLibraryInfo *TLI) {
1896 Type *CharPtrTy = B.getPtrTy();
1897 Type *SizeTTy = getSizeTTy(B, TLI);
1898 return emitLibCall(LibFunc_strlcpy, SizeTTy,
1899 {CharPtrTy, CharPtrTy, SizeTTy},
1900 {Dest, Src, Size}, B, TLI);
1901}
1902
1904 const TargetLibraryInfo *TLI) {
1905 Type *CharPtrTy = B.getPtrTy();
1906 Type *SizeTTy = getSizeTTy(B, TLI);
1907 return emitLibCall(LibFunc_strlcat, SizeTTy,
1908 {CharPtrTy, CharPtrTy, SizeTTy},
1909 {Dest, Src, Size}, B, TLI);
1910}
1911
1913 const TargetLibraryInfo *TLI) {
1914 Type *CharPtrTy = B.getPtrTy();
1915 Type *SizeTTy = getSizeTTy(B, TLI);
1916 return emitLibCall(LibFunc_strncat, CharPtrTy,
1917 {CharPtrTy, CharPtrTy, SizeTTy},
1918 {Dest, Src, Size}, B, TLI);
1919}
1920
1922 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1923 Type *CharPtrTy = B.getPtrTy();
1924 Type *IntTy = getIntTy(B, TLI);
1925 Type *SizeTTy = getSizeTTy(B, TLI);
1926 return emitLibCall(
1927 LibFunc_vsnprintf, IntTy,
1928 {CharPtrTy, SizeTTy, CharPtrTy, VAList->getType()},
1929 {Dest, Size, Fmt, VAList}, B, TLI);
1930}
1931
1933 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1934 Type *CharPtrTy = B.getPtrTy();
1935 Type *IntTy = getIntTy(B, TLI);
1936 return emitLibCall(LibFunc_vsprintf, IntTy,
1937 {CharPtrTy, CharPtrTy, VAList->getType()},
1938 {Dest, Fmt, VAList}, B, TLI);
1939}
1940
1941/// Append a suffix to the function name according to the type of 'Op'.
1943 SmallString<20> &NameBuffer) {
1944 if (!Op->getType()->isDoubleTy()) {
1945 NameBuffer += Name;
1946
1947 if (Op->getType()->isFloatTy())
1948 NameBuffer += 'f';
1949 else
1950 NameBuffer += 'l';
1951
1952 Name = NameBuffer;
1953 }
1954}
1955
1956static Value *emitUnaryFloatFnCallHelper(Value *Op, LibFunc TheLibFunc,
1957 StringRef Name, IRBuilderBase &B,
1958 const AttributeList &Attrs,
1959 const TargetLibraryInfo *TLI) {
1960 assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
1961
1962 Module *M = B.getModule();
1963 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op->getType(),
1964 Op->getType());
1965 CallInst *CI = B.CreateCall(Callee, Op, Name);
1966
1967 // The incoming attribute set may have come from a speculatable intrinsic, but
1968 // is being replaced with a library call which is not allowed to be
1969 // speculatable.
1970 CI->setAttributes(
1971 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1972 if (const Function *F =
1973 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1974 CI->setCallingConv(F->getCallingConv());
1975
1976 return CI;
1977}
1978
1980 StringRef Name, IRBuilderBase &B,
1981 const AttributeList &Attrs) {
1982 SmallString<20> NameBuffer;
1983 appendTypeSuffix(Op, Name, NameBuffer);
1984
1985 return emitUnaryFloatFnCallHelper(Op, TLI->getLibFunc(Name), Name, B, Attrs,
1986 TLI);
1987}
1988
1990 LibFunc DoubleFn, LibFunc FloatFn,
1991 LibFunc LongDoubleFn, IRBuilderBase &B,
1992 const AttributeList &Attrs) {
1993 // Get the name of the function according to TLI.
1994 Module *M = B.getModule();
1995 LibFunc TheLibFunc;
1996 StringRef Name = getFloatFn(M, TLI, Op->getType(), DoubleFn, FloatFn,
1997 LongDoubleFn, TheLibFunc);
1998
1999 return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
2000}
2001
2003 LibFunc TheLibFunc,
2004 StringRef Name, IRBuilderBase &B,
2005 const AttributeList &Attrs,
2006 const TargetLibraryInfo *TLI) {
2007 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
2008
2009 Module *M = B.getModule();
2010 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op1->getType(),
2011 Op1->getType(), Op2->getType());
2012 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2013 CallInst *CI = B.CreateCall(Callee, { Op1, Op2 }, Name);
2014
2015 // The incoming attribute set may have come from a speculatable intrinsic, but
2016 // is being replaced with a library call which is not allowed to be
2017 // speculatable.
2018 CI->setAttributes(
2019 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
2020 if (const Function *F =
2021 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
2022 CI->setCallingConv(F->getCallingConv());
2023
2024 return CI;
2025}
2026
2028 const TargetLibraryInfo *TLI,
2029 StringRef Name, IRBuilderBase &B,
2030 const AttributeList &Attrs) {
2031 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
2032
2033 SmallString<20> NameBuffer;
2034 appendTypeSuffix(Op1, Name, NameBuffer);
2035
2036 return emitBinaryFloatFnCallHelper(Op1, Op2, TLI->getLibFunc(Name), Name, B,
2037 Attrs, TLI);
2038}
2039
2041 const TargetLibraryInfo *TLI,
2042 LibFunc DoubleFn, LibFunc FloatFn,
2043 LibFunc LongDoubleFn, IRBuilderBase &B,
2044 const AttributeList &Attrs) {
2045 // Get the name of the function according to TLI.
2046 Module *M = B.getModule();
2047 LibFunc TheLibFunc;
2048 StringRef Name = getFloatFn(M, TLI, Op1->getType(), DoubleFn, FloatFn,
2049 LongDoubleFn, TheLibFunc);
2050
2051 return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
2052}
2053
2054// Emit a call to putchar(int) with Char as the argument. Char must have
2055// the same precision as int, which need not be 32 bits.
2057 const TargetLibraryInfo *TLI) {
2058 Type *IntTy = getIntTy(B, TLI);
2059 return emitLibCall(LibFunc_putchar, IntTy, IntTy, Char, B, TLI);
2060}
2061
2063 const TargetLibraryInfo *TLI) {
2064 Type *IntTy = getIntTy(B, TLI);
2065 return emitLibCall(LibFunc_puts, IntTy, B.getPtrTy(), Str, B, TLI);
2066}
2067
2069 const TargetLibraryInfo *TLI) {
2070 Type *IntTy = getIntTy(B, TLI);
2071 return emitLibCall(LibFunc_fputc, IntTy, {IntTy, File->getType()},
2072 {Char, File}, B, TLI);
2073}
2074
2076 const TargetLibraryInfo *TLI) {
2077 Type *IntTy = getIntTy(B, TLI);
2078 return emitLibCall(LibFunc_fputs, IntTy, {B.getPtrTy(), File->getType()},
2079 {Str, File}, B, TLI);
2080}
2081
2083 const DataLayout &DL, const TargetLibraryInfo *TLI) {
2084 Type *SizeTTy = getSizeTTy(B, TLI);
2085 return emitLibCall(LibFunc_fwrite, SizeTTy,
2086 {B.getPtrTy(), SizeTTy, SizeTTy, File->getType()},
2087 {Ptr, Size, ConstantInt::get(SizeTTy, 1), File}, B, TLI);
2088}
2089
2091 const TargetLibraryInfo *TLI) {
2092 Type *SizeTTy = getSizeTTy(B, TLI);
2093 return emitLibCall(LibFunc_malloc, B.getPtrTy(), SizeTTy, Num, B, TLI);
2094}
2095
2097 const TargetLibraryInfo &TLI, unsigned AddrSpace) {
2098 Type *SizeTTy = getSizeTTy(B, &TLI);
2099 return emitLibCall(LibFunc_calloc, B.getPtrTy(AddrSpace), {SizeTTy, SizeTTy},
2100 {Num, Size}, B, &TLI);
2101}
2102
2104 const TargetLibraryInfo *TLI,
2105 LibFunc SizeFeedbackNewFunc,
2106 Value *HotCold, Type *RetTy) {
2107 Module *M = B.getModule();
2108 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2109 return nullptr;
2110
2111 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2112 if (const Function *F = M->getFunction(Name);
2113 F && F->getReturnType() != RetTy)
2114 return nullptr;
2115
2116 FunctionCallee Func = getOrInsertLibFunc(M, *TLI, SizeFeedbackNewFunc, RetTy,
2117 Num->getType(), B.getInt8Ty());
2118 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2119 CallInst *CI = B.CreateCall(Func, {Num, HotCold}, "sized_ptr");
2120
2121 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2122 CI->setCallingConv(F->getCallingConv());
2123
2124 return CI;
2125}
2126
2129 const TargetLibraryInfo *TLI,
2130 LibFunc SizeFeedbackNewFunc,
2131 Value *HotCold, Type *RetTy) {
2132 Module *M = B.getModule();
2133 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2134 return nullptr;
2135
2136 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2137 if (const Function *F = M->getFunction(Name);
2138 F && F->getReturnType() != RetTy)
2139 return nullptr;
2140
2141 FunctionCallee Func =
2142 getOrInsertLibFunc(M, *TLI, SizeFeedbackNewFunc, RetTy, Num->getType(),
2143 Align->getType(), B.getInt8Ty());
2144 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2145 CallInst *CI = B.CreateCall(Func, {Num, Align, HotCold}, "sized_ptr");
2146
2147 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2148 CI->setCallingConv(F->getCallingConv());
2149
2150 return CI;
2151}
2152
2154 const TargetLibraryInfo *TLI, LibFunc NewFunc,
2155 Value *HotCold) {
2156 Module *M = B.getModule();
2157 if (!isLibFuncEmittable(M, TLI, NewFunc))
2158 return nullptr;
2159
2160 StringRef Name = TLI->getName(NewFunc);
2161 FunctionCallee Func = getOrInsertLibFunc(M, *TLI, NewFunc, B.getPtrTy(),
2162 Num->getType(), B.getInt8Ty());
2163 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2164 CallInst *CI = B.CreateCall(Func, {Num, HotCold}, Name);
2165
2166 if (const Function *F =
2167 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2168 CI->setCallingConv(F->getCallingConv());
2169
2170 return CI;
2171}
2172
2174 const TargetLibraryInfo *TLI,
2175 LibFunc NewFunc, Value *HotCold) {
2176 Module *M = B.getModule();
2177 if (!isLibFuncEmittable(M, TLI, NewFunc))
2178 return nullptr;
2179
2180 StringRef Name = TLI->getName(NewFunc);
2181 FunctionCallee Func =
2182 getOrInsertLibFunc(M, *TLI, NewFunc, B.getPtrTy(), Num->getType(),
2183 NoThrow->getType(), B.getInt8Ty());
2184 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2185 CallInst *CI = B.CreateCall(Func, {Num, NoThrow, HotCold}, Name);
2186
2187 if (const Function *F =
2188 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2189 CI->setCallingConv(F->getCallingConv());
2190
2191 return CI;
2192}
2193
2195 const TargetLibraryInfo *TLI,
2196 LibFunc NewFunc, Value *HotCold) {
2197 Module *M = B.getModule();
2198 if (!isLibFuncEmittable(M, TLI, NewFunc))
2199 return nullptr;
2200
2201 StringRef Name = TLI->getName(NewFunc);
2202 FunctionCallee Func =
2203 getOrInsertLibFunc(M, *TLI, NewFunc, B.getPtrTy(), Num->getType(),
2204 Align->getType(), B.getInt8Ty());
2205 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2206 CallInst *CI = B.CreateCall(Func, {Num, Align, HotCold}, Name);
2207
2208 if (const Function *F =
2209 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2210 CI->setCallingConv(F->getCallingConv());
2211
2212 return CI;
2213}
2214
2216 Value *NoThrow, IRBuilderBase &B,
2217 const TargetLibraryInfo *TLI,
2218 LibFunc NewFunc, Value *HotCold) {
2219 Module *M = B.getModule();
2220 if (!isLibFuncEmittable(M, TLI, NewFunc))
2221 return nullptr;
2222
2223 StringRef Name = TLI->getName(NewFunc);
2224 FunctionCallee Func =
2225 getOrInsertLibFunc(M, *TLI, NewFunc, B.getPtrTy(), Num->getType(),
2226 Align->getType(), NoThrow->getType(), B.getInt8Ty());
2227 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2228 CallInst *CI = B.CreateCall(Func, {Num, Align, NoThrow, HotCold}, Name);
2229
2230 if (const Function *F =
2231 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2232 CI->setCallingConv(F->getCallingConv());
2233
2234 return CI;
2235}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t 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 void setI8ArgExtAttr(Function &F, unsigned ArgNo, const TargetLibraryInfo &TLI, bool Signed=true)
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
RISCVCC::CondCode CC
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:111
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
Provides information about what library functions are available for the current target.
static Attribute::AttrKind getExtAttrForI8Param(bool Signed=true)
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:708
#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 * emitHotColdSizeReturningNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold, Type *RetTy)
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 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 * 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 * emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, Value *HotCold, Type *RetTy)
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