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