LLVM 22.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(NumInaccessibleMemOnly,
38 "Number of functions inferred as inaccessiblememonly");
39STATISTIC(NumReadOnly, "Number of functions inferred as readonly");
40STATISTIC(NumWriteOnly, "Number of functions inferred as writeonly");
41STATISTIC(NumArgMemOnly, "Number of functions inferred as argmemonly");
42STATISTIC(NumWriteErrnoMemOnly,
43 "Number of functions inferred as memory(errnomem: write)");
44STATISTIC(NumInaccessibleMemOrArgMemOnly,
45 "Number of functions inferred as inaccessiblemem_or_argmemonly");
47 NumWriteArgumentMemOrErrnoMemOnly,
48 "Number of functions inferred as memory(argmem: write, errnomem: write)");
49STATISTIC(NumNoUnwind, "Number of functions inferred as nounwind");
50STATISTIC(NumNoCallback, "Number of functions inferred as nocallback");
51STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture");
52STATISTIC(NumWriteOnlyArg, "Number of arguments inferred as writeonly");
53STATISTIC(NumReadOnlyArg, "Number of arguments inferred as readonly");
54STATISTIC(NumNoAlias, "Number of function returns inferred as noalias");
55STATISTIC(NumNoUndef, "Number of function returns inferred as noundef returns");
56STATISTIC(NumReturnedArg, "Number of arguments inferred as returned");
57STATISTIC(NumWillReturn, "Number of functions inferred as willreturn");
58STATISTIC(NumCold, "Number of functions inferred as cold");
59STATISTIC(NumNoReturn, "Number of functions inferred as no return");
60
62 if (F.doesNotAccessMemory())
63 return false;
64 F.setDoesNotAccessMemory();
65 ++NumReadNone;
66 return true;
67}
68
69static bool setIsCold(Function &F) {
70 if (F.hasFnAttribute(Attribute::Cold))
71 return false;
72 F.addFnAttr(Attribute::Cold);
73 ++NumCold;
74 return true;
75}
76
77static bool setNoReturn(Function &F) {
78 if (F.hasFnAttribute(Attribute::NoReturn))
79 return false;
80 F.addFnAttr(Attribute::NoReturn);
81 ++NumNoReturn;
82 return true;
83}
84
86 MemoryEffects OrigME = F.getMemoryEffects();
87 MemoryEffects NewME = OrigME & ME;
88 if (OrigME == NewME)
89 return false;
90 F.setMemoryEffects(NewME);
91 return true;
92}
93
96 return false;
97 ++NumInaccessibleMemOnly;
98 return true;
99}
100
103 return false;
104 ++NumReadOnly;
105 return true;
106}
107
110 return false;
111 ++NumWriteOnly;
112 return true;
113}
114
117 return false;
118 ++NumArgMemOnly;
119 return true;
120}
121
124 return false;
125 ++NumInaccessibleMemOrArgMemOnly;
126 return true;
127}
128
131 return false;
132 ++NumWriteErrnoMemOnly;
133 return true;
134}
135
139 return false;
140 ++NumWriteArgumentMemOrErrnoMemOnly;
141 return true;
142}
143
145 if (F.doesNotThrow())
146 return false;
147 F.setDoesNotThrow();
148 ++NumNoUnwind;
149 return true;
150}
151
153 if (F.hasFnAttribute(Attribute::NoCallback))
154 return false;
155 F.addFnAttr(Attribute::NoCallback);
156 ++NumNoCallback;
157 return true;
158}
159
161 if (F.hasRetAttribute(Attribute::NoAlias))
162 return false;
163 F.addRetAttr(Attribute::NoAlias);
164 ++NumNoAlias;
165 return true;
166}
167
168static bool setDoesNotCapture(Function &F, unsigned ArgNo) {
169 if (F.hasParamAttribute(ArgNo, Attribute::Captures))
170 return false;
171 F.addParamAttr(ArgNo, Attribute::getWithCaptureInfo(F.getContext(),
173 ++NumNoCapture;
174 return true;
175}
176
177static bool setDoesNotAlias(Function &F, unsigned ArgNo) {
178 if (F.hasParamAttribute(ArgNo, Attribute::NoAlias))
179 return false;
180 F.addParamAttr(ArgNo, Attribute::NoAlias);
181 ++NumNoAlias;
182 return true;
183}
184
185static bool setOnlyReadsMemory(Function &F, unsigned ArgNo) {
186 if (F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
187 return false;
188 F.addParamAttr(ArgNo, Attribute::ReadOnly);
189 ++NumReadOnlyArg;
190 return true;
191}
192
193static bool setOnlyWritesMemory(Function &F, unsigned ArgNo) {
194 if (F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
195 return false;
196 F.addParamAttr(ArgNo, Attribute::WriteOnly);
197 ++NumWriteOnlyArg;
198 return true;
199}
200
201static bool setRetNoUndef(Function &F) {
202 if (!F.getReturnType()->isVoidTy() &&
203 !F.hasRetAttribute(Attribute::NoUndef)) {
204 F.addRetAttr(Attribute::NoUndef);
205 ++NumNoUndef;
206 return true;
207 }
208 return false;
209}
210
211static bool setArgsNoUndef(Function &F) {
212 bool Changed = false;
213 for (unsigned ArgNo = 0; ArgNo < F.arg_size(); ++ArgNo) {
214 if (!F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
215 F.addParamAttr(ArgNo, Attribute::NoUndef);
216 ++NumNoUndef;
217 Changed = true;
218 }
219 }
220 return Changed;
221}
222
223static bool setArgNoUndef(Function &F, unsigned ArgNo) {
224 if (F.hasParamAttribute(ArgNo, Attribute::NoUndef))
225 return false;
226 F.addParamAttr(ArgNo, Attribute::NoUndef);
227 ++NumNoUndef;
228 return true;
229}
230
232 bool UndefAdded = false;
233 UndefAdded |= setRetNoUndef(F);
234 UndefAdded |= setArgsNoUndef(F);
235 return UndefAdded;
236}
237
238static bool setReturnedArg(Function &F, unsigned ArgNo) {
239 if (F.hasParamAttribute(ArgNo, Attribute::Returned))
240 return false;
241 F.addParamAttr(ArgNo, Attribute::Returned);
242 ++NumReturnedArg;
243 return true;
244}
245
246static bool setNonLazyBind(Function &F) {
247 if (F.hasFnAttribute(Attribute::NonLazyBind))
248 return false;
249 F.addFnAttr(Attribute::NonLazyBind);
250 return true;
251}
252
254 if (F.hasFnAttribute(Attribute::NoFree))
255 return false;
256 F.addFnAttr(Attribute::NoFree);
257 return true;
258}
259
260static bool setWillReturn(Function &F) {
261 if (F.hasFnAttribute(Attribute::WillReturn))
262 return false;
263 F.addFnAttr(Attribute::WillReturn);
264 ++NumWillReturn;
265 return true;
266}
267
268static bool setAlignedAllocParam(Function &F, unsigned ArgNo) {
269 if (F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
270 return false;
271 F.addParamAttr(ArgNo, Attribute::AllocAlign);
272 return true;
273}
274
275static bool setAllocatedPointerParam(Function &F, unsigned ArgNo) {
276 if (F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
277 return false;
278 F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
279 return true;
280}
281
282static bool setAllocSize(Function &F, unsigned ElemSizeArg,
283 std::optional<unsigned> NumElemsArg) {
284 if (F.hasFnAttribute(Attribute::AllocSize))
285 return false;
286 F.addFnAttr(Attribute::getWithAllocSizeArgs(F.getContext(), ElemSizeArg,
287 NumElemsArg));
288 return true;
289}
290
291static bool setAllocFamily(Function &F, StringRef Family) {
292 if (F.hasFnAttribute("alloc-family"))
293 return false;
294 F.addFnAttr("alloc-family", Family);
295 return true;
296}
297
299 if (F.hasFnAttribute(Attribute::AllocKind))
300 return false;
301 F.addFnAttr(
302 Attribute::get(F.getContext(), Attribute::AllocKind, uint64_t(K)));
303 return true;
304}
305
307 const TargetLibraryInfo &TLI) {
308 Function *F = M->getFunction(Name);
309 if (!F)
310 return false;
311 return inferNonMandatoryLibFuncAttrs(*F, TLI);
312}
313
315 const TargetLibraryInfo &TLI) {
316 LibFunc TheLibFunc;
317 if (!(TLI.getLibFunc(F, TheLibFunc) && TLI.has(TheLibFunc)))
318 return false;
319
320 bool Changed = false;
321
322 if (F.getParent() != nullptr && F.getParent()->getRtLibUseGOT())
324
325 switch (TheLibFunc) {
326 case LibFunc_nan:
327 case LibFunc_nanf:
328 case LibFunc_nanl:
329 case LibFunc_strlen:
330 case LibFunc_strnlen:
331 case LibFunc_wcslen:
338 break;
339 case LibFunc_strchr:
340 case LibFunc_strrchr:
346 break;
347 case LibFunc_strtol:
348 case LibFunc_strtod:
349 case LibFunc_strtof:
350 case LibFunc_strtoul:
351 case LibFunc_strtoll:
352 case LibFunc_strtold:
353 case LibFunc_strtoull:
359 break;
360 case LibFunc_strcat:
361 case LibFunc_strncat:
366 Changed |= setReturnedArg(F, 0);
371 break;
372 case LibFunc_strcpy:
373 case LibFunc_strncpy:
374 Changed |= setReturnedArg(F, 0);
375 [[fallthrough]];
376 case LibFunc_stpcpy:
377 case LibFunc_stpncpy:
387 break;
388 case LibFunc_strxfrm:
395 break;
396 case LibFunc_strcmp: // 0,1
397 case LibFunc_strspn: // 0,1
398 case LibFunc_strncmp: // 0,1
399 case LibFunc_strcspn: // 0,1
407 break;
408 case LibFunc_strcoll:
409 case LibFunc_strcasecmp: // 0,1
410 case LibFunc_strncasecmp: //
411 // Those functions may depend on the locale, which may be accessed through
412 // global memory.
419 break;
420 case LibFunc_strstr:
421 case LibFunc_strpbrk:
428 break;
429 case LibFunc_strtok:
430 case LibFunc_strtok_r:
436 break;
437 case LibFunc_scanf:
442 break;
443 case LibFunc_setbuf:
444 case LibFunc_setvbuf:
448 break;
449 case LibFunc_strndup:
450 Changed |= setArgNoUndef(F, 1);
451 [[fallthrough]];
452 case LibFunc_strdup:
453 Changed |= setAllocFamily(F, "malloc");
460 break;
461 case LibFunc_stat:
462 case LibFunc_statvfs:
468 break;
469 case LibFunc_sscanf:
476 break;
477 case LibFunc_sprintf:
485 break;
486 case LibFunc_snprintf:
494 break;
495 case LibFunc_setitimer:
502 break;
503 case LibFunc_system:
504 // May throw; "system" is a valid pthread cancellation point.
508 break;
509 case LibFunc_aligned_alloc:
511 Changed |= setAllocSize(F, 1, std::nullopt);
513 [[fallthrough]];
514 case LibFunc_valloc:
515 case LibFunc_malloc:
516 case LibFunc_vec_malloc:
517 Changed |= setAllocSize(F, 0, std::nullopt);
518 [[fallthrough]];
519 case LibFunc_pvalloc:
520 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_malloc ? "vec_malloc"
521 : "malloc");
528 break;
529 case LibFunc_memcmp:
537 break;
538 case LibFunc_memchr:
539 case LibFunc_memrchr:
545 break;
546 case LibFunc_modf:
547 case LibFunc_modff:
548 case LibFunc_modfl:
555 break;
556 case LibFunc_memcpy:
562 Changed |= setReturnedArg(F, 0);
567 break;
568 case LibFunc_memmove:
573 Changed |= setReturnedArg(F, 0);
577 break;
578 case LibFunc_mempcpy:
579 case LibFunc_memccpy:
581 [[fallthrough]];
582 case LibFunc_memcpy_chk:
591 break;
592 case LibFunc_memalign:
593 Changed |= setAllocFamily(F, "malloc");
596 Changed |= setAllocSize(F, 1, std::nullopt);
603 break;
604 case LibFunc_mkdir:
609 break;
610 case LibFunc_mktime:
615 break;
616 case LibFunc_realloc:
617 case LibFunc_reallocf:
618 case LibFunc_vec_realloc:
620 F, TheLibFunc == LibFunc_vec_realloc ? "vec_malloc" : "malloc");
623 Changed |= setAllocSize(F, 1, std::nullopt);
630 Changed |= setArgNoUndef(F, 1);
631 break;
632 case LibFunc_reallocarray:
633 Changed |= setAllocFamily(F, "malloc");
636 Changed |= setAllocSize(F, 1, 2);
643 Changed |= setArgNoUndef(F, 1);
644 Changed |= setArgNoUndef(F, 2);
645 break;
646 case LibFunc_read:
647 // May throw; "read" is a valid pthread cancellation point.
650 break;
651 case LibFunc_rewind:
655 break;
656 case LibFunc_rmdir:
657 case LibFunc_remove:
658 case LibFunc_realpath:
663 break;
664 case LibFunc_rename:
671 break;
672 case LibFunc_readlink:
678 break;
679 case LibFunc_write:
680 // May throw; "write" is a valid pthread cancellation point.
684 break;
685 case LibFunc_bcopy:
694 break;
695 case LibFunc_bcmp:
703 break;
704 case LibFunc_bzero:
711 break;
712 case LibFunc_calloc:
713 case LibFunc_vec_calloc:
714 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_calloc ? "vec_malloc"
715 : "malloc");
717 Changed |= setAllocSize(F, 0, 1);
723 break;
724 case LibFunc_chmod:
725 case LibFunc_chown:
730 break;
731 case LibFunc_ctermid:
732 case LibFunc_clearerr:
733 case LibFunc_closedir:
737 break;
738 case LibFunc_atoi:
739 case LibFunc_atol:
740 case LibFunc_atof:
741 case LibFunc_atoll:
747 break;
748 case LibFunc_access:
753 break;
754 case LibFunc_fopen:
762 break;
763 case LibFunc_fdopen:
769 break;
770 case LibFunc_feof:
774 break;
775 case LibFunc_free:
776 case LibFunc_vec_free:
777 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_free ? "vec_malloc"
778 : "malloc");
786 break;
787 case LibFunc_fseek:
788 case LibFunc_ftell:
789 case LibFunc_fgetc:
790 case LibFunc_fgetc_unlocked:
791 case LibFunc_fseeko:
792 case LibFunc_ftello:
793 case LibFunc_fileno:
794 case LibFunc_fflush:
795 case LibFunc_fclose:
796 case LibFunc_fsetpos:
797 case LibFunc_flockfile:
798 case LibFunc_funlockfile:
799 case LibFunc_ftrylockfile:
803 break;
804 case LibFunc_ferror:
809 break;
810 case LibFunc_fputc:
811 case LibFunc_fputc_unlocked:
812 case LibFunc_fstat:
816 break;
817 case LibFunc_frexp:
818 case LibFunc_frexpf:
819 case LibFunc_frexpl:
826 break;
827 case LibFunc_fstatvfs:
831 break;
832 case LibFunc_fgets:
833 case LibFunc_fgets_unlocked:
838 break;
839 case LibFunc_fread:
840 case LibFunc_fread_unlocked:
846 break;
847 case LibFunc_fwrite:
848 case LibFunc_fwrite_unlocked:
854 break;
855 case LibFunc_fputs:
856 case LibFunc_fputs_unlocked:
862 break;
863 case LibFunc_fscanf:
864 case LibFunc_fprintf:
870 break;
871 case LibFunc_fgetpos:
876 break;
877 case LibFunc_getc:
881 break;
882 case LibFunc_getlogin_r:
886 break;
887 case LibFunc_getc_unlocked:
891 break;
892 case LibFunc_getenv:
897 break;
898 case LibFunc_gets:
899 case LibFunc_getchar:
900 case LibFunc_getchar_unlocked:
903 break;
904 case LibFunc_getitimer:
908 break;
909 case LibFunc_getpwnam:
914 break;
915 case LibFunc_ungetc:
919 break;
920 case LibFunc_uname:
924 break;
925 case LibFunc_unlink:
930 break;
931 case LibFunc_unsetenv:
936 break;
937 case LibFunc_utime:
938 case LibFunc_utimes:
945 break;
946 case LibFunc_putc:
947 case LibFunc_putc_unlocked:
951 break;
952 case LibFunc_puts:
953 case LibFunc_printf:
954 case LibFunc_perror:
959 break;
960 case LibFunc_pread:
961 // May throw; "pread" is a valid pthread cancellation point.
964 break;
965 case LibFunc_pwrite:
966 // May throw; "pwrite" is a valid pthread cancellation point.
970 break;
971 case LibFunc_putchar:
972 case LibFunc_putchar_unlocked:
975 break;
976 case LibFunc_popen:
984 break;
985 case LibFunc_pclose:
989 break;
990 case LibFunc_vscanf:
995 break;
996 case LibFunc_vsscanf:
1003 break;
1004 case LibFunc_vfscanf:
1010 break;
1011 case LibFunc_vprintf:
1016 break;
1017 case LibFunc_vfprintf:
1018 case LibFunc_vsprintf:
1024 break;
1025 case LibFunc_vsnprintf:
1031 break;
1032 case LibFunc_open:
1033 // May throw; "open" is a valid pthread cancellation point.
1037 break;
1038 case LibFunc_opendir:
1044 break;
1045 case LibFunc_tmpfile:
1049 break;
1050 case LibFunc_times:
1054 break;
1055 case LibFunc_htonl:
1056 case LibFunc_htons:
1057 case LibFunc_ntohl:
1058 case LibFunc_ntohs:
1062 break;
1063 case LibFunc_lstat:
1069 break;
1070 case LibFunc_lchown:
1075 break;
1076 case LibFunc_qsort:
1077 // May throw/callback; places call through function pointer.
1078 // Cannot give undef pointer/size
1081 break;
1082 case LibFunc_dunder_strndup:
1083 Changed |= setArgNoUndef(F, 1);
1084 [[fallthrough]];
1085 case LibFunc_dunder_strdup:
1091 break;
1092 case LibFunc_dunder_strtok_r:
1097 break;
1098 case LibFunc_under_IO_getc:
1102 break;
1103 case LibFunc_under_IO_putc:
1107 break;
1108 case LibFunc_dunder_isoc99_scanf:
1113 break;
1114 case LibFunc_stat64:
1115 case LibFunc_lstat64:
1116 case LibFunc_statvfs64:
1122 break;
1123 case LibFunc_dunder_isoc99_sscanf:
1130 break;
1131 case LibFunc_fopen64:
1139 break;
1140 case LibFunc_fseeko64:
1141 case LibFunc_ftello64:
1145 break;
1146 case LibFunc_tmpfile64:
1150 break;
1151 case LibFunc_fstat64:
1152 case LibFunc_fstatvfs64:
1156 break;
1157 case LibFunc_open64:
1158 // May throw; "open" is a valid pthread cancellation point.
1162 break;
1163 case LibFunc_gettimeofday:
1164 // Currently some platforms have the restrict keyword on the arguments to
1165 // gettimeofday. To be conservative, do not add noalias to gettimeofday's
1166 // arguments.
1171 break;
1172 case LibFunc_memset_pattern4:
1173 case LibFunc_memset_pattern8:
1174 case LibFunc_memset_pattern16:
1178 [[fallthrough]];
1179 case LibFunc_memset:
1181 [[fallthrough]];
1182 case LibFunc_memset_chk:
1187 break;
1188 case LibFunc_abort:
1189 Changed |= setIsCold(F);
1190 Changed |= setNoReturn(F);
1192 break;
1193 case LibFunc_terminate:
1194 // May callback; terminate_handler may be called
1195 Changed |= setIsCold(F);
1196 Changed |= setNoReturn(F);
1197 break;
1198 case LibFunc_cxa_throw:
1199 Changed |= setIsCold(F);
1200 Changed |= setNoReturn(F);
1201 // Don't add `nofree` on `__cxa_throw`
1202 return Changed;
1203 // int __nvvm_reflect(const char *)
1204 case LibFunc_nvvm_reflect:
1208 break;
1209 case LibFunc_acos:
1210 case LibFunc_acosf:
1211 case LibFunc_acosh:
1212 case LibFunc_acoshf:
1213 case LibFunc_acoshl:
1214 case LibFunc_acosl:
1215 case LibFunc_asin:
1216 case LibFunc_asinf:
1217 case LibFunc_asinh:
1218 case LibFunc_asinhf:
1219 case LibFunc_asinhl:
1220 case LibFunc_asinl:
1221 case LibFunc_atan:
1222 case LibFunc_atan2:
1223 case LibFunc_atan2f:
1224 case LibFunc_atan2l:
1225 case LibFunc_atanf:
1226 case LibFunc_atanh:
1227 case LibFunc_atanhf:
1228 case LibFunc_atanhl:
1229 case LibFunc_atanl:
1230 case LibFunc_ceil:
1231 case LibFunc_ceilf:
1232 case LibFunc_ceill:
1233 case LibFunc_cos:
1234 case LibFunc_cosh:
1235 case LibFunc_coshf:
1236 case LibFunc_coshl:
1237 case LibFunc_cosf:
1238 case LibFunc_cosl:
1239 case LibFunc_cospi:
1240 case LibFunc_cospif:
1241 case LibFunc_erf:
1242 case LibFunc_erff:
1243 case LibFunc_erfl:
1244 case LibFunc_tgamma:
1245 case LibFunc_tgammaf:
1246 case LibFunc_tgammal:
1247 case LibFunc_exp:
1248 case LibFunc_expf:
1249 case LibFunc_expl:
1250 case LibFunc_exp2:
1251 case LibFunc_exp2f:
1252 case LibFunc_exp2l:
1253 case LibFunc_expm1:
1254 case LibFunc_expm1f:
1255 case LibFunc_expm1l:
1256 case LibFunc_fdim:
1257 case LibFunc_fdiml:
1258 case LibFunc_fdimf:
1259 case LibFunc_fmod:
1260 case LibFunc_fmodf:
1261 case LibFunc_fmodl:
1262 case LibFunc_hypot:
1263 case LibFunc_hypotf:
1264 case LibFunc_hypotl:
1265 case LibFunc_ldexp:
1266 case LibFunc_ldexpf:
1267 case LibFunc_ldexpl:
1268 case LibFunc_log:
1269 case LibFunc_log10:
1270 case LibFunc_log10f:
1271 case LibFunc_log10l:
1272 case LibFunc_log1p:
1273 case LibFunc_log1pf:
1274 case LibFunc_log1pl:
1275 case LibFunc_log2:
1276 case LibFunc_log2f:
1277 case LibFunc_log2l:
1278 case LibFunc_logb:
1279 case LibFunc_logbf:
1280 case LibFunc_logbl:
1281 case LibFunc_ilogb:
1282 case LibFunc_ilogbf:
1283 case LibFunc_ilogbl:
1284 case LibFunc_logf:
1285 case LibFunc_logl:
1286 case LibFunc_nextafter:
1287 case LibFunc_nextafterf:
1288 case LibFunc_nextafterl:
1289 case LibFunc_nexttoward:
1290 case LibFunc_nexttowardf:
1291 case LibFunc_nexttowardl:
1292 case LibFunc_pow:
1293 case LibFunc_powf:
1294 case LibFunc_powl:
1295 case LibFunc_remainder:
1296 case LibFunc_remainderf:
1297 case LibFunc_remainderl:
1298 case LibFunc_rint:
1299 case LibFunc_rintf:
1300 case LibFunc_rintl:
1301 case LibFunc_round:
1302 case LibFunc_roundf:
1303 case LibFunc_roundl:
1304 case LibFunc_scalbln:
1305 case LibFunc_scalblnf:
1306 case LibFunc_scalblnl:
1307 case LibFunc_scalbn:
1308 case LibFunc_scalbnf:
1309 case LibFunc_scalbnl:
1310 case LibFunc_sin:
1311 case LibFunc_sincospif_stret:
1312 case LibFunc_sinf:
1313 case LibFunc_sinh:
1314 case LibFunc_sinhf:
1315 case LibFunc_sinhl:
1316 case LibFunc_sinl:
1317 case LibFunc_sinpi:
1318 case LibFunc_sinpif:
1319 case LibFunc_sqrt:
1320 case LibFunc_sqrtf:
1321 case LibFunc_sqrtl:
1322 case LibFunc_tan:
1323 case LibFunc_tanf:
1324 case LibFunc_tanh:
1325 case LibFunc_tanhf:
1326 case LibFunc_tanhl:
1327 case LibFunc_tanl:
1333 break;
1334 case LibFunc_abs:
1335 case LibFunc_cbrt:
1336 case LibFunc_cbrtf:
1337 case LibFunc_cbrtl:
1338 case LibFunc_copysign:
1339 case LibFunc_copysignf:
1340 case LibFunc_copysignl:
1341 case LibFunc_fabs:
1342 case LibFunc_fabsf:
1343 case LibFunc_fabsl:
1344 case LibFunc_ffs:
1345 case LibFunc_ffsl:
1346 case LibFunc_ffsll:
1347 case LibFunc_floor:
1348 case LibFunc_floorf:
1349 case LibFunc_floorl:
1350 case LibFunc_fls:
1351 case LibFunc_flsl:
1352 case LibFunc_flsll:
1353 case LibFunc_fmax:
1354 case LibFunc_fmaxf:
1355 case LibFunc_fmaxl:
1356 case LibFunc_fmin:
1357 case LibFunc_fminf:
1358 case LibFunc_fminl:
1359 case LibFunc_labs:
1360 case LibFunc_llabs:
1361 case LibFunc_nearbyint:
1362 case LibFunc_nearbyintf:
1363 case LibFunc_nearbyintl:
1364 case LibFunc_toascii:
1365 case LibFunc_trunc:
1366 case LibFunc_truncf:
1367 case LibFunc_truncl:
1369 [[fallthrough]];
1370 case LibFunc_isascii:
1371 case LibFunc_isdigit:
1376 break;
1377 case LibFunc_sincos:
1378 case LibFunc_sincosf:
1379 case LibFunc_sincosl:
1382 [[fallthrough]];
1383 case LibFunc_remquo:
1384 case LibFunc_remquof:
1385 case LibFunc_remquol:
1393 break;
1394 default:
1395 // FIXME: It'd be really nice to cover all the library functions we're
1396 // aware of here.
1397 break;
1398 }
1399 // We have to do this step after AllocKind has been inferred on functions so
1400 // we can reliably identify free-like and realloc-like functions.
1401 if (!isLibFreeFunction(&F, TheLibFunc) && !isReallocLikeFn(&F))
1403 return Changed;
1404}
1405
1406static void setArgExtAttr(Function &F, unsigned ArgNo,
1407 const TargetLibraryInfo &TLI, bool Signed = true) {
1408 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Param(Signed);
1409 if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr))
1410 F.addParamAttr(ArgNo, ExtAttr);
1411}
1412
1414 const TargetLibraryInfo &TLI, bool Signed = true) {
1415 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Return(Signed);
1416 if (ExtAttr != Attribute::None && !F.hasRetAttribute(ExtAttr))
1417 F.addRetAttr(ExtAttr);
1418}
1419
1420// Modeled after X86TargetLowering::markLibCallAttributes.
1422 if (!F->arg_size() || F->isVarArg())
1423 return;
1424
1425 const CallingConv::ID CC = F->getCallingConv();
1426 if (CC != CallingConv::C && CC != CallingConv::X86_StdCall)
1427 return;
1428
1429 const Module *M = F->getParent();
1430 unsigned N = M->getNumberRegisterParameters();
1431 if (!N)
1432 return;
1433
1434 const DataLayout &DL = M->getDataLayout();
1435
1436 for (Argument &A : F->args()) {
1437 Type *T = A.getType();
1438 if (!T->isIntOrPtrTy())
1439 continue;
1440
1441 const TypeSize &TS = DL.getTypeAllocSize(T);
1442 if (TS > 8)
1443 continue;
1444
1445 assert(TS <= 4 && "Need to account for parameters larger than word size");
1446 const unsigned NumRegs = TS > 4 ? 2 : 1;
1447 if (N < NumRegs)
1448 return;
1449
1450 N -= NumRegs;
1451 F->addParamAttr(A.getArgNo(), Attribute::InReg);
1452 }
1453}
1454
1456 LibFunc TheLibFunc, FunctionType *T,
1457 AttributeList AttributeList) {
1458 assert(TLI.has(TheLibFunc) &&
1459 "Creating call to non-existing library function.");
1460 StringRef Name = TLI.getName(TheLibFunc);
1461 FunctionCallee C = M->getOrInsertFunction(Name, T, AttributeList);
1462
1463 // Make sure any mandatory argument attributes are added.
1464
1465 // Any outgoing i32 argument should be handled with setArgExtAttr() which
1466 // will add an extension attribute if the target ABI requires it. Adding
1467 // argument extensions is typically done by the front end but when an
1468 // optimizer is building a library call on its own it has to take care of
1469 // this. Each such generated function must be handled here with sign or
1470 // zero extensions as needed. F is retreived with cast<> because we demand
1471 // of the caller to have called isLibFuncEmittable() first.
1472 Function *F = cast<Function>(C.getCallee());
1473 assert(F->getFunctionType() == T && "Function type does not match.");
1474 switch (TheLibFunc) {
1475 case LibFunc_fputc:
1476 case LibFunc_putchar:
1477 setArgExtAttr(*F, 0, TLI);
1478 break;
1479 case LibFunc_ldexp:
1480 case LibFunc_ldexpf:
1481 case LibFunc_ldexpl:
1482 case LibFunc_memchr:
1483 case LibFunc_memrchr:
1484 case LibFunc_strchr:
1485 setArgExtAttr(*F, 1, TLI);
1486 break;
1487 case LibFunc_memccpy:
1488 setArgExtAttr(*F, 2, TLI);
1489 break;
1490
1491 // These are functions that are known to not need any argument extension
1492 // on any target: A size_t argument (which may be an i32 on some targets)
1493 // should not trigger the assert below.
1494 case LibFunc_bcmp:
1495 setRetExtAttr(*F, TLI);
1496 break;
1497 case LibFunc_calloc:
1498 case LibFunc_fwrite:
1499 case LibFunc_malloc:
1500 case LibFunc_memcmp:
1501 case LibFunc_memcpy_chk:
1502 case LibFunc_mempcpy:
1503 case LibFunc_memset_pattern16:
1504 case LibFunc_snprintf:
1505 case LibFunc_stpncpy:
1506 case LibFunc_strlcat:
1507 case LibFunc_strlcpy:
1508 case LibFunc_strncat:
1509 case LibFunc_strncmp:
1510 case LibFunc_strncpy:
1511 case LibFunc_vsnprintf:
1512 break;
1513
1514 default:
1515#ifndef NDEBUG
1516 for (unsigned i = 0; i < T->getNumParams(); i++)
1517 assert(!isa<IntegerType>(T->getParamType(i)) &&
1518 "Unhandled integer argument.");
1519#endif
1520 break;
1521 }
1522
1524
1525 return C;
1526}
1527
1529 LibFunc TheLibFunc, FunctionType *T) {
1530 return getOrInsertLibFunc(M, TLI, TheLibFunc, T, AttributeList());
1531}
1532
1534 LibFunc TheLibFunc) {
1535 StringRef FuncName = TLI->getName(TheLibFunc);
1536 if (!TLI->has(TheLibFunc))
1537 return false;
1538
1539 // Check if the Module already has a GlobalValue with the same name, in
1540 // which case it must be a Function with the expected type.
1541 if (GlobalValue *GV = M->getNamedValue(FuncName)) {
1542 if (auto *F = dyn_cast<Function>(GV))
1543 return TLI->isValidProtoForLibFunc(*F->getFunctionType(), TheLibFunc, *M);
1544 return false;
1545 }
1546
1547 return true;
1548}
1549
1551 StringRef Name) {
1552 LibFunc TheLibFunc;
1553 return TLI->getLibFunc(Name, TheLibFunc) &&
1554 isLibFuncEmittable(M, TLI, TheLibFunc);
1555}
1556
1557bool llvm::hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty,
1558 LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
1559 switch (Ty->getTypeID()) {
1560 case Type::HalfTyID:
1561 return false;
1562 case Type::FloatTyID:
1563 return isLibFuncEmittable(M, TLI, FloatFn);
1564 case Type::DoubleTyID:
1565 return isLibFuncEmittable(M, TLI, DoubleFn);
1566 default:
1567 return isLibFuncEmittable(M, TLI, LongDoubleFn);
1568 }
1569}
1570
1572 Type *Ty, LibFunc DoubleFn, LibFunc FloatFn,
1573 LibFunc LongDoubleFn, LibFunc &TheLibFunc) {
1574 assert(hasFloatFn(M, TLI, Ty, DoubleFn, FloatFn, LongDoubleFn) &&
1575 "Cannot get name for unavailable function!");
1576
1577 switch (Ty->getTypeID()) {
1578 case Type::HalfTyID:
1579 llvm_unreachable("No name for HalfTy!");
1580 case Type::FloatTyID:
1581 TheLibFunc = FloatFn;
1582 return TLI->getName(FloatFn);
1583 case Type::DoubleTyID:
1584 TheLibFunc = DoubleFn;
1585 return TLI->getName(DoubleFn);
1586 default:
1587 TheLibFunc = LongDoubleFn;
1588 return TLI->getName(LongDoubleFn);
1589 }
1590}
1591
1592//- Emit LibCalls ------------------------------------------------------------//
1593
1595 return B.getIntNTy(TLI->getIntSize());
1596}
1597
1599 const Module *M = B.GetInsertBlock()->getModule();
1600 return B.getIntNTy(TLI->getSizeTSize(*M));
1601}
1602
1603static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
1604 ArrayRef<Type *> ParamTypes,
1606 const TargetLibraryInfo *TLI,
1607 bool IsVaArgs = false) {
1608 Module *M = B.GetInsertBlock()->getModule();
1609 if (!isLibFuncEmittable(M, TLI, TheLibFunc))
1610 return nullptr;
1611
1612 StringRef FuncName = TLI->getName(TheLibFunc);
1613 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1614 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, FuncType);
1615 inferNonMandatoryLibFuncAttrs(M, FuncName, *TLI);
1616 CallInst *CI = B.CreateCall(Callee, Operands, FuncName);
1617 if (const Function *F =
1618 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1619 CI->setCallingConv(F->getCallingConv());
1620 return CI;
1621}
1622
1624 const TargetLibraryInfo *TLI) {
1625 Type *CharPtrTy = B.getPtrTy();
1626 Type *SizeTTy = getSizeTTy(B, TLI);
1627 return emitLibCall(LibFunc_strlen, SizeTTy, CharPtrTy, Ptr, B, TLI);
1628}
1629
1631 const TargetLibraryInfo *TLI) {
1632 assert(Ptr && Ptr->getType()->isPointerTy() &&
1633 "Argument to wcslen intrinsic must be a pointer.");
1634 Type *PtrTy = B.getPtrTy();
1635 Type *SizeTTy = getSizeTTy(B, TLI);
1636 return emitLibCall(LibFunc_wcslen, SizeTTy, PtrTy, Ptr, B, TLI);
1637}
1638
1640 const TargetLibraryInfo *TLI) {
1641 Type *CharPtrTy = B.getPtrTy();
1642 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy, Ptr, B, TLI);
1643}
1644
1646 const TargetLibraryInfo *TLI) {
1647 Type *CharPtrTy = B.getPtrTy();
1648 Type *IntTy = getIntTy(B, TLI);
1649 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1650 {Ptr, ConstantInt::get(IntTy, C)}, B, TLI);
1651}
1652
1654 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1655 Type *CharPtrTy = B.getPtrTy();
1656 Type *IntTy = getIntTy(B, TLI);
1657 Type *SizeTTy = getSizeTTy(B, TLI);
1658 return emitLibCall(
1659 LibFunc_strncmp, IntTy,
1660 {CharPtrTy, CharPtrTy, SizeTTy},
1661 {Ptr1, Ptr2, Len}, B, TLI);
1662}
1663
1665 const TargetLibraryInfo *TLI) {
1666 Type *CharPtrTy = Dst->getType();
1667 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1668 {Dst, Src}, B, TLI);
1669}
1670
1672 const TargetLibraryInfo *TLI) {
1673 Type *CharPtrTy = B.getPtrTy();
1674 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1675 {Dst, Src}, B, TLI);
1676}
1677
1679 const TargetLibraryInfo *TLI) {
1680 Type *CharPtrTy = B.getPtrTy();
1681 Type *SizeTTy = getSizeTTy(B, TLI);
1682 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1683 {Dst, Src, Len}, B, TLI);
1684}
1685
1687 const TargetLibraryInfo *TLI) {
1688 Type *CharPtrTy = B.getPtrTy();
1689 Type *SizeTTy = getSizeTTy(B, TLI);
1690 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1691 {Dst, Src, Len}, B, TLI);
1692}
1693
1694Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
1695 IRBuilderBase &B, const DataLayout &DL,
1696 const TargetLibraryInfo *TLI) {
1697 Module *M = B.GetInsertBlock()->getModule();
1698 if (!isLibFuncEmittable(M, TLI, LibFunc_memcpy_chk))
1699 return nullptr;
1700
1701 AttributeList AS;
1702 AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
1703 Attribute::NoUnwind);
1704 Type *VoidPtrTy = B.getPtrTy();
1705 Type *SizeTTy = getSizeTTy(B, TLI);
1706 FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
1707 AttributeList::get(M->getContext(), AS), VoidPtrTy,
1708 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1709 CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1710 if (const Function *F =
1712 CI->setCallingConv(F->getCallingConv());
1713 return CI;
1714}
1715
1717 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1718 Type *VoidPtrTy = B.getPtrTy();
1719 Type *SizeTTy = getSizeTTy(B, TLI);
1720 return emitLibCall(LibFunc_mempcpy, VoidPtrTy,
1721 {VoidPtrTy, VoidPtrTy, SizeTTy},
1722 {Dst, Src, Len}, B, TLI);
1723}
1724
1726 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1727 Type *VoidPtrTy = B.getPtrTy();
1728 Type *IntTy = getIntTy(B, TLI);
1729 Type *SizeTTy = getSizeTTy(B, TLI);
1730 return emitLibCall(LibFunc_memchr, VoidPtrTy,
1731 {VoidPtrTy, IntTy, SizeTTy},
1732 {Ptr, Val, Len}, B, TLI);
1733}
1734
1736 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1737 Type *VoidPtrTy = B.getPtrTy();
1738 Type *IntTy = getIntTy(B, TLI);
1739 Type *SizeTTy = getSizeTTy(B, TLI);
1740 return emitLibCall(LibFunc_memrchr, VoidPtrTy,
1741 {VoidPtrTy, IntTy, SizeTTy},
1742 {Ptr, Val, Len}, B, TLI);
1743}
1744
1746 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1747 Type *VoidPtrTy = B.getPtrTy();
1748 Type *IntTy = getIntTy(B, TLI);
1749 Type *SizeTTy = getSizeTTy(B, TLI);
1750 return emitLibCall(LibFunc_memcmp, IntTy,
1751 {VoidPtrTy, VoidPtrTy, SizeTTy},
1752 {Ptr1, Ptr2, Len}, B, TLI);
1753}
1754
1756 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1757 Type *VoidPtrTy = B.getPtrTy();
1758 Type *IntTy = getIntTy(B, TLI);
1759 Type *SizeTTy = getSizeTTy(B, TLI);
1760 return emitLibCall(LibFunc_bcmp, IntTy,
1761 {VoidPtrTy, VoidPtrTy, SizeTTy},
1762 {Ptr1, Ptr2, Len}, B, TLI);
1763}
1764
1765Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
1766 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1767 Type *VoidPtrTy = B.getPtrTy();
1768 Type *IntTy = getIntTy(B, TLI);
1769 Type *SizeTTy = getSizeTTy(B, TLI);
1770 return emitLibCall(LibFunc_memccpy, VoidPtrTy,
1771 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1772 {Ptr1, Ptr2, Val, Len}, B, TLI);
1773}
1774
1776 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1777 const TargetLibraryInfo *TLI) {
1778 Type *CharPtrTy = B.getPtrTy();
1779 Type *IntTy = getIntTy(B, TLI);
1780 Type *SizeTTy = getSizeTTy(B, TLI);
1781 SmallVector<Value *, 8> Args{Dest, Size, Fmt};
1782 llvm::append_range(Args, VariadicArgs);
1783 return emitLibCall(LibFunc_snprintf, IntTy,
1784 {CharPtrTy, SizeTTy, CharPtrTy},
1785 Args, B, TLI, /*IsVaArgs=*/true);
1786}
1787
1789 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1790 const TargetLibraryInfo *TLI) {
1791 Type *CharPtrTy = B.getPtrTy();
1792 Type *IntTy = getIntTy(B, TLI);
1793 SmallVector<Value *, 8> Args{Dest, Fmt};
1794 llvm::append_range(Args, VariadicArgs);
1795 return emitLibCall(LibFunc_sprintf, IntTy,
1796 {CharPtrTy, CharPtrTy}, Args, B, TLI,
1797 /*IsVaArgs=*/true);
1798}
1799
1801 const TargetLibraryInfo *TLI) {
1802 Type *CharPtrTy = B.getPtrTy();
1803 return emitLibCall(LibFunc_strcat, CharPtrTy,
1804 {CharPtrTy, CharPtrTy},
1805 {Dest, Src}, B, TLI);
1806}
1807
1809 const TargetLibraryInfo *TLI) {
1810 Type *CharPtrTy = B.getPtrTy();
1811 Type *SizeTTy = getSizeTTy(B, TLI);
1812 return emitLibCall(LibFunc_strlcpy, SizeTTy,
1813 {CharPtrTy, CharPtrTy, SizeTTy},
1814 {Dest, Src, Size}, B, TLI);
1815}
1816
1818 const TargetLibraryInfo *TLI) {
1819 Type *CharPtrTy = B.getPtrTy();
1820 Type *SizeTTy = getSizeTTy(B, TLI);
1821 return emitLibCall(LibFunc_strlcat, SizeTTy,
1822 {CharPtrTy, CharPtrTy, SizeTTy},
1823 {Dest, Src, Size}, B, TLI);
1824}
1825
1827 const TargetLibraryInfo *TLI) {
1828 Type *CharPtrTy = B.getPtrTy();
1829 Type *SizeTTy = getSizeTTy(B, TLI);
1830 return emitLibCall(LibFunc_strncat, CharPtrTy,
1831 {CharPtrTy, CharPtrTy, SizeTTy},
1832 {Dest, Src, Size}, B, TLI);
1833}
1834
1836 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1837 Type *CharPtrTy = B.getPtrTy();
1838 Type *IntTy = getIntTy(B, TLI);
1839 Type *SizeTTy = getSizeTTy(B, TLI);
1840 return emitLibCall(
1841 LibFunc_vsnprintf, IntTy,
1842 {CharPtrTy, SizeTTy, CharPtrTy, VAList->getType()},
1843 {Dest, Size, Fmt, VAList}, B, TLI);
1844}
1845
1847 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1848 Type *CharPtrTy = B.getPtrTy();
1849 Type *IntTy = getIntTy(B, TLI);
1850 return emitLibCall(LibFunc_vsprintf, IntTy,
1851 {CharPtrTy, CharPtrTy, VAList->getType()},
1852 {Dest, Fmt, VAList}, B, TLI);
1853}
1854
1855/// Append a suffix to the function name according to the type of 'Op'.
1857 SmallString<20> &NameBuffer) {
1858 if (!Op->getType()->isDoubleTy()) {
1859 NameBuffer += Name;
1860
1861 if (Op->getType()->isFloatTy())
1862 NameBuffer += 'f';
1863 else
1864 NameBuffer += 'l';
1865
1866 Name = NameBuffer;
1867 }
1868}
1869
1871 StringRef Name, IRBuilderBase &B,
1872 const AttributeList &Attrs,
1873 const TargetLibraryInfo *TLI) {
1874 assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
1875
1876 Module *M = B.GetInsertBlock()->getModule();
1877 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op->getType(),
1878 Op->getType());
1879 CallInst *CI = B.CreateCall(Callee, Op, Name);
1880
1881 // The incoming attribute set may have come from a speculatable intrinsic, but
1882 // is being replaced with a library call which is not allowed to be
1883 // speculatable.
1884 CI->setAttributes(
1885 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1886 if (const Function *F =
1887 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1888 CI->setCallingConv(F->getCallingConv());
1889
1890 return CI;
1891}
1892
1894 StringRef Name, IRBuilderBase &B,
1895 const AttributeList &Attrs) {
1896 SmallString<20> NameBuffer;
1897 appendTypeSuffix(Op, Name, NameBuffer);
1898
1899 LibFunc TheLibFunc;
1900 TLI->getLibFunc(Name, TheLibFunc);
1901
1902 return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1903}
1904
1906 LibFunc DoubleFn, LibFunc FloatFn,
1907 LibFunc LongDoubleFn, IRBuilderBase &B,
1908 const AttributeList &Attrs) {
1909 // Get the name of the function according to TLI.
1910 Module *M = B.GetInsertBlock()->getModule();
1911 LibFunc TheLibFunc;
1912 StringRef Name = getFloatFn(M, TLI, Op->getType(), DoubleFn, FloatFn,
1913 LongDoubleFn, TheLibFunc);
1914
1915 return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1916}
1917
1919 LibFunc TheLibFunc,
1920 StringRef Name, IRBuilderBase &B,
1921 const AttributeList &Attrs,
1922 const TargetLibraryInfo *TLI) {
1923 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1924
1925 Module *M = B.GetInsertBlock()->getModule();
1926 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op1->getType(),
1927 Op1->getType(), Op2->getType());
1928 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
1929 CallInst *CI = B.CreateCall(Callee, { Op1, Op2 }, Name);
1930
1931 // The incoming attribute set may have come from a speculatable intrinsic, but
1932 // is being replaced with a library call which is not allowed to be
1933 // speculatable.
1934 CI->setAttributes(
1935 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1936 if (const Function *F =
1937 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1938 CI->setCallingConv(F->getCallingConv());
1939
1940 return CI;
1941}
1942
1944 const TargetLibraryInfo *TLI,
1945 StringRef Name, IRBuilderBase &B,
1946 const AttributeList &Attrs) {
1947 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1948
1949 SmallString<20> NameBuffer;
1950 appendTypeSuffix(Op1, Name, NameBuffer);
1951
1952 LibFunc TheLibFunc;
1953 TLI->getLibFunc(Name, TheLibFunc);
1954
1955 return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
1956}
1957
1959 const TargetLibraryInfo *TLI,
1960 LibFunc DoubleFn, LibFunc FloatFn,
1961 LibFunc LongDoubleFn, IRBuilderBase &B,
1962 const AttributeList &Attrs) {
1963 // Get the name of the function according to TLI.
1964 Module *M = B.GetInsertBlock()->getModule();
1965 LibFunc TheLibFunc;
1966 StringRef Name = getFloatFn(M, TLI, Op1->getType(), DoubleFn, FloatFn,
1967 LongDoubleFn, TheLibFunc);
1968
1969 return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
1970}
1971
1972// Emit a call to putchar(int) with Char as the argument. Char must have
1973// the same precision as int, which need not be 32 bits.
1975 const TargetLibraryInfo *TLI) {
1976 Module *M = B.GetInsertBlock()->getModule();
1977 if (!isLibFuncEmittable(M, TLI, LibFunc_putchar))
1978 return nullptr;
1979
1980 Type *IntTy = getIntTy(B, TLI);
1981 StringRef PutCharName = TLI->getName(LibFunc_putchar);
1982 FunctionCallee PutChar = getOrInsertLibFunc(M, *TLI, LibFunc_putchar,
1983 IntTy, IntTy);
1984 inferNonMandatoryLibFuncAttrs(M, PutCharName, *TLI);
1985 CallInst *CI = B.CreateCall(PutChar, Char, PutCharName);
1986
1987 if (const Function *F =
1989 CI->setCallingConv(F->getCallingConv());
1990 return CI;
1991}
1992
1994 const TargetLibraryInfo *TLI) {
1995 Module *M = B.GetInsertBlock()->getModule();
1996 if (!isLibFuncEmittable(M, TLI, LibFunc_puts))
1997 return nullptr;
1998
1999 Type *IntTy = getIntTy(B, TLI);
2000 StringRef PutsName = TLI->getName(LibFunc_puts);
2001 FunctionCallee PutS =
2002 getOrInsertLibFunc(M, *TLI, LibFunc_puts, IntTy, B.getPtrTy());
2003 inferNonMandatoryLibFuncAttrs(M, PutsName, *TLI);
2004 CallInst *CI = B.CreateCall(PutS, Str, PutsName);
2005 if (const Function *F =
2007 CI->setCallingConv(F->getCallingConv());
2008 return CI;
2009}
2010
2012 const TargetLibraryInfo *TLI) {
2013 Module *M = B.GetInsertBlock()->getModule();
2014 if (!isLibFuncEmittable(M, TLI, LibFunc_fputc))
2015 return nullptr;
2016
2017 Type *IntTy = getIntTy(B, TLI);
2018 StringRef FPutcName = TLI->getName(LibFunc_fputc);
2019 FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputc, IntTy,
2020 IntTy, File->getType());
2021 if (File->getType()->isPointerTy())
2022 inferNonMandatoryLibFuncAttrs(M, FPutcName, *TLI);
2023 CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName);
2024
2025 if (const Function *Fn =
2026 dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
2027 CI->setCallingConv(Fn->getCallingConv());
2028 return CI;
2029}
2030
2032 const TargetLibraryInfo *TLI) {
2033 Module *M = B.GetInsertBlock()->getModule();
2034 if (!isLibFuncEmittable(M, TLI, LibFunc_fputs))
2035 return nullptr;
2036
2037 Type *IntTy = getIntTy(B, TLI);
2038 StringRef FPutsName = TLI->getName(LibFunc_fputs);
2039 FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputs, IntTy,
2040 B.getPtrTy(), File->getType());
2041 if (File->getType()->isPointerTy())
2042 inferNonMandatoryLibFuncAttrs(M, FPutsName, *TLI);
2043 CallInst *CI = B.CreateCall(F, {Str, File}, FPutsName);
2044
2045 if (const Function *Fn =
2046 dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
2047 CI->setCallingConv(Fn->getCallingConv());
2048 return CI;
2049}
2050
2052 const DataLayout &DL, const TargetLibraryInfo *TLI) {
2053 Module *M = B.GetInsertBlock()->getModule();
2054 if (!isLibFuncEmittable(M, TLI, LibFunc_fwrite))
2055 return nullptr;
2056
2057 Type *SizeTTy = getSizeTTy(B, TLI);
2058 StringRef FWriteName = TLI->getName(LibFunc_fwrite);
2060 getOrInsertLibFunc(M, *TLI, LibFunc_fwrite, SizeTTy, B.getPtrTy(),
2061 SizeTTy, SizeTTy, File->getType());
2062
2063 if (File->getType()->isPointerTy())
2064 inferNonMandatoryLibFuncAttrs(M, FWriteName, *TLI);
2065 CallInst *CI =
2066 B.CreateCall(F, {Ptr, Size,
2067 ConstantInt::get(SizeTTy, 1), File});
2068
2069 if (const Function *Fn =
2070 dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
2071 CI->setCallingConv(Fn->getCallingConv());
2072 return CI;
2073}
2074
2076 const TargetLibraryInfo *TLI) {
2077 Module *M = B.GetInsertBlock()->getModule();
2078 if (!isLibFuncEmittable(M, TLI, LibFunc_malloc))
2079 return nullptr;
2080
2081 StringRef MallocName = TLI->getName(LibFunc_malloc);
2082 Type *SizeTTy = getSizeTTy(B, TLI);
2084 getOrInsertLibFunc(M, *TLI, LibFunc_malloc, B.getPtrTy(), SizeTTy);
2085 inferNonMandatoryLibFuncAttrs(M, MallocName, *TLI);
2086 CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
2087
2088 if (const Function *F =
2089 dyn_cast<Function>(Malloc.getCallee()->stripPointerCasts()))
2090 CI->setCallingConv(F->getCallingConv());
2091
2092 return CI;
2093}
2094
2096 const TargetLibraryInfo &TLI, unsigned AddrSpace) {
2097 Module *M = B.GetInsertBlock()->getModule();
2098 if (!isLibFuncEmittable(M, &TLI, LibFunc_calloc))
2099 return nullptr;
2100
2101 StringRef CallocName = TLI.getName(LibFunc_calloc);
2102 Type *SizeTTy = getSizeTTy(B, &TLI);
2104 M, TLI, LibFunc_calloc, B.getPtrTy(AddrSpace), SizeTTy, SizeTTy);
2105 inferNonMandatoryLibFuncAttrs(M, CallocName, TLI);
2106 CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
2107
2108 if (const auto *F =
2110 CI->setCallingConv(F->getCallingConv());
2111
2112 return CI;
2113}
2114
2116 const TargetLibraryInfo *TLI,
2117 LibFunc SizeFeedbackNewFunc,
2118 uint8_t HotCold) {
2119 Module *M = B.GetInsertBlock()->getModule();
2120 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2121 return nullptr;
2122
2123 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2124
2125 // __sized_ptr_t struct return type { void*, size_t }
2126 StructType *SizedPtrT =
2127 StructType::get(M->getContext(), {B.getPtrTy(), Num->getType()});
2128 FunctionCallee Func =
2129 M->getOrInsertFunction(Name, SizedPtrT, Num->getType(), B.getInt8Ty());
2130 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2131 CallInst *CI = B.CreateCall(Func, {Num, B.getInt8(HotCold)}, "sized_ptr");
2132
2133 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2134 CI->setCallingConv(F->getCallingConv());
2135
2136 return CI;
2137}
2138
2141 const TargetLibraryInfo *TLI,
2142 LibFunc SizeFeedbackNewFunc,
2143 uint8_t HotCold) {
2144 Module *M = B.GetInsertBlock()->getModule();
2145 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2146 return nullptr;
2147
2148 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2149
2150 // __sized_ptr_t struct return type { void*, size_t }
2151 StructType *SizedPtrT =
2152 StructType::get(M->getContext(), {B.getPtrTy(), Num->getType()});
2153 FunctionCallee Func = M->getOrInsertFunction(Name, SizedPtrT, Num->getType(),
2154 Align->getType(), B.getInt8Ty());
2155 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2156 CallInst *CI =
2157 B.CreateCall(Func, {Num, Align, B.getInt8(HotCold)}, "sized_ptr");
2158
2159 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2160 CI->setCallingConv(F->getCallingConv());
2161
2162 return CI;
2163}
2164
2166 const TargetLibraryInfo *TLI, LibFunc NewFunc,
2167 uint8_t HotCold) {
2168 Module *M = B.GetInsertBlock()->getModule();
2169 if (!isLibFuncEmittable(M, TLI, NewFunc))
2170 return nullptr;
2171
2172 StringRef Name = TLI->getName(NewFunc);
2173 FunctionCallee Func =
2174 M->getOrInsertFunction(Name, B.getPtrTy(), Num->getType(), B.getInt8Ty());
2175 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2176 CallInst *CI = B.CreateCall(Func, {Num, B.getInt8(HotCold)}, Name);
2177
2178 if (const Function *F =
2179 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2180 CI->setCallingConv(F->getCallingConv());
2181
2182 return CI;
2183}
2184
2186 const TargetLibraryInfo *TLI,
2187 LibFunc NewFunc, uint8_t HotCold) {
2188 Module *M = B.GetInsertBlock()->getModule();
2189 if (!isLibFuncEmittable(M, TLI, NewFunc))
2190 return nullptr;
2191
2192 StringRef Name = TLI->getName(NewFunc);
2193 FunctionCallee Func = M->getOrInsertFunction(
2194 Name, B.getPtrTy(), Num->getType(), NoThrow->getType(), B.getInt8Ty());
2195 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2196 CallInst *CI = B.CreateCall(Func, {Num, NoThrow, B.getInt8(HotCold)}, Name);
2197
2198 if (const Function *F =
2199 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2200 CI->setCallingConv(F->getCallingConv());
2201
2202 return CI;
2203}
2204
2206 const TargetLibraryInfo *TLI,
2207 LibFunc NewFunc, uint8_t HotCold) {
2208 Module *M = B.GetInsertBlock()->getModule();
2209 if (!isLibFuncEmittable(M, TLI, NewFunc))
2210 return nullptr;
2211
2212 StringRef Name = TLI->getName(NewFunc);
2213 FunctionCallee Func = M->getOrInsertFunction(
2214 Name, B.getPtrTy(), Num->getType(), Align->getType(), B.getInt8Ty());
2215 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2216 CallInst *CI = B.CreateCall(Func, {Num, Align, B.getInt8(HotCold)}, Name);
2217
2218 if (const Function *F =
2219 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2220 CI->setCallingConv(F->getCallingConv());
2221
2222 return CI;
2223}
2224
2226 Value *NoThrow, IRBuilderBase &B,
2227 const TargetLibraryInfo *TLI,
2228 LibFunc NewFunc, uint8_t HotCold) {
2229 Module *M = B.GetInsertBlock()->getModule();
2230 if (!isLibFuncEmittable(M, TLI, NewFunc))
2231 return nullptr;
2232
2233 StringRef Name = TLI->getName(NewFunc);
2234 FunctionCallee Func = M->getOrInsertFunction(
2235 Name, B.getPtrTy(), Num->getType(), Align->getType(), NoThrow->getType(),
2236 B.getInt8Ty());
2237 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2238 CallInst *CI =
2239 B.CreateCall(Func, {Num, Align, NoThrow, B.getInt8(HotCold)}, Name);
2240
2241 if (const Function *F =
2242 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2243 CI->setCallingConv(F->getCallingConv());
2244
2245 return CI;
2246}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool setRetNoUndef(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 setDoesNotAlias(Function &F, unsigned ArgNo)
static bool setDoesNotAccessMemory(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 bool setOnlyAccessesInaccessibleMemory(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< 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:55
#define T
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
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
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:88
@ None
No attributes have been set.
Definition Attributes.h:90
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:367
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Class to represent function types.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
Class to represent integer types.
static MemoryEffectsBase readOnly()
Definition ModRef.h:125
static MemoryEffectsBase argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:135
static MemoryEffectsBase inaccessibleMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:141
static MemoryEffectsBase errnoMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:146
static MemoryEffectsBase writeOnly()
Definition ModRef.h:130
static MemoryEffectsBase inaccessibleOrArgMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:158
static MemoryEffectsBase argumentOrErrnoMemOnly(ModRefInfo ArgMR=ModRefInfo::ModRef, ModRefInfo ErrnoMR=ModRefInfo::ModRef)
Definition ModRef.h:167
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
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.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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:414
Provides information about what library functions are available for the current target.
bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F, const Module &M) const
Return true if the function type FTy is valid for the library function F, regardless of whether the f...
bool has(LibFunc F) const
Tests whether a library function is available.
unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
StringRef getName(LibFunc F) const
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
@ HalfTyID
16-bit floating point type
Definition Type.h:56
@ FloatTyID
32-bit floating point type
Definition Type.h:58
@ DoubleTyID
64-bit floating point type
Definition Type.h:59
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition Value.cpp:701
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.
LLVM_ABI Value * emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
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:51
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:2136
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
Definition ModRef.h:296
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 * 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 * 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.
@ 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 * emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
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 * emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
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 * emitHotColdSizeReturningNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
LLVM_ABI Value * emitHotColdNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t 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 * emitHotColdSizeReturningNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
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