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