LLVM 23.0.0git
BuildLibCalls.cpp
Go to the documentation of this file.
1//===- BuildLibCalls.cpp - Utility builder for libcalls -------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements some functions that will create standard C libcalls.
10//
11//===----------------------------------------------------------------------===//
12
15#include "llvm/ADT/Statistic.h"
18#include "llvm/IR/Argument.h"
19#include "llvm/IR/CallingConv.h"
20#include "llvm/IR/Constants.h"
21#include "llvm/IR/DataLayout.h"
23#include "llvm/IR/Function.h"
24#include "llvm/IR/IRBuilder.h"
25#include "llvm/IR/Module.h"
26#include "llvm/IR/Type.h"
28#include <optional>
29
30using namespace llvm;
31
32#define DEBUG_TYPE "build-libcalls"
33
34//- Infer Attributes ---------------------------------------------------------//
35
36STATISTIC(NumReadNone, "Number of functions inferred as readnone");
37STATISTIC(NumReadOnly, "Number of functions inferred as readonly");
38STATISTIC(NumWriteOnly, "Number of functions inferred as writeonly");
39STATISTIC(NumArgMemOnly, "Number of functions inferred as argmemonly");
40STATISTIC(NumWriteErrnoMemOnly,
41 "Number of functions inferred as memory(errnomem: write)");
42STATISTIC(NumInaccessibleMemOrArgMemOnly,
43 "Number of functions inferred as inaccessiblemem_or_argmemonly");
44STATISTIC(NumInaccessibleMemOrErrnoMemOnly,
45 "Number of functions inferred as memory(inaccessiblemem: readwrite, "
46 "errnomem: write)");
47STATISTIC(NumInaccessibleMemOrArgMemOrErrnoMemOnly,
48 "Number of functions inferred as memory(argmem: readwrite, "
49 "inaccessiblemem: readwrite, errnomem: write)");
51 NumWriteArgumentMemOrErrnoMemOnly,
52 "Number of functions inferred as memory(argmem: write, errnomem: write)");
53STATISTIC(NumNoUnwind, "Number of functions inferred as nounwind");
54STATISTIC(NumNoCallback, "Number of functions inferred as nocallback");
55STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture");
56STATISTIC(NumWriteOnlyArg, "Number of arguments inferred as writeonly");
57STATISTIC(NumReadOnlyArg, "Number of arguments inferred as readonly");
58STATISTIC(NumNoAlias, "Number of function returns inferred as noalias");
59STATISTIC(NumNoUndef, "Number of function returns inferred as noundef returns");
60STATISTIC(NumReturnedArg, "Number of arguments inferred as returned");
61STATISTIC(NumWillReturn, "Number of functions inferred as willreturn");
62STATISTIC(NumCold, "Number of functions inferred as cold");
63STATISTIC(NumNoReturn, "Number of functions inferred as no return");
64STATISTIC(NumNoSync, "Number of functions inferred as nosync");
65
67 if (F.doesNotAccessMemory())
68 return false;
69 F.setDoesNotAccessMemory();
70 ++NumReadNone;
71 return true;
72}
73
74static bool setIsCold(Function &F) {
75 if (F.hasFnAttribute(Attribute::Cold))
76 return false;
77 F.addFnAttr(Attribute::Cold);
78 ++NumCold;
79 return true;
80}
81
82static bool setNoReturn(Function &F) {
83 if (F.hasFnAttribute(Attribute::NoReturn))
84 return false;
85 F.addFnAttr(Attribute::NoReturn);
86 ++NumNoReturn;
87 return true;
88}
89
91 MemoryEffects OrigME = F.getMemoryEffects();
92 MemoryEffects NewME = OrigME & ME;
93 if (OrigME == NewME)
94 return false;
95 F.setMemoryEffects(NewME);
96 return true;
97}
98
101 return false;
102 ++NumReadOnly;
103 return true;
104}
105
108 return false;
109 ++NumWriteOnly;
110 return true;
111}
112
115 return false;
116 ++NumArgMemOnly;
117 return true;
118}
119
122 return false;
123 ++NumInaccessibleMemOrArgMemOnly;
124 return true;
125}
126
130 return false;
131 ++NumInaccessibleMemOrErrnoMemOnly;
132 return true;
133}
134
138 return false;
139 ++NumInaccessibleMemOrArgMemOrErrnoMemOnly;
140 return true;
141}
142
145 return false;
146 ++NumWriteErrnoMemOnly;
147 return true;
148}
149
153 return false;
154 ++NumWriteArgumentMemOrErrnoMemOnly;
155 return true;
156}
157
159 if (F.doesNotThrow())
160 return false;
161 F.setDoesNotThrow();
162 ++NumNoUnwind;
163 return true;
164}
165
167 if (F.hasFnAttribute(Attribute::NoCallback))
168 return false;
169 F.addFnAttr(Attribute::NoCallback);
170 ++NumNoCallback;
171 return true;
172}
173
175 if (F.hasRetAttribute(Attribute::NoAlias))
176 return false;
177 F.addRetAttr(Attribute::NoAlias);
178 ++NumNoAlias;
179 return true;
180}
181
182static bool setDoesNotCapture(Function &F, unsigned ArgNo) {
183 if (F.hasParamAttribute(ArgNo, Attribute::Captures))
184 return false;
185 F.addParamAttr(ArgNo, Attribute::getWithCaptureInfo(F.getContext(),
187 ++NumNoCapture;
188 return true;
189}
190
191static bool setDoesNotAlias(Function &F, unsigned ArgNo) {
192 if (F.hasParamAttribute(ArgNo, Attribute::NoAlias))
193 return false;
194 F.addParamAttr(ArgNo, Attribute::NoAlias);
195 ++NumNoAlias;
196 return true;
197}
198
199static bool setDoesNotSync(Function &F) {
200 if (F.hasFnAttribute(Attribute::NoSync))
201 return false;
202 F.addFnAttr(Attribute::NoSync);
203 ++NumNoSync;
204 return true;
205}
206
207static bool setOnlyReadsMemory(Function &F, unsigned ArgNo) {
208 if (F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
209 return false;
210 F.addParamAttr(ArgNo, Attribute::ReadOnly);
211 ++NumReadOnlyArg;
212 return true;
213}
214
215static bool setOnlyWritesMemory(Function &F, unsigned ArgNo) {
216 if (F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
217 return false;
218 F.addParamAttr(ArgNo, Attribute::WriteOnly);
219 ++NumWriteOnlyArg;
220 return true;
221}
222
223static bool setRetNoUndef(Function &F) {
224 if (!F.getReturnType()->isVoidTy() &&
225 !F.hasRetAttribute(Attribute::NoUndef)) {
226 F.addRetAttr(Attribute::NoUndef);
227 ++NumNoUndef;
228 return true;
229 }
230 return false;
231}
232
233static bool setArgsNoUndef(Function &F) {
234 bool Changed = false;
235 for (unsigned ArgNo = 0; ArgNo < F.arg_size(); ++ArgNo) {
236 if (!F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
237 F.addParamAttr(ArgNo, Attribute::NoUndef);
238 ++NumNoUndef;
239 Changed = true;
240 }
241 }
242 return Changed;
243}
244
245static bool setArgNoUndef(Function &F, unsigned ArgNo) {
246 if (F.hasParamAttribute(ArgNo, Attribute::NoUndef))
247 return false;
248 F.addParamAttr(ArgNo, Attribute::NoUndef);
249 ++NumNoUndef;
250 return true;
251}
252
254 bool UndefAdded = false;
255 UndefAdded |= setRetNoUndef(F);
256 UndefAdded |= setArgsNoUndef(F);
257 return UndefAdded;
258}
259
260static bool setReturnedArg(Function &F, unsigned ArgNo) {
261 if (F.hasParamAttribute(ArgNo, Attribute::Returned))
262 return false;
263 F.addParamAttr(ArgNo, Attribute::Returned);
264 ++NumReturnedArg;
265 return true;
266}
267
268static bool setNonLazyBind(Function &F) {
269 if (F.hasFnAttribute(Attribute::NonLazyBind))
270 return false;
271 F.addFnAttr(Attribute::NonLazyBind);
272 return true;
273}
274
276 if (F.hasFnAttribute(Attribute::NoFree))
277 return false;
278 F.addFnAttr(Attribute::NoFree);
279 return true;
280}
281
282static bool setWillReturn(Function &F) {
283 if (F.hasFnAttribute(Attribute::WillReturn))
284 return false;
285 F.addFnAttr(Attribute::WillReturn);
286 ++NumWillReturn;
287 return true;
288}
289
290static bool setAlignedAllocParam(Function &F, unsigned ArgNo) {
291 if (F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
292 return false;
293 F.addParamAttr(ArgNo, Attribute::AllocAlign);
294 return true;
295}
296
297static bool setAllocatedPointerParam(Function &F, unsigned ArgNo) {
298 if (F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
299 return false;
300 F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
301 return true;
302}
303
304static bool setAllocSize(Function &F, unsigned ElemSizeArg,
305 std::optional<unsigned> NumElemsArg) {
306 if (F.hasFnAttribute(Attribute::AllocSize))
307 return false;
308 F.addFnAttr(Attribute::getWithAllocSizeArgs(F.getContext(), ElemSizeArg,
309 NumElemsArg));
310 return true;
311}
312
313static bool setAllocFamily(Function &F, StringRef Family) {
314 if (F.hasFnAttribute("alloc-family"))
315 return false;
316 F.addFnAttr("alloc-family", Family);
317 return true;
318}
319
321 if (F.hasFnAttribute(Attribute::AllocKind))
322 return false;
323 F.addFnAttr(
324 Attribute::get(F.getContext(), Attribute::AllocKind, uint64_t(K)));
325 return true;
326}
327
329 const TargetLibraryInfo &TLI) {
330 Function *F = M->getFunction(Name);
331 if (!F)
332 return false;
333 return inferNonMandatoryLibFuncAttrs(*F, TLI);
334}
335
337 const TargetLibraryInfo &TLI) {
338 LibFunc TheLibFunc;
339 if (!(TLI.getLibFunc(F, TheLibFunc) && TLI.has(TheLibFunc)))
340 return false;
341
342 bool Changed = false;
343
344 if (F.getParent() != nullptr && F.getParent()->getRtLibUseGOT())
346
347 switch (TheLibFunc) {
348 case LibFunc_nan:
349 case LibFunc_nanf:
350 case LibFunc_nanl:
351 case LibFunc_strlen:
352 case LibFunc_strnlen:
353 case LibFunc_wcslen:
361 break;
362 case LibFunc_strchr:
363 case LibFunc_strrchr:
370 break;
371 case LibFunc_strtol:
372 case LibFunc_strtod:
373 case LibFunc_strtof:
374 case LibFunc_strtoul:
375 case LibFunc_strtoll:
376 case LibFunc_strtold:
377 case LibFunc_strtoull:
383 break;
384 case LibFunc_strcat:
385 case LibFunc_strncat:
390 Changed |= setReturnedArg(F, 0);
396 break;
397 case LibFunc_strcpy:
398 case LibFunc_strncpy:
399 Changed |= setReturnedArg(F, 0);
400 [[fallthrough]];
401 case LibFunc_stpcpy:
402 case LibFunc_stpncpy:
413 break;
414 case LibFunc_strxfrm:
421 break;
422 case LibFunc_strcmp: // 0,1
423 case LibFunc_strspn: // 0,1
424 case LibFunc_strncmp: // 0,1
425 case LibFunc_strcspn: // 0,1
434 break;
435 case LibFunc_strcoll:
436 case LibFunc_strcasecmp: // 0,1
437 case LibFunc_strncasecmp: //
438 // Those functions may depend on the locale, which may be accessed through
439 // global memory.
446 break;
447 case LibFunc_strstr:
448 case LibFunc_strpbrk:
456 break;
457 case LibFunc_strtok:
458 case LibFunc_strtok_r:
464 break;
465 case LibFunc_scanf:
470 break;
471 case LibFunc_setbuf:
472 case LibFunc_setvbuf:
476 break;
477 case LibFunc_strndup:
478 Changed |= setArgNoUndef(F, 1);
479 [[fallthrough]];
480 case LibFunc_strdup:
481 Changed |= setAllocFamily(F, "malloc");
488 break;
489 case LibFunc_stat:
490 case LibFunc_statvfs:
496 break;
497 case LibFunc_sscanf:
504 break;
505 case LibFunc_sprintf:
513 break;
514 case LibFunc_snprintf:
522 break;
523 case LibFunc_setitimer:
530 break;
531 case LibFunc_system:
532 // May throw; "system" is a valid pthread cancellation point.
536 break;
537 case LibFunc_aligned_alloc:
539 Changed |= setAllocSize(F, 1, std::nullopt);
541 [[fallthrough]];
542 case LibFunc_valloc:
543 case LibFunc_malloc:
544 case LibFunc_vec_malloc:
545 Changed |= setAllocSize(F, 0, std::nullopt);
546 [[fallthrough]];
547 case LibFunc_pvalloc:
548 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_malloc ? "vec_malloc"
549 : "malloc");
556 break;
557 case LibFunc_memcmp:
566 break;
567 case LibFunc_memchr:
568 case LibFunc_memrchr:
575 break;
576 case LibFunc_modf:
577 case LibFunc_modff:
578 case LibFunc_modfl:
586 break;
587 case LibFunc_memcpy:
593 Changed |= setReturnedArg(F, 0);
599 break;
600 case LibFunc_memmove:
605 Changed |= setReturnedArg(F, 0);
610 break;
611 case LibFunc_mempcpy:
612 case LibFunc_memccpy:
614 [[fallthrough]];
615 case LibFunc_memcpy_chk:
625 break;
626 case LibFunc_memalign:
627 Changed |= setAllocFamily(F, "malloc");
630 Changed |= setAllocSize(F, 1, std::nullopt);
637 break;
638 case LibFunc_mkdir:
643 break;
644 case LibFunc_mktime:
649 break;
650 case LibFunc_realloc:
651 case LibFunc_reallocf:
652 case LibFunc_vec_realloc:
654 F, TheLibFunc == LibFunc_vec_realloc ? "vec_malloc" : "malloc");
657 Changed |= setAllocSize(F, 1, std::nullopt);
664 Changed |= setArgNoUndef(F, 1);
665 break;
666 case LibFunc_reallocarray:
667 Changed |= setAllocFamily(F, "malloc");
670 Changed |= setAllocSize(F, 1, 2);
677 Changed |= setArgNoUndef(F, 1);
678 Changed |= setArgNoUndef(F, 2);
679 break;
680 case LibFunc_read:
681 // May throw; "read" is a valid pthread cancellation point.
684 break;
685 case LibFunc_rewind:
689 break;
690 case LibFunc_rmdir:
691 case LibFunc_remove:
692 case LibFunc_realpath:
697 break;
698 case LibFunc_rename:
705 break;
706 case LibFunc_readlink:
712 break;
713 case LibFunc_write:
714 // May throw; "write" is a valid pthread cancellation point.
718 break;
719 case LibFunc_bcopy:
729 break;
730 case LibFunc_bcmp:
739 break;
740 case LibFunc_bzero:
748 break;
749 case LibFunc_calloc:
750 case LibFunc_vec_calloc:
751 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_calloc ? "vec_malloc"
752 : "malloc");
754 Changed |= setAllocSize(F, 0, 1);
760 break;
761 case LibFunc_chmod:
762 case LibFunc_chown:
767 break;
768 case LibFunc_ctermid:
769 case LibFunc_clearerr:
770 case LibFunc_closedir:
774 break;
775 case LibFunc_atoi:
776 case LibFunc_atol:
777 case LibFunc_atof:
778 case LibFunc_atoll:
785 break;
786 case LibFunc_access:
791 break;
792 case LibFunc_fopen:
800 break;
801 case LibFunc_fdopen:
807 break;
808 case LibFunc_feof:
812 break;
813 case LibFunc_free:
814 case LibFunc_vec_free:
815 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_free ? "vec_malloc"
816 : "malloc");
824 break;
825 case LibFunc_fseek:
826 case LibFunc_ftell:
827 case LibFunc_fgetc:
828 case LibFunc_fgetc_unlocked:
829 case LibFunc_fseeko:
830 case LibFunc_ftello:
831 case LibFunc_fileno:
832 case LibFunc_fflush:
833 case LibFunc_fclose:
834 case LibFunc_fsetpos:
835 case LibFunc_flockfile:
836 case LibFunc_funlockfile:
837 case LibFunc_ftrylockfile:
841 break;
842 case LibFunc_ferror:
847 break;
848 case LibFunc_fputc:
849 case LibFunc_fputc_unlocked:
850 case LibFunc_fstat:
854 break;
855 case LibFunc_frexp:
856 case LibFunc_frexpf:
857 case LibFunc_frexpl:
865 break;
866 case LibFunc_fstatvfs:
870 break;
871 case LibFunc_fgets:
872 case LibFunc_fgets_unlocked:
877 break;
878 case LibFunc_fread:
879 case LibFunc_fread_unlocked:
885 break;
886 case LibFunc_fwrite:
887 case LibFunc_fwrite_unlocked:
893 break;
894 case LibFunc_fputs:
895 case LibFunc_fputs_unlocked:
901 break;
902 case LibFunc_fscanf:
903 case LibFunc_fprintf:
909 break;
910 case LibFunc_fgetpos:
915 break;
916 case LibFunc_getc:
920 break;
921 case LibFunc_getlogin_r:
925 break;
926 case LibFunc_getc_unlocked:
930 break;
931 case LibFunc_getenv:
936 break;
937 case LibFunc_gets:
938 case LibFunc_getchar:
939 case LibFunc_getchar_unlocked:
942 break;
943 case LibFunc_getitimer:
947 break;
948 case LibFunc_getpwnam:
953 break;
954 case LibFunc_ungetc:
958 break;
959 case LibFunc_uname:
963 break;
964 case LibFunc_unlink:
969 break;
970 case LibFunc_unsetenv:
975 break;
976 case LibFunc_utime:
977 case LibFunc_utimes:
984 break;
985 case LibFunc_putc:
986 case LibFunc_putc_unlocked:
990 break;
991 case LibFunc_puts:
992 case LibFunc_printf:
993 case LibFunc_perror:
998 break;
999 case LibFunc_pread:
1000 // May throw; "pread" is a valid pthread cancellation point.
1003 break;
1004 case LibFunc_pwrite:
1005 // May throw; "pwrite" is a valid pthread cancellation point.
1009 break;
1010 case LibFunc_putchar:
1011 case LibFunc_putchar_unlocked:
1014 break;
1015 case LibFunc_popen:
1023 break;
1024 case LibFunc_pclose:
1028 break;
1029 case LibFunc_vscanf:
1034 break;
1035 case LibFunc_vsscanf:
1042 break;
1043 case LibFunc_vfscanf:
1049 break;
1050 case LibFunc_vprintf:
1055 break;
1056 case LibFunc_vfprintf:
1057 case LibFunc_vsprintf:
1063 break;
1064 case LibFunc_vsnprintf:
1070 break;
1071 case LibFunc_open:
1072 // May throw; "open" is a valid pthread cancellation point.
1076 break;
1077 case LibFunc_opendir:
1083 break;
1084 case LibFunc_tmpfile:
1088 break;
1089 case LibFunc_times:
1093 break;
1094 case LibFunc_htonl:
1095 case LibFunc_htons:
1096 case LibFunc_ntohl:
1097 case LibFunc_ntohs:
1101 break;
1102 case LibFunc_lstat:
1108 break;
1109 case LibFunc_lchown:
1114 break;
1115 case LibFunc_qsort:
1116 // May throw/callback; places call through function pointer.
1117 // Cannot give undef pointer/size
1120 break;
1121 case LibFunc_dunder_strndup:
1122 Changed |= setArgNoUndef(F, 1);
1123 [[fallthrough]];
1124 case LibFunc_dunder_strdup:
1130 break;
1131 case LibFunc_dunder_strtok_r:
1136 break;
1137 case LibFunc_under_IO_getc:
1141 break;
1142 case LibFunc_under_IO_putc:
1146 break;
1147 case LibFunc_dunder_isoc99_scanf:
1152 break;
1153 case LibFunc_stat64:
1154 case LibFunc_lstat64:
1155 case LibFunc_statvfs64:
1161 break;
1162 case LibFunc_dunder_isoc99_sscanf:
1169 break;
1170 case LibFunc_fopen64:
1178 break;
1179 case LibFunc_fseeko64:
1180 case LibFunc_ftello64:
1184 break;
1185 case LibFunc_tmpfile64:
1189 break;
1190 case LibFunc_fstat64:
1191 case LibFunc_fstatvfs64:
1195 break;
1196 case LibFunc_open64:
1197 // May throw; "open" is a valid pthread cancellation point.
1201 break;
1202 case LibFunc_gettimeofday:
1203 // Currently some platforms have the restrict keyword on the arguments to
1204 // gettimeofday. To be conservative, do not add noalias to gettimeofday's
1205 // arguments.
1210 break;
1211 case LibFunc_memset_pattern4:
1212 case LibFunc_memset_pattern8:
1213 case LibFunc_memset_pattern16:
1217 [[fallthrough]];
1218 case LibFunc_memset:
1220 [[fallthrough]];
1221 case LibFunc_memset_chk:
1227 break;
1228 case LibFunc_abort:
1229 Changed |= setIsCold(F);
1230 Changed |= setNoReturn(F);
1232 break;
1233 case LibFunc_terminate:
1234 // May callback; terminate_handler may be called
1235 Changed |= setIsCold(F);
1236 Changed |= setNoReturn(F);
1237 break;
1238 case LibFunc_cxa_throw:
1239 Changed |= setIsCold(F);
1240 Changed |= setNoReturn(F);
1241 // Don't add `nofree` on `__cxa_throw`
1242 return Changed;
1243 // int __nvvm_reflect(const char *)
1244 case LibFunc_nvvm_reflect:
1248 break;
1249 case LibFunc_acos:
1250 case LibFunc_acosf:
1251 case LibFunc_acosh:
1252 case LibFunc_acoshf:
1253 case LibFunc_acoshl:
1254 case LibFunc_acosl:
1255 case LibFunc_asin:
1256 case LibFunc_asinf:
1257 case LibFunc_asinh:
1258 case LibFunc_asinhf:
1259 case LibFunc_asinhl:
1260 case LibFunc_asinl:
1261 case LibFunc_atan:
1262 case LibFunc_atan2:
1263 case LibFunc_atan2f:
1264 case LibFunc_atan2l:
1265 case LibFunc_atanf:
1266 case LibFunc_atanh:
1267 case LibFunc_atanhf:
1268 case LibFunc_atanhl:
1269 case LibFunc_atanl:
1270 case LibFunc_cos:
1271 case LibFunc_cosh:
1272 case LibFunc_coshf:
1273 case LibFunc_coshl:
1274 case LibFunc_cosf:
1275 case LibFunc_cosl:
1276 case LibFunc_cospi:
1277 case LibFunc_cospif:
1278 case LibFunc_erf:
1279 case LibFunc_erff:
1280 case LibFunc_erfl:
1281 case LibFunc_tgamma:
1282 case LibFunc_tgammaf:
1283 case LibFunc_tgammal:
1284 case LibFunc_exp:
1285 case LibFunc_expf:
1286 case LibFunc_expl:
1287 case LibFunc_exp2:
1288 case LibFunc_exp2f:
1289 case LibFunc_exp2l:
1290 case LibFunc_expm1:
1291 case LibFunc_expm1f:
1292 case LibFunc_expm1l:
1293 case LibFunc_fdim:
1294 case LibFunc_fdiml:
1295 case LibFunc_fdimf:
1296 case LibFunc_fmod:
1297 case LibFunc_fmodf:
1298 case LibFunc_fmodl:
1299 case LibFunc_hypot:
1300 case LibFunc_hypotf:
1301 case LibFunc_hypotl:
1302 case LibFunc_ldexp:
1303 case LibFunc_ldexpf:
1304 case LibFunc_ldexpl:
1305 case LibFunc_log:
1306 case LibFunc_log10:
1307 case LibFunc_log10f:
1308 case LibFunc_log10l:
1309 case LibFunc_log1p:
1310 case LibFunc_log1pf:
1311 case LibFunc_log1pl:
1312 case LibFunc_log2:
1313 case LibFunc_log2f:
1314 case LibFunc_log2l:
1315 case LibFunc_logb:
1316 case LibFunc_logbf:
1317 case LibFunc_logbl:
1318 case LibFunc_ilogb:
1319 case LibFunc_ilogbf:
1320 case LibFunc_ilogbl:
1321 case LibFunc_logf:
1322 case LibFunc_logl:
1323 case LibFunc_nextafter:
1324 case LibFunc_nextafterf:
1325 case LibFunc_nextafterl:
1326 case LibFunc_nexttoward:
1327 case LibFunc_nexttowardf:
1328 case LibFunc_nexttowardl:
1329 case LibFunc_pow:
1330 case LibFunc_powf:
1331 case LibFunc_powl:
1332 case LibFunc_remainder:
1333 case LibFunc_remainderf:
1334 case LibFunc_remainderl:
1335 case LibFunc_rint:
1336 case LibFunc_rintf:
1337 case LibFunc_rintl:
1338 case LibFunc_scalbln:
1339 case LibFunc_scalblnf:
1340 case LibFunc_scalblnl:
1341 case LibFunc_scalbn:
1342 case LibFunc_scalbnf:
1343 case LibFunc_scalbnl:
1344 case LibFunc_sin:
1345 case LibFunc_sincospif_stret:
1346 case LibFunc_sinf:
1347 case LibFunc_sinh:
1348 case LibFunc_sinhf:
1349 case LibFunc_sinhl:
1350 case LibFunc_sinl:
1351 case LibFunc_sinpi:
1352 case LibFunc_sinpif:
1353 case LibFunc_sqrt:
1354 case LibFunc_sqrtf:
1355 case LibFunc_sqrtl:
1356 case LibFunc_tan:
1357 case LibFunc_tanf:
1358 case LibFunc_tanh:
1359 case LibFunc_tanhf:
1360 case LibFunc_tanhl:
1361 case LibFunc_tanl:
1368 break;
1369 case LibFunc_abs:
1370 case LibFunc_cbrt:
1371 case LibFunc_cbrtf:
1372 case LibFunc_cbrtl:
1373 case LibFunc_copysign:
1374 case LibFunc_copysignf:
1375 case LibFunc_copysignl:
1376 case LibFunc_ceil:
1377 case LibFunc_ceilf:
1378 case LibFunc_ceill:
1379 case LibFunc_fabs:
1380 case LibFunc_fabsf:
1381 case LibFunc_fabsl:
1382 case LibFunc_ffs:
1383 case LibFunc_ffsl:
1384 case LibFunc_ffsll:
1385 case LibFunc_floor:
1386 case LibFunc_floorf:
1387 case LibFunc_floorl:
1388 case LibFunc_fls:
1389 case LibFunc_flsl:
1390 case LibFunc_flsll:
1391 case LibFunc_fmax:
1392 case LibFunc_fmaxf:
1393 case LibFunc_fmaxl:
1394 case LibFunc_fmin:
1395 case LibFunc_fminf:
1396 case LibFunc_fminl:
1397 case LibFunc_fmaximum_num:
1398 case LibFunc_fmaximum_numf:
1399 case LibFunc_fmaximum_numl:
1400 case LibFunc_fminimum_num:
1401 case LibFunc_fminimum_numf:
1402 case LibFunc_fminimum_numl:
1403 case LibFunc_labs:
1404 case LibFunc_llabs:
1405 case LibFunc_nearbyint:
1406 case LibFunc_nearbyintf:
1407 case LibFunc_nearbyintl:
1408 case LibFunc_round:
1409 case LibFunc_roundf:
1410 case LibFunc_roundl:
1411 case LibFunc_roundeven:
1412 case LibFunc_roundevenf:
1413 case LibFunc_roundevenl:
1414 case LibFunc_toascii:
1415 case LibFunc_trunc:
1416 case LibFunc_truncf:
1417 case LibFunc_truncl:
1419 [[fallthrough]];
1420 case LibFunc_isascii:
1421 case LibFunc_isdigit:
1426 break;
1427 case LibFunc_sincos:
1428 case LibFunc_sincosf:
1429 case LibFunc_sincosl:
1432 [[fallthrough]];
1433 case LibFunc_remquo:
1434 case LibFunc_remquof:
1435 case LibFunc_remquol:
1444 break;
1445 default:
1446 // FIXME: It'd be really nice to cover all the library functions we're
1447 // aware of here.
1448 break;
1449 }
1450 // We have to do this step after AllocKind has been inferred on functions so
1451 // we can reliably identify free-like and realloc-like functions.
1452 if (!isLibFreeFunction(&F, TheLibFunc) && !isReallocLikeFn(&F))
1454 return Changed;
1455}
1456
1457static void setArgExtAttr(Function &F, unsigned ArgNo,
1458 const TargetLibraryInfo &TLI, bool Signed = true) {
1459 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Param(Signed);
1460 if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr))
1461 F.addParamAttr(ArgNo, ExtAttr);
1462}
1463
1465 const TargetLibraryInfo &TLI, bool Signed = true) {
1466 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Return(Signed);
1467 if (ExtAttr != Attribute::None && !F.hasRetAttribute(ExtAttr))
1468 F.addRetAttr(ExtAttr);
1469}
1470
1471// Modeled after X86TargetLowering::markLibCallAttributes.
1473 if (!F->arg_size() || F->isVarArg())
1474 return;
1475
1476 const CallingConv::ID CC = F->getCallingConv();
1477 if (CC != CallingConv::C && CC != CallingConv::X86_StdCall)
1478 return;
1479
1480 const Module *M = F->getParent();
1481 unsigned N = M->getNumberRegisterParameters();
1482 if (!N)
1483 return;
1484
1485 const DataLayout &DL = M->getDataLayout();
1486
1487 for (Argument &A : F->args()) {
1488 Type *T = A.getType();
1489 if (!T->isIntOrPtrTy())
1490 continue;
1491
1492 const TypeSize &TS = DL.getTypeAllocSize(T);
1493 if (TS > 8)
1494 continue;
1495
1496 assert(TS <= 4 && "Need to account for parameters larger than word size");
1497 const unsigned NumRegs = TS > 4 ? 2 : 1;
1498 if (N < NumRegs)
1499 return;
1500
1501 N -= NumRegs;
1502 F->addParamAttr(A.getArgNo(), Attribute::InReg);
1503 }
1504}
1505
1507 LibFunc TheLibFunc, FunctionType *T,
1508 AttributeList AttributeList) {
1509 assert(TLI.has(TheLibFunc) &&
1510 "Creating call to non-existing library function.");
1511 StringRef Name = TLI.getName(TheLibFunc);
1512 FunctionCallee C = M->getOrInsertFunction(Name, T, AttributeList);
1513
1514 // Make sure any mandatory argument attributes are added.
1515
1516 // Any outgoing i32 argument should be handled with setArgExtAttr() which
1517 // will add an extension attribute if the target ABI requires it. Adding
1518 // argument extensions is typically done by the front end but when an
1519 // optimizer is building a library call on its own it has to take care of
1520 // this. Each such generated function must be handled here with sign or
1521 // zero extensions as needed. F is retreived with cast<> because we demand
1522 // of the caller to have called isLibFuncEmittable() first.
1523 Function *F = cast<Function>(C.getCallee());
1524 assert(F->getFunctionType() == T && "Function type does not match.");
1525 switch (TheLibFunc) {
1526 case LibFunc_fputc:
1527 case LibFunc_putchar:
1528 setArgExtAttr(*F, 0, TLI);
1529 break;
1530 case LibFunc_ldexp:
1531 case LibFunc_ldexpf:
1532 case LibFunc_ldexpl:
1533 case LibFunc_memchr:
1534 case LibFunc_memrchr:
1535 case LibFunc_strchr:
1536 setArgExtAttr(*F, 1, TLI);
1537 break;
1538 case LibFunc_memccpy:
1539 setArgExtAttr(*F, 2, TLI);
1540 break;
1541
1542 // These are functions that are known to not need any argument extension
1543 // on any target: A size_t argument (which may be an i32 on some targets)
1544 // should not trigger the assert below.
1545 case LibFunc_bcmp:
1546 setRetExtAttr(*F, TLI);
1547 break;
1548 case LibFunc_calloc:
1549 case LibFunc_fwrite:
1550 case LibFunc_malloc:
1551 case LibFunc_memcmp:
1552 case LibFunc_memcpy_chk:
1553 case LibFunc_mempcpy:
1554 case LibFunc_memset_pattern16:
1555 case LibFunc_snprintf:
1556 case LibFunc_stpncpy:
1557 case LibFunc_strlcat:
1558 case LibFunc_strlcpy:
1559 case LibFunc_strncat:
1560 case LibFunc_strncmp:
1561 case LibFunc_strncpy:
1562 case LibFunc_vsnprintf:
1563 break;
1564
1565 default:
1566#ifndef NDEBUG
1567 for (unsigned i = 0; i < T->getNumParams(); i++)
1568 assert(!isa<IntegerType>(T->getParamType(i)) &&
1569 "Unhandled integer argument.");
1570#endif
1571 break;
1572 }
1573
1575
1576 return C;
1577}
1578
1580 LibFunc TheLibFunc, FunctionType *T) {
1581 return getOrInsertLibFunc(M, TLI, TheLibFunc, T, AttributeList());
1582}
1583
1585 LibFunc TheLibFunc) {
1586 StringRef FuncName = TLI->getName(TheLibFunc);
1587 if (!TLI->has(TheLibFunc))
1588 return false;
1589
1590 // Check if the Module already has a GlobalValue with the same name, in
1591 // which case it must be a Function with the expected type.
1592 if (GlobalValue *GV = M->getNamedValue(FuncName)) {
1593 if (auto *F = dyn_cast<Function>(GV))
1594 return TLI->isValidProtoForLibFunc(*F->getFunctionType(), TheLibFunc, *M);
1595 return false;
1596 }
1597
1598 return true;
1599}
1600
1602 StringRef Name) {
1603 LibFunc TheLibFunc;
1604 return TLI->getLibFunc(Name, TheLibFunc) &&
1605 isLibFuncEmittable(M, TLI, TheLibFunc);
1606}
1607
1608bool llvm::hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty,
1609 LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
1610 switch (Ty->getTypeID()) {
1611 case Type::HalfTyID:
1612 return false;
1613 case Type::FloatTyID:
1614 return isLibFuncEmittable(M, TLI, FloatFn);
1615 case Type::DoubleTyID:
1616 return isLibFuncEmittable(M, TLI, DoubleFn);
1617 default:
1618 return isLibFuncEmittable(M, TLI, LongDoubleFn);
1619 }
1620}
1621
1623 Type *Ty, LibFunc DoubleFn, LibFunc FloatFn,
1624 LibFunc LongDoubleFn, LibFunc &TheLibFunc) {
1625 assert(hasFloatFn(M, TLI, Ty, DoubleFn, FloatFn, LongDoubleFn) &&
1626 "Cannot get name for unavailable function!");
1627
1628 switch (Ty->getTypeID()) {
1629 case Type::HalfTyID:
1630 llvm_unreachable("No name for HalfTy!");
1631 case Type::FloatTyID:
1632 TheLibFunc = FloatFn;
1633 return TLI->getName(FloatFn);
1634 case Type::DoubleTyID:
1635 TheLibFunc = DoubleFn;
1636 return TLI->getName(DoubleFn);
1637 default:
1638 TheLibFunc = LongDoubleFn;
1639 return TLI->getName(LongDoubleFn);
1640 }
1641}
1642
1643//- Emit LibCalls ------------------------------------------------------------//
1644
1646 return B.getIntNTy(TLI->getIntSize());
1647}
1648
1650 const Module *M = B.GetInsertBlock()->getModule();
1651 return B.getIntNTy(TLI->getSizeTSize(*M));
1652}
1653
1654static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
1655 ArrayRef<Type *> ParamTypes,
1657 const TargetLibraryInfo *TLI,
1658 bool IsVaArgs = false) {
1659 Module *M = B.GetInsertBlock()->getModule();
1660 if (!isLibFuncEmittable(M, TLI, TheLibFunc))
1661 return nullptr;
1662
1663 StringRef FuncName = TLI->getName(TheLibFunc);
1664 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1665 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, FuncType);
1666 inferNonMandatoryLibFuncAttrs(M, FuncName, *TLI);
1667 CallInst *CI = B.CreateCall(Callee, Operands, FuncName);
1668 if (const Function *F =
1669 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1670 CI->setCallingConv(F->getCallingConv());
1671 return CI;
1672}
1673
1675 const TargetLibraryInfo *TLI) {
1676 Type *CharPtrTy = B.getPtrTy();
1677 Type *SizeTTy = getSizeTTy(B, TLI);
1678 return emitLibCall(LibFunc_strlen, SizeTTy, CharPtrTy, Ptr, B, TLI);
1679}
1680
1682 const TargetLibraryInfo *TLI) {
1683 assert(Ptr && Ptr->getType()->isPointerTy() &&
1684 "Argument to wcslen intrinsic must be a pointer.");
1685 Type *PtrTy = B.getPtrTy();
1686 Type *SizeTTy = getSizeTTy(B, TLI);
1687 return emitLibCall(LibFunc_wcslen, SizeTTy, PtrTy, Ptr, B, TLI);
1688}
1689
1691 const TargetLibraryInfo *TLI) {
1692 Type *CharPtrTy = B.getPtrTy();
1693 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy, Ptr, B, TLI);
1694}
1695
1697 const TargetLibraryInfo *TLI) {
1698 Type *CharPtrTy = B.getPtrTy();
1699 Type *IntTy = getIntTy(B, TLI);
1700 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1701 {Ptr, ConstantInt::get(IntTy, (unsigned char)C)}, B, TLI);
1702}
1703
1705 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1706 Type *CharPtrTy = B.getPtrTy();
1707 Type *IntTy = getIntTy(B, TLI);
1708 Type *SizeTTy = getSizeTTy(B, TLI);
1709 return emitLibCall(
1710 LibFunc_strncmp, IntTy,
1711 {CharPtrTy, CharPtrTy, SizeTTy},
1712 {Ptr1, Ptr2, Len}, B, TLI);
1713}
1714
1716 const TargetLibraryInfo *TLI) {
1717 Type *CharPtrTy = Dst->getType();
1718 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1719 {Dst, Src}, B, TLI);
1720}
1721
1723 const TargetLibraryInfo *TLI) {
1724 Type *CharPtrTy = B.getPtrTy();
1725 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1726 {Dst, Src}, B, TLI);
1727}
1728
1730 const TargetLibraryInfo *TLI) {
1731 Type *CharPtrTy = B.getPtrTy();
1732 Type *SizeTTy = getSizeTTy(B, TLI);
1733 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1734 {Dst, Src, Len}, B, TLI);
1735}
1736
1738 const TargetLibraryInfo *TLI) {
1739 Type *CharPtrTy = B.getPtrTy();
1740 Type *SizeTTy = getSizeTTy(B, TLI);
1741 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1742 {Dst, Src, Len}, B, TLI);
1743}
1744
1745Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
1746 IRBuilderBase &B, const DataLayout &DL,
1747 const TargetLibraryInfo *TLI) {
1748 Module *M = B.GetInsertBlock()->getModule();
1749 if (!isLibFuncEmittable(M, TLI, LibFunc_memcpy_chk))
1750 return nullptr;
1751
1752 AttributeList AS;
1753 AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
1754 Attribute::NoUnwind);
1755 Type *VoidPtrTy = B.getPtrTy();
1756 Type *SizeTTy = getSizeTTy(B, TLI);
1757 FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
1758 AttributeList::get(M->getContext(), AS), VoidPtrTy,
1759 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1760 CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1761 if (const Function *F =
1763 CI->setCallingConv(F->getCallingConv());
1764 return CI;
1765}
1766
1768 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1769 Type *VoidPtrTy = B.getPtrTy();
1770 Type *SizeTTy = getSizeTTy(B, TLI);
1771 return emitLibCall(LibFunc_mempcpy, VoidPtrTy,
1772 {VoidPtrTy, VoidPtrTy, SizeTTy},
1773 {Dst, Src, Len}, B, TLI);
1774}
1775
1777 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1778 Type *VoidPtrTy = B.getPtrTy();
1779 Type *IntTy = getIntTy(B, TLI);
1780 Type *SizeTTy = getSizeTTy(B, TLI);
1781 return emitLibCall(LibFunc_memchr, VoidPtrTy,
1782 {VoidPtrTy, IntTy, SizeTTy},
1783 {Ptr, Val, Len}, B, TLI);
1784}
1785
1787 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1788 Type *VoidPtrTy = B.getPtrTy();
1789 Type *IntTy = getIntTy(B, TLI);
1790 Type *SizeTTy = getSizeTTy(B, TLI);
1791 return emitLibCall(LibFunc_memrchr, VoidPtrTy,
1792 {VoidPtrTy, IntTy, SizeTTy},
1793 {Ptr, Val, Len}, B, TLI);
1794}
1795
1797 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1798 Type *VoidPtrTy = B.getPtrTy();
1799 Type *IntTy = getIntTy(B, TLI);
1800 Type *SizeTTy = getSizeTTy(B, TLI);
1801 return emitLibCall(LibFunc_memcmp, IntTy,
1802 {VoidPtrTy, VoidPtrTy, SizeTTy},
1803 {Ptr1, Ptr2, Len}, B, TLI);
1804}
1805
1807 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1808 Type *VoidPtrTy = B.getPtrTy();
1809 Type *IntTy = getIntTy(B, TLI);
1810 Type *SizeTTy = getSizeTTy(B, TLI);
1811 return emitLibCall(LibFunc_bcmp, IntTy,
1812 {VoidPtrTy, VoidPtrTy, SizeTTy},
1813 {Ptr1, Ptr2, Len}, B, TLI);
1814}
1815
1816Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
1817 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1818 Type *VoidPtrTy = B.getPtrTy();
1819 Type *IntTy = getIntTy(B, TLI);
1820 Type *SizeTTy = getSizeTTy(B, TLI);
1821 return emitLibCall(LibFunc_memccpy, VoidPtrTy,
1822 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1823 {Ptr1, Ptr2, Val, Len}, B, TLI);
1824}
1825
1827 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1828 const TargetLibraryInfo *TLI) {
1829 Type *CharPtrTy = B.getPtrTy();
1830 Type *IntTy = getIntTy(B, TLI);
1831 Type *SizeTTy = getSizeTTy(B, TLI);
1832 SmallVector<Value *, 8> Args{Dest, Size, Fmt};
1833 llvm::append_range(Args, VariadicArgs);
1834 return emitLibCall(LibFunc_snprintf, IntTy,
1835 {CharPtrTy, SizeTTy, CharPtrTy},
1836 Args, B, TLI, /*IsVaArgs=*/true);
1837}
1838
1840 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1841 const TargetLibraryInfo *TLI) {
1842 Type *CharPtrTy = B.getPtrTy();
1843 Type *IntTy = getIntTy(B, TLI);
1844 SmallVector<Value *, 8> Args{Dest, Fmt};
1845 llvm::append_range(Args, VariadicArgs);
1846 return emitLibCall(LibFunc_sprintf, IntTy,
1847 {CharPtrTy, CharPtrTy}, Args, B, TLI,
1848 /*IsVaArgs=*/true);
1849}
1850
1852 const TargetLibraryInfo *TLI) {
1853 Type *CharPtrTy = B.getPtrTy();
1854 return emitLibCall(LibFunc_strcat, CharPtrTy,
1855 {CharPtrTy, CharPtrTy},
1856 {Dest, Src}, B, TLI);
1857}
1858
1860 const TargetLibraryInfo *TLI) {
1861 Type *CharPtrTy = B.getPtrTy();
1862 Type *SizeTTy = getSizeTTy(B, TLI);
1863 return emitLibCall(LibFunc_strlcpy, SizeTTy,
1864 {CharPtrTy, CharPtrTy, SizeTTy},
1865 {Dest, Src, Size}, B, TLI);
1866}
1867
1869 const TargetLibraryInfo *TLI) {
1870 Type *CharPtrTy = B.getPtrTy();
1871 Type *SizeTTy = getSizeTTy(B, TLI);
1872 return emitLibCall(LibFunc_strlcat, SizeTTy,
1873 {CharPtrTy, CharPtrTy, SizeTTy},
1874 {Dest, Src, Size}, B, TLI);
1875}
1876
1878 const TargetLibraryInfo *TLI) {
1879 Type *CharPtrTy = B.getPtrTy();
1880 Type *SizeTTy = getSizeTTy(B, TLI);
1881 return emitLibCall(LibFunc_strncat, CharPtrTy,
1882 {CharPtrTy, CharPtrTy, SizeTTy},
1883 {Dest, Src, Size}, B, TLI);
1884}
1885
1887 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1888 Type *CharPtrTy = B.getPtrTy();
1889 Type *IntTy = getIntTy(B, TLI);
1890 Type *SizeTTy = getSizeTTy(B, TLI);
1891 return emitLibCall(
1892 LibFunc_vsnprintf, IntTy,
1893 {CharPtrTy, SizeTTy, CharPtrTy, VAList->getType()},
1894 {Dest, Size, Fmt, VAList}, B, TLI);
1895}
1896
1898 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1899 Type *CharPtrTy = B.getPtrTy();
1900 Type *IntTy = getIntTy(B, TLI);
1901 return emitLibCall(LibFunc_vsprintf, IntTy,
1902 {CharPtrTy, CharPtrTy, VAList->getType()},
1903 {Dest, Fmt, VAList}, B, TLI);
1904}
1905
1906/// Append a suffix to the function name according to the type of 'Op'.
1908 SmallString<20> &NameBuffer) {
1909 if (!Op->getType()->isDoubleTy()) {
1910 NameBuffer += Name;
1911
1912 if (Op->getType()->isFloatTy())
1913 NameBuffer += 'f';
1914 else
1915 NameBuffer += 'l';
1916
1917 Name = NameBuffer;
1918 }
1919}
1920
1921static Value *emitUnaryFloatFnCallHelper(Value *Op, LibFunc TheLibFunc,
1922 StringRef Name, IRBuilderBase &B,
1923 const AttributeList &Attrs,
1924 const TargetLibraryInfo *TLI) {
1925 assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
1926
1927 Module *M = B.GetInsertBlock()->getModule();
1928 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op->getType(),
1929 Op->getType());
1930 CallInst *CI = B.CreateCall(Callee, Op, Name);
1931
1932 // The incoming attribute set may have come from a speculatable intrinsic, but
1933 // is being replaced with a library call which is not allowed to be
1934 // speculatable.
1935 CI->setAttributes(
1936 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1937 if (const Function *F =
1938 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1939 CI->setCallingConv(F->getCallingConv());
1940
1941 return CI;
1942}
1943
1945 StringRef Name, IRBuilderBase &B,
1946 const AttributeList &Attrs) {
1947 SmallString<20> NameBuffer;
1948 appendTypeSuffix(Op, Name, NameBuffer);
1949
1950 LibFunc TheLibFunc;
1951 TLI->getLibFunc(Name, TheLibFunc);
1952
1953 return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1954}
1955
1957 LibFunc DoubleFn, LibFunc FloatFn,
1958 LibFunc LongDoubleFn, IRBuilderBase &B,
1959 const AttributeList &Attrs) {
1960 // Get the name of the function according to TLI.
1961 Module *M = B.GetInsertBlock()->getModule();
1962 LibFunc TheLibFunc;
1963 StringRef Name = getFloatFn(M, TLI, Op->getType(), DoubleFn, FloatFn,
1964 LongDoubleFn, TheLibFunc);
1965
1966 return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1967}
1968
1970 LibFunc TheLibFunc,
1971 StringRef Name, IRBuilderBase &B,
1972 const AttributeList &Attrs,
1973 const TargetLibraryInfo *TLI) {
1974 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1975
1976 Module *M = B.GetInsertBlock()->getModule();
1977 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op1->getType(),
1978 Op1->getType(), Op2->getType());
1979 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
1980 CallInst *CI = B.CreateCall(Callee, { Op1, Op2 }, Name);
1981
1982 // The incoming attribute set may have come from a speculatable intrinsic, but
1983 // is being replaced with a library call which is not allowed to be
1984 // speculatable.
1985 CI->setAttributes(
1986 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1987 if (const Function *F =
1988 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1989 CI->setCallingConv(F->getCallingConv());
1990
1991 return CI;
1992}
1993
1995 const TargetLibraryInfo *TLI,
1996 StringRef Name, IRBuilderBase &B,
1997 const AttributeList &Attrs) {
1998 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1999
2000 SmallString<20> NameBuffer;
2001 appendTypeSuffix(Op1, Name, NameBuffer);
2002
2003 LibFunc TheLibFunc;
2004 TLI->getLibFunc(Name, TheLibFunc);
2005
2006 return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
2007}
2008
2010 const TargetLibraryInfo *TLI,
2011 LibFunc DoubleFn, LibFunc FloatFn,
2012 LibFunc LongDoubleFn, IRBuilderBase &B,
2013 const AttributeList &Attrs) {
2014 // Get the name of the function according to TLI.
2015 Module *M = B.GetInsertBlock()->getModule();
2016 LibFunc TheLibFunc;
2017 StringRef Name = getFloatFn(M, TLI, Op1->getType(), DoubleFn, FloatFn,
2018 LongDoubleFn, TheLibFunc);
2019
2020 return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
2021}
2022
2023// Emit a call to putchar(int) with Char as the argument. Char must have
2024// the same precision as int, which need not be 32 bits.
2026 const TargetLibraryInfo *TLI) {
2027 Module *M = B.GetInsertBlock()->getModule();
2028 if (!isLibFuncEmittable(M, TLI, LibFunc_putchar))
2029 return nullptr;
2030
2031 Type *IntTy = getIntTy(B, TLI);
2032 StringRef PutCharName = TLI->getName(LibFunc_putchar);
2033 FunctionCallee PutChar = getOrInsertLibFunc(M, *TLI, LibFunc_putchar,
2034 IntTy, IntTy);
2035 inferNonMandatoryLibFuncAttrs(M, PutCharName, *TLI);
2036 CallInst *CI = B.CreateCall(PutChar, Char, PutCharName);
2037
2038 if (const Function *F =
2040 CI->setCallingConv(F->getCallingConv());
2041 return CI;
2042}
2043
2045 const TargetLibraryInfo *TLI) {
2046 Module *M = B.GetInsertBlock()->getModule();
2047 if (!isLibFuncEmittable(M, TLI, LibFunc_puts))
2048 return nullptr;
2049
2050 Type *IntTy = getIntTy(B, TLI);
2051 StringRef PutsName = TLI->getName(LibFunc_puts);
2052 FunctionCallee PutS =
2053 getOrInsertLibFunc(M, *TLI, LibFunc_puts, IntTy, B.getPtrTy());
2054 inferNonMandatoryLibFuncAttrs(M, PutsName, *TLI);
2055 CallInst *CI = B.CreateCall(PutS, Str, PutsName);
2056 if (const Function *F =
2058 CI->setCallingConv(F->getCallingConv());
2059 return CI;
2060}
2061
2063 const TargetLibraryInfo *TLI) {
2064 Module *M = B.GetInsertBlock()->getModule();
2065 if (!isLibFuncEmittable(M, TLI, LibFunc_fputc))
2066 return nullptr;
2067
2068 Type *IntTy = getIntTy(B, TLI);
2069 StringRef FPutcName = TLI->getName(LibFunc_fputc);
2070 FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputc, IntTy,
2071 IntTy, File->getType());
2072 if (File->getType()->isPointerTy())
2073 inferNonMandatoryLibFuncAttrs(M, FPutcName, *TLI);
2074 CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName);
2075
2076 if (const Function *Fn =
2077 dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
2078 CI->setCallingConv(Fn->getCallingConv());
2079 return CI;
2080}
2081
2083 const TargetLibraryInfo *TLI) {
2084 Module *M = B.GetInsertBlock()->getModule();
2085 if (!isLibFuncEmittable(M, TLI, LibFunc_fputs))
2086 return nullptr;
2087
2088 Type *IntTy = getIntTy(B, TLI);
2089 StringRef FPutsName = TLI->getName(LibFunc_fputs);
2090 FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputs, IntTy,
2091 B.getPtrTy(), File->getType());
2092 if (File->getType()->isPointerTy())
2093 inferNonMandatoryLibFuncAttrs(M, FPutsName, *TLI);
2094 CallInst *CI = B.CreateCall(F, {Str, File}, FPutsName);
2095
2096 if (const Function *Fn =
2097 dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
2098 CI->setCallingConv(Fn->getCallingConv());
2099 return CI;
2100}
2101
2103 const DataLayout &DL, const TargetLibraryInfo *TLI) {
2104 Module *M = B.GetInsertBlock()->getModule();
2105 if (!isLibFuncEmittable(M, TLI, LibFunc_fwrite))
2106 return nullptr;
2107
2108 Type *SizeTTy = getSizeTTy(B, TLI);
2109 StringRef FWriteName = TLI->getName(LibFunc_fwrite);
2111 getOrInsertLibFunc(M, *TLI, LibFunc_fwrite, SizeTTy, B.getPtrTy(),
2112 SizeTTy, SizeTTy, File->getType());
2113
2114 if (File->getType()->isPointerTy())
2115 inferNonMandatoryLibFuncAttrs(M, FWriteName, *TLI);
2116 CallInst *CI =
2117 B.CreateCall(F, {Ptr, Size,
2118 ConstantInt::get(SizeTTy, 1), File});
2119
2120 if (const Function *Fn =
2121 dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
2122 CI->setCallingConv(Fn->getCallingConv());
2123 return CI;
2124}
2125
2127 const TargetLibraryInfo *TLI) {
2128 Module *M = B.GetInsertBlock()->getModule();
2129 if (!isLibFuncEmittable(M, TLI, LibFunc_malloc))
2130 return nullptr;
2131
2132 StringRef MallocName = TLI->getName(LibFunc_malloc);
2133 Type *SizeTTy = getSizeTTy(B, TLI);
2135 getOrInsertLibFunc(M, *TLI, LibFunc_malloc, B.getPtrTy(), SizeTTy);
2136 inferNonMandatoryLibFuncAttrs(M, MallocName, *TLI);
2137 CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
2138
2139 if (const Function *F =
2140 dyn_cast<Function>(Malloc.getCallee()->stripPointerCasts()))
2141 CI->setCallingConv(F->getCallingConv());
2142
2143 return CI;
2144}
2145
2147 const TargetLibraryInfo &TLI, unsigned AddrSpace) {
2148 Module *M = B.GetInsertBlock()->getModule();
2149 if (!isLibFuncEmittable(M, &TLI, LibFunc_calloc))
2150 return nullptr;
2151
2152 StringRef CallocName = TLI.getName(LibFunc_calloc);
2153 Type *SizeTTy = getSizeTTy(B, &TLI);
2155 M, TLI, LibFunc_calloc, B.getPtrTy(AddrSpace), SizeTTy, SizeTTy);
2156 inferNonMandatoryLibFuncAttrs(M, CallocName, TLI);
2157 CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
2158
2159 if (const auto *F =
2161 CI->setCallingConv(F->getCallingConv());
2162
2163 return CI;
2164}
2165
2167 const TargetLibraryInfo *TLI,
2168 LibFunc SizeFeedbackNewFunc,
2169 uint8_t HotCold) {
2170 Module *M = B.GetInsertBlock()->getModule();
2171 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2172 return nullptr;
2173
2174 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2175
2176 // __sized_ptr_t struct return type { void*, size_t }
2177 StructType *SizedPtrT =
2178 StructType::get(M->getContext(), {B.getPtrTy(), Num->getType()});
2179 FunctionCallee Func =
2180 M->getOrInsertFunction(Name, SizedPtrT, Num->getType(), B.getInt8Ty());
2181 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2182 CallInst *CI = B.CreateCall(Func, {Num, B.getInt8(HotCold)}, "sized_ptr");
2183
2184 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2185 CI->setCallingConv(F->getCallingConv());
2186
2187 return CI;
2188}
2189
2192 const TargetLibraryInfo *TLI,
2193 LibFunc SizeFeedbackNewFunc,
2194 uint8_t HotCold) {
2195 Module *M = B.GetInsertBlock()->getModule();
2196 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2197 return nullptr;
2198
2199 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2200
2201 // __sized_ptr_t struct return type { void*, size_t }
2202 StructType *SizedPtrT =
2203 StructType::get(M->getContext(), {B.getPtrTy(), Num->getType()});
2204 FunctionCallee Func = M->getOrInsertFunction(Name, SizedPtrT, Num->getType(),
2205 Align->getType(), B.getInt8Ty());
2206 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2207 CallInst *CI =
2208 B.CreateCall(Func, {Num, Align, B.getInt8(HotCold)}, "sized_ptr");
2209
2210 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2211 CI->setCallingConv(F->getCallingConv());
2212
2213 return CI;
2214}
2215
2217 const TargetLibraryInfo *TLI, LibFunc NewFunc,
2218 uint8_t HotCold) {
2219 Module *M = B.GetInsertBlock()->getModule();
2220 if (!isLibFuncEmittable(M, TLI, NewFunc))
2221 return nullptr;
2222
2223 StringRef Name = TLI->getName(NewFunc);
2224 FunctionCallee Func =
2225 M->getOrInsertFunction(Name, B.getPtrTy(), Num->getType(), B.getInt8Ty());
2226 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2227 CallInst *CI = B.CreateCall(Func, {Num, B.getInt8(HotCold)}, Name);
2228
2229 if (const Function *F =
2230 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2231 CI->setCallingConv(F->getCallingConv());
2232
2233 return CI;
2234}
2235
2237 const TargetLibraryInfo *TLI,
2238 LibFunc NewFunc, uint8_t HotCold) {
2239 Module *M = B.GetInsertBlock()->getModule();
2240 if (!isLibFuncEmittable(M, TLI, NewFunc))
2241 return nullptr;
2242
2243 StringRef Name = TLI->getName(NewFunc);
2244 FunctionCallee Func = M->getOrInsertFunction(
2245 Name, B.getPtrTy(), Num->getType(), NoThrow->getType(), B.getInt8Ty());
2246 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2247 CallInst *CI = B.CreateCall(Func, {Num, NoThrow, B.getInt8(HotCold)}, Name);
2248
2249 if (const Function *F =
2250 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2251 CI->setCallingConv(F->getCallingConv());
2252
2253 return CI;
2254}
2255
2257 const TargetLibraryInfo *TLI,
2258 LibFunc NewFunc, uint8_t HotCold) {
2259 Module *M = B.GetInsertBlock()->getModule();
2260 if (!isLibFuncEmittable(M, TLI, NewFunc))
2261 return nullptr;
2262
2263 StringRef Name = TLI->getName(NewFunc);
2264 FunctionCallee Func = M->getOrInsertFunction(
2265 Name, B.getPtrTy(), Num->getType(), Align->getType(), B.getInt8Ty());
2266 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2267 CallInst *CI = B.CreateCall(Func, {Num, Align, B.getInt8(HotCold)}, Name);
2268
2269 if (const Function *F =
2270 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2271 CI->setCallingConv(F->getCallingConv());
2272
2273 return CI;
2274}
2275
2277 Value *NoThrow, IRBuilderBase &B,
2278 const TargetLibraryInfo *TLI,
2279 LibFunc NewFunc, uint8_t HotCold) {
2280 Module *M = B.GetInsertBlock()->getModule();
2281 if (!isLibFuncEmittable(M, TLI, NewFunc))
2282 return nullptr;
2283
2284 StringRef Name = TLI->getName(NewFunc);
2285 FunctionCallee Func = M->getOrInsertFunction(
2286 Name, B.getPtrTy(), Num->getType(), Align->getType(), NoThrow->getType(),
2287 B.getInt8Ty());
2288 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2289 CallInst *CI =
2290 B.CreateCall(Func, {Num, Align, NoThrow, B.getInt8(HotCold)}, Name);
2291
2292 if (const Function *F =
2293 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2294 CI->setCallingConv(F->getCallingConv());
2295
2296 return CI;
2297}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool setRetNoUndef(Function &F)
static bool setOnlyAccessesInaccessibleMemOrArgMemOrErrnoMem(Function &F)
static void appendTypeSuffix(Value *Op, StringRef &Name, SmallString< 20 > &NameBuffer)
Append a suffix to the function name according to the type of 'Op'.
static bool setDoesNotSync(Function &F)
static bool setDoesNotAlias(Function &F, unsigned ArgNo)
static bool setDoesNotAccessMemory(Function &F)
static bool setOnlyAccessesInaccessibleMemOrErrnoMem(Function &F)
static bool setOnlyWritesArgMemOrErrnoMem(Function &F)
static bool setArgsNoUndef(Function &F)
static IntegerType * getSizeTTy(IRBuilderBase &B, const TargetLibraryInfo *TLI)
static Value * emitUnaryFloatFnCallHelper(Value *Op, LibFunc TheLibFunc, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs, const TargetLibraryInfo *TLI)
static bool setAllocatedPointerParam(Function &F, unsigned ArgNo)
static void setRetExtAttr(Function &F, const TargetLibraryInfo &TLI, bool Signed=true)
static bool setMemoryEffects(Function &F, MemoryEffects ME)
static Value * emitLibCall(LibFunc TheLibFunc, Type *ReturnType, ArrayRef< Type * > ParamTypes, ArrayRef< Value * > Operands, IRBuilderBase &B, const TargetLibraryInfo *TLI, bool IsVaArgs=false)
static bool setNonLazyBind(Function &F)
static bool setIsCold(Function &F)
static bool setOnlyAccessesInaccessibleMemOrArgMem(Function &F)
static bool setAllocSize(Function &F, unsigned ElemSizeArg, std::optional< unsigned > NumElemsArg)
static bool setAlignedAllocParam(Function &F, unsigned ArgNo)
static bool setRetAndArgsNoUndef(Function &F)
static bool setRetDoesNotAlias(Function &F)
static bool setReturnedArg(Function &F, unsigned ArgNo)
static Value * emitBinaryFloatFnCallHelper(Value *Op1, Value *Op2, LibFunc TheLibFunc, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs, const TargetLibraryInfo *TLI)
static bool setOnlyWritesErrnoMemory(Function &F)
static bool setDoesNotCapture(Function &F, unsigned ArgNo)
static bool setDoesNotThrow(Function &F)
static bool setWillReturn(Function &F)
static bool setAllocKind(Function &F, AllocFnKind K)
static bool setNoReturn(Function &F)
static IntegerType * getIntTy(IRBuilderBase &B, const TargetLibraryInfo *TLI)
static bool setAllocFamily(Function &F, StringRef Family)
static bool setArgNoUndef(Function &F, unsigned ArgNo)
static bool setDoesNotCallback(Function &F)
static void setArgExtAttr(Function &F, unsigned ArgNo, const TargetLibraryInfo &TLI, bool Signed=true)
static bool setOnlyAccessesArgMemory(Function &F)
static bool setOnlyWritesMemory(Function &F)
static bool setOnlyReadsMemory(Function &F)
static bool setDoesNotFreeMemory(Function &F)
static GCRegistry::Add< 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
This file defines the SmallString class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static LLVM_ABI Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:124
@ None
No attributes have been set.
Definition Attributes.h:126
static LLVM_ABI Attribute getWithCaptureInfo(LLVMContext &Context, CaptureInfo CI)
void setCallingConv(CallingConv::ID CC)
void setAttributes(AttributeList A)
Set the attributes for this call.
This class represents a function call, abstracting a target machine's calling convention.
static CaptureInfo none()
Create CaptureInfo that does not capture any components of the pointer.
Definition ModRef.h:427
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Class to represent function types.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
Class to represent integer types.
static MemoryEffectsBase readOnly()
Definition ModRef.h:133
static MemoryEffectsBase inaccessibleOrArgOrErrnoMemOnly(ModRefInfo InaccessibleOrArgMR=ModRefInfo::ModRef, ModRefInfo ErrnoMR=ModRefInfo::ModRef)
Definition ModRef.h:186
static MemoryEffectsBase argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:143
static MemoryEffectsBase errnoMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:154
static MemoryEffectsBase writeOnly()
Definition ModRef.h:138
static MemoryEffectsBase inaccessibleOrArgMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Definition ModRef.h:166
static MemoryEffectsBase argumentOrErrnoMemOnly(ModRefInfo ArgMR=ModRefInfo::ModRef, ModRefInfo ErrnoMR=ModRefInfo::ModRef)
Definition ModRef.h:198
static MemoryEffectsBase inaccessibleOrErrnoMemOnly(ModRefInfo InaccessibleMR=ModRefInfo::ModRef, ModRefInfo ErrnoMR=ModRefInfo::ModRef)
Definition ModRef.h:176
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition Type.cpp:479
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:46
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:282
@ 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:255
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition Value.cpp:712
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ X86_StdCall
stdcall is mostly used by the Win32 API.
Definition CallingConv.h:99
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI Value * emitUnaryFloatFnCall(Value *Op, const TargetLibraryInfo *TLI, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
LLVM_ABI Value * emitStrChr(Value *Ptr, char C, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strchr function to the builder, for the specified pointer and character.
LLVM_ABI Value * emitPutChar(Value *Char, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the putchar function. This assumes that Char is an 'int'.
LLVM_ABI Value * emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the __memcpy_chk function to the builder.
LLVM_ABI Value * emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strncpy function to the builder, for the specified pointer arguments and length.
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:53
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:2207
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
Definition ModRef.h:356
LLVM_ABI bool hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Check whether the overloaded floating point function corresponding to Ty is available.
LLVM_ABI bool inferNonMandatoryLibFuncAttrs(Module *M, StringRef Name, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
LLVM_ABI bool isLibFreeFunction(const Function *F, const LibFunc TLIFn)
isLibFreeFunction - Returns true if the function is a builtin free()
LLVM_ABI Value * 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.
@ 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 * 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