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