LLVM  16.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 
14 #include "llvm/ADT/SmallString.h"
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"
26 #include "llvm/Support/TypeSize.h"
27 
28 using namespace llvm;
29 
30 #define DEBUG_TYPE "build-libcalls"
31 
32 //- Infer Attributes ---------------------------------------------------------//
33 
34 STATISTIC(NumReadNone, "Number of functions inferred as readnone");
35 STATISTIC(NumInaccessibleMemOnly,
36  "Number of functions inferred as inaccessiblememonly");
37 STATISTIC(NumReadOnly, "Number of functions inferred as readonly");
38 STATISTIC(NumWriteOnly, "Number of functions inferred as writeonly");
39 STATISTIC(NumArgMemOnly, "Number of functions inferred as argmemonly");
40 STATISTIC(NumInaccessibleMemOrArgMemOnly,
41  "Number of functions inferred as inaccessiblemem_or_argmemonly");
42 STATISTIC(NumNoUnwind, "Number of functions inferred as nounwind");
43 STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture");
44 STATISTIC(NumWriteOnlyArg, "Number of arguments inferred as writeonly");
45 STATISTIC(NumReadOnlyArg, "Number of arguments inferred as readonly");
46 STATISTIC(NumNoAlias, "Number of function returns inferred as noalias");
47 STATISTIC(NumNoUndef, "Number of function returns inferred as noundef returns");
48 STATISTIC(NumReturnedArg, "Number of arguments inferred as returned");
49 STATISTIC(NumWillReturn, "Number of functions inferred as willreturn");
50 
52  if (F.doesNotAccessMemory())
53  return false;
54  F.setDoesNotAccessMemory();
55  ++NumReadNone;
56  return true;
57 }
58 
60  if (F.onlyAccessesInaccessibleMemory())
61  return false;
62  F.setOnlyAccessesInaccessibleMemory();
63  ++NumInaccessibleMemOnly;
64  return true;
65 }
66 
67 static bool setOnlyReadsMemory(Function &F) {
68  if (F.onlyReadsMemory())
69  return false;
70  F.setOnlyReadsMemory();
71  ++NumReadOnly;
72  return true;
73 }
74 
76  if (F.onlyWritesMemory()) // writeonly or readnone
77  return false;
78  // Turn readonly and writeonly into readnone.
79  if (F.hasFnAttribute(Attribute::ReadOnly)) {
80  F.removeFnAttr(Attribute::ReadOnly);
81  return setDoesNotAccessMemory(F);
82  }
83  ++NumWriteOnly;
84  F.setOnlyWritesMemory();
85  return true;
86 }
87 
89  if (F.onlyAccessesArgMemory())
90  return false;
91  F.setOnlyAccessesArgMemory();
92  ++NumArgMemOnly;
93  return true;
94 }
95 
97  if (F.onlyAccessesInaccessibleMemOrArgMem())
98  return false;
99  F.setOnlyAccessesInaccessibleMemOrArgMem();
100  ++NumInaccessibleMemOrArgMemOnly;
101  return true;
102 }
103 
104 static bool setDoesNotThrow(Function &F) {
105  if (F.doesNotThrow())
106  return false;
107  F.setDoesNotThrow();
108  ++NumNoUnwind;
109  return true;
110 }
111 
113  if (F.hasRetAttribute(Attribute::NoAlias))
114  return false;
115  F.addRetAttr(Attribute::NoAlias);
116  ++NumNoAlias;
117  return true;
118 }
119 
120 static bool setDoesNotCapture(Function &F, unsigned ArgNo) {
121  if (F.hasParamAttribute(ArgNo, Attribute::NoCapture))
122  return false;
123  F.addParamAttr(ArgNo, Attribute::NoCapture);
124  ++NumNoCapture;
125  return true;
126 }
127 
128 static bool setDoesNotAlias(Function &F, unsigned ArgNo) {
129  if (F.hasParamAttribute(ArgNo, Attribute::NoAlias))
130  return false;
131  F.addParamAttr(ArgNo, Attribute::NoAlias);
132  ++NumNoAlias;
133  return true;
134 }
135 
136 static bool setOnlyReadsMemory(Function &F, unsigned ArgNo) {
137  if (F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
138  return false;
139  F.addParamAttr(ArgNo, Attribute::ReadOnly);
140  ++NumReadOnlyArg;
141  return true;
142 }
143 
144 static bool setOnlyWritesMemory(Function &F, unsigned ArgNo) {
145  if (F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
146  return false;
147  F.addParamAttr(ArgNo, Attribute::WriteOnly);
148  ++NumWriteOnlyArg;
149  return true;
150 }
151 
152 static bool setRetNoUndef(Function &F) {
153  if (!F.getReturnType()->isVoidTy() &&
154  !F.hasRetAttribute(Attribute::NoUndef)) {
155  F.addRetAttr(Attribute::NoUndef);
156  ++NumNoUndef;
157  return true;
158  }
159  return false;
160 }
161 
162 static bool setArgsNoUndef(Function &F) {
163  bool Changed = false;
164  for (unsigned ArgNo = 0; ArgNo < F.arg_size(); ++ArgNo) {
165  if (!F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
166  F.addParamAttr(ArgNo, Attribute::NoUndef);
167  ++NumNoUndef;
168  Changed = true;
169  }
170  }
171  return Changed;
172 }
173 
174 static bool setArgNoUndef(Function &F, unsigned ArgNo) {
175  if (F.hasParamAttribute(ArgNo, Attribute::NoUndef))
176  return false;
177  F.addParamAttr(ArgNo, Attribute::NoUndef);
178  ++NumNoUndef;
179  return true;
180 }
181 
183  bool UndefAdded = false;
184  UndefAdded |= setRetNoUndef(F);
185  UndefAdded |= setArgsNoUndef(F);
186  return UndefAdded;
187 }
188 
189 static bool setReturnedArg(Function &F, unsigned ArgNo) {
190  if (F.hasParamAttribute(ArgNo, Attribute::Returned))
191  return false;
192  F.addParamAttr(ArgNo, Attribute::Returned);
193  ++NumReturnedArg;
194  return true;
195 }
196 
197 static bool setNonLazyBind(Function &F) {
198  if (F.hasFnAttribute(Attribute::NonLazyBind))
199  return false;
200  F.addFnAttr(Attribute::NonLazyBind);
201  return true;
202 }
203 
205  if (F.hasFnAttribute(Attribute::NoFree))
206  return false;
207  F.addFnAttr(Attribute::NoFree);
208  return true;
209 }
210 
211 static bool setWillReturn(Function &F) {
212  if (F.hasFnAttribute(Attribute::WillReturn))
213  return false;
214  F.addFnAttr(Attribute::WillReturn);
215  ++NumWillReturn;
216  return true;
217 }
218 
219 static bool setAlignedAllocParam(Function &F, unsigned ArgNo) {
220  if (F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
221  return false;
222  F.addParamAttr(ArgNo, Attribute::AllocAlign);
223  return true;
224 }
225 
226 static bool setAllocatedPointerParam(Function &F, unsigned ArgNo) {
227  if (F.hasParamAttribute(ArgNo, Attribute::AllocatedPointer))
228  return false;
229  F.addParamAttr(ArgNo, Attribute::AllocatedPointer);
230  return true;
231 }
232 
233 static bool setAllocSize(Function &F, unsigned ElemSizeArg,
234  Optional<unsigned> NumElemsArg) {
235  if (F.hasFnAttribute(Attribute::AllocSize))
236  return false;
237  F.addFnAttr(Attribute::getWithAllocSizeArgs(F.getContext(), ElemSizeArg,
238  NumElemsArg));
239  return true;
240 }
241 
242 static bool setAllocFamily(Function &F, StringRef Family) {
243  if (F.hasFnAttribute("alloc-family"))
244  return false;
245  F.addFnAttr("alloc-family", Family);
246  return true;
247 }
248 
249 static bool setAllocKind(Function &F, AllocFnKind K) {
250  if (F.hasFnAttribute(Attribute::AllocKind))
251  return false;
252  F.addFnAttr(
253  Attribute::get(F.getContext(), Attribute::AllocKind, uint64_t(K)));
254  return true;
255 }
256 
258  const TargetLibraryInfo &TLI) {
259  Function *F = M->getFunction(Name);
260  if (!F)
261  return false;
262  return inferNonMandatoryLibFuncAttrs(*F, TLI);
263 }
264 
266  const TargetLibraryInfo &TLI) {
267  LibFunc TheLibFunc;
268  if (!(TLI.getLibFunc(F, TheLibFunc) && TLI.has(TheLibFunc)))
269  return false;
270 
271  bool Changed = false;
272 
273  if (F.getParent() != nullptr && F.getParent()->getRtLibUseGOT())
274  Changed |= setNonLazyBind(F);
275 
276  switch (TheLibFunc) {
277  case LibFunc_strlen:
278  case LibFunc_strnlen:
279  case LibFunc_wcslen:
280  Changed |= setOnlyReadsMemory(F);
281  Changed |= setDoesNotThrow(F);
282  Changed |= setOnlyAccessesArgMemory(F);
283  Changed |= setWillReturn(F);
284  Changed |= setDoesNotCapture(F, 0);
285  break;
286  case LibFunc_strchr:
287  case LibFunc_strrchr:
288  Changed |= setOnlyAccessesArgMemory(F);
289  Changed |= setOnlyReadsMemory(F);
290  Changed |= setDoesNotThrow(F);
291  Changed |= setWillReturn(F);
292  break;
293  case LibFunc_strtol:
294  case LibFunc_strtod:
295  case LibFunc_strtof:
296  case LibFunc_strtoul:
297  case LibFunc_strtoll:
298  case LibFunc_strtold:
299  case LibFunc_strtoull:
300  Changed |= setDoesNotThrow(F);
301  Changed |= setWillReturn(F);
302  Changed |= setDoesNotCapture(F, 1);
303  Changed |= setOnlyReadsMemory(F, 0);
304  break;
305  case LibFunc_strcat:
306  case LibFunc_strncat:
307  Changed |= setOnlyAccessesArgMemory(F);
308  Changed |= setDoesNotThrow(F);
309  Changed |= setWillReturn(F);
310  Changed |= setReturnedArg(F, 0);
311  Changed |= setDoesNotCapture(F, 1);
312  Changed |= setOnlyReadsMemory(F, 1);
313  Changed |= setDoesNotAlias(F, 0);
314  Changed |= setDoesNotAlias(F, 1);
315  break;
316  case LibFunc_strcpy:
317  case LibFunc_strncpy:
318  Changed |= setReturnedArg(F, 0);
319  [[fallthrough]];
320  case LibFunc_stpcpy:
321  case LibFunc_stpncpy:
322  Changed |= setOnlyAccessesArgMemory(F);
323  Changed |= setDoesNotThrow(F);
324  Changed |= setWillReturn(F);
325  Changed |= setDoesNotCapture(F, 1);
326  Changed |= setOnlyWritesMemory(F, 0);
327  Changed |= setOnlyReadsMemory(F, 1);
328  Changed |= setDoesNotAlias(F, 0);
329  Changed |= setDoesNotAlias(F, 1);
330  break;
331  case LibFunc_strxfrm:
332  Changed |= setDoesNotThrow(F);
333  Changed |= setWillReturn(F);
334  Changed |= setDoesNotCapture(F, 0);
335  Changed |= setDoesNotCapture(F, 1);
336  Changed |= setOnlyReadsMemory(F, 1);
337  break;
338  case LibFunc_strcmp: // 0,1
339  case LibFunc_strspn: // 0,1
340  case LibFunc_strncmp: // 0,1
341  case LibFunc_strcspn: // 0,1
342  Changed |= setDoesNotThrow(F);
343  Changed |= setOnlyAccessesArgMemory(F);
344  Changed |= setWillReturn(F);
345  Changed |= setOnlyReadsMemory(F);
346  Changed |= setDoesNotCapture(F, 0);
347  Changed |= setDoesNotCapture(F, 1);
348  break;
349  case LibFunc_strcoll:
350  case LibFunc_strcasecmp: // 0,1
351  case LibFunc_strncasecmp: //
352  // Those functions may depend on the locale, which may be accessed through
353  // global memory.
354  Changed |= setOnlyReadsMemory(F);
355  Changed |= setDoesNotThrow(F);
356  Changed |= setWillReturn(F);
357  Changed |= setDoesNotCapture(F, 0);
358  Changed |= setDoesNotCapture(F, 1);
359  break;
360  case LibFunc_strstr:
361  case LibFunc_strpbrk:
362  Changed |= setOnlyAccessesArgMemory(F);
363  Changed |= setOnlyReadsMemory(F);
364  Changed |= setDoesNotThrow(F);
365  Changed |= setWillReturn(F);
366  Changed |= setDoesNotCapture(F, 1);
367  break;
368  case LibFunc_strtok:
369  case LibFunc_strtok_r:
370  Changed |= setDoesNotThrow(F);
371  Changed |= setWillReturn(F);
372  Changed |= setDoesNotCapture(F, 1);
373  Changed |= setOnlyReadsMemory(F, 1);
374  break;
375  case LibFunc_scanf:
376  Changed |= setRetAndArgsNoUndef(F);
377  Changed |= setDoesNotThrow(F);
378  Changed |= setDoesNotCapture(F, 0);
379  Changed |= setOnlyReadsMemory(F, 0);
380  break;
381  case LibFunc_setbuf:
382  case LibFunc_setvbuf:
383  Changed |= setRetAndArgsNoUndef(F);
384  Changed |= setDoesNotThrow(F);
385  Changed |= setDoesNotCapture(F, 0);
386  break;
387  case LibFunc_strndup:
388  Changed |= setArgNoUndef(F, 1);
389  [[fallthrough]];
390  case LibFunc_strdup:
391  Changed |= setAllocFamily(F, "malloc");
393  Changed |= setDoesNotThrow(F);
394  Changed |= setRetDoesNotAlias(F);
395  Changed |= setWillReturn(F);
396  Changed |= setDoesNotCapture(F, 0);
397  Changed |= setOnlyReadsMemory(F, 0);
398  break;
399  case LibFunc_stat:
400  case LibFunc_statvfs:
401  Changed |= setRetAndArgsNoUndef(F);
402  Changed |= setDoesNotThrow(F);
403  Changed |= setDoesNotCapture(F, 0);
404  Changed |= setDoesNotCapture(F, 1);
405  Changed |= setOnlyReadsMemory(F, 0);
406  break;
407  case LibFunc_sscanf:
408  Changed |= setRetAndArgsNoUndef(F);
409  Changed |= setDoesNotThrow(F);
410  Changed |= setDoesNotCapture(F, 0);
411  Changed |= setDoesNotCapture(F, 1);
412  Changed |= setOnlyReadsMemory(F, 0);
413  Changed |= setOnlyReadsMemory(F, 1);
414  break;
415  case LibFunc_sprintf:
416  Changed |= setRetAndArgsNoUndef(F);
417  Changed |= setDoesNotThrow(F);
418  Changed |= setDoesNotCapture(F, 0);
419  Changed |= setDoesNotAlias(F, 0);
420  Changed |= setOnlyWritesMemory(F, 0);
421  Changed |= setDoesNotCapture(F, 1);
422  Changed |= setOnlyReadsMemory(F, 1);
423  break;
424  case LibFunc_snprintf:
425  Changed |= setRetAndArgsNoUndef(F);
426  Changed |= setDoesNotThrow(F);
427  Changed |= setDoesNotCapture(F, 0);
428  Changed |= setDoesNotAlias(F, 0);
429  Changed |= setOnlyWritesMemory(F, 0);
430  Changed |= setDoesNotCapture(F, 2);
431  Changed |= setOnlyReadsMemory(F, 2);
432  break;
433  case LibFunc_setitimer:
434  Changed |= setRetAndArgsNoUndef(F);
435  Changed |= setDoesNotThrow(F);
436  Changed |= setWillReturn(F);
437  Changed |= setDoesNotCapture(F, 1);
438  Changed |= setDoesNotCapture(F, 2);
439  Changed |= setOnlyReadsMemory(F, 1);
440  break;
441  case LibFunc_system:
442  // May throw; "system" is a valid pthread cancellation point.
443  Changed |= setRetAndArgsNoUndef(F);
444  Changed |= setDoesNotCapture(F, 0);
445  Changed |= setOnlyReadsMemory(F, 0);
446  break;
447  case LibFunc_aligned_alloc:
448  Changed |= setAlignedAllocParam(F, 0);
449  Changed |= setAllocSize(F, 1, None);
451  [[fallthrough]];
452  case LibFunc_valloc:
453  case LibFunc_malloc:
454  case LibFunc_vec_malloc:
455  Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_malloc ? "vec_malloc"
456  : "malloc");
458  Changed |= setAllocSize(F, 0, None);
460  Changed |= setRetAndArgsNoUndef(F);
461  Changed |= setDoesNotThrow(F);
462  Changed |= setRetDoesNotAlias(F);
463  Changed |= setWillReturn(F);
464  break;
465  case LibFunc_memcmp:
466  Changed |= setOnlyAccessesArgMemory(F);
467  Changed |= setOnlyReadsMemory(F);
468  Changed |= setDoesNotThrow(F);
469  Changed |= setWillReturn(F);
470  Changed |= setDoesNotCapture(F, 0);
471  Changed |= setDoesNotCapture(F, 1);
472  break;
473  case LibFunc_memchr:
474  case LibFunc_memrchr:
475  Changed |= setDoesNotThrow(F);
476  Changed |= setOnlyAccessesArgMemory(F);
477  Changed |= setOnlyReadsMemory(F);
478  Changed |= setWillReturn(F);
479  break;
480  case LibFunc_modf:
481  case LibFunc_modff:
482  case LibFunc_modfl:
483  Changed |= setDoesNotThrow(F);
484  Changed |= setWillReturn(F);
485  Changed |= setDoesNotCapture(F, 1);
486  break;
487  case LibFunc_memcpy:
488  Changed |= setDoesNotThrow(F);
489  Changed |= setOnlyAccessesArgMemory(F);
490  Changed |= setWillReturn(F);
491  Changed |= setDoesNotAlias(F, 0);
492  Changed |= setReturnedArg(F, 0);
493  Changed |= setOnlyWritesMemory(F, 0);
494  Changed |= setDoesNotAlias(F, 1);
495  Changed |= setDoesNotCapture(F, 1);
496  Changed |= setOnlyReadsMemory(F, 1);
497  break;
498  case LibFunc_memmove:
499  Changed |= setDoesNotThrow(F);
500  Changed |= setOnlyAccessesArgMemory(F);
501  Changed |= setWillReturn(F);
502  Changed |= setReturnedArg(F, 0);
503  Changed |= setOnlyWritesMemory(F, 0);
504  Changed |= setDoesNotCapture(F, 1);
505  Changed |= setOnlyReadsMemory(F, 1);
506  break;
507  case LibFunc_mempcpy:
508  case LibFunc_memccpy:
509  Changed |= setWillReturn(F);
510  [[fallthrough]];
511  case LibFunc_memcpy_chk:
512  Changed |= setDoesNotThrow(F);
513  Changed |= setOnlyAccessesArgMemory(F);
514  Changed |= setDoesNotAlias(F, 0);
515  Changed |= setOnlyWritesMemory(F, 0);
516  Changed |= setDoesNotAlias(F, 1);
517  Changed |= setDoesNotCapture(F, 1);
518  Changed |= setOnlyReadsMemory(F, 1);
519  break;
520  case LibFunc_memalign:
521  Changed |= setAllocFamily(F, "malloc");
524  Changed |= setAllocSize(F, 1, None);
525  Changed |= setAlignedAllocParam(F, 0);
527  Changed |= setRetNoUndef(F);
528  Changed |= setDoesNotThrow(F);
529  Changed |= setRetDoesNotAlias(F);
530  Changed |= setWillReturn(F);
531  break;
532  case LibFunc_mkdir:
533  Changed |= setRetAndArgsNoUndef(F);
534  Changed |= setDoesNotThrow(F);
535  Changed |= setDoesNotCapture(F, 0);
536  Changed |= setOnlyReadsMemory(F, 0);
537  break;
538  case LibFunc_mktime:
539  Changed |= setRetAndArgsNoUndef(F);
540  Changed |= setDoesNotThrow(F);
541  Changed |= setWillReturn(F);
542  Changed |= setDoesNotCapture(F, 0);
543  break;
544  case LibFunc_realloc:
545  case LibFunc_reallocf:
546  case LibFunc_vec_realloc:
547  Changed |= setAllocFamily(
548  F, TheLibFunc == LibFunc_vec_realloc ? "vec_malloc" : "malloc");
549  Changed |= setAllocKind(F, AllocFnKind::Realloc);
550  Changed |= setAllocatedPointerParam(F, 0);
551  Changed |= setAllocSize(F, 1, None);
553  Changed |= setRetNoUndef(F);
554  Changed |= setDoesNotThrow(F);
555  Changed |= setRetDoesNotAlias(F);
556  Changed |= setWillReturn(F);
557  Changed |= setDoesNotCapture(F, 0);
558  Changed |= setArgNoUndef(F, 1);
559  break;
560  case LibFunc_read:
561  // May throw; "read" is a valid pthread cancellation point.
562  Changed |= setRetAndArgsNoUndef(F);
563  Changed |= setDoesNotCapture(F, 1);
564  break;
565  case LibFunc_rewind:
566  Changed |= setRetAndArgsNoUndef(F);
567  Changed |= setDoesNotThrow(F);
568  Changed |= setDoesNotCapture(F, 0);
569  break;
570  case LibFunc_rmdir:
571  case LibFunc_remove:
572  case LibFunc_realpath:
573  Changed |= setRetAndArgsNoUndef(F);
574  Changed |= setDoesNotThrow(F);
575  Changed |= setDoesNotCapture(F, 0);
576  Changed |= setOnlyReadsMemory(F, 0);
577  break;
578  case LibFunc_rename:
579  Changed |= setRetAndArgsNoUndef(F);
580  Changed |= setDoesNotThrow(F);
581  Changed |= setDoesNotCapture(F, 0);
582  Changed |= setDoesNotCapture(F, 1);
583  Changed |= setOnlyReadsMemory(F, 0);
584  Changed |= setOnlyReadsMemory(F, 1);
585  break;
586  case LibFunc_readlink:
587  Changed |= setRetAndArgsNoUndef(F);
588  Changed |= setDoesNotThrow(F);
589  Changed |= setDoesNotCapture(F, 0);
590  Changed |= setDoesNotCapture(F, 1);
591  Changed |= setOnlyReadsMemory(F, 0);
592  break;
593  case LibFunc_write:
594  // May throw; "write" is a valid pthread cancellation point.
595  Changed |= setRetAndArgsNoUndef(F);
596  Changed |= setDoesNotCapture(F, 1);
597  Changed |= setOnlyReadsMemory(F, 1);
598  break;
599  case LibFunc_bcopy:
600  Changed |= setDoesNotThrow(F);
601  Changed |= setOnlyAccessesArgMemory(F);
602  Changed |= setWillReturn(F);
603  Changed |= setDoesNotCapture(F, 0);
604  Changed |= setOnlyReadsMemory(F, 0);
605  Changed |= setOnlyWritesMemory(F, 1);
606  Changed |= setDoesNotCapture(F, 1);
607  break;
608  case LibFunc_bcmp:
609  Changed |= setDoesNotThrow(F);
610  Changed |= setOnlyAccessesArgMemory(F);
611  Changed |= setOnlyReadsMemory(F);
612  Changed |= setWillReturn(F);
613  Changed |= setDoesNotCapture(F, 0);
614  Changed |= setDoesNotCapture(F, 1);
615  break;
616  case LibFunc_bzero:
617  Changed |= setDoesNotThrow(F);
618  Changed |= setOnlyAccessesArgMemory(F);
619  Changed |= setWillReturn(F);
620  Changed |= setDoesNotCapture(F, 0);
621  Changed |= setOnlyWritesMemory(F, 0);
622  break;
623  case LibFunc_calloc:
624  case LibFunc_vec_calloc:
625  Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_calloc ? "vec_malloc"
626  : "malloc");
628  Changed |= setAllocSize(F, 0, 1);
630  Changed |= setRetAndArgsNoUndef(F);
631  Changed |= setDoesNotThrow(F);
632  Changed |= setRetDoesNotAlias(F);
633  Changed |= setWillReturn(F);
634  break;
635  case LibFunc_chmod:
636  case LibFunc_chown:
637  Changed |= setRetAndArgsNoUndef(F);
638  Changed |= setDoesNotThrow(F);
639  Changed |= setDoesNotCapture(F, 0);
640  Changed |= setOnlyReadsMemory(F, 0);
641  break;
642  case LibFunc_ctermid:
643  case LibFunc_clearerr:
644  case LibFunc_closedir:
645  Changed |= setRetAndArgsNoUndef(F);
646  Changed |= setDoesNotThrow(F);
647  Changed |= setDoesNotCapture(F, 0);
648  break;
649  case LibFunc_atoi:
650  case LibFunc_atol:
651  case LibFunc_atof:
652  case LibFunc_atoll:
653  Changed |= setDoesNotThrow(F);
654  Changed |= setOnlyReadsMemory(F);
655  Changed |= setWillReturn(F);
656  Changed |= setDoesNotCapture(F, 0);
657  break;
658  case LibFunc_access:
659  Changed |= setRetAndArgsNoUndef(F);
660  Changed |= setDoesNotThrow(F);
661  Changed |= setDoesNotCapture(F, 0);
662  Changed |= setOnlyReadsMemory(F, 0);
663  break;
664  case LibFunc_fopen:
665  Changed |= setRetAndArgsNoUndef(F);
666  Changed |= setDoesNotThrow(F);
667  Changed |= setRetDoesNotAlias(F);
668  Changed |= setDoesNotCapture(F, 0);
669  Changed |= setDoesNotCapture(F, 1);
670  Changed |= setOnlyReadsMemory(F, 0);
671  Changed |= setOnlyReadsMemory(F, 1);
672  break;
673  case LibFunc_fdopen:
674  Changed |= setRetAndArgsNoUndef(F);
675  Changed |= setDoesNotThrow(F);
676  Changed |= setRetDoesNotAlias(F);
677  Changed |= setDoesNotCapture(F, 1);
678  Changed |= setOnlyReadsMemory(F, 1);
679  break;
680  case LibFunc_feof:
681  Changed |= setRetAndArgsNoUndef(F);
682  Changed |= setDoesNotThrow(F);
683  Changed |= setDoesNotCapture(F, 0);
684  break;
685  case LibFunc_free:
686  case LibFunc_vec_free:
687  Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_free ? "vec_malloc"
688  : "malloc");
689  Changed |= setAllocKind(F, AllocFnKind::Free);
690  Changed |= setAllocatedPointerParam(F, 0);
692  Changed |= setArgsNoUndef(F);
693  Changed |= setDoesNotThrow(F);
694  Changed |= setWillReturn(F);
695  Changed |= setDoesNotCapture(F, 0);
696  break;
697  case LibFunc_fseek:
698  case LibFunc_ftell:
699  case LibFunc_fgetc:
700  case LibFunc_fgetc_unlocked:
701  case LibFunc_fseeko:
702  case LibFunc_ftello:
703  case LibFunc_fileno:
704  case LibFunc_fflush:
705  case LibFunc_fclose:
706  case LibFunc_fsetpos:
707  case LibFunc_flockfile:
708  case LibFunc_funlockfile:
709  case LibFunc_ftrylockfile:
710  Changed |= setRetAndArgsNoUndef(F);
711  Changed |= setDoesNotThrow(F);
712  Changed |= setDoesNotCapture(F, 0);
713  break;
714  case LibFunc_ferror:
715  Changed |= setRetAndArgsNoUndef(F);
716  Changed |= setDoesNotThrow(F);
717  Changed |= setDoesNotCapture(F, 0);
718  Changed |= setOnlyReadsMemory(F);
719  break;
720  case LibFunc_fputc:
721  case LibFunc_fputc_unlocked:
722  case LibFunc_fstat:
723  Changed |= setRetAndArgsNoUndef(F);
724  Changed |= setDoesNotThrow(F);
725  Changed |= setDoesNotCapture(F, 1);
726  break;
727  case LibFunc_frexp:
728  case LibFunc_frexpf:
729  case LibFunc_frexpl:
730  Changed |= setDoesNotThrow(F);
731  Changed |= setWillReturn(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_exp:
1141  case LibFunc_expf:
1142  case LibFunc_expl:
1143  case LibFunc_exp2:
1144  case LibFunc_exp2f:
1145  case LibFunc_exp2l:
1146  case LibFunc_expm1:
1147  case LibFunc_expm1f:
1148  case LibFunc_expm1l:
1149  case LibFunc_fabs:
1150  case LibFunc_fabsf:
1151  case LibFunc_fabsl:
1152  case LibFunc_ffs:
1153  case LibFunc_ffsl:
1154  case LibFunc_ffsll:
1155  case LibFunc_floor:
1156  case LibFunc_floorf:
1157  case LibFunc_floorl:
1158  case LibFunc_fls:
1159  case LibFunc_flsl:
1160  case LibFunc_flsll:
1161  case LibFunc_fmax:
1162  case LibFunc_fmaxf:
1163  case LibFunc_fmaxl:
1164  case LibFunc_fmin:
1165  case LibFunc_fminf:
1166  case LibFunc_fminl:
1167  case LibFunc_fmod:
1168  case LibFunc_fmodf:
1169  case LibFunc_fmodl:
1170  case LibFunc_isascii:
1171  case LibFunc_isdigit:
1172  case LibFunc_labs:
1173  case LibFunc_llabs:
1174  case LibFunc_log:
1175  case LibFunc_log10:
1176  case LibFunc_log10f:
1177  case LibFunc_log10l:
1178  case LibFunc_log1p:
1179  case LibFunc_log1pf:
1180  case LibFunc_log1pl:
1181  case LibFunc_log2:
1182  case LibFunc_log2f:
1183  case LibFunc_log2l:
1184  case LibFunc_logb:
1185  case LibFunc_logbf:
1186  case LibFunc_logbl:
1187  case LibFunc_logf:
1188  case LibFunc_logl:
1189  case LibFunc_nearbyint:
1190  case LibFunc_nearbyintf:
1191  case LibFunc_nearbyintl:
1192  case LibFunc_pow:
1193  case LibFunc_powf:
1194  case LibFunc_powl:
1195  case LibFunc_rint:
1196  case LibFunc_rintf:
1197  case LibFunc_rintl:
1198  case LibFunc_round:
1199  case LibFunc_roundf:
1200  case LibFunc_roundl:
1201  case LibFunc_sin:
1202  case LibFunc_sincospif_stret:
1203  case LibFunc_sinf:
1204  case LibFunc_sinh:
1205  case LibFunc_sinhf:
1206  case LibFunc_sinhl:
1207  case LibFunc_sinl:
1208  case LibFunc_sinpi:
1209  case LibFunc_sinpif:
1210  case LibFunc_sqrt:
1211  case LibFunc_sqrtf:
1212  case LibFunc_sqrtl:
1213  case LibFunc_tan:
1214  case LibFunc_tanf:
1215  case LibFunc_tanh:
1216  case LibFunc_tanhf:
1217  case LibFunc_tanhl:
1218  case LibFunc_tanl:
1219  case LibFunc_toascii:
1220  case LibFunc_trunc:
1221  case LibFunc_truncf:
1222  case LibFunc_truncl:
1223  Changed |= setDoesNotThrow(F);
1224  Changed |= setDoesNotFreeMemory(F);
1225  Changed |= setOnlyWritesMemory(F);
1226  Changed |= setWillReturn(F);
1227  break;
1228  default:
1229  // FIXME: It'd be really nice to cover all the library functions we're
1230  // aware of here.
1231  break;
1232  }
1233  // We have to do this step after AllocKind has been inferred on functions so
1234  // we can reliably identify free-like and realloc-like functions.
1235  if (!isLibFreeFunction(&F, TheLibFunc) && !isReallocLikeFn(&F, &TLI))
1236  Changed |= setDoesNotFreeMemory(F);
1237  return Changed;
1238 }
1239 
1240 static void setArgExtAttr(Function &F, unsigned ArgNo,
1241  const TargetLibraryInfo &TLI, bool Signed = true) {
1243  if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr))
1244  F.addParamAttr(ArgNo, ExtAttr);
1245 }
1246 
1247 // Modeled after X86TargetLowering::markLibCallAttributes.
1249  if (!F->arg_size() || F->isVarArg())
1250  return;
1251 
1252  const CallingConv::ID CC = F->getCallingConv();
1254  return;
1255 
1256  const Module *M = F->getParent();
1257  unsigned N = M->getNumberRegisterParameters();
1258  if (!N)
1259  return;
1260 
1261  const DataLayout &DL = M->getDataLayout();
1262 
1263  for (Argument &A : F->args()) {
1264  Type *T = A.getType();
1265  if (!T->isIntOrPtrTy())
1266  continue;
1267 
1268  const TypeSize &TS = DL.getTypeAllocSize(T);
1269  if (TS > 8)
1270  continue;
1271 
1272  assert(TS <= 4 && "Need to account for parameters larger than word size");
1273  const unsigned NumRegs = TS > 4 ? 2 : 1;
1274  if (N < NumRegs)
1275  return;
1276 
1277  N -= NumRegs;
1278  F->addParamAttr(A.getArgNo(), Attribute::InReg);
1279  }
1280 }
1281 
1283  LibFunc TheLibFunc, FunctionType *T,
1285  assert(TLI.has(TheLibFunc) &&
1286  "Creating call to non-existing library function.");
1287  StringRef Name = TLI.getName(TheLibFunc);
1288  FunctionCallee C = M->getOrInsertFunction(Name, T, AttributeList);
1289 
1290  // Make sure any mandatory argument attributes are added.
1291 
1292  // Any outgoing i32 argument should be handled with setArgExtAttr() which
1293  // will add an extension attribute if the target ABI requires it. Adding
1294  // argument extensions is typically done by the front end but when an
1295  // optimizer is building a library call on its own it has to take care of
1296  // this. Each such generated function must be handled here with sign or
1297  // zero extensions as needed. F is retreived with cast<> because we demand
1298  // of the caller to have called isLibFuncEmittable() first.
1299  Function *F = cast<Function>(C.getCallee());
1300  assert(F->getFunctionType() == T && "Function type does not match.");
1301  switch (TheLibFunc) {
1302  case LibFunc_fputc:
1303  case LibFunc_putchar:
1304  setArgExtAttr(*F, 0, TLI);
1305  break;
1306  case LibFunc_ldexp:
1307  case LibFunc_ldexpf:
1308  case LibFunc_ldexpl:
1309  case LibFunc_memchr:
1310  case LibFunc_memrchr:
1311  case LibFunc_strchr:
1312  setArgExtAttr(*F, 1, TLI);
1313  break;
1314  case LibFunc_memccpy:
1315  setArgExtAttr(*F, 2, TLI);
1316  break;
1317 
1318  // These are functions that are known to not need any argument extension
1319  // on any target: A size_t argument (which may be an i32 on some targets)
1320  // should not trigger the assert below.
1321  case LibFunc_bcmp:
1322  case LibFunc_calloc:
1323  case LibFunc_fwrite:
1324  case LibFunc_malloc:
1325  case LibFunc_memcmp:
1326  case LibFunc_memcpy_chk:
1327  case LibFunc_mempcpy:
1328  case LibFunc_memset_pattern16:
1329  case LibFunc_snprintf:
1330  case LibFunc_stpncpy:
1331  case LibFunc_strlcat:
1332  case LibFunc_strlcpy:
1333  case LibFunc_strncat:
1334  case LibFunc_strncmp:
1335  case LibFunc_strncpy:
1336  case LibFunc_vsnprintf:
1337  break;
1338 
1339  default:
1340 #ifndef NDEBUG
1341  for (unsigned i = 0; i < T->getNumParams(); i++)
1342  assert(!isa<IntegerType>(T->getParamType(i)) &&
1343  "Unhandled integer argument.");
1344 #endif
1345  break;
1346  }
1347 
1349 
1350  return C;
1351 }
1352 
1354  LibFunc TheLibFunc, FunctionType *T) {
1355  return getOrInsertLibFunc(M, TLI, TheLibFunc, T, AttributeList());
1356 }
1357 
1359  LibFunc TheLibFunc) {
1360  StringRef FuncName = TLI->getName(TheLibFunc);
1361  if (!TLI->has(TheLibFunc))
1362  return false;
1363 
1364  // Check if the Module already has a GlobalValue with the same name, in
1365  // which case it must be a Function with the expected type.
1366  if (GlobalValue *GV = M->getNamedValue(FuncName)) {
1367  if (auto *F = dyn_cast<Function>(GV))
1368  return TLI->isValidProtoForLibFunc(*F->getFunctionType(), TheLibFunc, *M);
1369  return false;
1370  }
1371 
1372  return true;
1373 }
1374 
1376  StringRef Name) {
1377  LibFunc TheLibFunc;
1378  return TLI->getLibFunc(Name, TheLibFunc) &&
1379  isLibFuncEmittable(M, TLI, TheLibFunc);
1380 }
1381 
1382 bool llvm::hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty,
1383  LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
1384  switch (Ty->getTypeID()) {
1385  case Type::HalfTyID:
1386  return false;
1387  case Type::FloatTyID:
1388  return isLibFuncEmittable(M, TLI, FloatFn);
1389  case Type::DoubleTyID:
1390  return isLibFuncEmittable(M, TLI, DoubleFn);
1391  default:
1392  return isLibFuncEmittable(M, TLI, LongDoubleFn);
1393  }
1394 }
1395 
1397  Type *Ty, LibFunc DoubleFn, LibFunc FloatFn,
1398  LibFunc LongDoubleFn, LibFunc &TheLibFunc) {
1399  assert(hasFloatFn(M, TLI, Ty, DoubleFn, FloatFn, LongDoubleFn) &&
1400  "Cannot get name for unavailable function!");
1401 
1402  switch (Ty->getTypeID()) {
1403  case Type::HalfTyID:
1404  llvm_unreachable("No name for HalfTy!");
1405  case Type::FloatTyID:
1406  TheLibFunc = FloatFn;
1407  return TLI->getName(FloatFn);
1408  case Type::DoubleTyID:
1409  TheLibFunc = DoubleFn;
1410  return TLI->getName(DoubleFn);
1411  default:
1412  TheLibFunc = LongDoubleFn;
1413  return TLI->getName(LongDoubleFn);
1414  }
1415 }
1416 
1417 //- Emit LibCalls ------------------------------------------------------------//
1418 
1420  unsigned AS = V->getType()->getPointerAddressSpace();
1421  return B.CreateBitCast(V, B.getInt8PtrTy(AS), "cstr");
1422 }
1423 
1425  return B.getIntNTy(TLI->getIntSize());
1426 }
1427 
1429  const Module *M = B.GetInsertBlock()->getModule();
1430  return B.getIntNTy(TLI->getSizeTSize(*M));
1431 }
1432 
1433 static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
1434  ArrayRef<Type *> ParamTypes,
1436  const TargetLibraryInfo *TLI,
1437  bool IsVaArgs = false) {
1438  Module *M = B.GetInsertBlock()->getModule();
1439  if (!isLibFuncEmittable(M, TLI, TheLibFunc))
1440  return nullptr;
1441 
1442  StringRef FuncName = TLI->getName(TheLibFunc);
1443  FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1444  FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, FuncType);
1445  inferNonMandatoryLibFuncAttrs(M, FuncName, *TLI);
1446  CallInst *CI = B.CreateCall(Callee, Operands, FuncName);
1447  if (const Function *F =
1448  dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1449  CI->setCallingConv(F->getCallingConv());
1450  return CI;
1451 }
1452 
1454  const TargetLibraryInfo *TLI) {
1455  Type *SizeTTy = getSizeTTy(B, TLI);
1456  return emitLibCall(LibFunc_strlen, SizeTTy,
1457  B.getInt8PtrTy(), castToCStr(Ptr, B), B, TLI);
1458 }
1459 
1461  const TargetLibraryInfo *TLI) {
1462  return emitLibCall(LibFunc_strdup, B.getInt8PtrTy(), B.getInt8PtrTy(),
1463  castToCStr(Ptr, B), B, TLI);
1464 }
1465 
1467  const TargetLibraryInfo *TLI) {
1468  Type *I8Ptr = B.getInt8PtrTy();
1469  Type *IntTy = getIntTy(B, TLI);
1470  return emitLibCall(LibFunc_strchr, I8Ptr, {I8Ptr, IntTy},
1471  {castToCStr(Ptr, B), ConstantInt::get(IntTy, C)}, B, TLI);
1472 }
1473 
1475  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1476  Type *IntTy = getIntTy(B, TLI);
1477  Type *SizeTTy = getSizeTTy(B, TLI);
1478  return emitLibCall(
1479  LibFunc_strncmp, IntTy,
1480  {B.getInt8PtrTy(), B.getInt8PtrTy(), SizeTTy},
1481  {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
1482 }
1483 
1485  const TargetLibraryInfo *TLI) {
1486  Type *I8Ptr = Dst->getType();
1487  return emitLibCall(LibFunc_strcpy, I8Ptr, {I8Ptr, I8Ptr},
1488  {castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI);
1489 }
1490 
1492  const TargetLibraryInfo *TLI) {
1493  Type *I8Ptr = B.getInt8PtrTy();
1494  return emitLibCall(LibFunc_stpcpy, I8Ptr, {I8Ptr, I8Ptr},
1495  {castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI);
1496 }
1497 
1499  const TargetLibraryInfo *TLI) {
1500  Type *I8Ptr = B.getInt8PtrTy();
1501  Type *SizeTTy = getSizeTTy(B, TLI);
1502  return emitLibCall(LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
1503  {castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
1504 }
1505 
1507  const TargetLibraryInfo *TLI) {
1508  Type *I8Ptr = B.getInt8PtrTy();
1509  Type *SizeTTy = getSizeTTy(B, TLI);
1510  return emitLibCall(LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
1511  {castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
1512 }
1513 
1514 Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
1515  IRBuilderBase &B, const DataLayout &DL,
1516  const TargetLibraryInfo *TLI) {
1517  Module *M = B.GetInsertBlock()->getModule();
1518  if (!isLibFuncEmittable(M, TLI, LibFunc_memcpy_chk))
1519  return nullptr;
1520 
1521  AttributeList AS;
1523  Attribute::NoUnwind);
1524  Type *I8Ptr = B.getInt8PtrTy();
1525  Type *SizeTTy = getSizeTTy(B, TLI);
1526  FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
1527  AttributeList::get(M->getContext(), AS), I8Ptr,
1528  I8Ptr, I8Ptr, SizeTTy, SizeTTy);
1529  Dst = castToCStr(Dst, B);
1530  Src = castToCStr(Src, B);
1531  CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1532  if (const Function *F =
1533  dyn_cast<Function>(MemCpy.getCallee()->stripPointerCasts()))
1534  CI->setCallingConv(F->getCallingConv());
1535  return CI;
1536 }
1537 
1539  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1540  Type *I8Ptr = B.getInt8PtrTy();
1541  Type *SizeTTy = getSizeTTy(B, TLI);
1542  return emitLibCall(LibFunc_mempcpy, I8Ptr,
1543  {I8Ptr, I8Ptr, SizeTTy},
1544  {Dst, Src, Len}, B, TLI);
1545 }
1546 
1548  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1549  Type *I8Ptr = B.getInt8PtrTy();
1550  Type *IntTy = getIntTy(B, TLI);
1551  Type *SizeTTy = getSizeTTy(B, TLI);
1552  return emitLibCall(LibFunc_memchr, I8Ptr,
1553  {I8Ptr, IntTy, SizeTTy},
1554  {castToCStr(Ptr, B), Val, Len}, B, TLI);
1555 }
1556 
1558  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1559  Type *I8Ptr = B.getInt8PtrTy();
1560  Type *IntTy = getIntTy(B, TLI);
1561  Type *SizeTTy = getSizeTTy(B, TLI);
1562  return emitLibCall(LibFunc_memrchr, I8Ptr,
1563  {I8Ptr, IntTy, SizeTTy},
1564  {castToCStr(Ptr, B), Val, Len}, B, TLI);
1565 }
1566 
1568  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1569  Type *I8Ptr = B.getInt8PtrTy();
1570  Type *IntTy = getIntTy(B, TLI);
1571  Type *SizeTTy = getSizeTTy(B, TLI);
1572  return emitLibCall(LibFunc_memcmp, IntTy,
1573  {I8Ptr, I8Ptr, SizeTTy},
1574  {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
1575 }
1576 
1578  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1579  Type *I8Ptr = B.getInt8PtrTy();
1580  Type *IntTy = getIntTy(B, TLI);
1581  Type *SizeTTy = getSizeTTy(B, TLI);
1582  return emitLibCall(LibFunc_bcmp, IntTy,
1583  {I8Ptr, I8Ptr, SizeTTy},
1584  {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
1585 }
1586 
1587 Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
1588  IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1589  Type *I8Ptr = B.getInt8PtrTy();
1590  Type *IntTy = getIntTy(B, TLI);
1591  Type *SizeTTy = getSizeTTy(B, TLI);
1592  return emitLibCall(LibFunc_memccpy, I8Ptr,
1593  {I8Ptr, I8Ptr, IntTy, SizeTTy},
1594  {Ptr1, Ptr2, Val, Len}, B, TLI);
1595 }
1596 
1598  ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1599  const TargetLibraryInfo *TLI) {
1600  Type *I8Ptr = B.getInt8PtrTy();
1601  Type *IntTy = getIntTy(B, TLI);
1602  Type *SizeTTy = getSizeTTy(B, TLI);
1603  SmallVector<Value *, 8> Args{castToCStr(Dest, B), Size, castToCStr(Fmt, B)};
1604  llvm::append_range(Args, VariadicArgs);
1605  return emitLibCall(LibFunc_snprintf, IntTy,
1606  {I8Ptr, SizeTTy, I8Ptr},
1607  Args, B, TLI, /*IsVaArgs=*/true);
1608 }
1609 
1611  ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1612  const TargetLibraryInfo *TLI) {
1613  Type *I8Ptr = B.getInt8PtrTy();
1614  Type *IntTy = getIntTy(B, TLI);
1616  llvm::append_range(Args, VariadicArgs);
1617  return emitLibCall(LibFunc_sprintf, IntTy,
1618  {I8Ptr, I8Ptr}, Args, B, TLI,
1619  /*IsVaArgs=*/true);
1620 }
1621 
1623  const TargetLibraryInfo *TLI) {
1624  return emitLibCall(LibFunc_strcat, B.getInt8PtrTy(),
1625  {B.getInt8PtrTy(), B.getInt8PtrTy()},
1626  {castToCStr(Dest, B), castToCStr(Src, B)}, B, TLI);
1627 }
1628 
1630  const TargetLibraryInfo *TLI) {
1631  Type *I8Ptr = B.getInt8PtrTy();
1632  Type *SizeTTy = getSizeTTy(B, TLI);
1633  return emitLibCall(LibFunc_strlcpy, SizeTTy,
1634  {I8Ptr, I8Ptr, SizeTTy},
1635  {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
1636 }
1637 
1639  const TargetLibraryInfo *TLI) {
1640  Type *I8Ptr = B.getInt8PtrTy();
1641  Type *SizeTTy = getSizeTTy(B, TLI);
1642  return emitLibCall(LibFunc_strlcat, SizeTTy,
1643  {I8Ptr, I8Ptr, SizeTTy},
1644  {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
1645 }
1646 
1648  const TargetLibraryInfo *TLI) {
1649  Type *I8Ptr = B.getInt8PtrTy();
1650  Type *SizeTTy = getSizeTTy(B, TLI);
1651  return emitLibCall(LibFunc_strncat, I8Ptr,
1652  {I8Ptr, I8Ptr, SizeTTy},
1653  {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
1654 }
1655 
1656 Value *llvm::emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList,
1657  IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1658  Type *I8Ptr = B.getInt8PtrTy();
1659  Type *IntTy = getIntTy(B, TLI);
1660  Type *SizeTTy = getSizeTTy(B, TLI);
1661  return emitLibCall(
1662  LibFunc_vsnprintf, IntTy,
1663  {I8Ptr, SizeTTy, I8Ptr, VAList->getType()},
1664  {castToCStr(Dest, B), Size, castToCStr(Fmt, B), VAList}, B, TLI);
1665 }
1666 
1667 Value *llvm::emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList,
1668  IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1669  Type *I8Ptr = B.getInt8PtrTy();
1670  Type *IntTy = getIntTy(B, TLI);
1671  return emitLibCall(LibFunc_vsprintf, IntTy,
1672  {I8Ptr, I8Ptr, VAList->getType()},
1673  {castToCStr(Dest, B), castToCStr(Fmt, B), VAList}, B, TLI);
1674 }
1675 
1676 /// Append a suffix to the function name according to the type of 'Op'.
1678  SmallString<20> &NameBuffer) {
1679  if (!Op->getType()->isDoubleTy()) {
1680  NameBuffer += Name;
1681 
1682  if (Op->getType()->isFloatTy())
1683  NameBuffer += 'f';
1684  else
1685  NameBuffer += 'l';
1686 
1687  Name = NameBuffer;
1688  }
1689 }
1690 
1693  const AttributeList &Attrs,
1694  const TargetLibraryInfo *TLI) {
1695  assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
1696 
1697  Module *M = B.GetInsertBlock()->getModule();
1698  FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op->getType(),
1699  Op->getType());
1700  CallInst *CI = B.CreateCall(Callee, Op, Name);
1701 
1702  // The incoming attribute set may have come from a speculatable intrinsic, but
1703  // is being replaced with a library call which is not allowed to be
1704  // speculatable.
1705  CI->setAttributes(
1706  Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1707  if (const Function *F =
1708  dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1709  CI->setCallingConv(F->getCallingConv());
1710 
1711  return CI;
1712 }
1713 
1716  const AttributeList &Attrs) {
1717  SmallString<20> NameBuffer;
1718  appendTypeSuffix(Op, Name, NameBuffer);
1719 
1720  LibFunc TheLibFunc;
1721  TLI->getLibFunc(Name, TheLibFunc);
1722 
1723  return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1724 }
1725 
1727  LibFunc DoubleFn, LibFunc FloatFn,
1728  LibFunc LongDoubleFn, IRBuilderBase &B,
1729  const AttributeList &Attrs) {
1730  // Get the name of the function according to TLI.
1731  Module *M = B.GetInsertBlock()->getModule();
1732  LibFunc TheLibFunc;
1733  StringRef Name = getFloatFn(M, TLI, Op->getType(), DoubleFn, FloatFn,
1734  LongDoubleFn, TheLibFunc);
1735 
1736  return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1737 }
1738 
1740  LibFunc TheLibFunc,
1742  const AttributeList &Attrs,
1743  const TargetLibraryInfo *TLI) {
1744  assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1745 
1746  Module *M = B.GetInsertBlock()->getModule();
1747  FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op1->getType(),
1748  Op1->getType(), Op2->getType());
1750  CallInst *CI = B.CreateCall(Callee, { Op1, Op2 }, Name);
1751 
1752  // The incoming attribute set may have come from a speculatable intrinsic, but
1753  // is being replaced with a library call which is not allowed to be
1754  // speculatable.
1755  CI->setAttributes(
1756  Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1757  if (const Function *F =
1758  dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1759  CI->setCallingConv(F->getCallingConv());
1760 
1761  return CI;
1762 }
1763 
1765  const TargetLibraryInfo *TLI,
1767  const AttributeList &Attrs) {
1768  assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1769 
1770  SmallString<20> NameBuffer;
1771  appendTypeSuffix(Op1, Name, NameBuffer);
1772 
1773  LibFunc TheLibFunc;
1774  TLI->getLibFunc(Name, TheLibFunc);
1775 
1776  return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
1777 }
1778 
1780  const TargetLibraryInfo *TLI,
1781  LibFunc DoubleFn, LibFunc FloatFn,
1782  LibFunc LongDoubleFn, IRBuilderBase &B,
1783  const AttributeList &Attrs) {
1784  // Get the name of the function according to TLI.
1785  Module *M = B.GetInsertBlock()->getModule();
1786  LibFunc TheLibFunc;
1787  StringRef Name = getFloatFn(M, TLI, Op1->getType(), DoubleFn, FloatFn,
1788  LongDoubleFn, TheLibFunc);
1789 
1790  return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
1791 }
1792 
1793 // Emit a call to putchar(int) with Char as the argument. Char must have
1794 // the same precision as int, which need not be 32 bits.
1796  const TargetLibraryInfo *TLI) {
1797  Module *M = B.GetInsertBlock()->getModule();
1798  if (!isLibFuncEmittable(M, TLI, LibFunc_putchar))
1799  return nullptr;
1800 
1801  Type *IntTy = getIntTy(B, TLI);
1802  StringRef PutCharName = TLI->getName(LibFunc_putchar);
1803  FunctionCallee PutChar = getOrInsertLibFunc(M, *TLI, LibFunc_putchar,
1804  IntTy, IntTy);
1805  inferNonMandatoryLibFuncAttrs(M, PutCharName, *TLI);
1806  CallInst *CI = B.CreateCall(PutChar, Char, PutCharName);
1807 
1808  if (const Function *F =
1809  dyn_cast<Function>(PutChar.getCallee()->stripPointerCasts()))
1810  CI->setCallingConv(F->getCallingConv());
1811  return CI;
1812 }
1813 
1815  const TargetLibraryInfo *TLI) {
1816  Module *M = B.GetInsertBlock()->getModule();
1817  if (!isLibFuncEmittable(M, TLI, LibFunc_puts))
1818  return nullptr;
1819 
1820  Type *IntTy = getIntTy(B, TLI);
1821  StringRef PutsName = TLI->getName(LibFunc_puts);
1822  FunctionCallee PutS = getOrInsertLibFunc(M, *TLI, LibFunc_puts, IntTy,
1823  B.getInt8PtrTy());
1824  inferNonMandatoryLibFuncAttrs(M, PutsName, *TLI);
1825  CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), PutsName);
1826  if (const Function *F =
1827  dyn_cast<Function>(PutS.getCallee()->stripPointerCasts()))
1828  CI->setCallingConv(F->getCallingConv());
1829  return CI;
1830 }
1831 
1833  const TargetLibraryInfo *TLI) {
1834  Module *M = B.GetInsertBlock()->getModule();
1835  if (!isLibFuncEmittable(M, TLI, LibFunc_fputc))
1836  return nullptr;
1837 
1838  Type *IntTy = getIntTy(B, TLI);
1839  StringRef FPutcName = TLI->getName(LibFunc_fputc);
1840  FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputc, IntTy,
1841  IntTy, File->getType());
1842  if (File->getType()->isPointerTy())
1843  inferNonMandatoryLibFuncAttrs(M, FPutcName, *TLI);
1844  CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName);
1845 
1846  if (const Function *Fn =
1847  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1848  CI->setCallingConv(Fn->getCallingConv());
1849  return CI;
1850 }
1851 
1853  const TargetLibraryInfo *TLI) {
1854  Module *M = B.GetInsertBlock()->getModule();
1855  if (!isLibFuncEmittable(M, TLI, LibFunc_fputs))
1856  return nullptr;
1857 
1858  Type *IntTy = getIntTy(B, TLI);
1859  StringRef FPutsName = TLI->getName(LibFunc_fputs);
1860  FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputs, IntTy,
1861  B.getInt8PtrTy(), File->getType());
1862  if (File->getType()->isPointerTy())
1863  inferNonMandatoryLibFuncAttrs(M, FPutsName, *TLI);
1864  CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsName);
1865 
1866  if (const Function *Fn =
1867  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1868  CI->setCallingConv(Fn->getCallingConv());
1869  return CI;
1870 }
1871 
1873  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1874  Module *M = B.GetInsertBlock()->getModule();
1875  if (!isLibFuncEmittable(M, TLI, LibFunc_fwrite))
1876  return nullptr;
1877 
1878  Type *SizeTTy = getSizeTTy(B, TLI);
1879  StringRef FWriteName = TLI->getName(LibFunc_fwrite);
1880  FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fwrite,
1881  SizeTTy, B.getInt8PtrTy(), SizeTTy,
1882  SizeTTy, File->getType());
1883 
1884  if (File->getType()->isPointerTy())
1885  inferNonMandatoryLibFuncAttrs(M, FWriteName, *TLI);
1886  CallInst *CI =
1887  B.CreateCall(F, {castToCStr(Ptr, B), Size,
1888  ConstantInt::get(SizeTTy, 1), File});
1889 
1890  if (const Function *Fn =
1891  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1892  CI->setCallingConv(Fn->getCallingConv());
1893  return CI;
1894 }
1895 
1897  const TargetLibraryInfo *TLI) {
1898  Module *M = B.GetInsertBlock()->getModule();
1899  if (!isLibFuncEmittable(M, TLI, LibFunc_malloc))
1900  return nullptr;
1901 
1902  StringRef MallocName = TLI->getName(LibFunc_malloc);
1903  Type *SizeTTy = getSizeTTy(B, TLI);
1904  FunctionCallee Malloc = getOrInsertLibFunc(M, *TLI, LibFunc_malloc,
1905  B.getInt8PtrTy(), SizeTTy);
1906  inferNonMandatoryLibFuncAttrs(M, MallocName, *TLI);
1907  CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
1908 
1909  if (const Function *F =
1910  dyn_cast<Function>(Malloc.getCallee()->stripPointerCasts()))
1911  CI->setCallingConv(F->getCallingConv());
1912 
1913  return CI;
1914 }
1915 
1917  const TargetLibraryInfo &TLI) {
1918  Module *M = B.GetInsertBlock()->getModule();
1919  if (!isLibFuncEmittable(M, &TLI, LibFunc_calloc))
1920  return nullptr;
1921 
1922  StringRef CallocName = TLI.getName(LibFunc_calloc);
1923  Type *SizeTTy = getSizeTTy(B, &TLI);
1924  FunctionCallee Calloc = getOrInsertLibFunc(M, TLI, LibFunc_calloc,
1925  B.getInt8PtrTy(), SizeTTy, SizeTTy);
1926  inferNonMandatoryLibFuncAttrs(M, CallocName, TLI);
1927  CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
1928 
1929  if (const auto *F =
1930  dyn_cast<Function>(Calloc.getCallee()->stripPointerCasts()))
1931  CI->setCallingConv(F->getCallingConv());
1932 
1933  return CI;
1934 }
setAllocSize
static bool setAllocSize(Function &F, unsigned ElemSizeArg, Optional< unsigned > NumElemsArg)
Definition: BuildLibCalls.cpp:233
i
i
Definition: README.txt:29
emitUnaryFloatFnCallHelper
static Value * emitUnaryFloatFnCallHelper(Value *Op, LibFunc TheLibFunc, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs, const TargetLibraryInfo *TLI)
Definition: BuildLibCalls.cpp:1691
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm::Type::FloatTyID
@ FloatTyID
32-bit floating point type
Definition: Type.h:58
Signed
@ Signed
Definition: NVPTXISelLowering.cpp:4710
getSizeTTy
static IntegerType * getSizeTTy(IRBuilderBase &B, const TargetLibraryInfo *TLI)
Definition: BuildLibCalls.cpp:1428
llvm::Type::DoubleTyID
@ DoubleTyID
64-bit floating point type
Definition: Type.h:59
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::Attribute::getWithAllocSizeArgs
static Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Definition: Attributes.cpp:212
MallocFamily::Malloc
@ Malloc
T
llvm::Function
Definition: Function.h:60
llvm::emitCalloc
Value * emitCalloc(Value *Num, Value *Size, IRBuilderBase &B, const TargetLibraryInfo &TLI)
Emit a call to the calloc function.
Definition: BuildLibCalls.cpp:1916
llvm::Attribute::get
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:90
TypeSize.h
llvm::SmallVector< Value *, 8 >
Statistic.h
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:1714
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:1567
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:1872
llvm::Type::getPointerAddressSpace
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:729
setOnlyAccessesArgMemory
static bool setOnlyAccessesArgMemory(Function &F)
Definition: BuildLibCalls.cpp:88
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:1677
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:1587
llvm::FunctionType::get
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:361
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:1050
llvm::Type::getTypeID
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:136
setDoesNotCapture
static bool setDoesNotCapture(Function &F, unsigned ArgNo)
Definition: BuildLibCalls.cpp:120
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Module.h
setOnlyReadsMemory
static bool setOnlyReadsMemory(Function &F)
Definition: BuildLibCalls.cpp:67
setArgNoUndef
static bool setArgNoUndef(Function &F, unsigned ArgNo)
Definition: BuildLibCalls.cpp:174
MemoryBuiltins.h
llvm::AttributeList
Definition: Attributes.h:425
llvm::TargetLibraryInfo::getExtAttrForI32Param
Attribute::AttrKind getExtAttrForI32Param(bool Signed=true) const
Returns extension attribute kind to be used for i32 parameters corresponding to C-level int or unsign...
Definition: TargetLibraryInfo.h:390
llvm::AllocFnKind::Alloc
@ Alloc
llvm::Optional< unsigned >
setArgExtAttr
static void setArgExtAttr(Function &F, unsigned ArgNo, const TargetLibraryInfo &TLI, bool Signed=true)
Definition: BuildLibCalls.cpp:1240
setDoesNotAccessMemory
static bool setDoesNotAccessMemory(Function &F)
Definition: BuildLibCalls.cpp:51
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:1433
F
#define F(x, y, z)
Definition: MD5.cpp:55
setWillReturn
static bool setWillReturn(Function &F)
Definition: BuildLibCalls.cpp:211
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:1460
llvm::emitFPutC
Value * emitFPutC(Value *Char, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
Definition: BuildLibCalls.cpp:1832
Constants.h
llvm::TargetLibraryInfo::getIntSize
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
Definition: TargetLibraryInfo.h:416
SmallString.h
setRetNoUndef
static bool setRetNoUndef(Function &F)
Definition: BuildLibCalls.cpp:152
llvm::LibFunc
LibFunc
Definition: TargetLibraryInfo.h:35
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::CallBase::setAttributes
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
Definition: InstrTypes.h:1478
llvm::emitStrCat
Value * emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcat function.
Definition: BuildLibCalls.cpp:1622
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:1629
TargetLibraryInfo.h
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::IntegerType
Class to represent integer types.
Definition: DerivedTypes.h:40
llvm::TargetLibraryInfo::getLibFunc
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
Definition: TargetLibraryInfo.h:297
emitBinaryFloatFnCallHelper
static Value * emitBinaryFloatFnCallHelper(Value *Op1, Value *Op2, LibFunc TheLibFunc, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs, const TargetLibraryInfo *TLI)
Definition: BuildLibCalls.cpp:1739
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
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:1795
llvm::ConstantInt::get
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:879
llvm::TargetLibraryInfo::getName
StringRef getName(LibFunc F) const
Definition: TargetLibraryInfo.h:377
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:1557
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:1474
llvm::None
const NoneType None
Definition: None.h:24
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
markRegisterParameterAttributes
static void markRegisterParameterAttributes(Function *F)
Definition: BuildLibCalls.cpp:1248
Type.h
llvm::SmallString
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
Operands
mir Rename Register Operands
Definition: MIRNamerPass.cpp:74
llvm::isReallocLikeFn
bool isReallocLikeFn(const Function *F, const TargetLibraryInfo *TLI)
Tests if a function is a call or invoke to a library function that reallocates memory (e....
Definition: MemoryBuiltins.cpp:345
llvm::AllocFnKind::Realloc
@ Realloc
llvm::AllocFnKind::Free
@ Free
setDoesNotAlias
static bool setDoesNotAlias(Function &F, unsigned ArgNo)
Definition: BuildLibCalls.cpp:128
llvm::GlobalValue
Definition: GlobalValue.h:44
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:1396
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:1610
uint64_t
llvm::Attribute::None
@ None
No attributes have been set.
Definition: Attributes.h:86
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:1514
setReturnedArg
static bool setReturnedArg(Function &F, unsigned ArgNo)
Definition: BuildLibCalls.cpp:189
setAllocFamily
static bool setAllocFamily(Function &F, StringRef Family)
Definition: BuildLibCalls.cpp:242
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:1382
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:1638
setOnlyAccessesInaccessibleMemory
static bool setOnlyAccessesInaccessibleMemory(Function &F)
Definition: BuildLibCalls.cpp:59
llvm::Attribute::AttrKind
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:84
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:1282
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:1577
llvm::AllocFnKind::Aligned
@ Aligned
IRBuilder.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
setArgsNoUndef
static bool setArgsNoUndef(Function &F)
Definition: BuildLibCalls.cpp:162
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:1538
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:1506
Ptr
@ Ptr
Definition: TargetLibraryInfo.cpp:60
llvm::TargetLibraryInfo::has
bool has(LibFunc F) const
Tests whether a library function is available.
Definition: TargetLibraryInfo.h:331
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:1647
setDoesNotFreeMemory
static bool setDoesNotFreeMemory(Function &F)
Definition: BuildLibCalls.cpp:204
setRetAndArgsNoUndef
static bool setRetAndArgsNoUndef(Function &F)
Definition: BuildLibCalls.cpp:182
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::ARM::WinEH::ReturnType
ReturnType
Definition: ARMWinEH.h:25
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::TargetLibraryInfo::getSizeTSize
unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
Definition: TargetLibraryInfo.h:413
setOnlyAccessesInaccessibleMemOrArgMem
static bool setOnlyAccessesInaccessibleMemOrArgMem(Function &F)
Definition: BuildLibCalls.cpp:96
DataLayout.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:1818
llvm::IRBuilderBase
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:93
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
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:1491
CC
auto CC
Definition: RISCVRedundantCopyElimination.cpp:79
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:1453
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:1484
setRetDoesNotAlias
static bool setRetDoesNotAlias(Function &F)
Definition: BuildLibCalls.cpp:112
getIntTy
static IntegerType * getIntTy(IRBuilderBase &B, const TargetLibraryInfo *TLI)
Definition: BuildLibCalls.cpp:1424
llvm::Value::stripPointerCasts
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:685
llvm::FunctionCallee::getCallee
Value * getCallee()
Definition: DerivedTypes.h:184
Argument.h
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:187
CallingConv.h
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:1358
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:348
llvm::TypeSize
Definition: TypeSize.h:435
llvm::AllocFnKind::Uninitialized
@ Uninitialized
Function.h
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:225
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:288
llvm::emitFPutS
Value * emitFPutS(Value *Str, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
Definition: BuildLibCalls.cpp:1852
setAllocatedPointerParam
static bool setAllocatedPointerParam(Function &F, unsigned ArgNo)
Definition: BuildLibCalls.cpp:226
setAllocKind
static bool setAllocKind(Function &F, AllocFnKind K)
Definition: BuildLibCalls.cpp:249
llvm::emitMalloc
Value * emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
Definition: BuildLibCalls.cpp:1896
llvm::castToCStr
Value * castToCStr(Value *V, IRBuilderBase &B)
Return V if it is an i8*, otherwise cast it to i8*.
Definition: BuildLibCalls.cpp:1419
setDoesNotThrow
static bool setDoesNotThrow(Function &F)
Definition: BuildLibCalls.cpp:104
llvm::AttributeList::FunctionIndex
@ FunctionIndex
Definition: Attributes.h:429
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:1498
N
#define N
llvm::CallingConv::X86_StdCall
@ X86_StdCall
stdcall is mostly used by the Win32 API.
Definition: CallingConv.h:96
llvm::AllocFnKind
AllocFnKind
Definition: Attributes.h:47
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:1764
llvm::FunctionCallee
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:165
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:1597
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:1814
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:1466
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1474
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:257
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::isLibFreeFunction
bool isLibFreeFunction(const Function *F, const LibFunc TLIFn)
isLibFreeFunction - Returns true if the function is a builtin free()
Definition: MemoryBuiltins.cpp:563
setNonLazyBind
static bool setNonLazyBind(Function &F)
Definition: BuildLibCalls.cpp:197
setOnlyWritesMemory
static bool setOnlyWritesMemory(Function &F)
Definition: BuildLibCalls.cpp:75
setAlignedAllocParam
static bool setAlignedAllocParam(Function &F, unsigned ArgNo)
Definition: BuildLibCalls.cpp:219
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:1667
BuildLibCalls.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
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:1656
llvm::Type::HalfTyID
@ HalfTyID
16-bit floating point type
Definition: Type.h:56
llvm::AllocFnKind::Zeroed
@ Zeroed
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:1547
llvm::CallBase::setCallingConv
void setCallingConv(CallingConv::ID CC)
Definition: InstrTypes.h:1459
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:103