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