Movatterモバイル変換


[0]ホーム

URL:


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

Generated on Sun Jul 20 2025 14:26:50 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp