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 setI8ArgExtAttr(Function &F, unsigned ArgNo,
1466 const TargetLibraryInfo &TLI, bool Signed = true) {
1468 if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr))
1469 F.addParamAttr(ArgNo, ExtAttr);
1470}
1471
1472static void setArgExtAttr(Function &F, unsigned ArgNo,
1473 const TargetLibraryInfo &TLI, bool Signed = true) {
1474 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Param(Signed);
1475 if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr))
1476 F.addParamAttr(ArgNo, ExtAttr);
1477}
1478
1480 const TargetLibraryInfo &TLI, bool Signed = true) {
1481 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Return(Signed);
1482 if (ExtAttr != Attribute::None && !F.hasRetAttribute(ExtAttr))
1483 F.addRetAttr(ExtAttr);
1484}
1485
1486// Modeled after X86TargetLowering::markLibCallAttributes.
1488 if (!F->arg_size() || F->isVarArg())
1489 return;
1490
1491 const CallingConv::ID CC = F->getCallingConv();
1492 if (CC != CallingConv::C && CC != CallingConv::X86_StdCall)
1493 return;
1494
1495 const Module *M = F->getParent();
1496 unsigned N = M->getNumberRegisterParameters();
1497 if (!N)
1498 return;
1499
1500 const DataLayout &DL = M->getDataLayout();
1501
1502 for (Argument &A : F->args()) {
1503 Type *T = A.getType();
1504 if (!T->isIntOrPtrTy())
1505 continue;
1506
1507 const TypeSize &TS = DL.getTypeAllocSize(T);
1508 if (TS > 8)
1509 continue;
1510
1511 assert(TS <= 4 && "Need to account for parameters larger than word size");
1512 const unsigned NumRegs = TS > 4 ? 2 : 1;
1513 if (N < NumRegs)
1514 return;
1515
1516 N -= NumRegs;
1517 F->addParamAttr(A.getArgNo(), Attribute::InReg);
1518 }
1519}
1520
1522 LibFunc TheLibFunc, FunctionType *T,
1524 assert(TLI.has(TheLibFunc) &&
1525 "Creating call to non-existing library function.");
1526 StringRef Name = TLI.getName(TheLibFunc);
1527 FunctionCallee C = M->getOrInsertFunction(Name, T, AttributeList);
1528
1529 // Make sure any mandatory argument attributes are added.
1530
1531 // Any outgoing i32 argument should be handled with setArgExtAttr() which
1532 // will add an extension attribute if the target ABI requires it. Adding
1533 // argument extensions is typically done by the front end but when an
1534 // optimizer is building a library call on its own it has to take care of
1535 // this. Each such generated function must be handled here with sign or
1536 // zero extensions as needed. F is retreived with cast<> because we demand
1537 // of the caller to have called isLibFuncEmittable() first.
1538 Function *F = cast<Function>(C.getCallee());
1539 assert(F->getFunctionType() == T && "Function type does not match.");
1540 switch (TheLibFunc) {
1541 case LibFunc_fputc:
1542 case LibFunc_putchar:
1543 setArgExtAttr(*F, 0, TLI);
1544 break;
1545 case LibFunc_ldexp:
1546 case LibFunc_ldexpf:
1547 case LibFunc_ldexpl:
1548 case LibFunc_memchr:
1549 case LibFunc_memrchr:
1550 case LibFunc_strchr:
1551 setArgExtAttr(*F, 1, TLI);
1552 break;
1553 case LibFunc_memccpy:
1554 setArgExtAttr(*F, 2, TLI);
1555 break;
1556
1557 // The last argument of the hot-cold operator new variants is an i8
1558 // __hot_cold_t hint.
1559 case LibFunc_Znwm12__hot_cold_t:
1560 case LibFunc_Znam12__hot_cold_t:
1561 case LibFunc_size_returning_new_hot_cold:
1562 setI8ArgExtAttr(*F, 1, TLI, /*Signed=*/false);
1563 break;
1564 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
1565 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
1566 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
1567 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
1568 case LibFunc_size_returning_new_aligned_hot_cold:
1569 setI8ArgExtAttr(*F, 2, TLI, /*Signed=*/false);
1570 break;
1571 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1572 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1573 setI8ArgExtAttr(*F, 3, TLI, /*Signed=*/false);
1574 break;
1575
1576 // These are functions that are known to not need any argument extension
1577 // on any target: A size_t argument (which may be an i32 on some targets)
1578 // should not trigger the assert below.
1579 case LibFunc_bcmp:
1580 setRetExtAttr(*F, TLI);
1581 break;
1582 case LibFunc_calloc:
1583 case LibFunc_fwrite:
1584 case LibFunc_malloc:
1585 case LibFunc_memcmp:
1586 case LibFunc_memcpy_chk:
1587 case LibFunc_mempcpy:
1588 case LibFunc_memset_pattern16:
1589 case LibFunc_snprintf:
1590 case LibFunc_stpncpy:
1591 case LibFunc_strlcat:
1592 case LibFunc_strlcpy:
1593 case LibFunc_strncat:
1594 case LibFunc_strncmp:
1595 case LibFunc_strncpy:
1596 case LibFunc_vsnprintf:
1597 break;
1598
1599 default:
1600#ifndef NDEBUG
1601 for (unsigned i = 0; i < T->getNumParams(); i++)
1602 assert(!isa<IntegerType>(T->getParamType(i)) &&
1603 "Unhandled integer argument.");
1604#endif
1605 break;
1606 }
1607
1609
1610 return C;
1611}
1612
1614 LibFunc TheLibFunc, FunctionType *T) {
1615 return getOrInsertLibFunc(M, TLI, TheLibFunc, T, AttributeList());
1616}
1617
1619 LibFunc TheLibFunc) {
1620 StringRef FuncName = TLI->getName(TheLibFunc);
1621 if (!TLI->has(TheLibFunc))
1622 return false;
1623
1624 // Check if the Module already has a GlobalValue with the same name, in
1625 // which case it must be a Function with the expected type.
1626 if (GlobalValue *GV = M->getNamedValue(FuncName)) {
1627 if (auto *F = dyn_cast<Function>(GV))
1628 return TLI->isValidProtoForLibFunc(*F->getFunctionType(), TheLibFunc, *M);
1629 return false;
1630 }
1631
1632 return true;
1633}
1634
1636 StringRef Name) {
1637 return isLibFuncEmittable(M, TLI, TLI->getLibFunc(Name));
1638}
1639
1640bool llvm::hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty,
1641 LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
1642 switch (Ty->getTypeID()) {
1643 case Type::HalfTyID:
1644 return false;
1645 case Type::FloatTyID:
1646 return isLibFuncEmittable(M, TLI, FloatFn);
1647 case Type::DoubleTyID:
1648 return isLibFuncEmittable(M, TLI, DoubleFn);
1649 default:
1650 return isLibFuncEmittable(M, TLI, LongDoubleFn);
1651 }
1652}
1653
1655 Type *Ty, LibFunc DoubleFn, LibFunc FloatFn,
1656 LibFunc LongDoubleFn, LibFunc &TheLibFunc) {
1657 assert(hasFloatFn(M, TLI, Ty, DoubleFn, FloatFn, LongDoubleFn) &&
1658 "Cannot get name for unavailable function!");
1659
1660 switch (Ty->getTypeID()) {
1661 case Type::HalfTyID:
1662 llvm_unreachable("No name for HalfTy!");
1663 case Type::FloatTyID:
1664 TheLibFunc = FloatFn;
1665 return TLI->getName(FloatFn);
1666 case Type::DoubleTyID:
1667 TheLibFunc = DoubleFn;
1668 return TLI->getName(DoubleFn);
1669 default:
1670 TheLibFunc = LongDoubleFn;
1671 return TLI->getName(LongDoubleFn);
1672 }
1673}
1674
1675//- Emit LibCalls ------------------------------------------------------------//
1676
1678 return B.getIntNTy(TLI->getIntSize());
1679}
1680
1682 const Module *M = B.getModule();
1683 return B.getIntNTy(TLI->getSizeTSize(*M));
1684}
1685
1686static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
1687 ArrayRef<Type *> ParamTypes,
1689 const TargetLibraryInfo *TLI,
1690 bool IsVaArgs = false) {
1691 Module *M = B.getModule();
1692 if (!isLibFuncEmittable(M, TLI, TheLibFunc))
1693 return nullptr;
1694
1695 StringRef FuncName = TLI->getName(TheLibFunc);
1696 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1697 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, FuncType);
1698 inferNonMandatoryLibFuncAttrs(M, FuncName, *TLI);
1699 CallInst *CI = B.CreateCall(Callee, Operands, FuncName);
1700 if (const Function *F =
1701 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1702 CI->setCallingConv(F->getCallingConv());
1703 return CI;
1704}
1705
1707 const TargetLibraryInfo *TLI) {
1708 Type *CharPtrTy = B.getPtrTy();
1709 Type *SizeTTy = getSizeTTy(B, TLI);
1710 return emitLibCall(LibFunc_strlen, SizeTTy, CharPtrTy, Ptr, B, TLI);
1711}
1712
1714 const TargetLibraryInfo *TLI) {
1715 assert(Ptr && Ptr->getType()->isPointerTy() &&
1716 "Argument to wcslen intrinsic must be a pointer.");
1717 Type *PtrTy = B.getPtrTy();
1718 Type *SizeTTy = getSizeTTy(B, TLI);
1719 return emitLibCall(LibFunc_wcslen, SizeTTy, PtrTy, Ptr, B, TLI);
1720}
1721
1723 const TargetLibraryInfo *TLI) {
1724 Type *CharPtrTy = B.getPtrTy();
1725 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy, Ptr, B, TLI);
1726}
1727
1729 const TargetLibraryInfo *TLI) {
1730 Type *CharPtrTy = B.getPtrTy();
1731 Type *IntTy = getIntTy(B, TLI);
1732 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1733 {Ptr, ConstantInt::get(IntTy, (unsigned char)C)}, B, TLI);
1734}
1735
1737 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1738 Type *CharPtrTy = B.getPtrTy();
1739 Type *IntTy = getIntTy(B, TLI);
1740 Type *SizeTTy = getSizeTTy(B, TLI);
1741 return emitLibCall(
1742 LibFunc_strncmp, IntTy,
1743 {CharPtrTy, CharPtrTy, SizeTTy},
1744 {Ptr1, Ptr2, Len}, B, TLI);
1745}
1746
1748 const TargetLibraryInfo *TLI) {
1749 Type *CharPtrTy = Dst->getType();
1750 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1751 {Dst, Src}, B, TLI);
1752}
1753
1755 const TargetLibraryInfo *TLI) {
1756 Type *CharPtrTy = B.getPtrTy();
1757 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1758 {Dst, Src}, B, TLI);
1759}
1760
1762 const TargetLibraryInfo *TLI) {
1763 Type *CharPtrTy = B.getPtrTy();
1764 Type *SizeTTy = getSizeTTy(B, TLI);
1765 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1766 {Dst, Src, Len}, B, TLI);
1767}
1768
1770 const TargetLibraryInfo *TLI) {
1771 Type *CharPtrTy = B.getPtrTy();
1772 Type *SizeTTy = getSizeTTy(B, TLI);
1773 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1774 {Dst, Src, Len}, B, TLI);
1775}
1776
1777Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
1778 IRBuilderBase &B, const DataLayout &DL,
1779 const TargetLibraryInfo *TLI) {
1780 Module *M = B.getModule();
1781 if (!isLibFuncEmittable(M, TLI, LibFunc_memcpy_chk))
1782 return nullptr;
1783
1784 AttributeList AS;
1785 AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
1786 Attribute::NoUnwind);
1787 Type *VoidPtrTy = B.getPtrTy();
1788 Type *SizeTTy = getSizeTTy(B, TLI);
1789 FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
1790 AttributeList::get(M->getContext(), AS), VoidPtrTy,
1791 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1792 CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1793 if (const Function *F =
1795 CI->setCallingConv(F->getCallingConv());
1796 return CI;
1797}
1798
1800 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1801 Type *VoidPtrTy = B.getPtrTy();
1802 Type *SizeTTy = getSizeTTy(B, TLI);
1803 return emitLibCall(LibFunc_mempcpy, VoidPtrTy,
1804 {VoidPtrTy, VoidPtrTy, SizeTTy},
1805 {Dst, Src, Len}, B, TLI);
1806}
1807
1809 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1810 Type *VoidPtrTy = B.getPtrTy();
1811 Type *IntTy = getIntTy(B, TLI);
1812 Type *SizeTTy = getSizeTTy(B, TLI);
1813 return emitLibCall(LibFunc_memchr, VoidPtrTy,
1814 {VoidPtrTy, IntTy, SizeTTy},
1815 {Ptr, Val, Len}, B, TLI);
1816}
1817
1819 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1820 Type *VoidPtrTy = B.getPtrTy();
1821 Type *IntTy = getIntTy(B, TLI);
1822 Type *SizeTTy = getSizeTTy(B, TLI);
1823 return emitLibCall(LibFunc_memrchr, VoidPtrTy,
1824 {VoidPtrTy, IntTy, SizeTTy},
1825 {Ptr, Val, Len}, B, TLI);
1826}
1827
1829 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1830 Type *VoidPtrTy = B.getPtrTy();
1831 Type *IntTy = getIntTy(B, TLI);
1832 Type *SizeTTy = getSizeTTy(B, TLI);
1833 return emitLibCall(LibFunc_memcmp, IntTy,
1834 {VoidPtrTy, VoidPtrTy, SizeTTy},
1835 {Ptr1, Ptr2, Len}, B, TLI);
1836}
1837
1839 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1840 Type *VoidPtrTy = B.getPtrTy();
1841 Type *IntTy = getIntTy(B, TLI);
1842 Type *SizeTTy = getSizeTTy(B, TLI);
1843 return emitLibCall(LibFunc_bcmp, IntTy,
1844 {VoidPtrTy, VoidPtrTy, SizeTTy},
1845 {Ptr1, Ptr2, Len}, B, TLI);
1846}
1847
1848Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
1849 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1850 Type *VoidPtrTy = B.getPtrTy();
1851 Type *IntTy = getIntTy(B, TLI);
1852 Type *SizeTTy = getSizeTTy(B, TLI);
1853 return emitLibCall(LibFunc_memccpy, VoidPtrTy,
1854 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1855 {Ptr1, Ptr2, Val, Len}, B, TLI);
1856}
1857
1859 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1860 const TargetLibraryInfo *TLI) {
1861 Type *CharPtrTy = B.getPtrTy();
1862 Type *IntTy = getIntTy(B, TLI);
1863 Type *SizeTTy = getSizeTTy(B, TLI);
1864 SmallVector<Value *, 8> Args{Dest, Size, Fmt};
1865 llvm::append_range(Args, VariadicArgs);
1866 return emitLibCall(LibFunc_snprintf, IntTy,
1867 {CharPtrTy, SizeTTy, CharPtrTy},
1868 Args, B, TLI, /*IsVaArgs=*/true);
1869}
1870
1872 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1873 const TargetLibraryInfo *TLI) {
1874 Type *CharPtrTy = B.getPtrTy();
1875 Type *IntTy = getIntTy(B, TLI);
1876 SmallVector<Value *, 8> Args{Dest, Fmt};
1877 llvm::append_range(Args, VariadicArgs);
1878 return emitLibCall(LibFunc_sprintf, IntTy,
1879 {CharPtrTy, CharPtrTy}, Args, B, TLI,
1880 /*IsVaArgs=*/true);
1881}
1882
1884 const TargetLibraryInfo *TLI) {
1885 Type *CharPtrTy = B.getPtrTy();
1886 return emitLibCall(LibFunc_strcat, CharPtrTy,
1887 {CharPtrTy, CharPtrTy},
1888 {Dest, Src}, B, TLI);
1889}
1890
1892 const TargetLibraryInfo *TLI) {
1893 Type *CharPtrTy = B.getPtrTy();
1894 Type *SizeTTy = getSizeTTy(B, TLI);
1895 return emitLibCall(LibFunc_strlcpy, SizeTTy,
1896 {CharPtrTy, CharPtrTy, SizeTTy},
1897 {Dest, Src, Size}, B, TLI);
1898}
1899
1901 const TargetLibraryInfo *TLI) {
1902 Type *CharPtrTy = B.getPtrTy();
1903 Type *SizeTTy = getSizeTTy(B, TLI);
1904 return emitLibCall(LibFunc_strlcat, SizeTTy,
1905 {CharPtrTy, CharPtrTy, SizeTTy},
1906 {Dest, Src, Size}, B, TLI);
1907}
1908
1910 const TargetLibraryInfo *TLI) {
1911 Type *CharPtrTy = B.getPtrTy();
1912 Type *SizeTTy = getSizeTTy(B, TLI);
1913 return emitLibCall(LibFunc_strncat, CharPtrTy,
1914 {CharPtrTy, CharPtrTy, SizeTTy},
1915 {Dest, Src, Size}, B, TLI);
1916}
1917
1919 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1920 Type *CharPtrTy = B.getPtrTy();
1921 Type *IntTy = getIntTy(B, TLI);
1922 Type *SizeTTy = getSizeTTy(B, TLI);
1923 return emitLibCall(
1924 LibFunc_vsnprintf, IntTy,
1925 {CharPtrTy, SizeTTy, CharPtrTy, VAList->getType()},
1926 {Dest, Size, Fmt, VAList}, B, TLI);
1927}
1928
1930 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1931 Type *CharPtrTy = B.getPtrTy();
1932 Type *IntTy = getIntTy(B, TLI);
1933 return emitLibCall(LibFunc_vsprintf, IntTy,
1934 {CharPtrTy, CharPtrTy, VAList->getType()},
1935 {Dest, Fmt, VAList}, B, TLI);
1936}
1937
1938/// Append a suffix to the function name according to the type of 'Op'.
1940 SmallString<20> &NameBuffer) {
1941 if (!Op->getType()->isDoubleTy()) {
1942 NameBuffer += Name;
1943
1944 if (Op->getType()->isFloatTy())
1945 NameBuffer += 'f';
1946 else
1947 NameBuffer += 'l';
1948
1949 Name = NameBuffer;
1950 }
1951}
1952
1953static Value *emitUnaryFloatFnCallHelper(Value *Op, LibFunc TheLibFunc,
1954 StringRef Name, IRBuilderBase &B,
1955 const AttributeList &Attrs,
1956 const TargetLibraryInfo *TLI) {
1957 assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
1958
1959 Module *M = B.getModule();
1960 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op->getType(),
1961 Op->getType());
1962 CallInst *CI = B.CreateCall(Callee, Op, Name);
1963
1964 // The incoming attribute set may have come from a speculatable intrinsic, but
1965 // is being replaced with a library call which is not allowed to be
1966 // speculatable.
1967 CI->setAttributes(
1968 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1969 if (const Function *F =
1970 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1971 CI->setCallingConv(F->getCallingConv());
1972
1973 return CI;
1974}
1975
1977 StringRef Name, IRBuilderBase &B,
1978 const AttributeList &Attrs) {
1979 SmallString<20> NameBuffer;
1980 appendTypeSuffix(Op, Name, NameBuffer);
1981
1982 return emitUnaryFloatFnCallHelper(Op, TLI->getLibFunc(Name), Name, B, Attrs,
1983 TLI);
1984}
1985
1987 LibFunc DoubleFn, LibFunc FloatFn,
1988 LibFunc LongDoubleFn, IRBuilderBase &B,
1989 const AttributeList &Attrs) {
1990 // Get the name of the function according to TLI.
1991 Module *M = B.getModule();
1992 LibFunc TheLibFunc;
1993 StringRef Name = getFloatFn(M, TLI, Op->getType(), DoubleFn, FloatFn,
1994 LongDoubleFn, TheLibFunc);
1995
1996 return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1997}
1998
2000 LibFunc TheLibFunc,
2001 StringRef Name, IRBuilderBase &B,
2002 const AttributeList &Attrs,
2003 const TargetLibraryInfo *TLI) {
2004 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
2005
2006 Module *M = B.getModule();
2007 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op1->getType(),
2008 Op1->getType(), Op2->getType());
2009 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2010 CallInst *CI = B.CreateCall(Callee, { Op1, Op2 }, Name);
2011
2012 // The incoming attribute set may have come from a speculatable intrinsic, but
2013 // is being replaced with a library call which is not allowed to be
2014 // speculatable.
2015 CI->setAttributes(
2016 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
2017 if (const Function *F =
2018 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
2019 CI->setCallingConv(F->getCallingConv());
2020
2021 return CI;
2022}
2023
2025 const TargetLibraryInfo *TLI,
2026 StringRef Name, IRBuilderBase &B,
2027 const AttributeList &Attrs) {
2028 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
2029
2030 SmallString<20> NameBuffer;
2031 appendTypeSuffix(Op1, Name, NameBuffer);
2032
2033 return emitBinaryFloatFnCallHelper(Op1, Op2, TLI->getLibFunc(Name), Name, B,
2034 Attrs, TLI);
2035}
2036
2038 const TargetLibraryInfo *TLI,
2039 LibFunc DoubleFn, LibFunc FloatFn,
2040 LibFunc LongDoubleFn, IRBuilderBase &B,
2041 const AttributeList &Attrs) {
2042 // Get the name of the function according to TLI.
2043 Module *M = B.getModule();
2044 LibFunc TheLibFunc;
2045 StringRef Name = getFloatFn(M, TLI, Op1->getType(), DoubleFn, FloatFn,
2046 LongDoubleFn, TheLibFunc);
2047
2048 return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
2049}
2050
2051// Emit a call to putchar(int) with Char as the argument. Char must have
2052// the same precision as int, which need not be 32 bits.
2054 const TargetLibraryInfo *TLI) {
2055 Type *IntTy = getIntTy(B, TLI);
2056 return emitLibCall(LibFunc_putchar, IntTy, IntTy, Char, B, TLI);
2057}
2058
2060 const TargetLibraryInfo *TLI) {
2061 Type *IntTy = getIntTy(B, TLI);
2062 return emitLibCall(LibFunc_puts, IntTy, B.getPtrTy(), Str, B, TLI);
2063}
2064
2066 const TargetLibraryInfo *TLI) {
2067 Type *IntTy = getIntTy(B, TLI);
2068 return emitLibCall(LibFunc_fputc, IntTy, {IntTy, File->getType()},
2069 {Char, File}, B, TLI);
2070}
2071
2073 const TargetLibraryInfo *TLI) {
2074 Type *IntTy = getIntTy(B, TLI);
2075 return emitLibCall(LibFunc_fputs, IntTy, {B.getPtrTy(), File->getType()},
2076 {Str, File}, B, TLI);
2077}
2078
2080 const DataLayout &DL, const TargetLibraryInfo *TLI) {
2081 Type *SizeTTy = getSizeTTy(B, TLI);
2082 return emitLibCall(LibFunc_fwrite, SizeTTy,
2083 {B.getPtrTy(), SizeTTy, SizeTTy, File->getType()},
2084 {Ptr, Size, ConstantInt::get(SizeTTy, 1), File}, B, TLI);
2085}
2086
2088 const TargetLibraryInfo *TLI) {
2089 Type *SizeTTy = getSizeTTy(B, TLI);
2090 return emitLibCall(LibFunc_malloc, B.getPtrTy(), SizeTTy, Num, B, TLI);
2091}
2092
2094 const TargetLibraryInfo &TLI, unsigned AddrSpace) {
2095 Type *SizeTTy = getSizeTTy(B, &TLI);
2096 return emitLibCall(LibFunc_calloc, B.getPtrTy(AddrSpace), {SizeTTy, SizeTTy},
2097 {Num, Size}, B, &TLI);
2098}
2099
2101 const TargetLibraryInfo *TLI,
2102 LibFunc SizeFeedbackNewFunc,
2103 Value *HotCold) {
2104 Module *M = B.getModule();
2105 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2106 return nullptr;
2107
2108 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2109
2110 // __sized_ptr_t struct return type { void*, size_t }
2111 StructType *SizedPtrT =
2112 StructType::get(M->getContext(), {B.getPtrTy(), Num->getType()});
2114 M, *TLI, SizeFeedbackNewFunc, SizedPtrT, Num->getType(), B.getInt8Ty());
2115 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2116 CallInst *CI = B.CreateCall(Func, {Num, HotCold}, "sized_ptr");
2117
2118 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2119 CI->setCallingConv(F->getCallingConv());
2120
2121 return CI;
2122}
2123
2126 const TargetLibraryInfo *TLI,
2127 LibFunc SizeFeedbackNewFunc,
2128 Value *HotCold) {
2129 Module *M = B.getModule();
2130 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2131 return nullptr;
2132
2133 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2134
2135 // __sized_ptr_t struct return type { void*, size_t }
2136 StructType *SizedPtrT =
2137 StructType::get(M->getContext(), {B.getPtrTy(), Num->getType()});
2138 FunctionCallee Func =
2139 getOrInsertLibFunc(M, *TLI, SizeFeedbackNewFunc, SizedPtrT,
2140 Num->getType(), Align->getType(), B.getInt8Ty());
2141 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2142 CallInst *CI = B.CreateCall(Func, {Num, Align, HotCold}, "sized_ptr");
2143
2144 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2145 CI->setCallingConv(F->getCallingConv());
2146
2147 return CI;
2148}
2149
2151 const TargetLibraryInfo *TLI, LibFunc NewFunc,
2152 Value *HotCold) {
2153 Module *M = B.getModule();
2154 if (!isLibFuncEmittable(M, TLI, NewFunc))
2155 return nullptr;
2156
2157 StringRef Name = TLI->getName(NewFunc);
2158 FunctionCallee Func = getOrInsertLibFunc(M, *TLI, NewFunc, B.getPtrTy(),
2159 Num->getType(), B.getInt8Ty());
2160 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2161 CallInst *CI = B.CreateCall(Func, {Num, HotCold}, Name);
2162
2163 if (const Function *F =
2164 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2165 CI->setCallingConv(F->getCallingConv());
2166
2167 return CI;
2168}
2169
2171 const TargetLibraryInfo *TLI,
2172 LibFunc NewFunc, Value *HotCold) {
2173 Module *M = B.getModule();
2174 if (!isLibFuncEmittable(M, TLI, NewFunc))
2175 return nullptr;
2176
2177 StringRef Name = TLI->getName(NewFunc);
2178 FunctionCallee Func =
2179 getOrInsertLibFunc(M, *TLI, NewFunc, B.getPtrTy(), Num->getType(),
2180 NoThrow->getType(), B.getInt8Ty());
2181 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2182 CallInst *CI = B.CreateCall(Func, {Num, NoThrow, HotCold}, Name);
2183
2184 if (const Function *F =
2185 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2186 CI->setCallingConv(F->getCallingConv());
2187
2188 return CI;
2189}
2190
2192 const TargetLibraryInfo *TLI,
2193 LibFunc NewFunc, Value *HotCold) {
2194 Module *M = B.getModule();
2195 if (!isLibFuncEmittable(M, TLI, NewFunc))
2196 return nullptr;
2197
2198 StringRef Name = TLI->getName(NewFunc);
2199 FunctionCallee Func =
2200 getOrInsertLibFunc(M, *TLI, NewFunc, B.getPtrTy(), Num->getType(),
2201 Align->getType(), B.getInt8Ty());
2202 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2203 CallInst *CI = B.CreateCall(Func, {Num, Align, HotCold}, Name);
2204
2205 if (const Function *F =
2206 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2207 CI->setCallingConv(F->getCallingConv());
2208
2209 return CI;
2210}
2211
2213 Value *NoThrow, IRBuilderBase &B,
2214 const TargetLibraryInfo *TLI,
2215 LibFunc NewFunc, Value *HotCold) {
2216 Module *M = B.getModule();
2217 if (!isLibFuncEmittable(M, TLI, NewFunc))
2218 return nullptr;
2219
2220 StringRef Name = TLI->getName(NewFunc);
2221 FunctionCallee Func =
2222 getOrInsertLibFunc(M, *TLI, NewFunc, B.getPtrTy(), Num->getType(),
2223 Align->getType(), NoThrow->getType(), B.getInt8Ty());
2224 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2225 CallInst *CI = B.CreateCall(Func, {Num, Align, NoThrow, HotCold}, Name);
2226
2227 if (const Function *F =
2228 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2229 CI->setCallingConv(F->getCallingConv());
2230
2231 return CI;
2232}
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
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
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.
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
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