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;
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 case LibFunc_dunder_strndup:
479 Changed |= setArgNoUndef(F, 1);
480 [[fallthrough]];
481 case LibFunc_strdup:
482 case LibFunc_dunder_strdup:
483 Changed |= setAllocFamily(F, "malloc");
491 break;
492 case LibFunc_stat:
493 case LibFunc_statvfs:
499 break;
500 case LibFunc_sscanf:
507 break;
508 case LibFunc_sprintf:
516 break;
517 case LibFunc_snprintf:
525 break;
526 case LibFunc_setitimer:
533 break;
534 case LibFunc_system:
535 // May throw; "system" is a valid pthread cancellation point.
539 break;
540 case LibFunc_posix_memalign:
547 break;
548 case LibFunc_aligned_alloc:
550 Changed |= setAllocSize(F, 1, std::nullopt);
552 [[fallthrough]];
553 case LibFunc_valloc:
554 case LibFunc_malloc:
555 case LibFunc_vec_malloc:
556 Changed |= setAllocSize(F, 0, std::nullopt);
557 [[fallthrough]];
558 case LibFunc_pvalloc:
559 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_malloc ? "vec_malloc"
560 : "malloc");
567 break;
568 case LibFunc_memcmp:
577 break;
578 case LibFunc_memchr:
579 case LibFunc_memrchr:
586 break;
587 case LibFunc_modf:
588 case LibFunc_modff:
589 case LibFunc_modfl:
597 break;
598 case LibFunc_memcpy:
604 Changed |= setReturnedArg(F, 0);
610 break;
611 case LibFunc_memmove:
616 Changed |= setReturnedArg(F, 0);
621 break;
622 case LibFunc_mempcpy:
623 case LibFunc_memccpy:
625 [[fallthrough]];
626 case LibFunc_memcpy_chk:
636 break;
637 case LibFunc_memalign:
638 Changed |= setAllocFamily(F, "malloc");
641 Changed |= setAllocSize(F, 1, std::nullopt);
648 break;
649 case LibFunc_mkdir:
654 break;
655 case LibFunc_mktime:
660 break;
661 case LibFunc_realloc:
662 case LibFunc_reallocf:
663 case LibFunc_vec_realloc:
665 F, TheLibFunc == LibFunc_vec_realloc ? "vec_malloc" : "malloc");
668 Changed |= setAllocSize(F, 1, std::nullopt);
675 Changed |= setArgNoUndef(F, 1);
676 break;
677 case LibFunc_reallocarray:
678 Changed |= setAllocFamily(F, "malloc");
681 Changed |= setAllocSize(F, 1, 2);
688 Changed |= setArgNoUndef(F, 1);
689 Changed |= setArgNoUndef(F, 2);
690 break;
691 case LibFunc_read:
692 // May throw; "read" is a valid pthread cancellation point.
695 break;
696 case LibFunc_rewind:
700 break;
701 case LibFunc_rmdir:
702 case LibFunc_remove:
703 case LibFunc_realpath:
708 break;
709 case LibFunc_rename:
716 break;
717 case LibFunc_readlink:
723 break;
724 case LibFunc_write:
725 // May throw; "write" is a valid pthread cancellation point.
729 break;
730 case LibFunc_bcopy:
740 break;
741 case LibFunc_bcmp:
750 break;
751 case LibFunc_bzero:
759 break;
760 case LibFunc_calloc:
761 case LibFunc_vec_calloc:
762 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_calloc ? "vec_malloc"
763 : "malloc");
765 Changed |= setAllocSize(F, 0, 1);
771 break;
772 case LibFunc_cheriot_heap_allocate:
773 Changed |= setAllocFamily(F, "cheriot_heap_allocate");
775 Changed |= setAllocSize(F, 2, std::nullopt);
777 break;
778 case LibFunc_cheriot_heap_free:
779 Changed |= setAllocFamily(F, "cheriot_heap_allocate");
782 break;
783 case LibFunc_chmod:
784 case LibFunc_chown:
789 break;
790 case LibFunc_ctermid:
793 break;
794 case LibFunc_clearerr:
795 case LibFunc_closedir:
799 break;
800 case LibFunc_atoi:
801 case LibFunc_atol:
802 case LibFunc_atof:
803 case LibFunc_atoll:
810 break;
811 case LibFunc_access:
816 break;
817 case LibFunc_fopen:
825 break;
826 case LibFunc_fdopen:
832 break;
833 case LibFunc_feof:
837 break;
838 case LibFunc_free:
839 case LibFunc_vec_free:
840 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_free ? "vec_malloc"
841 : "malloc");
849 break;
850 case LibFunc_fseek:
851 case LibFunc_ftell:
852 case LibFunc_fgetc:
853 case LibFunc_fgetc_unlocked:
854 case LibFunc_fseeko:
855 case LibFunc_ftello:
856 case LibFunc_fileno:
857 case LibFunc_fflush:
858 case LibFunc_fclose:
859 case LibFunc_fsetpos:
860 case LibFunc_flockfile:
861 case LibFunc_funlockfile:
862 case LibFunc_ftrylockfile:
866 break;
867 case LibFunc_ferror:
872 break;
873 case LibFunc_fputc:
874 case LibFunc_fputc_unlocked:
875 case LibFunc_fstat:
879 break;
880 case LibFunc_frexp:
881 case LibFunc_frexpf:
882 case LibFunc_frexpl:
890 break;
891 case LibFunc_fstatvfs:
895 break;
896 case LibFunc_fgets:
897 case LibFunc_fgets_unlocked:
902 break;
903 case LibFunc_fread:
904 case LibFunc_fread_unlocked:
910 break;
911 case LibFunc_fwrite:
912 case LibFunc_fwrite_unlocked:
918 break;
919 case LibFunc_fputs:
920 case LibFunc_fputs_unlocked:
926 break;
927 case LibFunc_fscanf:
928 case LibFunc_fprintf:
934 break;
935 case LibFunc_fgetpos:
940 break;
941 case LibFunc_getc:
945 break;
946 case LibFunc_getlogin_r:
950 break;
951 case LibFunc_getc_unlocked:
955 break;
956 case LibFunc_getenv:
961 break;
962 case LibFunc_gets:
963 case LibFunc_getchar:
964 case LibFunc_getchar_unlocked:
967 break;
968 case LibFunc_getitimer:
972 break;
973 case LibFunc_getpwnam:
978 break;
979 case LibFunc_ungetc:
983 break;
984 case LibFunc_uname:
988 break;
989 case LibFunc_unlink:
994 break;
995 case LibFunc_unsetenv:
1000 break;
1001 case LibFunc_utime:
1002 case LibFunc_utimes:
1009 break;
1010 case LibFunc_putc:
1011 case LibFunc_putc_unlocked:
1015 break;
1016 case LibFunc_puts:
1017 case LibFunc_printf:
1018 case LibFunc_perror:
1023 break;
1024 case LibFunc_pread:
1025 // May throw; "pread" is a valid pthread cancellation point.
1028 break;
1029 case LibFunc_pwrite:
1030 // May throw; "pwrite" is a valid pthread cancellation point.
1034 break;
1035 case LibFunc_putchar:
1036 case LibFunc_putchar_unlocked:
1039 break;
1040 case LibFunc_popen:
1048 break;
1049 case LibFunc_pclose:
1053 break;
1054 case LibFunc_vscanf:
1059 break;
1060 case LibFunc_vsscanf:
1067 break;
1068 case LibFunc_vfscanf:
1074 break;
1075 case LibFunc_vprintf:
1080 break;
1081 case LibFunc_vfprintf:
1082 case LibFunc_vsprintf:
1088 break;
1089 case LibFunc_vsnprintf:
1095 break;
1096 case LibFunc_open:
1097 // May throw; "open" is a valid pthread cancellation point.
1101 break;
1102 case LibFunc_opendir:
1108 break;
1109 case LibFunc_tmpfile:
1113 break;
1114 case LibFunc_times:
1118 break;
1119 case LibFunc_htonl:
1120 case LibFunc_htons:
1121 case LibFunc_ntohl:
1122 case LibFunc_ntohs:
1126 break;
1127 case LibFunc_lstat:
1133 break;
1134 case LibFunc_lchown:
1139 break;
1140 case LibFunc_qsort:
1141 // May throw/callback; places call through function pointer.
1142 // Cannot give undef pointer/size
1145 break;
1146 case LibFunc_dunder_strtok_r:
1151 break;
1152 case LibFunc_under_IO_getc:
1156 break;
1157 case LibFunc_under_IO_putc:
1161 break;
1162 case LibFunc_dunder_isoc99_scanf:
1167 break;
1168 case LibFunc_stat64:
1169 case LibFunc_lstat64:
1170 case LibFunc_statvfs64:
1176 break;
1177 case LibFunc_dunder_isoc99_sscanf:
1184 break;
1185 case LibFunc_fopen64:
1193 break;
1194 case LibFunc_fseeko64:
1195 case LibFunc_ftello64:
1199 break;
1200 case LibFunc_tmpfile64:
1204 break;
1205 case LibFunc_fstat64:
1206 case LibFunc_fstatvfs64:
1210 break;
1211 case LibFunc_open64:
1212 // May throw; "open" is a valid pthread cancellation point.
1216 break;
1217 case LibFunc_gettimeofday:
1218 // Currently some platforms have the restrict keyword on the arguments to
1219 // gettimeofday. To be conservative, do not add noalias to gettimeofday's
1220 // arguments.
1225 break;
1226 case LibFunc_memset_pattern4:
1227 case LibFunc_memset_pattern8:
1228 case LibFunc_memset_pattern16:
1232 [[fallthrough]];
1233 case LibFunc_memset:
1235 [[fallthrough]];
1236 case LibFunc_memset_chk:
1242 break;
1243 case LibFunc_abort:
1244 Changed |= setIsCold(F);
1245 Changed |= setNoReturn(F);
1247 break;
1248 case LibFunc_terminate:
1249 // May callback; terminate_handler may be called
1250 Changed |= setIsCold(F);
1251 Changed |= setNoReturn(F);
1252 break;
1253 case LibFunc_cxa_throw:
1254 Changed |= setIsCold(F);
1255 Changed |= setNoReturn(F);
1256 // Don't add `nofree` on `__cxa_throw`
1257 return Changed;
1258 // int __nvvm_reflect(const char *)
1259 case LibFunc_nvvm_reflect:
1263 break;
1264 case LibFunc_acos:
1265 case LibFunc_acosf:
1266 case LibFunc_acosh:
1267 case LibFunc_acoshf:
1268 case LibFunc_acoshl:
1269 case LibFunc_acosl:
1270 case LibFunc_asin:
1271 case LibFunc_asinf:
1272 case LibFunc_asinh:
1273 case LibFunc_asinhf:
1274 case LibFunc_asinhl:
1275 case LibFunc_asinl:
1276 case LibFunc_atan:
1277 case LibFunc_atan2:
1278 case LibFunc_atan2f:
1279 case LibFunc_atan2l:
1280 case LibFunc_atanf:
1281 case LibFunc_atanh:
1282 case LibFunc_atanhf:
1283 case LibFunc_atanhl:
1284 case LibFunc_atanl:
1285 case LibFunc_cos:
1286 case LibFunc_cosh:
1287 case LibFunc_coshf:
1288 case LibFunc_coshl:
1289 case LibFunc_cosf:
1290 case LibFunc_cosl:
1291 case LibFunc_cospi:
1292 case LibFunc_cospif:
1293 case LibFunc_erf:
1294 case LibFunc_erff:
1295 case LibFunc_erfl:
1296 case LibFunc_tgamma:
1297 case LibFunc_tgammaf:
1298 case LibFunc_tgammal:
1299 case LibFunc_exp:
1300 case LibFunc_expf:
1301 case LibFunc_expl:
1302 case LibFunc_exp2:
1303 case LibFunc_exp2f:
1304 case LibFunc_exp2l:
1305 case LibFunc_expm1:
1306 case LibFunc_expm1f:
1307 case LibFunc_expm1l:
1308 case LibFunc_fdim:
1309 case LibFunc_fdiml:
1310 case LibFunc_fdimf:
1311 case LibFunc_fmod:
1312 case LibFunc_fmodf:
1313 case LibFunc_fmodl:
1314 case LibFunc_hypot:
1315 case LibFunc_hypotf:
1316 case LibFunc_hypotl:
1317 case LibFunc_ldexp:
1318 case LibFunc_ldexpf:
1319 case LibFunc_ldexpl:
1320 case LibFunc_log:
1321 case LibFunc_log10:
1322 case LibFunc_log10f:
1323 case LibFunc_log10l:
1324 case LibFunc_log1p:
1325 case LibFunc_log1pf:
1326 case LibFunc_log1pl:
1327 case LibFunc_log2:
1328 case LibFunc_log2f:
1329 case LibFunc_log2l:
1330 case LibFunc_logb:
1331 case LibFunc_logbf:
1332 case LibFunc_logbl:
1333 case LibFunc_ilogb:
1334 case LibFunc_ilogbf:
1335 case LibFunc_ilogbl:
1336 case LibFunc_logf:
1337 case LibFunc_logl:
1338 case LibFunc_nextafter:
1339 case LibFunc_nextafterf:
1340 case LibFunc_nextafterl:
1341 case LibFunc_nexttoward:
1342 case LibFunc_nexttowardf:
1343 case LibFunc_nexttowardl:
1344 case LibFunc_pow:
1345 case LibFunc_powf:
1346 case LibFunc_powl:
1347 case LibFunc_remainder:
1348 case LibFunc_remainderf:
1349 case LibFunc_remainderl:
1350 case LibFunc_rint:
1351 case LibFunc_rintf:
1352 case LibFunc_rintl:
1353 case LibFunc_scalbln:
1354 case LibFunc_scalblnf:
1355 case LibFunc_scalblnl:
1356 case LibFunc_scalbn:
1357 case LibFunc_scalbnf:
1358 case LibFunc_scalbnl:
1359 case LibFunc_sin:
1360 case LibFunc_sinf:
1361 case LibFunc_sinh:
1362 case LibFunc_sinhf:
1363 case LibFunc_sinhl:
1364 case LibFunc_sinl:
1365 case LibFunc_sinpi:
1366 case LibFunc_sinpif:
1367 case LibFunc_sqrt:
1368 case LibFunc_sqrtf:
1369 case LibFunc_sqrtl:
1370 case LibFunc_tan:
1371 case LibFunc_tanf:
1372 case LibFunc_tanh:
1373 case LibFunc_tanhf:
1374 case LibFunc_tanhl:
1375 case LibFunc_tanl:
1382 break;
1383 case LibFunc_abs:
1384 case LibFunc_cbrt:
1385 case LibFunc_cbrtf:
1386 case LibFunc_cbrtl:
1387 case LibFunc_copysign:
1388 case LibFunc_copysignf:
1389 case LibFunc_copysignl:
1390 case LibFunc_ceil:
1391 case LibFunc_ceilf:
1392 case LibFunc_ceill:
1393 case LibFunc_fabs:
1394 case LibFunc_fabsf:
1395 case LibFunc_fabsl:
1396 case LibFunc_ffs:
1397 case LibFunc_ffsl:
1398 case LibFunc_ffsll:
1399 case LibFunc_floor:
1400 case LibFunc_floorf:
1401 case LibFunc_floorl:
1402 case LibFunc_fls:
1403 case LibFunc_flsl:
1404 case LibFunc_flsll:
1405 case LibFunc_fmax:
1406 case LibFunc_fmaxf:
1407 case LibFunc_fmaxl:
1408 case LibFunc_fmin:
1409 case LibFunc_fminf:
1410 case LibFunc_fminl:
1411 case LibFunc_fmaximum_num:
1412 case LibFunc_fmaximum_numf:
1413 case LibFunc_fmaximum_numl:
1414 case LibFunc_fminimum_num:
1415 case LibFunc_fminimum_numf:
1416 case LibFunc_fminimum_numl:
1417 case LibFunc_labs:
1418 case LibFunc_llabs:
1419 case LibFunc_nearbyint:
1420 case LibFunc_nearbyintf:
1421 case LibFunc_nearbyintl:
1422 case LibFunc_round:
1423 case LibFunc_roundf:
1424 case LibFunc_roundl:
1425 case LibFunc_roundeven:
1426 case LibFunc_roundevenf:
1427 case LibFunc_roundevenl:
1428 case LibFunc_sincos_stret:
1429 case LibFunc_sincosf_stret:
1430 case LibFunc_sincospi_stret:
1431 case LibFunc_sincospif_stret:
1432 case LibFunc_toascii:
1433 case LibFunc_trunc:
1434 case LibFunc_truncf:
1435 case LibFunc_truncl:
1437 [[fallthrough]];
1438 case LibFunc_isascii:
1439 case LibFunc_isdigit:
1444 break;
1445 case LibFunc_sincos:
1446 case LibFunc_sincosf:
1447 case LibFunc_sincosl:
1450 [[fallthrough]];
1451 case LibFunc_remquo:
1452 case LibFunc_remquof:
1453 case LibFunc_remquol:
1462 break;
1463 default:
1464 // FIXME: It'd be really nice to cover all the library functions we're
1465 // aware of here.
1466 break;
1467 }
1468 // We have to do this step after AllocKind has been inferred on functions so
1469 // we can reliably identify free-like and realloc-like functions.
1470 if (!isFreeLikeFn(&F) && !isReallocLikeFn(&F))
1472 return Changed;
1473}
1474
1475static void setI8ArgExtAttr(Function &F, unsigned ArgNo,
1476 const TargetLibraryInfo &TLI, bool Signed = true) {
1477 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI8Param(Signed);
1478 if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr))
1479 F.addParamAttr(ArgNo, ExtAttr);
1480}
1481
1482static void setArgExtAttr(Function &F, unsigned ArgNo,
1483 const TargetLibraryInfo &TLI, bool Signed = true) {
1484 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Param(Signed);
1485 if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr))
1486 F.addParamAttr(ArgNo, ExtAttr);
1487}
1488
1490 const TargetLibraryInfo &TLI, bool Signed = true) {
1491 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Return(Signed);
1492 if (ExtAttr != Attribute::None && !F.hasRetAttribute(ExtAttr))
1493 F.addRetAttr(ExtAttr);
1494}
1495
1496// Modeled after X86TargetLowering::markLibCallAttributes.
1498 if (!F->arg_size() || F->isVarArg())
1499 return;
1500
1501 const CallingConv::ID CC = F->getCallingConv();
1503 return;
1504
1505 const Module *M = F->getParent();
1506 unsigned N = M->getNumberRegisterParameters();
1507 if (!N)
1508 return;
1509
1510 const DataLayout &DL = M->getDataLayout();
1511
1512 for (Argument &A : F->args()) {
1513 Type *T = A.getType();
1514 if (!T->isIntOrPtrTy())
1515 continue;
1516
1517 const TypeSize &TS = DL.getTypeAllocSize(T);
1518 if (TS > 8)
1519 continue;
1520
1521 assert(TS <= 4 && "Need to account for parameters larger than word size");
1522 const unsigned NumRegs = TS > 4 ? 2 : 1;
1523 if (N < NumRegs)
1524 return;
1525
1526 N -= NumRegs;
1527 F->addParamAttr(A.getArgNo(), Attribute::InReg);
1528 }
1529}
1530
1532 LibFunc TheLibFunc, FunctionType *T,
1534 assert(TLI.has(TheLibFunc) &&
1535 "Creating call to non-existing library function.");
1536 StringRef Name = TLI.getName(TheLibFunc);
1537 FunctionCallee C = M->getOrInsertFunction(Name, T, AttributeList);
1538
1539 // Make sure any mandatory argument attributes are added.
1540
1541 // Any outgoing i32 argument should be handled with setArgExtAttr() which
1542 // will add an extension attribute if the target ABI requires it. Adding
1543 // argument extensions is typically done by the front end but when an
1544 // optimizer is building a library call on its own it has to take care of
1545 // this. Each such generated function must be handled here with sign or
1546 // zero extensions as needed. F is retreived with cast<> because we demand
1547 // of the caller to have called isLibFuncEmittable() first.
1548 Function *F = cast<Function>(C.getCallee());
1549 assert(F->getFunctionType() == T && "Function type does not match.");
1550 switch (TheLibFunc) {
1551 case LibFunc_fputc:
1552 case LibFunc_putchar:
1553 setArgExtAttr(*F, 0, TLI);
1554 break;
1555 case LibFunc_ldexp:
1556 case LibFunc_ldexpf:
1557 case LibFunc_ldexpl:
1558 case LibFunc_memchr:
1559 case LibFunc_memrchr:
1560 case LibFunc_strchr:
1561 setArgExtAttr(*F, 1, TLI);
1562 break;
1563 case LibFunc_memccpy:
1564 setArgExtAttr(*F, 2, TLI);
1565 break;
1566
1567 // The last argument of the hot-cold operator new variants is an i8
1568 // __hot_cold_t hint.
1569 case LibFunc_Znwm12__hot_cold_t:
1570 case LibFunc_Znam12__hot_cold_t:
1571 case LibFunc_size_returning_new_hot_cold:
1572 setI8ArgExtAttr(*F, 1, TLI, /*Signed=*/false);
1573 break;
1574 case LibFunc_ZnwmRKSt9nothrow_t12__hot_cold_t:
1575 case LibFunc_ZnamRKSt9nothrow_t12__hot_cold_t:
1576 case LibFunc_ZnwmSt11align_val_t12__hot_cold_t:
1577 case LibFunc_ZnamSt11align_val_t12__hot_cold_t:
1578 case LibFunc_size_returning_new_aligned_hot_cold:
1579 setI8ArgExtAttr(*F, 2, TLI, /*Signed=*/false);
1580 break;
1581 case LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1582 case LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t:
1583 setI8ArgExtAttr(*F, 3, TLI, /*Signed=*/false);
1584 break;
1585
1586 // These are functions that are known to not need any argument extension
1587 // on any target: A size_t argument (which may be an i32 on some targets)
1588 // should not trigger the assert below.
1589 case LibFunc_bcmp:
1590 setRetExtAttr(*F, TLI);
1591 break;
1592 case LibFunc_calloc:
1593 case LibFunc_fwrite:
1594 case LibFunc_malloc:
1595 case LibFunc_memcmp:
1596 case LibFunc_memcpy_chk:
1597 case LibFunc_mempcpy:
1598 case LibFunc_memset_pattern16:
1599 case LibFunc_snprintf:
1600 case LibFunc_stpncpy:
1601 case LibFunc_strlcat:
1602 case LibFunc_strlcpy:
1603 case LibFunc_strncat:
1604 case LibFunc_strncmp:
1605 case LibFunc_strncpy:
1606 case LibFunc_vsnprintf:
1607 break;
1608
1609 default:
1610#ifndef NDEBUG
1611 for (unsigned i = 0; i < T->getNumParams(); i++)
1612 assert(!isa<IntegerType>(T->getParamType(i)) &&
1613 "Unhandled integer argument.");
1614#endif
1615 break;
1616 }
1617
1619
1620 return C;
1621}
1622
1624 LibFunc TheLibFunc, FunctionType *T) {
1625 return getOrInsertLibFunc(M, TLI, TheLibFunc, T, AttributeList());
1626}
1627
1629 LibFunc TheLibFunc) {
1630 StringRef FuncName = TLI->getName(TheLibFunc);
1631 if (!TLI->has(TheLibFunc))
1632 return false;
1633
1634 // Check if the Module already has a GlobalValue with the same name, in
1635 // which case it must be a Function with the expected type.
1636 if (GlobalValue *GV = M->getNamedValue(FuncName)) {
1637 if (auto *F = dyn_cast<Function>(GV))
1638 return TLI->isValidProtoForLibFunc(*F->getFunctionType(), TheLibFunc, *M);
1639 return false;
1640 }
1641
1642 return true;
1643}
1644
1646 StringRef Name) {
1647 return isLibFuncEmittable(M, TLI, TLI->getLibFunc(Name));
1648}
1649
1651 LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
1652 switch (Ty->getTypeID()) {
1653 case Type::HalfTyID:
1654 return false;
1655 case Type::FloatTyID:
1656 return isLibFuncEmittable(M, TLI, FloatFn);
1657 case Type::DoubleTyID:
1658 return isLibFuncEmittable(M, TLI, DoubleFn);
1659 default:
1660 return isLibFuncEmittable(M, TLI, LongDoubleFn);
1661 }
1662}
1663
1665 Type *Ty, LibFunc DoubleFn, LibFunc FloatFn,
1666 LibFunc LongDoubleFn, LibFunc &TheLibFunc) {
1667 assert(hasFloatFn(M, TLI, Ty, DoubleFn, FloatFn, LongDoubleFn) &&
1668 "Cannot get name for unavailable function!");
1669
1670 switch (Ty->getTypeID()) {
1671 case Type::HalfTyID:
1672 llvm_unreachable("No name for HalfTy!");
1673 case Type::FloatTyID:
1674 TheLibFunc = FloatFn;
1675 return TLI->getName(FloatFn);
1676 case Type::DoubleTyID:
1677 TheLibFunc = DoubleFn;
1678 return TLI->getName(DoubleFn);
1679 default:
1680 TheLibFunc = LongDoubleFn;
1681 return TLI->getName(LongDoubleFn);
1682 }
1683}
1684
1685//- Emit LibCalls ------------------------------------------------------------//
1686
1688 return B.getIntNTy(TLI->getIntSize());
1689}
1690
1692 const Module *M = B.getModule();
1693 return B.getIntNTy(TLI->getSizeTSize(*M));
1694}
1695
1696static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
1697 ArrayRef<Type *> ParamTypes,
1699 const TargetLibraryInfo *TLI,
1700 bool IsVaArgs = false) {
1701 Module *M = B.getModule();
1702 if (!isLibFuncEmittable(M, TLI, TheLibFunc))
1703 return nullptr;
1704
1705 StringRef FuncName = TLI->getName(TheLibFunc);
1706 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1707 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, FuncType);
1708 inferNonMandatoryLibFuncAttrs(M, FuncName, *TLI);
1709 CallInst *CI = B.CreateCall(Callee, Operands, FuncName);
1710 if (const Function *F =
1711 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1712 CI->setCallingConv(F->getCallingConv());
1713 return CI;
1714}
1715
1717 const TargetLibraryInfo *TLI) {
1718 Type *CharPtrTy = B.getPtrTy();
1719 Type *SizeTTy = getSizeTTy(B, TLI);
1720 return emitLibCall(LibFunc_strlen, SizeTTy, CharPtrTy, Ptr, B, TLI);
1721}
1722
1724 const TargetLibraryInfo *TLI) {
1725 assert(Ptr && Ptr->getType()->isPointerTy() &&
1726 "Argument to wcslen intrinsic must be a pointer.");
1727 Type *PtrTy = B.getPtrTy();
1728 Type *SizeTTy = getSizeTTy(B, TLI);
1729 return emitLibCall(LibFunc_wcslen, SizeTTy, PtrTy, Ptr, B, TLI);
1730}
1731
1733 const TargetLibraryInfo *TLI) {
1734 Type *CharPtrTy = B.getPtrTy();
1735 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy, Ptr, B, TLI);
1736}
1737
1739 const TargetLibraryInfo *TLI) {
1740 Type *CharPtrTy = B.getPtrTy();
1741 Type *IntTy = getIntTy(B, TLI);
1742 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1743 {Ptr, ConstantInt::get(IntTy, (unsigned char)C)}, B, TLI);
1744}
1745
1747 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1748 Type *CharPtrTy = B.getPtrTy();
1749 Type *IntTy = getIntTy(B, TLI);
1750 Type *SizeTTy = getSizeTTy(B, TLI);
1751 return emitLibCall(
1752 LibFunc_strncmp, IntTy,
1753 {CharPtrTy, CharPtrTy, SizeTTy},
1754 {Ptr1, Ptr2, Len}, B, TLI);
1755}
1756
1758 const TargetLibraryInfo *TLI) {
1759 Type *CharPtrTy = Dst->getType();
1760 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1761 {Dst, Src}, B, TLI);
1762}
1763
1765 const TargetLibraryInfo *TLI) {
1766 Type *CharPtrTy = B.getPtrTy();
1767 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1768 {Dst, Src}, B, TLI);
1769}
1770
1772 const TargetLibraryInfo *TLI) {
1773 Type *CharPtrTy = B.getPtrTy();
1774 Type *SizeTTy = getSizeTTy(B, TLI);
1775 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1776 {Dst, Src, Len}, B, TLI);
1777}
1778
1780 const TargetLibraryInfo *TLI) {
1781 Type *CharPtrTy = B.getPtrTy();
1782 Type *SizeTTy = getSizeTTy(B, TLI);
1783 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1784 {Dst, Src, Len}, B, TLI);
1785}
1786
1787Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
1788 IRBuilderBase &B, const DataLayout &DL,
1789 const TargetLibraryInfo *TLI) {
1790 Module *M = B.getModule();
1791 if (!isLibFuncEmittable(M, TLI, LibFunc_memcpy_chk))
1792 return nullptr;
1793
1794 AttributeList AS;
1795 AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
1796 Attribute::NoUnwind);
1797 Type *VoidPtrTy = B.getPtrTy();
1798 Type *SizeTTy = getSizeTTy(B, TLI);
1799 FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
1800 AttributeList::get(M->getContext(), AS), VoidPtrTy,
1801 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1802 CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1803 if (const Function *F =
1805 CI->setCallingConv(F->getCallingConv());
1806 return CI;
1807}
1808
1810 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1811 Type *VoidPtrTy = B.getPtrTy();
1812 Type *SizeTTy = getSizeTTy(B, TLI);
1813 return emitLibCall(LibFunc_mempcpy, VoidPtrTy,
1814 {VoidPtrTy, VoidPtrTy, SizeTTy},
1815 {Dst, Src, 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_memchr, 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_memrchr, VoidPtrTy,
1834 {VoidPtrTy, IntTy, SizeTTy},
1835 {Ptr, Val, 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_memcmp, IntTy,
1844 {VoidPtrTy, VoidPtrTy, SizeTTy},
1845 {Ptr1, Ptr2, Len}, B, TLI);
1846}
1847
1849 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1850 Type *VoidPtrTy = B.getPtrTy();
1851 Type *IntTy = getIntTy(B, TLI);
1852 Type *SizeTTy = getSizeTTy(B, TLI);
1853 return emitLibCall(LibFunc_bcmp, IntTy,
1854 {VoidPtrTy, VoidPtrTy, SizeTTy},
1855 {Ptr1, Ptr2, Len}, B, TLI);
1856}
1857
1858Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
1860 Type *VoidPtrTy = B.getPtrTy();
1861 Type *IntTy = getIntTy(B, TLI);
1862 Type *SizeTTy = getSizeTTy(B, TLI);
1863 return emitLibCall(LibFunc_memccpy, VoidPtrTy,
1864 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1865 {Ptr1, Ptr2, Val, Len}, B, TLI);
1866}
1867
1869 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1870 const TargetLibraryInfo *TLI) {
1871 Type *CharPtrTy = B.getPtrTy();
1872 Type *IntTy = getIntTy(B, TLI);
1873 Type *SizeTTy = getSizeTTy(B, TLI);
1874 SmallVector<Value *, 8> Args{Dest, Size, Fmt};
1875 llvm::append_range(Args, VariadicArgs);
1876 return emitLibCall(LibFunc_snprintf, IntTy,
1877 {CharPtrTy, SizeTTy, CharPtrTy},
1878 Args, B, TLI, /*IsVaArgs=*/true);
1879}
1880
1882 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1883 const TargetLibraryInfo *TLI) {
1884 Type *CharPtrTy = B.getPtrTy();
1885 Type *IntTy = getIntTy(B, TLI);
1886 SmallVector<Value *, 8> Args{Dest, Fmt};
1887 llvm::append_range(Args, VariadicArgs);
1888 return emitLibCall(LibFunc_sprintf, IntTy,
1889 {CharPtrTy, CharPtrTy}, Args, B, TLI,
1890 /*IsVaArgs=*/true);
1891}
1892
1894 const TargetLibraryInfo *TLI) {
1895 Type *CharPtrTy = B.getPtrTy();
1896 return emitLibCall(LibFunc_strcat, CharPtrTy,
1897 {CharPtrTy, CharPtrTy},
1898 {Dest, Src}, B, TLI);
1899}
1900
1902 const TargetLibraryInfo *TLI) {
1903 Type *CharPtrTy = B.getPtrTy();
1904 Type *SizeTTy = getSizeTTy(B, TLI);
1905 return emitLibCall(LibFunc_strlcpy, SizeTTy,
1906 {CharPtrTy, CharPtrTy, SizeTTy},
1907 {Dest, Src, Size}, B, TLI);
1908}
1909
1911 const TargetLibraryInfo *TLI) {
1912 Type *CharPtrTy = B.getPtrTy();
1913 Type *SizeTTy = getSizeTTy(B, TLI);
1914 return emitLibCall(LibFunc_strlcat, SizeTTy,
1915 {CharPtrTy, CharPtrTy, SizeTTy},
1916 {Dest, Src, Size}, B, TLI);
1917}
1918
1920 const TargetLibraryInfo *TLI) {
1921 Type *CharPtrTy = B.getPtrTy();
1922 Type *SizeTTy = getSizeTTy(B, TLI);
1923 return emitLibCall(LibFunc_strncat, CharPtrTy,
1924 {CharPtrTy, CharPtrTy, SizeTTy},
1925 {Dest, Src, Size}, B, TLI);
1926}
1927
1930 Type *CharPtrTy = B.getPtrTy();
1931 Type *IntTy = getIntTy(B, TLI);
1932 Type *SizeTTy = getSizeTTy(B, TLI);
1933 return emitLibCall(
1934 LibFunc_vsnprintf, IntTy,
1935 {CharPtrTy, SizeTTy, CharPtrTy, VAList->getType()},
1936 {Dest, Size, Fmt, VAList}, B, TLI);
1937}
1938
1941 Type *CharPtrTy = B.getPtrTy();
1942 Type *IntTy = getIntTy(B, TLI);
1943 return emitLibCall(LibFunc_vsprintf, IntTy,
1944 {CharPtrTy, CharPtrTy, VAList->getType()},
1945 {Dest, Fmt, VAList}, B, TLI);
1946}
1947
1948/// Append a suffix to the function name according to the type of 'Op'.
1950 SmallString<20> &NameBuffer) {
1951 if (!Op->getType()->isDoubleTy()) {
1952 NameBuffer += Name;
1953
1954 if (Op->getType()->isFloatTy())
1955 NameBuffer += 'f';
1956 else
1957 NameBuffer += 'l';
1958
1959 Name = NameBuffer;
1960 }
1961}
1962
1963static Value *emitUnaryFloatFnCallHelper(Value *Op, LibFunc TheLibFunc,
1964 StringRef Name, IRBuilderBase &B,
1965 const AttributeList &Attrs,
1966 const TargetLibraryInfo *TLI) {
1967 assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
1968
1969 Module *M = B.getModule();
1970 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op->getType(),
1971 Op->getType());
1972 CallInst *CI = B.CreateCall(Callee, Op, Name);
1973
1974 // The incoming attribute set may have come from a speculatable intrinsic, but
1975 // is being replaced with a library call which is not allowed to be
1976 // speculatable.
1977 CI->setAttributes(
1978 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1979 if (const Function *F =
1980 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1981 CI->setCallingConv(F->getCallingConv());
1982
1983 return CI;
1984}
1985
1987 StringRef Name, IRBuilderBase &B,
1988 const AttributeList &Attrs) {
1989 SmallString<20> NameBuffer;
1990 appendTypeSuffix(Op, Name, NameBuffer);
1991
1992 return emitUnaryFloatFnCallHelper(Op, TLI->getLibFunc(Name), Name, B, Attrs,
1993 TLI);
1994}
1995
1997 LibFunc DoubleFn, LibFunc FloatFn,
1998 LibFunc LongDoubleFn, IRBuilderBase &B,
1999 const AttributeList &Attrs) {
2000 // Get the name of the function according to TLI.
2001 Module *M = B.getModule();
2002 LibFunc TheLibFunc;
2003 StringRef Name = getFloatFn(M, TLI, Op->getType(), DoubleFn, FloatFn,
2004 LongDoubleFn, TheLibFunc);
2005
2006 return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
2007}
2008
2010 LibFunc TheLibFunc,
2011 StringRef Name, IRBuilderBase &B,
2012 const AttributeList &Attrs,
2013 const TargetLibraryInfo *TLI) {
2014 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
2015
2016 Module *M = B.getModule();
2017 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op1->getType(),
2018 Op1->getType(), Op2->getType());
2020 CallInst *CI = B.CreateCall(Callee, { Op1, Op2 }, Name);
2021
2022 // The incoming attribute set may have come from a speculatable intrinsic, but
2023 // is being replaced with a library call which is not allowed to be
2024 // speculatable.
2025 CI->setAttributes(
2026 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
2027 if (const Function *F =
2028 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
2029 CI->setCallingConv(F->getCallingConv());
2030
2031 return CI;
2032}
2033
2035 const TargetLibraryInfo *TLI,
2036 StringRef Name, IRBuilderBase &B,
2037 const AttributeList &Attrs) {
2038 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
2039
2040 SmallString<20> NameBuffer;
2041 appendTypeSuffix(Op1, Name, NameBuffer);
2042
2043 return emitBinaryFloatFnCallHelper(Op1, Op2, TLI->getLibFunc(Name), Name, B,
2044 Attrs, TLI);
2045}
2046
2048 const TargetLibraryInfo *TLI,
2049 LibFunc DoubleFn, LibFunc FloatFn,
2050 LibFunc LongDoubleFn, IRBuilderBase &B,
2051 const AttributeList &Attrs) {
2052 // Get the name of the function according to TLI.
2053 Module *M = B.getModule();
2054 LibFunc TheLibFunc;
2055 StringRef Name = getFloatFn(M, TLI, Op1->getType(), DoubleFn, FloatFn,
2056 LongDoubleFn, TheLibFunc);
2057
2058 return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
2059}
2060
2061// Emit a call to putchar(int) with Char as the argument. Char must have
2062// the same precision as int, which need not be 32 bits.
2064 const TargetLibraryInfo *TLI) {
2065 Type *IntTy = getIntTy(B, TLI);
2066 return emitLibCall(LibFunc_putchar, IntTy, IntTy, Char, B, TLI);
2067}
2068
2070 const TargetLibraryInfo *TLI) {
2071 Type *IntTy = getIntTy(B, TLI);
2072 return emitLibCall(LibFunc_puts, IntTy, B.getPtrTy(), Str, B, TLI);
2073}
2074
2076 const TargetLibraryInfo *TLI) {
2077 Type *IntTy = getIntTy(B, TLI);
2078 return emitLibCall(LibFunc_fputc, IntTy, {IntTy, File->getType()},
2079 {Char, File}, B, TLI);
2080}
2081
2083 const TargetLibraryInfo *TLI) {
2084 Type *IntTy = getIntTy(B, TLI);
2085 return emitLibCall(LibFunc_fputs, IntTy, {B.getPtrTy(), File->getType()},
2086 {Str, File}, B, TLI);
2087}
2088
2090 const DataLayout &DL, const TargetLibraryInfo *TLI) {
2091 Type *SizeTTy = getSizeTTy(B, TLI);
2092 return emitLibCall(LibFunc_fwrite, SizeTTy,
2093 {B.getPtrTy(), SizeTTy, SizeTTy, File->getType()},
2094 {Ptr, Size, ConstantInt::get(SizeTTy, 1), File}, B, TLI);
2095}
2096
2098 const TargetLibraryInfo *TLI) {
2099 Type *SizeTTy = getSizeTTy(B, TLI);
2100 return emitLibCall(LibFunc_malloc, B.getPtrTy(), SizeTTy, Num, B, TLI);
2101}
2102
2104 const TargetLibraryInfo &TLI, unsigned AddrSpace) {
2105 Type *SizeTTy = getSizeTTy(B, &TLI);
2106 return emitLibCall(LibFunc_calloc, B.getPtrTy(AddrSpace), {SizeTTy, SizeTTy},
2107 {Num, Size}, B, &TLI);
2108}
2109
2111 const TargetLibraryInfo *TLI,
2112 LibFunc SizeFeedbackNewFunc,
2113 Value *HotCold, Type *RetTy) {
2114 Module *M = B.getModule();
2115 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2116 return nullptr;
2117
2118 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2119 if (const Function *F = M->getFunction(Name);
2120 F && F->getReturnType() != RetTy)
2121 return nullptr;
2122
2123 FunctionCallee Func = getOrInsertLibFunc(M, *TLI, SizeFeedbackNewFunc, RetTy,
2124 Num->getType(), B.getInt8Ty());
2126 CallInst *CI = B.CreateCall(Func, {Num, HotCold}, "sized_ptr");
2127
2128 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2129 CI->setCallingConv(F->getCallingConv());
2130
2131 return CI;
2132}
2133
2136 const TargetLibraryInfo *TLI,
2137 LibFunc SizeFeedbackNewFunc,
2138 Value *HotCold, Type *RetTy) {
2139 Module *M = B.getModule();
2140 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2141 return nullptr;
2142
2143 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2144 if (const Function *F = M->getFunction(Name);
2145 F && F->getReturnType() != RetTy)
2146 return nullptr;
2147
2148 FunctionCallee Func =
2149 getOrInsertLibFunc(M, *TLI, SizeFeedbackNewFunc, RetTy, Num->getType(),
2150 Align->getType(), B.getInt8Ty());
2152 CallInst *CI = B.CreateCall(Func, {Num, Align, HotCold}, "sized_ptr");
2153
2154 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2155 CI->setCallingConv(F->getCallingConv());
2156
2157 return CI;
2158}
2159
2161 const TargetLibraryInfo *TLI, LibFunc NewFunc,
2162 Value *HotCold) {
2163 Module *M = B.getModule();
2164 if (!isLibFuncEmittable(M, TLI, NewFunc))
2165 return nullptr;
2166
2167 StringRef Name = TLI->getName(NewFunc);
2168 FunctionCallee Func = getOrInsertLibFunc(M, *TLI, NewFunc, B.getPtrTy(),
2169 Num->getType(), B.getInt8Ty());
2171 CallInst *CI = B.CreateCall(Func, {Num, HotCold}, Name);
2172
2173 if (const Function *F =
2174 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2175 CI->setCallingConv(F->getCallingConv());
2176
2177 return CI;
2178}
2179
2181 const TargetLibraryInfo *TLI,
2182 LibFunc NewFunc, Value *HotCold) {
2183 Module *M = B.getModule();
2184 if (!isLibFuncEmittable(M, TLI, NewFunc))
2185 return nullptr;
2186
2187 StringRef Name = TLI->getName(NewFunc);
2188 FunctionCallee Func =
2189 getOrInsertLibFunc(M, *TLI, NewFunc, B.getPtrTy(), Num->getType(),
2190 NoThrow->getType(), B.getInt8Ty());
2192 CallInst *CI = B.CreateCall(Func, {Num, NoThrow, HotCold}, Name);
2193
2194 if (const Function *F =
2195 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2196 CI->setCallingConv(F->getCallingConv());
2197
2198 return CI;
2199}
2200
2202 const TargetLibraryInfo *TLI,
2203 LibFunc NewFunc, Value *HotCold) {
2204 Module *M = B.getModule();
2205 if (!isLibFuncEmittable(M, TLI, NewFunc))
2206 return nullptr;
2207
2208 StringRef Name = TLI->getName(NewFunc);
2209 FunctionCallee Func =
2210 getOrInsertLibFunc(M, *TLI, NewFunc, B.getPtrTy(), Num->getType(),
2211 Align->getType(), B.getInt8Ty());
2213 CallInst *CI = B.CreateCall(Func, {Num, Align, HotCold}, Name);
2214
2215 if (const Function *F =
2216 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2217 CI->setCallingConv(F->getCallingConv());
2218
2219 return CI;
2220}
2221
2223 Value *NoThrow, IRBuilderBase &B,
2224 const TargetLibraryInfo *TLI,
2225 LibFunc NewFunc, Value *HotCold) {
2226 Module *M = B.getModule();
2227 if (!isLibFuncEmittable(M, TLI, NewFunc))
2228 return nullptr;
2229
2230 StringRef Name = TLI->getName(NewFunc);
2231 FunctionCallee Func =
2232 getOrInsertLibFunc(M, *TLI, NewFunc, B.getPtrTy(), Num->getType(),
2233 Align->getType(), NoThrow->getType(), B.getInt8Ty());
2235 CallInst *CI = B.CreateCall(Func, {Num, Align, NoThrow, HotCold}, Name);
2236
2237 if (const Function *F =
2238 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2239 CI->setCallingConv(F->getCallingConv());
2240
2241 return CI;
2242}
const TargetLowering & TLI
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)
static LLVM_ABI Attribute getWithCaptureInfo(LLVMContext &Context, CaptureInfo CI)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:126
@ None
No attributes have been set.
Definition Attributes.h:128
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:28
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.
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:707
#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:55
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:2229
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 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 isFreeLikeFn(const Function *F)
Returns true if the function has allockind(free).
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