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");
64
66 if (F.doesNotAccessMemory())
67 return false;
68 F.setDoesNotAccessMemory();
69 ++NumReadNone;
70 return true;
71}
72
73static bool setIsCold(Function &F) {
74 if (F.hasFnAttribute(Attribute::Cold))
75 return false;
76 F.addFnAttr(Attribute::Cold);
77 ++NumCold;
78 return true;
79}
80
81static bool setNoReturn(Function &F) {
82 if (F.hasFnAttribute(Attribute::NoReturn))
83 return false;
84 F.addFnAttr(Attribute::NoReturn);
85 ++NumNoReturn;
86 return true;
87}
88
90 MemoryEffects OrigME = F.getMemoryEffects();
91 MemoryEffects NewME = OrigME & ME;
92 if (OrigME == NewME)
93 return false;
94 F.setMemoryEffects(NewME);
95 return true;
96}
97
100 return false;
101 ++NumReadOnly;
102 return true;
103}
104
107 return false;
108 ++NumWriteOnly;
109 return true;
110}
111
114 return false;
115 ++NumArgMemOnly;
116 return true;
117}
118
121 return false;
122 ++NumInaccessibleMemOrArgMemOnly;
123 return true;
124}
125
129 return false;
130 ++NumInaccessibleMemOrErrnoMemOnly;
131 return true;
132}
133
137 return false;
138 ++NumInaccessibleMemOrArgMemOrErrnoMemOnly;
139 return true;
140}
141
144 return false;
145 ++NumWriteErrnoMemOnly;
146 return true;
147}
148
152 return false;
153 ++NumWriteArgumentMemOrErrnoMemOnly;
154 return true;
155}
156
158 if (F.doesNotThrow())
159 return false;
160 F.setDoesNotThrow();
161 ++NumNoUnwind;
162 return true;
163}
164
166 if (F.hasFnAttribute(Attribute::NoCallback))
167 return false;
168 F.addFnAttr(Attribute::NoCallback);
169 ++NumNoCallback;
170 return true;
171}
172
174 if (F.hasRetAttribute(Attribute::NoAlias))
175 return false;
176 F.addRetAttr(Attribute::NoAlias);
177 ++NumNoAlias;
178 return true;
179}
180
181static bool setDoesNotCapture(Function &F, unsigned ArgNo) {
182 if (F.hasParamAttribute(ArgNo, Attribute::Captures))
183 return false;
184 F.addParamAttr(ArgNo, Attribute::getWithCaptureInfo(F.getContext(),
186 ++NumNoCapture;
187 return true;
188}
189
190static bool setDoesNotAlias(Function &F, unsigned ArgNo) {
191 if (F.hasParamAttribute(ArgNo, Attribute::NoAlias))
192 return false;
193 F.addParamAttr(ArgNo, Attribute::NoAlias);
194 ++NumNoAlias;
195 return true;
196}
197
198static bool setOnlyReadsMemory(Function &F, unsigned ArgNo) {
199 if (F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
200 return false;
201 F.addParamAttr(ArgNo, Attribute::ReadOnly);
202 ++NumReadOnlyArg;
203 return true;
204}
205
206static bool setOnlyWritesMemory(Function &F, unsigned ArgNo) {
207 if (F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
208 return false;
209 F.addParamAttr(ArgNo, Attribute::WriteOnly);
210 ++NumWriteOnlyArg;
211 return true;
212}
213
214static bool setRetNoUndef(Function &F) {
215 if (!F.getReturnType()->isVoidTy() &&
216 !F.hasRetAttribute(Attribute::NoUndef)) {
217 F.addRetAttr(Attribute::NoUndef);
218 ++NumNoUndef;
219 return true;
220 }
221 return false;
222}
223
224static bool setArgsNoUndef(Function &F) {
225 bool Changed = false;
226 for (unsigned ArgNo = 0; ArgNo < F.arg_size(); ++ArgNo) {
227 if (!F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
228 F.addParamAttr(ArgNo, Attribute::NoUndef);
229 ++NumNoUndef;
230 Changed = true;
231 }
232 }
233 return Changed;
234}
235
236static bool setArgNoUndef(Function &F, unsigned ArgNo) {
237 if (F.hasParamAttribute(ArgNo, Attribute::NoUndef))
238 return false;
239 F.addParamAttr(ArgNo, Attribute::NoUndef);
240 ++NumNoUndef;
241 return true;
242}
243
245 bool UndefAdded = false;
246 UndefAdded |= setRetNoUndef(F);
247 UndefAdded |= setArgsNoUndef(F);
248 return UndefAdded;
249}
250
251static bool setReturnedArg(Function &F, unsigned ArgNo) {
252 if (F.hasParamAttribute(ArgNo, Attribute::Returned))
253 return false;
254 F.addParamAttr(ArgNo, Attribute::Returned);
255 ++NumReturnedArg;
256 return true;
257}
258
259static bool setNonLazyBind(Function &F) {
260 if (F.hasFnAttribute(Attribute::NonLazyBind))
261 return false;
262 F.addFnAttr(Attribute::NonLazyBind);
263 return true;
264}
265
267 if (F.hasFnAttribute(Attribute::NoFree))
268 return false;
269 F.addFnAttr(Attribute::NoFree);
270 return true;
271}
272
273static bool setWillReturn(Function &F) {
274 if (F.hasFnAttribute(Attribute::WillReturn))
275 return false;
276 F.addFnAttr(Attribute::WillReturn);
277 ++NumWillReturn;
278 return true;
279}
280
281static bool setAlignedAllocParam(Function &F, unsigned ArgNo) {
282 if (F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
283 return false;
284 F.addParamAttr(ArgNo, Attribute::AllocAlign);
285 return true;
286}
287
288static bool setAllocatedPointerParam(Function &F, unsigned ArgNo) {
289 if (F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
290 return false;
291 F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
292 return true;
293}
294
295static bool setAllocSize(Function &F, unsigned ElemSizeArg,
296 std::optional<unsigned> NumElemsArg) {
297 if (F.hasFnAttribute(Attribute::AllocSize))
298 return false;
299 F.addFnAttr(Attribute::getWithAllocSizeArgs(F.getContext(), ElemSizeArg,
300 NumElemsArg));
301 return true;
302}
303
304static bool setAllocFamily(Function &F, StringRef Family) {
305 if (F.hasFnAttribute("alloc-family"))
306 return false;
307 F.addFnAttr("alloc-family", Family);
308 return true;
309}
310
312 if (F.hasFnAttribute(Attribute::AllocKind))
313 return false;
314 F.addFnAttr(
315 Attribute::get(F.getContext(), Attribute::AllocKind, uint64_t(K)));
316 return true;
317}
318
320 const TargetLibraryInfo &TLI) {
321 Function *F = M->getFunction(Name);
322 if (!F)
323 return false;
324 return inferNonMandatoryLibFuncAttrs(*F, TLI);
325}
326
328 const TargetLibraryInfo &TLI) {
329 LibFunc TheLibFunc;
330 if (!(TLI.getLibFunc(F, TheLibFunc) && TLI.has(TheLibFunc)))
331 return false;
332
333 bool Changed = false;
334
335 if (F.getParent() != nullptr && F.getParent()->getRtLibUseGOT())
337
338 switch (TheLibFunc) {
339 case LibFunc_nan:
340 case LibFunc_nanf:
341 case LibFunc_nanl:
342 case LibFunc_strlen:
343 case LibFunc_strnlen:
344 case LibFunc_wcslen:
351 break;
352 case LibFunc_strchr:
353 case LibFunc_strrchr:
359 break;
360 case LibFunc_strtol:
361 case LibFunc_strtod:
362 case LibFunc_strtof:
363 case LibFunc_strtoul:
364 case LibFunc_strtoll:
365 case LibFunc_strtold:
366 case LibFunc_strtoull:
372 break;
373 case LibFunc_strcat:
374 case LibFunc_strncat:
379 Changed |= setReturnedArg(F, 0);
384 break;
385 case LibFunc_strcpy:
386 case LibFunc_strncpy:
387 Changed |= setReturnedArg(F, 0);
388 [[fallthrough]];
389 case LibFunc_stpcpy:
390 case LibFunc_stpncpy:
400 break;
401 case LibFunc_strxfrm:
408 break;
409 case LibFunc_strcmp: // 0,1
410 case LibFunc_strspn: // 0,1
411 case LibFunc_strncmp: // 0,1
412 case LibFunc_strcspn: // 0,1
420 break;
421 case LibFunc_strcoll:
422 case LibFunc_strcasecmp: // 0,1
423 case LibFunc_strncasecmp: //
424 // Those functions may depend on the locale, which may be accessed through
425 // global memory.
432 break;
433 case LibFunc_strstr:
434 case LibFunc_strpbrk:
441 break;
442 case LibFunc_strtok:
443 case LibFunc_strtok_r:
449 break;
450 case LibFunc_scanf:
455 break;
456 case LibFunc_setbuf:
457 case LibFunc_setvbuf:
461 break;
462 case LibFunc_strndup:
463 Changed |= setArgNoUndef(F, 1);
464 [[fallthrough]];
465 case LibFunc_strdup:
466 Changed |= setAllocFamily(F, "malloc");
473 break;
474 case LibFunc_stat:
475 case LibFunc_statvfs:
481 break;
482 case LibFunc_sscanf:
489 break;
490 case LibFunc_sprintf:
498 break;
499 case LibFunc_snprintf:
507 break;
508 case LibFunc_setitimer:
515 break;
516 case LibFunc_system:
517 // May throw; "system" is a valid pthread cancellation point.
521 break;
522 case LibFunc_aligned_alloc:
524 Changed |= setAllocSize(F, 1, std::nullopt);
526 [[fallthrough]];
527 case LibFunc_valloc:
528 case LibFunc_malloc:
529 case LibFunc_vec_malloc:
530 Changed |= setAllocSize(F, 0, std::nullopt);
531 [[fallthrough]];
532 case LibFunc_pvalloc:
533 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_malloc ? "vec_malloc"
534 : "malloc");
541 break;
542 case LibFunc_memcmp:
550 break;
551 case LibFunc_memchr:
552 case LibFunc_memrchr:
558 break;
559 case LibFunc_modf:
560 case LibFunc_modff:
561 case LibFunc_modfl:
568 break;
569 case LibFunc_memcpy:
575 Changed |= setReturnedArg(F, 0);
580 break;
581 case LibFunc_memmove:
586 Changed |= setReturnedArg(F, 0);
590 break;
591 case LibFunc_mempcpy:
592 case LibFunc_memccpy:
594 [[fallthrough]];
595 case LibFunc_memcpy_chk:
604 break;
605 case LibFunc_memalign:
606 Changed |= setAllocFamily(F, "malloc");
609 Changed |= setAllocSize(F, 1, std::nullopt);
616 break;
617 case LibFunc_mkdir:
622 break;
623 case LibFunc_mktime:
628 break;
629 case LibFunc_realloc:
630 case LibFunc_reallocf:
631 case LibFunc_vec_realloc:
633 F, TheLibFunc == LibFunc_vec_realloc ? "vec_malloc" : "malloc");
636 Changed |= setAllocSize(F, 1, std::nullopt);
643 Changed |= setArgNoUndef(F, 1);
644 break;
645 case LibFunc_reallocarray:
646 Changed |= setAllocFamily(F, "malloc");
649 Changed |= setAllocSize(F, 1, 2);
656 Changed |= setArgNoUndef(F, 1);
657 Changed |= setArgNoUndef(F, 2);
658 break;
659 case LibFunc_read:
660 // May throw; "read" is a valid pthread cancellation point.
663 break;
664 case LibFunc_rewind:
668 break;
669 case LibFunc_rmdir:
670 case LibFunc_remove:
671 case LibFunc_realpath:
676 break;
677 case LibFunc_rename:
684 break;
685 case LibFunc_readlink:
691 break;
692 case LibFunc_write:
693 // May throw; "write" is a valid pthread cancellation point.
697 break;
698 case LibFunc_bcopy:
707 break;
708 case LibFunc_bcmp:
716 break;
717 case LibFunc_bzero:
724 break;
725 case LibFunc_calloc:
726 case LibFunc_vec_calloc:
727 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_calloc ? "vec_malloc"
728 : "malloc");
730 Changed |= setAllocSize(F, 0, 1);
736 break;
737 case LibFunc_chmod:
738 case LibFunc_chown:
743 break;
744 case LibFunc_ctermid:
745 case LibFunc_clearerr:
746 case LibFunc_closedir:
750 break;
751 case LibFunc_atoi:
752 case LibFunc_atol:
753 case LibFunc_atof:
754 case LibFunc_atoll:
760 break;
761 case LibFunc_access:
766 break;
767 case LibFunc_fopen:
775 break;
776 case LibFunc_fdopen:
782 break;
783 case LibFunc_feof:
787 break;
788 case LibFunc_free:
789 case LibFunc_vec_free:
790 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_free ? "vec_malloc"
791 : "malloc");
799 break;
800 case LibFunc_fseek:
801 case LibFunc_ftell:
802 case LibFunc_fgetc:
803 case LibFunc_fgetc_unlocked:
804 case LibFunc_fseeko:
805 case LibFunc_ftello:
806 case LibFunc_fileno:
807 case LibFunc_fflush:
808 case LibFunc_fclose:
809 case LibFunc_fsetpos:
810 case LibFunc_flockfile:
811 case LibFunc_funlockfile:
812 case LibFunc_ftrylockfile:
816 break;
817 case LibFunc_ferror:
822 break;
823 case LibFunc_fputc:
824 case LibFunc_fputc_unlocked:
825 case LibFunc_fstat:
829 break;
830 case LibFunc_frexp:
831 case LibFunc_frexpf:
832 case LibFunc_frexpl:
839 break;
840 case LibFunc_fstatvfs:
844 break;
845 case LibFunc_fgets:
846 case LibFunc_fgets_unlocked:
851 break;
852 case LibFunc_fread:
853 case LibFunc_fread_unlocked:
859 break;
860 case LibFunc_fwrite:
861 case LibFunc_fwrite_unlocked:
867 break;
868 case LibFunc_fputs:
869 case LibFunc_fputs_unlocked:
875 break;
876 case LibFunc_fscanf:
877 case LibFunc_fprintf:
883 break;
884 case LibFunc_fgetpos:
889 break;
890 case LibFunc_getc:
894 break;
895 case LibFunc_getlogin_r:
899 break;
900 case LibFunc_getc_unlocked:
904 break;
905 case LibFunc_getenv:
910 break;
911 case LibFunc_gets:
912 case LibFunc_getchar:
913 case LibFunc_getchar_unlocked:
916 break;
917 case LibFunc_getitimer:
921 break;
922 case LibFunc_getpwnam:
927 break;
928 case LibFunc_ungetc:
932 break;
933 case LibFunc_uname:
937 break;
938 case LibFunc_unlink:
943 break;
944 case LibFunc_unsetenv:
949 break;
950 case LibFunc_utime:
951 case LibFunc_utimes:
958 break;
959 case LibFunc_putc:
960 case LibFunc_putc_unlocked:
964 break;
965 case LibFunc_puts:
966 case LibFunc_printf:
967 case LibFunc_perror:
972 break;
973 case LibFunc_pread:
974 // May throw; "pread" is a valid pthread cancellation point.
977 break;
978 case LibFunc_pwrite:
979 // May throw; "pwrite" is a valid pthread cancellation point.
983 break;
984 case LibFunc_putchar:
985 case LibFunc_putchar_unlocked:
988 break;
989 case LibFunc_popen:
997 break;
998 case LibFunc_pclose:
1002 break;
1003 case LibFunc_vscanf:
1008 break;
1009 case LibFunc_vsscanf:
1016 break;
1017 case LibFunc_vfscanf:
1023 break;
1024 case LibFunc_vprintf:
1029 break;
1030 case LibFunc_vfprintf:
1031 case LibFunc_vsprintf:
1037 break;
1038 case LibFunc_vsnprintf:
1044 break;
1045 case LibFunc_open:
1046 // May throw; "open" is a valid pthread cancellation point.
1050 break;
1051 case LibFunc_opendir:
1057 break;
1058 case LibFunc_tmpfile:
1062 break;
1063 case LibFunc_times:
1067 break;
1068 case LibFunc_htonl:
1069 case LibFunc_htons:
1070 case LibFunc_ntohl:
1071 case LibFunc_ntohs:
1075 break;
1076 case LibFunc_lstat:
1082 break;
1083 case LibFunc_lchown:
1088 break;
1089 case LibFunc_qsort:
1090 // May throw/callback; places call through function pointer.
1091 // Cannot give undef pointer/size
1094 break;
1095 case LibFunc_dunder_strndup:
1096 Changed |= setArgNoUndef(F, 1);
1097 [[fallthrough]];
1098 case LibFunc_dunder_strdup:
1104 break;
1105 case LibFunc_dunder_strtok_r:
1110 break;
1111 case LibFunc_under_IO_getc:
1115 break;
1116 case LibFunc_under_IO_putc:
1120 break;
1121 case LibFunc_dunder_isoc99_scanf:
1126 break;
1127 case LibFunc_stat64:
1128 case LibFunc_lstat64:
1129 case LibFunc_statvfs64:
1135 break;
1136 case LibFunc_dunder_isoc99_sscanf:
1143 break;
1144 case LibFunc_fopen64:
1152 break;
1153 case LibFunc_fseeko64:
1154 case LibFunc_ftello64:
1158 break;
1159 case LibFunc_tmpfile64:
1163 break;
1164 case LibFunc_fstat64:
1165 case LibFunc_fstatvfs64:
1169 break;
1170 case LibFunc_open64:
1171 // May throw; "open" is a valid pthread cancellation point.
1175 break;
1176 case LibFunc_gettimeofday:
1177 // Currently some platforms have the restrict keyword on the arguments to
1178 // gettimeofday. To be conservative, do not add noalias to gettimeofday's
1179 // arguments.
1184 break;
1185 case LibFunc_memset_pattern4:
1186 case LibFunc_memset_pattern8:
1187 case LibFunc_memset_pattern16:
1191 [[fallthrough]];
1192 case LibFunc_memset:
1194 [[fallthrough]];
1195 case LibFunc_memset_chk:
1200 break;
1201 case LibFunc_abort:
1202 Changed |= setIsCold(F);
1203 Changed |= setNoReturn(F);
1205 break;
1206 case LibFunc_terminate:
1207 // May callback; terminate_handler may be called
1208 Changed |= setIsCold(F);
1209 Changed |= setNoReturn(F);
1210 break;
1211 case LibFunc_cxa_throw:
1212 Changed |= setIsCold(F);
1213 Changed |= setNoReturn(F);
1214 // Don't add `nofree` on `__cxa_throw`
1215 return Changed;
1216 // int __nvvm_reflect(const char *)
1217 case LibFunc_nvvm_reflect:
1221 break;
1222 case LibFunc_acos:
1223 case LibFunc_acosf:
1224 case LibFunc_acosh:
1225 case LibFunc_acoshf:
1226 case LibFunc_acoshl:
1227 case LibFunc_acosl:
1228 case LibFunc_asin:
1229 case LibFunc_asinf:
1230 case LibFunc_asinh:
1231 case LibFunc_asinhf:
1232 case LibFunc_asinhl:
1233 case LibFunc_asinl:
1234 case LibFunc_atan:
1235 case LibFunc_atan2:
1236 case LibFunc_atan2f:
1237 case LibFunc_atan2l:
1238 case LibFunc_atanf:
1239 case LibFunc_atanh:
1240 case LibFunc_atanhf:
1241 case LibFunc_atanhl:
1242 case LibFunc_atanl:
1243 case LibFunc_cos:
1244 case LibFunc_cosh:
1245 case LibFunc_coshf:
1246 case LibFunc_coshl:
1247 case LibFunc_cosf:
1248 case LibFunc_cosl:
1249 case LibFunc_cospi:
1250 case LibFunc_cospif:
1251 case LibFunc_erf:
1252 case LibFunc_erff:
1253 case LibFunc_erfl:
1254 case LibFunc_tgamma:
1255 case LibFunc_tgammaf:
1256 case LibFunc_tgammal:
1257 case LibFunc_exp:
1258 case LibFunc_expf:
1259 case LibFunc_expl:
1260 case LibFunc_exp2:
1261 case LibFunc_exp2f:
1262 case LibFunc_exp2l:
1263 case LibFunc_expm1:
1264 case LibFunc_expm1f:
1265 case LibFunc_expm1l:
1266 case LibFunc_fdim:
1267 case LibFunc_fdiml:
1268 case LibFunc_fdimf:
1269 case LibFunc_fmod:
1270 case LibFunc_fmodf:
1271 case LibFunc_fmodl:
1272 case LibFunc_hypot:
1273 case LibFunc_hypotf:
1274 case LibFunc_hypotl:
1275 case LibFunc_ldexp:
1276 case LibFunc_ldexpf:
1277 case LibFunc_ldexpl:
1278 case LibFunc_log:
1279 case LibFunc_log10:
1280 case LibFunc_log10f:
1281 case LibFunc_log10l:
1282 case LibFunc_log1p:
1283 case LibFunc_log1pf:
1284 case LibFunc_log1pl:
1285 case LibFunc_log2:
1286 case LibFunc_log2f:
1287 case LibFunc_log2l:
1288 case LibFunc_logb:
1289 case LibFunc_logbf:
1290 case LibFunc_logbl:
1291 case LibFunc_ilogb:
1292 case LibFunc_ilogbf:
1293 case LibFunc_ilogbl:
1294 case LibFunc_logf:
1295 case LibFunc_logl:
1296 case LibFunc_nextafter:
1297 case LibFunc_nextafterf:
1298 case LibFunc_nextafterl:
1299 case LibFunc_nexttoward:
1300 case LibFunc_nexttowardf:
1301 case LibFunc_nexttowardl:
1302 case LibFunc_pow:
1303 case LibFunc_powf:
1304 case LibFunc_powl:
1305 case LibFunc_remainder:
1306 case LibFunc_remainderf:
1307 case LibFunc_remainderl:
1308 case LibFunc_rint:
1309 case LibFunc_rintf:
1310 case LibFunc_rintl:
1311 case LibFunc_scalbln:
1312 case LibFunc_scalblnf:
1313 case LibFunc_scalblnl:
1314 case LibFunc_scalbn:
1315 case LibFunc_scalbnf:
1316 case LibFunc_scalbnl:
1317 case LibFunc_sin:
1318 case LibFunc_sincospif_stret:
1319 case LibFunc_sinf:
1320 case LibFunc_sinh:
1321 case LibFunc_sinhf:
1322 case LibFunc_sinhl:
1323 case LibFunc_sinl:
1324 case LibFunc_sinpi:
1325 case LibFunc_sinpif:
1326 case LibFunc_sqrt:
1327 case LibFunc_sqrtf:
1328 case LibFunc_sqrtl:
1329 case LibFunc_tan:
1330 case LibFunc_tanf:
1331 case LibFunc_tanh:
1332 case LibFunc_tanhf:
1333 case LibFunc_tanhl:
1334 case LibFunc_tanl:
1340 break;
1341 case LibFunc_abs:
1342 case LibFunc_cbrt:
1343 case LibFunc_cbrtf:
1344 case LibFunc_cbrtl:
1345 case LibFunc_copysign:
1346 case LibFunc_copysignf:
1347 case LibFunc_copysignl:
1348 case LibFunc_ceil:
1349 case LibFunc_ceilf:
1350 case LibFunc_ceill:
1351 case LibFunc_fabs:
1352 case LibFunc_fabsf:
1353 case LibFunc_fabsl:
1354 case LibFunc_ffs:
1355 case LibFunc_ffsl:
1356 case LibFunc_ffsll:
1357 case LibFunc_floor:
1358 case LibFunc_floorf:
1359 case LibFunc_floorl:
1360 case LibFunc_fls:
1361 case LibFunc_flsl:
1362 case LibFunc_flsll:
1363 case LibFunc_fmax:
1364 case LibFunc_fmaxf:
1365 case LibFunc_fmaxl:
1366 case LibFunc_fmin:
1367 case LibFunc_fminf:
1368 case LibFunc_fminl:
1369 case LibFunc_fmaximum_num:
1370 case LibFunc_fmaximum_numf:
1371 case LibFunc_fmaximum_numl:
1372 case LibFunc_fminimum_num:
1373 case LibFunc_fminimum_numf:
1374 case LibFunc_fminimum_numl:
1375 case LibFunc_labs:
1376 case LibFunc_llabs:
1377 case LibFunc_nearbyint:
1378 case LibFunc_nearbyintf:
1379 case LibFunc_nearbyintl:
1380 case LibFunc_round:
1381 case LibFunc_roundf:
1382 case LibFunc_roundl:
1383 case LibFunc_roundeven:
1384 case LibFunc_roundevenf:
1385 case LibFunc_roundevenl:
1386 case LibFunc_toascii:
1387 case LibFunc_trunc:
1388 case LibFunc_truncf:
1389 case LibFunc_truncl:
1391 [[fallthrough]];
1392 case LibFunc_isascii:
1393 case LibFunc_isdigit:
1398 break;
1399 case LibFunc_sincos:
1400 case LibFunc_sincosf:
1401 case LibFunc_sincosl:
1404 [[fallthrough]];
1405 case LibFunc_remquo:
1406 case LibFunc_remquof:
1407 case LibFunc_remquol:
1415 break;
1416 default:
1417 // FIXME: It'd be really nice to cover all the library functions we're
1418 // aware of here.
1419 break;
1420 }
1421 // We have to do this step after AllocKind has been inferred on functions so
1422 // we can reliably identify free-like and realloc-like functions.
1423 if (!isLibFreeFunction(&F, TheLibFunc) && !isReallocLikeFn(&F))
1425 return Changed;
1426}
1427
1428static void setArgExtAttr(Function &F, unsigned ArgNo,
1429 const TargetLibraryInfo &TLI, bool Signed = true) {
1430 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Param(Signed);
1431 if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr))
1432 F.addParamAttr(ArgNo, ExtAttr);
1433}
1434
1436 const TargetLibraryInfo &TLI, bool Signed = true) {
1437 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Return(Signed);
1438 if (ExtAttr != Attribute::None && !F.hasRetAttribute(ExtAttr))
1439 F.addRetAttr(ExtAttr);
1440}
1441
1442// Modeled after X86TargetLowering::markLibCallAttributes.
1444 if (!F->arg_size() || F->isVarArg())
1445 return;
1446
1447 const CallingConv::ID CC = F->getCallingConv();
1448 if (CC != CallingConv::C && CC != CallingConv::X86_StdCall)
1449 return;
1450
1451 const Module *M = F->getParent();
1452 unsigned N = M->getNumberRegisterParameters();
1453 if (!N)
1454 return;
1455
1456 const DataLayout &DL = M->getDataLayout();
1457
1458 for (Argument &A : F->args()) {
1459 Type *T = A.getType();
1460 if (!T->isIntOrPtrTy())
1461 continue;
1462
1463 const TypeSize &TS = DL.getTypeAllocSize(T);
1464 if (TS > 8)
1465 continue;
1466
1467 assert(TS <= 4 && "Need to account for parameters larger than word size");
1468 const unsigned NumRegs = TS > 4 ? 2 : 1;
1469 if (N < NumRegs)
1470 return;
1471
1472 N -= NumRegs;
1473 F->addParamAttr(A.getArgNo(), Attribute::InReg);
1474 }
1475}
1476
1478 LibFunc TheLibFunc, FunctionType *T,
1479 AttributeList AttributeList) {
1480 assert(TLI.has(TheLibFunc) &&
1481 "Creating call to non-existing library function.");
1482 StringRef Name = TLI.getName(TheLibFunc);
1483 FunctionCallee C = M->getOrInsertFunction(Name, T, AttributeList);
1484
1485 // Make sure any mandatory argument attributes are added.
1486
1487 // Any outgoing i32 argument should be handled with setArgExtAttr() which
1488 // will add an extension attribute if the target ABI requires it. Adding
1489 // argument extensions is typically done by the front end but when an
1490 // optimizer is building a library call on its own it has to take care of
1491 // this. Each such generated function must be handled here with sign or
1492 // zero extensions as needed. F is retreived with cast<> because we demand
1493 // of the caller to have called isLibFuncEmittable() first.
1494 Function *F = cast<Function>(C.getCallee());
1495 assert(F->getFunctionType() == T && "Function type does not match.");
1496 switch (TheLibFunc) {
1497 case LibFunc_fputc:
1498 case LibFunc_putchar:
1499 setArgExtAttr(*F, 0, TLI);
1500 break;
1501 case LibFunc_ldexp:
1502 case LibFunc_ldexpf:
1503 case LibFunc_ldexpl:
1504 case LibFunc_memchr:
1505 case LibFunc_memrchr:
1506 case LibFunc_strchr:
1507 setArgExtAttr(*F, 1, TLI);
1508 break;
1509 case LibFunc_memccpy:
1510 setArgExtAttr(*F, 2, TLI);
1511 break;
1512
1513 // These are functions that are known to not need any argument extension
1514 // on any target: A size_t argument (which may be an i32 on some targets)
1515 // should not trigger the assert below.
1516 case LibFunc_bcmp:
1517 setRetExtAttr(*F, TLI);
1518 break;
1519 case LibFunc_calloc:
1520 case LibFunc_fwrite:
1521 case LibFunc_malloc:
1522 case LibFunc_memcmp:
1523 case LibFunc_memcpy_chk:
1524 case LibFunc_mempcpy:
1525 case LibFunc_memset_pattern16:
1526 case LibFunc_snprintf:
1527 case LibFunc_stpncpy:
1528 case LibFunc_strlcat:
1529 case LibFunc_strlcpy:
1530 case LibFunc_strncat:
1531 case LibFunc_strncmp:
1532 case LibFunc_strncpy:
1533 case LibFunc_vsnprintf:
1534 break;
1535
1536 default:
1537#ifndef NDEBUG
1538 for (unsigned i = 0; i < T->getNumParams(); i++)
1539 assert(!isa<IntegerType>(T->getParamType(i)) &&
1540 "Unhandled integer argument.");
1541#endif
1542 break;
1543 }
1544
1546
1547 return C;
1548}
1549
1551 LibFunc TheLibFunc, FunctionType *T) {
1552 return getOrInsertLibFunc(M, TLI, TheLibFunc, T, AttributeList());
1553}
1554
1556 LibFunc TheLibFunc) {
1557 StringRef FuncName = TLI->getName(TheLibFunc);
1558 if (!TLI->has(TheLibFunc))
1559 return false;
1560
1561 // Check if the Module already has a GlobalValue with the same name, in
1562 // which case it must be a Function with the expected type.
1563 if (GlobalValue *GV = M->getNamedValue(FuncName)) {
1564 if (auto *F = dyn_cast<Function>(GV))
1565 return TLI->isValidProtoForLibFunc(*F->getFunctionType(), TheLibFunc, *M);
1566 return false;
1567 }
1568
1569 return true;
1570}
1571
1573 StringRef Name) {
1574 LibFunc TheLibFunc;
1575 return TLI->getLibFunc(Name, TheLibFunc) &&
1576 isLibFuncEmittable(M, TLI, TheLibFunc);
1577}
1578
1579bool llvm::hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty,
1580 LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
1581 switch (Ty->getTypeID()) {
1582 case Type::HalfTyID:
1583 return false;
1584 case Type::FloatTyID:
1585 return isLibFuncEmittable(M, TLI, FloatFn);
1586 case Type::DoubleTyID:
1587 return isLibFuncEmittable(M, TLI, DoubleFn);
1588 default:
1589 return isLibFuncEmittable(M, TLI, LongDoubleFn);
1590 }
1591}
1592
1594 Type *Ty, LibFunc DoubleFn, LibFunc FloatFn,
1595 LibFunc LongDoubleFn, LibFunc &TheLibFunc) {
1596 assert(hasFloatFn(M, TLI, Ty, DoubleFn, FloatFn, LongDoubleFn) &&
1597 "Cannot get name for unavailable function!");
1598
1599 switch (Ty->getTypeID()) {
1600 case Type::HalfTyID:
1601 llvm_unreachable("No name for HalfTy!");
1602 case Type::FloatTyID:
1603 TheLibFunc = FloatFn;
1604 return TLI->getName(FloatFn);
1605 case Type::DoubleTyID:
1606 TheLibFunc = DoubleFn;
1607 return TLI->getName(DoubleFn);
1608 default:
1609 TheLibFunc = LongDoubleFn;
1610 return TLI->getName(LongDoubleFn);
1611 }
1612}
1613
1614//- Emit LibCalls ------------------------------------------------------------//
1615
1617 return B.getIntNTy(TLI->getIntSize());
1618}
1619
1621 const Module *M = B.GetInsertBlock()->getModule();
1622 return B.getIntNTy(TLI->getSizeTSize(*M));
1623}
1624
1625static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
1626 ArrayRef<Type *> ParamTypes,
1628 const TargetLibraryInfo *TLI,
1629 bool IsVaArgs = false) {
1630 Module *M = B.GetInsertBlock()->getModule();
1631 if (!isLibFuncEmittable(M, TLI, TheLibFunc))
1632 return nullptr;
1633
1634 StringRef FuncName = TLI->getName(TheLibFunc);
1635 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1636 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, FuncType);
1637 inferNonMandatoryLibFuncAttrs(M, FuncName, *TLI);
1638 CallInst *CI = B.CreateCall(Callee, Operands, FuncName);
1639 if (const Function *F =
1640 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1641 CI->setCallingConv(F->getCallingConv());
1642 return CI;
1643}
1644
1646 const TargetLibraryInfo *TLI) {
1647 Type *CharPtrTy = B.getPtrTy();
1648 Type *SizeTTy = getSizeTTy(B, TLI);
1649 return emitLibCall(LibFunc_strlen, SizeTTy, CharPtrTy, Ptr, B, TLI);
1650}
1651
1653 const TargetLibraryInfo *TLI) {
1654 assert(Ptr && Ptr->getType()->isPointerTy() &&
1655 "Argument to wcslen intrinsic must be a pointer.");
1656 Type *PtrTy = B.getPtrTy();
1657 Type *SizeTTy = getSizeTTy(B, TLI);
1658 return emitLibCall(LibFunc_wcslen, SizeTTy, PtrTy, Ptr, B, TLI);
1659}
1660
1662 const TargetLibraryInfo *TLI) {
1663 Type *CharPtrTy = B.getPtrTy();
1664 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy, Ptr, B, TLI);
1665}
1666
1668 const TargetLibraryInfo *TLI) {
1669 Type *CharPtrTy = B.getPtrTy();
1670 Type *IntTy = getIntTy(B, TLI);
1671 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1672 {Ptr, ConstantInt::get(IntTy, C)}, B, TLI);
1673}
1674
1676 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1677 Type *CharPtrTy = B.getPtrTy();
1678 Type *IntTy = getIntTy(B, TLI);
1679 Type *SizeTTy = getSizeTTy(B, TLI);
1680 return emitLibCall(
1681 LibFunc_strncmp, IntTy,
1682 {CharPtrTy, CharPtrTy, SizeTTy},
1683 {Ptr1, Ptr2, Len}, B, TLI);
1684}
1685
1687 const TargetLibraryInfo *TLI) {
1688 Type *CharPtrTy = Dst->getType();
1689 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1690 {Dst, Src}, B, TLI);
1691}
1692
1694 const TargetLibraryInfo *TLI) {
1695 Type *CharPtrTy = B.getPtrTy();
1696 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1697 {Dst, Src}, B, TLI);
1698}
1699
1701 const TargetLibraryInfo *TLI) {
1702 Type *CharPtrTy = B.getPtrTy();
1703 Type *SizeTTy = getSizeTTy(B, TLI);
1704 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1705 {Dst, Src, Len}, B, TLI);
1706}
1707
1709 const TargetLibraryInfo *TLI) {
1710 Type *CharPtrTy = B.getPtrTy();
1711 Type *SizeTTy = getSizeTTy(B, TLI);
1712 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1713 {Dst, Src, Len}, B, TLI);
1714}
1715
1716Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
1717 IRBuilderBase &B, const DataLayout &DL,
1718 const TargetLibraryInfo *TLI) {
1719 Module *M = B.GetInsertBlock()->getModule();
1720 if (!isLibFuncEmittable(M, TLI, LibFunc_memcpy_chk))
1721 return nullptr;
1722
1723 AttributeList AS;
1724 AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
1725 Attribute::NoUnwind);
1726 Type *VoidPtrTy = B.getPtrTy();
1727 Type *SizeTTy = getSizeTTy(B, TLI);
1728 FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
1729 AttributeList::get(M->getContext(), AS), VoidPtrTy,
1730 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1731 CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1732 if (const Function *F =
1734 CI->setCallingConv(F->getCallingConv());
1735 return CI;
1736}
1737
1739 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1740 Type *VoidPtrTy = B.getPtrTy();
1741 Type *SizeTTy = getSizeTTy(B, TLI);
1742 return emitLibCall(LibFunc_mempcpy, VoidPtrTy,
1743 {VoidPtrTy, VoidPtrTy, SizeTTy},
1744 {Dst, Src, Len}, B, TLI);
1745}
1746
1748 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1749 Type *VoidPtrTy = B.getPtrTy();
1750 Type *IntTy = getIntTy(B, TLI);
1751 Type *SizeTTy = getSizeTTy(B, TLI);
1752 return emitLibCall(LibFunc_memchr, VoidPtrTy,
1753 {VoidPtrTy, IntTy, SizeTTy},
1754 {Ptr, Val, Len}, B, TLI);
1755}
1756
1758 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1759 Type *VoidPtrTy = B.getPtrTy();
1760 Type *IntTy = getIntTy(B, TLI);
1761 Type *SizeTTy = getSizeTTy(B, TLI);
1762 return emitLibCall(LibFunc_memrchr, VoidPtrTy,
1763 {VoidPtrTy, IntTy, SizeTTy},
1764 {Ptr, Val, Len}, B, TLI);
1765}
1766
1768 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1769 Type *VoidPtrTy = B.getPtrTy();
1770 Type *IntTy = getIntTy(B, TLI);
1771 Type *SizeTTy = getSizeTTy(B, TLI);
1772 return emitLibCall(LibFunc_memcmp, IntTy,
1773 {VoidPtrTy, VoidPtrTy, SizeTTy},
1774 {Ptr1, Ptr2, Len}, B, TLI);
1775}
1776
1778 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1779 Type *VoidPtrTy = B.getPtrTy();
1780 Type *IntTy = getIntTy(B, TLI);
1781 Type *SizeTTy = getSizeTTy(B, TLI);
1782 return emitLibCall(LibFunc_bcmp, IntTy,
1783 {VoidPtrTy, VoidPtrTy, SizeTTy},
1784 {Ptr1, Ptr2, Len}, B, TLI);
1785}
1786
1787Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
1788 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1789 Type *VoidPtrTy = B.getPtrTy();
1790 Type *IntTy = getIntTy(B, TLI);
1791 Type *SizeTTy = getSizeTTy(B, TLI);
1792 return emitLibCall(LibFunc_memccpy, VoidPtrTy,
1793 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1794 {Ptr1, Ptr2, Val, Len}, B, TLI);
1795}
1796
1798 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1799 const TargetLibraryInfo *TLI) {
1800 Type *CharPtrTy = B.getPtrTy();
1801 Type *IntTy = getIntTy(B, TLI);
1802 Type *SizeTTy = getSizeTTy(B, TLI);
1803 SmallVector<Value *, 8> Args{Dest, Size, Fmt};
1804 llvm::append_range(Args, VariadicArgs);
1805 return emitLibCall(LibFunc_snprintf, IntTy,
1806 {CharPtrTy, SizeTTy, CharPtrTy},
1807 Args, B, TLI, /*IsVaArgs=*/true);
1808}
1809
1811 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1812 const TargetLibraryInfo *TLI) {
1813 Type *CharPtrTy = B.getPtrTy();
1814 Type *IntTy = getIntTy(B, TLI);
1815 SmallVector<Value *, 8> Args{Dest, Fmt};
1816 llvm::append_range(Args, VariadicArgs);
1817 return emitLibCall(LibFunc_sprintf, IntTy,
1818 {CharPtrTy, CharPtrTy}, Args, B, TLI,
1819 /*IsVaArgs=*/true);
1820}
1821
1823 const TargetLibraryInfo *TLI) {
1824 Type *CharPtrTy = B.getPtrTy();
1825 return emitLibCall(LibFunc_strcat, CharPtrTy,
1826 {CharPtrTy, CharPtrTy},
1827 {Dest, Src}, B, TLI);
1828}
1829
1831 const TargetLibraryInfo *TLI) {
1832 Type *CharPtrTy = B.getPtrTy();
1833 Type *SizeTTy = getSizeTTy(B, TLI);
1834 return emitLibCall(LibFunc_strlcpy, SizeTTy,
1835 {CharPtrTy, CharPtrTy, SizeTTy},
1836 {Dest, Src, Size}, B, TLI);
1837}
1838
1840 const TargetLibraryInfo *TLI) {
1841 Type *CharPtrTy = B.getPtrTy();
1842 Type *SizeTTy = getSizeTTy(B, TLI);
1843 return emitLibCall(LibFunc_strlcat, SizeTTy,
1844 {CharPtrTy, CharPtrTy, SizeTTy},
1845 {Dest, Src, Size}, B, TLI);
1846}
1847
1849 const TargetLibraryInfo *TLI) {
1850 Type *CharPtrTy = B.getPtrTy();
1851 Type *SizeTTy = getSizeTTy(B, TLI);
1852 return emitLibCall(LibFunc_strncat, CharPtrTy,
1853 {CharPtrTy, CharPtrTy, SizeTTy},
1854 {Dest, Src, Size}, B, TLI);
1855}
1856
1858 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1859 Type *CharPtrTy = B.getPtrTy();
1860 Type *IntTy = getIntTy(B, TLI);
1861 Type *SizeTTy = getSizeTTy(B, TLI);
1862 return emitLibCall(
1863 LibFunc_vsnprintf, IntTy,
1864 {CharPtrTy, SizeTTy, CharPtrTy, VAList->getType()},
1865 {Dest, Size, Fmt, VAList}, B, TLI);
1866}
1867
1869 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1870 Type *CharPtrTy = B.getPtrTy();
1871 Type *IntTy = getIntTy(B, TLI);
1872 return emitLibCall(LibFunc_vsprintf, IntTy,
1873 {CharPtrTy, CharPtrTy, VAList->getType()},
1874 {Dest, Fmt, VAList}, B, TLI);
1875}
1876
1877/// Append a suffix to the function name according to the type of 'Op'.
1879 SmallString<20> &NameBuffer) {
1880 if (!Op->getType()->isDoubleTy()) {
1881 NameBuffer += Name;
1882
1883 if (Op->getType()->isFloatTy())
1884 NameBuffer += 'f';
1885 else
1886 NameBuffer += 'l';
1887
1888 Name = NameBuffer;
1889 }
1890}
1891
1892static Value *emitUnaryFloatFnCallHelper(Value *Op, LibFunc TheLibFunc,
1893 StringRef Name, IRBuilderBase &B,
1894 const AttributeList &Attrs,
1895 const TargetLibraryInfo *TLI) {
1896 assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
1897
1898 Module *M = B.GetInsertBlock()->getModule();
1899 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op->getType(),
1900 Op->getType());
1901 CallInst *CI = B.CreateCall(Callee, Op, Name);
1902
1903 // The incoming attribute set may have come from a speculatable intrinsic, but
1904 // is being replaced with a library call which is not allowed to be
1905 // speculatable.
1906 CI->setAttributes(
1907 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1908 if (const Function *F =
1909 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1910 CI->setCallingConv(F->getCallingConv());
1911
1912 return CI;
1913}
1914
1916 StringRef Name, IRBuilderBase &B,
1917 const AttributeList &Attrs) {
1918 SmallString<20> NameBuffer;
1919 appendTypeSuffix(Op, Name, NameBuffer);
1920
1921 LibFunc TheLibFunc;
1922 TLI->getLibFunc(Name, TheLibFunc);
1923
1924 return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1925}
1926
1928 LibFunc DoubleFn, LibFunc FloatFn,
1929 LibFunc LongDoubleFn, IRBuilderBase &B,
1930 const AttributeList &Attrs) {
1931 // Get the name of the function according to TLI.
1932 Module *M = B.GetInsertBlock()->getModule();
1933 LibFunc TheLibFunc;
1934 StringRef Name = getFloatFn(M, TLI, Op->getType(), DoubleFn, FloatFn,
1935 LongDoubleFn, TheLibFunc);
1936
1937 return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1938}
1939
1941 LibFunc TheLibFunc,
1942 StringRef Name, IRBuilderBase &B,
1943 const AttributeList &Attrs,
1944 const TargetLibraryInfo *TLI) {
1945 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1946
1947 Module *M = B.GetInsertBlock()->getModule();
1948 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op1->getType(),
1949 Op1->getType(), Op2->getType());
1950 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
1951 CallInst *CI = B.CreateCall(Callee, { Op1, Op2 }, Name);
1952
1953 // The incoming attribute set may have come from a speculatable intrinsic, but
1954 // is being replaced with a library call which is not allowed to be
1955 // speculatable.
1956 CI->setAttributes(
1957 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1958 if (const Function *F =
1959 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1960 CI->setCallingConv(F->getCallingConv());
1961
1962 return CI;
1963}
1964
1966 const TargetLibraryInfo *TLI,
1967 StringRef Name, IRBuilderBase &B,
1968 const AttributeList &Attrs) {
1969 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1970
1971 SmallString<20> NameBuffer;
1972 appendTypeSuffix(Op1, Name, NameBuffer);
1973
1974 LibFunc TheLibFunc;
1975 TLI->getLibFunc(Name, TheLibFunc);
1976
1977 return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
1978}
1979
1981 const TargetLibraryInfo *TLI,
1982 LibFunc DoubleFn, LibFunc FloatFn,
1983 LibFunc LongDoubleFn, IRBuilderBase &B,
1984 const AttributeList &Attrs) {
1985 // Get the name of the function according to TLI.
1986 Module *M = B.GetInsertBlock()->getModule();
1987 LibFunc TheLibFunc;
1988 StringRef Name = getFloatFn(M, TLI, Op1->getType(), DoubleFn, FloatFn,
1989 LongDoubleFn, TheLibFunc);
1990
1991 return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
1992}
1993
1994// Emit a call to putchar(int) with Char as the argument. Char must have
1995// the same precision as int, which need not be 32 bits.
1997 const TargetLibraryInfo *TLI) {
1998 Module *M = B.GetInsertBlock()->getModule();
1999 if (!isLibFuncEmittable(M, TLI, LibFunc_putchar))
2000 return nullptr;
2001
2002 Type *IntTy = getIntTy(B, TLI);
2003 StringRef PutCharName = TLI->getName(LibFunc_putchar);
2004 FunctionCallee PutChar = getOrInsertLibFunc(M, *TLI, LibFunc_putchar,
2005 IntTy, IntTy);
2006 inferNonMandatoryLibFuncAttrs(M, PutCharName, *TLI);
2007 CallInst *CI = B.CreateCall(PutChar, Char, PutCharName);
2008
2009 if (const Function *F =
2011 CI->setCallingConv(F->getCallingConv());
2012 return CI;
2013}
2014
2016 const TargetLibraryInfo *TLI) {
2017 Module *M = B.GetInsertBlock()->getModule();
2018 if (!isLibFuncEmittable(M, TLI, LibFunc_puts))
2019 return nullptr;
2020
2021 Type *IntTy = getIntTy(B, TLI);
2022 StringRef PutsName = TLI->getName(LibFunc_puts);
2023 FunctionCallee PutS =
2024 getOrInsertLibFunc(M, *TLI, LibFunc_puts, IntTy, B.getPtrTy());
2025 inferNonMandatoryLibFuncAttrs(M, PutsName, *TLI);
2026 CallInst *CI = B.CreateCall(PutS, Str, PutsName);
2027 if (const Function *F =
2029 CI->setCallingConv(F->getCallingConv());
2030 return CI;
2031}
2032
2034 const TargetLibraryInfo *TLI) {
2035 Module *M = B.GetInsertBlock()->getModule();
2036 if (!isLibFuncEmittable(M, TLI, LibFunc_fputc))
2037 return nullptr;
2038
2039 Type *IntTy = getIntTy(B, TLI);
2040 StringRef FPutcName = TLI->getName(LibFunc_fputc);
2041 FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputc, IntTy,
2042 IntTy, File->getType());
2043 if (File->getType()->isPointerTy())
2044 inferNonMandatoryLibFuncAttrs(M, FPutcName, *TLI);
2045 CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName);
2046
2047 if (const Function *Fn =
2048 dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
2049 CI->setCallingConv(Fn->getCallingConv());
2050 return CI;
2051}
2052
2054 const TargetLibraryInfo *TLI) {
2055 Module *M = B.GetInsertBlock()->getModule();
2056 if (!isLibFuncEmittable(M, TLI, LibFunc_fputs))
2057 return nullptr;
2058
2059 Type *IntTy = getIntTy(B, TLI);
2060 StringRef FPutsName = TLI->getName(LibFunc_fputs);
2061 FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputs, IntTy,
2062 B.getPtrTy(), File->getType());
2063 if (File->getType()->isPointerTy())
2064 inferNonMandatoryLibFuncAttrs(M, FPutsName, *TLI);
2065 CallInst *CI = B.CreateCall(F, {Str, File}, FPutsName);
2066
2067 if (const Function *Fn =
2068 dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
2069 CI->setCallingConv(Fn->getCallingConv());
2070 return CI;
2071}
2072
2074 const DataLayout &DL, const TargetLibraryInfo *TLI) {
2075 Module *M = B.GetInsertBlock()->getModule();
2076 if (!isLibFuncEmittable(M, TLI, LibFunc_fwrite))
2077 return nullptr;
2078
2079 Type *SizeTTy = getSizeTTy(B, TLI);
2080 StringRef FWriteName = TLI->getName(LibFunc_fwrite);
2082 getOrInsertLibFunc(M, *TLI, LibFunc_fwrite, SizeTTy, B.getPtrTy(),
2083 SizeTTy, SizeTTy, File->getType());
2084
2085 if (File->getType()->isPointerTy())
2086 inferNonMandatoryLibFuncAttrs(M, FWriteName, *TLI);
2087 CallInst *CI =
2088 B.CreateCall(F, {Ptr, Size,
2089 ConstantInt::get(SizeTTy, 1), File});
2090
2091 if (const Function *Fn =
2092 dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
2093 CI->setCallingConv(Fn->getCallingConv());
2094 return CI;
2095}
2096
2098 const TargetLibraryInfo *TLI) {
2099 Module *M = B.GetInsertBlock()->getModule();
2100 if (!isLibFuncEmittable(M, TLI, LibFunc_malloc))
2101 return nullptr;
2102
2103 StringRef MallocName = TLI->getName(LibFunc_malloc);
2104 Type *SizeTTy = getSizeTTy(B, TLI);
2106 getOrInsertLibFunc(M, *TLI, LibFunc_malloc, B.getPtrTy(), SizeTTy);
2107 inferNonMandatoryLibFuncAttrs(M, MallocName, *TLI);
2108 CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
2109
2110 if (const Function *F =
2111 dyn_cast<Function>(Malloc.getCallee()->stripPointerCasts()))
2112 CI->setCallingConv(F->getCallingConv());
2113
2114 return CI;
2115}
2116
2118 const TargetLibraryInfo &TLI, unsigned AddrSpace) {
2119 Module *M = B.GetInsertBlock()->getModule();
2120 if (!isLibFuncEmittable(M, &TLI, LibFunc_calloc))
2121 return nullptr;
2122
2123 StringRef CallocName = TLI.getName(LibFunc_calloc);
2124 Type *SizeTTy = getSizeTTy(B, &TLI);
2126 M, TLI, LibFunc_calloc, B.getPtrTy(AddrSpace), SizeTTy, SizeTTy);
2127 inferNonMandatoryLibFuncAttrs(M, CallocName, TLI);
2128 CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
2129
2130 if (const auto *F =
2132 CI->setCallingConv(F->getCallingConv());
2133
2134 return CI;
2135}
2136
2138 const TargetLibraryInfo *TLI,
2139 LibFunc SizeFeedbackNewFunc,
2140 uint8_t HotCold) {
2141 Module *M = B.GetInsertBlock()->getModule();
2142 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2143 return nullptr;
2144
2145 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2146
2147 // __sized_ptr_t struct return type { void*, size_t }
2148 StructType *SizedPtrT =
2149 StructType::get(M->getContext(), {B.getPtrTy(), Num->getType()});
2150 FunctionCallee Func =
2151 M->getOrInsertFunction(Name, SizedPtrT, Num->getType(), B.getInt8Ty());
2152 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2153 CallInst *CI = B.CreateCall(Func, {Num, B.getInt8(HotCold)}, "sized_ptr");
2154
2155 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2156 CI->setCallingConv(F->getCallingConv());
2157
2158 return CI;
2159}
2160
2163 const TargetLibraryInfo *TLI,
2164 LibFunc SizeFeedbackNewFunc,
2165 uint8_t HotCold) {
2166 Module *M = B.GetInsertBlock()->getModule();
2167 if (!isLibFuncEmittable(M, TLI, SizeFeedbackNewFunc))
2168 return nullptr;
2169
2170 StringRef Name = TLI->getName(SizeFeedbackNewFunc);
2171
2172 // __sized_ptr_t struct return type { void*, size_t }
2173 StructType *SizedPtrT =
2174 StructType::get(M->getContext(), {B.getPtrTy(), Num->getType()});
2175 FunctionCallee Func = M->getOrInsertFunction(Name, SizedPtrT, Num->getType(),
2176 Align->getType(), B.getInt8Ty());
2177 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2178 CallInst *CI =
2179 B.CreateCall(Func, {Num, Align, B.getInt8(HotCold)}, "sized_ptr");
2180
2181 if (const Function *F = dyn_cast<Function>(Func.getCallee()))
2182 CI->setCallingConv(F->getCallingConv());
2183
2184 return CI;
2185}
2186
2188 const TargetLibraryInfo *TLI, LibFunc NewFunc,
2189 uint8_t HotCold) {
2190 Module *M = B.GetInsertBlock()->getModule();
2191 if (!isLibFuncEmittable(M, TLI, NewFunc))
2192 return nullptr;
2193
2194 StringRef Name = TLI->getName(NewFunc);
2195 FunctionCallee Func =
2196 M->getOrInsertFunction(Name, B.getPtrTy(), Num->getType(), B.getInt8Ty());
2197 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2198 CallInst *CI = B.CreateCall(Func, {Num, B.getInt8(HotCold)}, Name);
2199
2200 if (const Function *F =
2201 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2202 CI->setCallingConv(F->getCallingConv());
2203
2204 return CI;
2205}
2206
2208 const TargetLibraryInfo *TLI,
2209 LibFunc NewFunc, uint8_t HotCold) {
2210 Module *M = B.GetInsertBlock()->getModule();
2211 if (!isLibFuncEmittable(M, TLI, NewFunc))
2212 return nullptr;
2213
2214 StringRef Name = TLI->getName(NewFunc);
2215 FunctionCallee Func = M->getOrInsertFunction(
2216 Name, B.getPtrTy(), Num->getType(), NoThrow->getType(), B.getInt8Ty());
2217 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2218 CallInst *CI = B.CreateCall(Func, {Num, NoThrow, B.getInt8(HotCold)}, Name);
2219
2220 if (const Function *F =
2221 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2222 CI->setCallingConv(F->getCallingConv());
2223
2224 return CI;
2225}
2226
2228 const TargetLibraryInfo *TLI,
2229 LibFunc NewFunc, uint8_t HotCold) {
2230 Module *M = B.GetInsertBlock()->getModule();
2231 if (!isLibFuncEmittable(M, TLI, NewFunc))
2232 return nullptr;
2233
2234 StringRef Name = TLI->getName(NewFunc);
2235 FunctionCallee Func = M->getOrInsertFunction(
2236 Name, B.getPtrTy(), Num->getType(), Align->getType(), B.getInt8Ty());
2237 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2238 CallInst *CI = B.CreateCall(Func, {Num, Align, B.getInt8(HotCold)}, Name);
2239
2240 if (const Function *F =
2241 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2242 CI->setCallingConv(F->getCallingConv());
2243
2244 return CI;
2245}
2246
2248 Value *NoThrow, IRBuilderBase &B,
2249 const TargetLibraryInfo *TLI,
2250 LibFunc NewFunc, uint8_t HotCold) {
2251 Module *M = B.GetInsertBlock()->getModule();
2252 if (!isLibFuncEmittable(M, TLI, NewFunc))
2253 return nullptr;
2254
2255 StringRef Name = TLI->getName(NewFunc);
2256 FunctionCallee Func = M->getOrInsertFunction(
2257 Name, B.getPtrTy(), Num->getType(), Align->getType(), NoThrow->getType(),
2258 B.getInt8Ty());
2259 inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
2260 CallInst *CI =
2261 B.CreateCall(Func, {Num, Align, NoThrow, B.getInt8(HotCold)}, Name);
2262
2263 if (const Function *F =
2264 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2265 CI->setCallingConv(F->getCallingConv());
2266
2267 return CI;
2268}
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 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
ArrayRef - 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:407
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: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:413
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
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:267
@ 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:713
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.
Definition Types.h:26
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:2208
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
Definition ModRef.h:336
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