LLVM 20.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"
22#include "llvm/IR/Function.h"
23#include "llvm/IR/IRBuilder.h"
24#include "llvm/IR/Module.h"
25#include "llvm/IR/Type.h"
27#include <optional>
28
29using namespace llvm;
30
31#define DEBUG_TYPE "build-libcalls"
32
33//- Infer Attributes ---------------------------------------------------------//
34
35STATISTIC(NumReadNone, "Number of functions inferred as readnone");
36STATISTIC(NumInaccessibleMemOnly,
37 "Number of functions inferred as inaccessiblememonly");
38STATISTIC(NumReadOnly, "Number of functions inferred as readonly");
39STATISTIC(NumWriteOnly, "Number of functions inferred as writeonly");
40STATISTIC(NumArgMemOnly, "Number of functions inferred as argmemonly");
41STATISTIC(NumInaccessibleMemOrArgMemOnly,
42 "Number of functions inferred as inaccessiblemem_or_argmemonly");
43STATISTIC(NumNoUnwind, "Number of functions inferred as nounwind");
44STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture");
45STATISTIC(NumWriteOnlyArg, "Number of arguments inferred as writeonly");
46STATISTIC(NumReadOnlyArg, "Number of arguments inferred as readonly");
47STATISTIC(NumNoAlias, "Number of function returns inferred as noalias");
48STATISTIC(NumNoUndef, "Number of function returns inferred as noundef returns");
49STATISTIC(NumReturnedArg, "Number of arguments inferred as returned");
50STATISTIC(NumWillReturn, "Number of functions inferred as willreturn");
51STATISTIC(NumCold, "Number of functions inferred as cold");
52
54 if (F.doesNotAccessMemory())
55 return false;
56 F.setDoesNotAccessMemory();
57 ++NumReadNone;
58 return true;
59}
60
61static bool setIsCold(Function &F) {
62 if (F.hasFnAttribute(Attribute::Cold))
63 return false;
64 F.addFnAttr(Attribute::Cold);
65 ++NumCold;
66 return true;
67}
68
70 if (F.onlyAccessesInaccessibleMemory())
71 return false;
72 F.setOnlyAccessesInaccessibleMemory();
73 ++NumInaccessibleMemOnly;
74 return true;
75}
76
78 if (F.onlyReadsMemory())
79 return false;
80 F.setOnlyReadsMemory();
81 ++NumReadOnly;
82 return true;
83}
84
86 if (F.onlyWritesMemory()) // writeonly or readnone
87 return false;
88 ++NumWriteOnly;
89 F.setOnlyWritesMemory();
90 return true;
91}
92
94 if (F.onlyAccessesArgMemory())
95 return false;
96 F.setOnlyAccessesArgMemory();
97 ++NumArgMemOnly;
98 return true;
99}
100
102 if (F.onlyAccessesInaccessibleMemOrArgMem())
103 return false;
104 F.setOnlyAccessesInaccessibleMemOrArgMem();
105 ++NumInaccessibleMemOrArgMemOnly;
106 return true;
107}
108
110 if (F.doesNotThrow())
111 return false;
112 F.setDoesNotThrow();
113 ++NumNoUnwind;
114 return true;
115}
116
118 if (F.hasRetAttribute(Attribute::NoAlias))
119 return false;
120 F.addRetAttr(Attribute::NoAlias);
121 ++NumNoAlias;
122 return true;
123}
124
125static bool setDoesNotCapture(Function &F, unsigned ArgNo) {
126 if (F.hasParamAttribute(ArgNo, Attribute::NoCapture))
127 return false;
128 F.addParamAttr(ArgNo, Attribute::NoCapture);
129 ++NumNoCapture;
130 return true;
131}
132
133static bool setDoesNotAlias(Function &F, unsigned ArgNo) {
134 if (F.hasParamAttribute(ArgNo, Attribute::NoAlias))
135 return false;
136 F.addParamAttr(ArgNo, Attribute::NoAlias);
137 ++NumNoAlias;
138 return true;
139}
140
141static bool setOnlyReadsMemory(Function &F, unsigned ArgNo) {
142 if (F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
143 return false;
144 F.addParamAttr(ArgNo, Attribute::ReadOnly);
145 ++NumReadOnlyArg;
146 return true;
147}
148
149static bool setOnlyWritesMemory(Function &F, unsigned ArgNo) {
150 if (F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
151 return false;
152 F.addParamAttr(ArgNo, Attribute::WriteOnly);
153 ++NumWriteOnlyArg;
154 return true;
155}
156
157static bool setRetNoUndef(Function &F) {
158 if (!F.getReturnType()->isVoidTy() &&
159 !F.hasRetAttribute(Attribute::NoUndef)) {
160 F.addRetAttr(Attribute::NoUndef);
161 ++NumNoUndef;
162 return true;
163 }
164 return false;
165}
166
167static bool setArgsNoUndef(Function &F) {
168 bool Changed = false;
169 for (unsigned ArgNo = 0; ArgNo < F.arg_size(); ++ArgNo) {
170 if (!F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
171 F.addParamAttr(ArgNo, Attribute::NoUndef);
172 ++NumNoUndef;
173 Changed = true;
174 }
175 }
176 return Changed;
177}
178
179static bool setArgNoUndef(Function &F, unsigned ArgNo) {
180 if (F.hasParamAttribute(ArgNo, Attribute::NoUndef))
181 return false;
182 F.addParamAttr(ArgNo, Attribute::NoUndef);
183 ++NumNoUndef;
184 return true;
185}
186
188 bool UndefAdded = false;
189 UndefAdded |= setRetNoUndef(F);
190 UndefAdded |= setArgsNoUndef(F);
191 return UndefAdded;
192}
193
194static bool setReturnedArg(Function &F, unsigned ArgNo) {
195 if (F.hasParamAttribute(ArgNo, Attribute::Returned))
196 return false;
197 F.addParamAttr(ArgNo, Attribute::Returned);
198 ++NumReturnedArg;
199 return true;
200}
201
202static bool setNonLazyBind(Function &F) {
203 if (F.hasFnAttribute(Attribute::NonLazyBind))
204 return false;
205 F.addFnAttr(Attribute::NonLazyBind);
206 return true;
207}
208
210 if (F.hasFnAttribute(Attribute::NoFree))
211 return false;
212 F.addFnAttr(Attribute::NoFree);
213 return true;
214}
215
216static bool setWillReturn(Function &F) {
217 if (F.hasFnAttribute(Attribute::WillReturn))
218 return false;
219 F.addFnAttr(Attribute::WillReturn);
220 ++NumWillReturn;
221 return true;
222}
223
224static bool setAlignedAllocParam(Function &F, unsigned ArgNo) {
225 if (F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
226 return false;
227 F.addParamAttr(ArgNo, Attribute::AllocAlign);
228 return true;
229}
230
231static bool setAllocatedPointerParam(Function &F, unsigned ArgNo) {
232 if (F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
233 return false;
234 F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
235 return true;
236}
237
238static bool setAllocSize(Function &F, unsigned ElemSizeArg,
239 std::optional<unsigned> NumElemsArg) {
240 if (F.hasFnAttribute(Attribute::AllocSize))
241 return false;
242 F.addFnAttr(Attribute::getWithAllocSizeArgs(F.getContext(), ElemSizeArg,
243 NumElemsArg));
244 return true;
245}
246
247static bool setAllocFamily(Function &F, StringRef Family) {
248 if (F.hasFnAttribute("alloc-family"))
249 return false;
250 F.addFnAttr("alloc-family", Family);
251 return true;
252}
253
255 if (F.hasFnAttribute(Attribute::AllocKind))
256 return false;
257 F.addFnAttr(
258 Attribute::get(F.getContext(), Attribute::AllocKind, uint64_t(K)));
259 return true;
260}
261
263 const TargetLibraryInfo &TLI) {
264 Function *F = M->getFunction(Name);
265 if (!F)
266 return false;
267 return inferNonMandatoryLibFuncAttrs(*F, TLI);
268}
269
271 const TargetLibraryInfo &TLI) {
272 LibFunc TheLibFunc;
273 if (!(TLI.getLibFunc(F, TheLibFunc) && TLI.has(TheLibFunc)))
274 return false;
275
276 bool Changed = false;
277
278 if (F.getParent() != nullptr && F.getParent()->getRtLibUseGOT())
279 Changed |= setNonLazyBind(F);
280
281 switch (TheLibFunc) {
282 case LibFunc_nan:
283 case LibFunc_nanf:
284 case LibFunc_nanl:
285 case LibFunc_strlen:
286 case LibFunc_strnlen:
287 case LibFunc_wcslen:
288 Changed |= setOnlyReadsMemory(F);
289 Changed |= setDoesNotThrow(F);
290 Changed |= setOnlyAccessesArgMemory(F);
291 Changed |= setWillReturn(F);
292 Changed |= setDoesNotCapture(F, 0);
293 break;
294 case LibFunc_strchr:
295 case LibFunc_strrchr:
296 Changed |= setOnlyAccessesArgMemory(F);
297 Changed |= setOnlyReadsMemory(F);
298 Changed |= setDoesNotThrow(F);
299 Changed |= setWillReturn(F);
300 break;
301 case LibFunc_strtol:
302 case LibFunc_strtod:
303 case LibFunc_strtof:
304 case LibFunc_strtoul:
305 case LibFunc_strtoll:
306 case LibFunc_strtold:
307 case LibFunc_strtoull:
308 Changed |= setDoesNotThrow(F);
309 Changed |= setWillReturn(F);
310 Changed |= setDoesNotCapture(F, 1);
311 Changed |= setOnlyReadsMemory(F, 0);
312 break;
313 case LibFunc_strcat:
314 case LibFunc_strncat:
315 Changed |= setOnlyAccessesArgMemory(F);
316 Changed |= setDoesNotThrow(F);
317 Changed |= setWillReturn(F);
318 Changed |= setReturnedArg(F, 0);
319 Changed |= setDoesNotCapture(F, 1);
320 Changed |= setOnlyReadsMemory(F, 1);
321 Changed |= setDoesNotAlias(F, 0);
322 Changed |= setDoesNotAlias(F, 1);
323 break;
324 case LibFunc_strcpy:
325 case LibFunc_strncpy:
326 Changed |= setReturnedArg(F, 0);
327 [[fallthrough]];
328 case LibFunc_stpcpy:
329 case LibFunc_stpncpy:
330 Changed |= setOnlyAccessesArgMemory(F);
331 Changed |= setDoesNotThrow(F);
332 Changed |= setWillReturn(F);
333 Changed |= setDoesNotCapture(F, 1);
334 Changed |= setOnlyWritesMemory(F, 0);
335 Changed |= setOnlyReadsMemory(F, 1);
336 Changed |= setDoesNotAlias(F, 0);
337 Changed |= setDoesNotAlias(F, 1);
338 break;
339 case LibFunc_strxfrm:
340 Changed |= setDoesNotThrow(F);
341 Changed |= setWillReturn(F);
342 Changed |= setDoesNotCapture(F, 0);
343 Changed |= setDoesNotCapture(F, 1);
344 Changed |= setOnlyReadsMemory(F, 1);
345 break;
346 case LibFunc_strcmp: // 0,1
347 case LibFunc_strspn: // 0,1
348 case LibFunc_strncmp: // 0,1
349 case LibFunc_strcspn: // 0,1
350 Changed |= setDoesNotThrow(F);
351 Changed |= setOnlyAccessesArgMemory(F);
352 Changed |= setWillReturn(F);
353 Changed |= setOnlyReadsMemory(F);
354 Changed |= setDoesNotCapture(F, 0);
355 Changed |= setDoesNotCapture(F, 1);
356 break;
357 case LibFunc_strcoll:
358 case LibFunc_strcasecmp: // 0,1
359 case LibFunc_strncasecmp: //
360 // Those functions may depend on the locale, which may be accessed through
361 // global memory.
362 Changed |= setOnlyReadsMemory(F);
363 Changed |= setDoesNotThrow(F);
364 Changed |= setWillReturn(F);
365 Changed |= setDoesNotCapture(F, 0);
366 Changed |= setDoesNotCapture(F, 1);
367 break;
368 case LibFunc_strstr:
369 case LibFunc_strpbrk:
370 Changed |= setOnlyAccessesArgMemory(F);
371 Changed |= setOnlyReadsMemory(F);
372 Changed |= setDoesNotThrow(F);
373 Changed |= setWillReturn(F);
374 Changed |= setDoesNotCapture(F, 1);
375 break;
376 case LibFunc_strtok:
377 case LibFunc_strtok_r:
378 Changed |= setDoesNotThrow(F);
379 Changed |= setWillReturn(F);
380 Changed |= setDoesNotCapture(F, 1);
381 Changed |= setOnlyReadsMemory(F, 1);
382 break;
383 case LibFunc_scanf:
384 Changed |= setRetAndArgsNoUndef(F);
385 Changed |= setDoesNotThrow(F);
386 Changed |= setDoesNotCapture(F, 0);
387 Changed |= setOnlyReadsMemory(F, 0);
388 break;
389 case LibFunc_setbuf:
390 case LibFunc_setvbuf:
391 Changed |= setRetAndArgsNoUndef(F);
392 Changed |= setDoesNotThrow(F);
393 Changed |= setDoesNotCapture(F, 0);
394 break;
395 case LibFunc_strndup:
396 Changed |= setArgNoUndef(F, 1);
397 [[fallthrough]];
398 case LibFunc_strdup:
399 Changed |= setAllocFamily(F, "malloc");
401 Changed |= setDoesNotThrow(F);
402 Changed |= setRetDoesNotAlias(F);
403 Changed |= setWillReturn(F);
404 Changed |= setDoesNotCapture(F, 0);
405 Changed |= setOnlyReadsMemory(F, 0);
406 break;
407 case LibFunc_stat:
408 case LibFunc_statvfs:
409 Changed |= setRetAndArgsNoUndef(F);
410 Changed |= setDoesNotThrow(F);
411 Changed |= setDoesNotCapture(F, 0);
412 Changed |= setDoesNotCapture(F, 1);
413 Changed |= setOnlyReadsMemory(F, 0);
414 break;
415 case LibFunc_sscanf:
416 Changed |= setRetAndArgsNoUndef(F);
417 Changed |= setDoesNotThrow(F);
418 Changed |= setDoesNotCapture(F, 0);
419 Changed |= setDoesNotCapture(F, 1);
420 Changed |= setOnlyReadsMemory(F, 0);
421 Changed |= setOnlyReadsMemory(F, 1);
422 break;
423 case LibFunc_sprintf:
424 Changed |= setRetAndArgsNoUndef(F);
425 Changed |= setDoesNotThrow(F);
426 Changed |= setDoesNotCapture(F, 0);
427 Changed |= setDoesNotAlias(F, 0);
428 Changed |= setOnlyWritesMemory(F, 0);
429 Changed |= setDoesNotCapture(F, 1);
430 Changed |= setOnlyReadsMemory(F, 1);
431 break;
432 case LibFunc_snprintf:
433 Changed |= setRetAndArgsNoUndef(F);
434 Changed |= setDoesNotThrow(F);
435 Changed |= setDoesNotCapture(F, 0);
436 Changed |= setDoesNotAlias(F, 0);
437 Changed |= setOnlyWritesMemory(F, 0);
438 Changed |= setDoesNotCapture(F, 2);
439 Changed |= setOnlyReadsMemory(F, 2);
440 break;
441 case LibFunc_setitimer:
442 Changed |= setRetAndArgsNoUndef(F);
443 Changed |= setDoesNotThrow(F);
444 Changed |= setWillReturn(F);
445 Changed |= setDoesNotCapture(F, 1);
446 Changed |= setDoesNotCapture(F, 2);
447 Changed |= setOnlyReadsMemory(F, 1);
448 break;
449 case LibFunc_system:
450 // May throw; "system" is a valid pthread cancellation point.
451 Changed |= setRetAndArgsNoUndef(F);
452 Changed |= setDoesNotCapture(F, 0);
453 Changed |= setOnlyReadsMemory(F, 0);
454 break;
455 case LibFunc_aligned_alloc:
456 Changed |= setAlignedAllocParam(F, 0);
457 Changed |= setAllocSize(F, 1, std::nullopt);
458 Changed |= setAllocKind(F, AllocFnKind::Alloc | AllocFnKind::Uninitialized | AllocFnKind::Aligned);
459 [[fallthrough]];
460 case LibFunc_valloc:
461 case LibFunc_malloc:
462 case LibFunc_vec_malloc:
463 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_malloc ? "vec_malloc"
464 : "malloc");
465 Changed |= setAllocKind(F, AllocFnKind::Alloc | AllocFnKind::Uninitialized);
466 Changed |= setAllocSize(F, 0, std::nullopt);
468 Changed |= setRetAndArgsNoUndef(F);
469 Changed |= setDoesNotThrow(F);
470 Changed |= setRetDoesNotAlias(F);
471 Changed |= setWillReturn(F);
472 break;
473 case LibFunc_memcmp:
474 Changed |= setOnlyAccessesArgMemory(F);
475 Changed |= setOnlyReadsMemory(F);
476 Changed |= setDoesNotThrow(F);
477 Changed |= setWillReturn(F);
478 Changed |= setDoesNotCapture(F, 0);
479 Changed |= setDoesNotCapture(F, 1);
480 break;
481 case LibFunc_memchr:
482 case LibFunc_memrchr:
483 Changed |= setDoesNotThrow(F);
484 Changed |= setOnlyAccessesArgMemory(F);
485 Changed |= setOnlyReadsMemory(F);
486 Changed |= setWillReturn(F);
487 break;
488 case LibFunc_modf:
489 case LibFunc_modff:
490 case LibFunc_modfl:
491 Changed |= setDoesNotThrow(F);
492 Changed |= setWillReturn(F);
493 Changed |= setOnlyAccessesArgMemory(F);
494 Changed |= setOnlyWritesMemory(F);
495 Changed |= setDoesNotCapture(F, 1);
496 break;
497 case LibFunc_memcpy:
498 Changed |= setDoesNotThrow(F);
499 Changed |= setOnlyAccessesArgMemory(F);
500 Changed |= setWillReturn(F);
501 Changed |= setDoesNotAlias(F, 0);
502 Changed |= setReturnedArg(F, 0);
503 Changed |= setOnlyWritesMemory(F, 0);
504 Changed |= setDoesNotAlias(F, 1);
505 Changed |= setDoesNotCapture(F, 1);
506 Changed |= setOnlyReadsMemory(F, 1);
507 break;
508 case LibFunc_memmove:
509 Changed |= setDoesNotThrow(F);
510 Changed |= setOnlyAccessesArgMemory(F);
511 Changed |= setWillReturn(F);
512 Changed |= setReturnedArg(F, 0);
513 Changed |= setOnlyWritesMemory(F, 0);
514 Changed |= setDoesNotCapture(F, 1);
515 Changed |= setOnlyReadsMemory(F, 1);
516 break;
517 case LibFunc_mempcpy:
518 case LibFunc_memccpy:
519 Changed |= setWillReturn(F);
520 [[fallthrough]];
521 case LibFunc_memcpy_chk:
522 Changed |= setDoesNotThrow(F);
523 Changed |= setOnlyAccessesArgMemory(F);
524 Changed |= setDoesNotAlias(F, 0);
525 Changed |= setOnlyWritesMemory(F, 0);
526 Changed |= setDoesNotAlias(F, 1);
527 Changed |= setDoesNotCapture(F, 1);
528 Changed |= setOnlyReadsMemory(F, 1);
529 break;
530 case LibFunc_memalign:
531 Changed |= setAllocFamily(F, "malloc");
532 Changed |= setAllocKind(F, AllocFnKind::Alloc | AllocFnKind::Aligned |
533 AllocFnKind::Uninitialized);
534 Changed |= setAllocSize(F, 1, std::nullopt);
535 Changed |= setAlignedAllocParam(F, 0);
537 Changed |= setRetNoUndef(F);
538 Changed |= setDoesNotThrow(F);
539 Changed |= setRetDoesNotAlias(F);
540 Changed |= setWillReturn(F);
541 break;
542 case LibFunc_mkdir:
543 Changed |= setRetAndArgsNoUndef(F);
544 Changed |= setDoesNotThrow(F);
545 Changed |= setDoesNotCapture(F, 0);
546 Changed |= setOnlyReadsMemory(F, 0);
547 break;
548 case LibFunc_mktime:
549 Changed |= setRetAndArgsNoUndef(F);
550 Changed |= setDoesNotThrow(F);
551 Changed |= setWillReturn(F);
552 Changed |= setDoesNotCapture(F, 0);
553 break;
554 case LibFunc_realloc:
555 case LibFunc_reallocf:
556 case LibFunc_vec_realloc:
557 Changed |= setAllocFamily(
558 F, TheLibFunc == LibFunc_vec_realloc ? "vec_malloc" : "malloc");
559 Changed |= setAllocKind(F, AllocFnKind::Realloc);
560 Changed |= setAllocatedPointerParam(F, 0);
561 Changed |= setAllocSize(F, 1, std::nullopt);
563 Changed |= setRetNoUndef(F);
564 Changed |= setDoesNotThrow(F);
565 Changed |= setRetDoesNotAlias(F);
566 Changed |= setWillReturn(F);
567 Changed |= setDoesNotCapture(F, 0);
568 Changed |= setArgNoUndef(F, 1);
569 break;
570 case LibFunc_read:
571 // May throw; "read" is a valid pthread cancellation point.
572 Changed |= setRetAndArgsNoUndef(F);
573 Changed |= setDoesNotCapture(F, 1);
574 break;
575 case LibFunc_rewind:
576 Changed |= setRetAndArgsNoUndef(F);
577 Changed |= setDoesNotThrow(F);
578 Changed |= setDoesNotCapture(F, 0);
579 break;
580 case LibFunc_rmdir:
581 case LibFunc_remove:
582 case LibFunc_realpath:
583 Changed |= setRetAndArgsNoUndef(F);
584 Changed |= setDoesNotThrow(F);
585 Changed |= setDoesNotCapture(F, 0);
586 Changed |= setOnlyReadsMemory(F, 0);
587 break;
588 case LibFunc_rename:
589 Changed |= setRetAndArgsNoUndef(F);
590 Changed |= setDoesNotThrow(F);
591 Changed |= setDoesNotCapture(F, 0);
592 Changed |= setDoesNotCapture(F, 1);
593 Changed |= setOnlyReadsMemory(F, 0);
594 Changed |= setOnlyReadsMemory(F, 1);
595 break;
596 case LibFunc_readlink:
597 Changed |= setRetAndArgsNoUndef(F);
598 Changed |= setDoesNotThrow(F);
599 Changed |= setDoesNotCapture(F, 0);
600 Changed |= setDoesNotCapture(F, 1);
601 Changed |= setOnlyReadsMemory(F, 0);
602 break;
603 case LibFunc_write:
604 // May throw; "write" is a valid pthread cancellation point.
605 Changed |= setRetAndArgsNoUndef(F);
606 Changed |= setDoesNotCapture(F, 1);
607 Changed |= setOnlyReadsMemory(F, 1);
608 break;
609 case LibFunc_bcopy:
610 Changed |= setDoesNotThrow(F);
611 Changed |= setOnlyAccessesArgMemory(F);
612 Changed |= setWillReturn(F);
613 Changed |= setDoesNotCapture(F, 0);
614 Changed |= setOnlyReadsMemory(F, 0);
615 Changed |= setOnlyWritesMemory(F, 1);
616 Changed |= setDoesNotCapture(F, 1);
617 break;
618 case LibFunc_bcmp:
619 Changed |= setDoesNotThrow(F);
620 Changed |= setOnlyAccessesArgMemory(F);
621 Changed |= setOnlyReadsMemory(F);
622 Changed |= setWillReturn(F);
623 Changed |= setDoesNotCapture(F, 0);
624 Changed |= setDoesNotCapture(F, 1);
625 break;
626 case LibFunc_bzero:
627 Changed |= setDoesNotThrow(F);
628 Changed |= setOnlyAccessesArgMemory(F);
629 Changed |= setWillReturn(F);
630 Changed |= setDoesNotCapture(F, 0);
631 Changed |= setOnlyWritesMemory(F, 0);
632 break;
633 case LibFunc_calloc:
634 case LibFunc_vec_calloc:
635 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_calloc ? "vec_malloc"
636 : "malloc");
637 Changed |= setAllocKind(F, AllocFnKind::Alloc | AllocFnKind::Zeroed);
638 Changed |= setAllocSize(F, 0, 1);
640 Changed |= setRetAndArgsNoUndef(F);
641 Changed |= setDoesNotThrow(F);
642 Changed |= setRetDoesNotAlias(F);
643 Changed |= setWillReturn(F);
644 break;
645 case LibFunc_chmod:
646 case LibFunc_chown:
647 Changed |= setRetAndArgsNoUndef(F);
648 Changed |= setDoesNotThrow(F);
649 Changed |= setDoesNotCapture(F, 0);
650 Changed |= setOnlyReadsMemory(F, 0);
651 break;
652 case LibFunc_ctermid:
653 case LibFunc_clearerr:
654 case LibFunc_closedir:
655 Changed |= setRetAndArgsNoUndef(F);
656 Changed |= setDoesNotThrow(F);
657 Changed |= setDoesNotCapture(F, 0);
658 break;
659 case LibFunc_atoi:
660 case LibFunc_atol:
661 case LibFunc_atof:
662 case LibFunc_atoll:
663 Changed |= setDoesNotThrow(F);
664 Changed |= setOnlyReadsMemory(F);
665 Changed |= setWillReturn(F);
666 Changed |= setDoesNotCapture(F, 0);
667 break;
668 case LibFunc_access:
669 Changed |= setRetAndArgsNoUndef(F);
670 Changed |= setDoesNotThrow(F);
671 Changed |= setDoesNotCapture(F, 0);
672 Changed |= setOnlyReadsMemory(F, 0);
673 break;
674 case LibFunc_fopen:
675 Changed |= setRetAndArgsNoUndef(F);
676 Changed |= setDoesNotThrow(F);
677 Changed |= setRetDoesNotAlias(F);
678 Changed |= setDoesNotCapture(F, 0);
679 Changed |= setDoesNotCapture(F, 1);
680 Changed |= setOnlyReadsMemory(F, 0);
681 Changed |= setOnlyReadsMemory(F, 1);
682 break;
683 case LibFunc_fdopen:
684 Changed |= setRetAndArgsNoUndef(F);
685 Changed |= setDoesNotThrow(F);
686 Changed |= setRetDoesNotAlias(F);
687 Changed |= setDoesNotCapture(F, 1);
688 Changed |= setOnlyReadsMemory(F, 1);
689 break;
690 case LibFunc_feof:
691 Changed |= setRetAndArgsNoUndef(F);
692 Changed |= setDoesNotThrow(F);
693 Changed |= setDoesNotCapture(F, 0);
694 break;
695 case LibFunc_free:
696 case LibFunc_vec_free:
697 Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_free ? "vec_malloc"
698 : "malloc");
699 Changed |= setAllocKind(F, AllocFnKind::Free);
700 Changed |= setAllocatedPointerParam(F, 0);
702 Changed |= setArgsNoUndef(F);
703 Changed |= setDoesNotThrow(F);
704 Changed |= setWillReturn(F);
705 Changed |= setDoesNotCapture(F, 0);
706 break;
707 case LibFunc_fseek:
708 case LibFunc_ftell:
709 case LibFunc_fgetc:
710 case LibFunc_fgetc_unlocked:
711 case LibFunc_fseeko:
712 case LibFunc_ftello:
713 case LibFunc_fileno:
714 case LibFunc_fflush:
715 case LibFunc_fclose:
716 case LibFunc_fsetpos:
717 case LibFunc_flockfile:
718 case LibFunc_funlockfile:
719 case LibFunc_ftrylockfile:
720 Changed |= setRetAndArgsNoUndef(F);
721 Changed |= setDoesNotThrow(F);
722 Changed |= setDoesNotCapture(F, 0);
723 break;
724 case LibFunc_ferror:
725 Changed |= setRetAndArgsNoUndef(F);
726 Changed |= setDoesNotThrow(F);
727 Changed |= setDoesNotCapture(F, 0);
728 Changed |= setOnlyReadsMemory(F);
729 break;
730 case LibFunc_fputc:
731 case LibFunc_fputc_unlocked:
732 case LibFunc_fstat:
733 Changed |= setRetAndArgsNoUndef(F);
734 Changed |= setDoesNotThrow(F);
735 Changed |= setDoesNotCapture(F, 1);
736 break;
737 case LibFunc_frexp:
738 case LibFunc_frexpf:
739 case LibFunc_frexpl:
740 Changed |= setDoesNotThrow(F);
741 Changed |= setWillReturn(F);
742 Changed |= setOnlyAccessesArgMemory(F);
743 Changed |= setOnlyWritesMemory(F);
744 Changed |= setDoesNotCapture(F, 1);
745 break;
746 case LibFunc_fstatvfs:
747 Changed |= setRetAndArgsNoUndef(F);
748 Changed |= setDoesNotThrow(F);
749 Changed |= setDoesNotCapture(F, 1);
750 break;
751 case LibFunc_fgets:
752 case LibFunc_fgets_unlocked:
753 Changed |= setRetAndArgsNoUndef(F);
754 Changed |= setDoesNotThrow(F);
755 Changed |= setDoesNotCapture(F, 2);
756 break;
757 case LibFunc_fread:
758 case LibFunc_fread_unlocked:
759 Changed |= setRetAndArgsNoUndef(F);
760 Changed |= setDoesNotThrow(F);
761 Changed |= setDoesNotCapture(F, 0);
762 Changed |= setDoesNotCapture(F, 3);
763 break;
764 case LibFunc_fwrite:
765 case LibFunc_fwrite_unlocked:
766 Changed |= setRetAndArgsNoUndef(F);
767 Changed |= setDoesNotThrow(F);
768 Changed |= setDoesNotCapture(F, 0);
769 Changed |= setDoesNotCapture(F, 3);
770 // FIXME: readonly #1?
771 break;
772 case LibFunc_fputs:
773 case LibFunc_fputs_unlocked:
774 Changed |= setRetAndArgsNoUndef(F);
775 Changed |= setDoesNotThrow(F);
776 Changed |= setDoesNotCapture(F, 0);
777 Changed |= setDoesNotCapture(F, 1);
778 Changed |= setOnlyReadsMemory(F, 0);
779 break;
780 case LibFunc_fscanf:
781 case LibFunc_fprintf:
782 Changed |= setRetAndArgsNoUndef(F);
783 Changed |= setDoesNotThrow(F);
784 Changed |= setDoesNotCapture(F, 0);
785 Changed |= setDoesNotCapture(F, 1);
786 Changed |= setOnlyReadsMemory(F, 1);
787 break;
788 case LibFunc_fgetpos:
789 Changed |= setRetAndArgsNoUndef(F);
790 Changed |= setDoesNotThrow(F);
791 Changed |= setDoesNotCapture(F, 0);
792 Changed |= setDoesNotCapture(F, 1);
793 break;
794 case LibFunc_getc:
795 Changed |= setRetAndArgsNoUndef(F);
796 Changed |= setDoesNotThrow(F);
797 Changed |= setDoesNotCapture(F, 0);
798 break;
799 case LibFunc_getlogin_r:
800 Changed |= setRetAndArgsNoUndef(F);
801 Changed |= setDoesNotThrow(F);
802 Changed |= setDoesNotCapture(F, 0);
803 break;
804 case LibFunc_getc_unlocked:
805 Changed |= setRetAndArgsNoUndef(F);
806 Changed |= setDoesNotThrow(F);
807 Changed |= setDoesNotCapture(F, 0);
808 break;
809 case LibFunc_getenv:
810 Changed |= setRetAndArgsNoUndef(F);
811 Changed |= setDoesNotThrow(F);
812 Changed |= setOnlyReadsMemory(F);
813 Changed |= setDoesNotCapture(F, 0);
814 break;
815 case LibFunc_gets:
816 case LibFunc_getchar:
817 case LibFunc_getchar_unlocked:
818 Changed |= setRetAndArgsNoUndef(F);
819 Changed |= setDoesNotThrow(F);
820 break;
821 case LibFunc_getitimer:
822 Changed |= setRetAndArgsNoUndef(F);
823 Changed |= setDoesNotThrow(F);
824 Changed |= setDoesNotCapture(F, 1);
825 break;
826 case LibFunc_getpwnam:
827 Changed |= setRetAndArgsNoUndef(F);
828 Changed |= setDoesNotThrow(F);
829 Changed |= setDoesNotCapture(F, 0);
830 Changed |= setOnlyReadsMemory(F, 0);
831 break;
832 case LibFunc_ungetc:
833 Changed |= setRetAndArgsNoUndef(F);
834 Changed |= setDoesNotThrow(F);
835 Changed |= setDoesNotCapture(F, 1);
836 break;
837 case LibFunc_uname:
838 Changed |= setRetAndArgsNoUndef(F);
839 Changed |= setDoesNotThrow(F);
840 Changed |= setDoesNotCapture(F, 0);
841 break;
842 case LibFunc_unlink:
843 Changed |= setRetAndArgsNoUndef(F);
844 Changed |= setDoesNotThrow(F);
845 Changed |= setDoesNotCapture(F, 0);
846 Changed |= setOnlyReadsMemory(F, 0);
847 break;
848 case LibFunc_unsetenv:
849 Changed |= setRetAndArgsNoUndef(F);
850 Changed |= setDoesNotThrow(F);
851 Changed |= setDoesNotCapture(F, 0);
852 Changed |= setOnlyReadsMemory(F, 0);
853 break;
854 case LibFunc_utime:
855 case LibFunc_utimes:
856 Changed |= setRetAndArgsNoUndef(F);
857 Changed |= setDoesNotThrow(F);
858 Changed |= setDoesNotCapture(F, 0);
859 Changed |= setDoesNotCapture(F, 1);
860 Changed |= setOnlyReadsMemory(F, 0);
861 Changed |= setOnlyReadsMemory(F, 1);
862 break;
863 case LibFunc_putc:
864 case LibFunc_putc_unlocked:
865 Changed |= setRetAndArgsNoUndef(F);
866 Changed |= setDoesNotThrow(F);
867 Changed |= setDoesNotCapture(F, 1);
868 break;
869 case LibFunc_puts:
870 case LibFunc_printf:
871 case LibFunc_perror:
872 Changed |= setRetAndArgsNoUndef(F);
873 Changed |= setDoesNotThrow(F);
874 Changed |= setDoesNotCapture(F, 0);
875 Changed |= setOnlyReadsMemory(F, 0);
876 break;
877 case LibFunc_pread:
878 // May throw; "pread" is a valid pthread cancellation point.
879 Changed |= setRetAndArgsNoUndef(F);
880 Changed |= setDoesNotCapture(F, 1);
881 break;
882 case LibFunc_pwrite:
883 // May throw; "pwrite" is a valid pthread cancellation point.
884 Changed |= setRetAndArgsNoUndef(F);
885 Changed |= setDoesNotCapture(F, 1);
886 Changed |= setOnlyReadsMemory(F, 1);
887 break;
888 case LibFunc_putchar:
889 case LibFunc_putchar_unlocked:
890 Changed |= setRetAndArgsNoUndef(F);
891 Changed |= setDoesNotThrow(F);
892 break;
893 case LibFunc_popen:
894 Changed |= setRetAndArgsNoUndef(F);
895 Changed |= setDoesNotThrow(F);
896 Changed |= setRetDoesNotAlias(F);
897 Changed |= setDoesNotCapture(F, 0);
898 Changed |= setDoesNotCapture(F, 1);
899 Changed |= setOnlyReadsMemory(F, 0);
900 Changed |= setOnlyReadsMemory(F, 1);
901 break;
902 case LibFunc_pclose:
903 Changed |= setRetAndArgsNoUndef(F);
904 Changed |= setDoesNotThrow(F);
905 Changed |= setDoesNotCapture(F, 0);
906 break;
907 case LibFunc_vscanf:
908 Changed |= setRetAndArgsNoUndef(F);
909 Changed |= setDoesNotThrow(F);
910 Changed |= setDoesNotCapture(F, 0);
911 Changed |= setOnlyReadsMemory(F, 0);
912 break;
913 case LibFunc_vsscanf:
914 Changed |= setRetAndArgsNoUndef(F);
915 Changed |= setDoesNotThrow(F);
916 Changed |= setDoesNotCapture(F, 0);
917 Changed |= setDoesNotCapture(F, 1);
918 Changed |= setOnlyReadsMemory(F, 0);
919 Changed |= setOnlyReadsMemory(F, 1);
920 break;
921 case LibFunc_vfscanf:
922 Changed |= setRetAndArgsNoUndef(F);
923 Changed |= setDoesNotThrow(F);
924 Changed |= setDoesNotCapture(F, 0);
925 Changed |= setDoesNotCapture(F, 1);
926 Changed |= setOnlyReadsMemory(F, 1);
927 break;
928 case LibFunc_vprintf:
929 Changed |= setRetAndArgsNoUndef(F);
930 Changed |= setDoesNotThrow(F);
931 Changed |= setDoesNotCapture(F, 0);
932 Changed |= setOnlyReadsMemory(F, 0);
933 break;
934 case LibFunc_vfprintf:
935 case LibFunc_vsprintf:
936 Changed |= setRetAndArgsNoUndef(F);
937 Changed |= setDoesNotThrow(F);
938 Changed |= setDoesNotCapture(F, 0);
939 Changed |= setDoesNotCapture(F, 1);
940 Changed |= setOnlyReadsMemory(F, 1);
941 break;
942 case LibFunc_vsnprintf:
943 Changed |= setRetAndArgsNoUndef(F);
944 Changed |= setDoesNotThrow(F);
945 Changed |= setDoesNotCapture(F, 0);
946 Changed |= setDoesNotCapture(F, 2);
947 Changed |= setOnlyReadsMemory(F, 2);
948 break;
949 case LibFunc_open:
950 // May throw; "open" is a valid pthread cancellation point.
951 Changed |= setRetAndArgsNoUndef(F);
952 Changed |= setDoesNotCapture(F, 0);
953 Changed |= setOnlyReadsMemory(F, 0);
954 break;
955 case LibFunc_opendir:
956 Changed |= setRetAndArgsNoUndef(F);
957 Changed |= setDoesNotThrow(F);
958 Changed |= setRetDoesNotAlias(F);
959 Changed |= setDoesNotCapture(F, 0);
960 Changed |= setOnlyReadsMemory(F, 0);
961 break;
962 case LibFunc_tmpfile:
963 Changed |= setRetAndArgsNoUndef(F);
964 Changed |= setDoesNotThrow(F);
965 Changed |= setRetDoesNotAlias(F);
966 break;
967 case LibFunc_times:
968 Changed |= setRetAndArgsNoUndef(F);
969 Changed |= setDoesNotThrow(F);
970 Changed |= setDoesNotCapture(F, 0);
971 break;
972 case LibFunc_htonl:
973 case LibFunc_htons:
974 case LibFunc_ntohl:
975 case LibFunc_ntohs:
976 Changed |= setDoesNotThrow(F);
977 Changed |= setDoesNotAccessMemory(F);
978 break;
979 case LibFunc_lstat:
980 Changed |= setRetAndArgsNoUndef(F);
981 Changed |= setDoesNotThrow(F);
982 Changed |= setDoesNotCapture(F, 0);
983 Changed |= setDoesNotCapture(F, 1);
984 Changed |= setOnlyReadsMemory(F, 0);
985 break;
986 case LibFunc_lchown:
987 Changed |= setRetAndArgsNoUndef(F);
988 Changed |= setDoesNotThrow(F);
989 Changed |= setDoesNotCapture(F, 0);
990 Changed |= setOnlyReadsMemory(F, 0);
991 break;
992 case LibFunc_qsort:
993 // May throw; places call through function pointer.
994 // Cannot give undef pointer/size
995 Changed |= setRetAndArgsNoUndef(F);
996 Changed |= setDoesNotCapture(F, 3);
997 break;
998 case LibFunc_dunder_strndup:
999 Changed |= setArgNoUndef(F, 1);
1000 [[fallthrough]];
1001 case LibFunc_dunder_strdup:
1002 Changed |= setDoesNotThrow(F);
1003 Changed |= setRetDoesNotAlias(F);
1004 Changed |= setWillReturn(F);
1005 Changed |= setDoesNotCapture(F, 0);
1006 Changed |= setOnlyReadsMemory(F, 0);
1007 break;
1008 case LibFunc_dunder_strtok_r:
1009 Changed |= setDoesNotThrow(F);
1010 Changed |= setDoesNotCapture(F, 1);
1011 Changed |= setOnlyReadsMemory(F, 1);
1012 break;
1013 case LibFunc_under_IO_getc:
1014 Changed |= setRetAndArgsNoUndef(F);
1015 Changed |= setDoesNotThrow(F);
1016 Changed |= setDoesNotCapture(F, 0);
1017 break;
1018 case LibFunc_under_IO_putc:
1019 Changed |= setRetAndArgsNoUndef(F);
1020 Changed |= setDoesNotThrow(F);
1021 Changed |= setDoesNotCapture(F, 1);
1022 break;
1023 case LibFunc_dunder_isoc99_scanf:
1024 Changed |= setRetAndArgsNoUndef(F);
1025 Changed |= setDoesNotThrow(F);
1026 Changed |= setDoesNotCapture(F, 0);
1027 Changed |= setOnlyReadsMemory(F, 0);
1028 break;
1029 case LibFunc_stat64:
1030 case LibFunc_lstat64:
1031 case LibFunc_statvfs64:
1032 Changed |= setRetAndArgsNoUndef(F);
1033 Changed |= setDoesNotThrow(F);
1034 Changed |= setDoesNotCapture(F, 0);
1035 Changed |= setDoesNotCapture(F, 1);
1036 Changed |= setOnlyReadsMemory(F, 0);
1037 break;
1038 case LibFunc_dunder_isoc99_sscanf:
1039 Changed |= setRetAndArgsNoUndef(F);
1040 Changed |= setDoesNotThrow(F);
1041 Changed |= setDoesNotCapture(F, 0);
1042 Changed |= setDoesNotCapture(F, 1);
1043 Changed |= setOnlyReadsMemory(F, 0);
1044 Changed |= setOnlyReadsMemory(F, 1);
1045 break;
1046 case LibFunc_fopen64:
1047 Changed |= setRetAndArgsNoUndef(F);
1048 Changed |= setDoesNotThrow(F);
1049 Changed |= setRetDoesNotAlias(F);
1050 Changed |= setDoesNotCapture(F, 0);
1051 Changed |= setDoesNotCapture(F, 1);
1052 Changed |= setOnlyReadsMemory(F, 0);
1053 Changed |= setOnlyReadsMemory(F, 1);
1054 break;
1055 case LibFunc_fseeko64:
1056 case LibFunc_ftello64:
1057 Changed |= setRetAndArgsNoUndef(F);
1058 Changed |= setDoesNotThrow(F);
1059 Changed |= setDoesNotCapture(F, 0);
1060 break;
1061 case LibFunc_tmpfile64:
1062 Changed |= setRetAndArgsNoUndef(F);
1063 Changed |= setDoesNotThrow(F);
1064 Changed |= setRetDoesNotAlias(F);
1065 break;
1066 case LibFunc_fstat64:
1067 case LibFunc_fstatvfs64:
1068 Changed |= setRetAndArgsNoUndef(F);
1069 Changed |= setDoesNotThrow(F);
1070 Changed |= setDoesNotCapture(F, 1);
1071 break;
1072 case LibFunc_open64:
1073 // May throw; "open" is a valid pthread cancellation point.
1074 Changed |= setRetAndArgsNoUndef(F);
1075 Changed |= setDoesNotCapture(F, 0);
1076 Changed |= setOnlyReadsMemory(F, 0);
1077 break;
1078 case LibFunc_gettimeofday:
1079 // Currently some platforms have the restrict keyword on the arguments to
1080 // gettimeofday. To be conservative, do not add noalias to gettimeofday's
1081 // arguments.
1082 Changed |= setRetAndArgsNoUndef(F);
1083 Changed |= setDoesNotThrow(F);
1084 Changed |= setDoesNotCapture(F, 0);
1085 Changed |= setDoesNotCapture(F, 1);
1086 break;
1087 case LibFunc_memset_pattern4:
1088 case LibFunc_memset_pattern8:
1089 case LibFunc_memset_pattern16:
1090 Changed |= setDoesNotCapture(F, 0);
1091 Changed |= setDoesNotCapture(F, 1);
1092 Changed |= setOnlyReadsMemory(F, 1);
1093 [[fallthrough]];
1094 case LibFunc_memset:
1095 Changed |= setWillReturn(F);
1096 [[fallthrough]];
1097 case LibFunc_memset_chk:
1098 Changed |= setOnlyAccessesArgMemory(F);
1099 Changed |= setOnlyWritesMemory(F, 0);
1100 Changed |= setDoesNotThrow(F);
1101 break;
1102 case LibFunc_abort:
1103 Changed |= setIsCold(F);
1104 break;
1105 // int __nvvm_reflect(const char *)
1106 case LibFunc_nvvm_reflect:
1107 Changed |= setRetAndArgsNoUndef(F);
1108 Changed |= setDoesNotAccessMemory(F);
1109 Changed |= setDoesNotThrow(F);
1110 break;
1111 case LibFunc_ldexp:
1112 case LibFunc_ldexpf:
1113 case LibFunc_ldexpl:
1114 Changed |= setWillReturn(F);
1115 break;
1116 case LibFunc_remquo:
1117 case LibFunc_remquof:
1118 case LibFunc_remquol:
1119 Changed |= setDoesNotCapture(F, 2);
1120 [[fallthrough]];
1121 case LibFunc_abs:
1122 case LibFunc_acos:
1123 case LibFunc_acosf:
1124 case LibFunc_acosh:
1125 case LibFunc_acoshf:
1126 case LibFunc_acoshl:
1127 case LibFunc_acosl:
1128 case LibFunc_asin:
1129 case LibFunc_asinf:
1130 case LibFunc_asinh:
1131 case LibFunc_asinhf:
1132 case LibFunc_asinhl:
1133 case LibFunc_asinl:
1134 case LibFunc_atan:
1135 case LibFunc_atan2:
1136 case LibFunc_atan2f:
1137 case LibFunc_atan2l:
1138 case LibFunc_atanf:
1139 case LibFunc_atanh:
1140 case LibFunc_atanhf:
1141 case LibFunc_atanhl:
1142 case LibFunc_atanl:
1143 case LibFunc_cbrt:
1144 case LibFunc_cbrtf:
1145 case LibFunc_cbrtl:
1146 case LibFunc_ceil:
1147 case LibFunc_ceilf:
1148 case LibFunc_ceill:
1149 case LibFunc_copysign:
1150 case LibFunc_copysignf:
1151 case LibFunc_copysignl:
1152 case LibFunc_cos:
1153 case LibFunc_cosh:
1154 case LibFunc_coshf:
1155 case LibFunc_coshl:
1156 case LibFunc_cosf:
1157 case LibFunc_cosl:
1158 case LibFunc_cospi:
1159 case LibFunc_cospif:
1160 case LibFunc_erf:
1161 case LibFunc_erff:
1162 case LibFunc_erfl:
1163 case LibFunc_exp:
1164 case LibFunc_expf:
1165 case LibFunc_expl:
1166 case LibFunc_exp2:
1167 case LibFunc_exp2f:
1168 case LibFunc_exp2l:
1169 case LibFunc_expm1:
1170 case LibFunc_expm1f:
1171 case LibFunc_expm1l:
1172 case LibFunc_fabs:
1173 case LibFunc_fabsf:
1174 case LibFunc_fabsl:
1175 case LibFunc_ffs:
1176 case LibFunc_ffsl:
1177 case LibFunc_ffsll:
1178 case LibFunc_floor:
1179 case LibFunc_floorf:
1180 case LibFunc_floorl:
1181 case LibFunc_fls:
1182 case LibFunc_flsl:
1183 case LibFunc_flsll:
1184 case LibFunc_fmax:
1185 case LibFunc_fmaxf:
1186 case LibFunc_fmaxl:
1187 case LibFunc_fmin:
1188 case LibFunc_fminf:
1189 case LibFunc_fminl:
1190 case LibFunc_fmod:
1191 case LibFunc_fmodf:
1192 case LibFunc_fmodl:
1193 case LibFunc_isascii:
1194 case LibFunc_isdigit:
1195 case LibFunc_labs:
1196 case LibFunc_llabs:
1197 case LibFunc_log:
1198 case LibFunc_log10:
1199 case LibFunc_log10f:
1200 case LibFunc_log10l:
1201 case LibFunc_log1p:
1202 case LibFunc_log1pf:
1203 case LibFunc_log1pl:
1204 case LibFunc_log2:
1205 case LibFunc_log2f:
1206 case LibFunc_log2l:
1207 case LibFunc_logb:
1208 case LibFunc_logbf:
1209 case LibFunc_logbl:
1210 case LibFunc_logf:
1211 case LibFunc_logl:
1212 case LibFunc_nearbyint:
1213 case LibFunc_nearbyintf:
1214 case LibFunc_nearbyintl:
1215 case LibFunc_pow:
1216 case LibFunc_powf:
1217 case LibFunc_powl:
1218 case LibFunc_remainder:
1219 case LibFunc_remainderf:
1220 case LibFunc_remainderl:
1221 case LibFunc_rint:
1222 case LibFunc_rintf:
1223 case LibFunc_rintl:
1224 case LibFunc_round:
1225 case LibFunc_roundf:
1226 case LibFunc_roundl:
1227 case LibFunc_sin:
1228 case LibFunc_sincospif_stret:
1229 case LibFunc_sinf:
1230 case LibFunc_sinh:
1231 case LibFunc_sinhf:
1232 case LibFunc_sinhl:
1233 case LibFunc_sinl:
1234 case LibFunc_sinpi:
1235 case LibFunc_sinpif:
1236 case LibFunc_sqrt:
1237 case LibFunc_sqrtf:
1238 case LibFunc_sqrtl:
1239 case LibFunc_tan:
1240 case LibFunc_tanf:
1241 case LibFunc_tanh:
1242 case LibFunc_tanhf:
1243 case LibFunc_tanhl:
1244 case LibFunc_tanl:
1245 case LibFunc_toascii:
1246 case LibFunc_trunc:
1247 case LibFunc_truncf:
1248 case LibFunc_truncl:
1249 Changed |= setDoesNotThrow(F);
1250 Changed |= setDoesNotFreeMemory(F);
1251 Changed |= setOnlyWritesMemory(F);
1252 Changed |= setWillReturn(F);
1253 break;
1254 default:
1255 // FIXME: It'd be really nice to cover all the library functions we're
1256 // aware of here.
1257 break;
1258 }
1259 // We have to do this step after AllocKind has been inferred on functions so
1260 // we can reliably identify free-like and realloc-like functions.
1261 if (!isLibFreeFunction(&F, TheLibFunc) && !isReallocLikeFn(&F))
1262 Changed |= setDoesNotFreeMemory(F);
1263 return Changed;
1264}
1265
1266static void setArgExtAttr(Function &F, unsigned ArgNo,
1267 const TargetLibraryInfo &TLI, bool Signed = true) {
1268 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Param(Signed);
1269 if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr))
1270 F.addParamAttr(ArgNo, ExtAttr);
1271}
1272
1274 const TargetLibraryInfo &TLI, bool Signed = true) {
1275 Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Return(Signed);
1276 if (ExtAttr != Attribute::None && !F.hasRetAttribute(ExtAttr))
1277 F.addRetAttr(ExtAttr);
1278}
1279
1280// Modeled after X86TargetLowering::markLibCallAttributes.
1282 if (!F->arg_size() || F->isVarArg())
1283 return;
1284
1285 const CallingConv::ID CC = F->getCallingConv();
1287 return;
1288
1289 const Module *M = F->getParent();
1290 unsigned N = M->getNumberRegisterParameters();
1291 if (!N)
1292 return;
1293
1294 const DataLayout &DL = M->getDataLayout();
1295
1296 for (Argument &A : F->args()) {
1297 Type *T = A.getType();
1298 if (!T->isIntOrPtrTy())
1299 continue;
1300
1301 const TypeSize &TS = DL.getTypeAllocSize(T);
1302 if (TS > 8)
1303 continue;
1304
1305 assert(TS <= 4 && "Need to account for parameters larger than word size");
1306 const unsigned NumRegs = TS > 4 ? 2 : 1;
1307 if (N < NumRegs)
1308 return;
1309
1310 N -= NumRegs;
1311 F->addParamAttr(A.getArgNo(), Attribute::InReg);
1312 }
1313}
1314
1316 LibFunc TheLibFunc, FunctionType *T,
1318 assert(TLI.has(TheLibFunc) &&
1319 "Creating call to non-existing library function.");
1320 StringRef Name = TLI.getName(TheLibFunc);
1321 FunctionCallee C = M->getOrInsertFunction(Name, T, AttributeList);
1322
1323 // Make sure any mandatory argument attributes are added.
1324
1325 // Any outgoing i32 argument should be handled with setArgExtAttr() which
1326 // will add an extension attribute if the target ABI requires it. Adding
1327 // argument extensions is typically done by the front end but when an
1328 // optimizer is building a library call on its own it has to take care of
1329 // this. Each such generated function must be handled here with sign or
1330 // zero extensions as needed. F is retreived with cast<> because we demand
1331 // of the caller to have called isLibFuncEmittable() first.
1332 Function *F = cast<Function>(C.getCallee());
1333 assert(F->getFunctionType() == T && "Function type does not match.");
1334 switch (TheLibFunc) {
1335 case LibFunc_fputc:
1336 case LibFunc_putchar:
1337 setArgExtAttr(*F, 0, TLI);
1338 break;
1339 case LibFunc_ldexp:
1340 case LibFunc_ldexpf:
1341 case LibFunc_ldexpl:
1342 case LibFunc_memchr:
1343 case LibFunc_memrchr:
1344 case LibFunc_strchr:
1345 setArgExtAttr(*F, 1, TLI);
1346 break;
1347 case LibFunc_memccpy:
1348 setArgExtAttr(*F, 2, TLI);
1349 break;
1350
1351 // These are functions that are known to not need any argument extension
1352 // on any target: A size_t argument (which may be an i32 on some targets)
1353 // should not trigger the assert below.
1354 case LibFunc_bcmp:
1355 setRetExtAttr(*F, TLI);
1356 break;
1357 case LibFunc_calloc:
1358 case LibFunc_fwrite:
1359 case LibFunc_malloc:
1360 case LibFunc_memcmp:
1361 case LibFunc_memcpy_chk:
1362 case LibFunc_mempcpy:
1363 case LibFunc_memset_pattern16:
1364 case LibFunc_snprintf:
1365 case LibFunc_stpncpy:
1366 case LibFunc_strlcat:
1367 case LibFunc_strlcpy:
1368 case LibFunc_strncat:
1369 case LibFunc_strncmp:
1370 case LibFunc_strncpy:
1371 case LibFunc_vsnprintf:
1372 break;
1373
1374 default:
1375#ifndef NDEBUG
1376 for (unsigned i = 0; i < T->getNumParams(); i++)
1377 assert(!isa<IntegerType>(T->getParamType(i)) &&
1378 "Unhandled integer argument.");
1379#endif
1380 break;
1381 }
1382
1384
1385 return C;
1386}
1387
1389 LibFunc TheLibFunc, FunctionType *T) {
1390 return getOrInsertLibFunc(M, TLI, TheLibFunc, T, AttributeList());
1391}
1392
1394 LibFunc TheLibFunc) {
1395 StringRef FuncName = TLI->getName(TheLibFunc);
1396 if (!TLI->has(TheLibFunc))
1397 return false;
1398
1399 // Check if the Module already has a GlobalValue with the same name, in
1400 // which case it must be a Function with the expected type.
1401 if (GlobalValue *GV = M->getNamedValue(FuncName)) {
1402 if (auto *F = dyn_cast<Function>(GV))
1403 return TLI->isValidProtoForLibFunc(*F->getFunctionType(), TheLibFunc, *M);
1404 return false;
1405 }
1406
1407 return true;
1408}
1409
1411 StringRef Name) {
1412 LibFunc TheLibFunc;
1413 return TLI->getLibFunc(Name, TheLibFunc) &&
1414 isLibFuncEmittable(M, TLI, TheLibFunc);
1415}
1416
1417bool llvm::hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty,
1418 LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
1419 switch (Ty->getTypeID()) {
1420 case Type::HalfTyID:
1421 return false;
1422 case Type::FloatTyID:
1423 return isLibFuncEmittable(M, TLI, FloatFn);
1424 case Type::DoubleTyID:
1425 return isLibFuncEmittable(M, TLI, DoubleFn);
1426 default:
1427 return isLibFuncEmittable(M, TLI, LongDoubleFn);
1428 }
1429}
1430
1432 Type *Ty, LibFunc DoubleFn, LibFunc FloatFn,
1433 LibFunc LongDoubleFn, LibFunc &TheLibFunc) {
1434 assert(hasFloatFn(M, TLI, Ty, DoubleFn, FloatFn, LongDoubleFn) &&
1435 "Cannot get name for unavailable function!");
1436
1437 switch (Ty->getTypeID()) {
1438 case Type::HalfTyID:
1439 llvm_unreachable("No name for HalfTy!");
1440 case Type::FloatTyID:
1441 TheLibFunc = FloatFn;
1442 return TLI->getName(FloatFn);
1443 case Type::DoubleTyID:
1444 TheLibFunc = DoubleFn;
1445 return TLI->getName(DoubleFn);
1446 default:
1447 TheLibFunc = LongDoubleFn;
1448 return TLI->getName(LongDoubleFn);
1449 }
1450}
1451
1452//- Emit LibCalls ------------------------------------------------------------//
1453
1455 return B.getIntNTy(TLI->getIntSize());
1456}
1457
1459 const Module *M = B.GetInsertBlock()->getModule();
1460 return B.getIntNTy(TLI->getSizeTSize(*M));
1461}
1462
1463static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
1464 ArrayRef<Type *> ParamTypes,
1466 const TargetLibraryInfo *TLI,
1467 bool IsVaArgs = false) {
1468 Module *M = B.GetInsertBlock()->getModule();
1469 if (!isLibFuncEmittable(M, TLI, TheLibFunc))
1470 return nullptr;
1471
1472 StringRef FuncName = TLI->getName(TheLibFunc);
1473 FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1474 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, FuncType);
1475 inferNonMandatoryLibFuncAttrs(M, FuncName, *TLI);
1476 CallInst *CI = B.CreateCall(Callee, Operands, FuncName);
1477 if (const Function *F =
1478 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1479 CI->setCallingConv(F->getCallingConv());
1480 return CI;
1481}
1482
1484 const TargetLibraryInfo *TLI) {
1485 Type *CharPtrTy = B.getPtrTy();
1486 Type *SizeTTy = getSizeTTy(B, TLI);
1487 return emitLibCall(LibFunc_strlen, SizeTTy, CharPtrTy, Ptr, B, TLI);
1488}
1489
1491 const TargetLibraryInfo *TLI) {
1492 Type *CharPtrTy = B.getPtrTy();
1493 return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy, Ptr, B, TLI);
1494}
1495
1497 const TargetLibraryInfo *TLI) {
1498 Type *CharPtrTy = B.getPtrTy();
1499 Type *IntTy = getIntTy(B, TLI);
1500 return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
1501 {Ptr, ConstantInt::get(IntTy, C)}, B, TLI);
1502}
1503
1505 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1506 Type *CharPtrTy = B.getPtrTy();
1507 Type *IntTy = getIntTy(B, TLI);
1508 Type *SizeTTy = getSizeTTy(B, TLI);
1509 return emitLibCall(
1510 LibFunc_strncmp, IntTy,
1511 {CharPtrTy, CharPtrTy, SizeTTy},
1512 {Ptr1, Ptr2, Len}, B, TLI);
1513}
1514
1516 const TargetLibraryInfo *TLI) {
1517 Type *CharPtrTy = Dst->getType();
1518 return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1519 {Dst, Src}, B, TLI);
1520}
1521
1523 const TargetLibraryInfo *TLI) {
1524 Type *CharPtrTy = B.getPtrTy();
1525 return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
1526 {Dst, Src}, B, TLI);
1527}
1528
1530 const TargetLibraryInfo *TLI) {
1531 Type *CharPtrTy = B.getPtrTy();
1532 Type *SizeTTy = getSizeTTy(B, TLI);
1533 return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1534 {Dst, Src, Len}, B, TLI);
1535}
1536
1538 const TargetLibraryInfo *TLI) {
1539 Type *CharPtrTy = B.getPtrTy();
1540 Type *SizeTTy = getSizeTTy(B, TLI);
1541 return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
1542 {Dst, Src, Len}, B, TLI);
1543}
1544
1545Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
1546 IRBuilderBase &B, const DataLayout &DL,
1547 const TargetLibraryInfo *TLI) {
1548 Module *M = B.GetInsertBlock()->getModule();
1549 if (!isLibFuncEmittable(M, TLI, LibFunc_memcpy_chk))
1550 return nullptr;
1551
1552 AttributeList AS;
1554 Attribute::NoUnwind);
1555 Type *VoidPtrTy = B.getPtrTy();
1556 Type *SizeTTy = getSizeTTy(B, TLI);
1557 FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
1558 AttributeList::get(M->getContext(), AS), VoidPtrTy,
1559 VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
1560 CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1561 if (const Function *F =
1562 dyn_cast<Function>(MemCpy.getCallee()->stripPointerCasts()))
1563 CI->setCallingConv(F->getCallingConv());
1564 return CI;
1565}
1566
1568 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1569 Type *VoidPtrTy = B.getPtrTy();
1570 Type *SizeTTy = getSizeTTy(B, TLI);
1571 return emitLibCall(LibFunc_mempcpy, VoidPtrTy,
1572 {VoidPtrTy, VoidPtrTy, SizeTTy},
1573 {Dst, Src, Len}, B, TLI);
1574}
1575
1577 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1578 Type *VoidPtrTy = B.getPtrTy();
1579 Type *IntTy = getIntTy(B, TLI);
1580 Type *SizeTTy = getSizeTTy(B, TLI);
1581 return emitLibCall(LibFunc_memchr, VoidPtrTy,
1582 {VoidPtrTy, IntTy, SizeTTy},
1583 {Ptr, Val, Len}, B, TLI);
1584}
1585
1587 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1588 Type *VoidPtrTy = B.getPtrTy();
1589 Type *IntTy = getIntTy(B, TLI);
1590 Type *SizeTTy = getSizeTTy(B, TLI);
1591 return emitLibCall(LibFunc_memrchr, VoidPtrTy,
1592 {VoidPtrTy, IntTy, SizeTTy},
1593 {Ptr, Val, Len}, B, TLI);
1594}
1595
1597 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1598 Type *VoidPtrTy = B.getPtrTy();
1599 Type *IntTy = getIntTy(B, TLI);
1600 Type *SizeTTy = getSizeTTy(B, TLI);
1601 return emitLibCall(LibFunc_memcmp, IntTy,
1602 {VoidPtrTy, VoidPtrTy, SizeTTy},
1603 {Ptr1, Ptr2, Len}, B, TLI);
1604}
1605
1607 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1608 Type *VoidPtrTy = B.getPtrTy();
1609 Type *IntTy = getIntTy(B, TLI);
1610 Type *SizeTTy = getSizeTTy(B, TLI);
1611 return emitLibCall(LibFunc_bcmp, IntTy,
1612 {VoidPtrTy, VoidPtrTy, SizeTTy},
1613 {Ptr1, Ptr2, Len}, B, TLI);
1614}
1615
1616Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
1617 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1618 Type *VoidPtrTy = B.getPtrTy();
1619 Type *IntTy = getIntTy(B, TLI);
1620 Type *SizeTTy = getSizeTTy(B, TLI);
1621 return emitLibCall(LibFunc_memccpy, VoidPtrTy,
1622 {VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
1623 {Ptr1, Ptr2, Val, Len}, B, TLI);
1624}
1625
1627 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1628 const TargetLibraryInfo *TLI) {
1629 Type *CharPtrTy = B.getPtrTy();
1630 Type *IntTy = getIntTy(B, TLI);
1631 Type *SizeTTy = getSizeTTy(B, TLI);
1632 SmallVector<Value *, 8> Args{Dest, Size, Fmt};
1633 llvm::append_range(Args, VariadicArgs);
1634 return emitLibCall(LibFunc_snprintf, IntTy,
1635 {CharPtrTy, SizeTTy, CharPtrTy},
1636 Args, B, TLI, /*IsVaArgs=*/true);
1637}
1638
1640 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1641 const TargetLibraryInfo *TLI) {
1642 Type *CharPtrTy = B.getPtrTy();
1643 Type *IntTy = getIntTy(B, TLI);
1644 SmallVector<Value *, 8> Args{Dest, Fmt};
1645 llvm::append_range(Args, VariadicArgs);
1646 return emitLibCall(LibFunc_sprintf, IntTy,
1647 {CharPtrTy, CharPtrTy}, Args, B, TLI,
1648 /*IsVaArgs=*/true);
1649}
1650
1652 const TargetLibraryInfo *TLI) {
1653 Type *CharPtrTy = B.getPtrTy();
1654 return emitLibCall(LibFunc_strcat, CharPtrTy,
1655 {CharPtrTy, CharPtrTy},
1656 {Dest, Src}, B, TLI);
1657}
1658
1660 const TargetLibraryInfo *TLI) {
1661 Type *CharPtrTy = B.getPtrTy();
1662 Type *SizeTTy = getSizeTTy(B, TLI);
1663 return emitLibCall(LibFunc_strlcpy, SizeTTy,
1664 {CharPtrTy, CharPtrTy, SizeTTy},
1665 {Dest, Src, Size}, B, TLI);
1666}
1667
1669 const TargetLibraryInfo *TLI) {
1670 Type *CharPtrTy = B.getPtrTy();
1671 Type *SizeTTy = getSizeTTy(B, TLI);
1672 return emitLibCall(LibFunc_strlcat, SizeTTy,
1673 {CharPtrTy, CharPtrTy, SizeTTy},
1674 {Dest, Src, Size}, B, TLI);
1675}
1676
1678 const TargetLibraryInfo *TLI) {
1679 Type *CharPtrTy = B.getPtrTy();
1680 Type *SizeTTy = getSizeTTy(B, TLI);
1681 return emitLibCall(LibFunc_strncat, CharPtrTy,
1682 {CharPtrTy, CharPtrTy, SizeTTy},
1683 {Dest, Src, Size}, B, TLI);
1684}
1685
1687 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1688 Type *CharPtrTy = B.getPtrTy();
1689 Type *IntTy = getIntTy(B, TLI);
1690 Type *SizeTTy = getSizeTTy(B, TLI);
1691 return emitLibCall(
1692 LibFunc_vsnprintf, IntTy,
1693 {CharPtrTy, SizeTTy, CharPtrTy, VAList->getType()},
1694 {Dest, Size, Fmt, VAList}, B, TLI);
1695}
1696
1698 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1699 Type *CharPtrTy = B.getPtrTy();
1700 Type *IntTy = getIntTy(B, TLI);
1701 return emitLibCall(LibFunc_vsprintf, IntTy,
1702 {CharPtrTy, CharPtrTy, VAList->getType()},
1703 {Dest, Fmt, VAList}, B, TLI);
1704}
1705
1706/// Append a suffix to the function name according to the type of 'Op'.
1708 SmallString<20> &NameBuffer) {
1709 if (!Op->getType()->isDoubleTy()) {
1710 NameBuffer += Name;
1711
1712 if (Op->getType()->isFloatTy())
1713 NameBuffer += 'f';
1714 else
1715 NameBuffer += 'l';
1716
1717 Name = NameBuffer;
1718 }
1719}
1720
1723 const AttributeList &Attrs,
1724 const TargetLibraryInfo *TLI) {
1725 assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
1726
1727 Module *M = B.GetInsertBlock()->getModule();
1728 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op->getType(),
1729 Op->getType());
1730 CallInst *CI = B.CreateCall(Callee, Op, Name);
1731
1732 // The incoming attribute set may have come from a speculatable intrinsic, but
1733 // is being replaced with a library call which is not allowed to be
1734 // speculatable.
1735 CI->setAttributes(
1736 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1737 if (const Function *F =
1738 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1739 CI->setCallingConv(F->getCallingConv());
1740
1741 return CI;
1742}
1743
1746 const AttributeList &Attrs) {
1747 SmallString<20> NameBuffer;
1748 appendTypeSuffix(Op, Name, NameBuffer);
1749
1750 LibFunc TheLibFunc;
1751 TLI->getLibFunc(Name, TheLibFunc);
1752
1753 return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1754}
1755
1757 LibFunc DoubleFn, LibFunc FloatFn,
1758 LibFunc LongDoubleFn, IRBuilderBase &B,
1759 const AttributeList &Attrs) {
1760 // Get the name of the function according to TLI.
1761 Module *M = B.GetInsertBlock()->getModule();
1762 LibFunc TheLibFunc;
1763 StringRef Name = getFloatFn(M, TLI, Op->getType(), DoubleFn, FloatFn,
1764 LongDoubleFn, TheLibFunc);
1765
1766 return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1767}
1768
1770 LibFunc TheLibFunc,
1772 const AttributeList &Attrs,
1773 const TargetLibraryInfo *TLI) {
1774 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1775
1776 Module *M = B.GetInsertBlock()->getModule();
1777 FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op1->getType(),
1778 Op1->getType(), Op2->getType());
1780 CallInst *CI = B.CreateCall(Callee, { Op1, Op2 }, Name);
1781
1782 // The incoming attribute set may have come from a speculatable intrinsic, but
1783 // is being replaced with a library call which is not allowed to be
1784 // speculatable.
1785 CI->setAttributes(
1786 Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1787 if (const Function *F =
1788 dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1789 CI->setCallingConv(F->getCallingConv());
1790
1791 return CI;
1792}
1793
1795 const TargetLibraryInfo *TLI,
1797 const AttributeList &Attrs) {
1798 assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1799
1800 SmallString<20> NameBuffer;
1801 appendTypeSuffix(Op1, Name, NameBuffer);
1802
1803 LibFunc TheLibFunc;
1804 TLI->getLibFunc(Name, TheLibFunc);
1805
1806 return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
1807}
1808
1810 const TargetLibraryInfo *TLI,
1811 LibFunc DoubleFn, LibFunc FloatFn,
1812 LibFunc LongDoubleFn, IRBuilderBase &B,
1813 const AttributeList &Attrs) {
1814 // Get the name of the function according to TLI.
1815 Module *M = B.GetInsertBlock()->getModule();
1816 LibFunc TheLibFunc;
1817 StringRef Name = getFloatFn(M, TLI, Op1->getType(), DoubleFn, FloatFn,
1818 LongDoubleFn, TheLibFunc);
1819
1820 return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
1821}
1822
1823// Emit a call to putchar(int) with Char as the argument. Char must have
1824// the same precision as int, which need not be 32 bits.
1826 const TargetLibraryInfo *TLI) {
1827 Module *M = B.GetInsertBlock()->getModule();
1828 if (!isLibFuncEmittable(M, TLI, LibFunc_putchar))
1829 return nullptr;
1830
1831 Type *IntTy = getIntTy(B, TLI);
1832 StringRef PutCharName = TLI->getName(LibFunc_putchar);
1833 FunctionCallee PutChar = getOrInsertLibFunc(M, *TLI, LibFunc_putchar,
1834 IntTy, IntTy);
1835 inferNonMandatoryLibFuncAttrs(M, PutCharName, *TLI);
1836 CallInst *CI = B.CreateCall(PutChar, Char, PutCharName);
1837
1838 if (const Function *F =
1839 dyn_cast<Function>(PutChar.getCallee()->stripPointerCasts()))
1840 CI->setCallingConv(F->getCallingConv());
1841 return CI;
1842}
1843
1845 const TargetLibraryInfo *TLI) {
1846 Module *M = B.GetInsertBlock()->getModule();
1847 if (!isLibFuncEmittable(M, TLI, LibFunc_puts))
1848 return nullptr;
1849
1850 Type *IntTy = getIntTy(B, TLI);
1851 StringRef PutsName = TLI->getName(LibFunc_puts);
1852 FunctionCallee PutS = getOrInsertLibFunc(M, *TLI, LibFunc_puts, IntTy,
1853 B.getPtrTy());
1854 inferNonMandatoryLibFuncAttrs(M, PutsName, *TLI);
1855 CallInst *CI = B.CreateCall(PutS, Str, PutsName);
1856 if (const Function *F =
1857 dyn_cast<Function>(PutS.getCallee()->stripPointerCasts()))
1858 CI->setCallingConv(F->getCallingConv());
1859 return CI;
1860}
1861
1863 const TargetLibraryInfo *TLI) {
1864 Module *M = B.GetInsertBlock()->getModule();
1865 if (!isLibFuncEmittable(M, TLI, LibFunc_fputc))
1866 return nullptr;
1867
1868 Type *IntTy = getIntTy(B, TLI);
1869 StringRef FPutcName = TLI->getName(LibFunc_fputc);
1870 FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputc, IntTy,
1871 IntTy, File->getType());
1872 if (File->getType()->isPointerTy())
1873 inferNonMandatoryLibFuncAttrs(M, FPutcName, *TLI);
1874 CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName);
1875
1876 if (const Function *Fn =
1877 dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1878 CI->setCallingConv(Fn->getCallingConv());
1879 return CI;
1880}
1881
1883 const TargetLibraryInfo *TLI) {
1884 Module *M = B.GetInsertBlock()->getModule();
1885 if (!isLibFuncEmittable(M, TLI, LibFunc_fputs))
1886 return nullptr;
1887
1888 Type *IntTy = getIntTy(B, TLI);
1889 StringRef FPutsName = TLI->getName(LibFunc_fputs);
1890 FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputs, IntTy,
1891 B.getPtrTy(), File->getType());
1892 if (File->getType()->isPointerTy())
1893 inferNonMandatoryLibFuncAttrs(M, FPutsName, *TLI);
1894 CallInst *CI = B.CreateCall(F, {Str, File}, FPutsName);
1895
1896 if (const Function *Fn =
1897 dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1898 CI->setCallingConv(Fn->getCallingConv());
1899 return CI;
1900}
1901
1903 const DataLayout &DL, const TargetLibraryInfo *TLI) {
1904 Module *M = B.GetInsertBlock()->getModule();
1905 if (!isLibFuncEmittable(M, TLI, LibFunc_fwrite))
1906 return nullptr;
1907
1908 Type *SizeTTy = getSizeTTy(B, TLI);
1909 StringRef FWriteName = TLI->getName(LibFunc_fwrite);
1910 FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fwrite,
1911 SizeTTy, B.getPtrTy(), SizeTTy,
1912 SizeTTy, File->getType());
1913
1914 if (File->getType()->isPointerTy())
1915 inferNonMandatoryLibFuncAttrs(M, FWriteName, *TLI);
1916 CallInst *CI =
1917 B.CreateCall(F, {Ptr, Size,
1918 ConstantInt::get(SizeTTy, 1), File});
1919
1920 if (const Function *Fn =
1921 dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1922 CI->setCallingConv(Fn->getCallingConv());
1923 return CI;
1924}
1925
1927 const TargetLibraryInfo *TLI) {
1928 Module *M = B.GetInsertBlock()->getModule();
1929 if (!isLibFuncEmittable(M, TLI, LibFunc_malloc))
1930 return nullptr;
1931
1932 StringRef MallocName = TLI->getName(LibFunc_malloc);
1933 Type *SizeTTy = getSizeTTy(B, TLI);
1934 FunctionCallee Malloc = getOrInsertLibFunc(M, *TLI, LibFunc_malloc,
1935 B.getPtrTy(), SizeTTy);
1936 inferNonMandatoryLibFuncAttrs(M, MallocName, *TLI);
1937 CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
1938
1939 if (const Function *F =
1940 dyn_cast<Function>(Malloc.getCallee()->stripPointerCasts()))
1941 CI->setCallingConv(F->getCallingConv());
1942
1943 return CI;
1944}
1945
1947 const TargetLibraryInfo &TLI) {
1948 Module *M = B.GetInsertBlock()->getModule();
1949 if (!isLibFuncEmittable(M, &TLI, LibFunc_calloc))
1950 return nullptr;
1951
1952 StringRef CallocName = TLI.getName(LibFunc_calloc);
1953 Type *SizeTTy = getSizeTTy(B, &TLI);
1954 FunctionCallee Calloc = getOrInsertLibFunc(M, TLI, LibFunc_calloc,
1955 B.getPtrTy(), SizeTTy, SizeTTy);
1956 inferNonMandatoryLibFuncAttrs(M, CallocName, TLI);
1957 CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
1958
1959 if (const auto *F =
1960 dyn_cast<Function>(Calloc.getCallee()->stripPointerCasts()))
1961 CI->setCallingConv(F->getCallingConv());
1962
1963 return CI;
1964}
1965
1967 const TargetLibraryInfo *TLI, LibFunc NewFunc,
1968 uint8_t HotCold) {
1969 Module *M = B.GetInsertBlock()->getModule();
1970 if (!isLibFuncEmittable(M, TLI, NewFunc))
1971 return nullptr;
1972
1973 StringRef Name = TLI->getName(NewFunc);
1974 FunctionCallee Func = M->getOrInsertFunction(Name, B.getPtrTy(),
1975 Num->getType(), B.getInt8Ty());
1977 CallInst *CI = B.CreateCall(Func, {Num, B.getInt8(HotCold)}, Name);
1978
1979 if (const Function *F =
1980 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
1981 CI->setCallingConv(F->getCallingConv());
1982
1983 return CI;
1984}
1985
1987 const TargetLibraryInfo *TLI,
1988 LibFunc NewFunc, uint8_t HotCold) {
1989 Module *M = B.GetInsertBlock()->getModule();
1990 if (!isLibFuncEmittable(M, TLI, NewFunc))
1991 return nullptr;
1992
1993 StringRef Name = TLI->getName(NewFunc);
1994 FunctionCallee Func =
1995 M->getOrInsertFunction(Name, B.getPtrTy(), Num->getType(),
1996 NoThrow->getType(), B.getInt8Ty());
1998 CallInst *CI = B.CreateCall(Func, {Num, NoThrow, B.getInt8(HotCold)}, Name);
1999
2000 if (const Function *F =
2001 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2002 CI->setCallingConv(F->getCallingConv());
2003
2004 return CI;
2005}
2006
2008 const TargetLibraryInfo *TLI,
2009 LibFunc NewFunc, uint8_t HotCold) {
2010 Module *M = B.GetInsertBlock()->getModule();
2011 if (!isLibFuncEmittable(M, TLI, NewFunc))
2012 return nullptr;
2013
2014 StringRef Name = TLI->getName(NewFunc);
2015 FunctionCallee Func = M->getOrInsertFunction(
2016 Name, B.getPtrTy(), Num->getType(), Align->getType(), B.getInt8Ty());
2018 CallInst *CI = B.CreateCall(Func, {Num, Align, B.getInt8(HotCold)}, Name);
2019
2020 if (const Function *F =
2021 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2022 CI->setCallingConv(F->getCallingConv());
2023
2024 return CI;
2025}
2026
2028 Value *NoThrow, IRBuilderBase &B,
2029 const TargetLibraryInfo *TLI,
2030 LibFunc NewFunc, uint8_t HotCold) {
2031 Module *M = B.GetInsertBlock()->getModule();
2032 if (!isLibFuncEmittable(M, TLI, NewFunc))
2033 return nullptr;
2034
2035 StringRef Name = TLI->getName(NewFunc);
2036 FunctionCallee Func = M->getOrInsertFunction(
2037 Name, B.getPtrTy(), Num->getType(), Align->getType(),
2038 NoThrow->getType(), B.getInt8Ty());
2040 CallInst *CI =
2041 B.CreateCall(Func, {Num, Align, NoThrow, B.getInt8(HotCold)}, Name);
2042
2043 if (const Function *F =
2044 dyn_cast<Function>(Func.getCallee()->stripPointerCasts()))
2045 CI->setCallingConv(F->getCallingConv());
2046
2047 return CI;
2048}
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 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 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 setDoesNotCapture(Function &F, unsigned ArgNo)
static bool setDoesNotThrow(Function &F)
static bool setWillReturn(Function &F)
static bool setAllocKind(Function &F, AllocFnKind K)
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 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< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::string Name
uint64_t Size
#define F(x, y, z)
Definition: MD5.cpp:55
mir Rename Register Operands
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:31
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:94
static Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
Definition: Attributes.cpp:291
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:86
@ None
No attributes have been set.
Definition: Attributes.h:88
void setCallingConv(CallingConv::ID CC)
Definition: InstrTypes.h:1527
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
Definition: InstrTypes.h:1546
This class represents a function call, abstracting a target machine's calling convention.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:168
Class to represent function types.
Definition: DerivedTypes.h:103
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:91
Class to represent integer types.
Definition: DerivedTypes.h:40
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
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.
Definition: SmallVector.h:1210
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:136
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:694
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ 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: AddressRanges.h:18
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.
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.
Value * emitPutChar(Value *Char, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the putchar function. This assumes that Char is an 'int'.
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.
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.
Value * emitHotColdNewAlignedNoThrow(Value *Num, Value *Align, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
AllocFnKind
Definition: Attributes.h:49
Value * emitCalloc(Value *Num, Value *Size, IRBuilderBase &B, const TargetLibraryInfo &TLI)
Emit a call to the calloc function.
Value * emitSPrintf(Value *Dest, Value *Fmt, ArrayRef< Value * > VariadicArgs, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the sprintf function.
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.
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:2073
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.
bool inferNonMandatoryLibFuncAttrs(Module *M, StringRef Name, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
bool isLibFreeFunction(const Function *F, const LibFunc TLIFn)
isLibFreeFunction - Returns true if the function is a builtin free()
Value * emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strncat function.
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...
Value * emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsnprintf function.
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.
Value * emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memcmp function.
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.
Value * emitFPutS(Value *Str, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
Value * emitStrDup(Value *Ptr, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strdup function to the builder, for the specified pointer.
Value * emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the bcmp function.
void markRegisterParameterAttributes(Function *F)
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.
FunctionCallee getOrInsertLibFunc(Module *M, const TargetLibraryInfo &TLI, LibFunc TheLibFunc, FunctionType *T, AttributeList AttributeList)
Calls getOrInsertFunction() and then makes sure to add mandatory argument attributes.
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.
Value * emitFPutC(Value *Char, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
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.
Value * emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcat function.
Value * emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsprintf function.
bool isReallocLikeFn(const Function *F)
Tests if a function is a call or invoke to a library function that reallocates memory (e....
Value * emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite function.
Value * emitSNPrintf(Value *Dest, Value *Size, Value *Fmt, ArrayRef< Value * > Args, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the snprintf function.
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.
Value * emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
Value * emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
Value * emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
Value * emitPutS(Value *Str, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
Value * emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the memccpy function.
Value * emitHotColdNew(Value *Num, IRBuilderBase &B, const TargetLibraryInfo *TLI, LibFunc NewFunc, uint8_t HotCold)
Emit a call to the hot/cold operator new function.
Value * emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcpy function.
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.
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