LLVM  15.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(!isLibFreeFunction(&F, TheLibFunc) && !isReallocLikeFn(&F, &TLI))
274  Changed |= setDoesNotFreeMemory(F);
275 
276  if (F.getParent() != nullptr && F.getParent()->getRtLibUseGOT())
277  Changed |= setNonLazyBind(F);
278 
279  switch (TheLibFunc) {
280  case LibFunc_strlen:
281  case LibFunc_strnlen:
282  case LibFunc_wcslen:
283  Changed |= setOnlyReadsMemory(F);
284  Changed |= setDoesNotThrow(F);
285  Changed |= setOnlyAccessesArgMemory(F);
286  Changed |= setWillReturn(F);
287  Changed |= setDoesNotCapture(F, 0);
288  return Changed;
289  case LibFunc_strchr:
290  case LibFunc_strrchr:
291  Changed |= setOnlyAccessesArgMemory(F);
292  Changed |= setOnlyReadsMemory(F);
293  Changed |= setDoesNotThrow(F);
294  Changed |= setWillReturn(F);
295  return Changed;
296  case LibFunc_strtol:
297  case LibFunc_strtod:
298  case LibFunc_strtof:
299  case LibFunc_strtoul:
300  case LibFunc_strtoll:
301  case LibFunc_strtold:
302  case LibFunc_strtoull:
303  Changed |= setDoesNotThrow(F);
304  Changed |= setWillReturn(F);
305  Changed |= setDoesNotCapture(F, 1);
306  Changed |= setOnlyReadsMemory(F, 0);
307  return Changed;
308  case LibFunc_strcat:
309  case LibFunc_strncat:
310  Changed |= setOnlyAccessesArgMemory(F);
311  Changed |= setDoesNotThrow(F);
312  Changed |= setWillReturn(F);
313  Changed |= setReturnedArg(F, 0);
314  Changed |= setDoesNotCapture(F, 1);
315  Changed |= setOnlyReadsMemory(F, 1);
316  Changed |= setDoesNotAlias(F, 0);
317  Changed |= setDoesNotAlias(F, 1);
318  return Changed;
319  case LibFunc_strcpy:
320  case LibFunc_strncpy:
321  Changed |= setReturnedArg(F, 0);
323  case LibFunc_stpcpy:
324  case LibFunc_stpncpy:
325  Changed |= setOnlyAccessesArgMemory(F);
326  Changed |= setDoesNotThrow(F);
327  Changed |= setWillReturn(F);
328  Changed |= setDoesNotCapture(F, 1);
329  Changed |= setOnlyWritesMemory(F, 0);
330  Changed |= setOnlyReadsMemory(F, 1);
331  Changed |= setDoesNotAlias(F, 0);
332  Changed |= setDoesNotAlias(F, 1);
333  return Changed;
334  case LibFunc_strxfrm:
335  Changed |= setDoesNotThrow(F);
336  Changed |= setWillReturn(F);
337  Changed |= setDoesNotCapture(F, 0);
338  Changed |= setDoesNotCapture(F, 1);
339  Changed |= setOnlyReadsMemory(F, 1);
340  return Changed;
341  case LibFunc_strcmp: // 0,1
342  case LibFunc_strspn: // 0,1
343  case LibFunc_strncmp: // 0,1
344  case LibFunc_strcspn: // 0,1
345  Changed |= setDoesNotThrow(F);
346  Changed |= setOnlyAccessesArgMemory(F);
347  Changed |= setWillReturn(F);
348  Changed |= setOnlyReadsMemory(F);
349  Changed |= setDoesNotCapture(F, 0);
350  Changed |= setDoesNotCapture(F, 1);
351  return Changed;
352  case LibFunc_strcoll:
353  case LibFunc_strcasecmp: // 0,1
354  case LibFunc_strncasecmp: //
355  // Those functions may depend on the locale, which may be accessed through
356  // global memory.
357  Changed |= setOnlyReadsMemory(F);
358  Changed |= setDoesNotThrow(F);
359  Changed |= setWillReturn(F);
360  Changed |= setDoesNotCapture(F, 0);
361  Changed |= setDoesNotCapture(F, 1);
362  return Changed;
363  case LibFunc_strstr:
364  case LibFunc_strpbrk:
365  Changed |= setOnlyAccessesArgMemory(F);
366  Changed |= setOnlyReadsMemory(F);
367  Changed |= setDoesNotThrow(F);
368  Changed |= setWillReturn(F);
369  Changed |= setDoesNotCapture(F, 1);
370  return Changed;
371  case LibFunc_strtok:
372  case LibFunc_strtok_r:
373  Changed |= setDoesNotThrow(F);
374  Changed |= setWillReturn(F);
375  Changed |= setDoesNotCapture(F, 1);
376  Changed |= setOnlyReadsMemory(F, 1);
377  return Changed;
378  case LibFunc_scanf:
379  Changed |= setRetAndArgsNoUndef(F);
380  Changed |= setDoesNotThrow(F);
381  Changed |= setDoesNotCapture(F, 0);
382  Changed |= setOnlyReadsMemory(F, 0);
383  return Changed;
384  case LibFunc_setbuf:
385  case LibFunc_setvbuf:
386  Changed |= setRetAndArgsNoUndef(F);
387  Changed |= setDoesNotThrow(F);
388  Changed |= setDoesNotCapture(F, 0);
389  return Changed;
390  case LibFunc_strndup:
391  Changed |= setArgNoUndef(F, 1);
393  case LibFunc_strdup:
394  Changed |= setAllocFamily(F, "malloc");
396  Changed |= setDoesNotThrow(F);
397  Changed |= setRetDoesNotAlias(F);
398  Changed |= setWillReturn(F);
399  Changed |= setDoesNotCapture(F, 0);
400  Changed |= setOnlyReadsMemory(F, 0);
401  return Changed;
402  case LibFunc_stat:
403  case LibFunc_statvfs:
404  Changed |= setRetAndArgsNoUndef(F);
405  Changed |= setDoesNotThrow(F);
406  Changed |= setDoesNotCapture(F, 0);
407  Changed |= setDoesNotCapture(F, 1);
408  Changed |= setOnlyReadsMemory(F, 0);
409  return Changed;
410  case LibFunc_sscanf:
411  Changed |= setRetAndArgsNoUndef(F);
412  Changed |= setDoesNotThrow(F);
413  Changed |= setDoesNotCapture(F, 0);
414  Changed |= setDoesNotCapture(F, 1);
415  Changed |= setOnlyReadsMemory(F, 0);
416  Changed |= setOnlyReadsMemory(F, 1);
417  return Changed;
418  case LibFunc_sprintf:
419  Changed |= setRetAndArgsNoUndef(F);
420  Changed |= setDoesNotThrow(F);
421  Changed |= setDoesNotCapture(F, 0);
422  Changed |= setDoesNotAlias(F, 0);
423  Changed |= setOnlyWritesMemory(F, 0);
424  Changed |= setDoesNotCapture(F, 1);
425  Changed |= setOnlyReadsMemory(F, 1);
426  return Changed;
427  case LibFunc_snprintf:
428  Changed |= setRetAndArgsNoUndef(F);
429  Changed |= setDoesNotThrow(F);
430  Changed |= setDoesNotCapture(F, 0);
431  Changed |= setDoesNotAlias(F, 0);
432  Changed |= setOnlyWritesMemory(F, 0);
433  Changed |= setDoesNotCapture(F, 2);
434  Changed |= setOnlyReadsMemory(F, 2);
435  return Changed;
436  case LibFunc_setitimer:
437  Changed |= setRetAndArgsNoUndef(F);
438  Changed |= setDoesNotThrow(F);
439  Changed |= setWillReturn(F);
440  Changed |= setDoesNotCapture(F, 1);
441  Changed |= setDoesNotCapture(F, 2);
442  Changed |= setOnlyReadsMemory(F, 1);
443  return Changed;
444  case LibFunc_system:
445  // May throw; "system" is a valid pthread cancellation point.
446  Changed |= setRetAndArgsNoUndef(F);
447  Changed |= setDoesNotCapture(F, 0);
448  Changed |= setOnlyReadsMemory(F, 0);
449  return Changed;
450  case LibFunc_aligned_alloc:
451  Changed |= setAlignedAllocParam(F, 0);
452  Changed |= setAllocSize(F, 1, None);
455  case LibFunc_valloc:
456  case LibFunc_malloc:
457  case LibFunc_vec_malloc:
458  Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_malloc ? "vec_malloc"
459  : "malloc");
461  Changed |= setAllocSize(F, 0, None);
463  Changed |= setRetAndArgsNoUndef(F);
464  Changed |= setDoesNotThrow(F);
465  Changed |= setRetDoesNotAlias(F);
466  Changed |= setWillReturn(F);
467  return Changed;
468  case LibFunc_memcmp:
469  Changed |= setOnlyAccessesArgMemory(F);
470  Changed |= setOnlyReadsMemory(F);
471  Changed |= setDoesNotThrow(F);
472  Changed |= setWillReturn(F);
473  Changed |= setDoesNotCapture(F, 0);
474  Changed |= setDoesNotCapture(F, 1);
475  return Changed;
476  case LibFunc_memchr:
477  case LibFunc_memrchr:
478  Changed |= setDoesNotThrow(F);
479  Changed |= setOnlyAccessesArgMemory(F);
480  Changed |= setOnlyReadsMemory(F);
481  Changed |= setWillReturn(F);
482  return Changed;
483  case LibFunc_modf:
484  case LibFunc_modff:
485  case LibFunc_modfl:
486  Changed |= setDoesNotThrow(F);
487  Changed |= setWillReturn(F);
488  Changed |= setDoesNotCapture(F, 1);
489  return Changed;
490  case LibFunc_memcpy:
491  Changed |= setDoesNotThrow(F);
492  Changed |= setOnlyAccessesArgMemory(F);
493  Changed |= setWillReturn(F);
494  Changed |= setDoesNotAlias(F, 0);
495  Changed |= setReturnedArg(F, 0);
496  Changed |= setOnlyWritesMemory(F, 0);
497  Changed |= setDoesNotAlias(F, 1);
498  Changed |= setDoesNotCapture(F, 1);
499  Changed |= setOnlyReadsMemory(F, 1);
500  return Changed;
501  case LibFunc_memmove:
502  Changed |= setDoesNotThrow(F);
503  Changed |= setOnlyAccessesArgMemory(F);
504  Changed |= setWillReturn(F);
505  Changed |= setReturnedArg(F, 0);
506  Changed |= setOnlyWritesMemory(F, 0);
507  Changed |= setDoesNotCapture(F, 1);
508  Changed |= setOnlyReadsMemory(F, 1);
509  return Changed;
510  case LibFunc_mempcpy:
511  case LibFunc_memccpy:
512  Changed |= setWillReturn(F);
514  case LibFunc_memcpy_chk:
515  Changed |= setDoesNotThrow(F);
516  Changed |= setOnlyAccessesArgMemory(F);
517  Changed |= setDoesNotAlias(F, 0);
518  Changed |= setOnlyWritesMemory(F, 0);
519  Changed |= setDoesNotAlias(F, 1);
520  Changed |= setDoesNotCapture(F, 1);
521  Changed |= setOnlyReadsMemory(F, 1);
522  return Changed;
523  case LibFunc_memalign:
524  Changed |= setAllocFamily(F, "malloc");
527  Changed |= setAllocSize(F, 1, None);
528  Changed |= setAlignedAllocParam(F, 0);
530  Changed |= setRetNoUndef(F);
531  Changed |= setDoesNotThrow(F);
532  Changed |= setRetDoesNotAlias(F);
533  Changed |= setWillReturn(F);
534  return Changed;
535  case LibFunc_mkdir:
536  Changed |= setRetAndArgsNoUndef(F);
537  Changed |= setDoesNotThrow(F);
538  Changed |= setDoesNotCapture(F, 0);
539  Changed |= setOnlyReadsMemory(F, 0);
540  return Changed;
541  case LibFunc_mktime:
542  Changed |= setRetAndArgsNoUndef(F);
543  Changed |= setDoesNotThrow(F);
544  Changed |= setWillReturn(F);
545  Changed |= setDoesNotCapture(F, 0);
546  return Changed;
547  case LibFunc_realloc:
548  case LibFunc_reallocf:
549  case LibFunc_vec_realloc:
550  Changed |= setAllocFamily(
551  F, TheLibFunc == LibFunc_vec_realloc ? "vec_malloc" : "malloc");
552  Changed |= setAllocKind(F, AllocFnKind::Realloc);
553  Changed |= setAllocatedPointerParam(F, 0);
554  Changed |= setAllocSize(F, 1, None);
556  Changed |= setRetNoUndef(F);
557  Changed |= setDoesNotThrow(F);
558  Changed |= setRetDoesNotAlias(F);
559  Changed |= setWillReturn(F);
560  Changed |= setDoesNotCapture(F, 0);
561  Changed |= setArgNoUndef(F, 1);
562  return Changed;
563  case LibFunc_read:
564  // May throw; "read" is a valid pthread cancellation point.
565  Changed |= setRetAndArgsNoUndef(F);
566  Changed |= setDoesNotCapture(F, 1);
567  return Changed;
568  case LibFunc_rewind:
569  Changed |= setRetAndArgsNoUndef(F);
570  Changed |= setDoesNotThrow(F);
571  Changed |= setDoesNotCapture(F, 0);
572  return Changed;
573  case LibFunc_rmdir:
574  case LibFunc_remove:
575  case LibFunc_realpath:
576  Changed |= setRetAndArgsNoUndef(F);
577  Changed |= setDoesNotThrow(F);
578  Changed |= setDoesNotCapture(F, 0);
579  Changed |= setOnlyReadsMemory(F, 0);
580  return Changed;
581  case LibFunc_rename:
582  Changed |= setRetAndArgsNoUndef(F);
583  Changed |= setDoesNotThrow(F);
584  Changed |= setDoesNotCapture(F, 0);
585  Changed |= setDoesNotCapture(F, 1);
586  Changed |= setOnlyReadsMemory(F, 0);
587  Changed |= setOnlyReadsMemory(F, 1);
588  return Changed;
589  case LibFunc_readlink:
590  Changed |= setRetAndArgsNoUndef(F);
591  Changed |= setDoesNotThrow(F);
592  Changed |= setDoesNotCapture(F, 0);
593  Changed |= setDoesNotCapture(F, 1);
594  Changed |= setOnlyReadsMemory(F, 0);
595  return Changed;
596  case LibFunc_write:
597  // May throw; "write" is a valid pthread cancellation point.
598  Changed |= setRetAndArgsNoUndef(F);
599  Changed |= setDoesNotCapture(F, 1);
600  Changed |= setOnlyReadsMemory(F, 1);
601  return Changed;
602  case LibFunc_bcopy:
603  Changed |= setDoesNotThrow(F);
604  Changed |= setOnlyAccessesArgMemory(F);
605  Changed |= setWillReturn(F);
606  Changed |= setDoesNotCapture(F, 0);
607  Changed |= setOnlyReadsMemory(F, 0);
608  Changed |= setOnlyWritesMemory(F, 1);
609  Changed |= setDoesNotCapture(F, 1);
610  return Changed;
611  case LibFunc_bcmp:
612  Changed |= setDoesNotThrow(F);
613  Changed |= setOnlyAccessesArgMemory(F);
614  Changed |= setOnlyReadsMemory(F);
615  Changed |= setWillReturn(F);
616  Changed |= setDoesNotCapture(F, 0);
617  Changed |= setDoesNotCapture(F, 1);
618  return Changed;
619  case LibFunc_bzero:
620  Changed |= setDoesNotThrow(F);
621  Changed |= setOnlyAccessesArgMemory(F);
622  Changed |= setWillReturn(F);
623  Changed |= setDoesNotCapture(F, 0);
624  Changed |= setOnlyWritesMemory(F, 0);
625  return Changed;
626  case LibFunc_calloc:
627  case LibFunc_vec_calloc:
628  Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_calloc ? "vec_malloc"
629  : "malloc");
631  Changed |= setAllocSize(F, 0, 1);
633  Changed |= setRetAndArgsNoUndef(F);
634  Changed |= setDoesNotThrow(F);
635  Changed |= setRetDoesNotAlias(F);
636  Changed |= setWillReturn(F);
637  return Changed;
638  case LibFunc_chmod:
639  case LibFunc_chown:
640  Changed |= setRetAndArgsNoUndef(F);
641  Changed |= setDoesNotThrow(F);
642  Changed |= setDoesNotCapture(F, 0);
643  Changed |= setOnlyReadsMemory(F, 0);
644  return Changed;
645  case LibFunc_ctermid:
646  case LibFunc_clearerr:
647  case LibFunc_closedir:
648  Changed |= setRetAndArgsNoUndef(F);
649  Changed |= setDoesNotThrow(F);
650  Changed |= setDoesNotCapture(F, 0);
651  return Changed;
652  case LibFunc_atoi:
653  case LibFunc_atol:
654  case LibFunc_atof:
655  case LibFunc_atoll:
656  Changed |= setDoesNotThrow(F);
657  Changed |= setOnlyReadsMemory(F);
658  Changed |= setWillReturn(F);
659  Changed |= setDoesNotCapture(F, 0);
660  return Changed;
661  case LibFunc_access:
662  Changed |= setRetAndArgsNoUndef(F);
663  Changed |= setDoesNotThrow(F);
664  Changed |= setDoesNotCapture(F, 0);
665  Changed |= setOnlyReadsMemory(F, 0);
666  return Changed;
667  case LibFunc_fopen:
668  Changed |= setRetAndArgsNoUndef(F);
669  Changed |= setDoesNotThrow(F);
670  Changed |= setRetDoesNotAlias(F);
671  Changed |= setDoesNotCapture(F, 0);
672  Changed |= setDoesNotCapture(F, 1);
673  Changed |= setOnlyReadsMemory(F, 0);
674  Changed |= setOnlyReadsMemory(F, 1);
675  return Changed;
676  case LibFunc_fdopen:
677  Changed |= setRetAndArgsNoUndef(F);
678  Changed |= setDoesNotThrow(F);
679  Changed |= setRetDoesNotAlias(F);
680  Changed |= setDoesNotCapture(F, 1);
681  Changed |= setOnlyReadsMemory(F, 1);
682  return Changed;
683  case LibFunc_feof:
684  Changed |= setRetAndArgsNoUndef(F);
685  Changed |= setDoesNotThrow(F);
686  Changed |= setDoesNotCapture(F, 0);
687  return Changed;
688  case LibFunc_free:
689  case LibFunc_vec_free:
690  Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_free ? "vec_malloc"
691  : "malloc");
692  Changed |= setAllocKind(F, AllocFnKind::Free);
693  Changed |= setAllocatedPointerParam(F, 0);
695  Changed |= setArgsNoUndef(F);
696  Changed |= setDoesNotThrow(F);
697  Changed |= setWillReturn(F);
698  Changed |= setDoesNotCapture(F, 0);
699  return Changed;
700  case LibFunc_fseek:
701  case LibFunc_ftell:
702  case LibFunc_fgetc:
703  case LibFunc_fgetc_unlocked:
704  case LibFunc_fseeko:
705  case LibFunc_ftello:
706  case LibFunc_fileno:
707  case LibFunc_fflush:
708  case LibFunc_fclose:
709  case LibFunc_fsetpos:
710  case LibFunc_flockfile:
711  case LibFunc_funlockfile:
712  case LibFunc_ftrylockfile:
713  Changed |= setRetAndArgsNoUndef(F);
714  Changed |= setDoesNotThrow(F);
715  Changed |= setDoesNotCapture(F, 0);
716  return Changed;
717  case LibFunc_ferror:
718  Changed |= setRetAndArgsNoUndef(F);
719  Changed |= setDoesNotThrow(F);
720  Changed |= setDoesNotCapture(F, 0);
721  Changed |= setOnlyReadsMemory(F);
722  return Changed;
723  case LibFunc_fputc:
724  case LibFunc_fputc_unlocked:
725  case LibFunc_fstat:
726  Changed |= setRetAndArgsNoUndef(F);
727  Changed |= setDoesNotThrow(F);
728  Changed |= setDoesNotCapture(F, 1);
729  return Changed;
730  case LibFunc_frexp:
731  case LibFunc_frexpf:
732  case LibFunc_frexpl:
733  Changed |= setDoesNotThrow(F);
734  Changed |= setWillReturn(F);
735  Changed |= setDoesNotCapture(F, 1);
736  return Changed;
737  case LibFunc_fstatvfs:
738  Changed |= setRetAndArgsNoUndef(F);
739  Changed |= setDoesNotThrow(F);
740  Changed |= setDoesNotCapture(F, 1);
741  return Changed;
742  case LibFunc_fgets:
743  case LibFunc_fgets_unlocked:
744  Changed |= setRetAndArgsNoUndef(F);
745  Changed |= setDoesNotThrow(F);
746  Changed |= setDoesNotCapture(F, 2);
747  return Changed;
748  case LibFunc_fread:
749  case LibFunc_fread_unlocked:
750  Changed |= setRetAndArgsNoUndef(F);
751  Changed |= setDoesNotThrow(F);
752  Changed |= setDoesNotCapture(F, 0);
753  Changed |= setDoesNotCapture(F, 3);
754  return Changed;
755  case LibFunc_fwrite:
756  case LibFunc_fwrite_unlocked:
757  Changed |= setRetAndArgsNoUndef(F);
758  Changed |= setDoesNotThrow(F);
759  Changed |= setDoesNotCapture(F, 0);
760  Changed |= setDoesNotCapture(F, 3);
761  // FIXME: readonly #1?
762  return Changed;
763  case LibFunc_fputs:
764  case LibFunc_fputs_unlocked:
765  Changed |= setRetAndArgsNoUndef(F);
766  Changed |= setDoesNotThrow(F);
767  Changed |= setDoesNotCapture(F, 0);
768  Changed |= setDoesNotCapture(F, 1);
769  Changed |= setOnlyReadsMemory(F, 0);
770  return Changed;
771  case LibFunc_fscanf:
772  case LibFunc_fprintf:
773  Changed |= setRetAndArgsNoUndef(F);
774  Changed |= setDoesNotThrow(F);
775  Changed |= setDoesNotCapture(F, 0);
776  Changed |= setDoesNotCapture(F, 1);
777  Changed |= setOnlyReadsMemory(F, 1);
778  return Changed;
779  case LibFunc_fgetpos:
780  Changed |= setRetAndArgsNoUndef(F);
781  Changed |= setDoesNotThrow(F);
782  Changed |= setDoesNotCapture(F, 0);
783  Changed |= setDoesNotCapture(F, 1);
784  return Changed;
785  case LibFunc_getc:
786  Changed |= setRetAndArgsNoUndef(F);
787  Changed |= setDoesNotThrow(F);
788  Changed |= setDoesNotCapture(F, 0);
789  return Changed;
790  case LibFunc_getlogin_r:
791  Changed |= setRetAndArgsNoUndef(F);
792  Changed |= setDoesNotThrow(F);
793  Changed |= setDoesNotCapture(F, 0);
794  return Changed;
795  case LibFunc_getc_unlocked:
796  Changed |= setRetAndArgsNoUndef(F);
797  Changed |= setDoesNotThrow(F);
798  Changed |= setDoesNotCapture(F, 0);
799  return Changed;
800  case LibFunc_getenv:
801  Changed |= setRetAndArgsNoUndef(F);
802  Changed |= setDoesNotThrow(F);
803  Changed |= setOnlyReadsMemory(F);
804  Changed |= setDoesNotCapture(F, 0);
805  return Changed;
806  case LibFunc_gets:
807  case LibFunc_getchar:
808  case LibFunc_getchar_unlocked:
809  Changed |= setRetAndArgsNoUndef(F);
810  Changed |= setDoesNotThrow(F);
811  return Changed;
812  case LibFunc_getitimer:
813  Changed |= setRetAndArgsNoUndef(F);
814  Changed |= setDoesNotThrow(F);
815  Changed |= setDoesNotCapture(F, 1);
816  return Changed;
817  case LibFunc_getpwnam:
818  Changed |= setRetAndArgsNoUndef(F);
819  Changed |= setDoesNotThrow(F);
820  Changed |= setDoesNotCapture(F, 0);
821  Changed |= setOnlyReadsMemory(F, 0);
822  return Changed;
823  case LibFunc_ungetc:
824  Changed |= setRetAndArgsNoUndef(F);
825  Changed |= setDoesNotThrow(F);
826  Changed |= setDoesNotCapture(F, 1);
827  return Changed;
828  case LibFunc_uname:
829  Changed |= setRetAndArgsNoUndef(F);
830  Changed |= setDoesNotThrow(F);
831  Changed |= setDoesNotCapture(F, 0);
832  return Changed;
833  case LibFunc_unlink:
834  Changed |= setRetAndArgsNoUndef(F);
835  Changed |= setDoesNotThrow(F);
836  Changed |= setDoesNotCapture(F, 0);
837  Changed |= setOnlyReadsMemory(F, 0);
838  return Changed;
839  case LibFunc_unsetenv:
840  Changed |= setRetAndArgsNoUndef(F);
841  Changed |= setDoesNotThrow(F);
842  Changed |= setDoesNotCapture(F, 0);
843  Changed |= setOnlyReadsMemory(F, 0);
844  return Changed;
845  case LibFunc_utime:
846  case LibFunc_utimes:
847  Changed |= setRetAndArgsNoUndef(F);
848  Changed |= setDoesNotThrow(F);
849  Changed |= setDoesNotCapture(F, 0);
850  Changed |= setDoesNotCapture(F, 1);
851  Changed |= setOnlyReadsMemory(F, 0);
852  Changed |= setOnlyReadsMemory(F, 1);
853  return Changed;
854  case LibFunc_putc:
855  case LibFunc_putc_unlocked:
856  Changed |= setRetAndArgsNoUndef(F);
857  Changed |= setDoesNotThrow(F);
858  Changed |= setDoesNotCapture(F, 1);
859  return Changed;
860  case LibFunc_puts:
861  case LibFunc_printf:
862  case LibFunc_perror:
863  Changed |= setRetAndArgsNoUndef(F);
864  Changed |= setDoesNotThrow(F);
865  Changed |= setDoesNotCapture(F, 0);
866  Changed |= setOnlyReadsMemory(F, 0);
867  return Changed;
868  case LibFunc_pread:
869  // May throw; "pread" is a valid pthread cancellation point.
870  Changed |= setRetAndArgsNoUndef(F);
871  Changed |= setDoesNotCapture(F, 1);
872  return Changed;
873  case LibFunc_pwrite:
874  // May throw; "pwrite" is a valid pthread cancellation point.
875  Changed |= setRetAndArgsNoUndef(F);
876  Changed |= setDoesNotCapture(F, 1);
877  Changed |= setOnlyReadsMemory(F, 1);
878  return Changed;
879  case LibFunc_putchar:
880  case LibFunc_putchar_unlocked:
881  Changed |= setRetAndArgsNoUndef(F);
882  Changed |= setDoesNotThrow(F);
883  return Changed;
884  case LibFunc_popen:
885  Changed |= setRetAndArgsNoUndef(F);
886  Changed |= setDoesNotThrow(F);
887  Changed |= setRetDoesNotAlias(F);
888  Changed |= setDoesNotCapture(F, 0);
889  Changed |= setDoesNotCapture(F, 1);
890  Changed |= setOnlyReadsMemory(F, 0);
891  Changed |= setOnlyReadsMemory(F, 1);
892  return Changed;
893  case LibFunc_pclose:
894  Changed |= setRetAndArgsNoUndef(F);
895  Changed |= setDoesNotThrow(F);
896  Changed |= setDoesNotCapture(F, 0);
897  return Changed;
898  case LibFunc_vscanf:
899  Changed |= setRetAndArgsNoUndef(F);
900  Changed |= setDoesNotThrow(F);
901  Changed |= setDoesNotCapture(F, 0);
902  Changed |= setOnlyReadsMemory(F, 0);
903  return Changed;
904  case LibFunc_vsscanf:
905  Changed |= setRetAndArgsNoUndef(F);
906  Changed |= setDoesNotThrow(F);
907  Changed |= setDoesNotCapture(F, 0);
908  Changed |= setDoesNotCapture(F, 1);
909  Changed |= setOnlyReadsMemory(F, 0);
910  Changed |= setOnlyReadsMemory(F, 1);
911  return Changed;
912  case LibFunc_vfscanf:
913  Changed |= setRetAndArgsNoUndef(F);
914  Changed |= setDoesNotThrow(F);
915  Changed |= setDoesNotCapture(F, 0);
916  Changed |= setDoesNotCapture(F, 1);
917  Changed |= setOnlyReadsMemory(F, 1);
918  return Changed;
919  case LibFunc_vprintf:
920  Changed |= setRetAndArgsNoUndef(F);
921  Changed |= setDoesNotThrow(F);
922  Changed |= setDoesNotCapture(F, 0);
923  Changed |= setOnlyReadsMemory(F, 0);
924  return Changed;
925  case LibFunc_vfprintf:
926  case LibFunc_vsprintf:
927  Changed |= setRetAndArgsNoUndef(F);
928  Changed |= setDoesNotThrow(F);
929  Changed |= setDoesNotCapture(F, 0);
930  Changed |= setDoesNotCapture(F, 1);
931  Changed |= setOnlyReadsMemory(F, 1);
932  return Changed;
933  case LibFunc_vsnprintf:
934  Changed |= setRetAndArgsNoUndef(F);
935  Changed |= setDoesNotThrow(F);
936  Changed |= setDoesNotCapture(F, 0);
937  Changed |= setDoesNotCapture(F, 2);
938  Changed |= setOnlyReadsMemory(F, 2);
939  return Changed;
940  case LibFunc_open:
941  // May throw; "open" is a valid pthread cancellation point.
942  Changed |= setRetAndArgsNoUndef(F);
943  Changed |= setDoesNotCapture(F, 0);
944  Changed |= setOnlyReadsMemory(F, 0);
945  return Changed;
946  case LibFunc_opendir:
947  Changed |= setRetAndArgsNoUndef(F);
948  Changed |= setDoesNotThrow(F);
949  Changed |= setRetDoesNotAlias(F);
950  Changed |= setDoesNotCapture(F, 0);
951  Changed |= setOnlyReadsMemory(F, 0);
952  return Changed;
953  case LibFunc_tmpfile:
954  Changed |= setRetAndArgsNoUndef(F);
955  Changed |= setDoesNotThrow(F);
956  Changed |= setRetDoesNotAlias(F);
957  return Changed;
958  case LibFunc_times:
959  Changed |= setRetAndArgsNoUndef(F);
960  Changed |= setDoesNotThrow(F);
961  Changed |= setDoesNotCapture(F, 0);
962  return Changed;
963  case LibFunc_htonl:
964  case LibFunc_htons:
965  case LibFunc_ntohl:
966  case LibFunc_ntohs:
967  Changed |= setDoesNotThrow(F);
968  Changed |= setDoesNotAccessMemory(F);
969  return Changed;
970  case LibFunc_lstat:
971  Changed |= setRetAndArgsNoUndef(F);
972  Changed |= setDoesNotThrow(F);
973  Changed |= setDoesNotCapture(F, 0);
974  Changed |= setDoesNotCapture(F, 1);
975  Changed |= setOnlyReadsMemory(F, 0);
976  return Changed;
977  case LibFunc_lchown:
978  Changed |= setRetAndArgsNoUndef(F);
979  Changed |= setDoesNotThrow(F);
980  Changed |= setDoesNotCapture(F, 0);
981  Changed |= setOnlyReadsMemory(F, 0);
982  return Changed;
983  case LibFunc_qsort:
984  // May throw; places call through function pointer.
985  // Cannot give undef pointer/size
986  Changed |= setRetAndArgsNoUndef(F);
987  Changed |= setDoesNotCapture(F, 3);
988  return Changed;
989  case LibFunc_dunder_strndup:
990  Changed |= setArgNoUndef(F, 1);
992  case LibFunc_dunder_strdup:
993  Changed |= setDoesNotThrow(F);
994  Changed |= setRetDoesNotAlias(F);
995  Changed |= setWillReturn(F);
996  Changed |= setDoesNotCapture(F, 0);
997  Changed |= setOnlyReadsMemory(F, 0);
998  return Changed;
999  case LibFunc_dunder_strtok_r:
1000  Changed |= setDoesNotThrow(F);
1001  Changed |= setDoesNotCapture(F, 1);
1002  Changed |= setOnlyReadsMemory(F, 1);
1003  return Changed;
1004  case LibFunc_under_IO_getc:
1005  Changed |= setRetAndArgsNoUndef(F);
1006  Changed |= setDoesNotThrow(F);
1007  Changed |= setDoesNotCapture(F, 0);
1008  return Changed;
1009  case LibFunc_under_IO_putc:
1010  Changed |= setRetAndArgsNoUndef(F);
1011  Changed |= setDoesNotThrow(F);
1012  Changed |= setDoesNotCapture(F, 1);
1013  return Changed;
1014  case LibFunc_dunder_isoc99_scanf:
1015  Changed |= setRetAndArgsNoUndef(F);
1016  Changed |= setDoesNotThrow(F);
1017  Changed |= setDoesNotCapture(F, 0);
1018  Changed |= setOnlyReadsMemory(F, 0);
1019  return Changed;
1020  case LibFunc_stat64:
1021  case LibFunc_lstat64:
1022  case LibFunc_statvfs64:
1023  Changed |= setRetAndArgsNoUndef(F);
1024  Changed |= setDoesNotThrow(F);
1025  Changed |= setDoesNotCapture(F, 0);
1026  Changed |= setDoesNotCapture(F, 1);
1027  Changed |= setOnlyReadsMemory(F, 0);
1028  return Changed;
1029  case LibFunc_dunder_isoc99_sscanf:
1030  Changed |= setRetAndArgsNoUndef(F);
1031  Changed |= setDoesNotThrow(F);
1032  Changed |= setDoesNotCapture(F, 0);
1033  Changed |= setDoesNotCapture(F, 1);
1034  Changed |= setOnlyReadsMemory(F, 0);
1035  Changed |= setOnlyReadsMemory(F, 1);
1036  return Changed;
1037  case LibFunc_fopen64:
1038  Changed |= setRetAndArgsNoUndef(F);
1039  Changed |= setDoesNotThrow(F);
1040  Changed |= setRetDoesNotAlias(F);
1041  Changed |= setDoesNotCapture(F, 0);
1042  Changed |= setDoesNotCapture(F, 1);
1043  Changed |= setOnlyReadsMemory(F, 0);
1044  Changed |= setOnlyReadsMemory(F, 1);
1045  return Changed;
1046  case LibFunc_fseeko64:
1047  case LibFunc_ftello64:
1048  Changed |= setRetAndArgsNoUndef(F);
1049  Changed |= setDoesNotThrow(F);
1050  Changed |= setDoesNotCapture(F, 0);
1051  return Changed;
1052  case LibFunc_tmpfile64:
1053  Changed |= setRetAndArgsNoUndef(F);
1054  Changed |= setDoesNotThrow(F);
1055  Changed |= setRetDoesNotAlias(F);
1056  return Changed;
1057  case LibFunc_fstat64:
1058  case LibFunc_fstatvfs64:
1059  Changed |= setRetAndArgsNoUndef(F);
1060  Changed |= setDoesNotThrow(F);
1061  Changed |= setDoesNotCapture(F, 1);
1062  return Changed;
1063  case LibFunc_open64:
1064  // May throw; "open" is a valid pthread cancellation point.
1065  Changed |= setRetAndArgsNoUndef(F);
1066  Changed |= setDoesNotCapture(F, 0);
1067  Changed |= setOnlyReadsMemory(F, 0);
1068  return Changed;
1069  case LibFunc_gettimeofday:
1070  // Currently some platforms have the restrict keyword on the arguments to
1071  // gettimeofday. To be conservative, do not add noalias to gettimeofday's
1072  // arguments.
1073  Changed |= setRetAndArgsNoUndef(F);
1074  Changed |= setDoesNotThrow(F);
1075  Changed |= setDoesNotCapture(F, 0);
1076  Changed |= setDoesNotCapture(F, 1);
1077  return Changed;
1078  case LibFunc_memset_pattern4:
1079  case LibFunc_memset_pattern8:
1080  case LibFunc_memset_pattern16:
1081  Changed |= setDoesNotCapture(F, 0);
1082  Changed |= setDoesNotCapture(F, 1);
1083  Changed |= setOnlyReadsMemory(F, 1);
1085  case LibFunc_memset:
1086  Changed |= setWillReturn(F);
1088  case LibFunc_memset_chk:
1089  Changed |= setOnlyAccessesArgMemory(F);
1090  Changed |= setOnlyWritesMemory(F, 0);
1091  Changed |= setDoesNotThrow(F);
1092  return Changed;
1093  // int __nvvm_reflect(const char *)
1094  case LibFunc_nvvm_reflect:
1095  Changed |= setRetAndArgsNoUndef(F);
1096  Changed |= setDoesNotAccessMemory(F);
1097  Changed |= setDoesNotThrow(F);
1098  return Changed;
1099  case LibFunc_ldexp:
1100  case LibFunc_ldexpf:
1101  case LibFunc_ldexpl:
1102  Changed |= setWillReturn(F);
1103  return Changed;
1104  case LibFunc_abs:
1105  case LibFunc_acos:
1106  case LibFunc_acosf:
1107  case LibFunc_acosh:
1108  case LibFunc_acoshf:
1109  case LibFunc_acoshl:
1110  case LibFunc_acosl:
1111  case LibFunc_asin:
1112  case LibFunc_asinf:
1113  case LibFunc_asinh:
1114  case LibFunc_asinhf:
1115  case LibFunc_asinhl:
1116  case LibFunc_asinl:
1117  case LibFunc_atan:
1118  case LibFunc_atan2:
1119  case LibFunc_atan2f:
1120  case LibFunc_atan2l:
1121  case LibFunc_atanf:
1122  case LibFunc_atanh:
1123  case LibFunc_atanhf:
1124  case LibFunc_atanhl:
1125  case LibFunc_atanl:
1126  case LibFunc_cbrt:
1127  case LibFunc_cbrtf:
1128  case LibFunc_cbrtl:
1129  case LibFunc_ceil:
1130  case LibFunc_ceilf:
1131  case LibFunc_ceill:
1132  case LibFunc_copysign:
1133  case LibFunc_copysignf:
1134  case LibFunc_copysignl:
1135  case LibFunc_cos:
1136  case LibFunc_cosh:
1137  case LibFunc_coshf:
1138  case LibFunc_coshl:
1139  case LibFunc_cosf:
1140  case LibFunc_cosl:
1141  case LibFunc_cospi:
1142  case LibFunc_cospif:
1143  case LibFunc_exp:
1144  case LibFunc_expf:
1145  case LibFunc_expl:
1146  case LibFunc_exp2:
1147  case LibFunc_exp2f:
1148  case LibFunc_exp2l:
1149  case LibFunc_expm1:
1150  case LibFunc_expm1f:
1151  case LibFunc_expm1l:
1152  case LibFunc_fabs:
1153  case LibFunc_fabsf:
1154  case LibFunc_fabsl:
1155  case LibFunc_ffs:
1156  case LibFunc_ffsl:
1157  case LibFunc_ffsll:
1158  case LibFunc_floor:
1159  case LibFunc_floorf:
1160  case LibFunc_floorl:
1161  case LibFunc_fls:
1162  case LibFunc_flsl:
1163  case LibFunc_flsll:
1164  case LibFunc_fmax:
1165  case LibFunc_fmaxf:
1166  case LibFunc_fmaxl:
1167  case LibFunc_fmin:
1168  case LibFunc_fminf:
1169  case LibFunc_fminl:
1170  case LibFunc_fmod:
1171  case LibFunc_fmodf:
1172  case LibFunc_fmodl:
1173  case LibFunc_isascii:
1174  case LibFunc_isdigit:
1175  case LibFunc_labs:
1176  case LibFunc_llabs:
1177  case LibFunc_log:
1178  case LibFunc_log10:
1179  case LibFunc_log10f:
1180  case LibFunc_log10l:
1181  case LibFunc_log1p:
1182  case LibFunc_log1pf:
1183  case LibFunc_log1pl:
1184  case LibFunc_log2:
1185  case LibFunc_log2f:
1186  case LibFunc_log2l:
1187  case LibFunc_logb:
1188  case LibFunc_logbf:
1189  case LibFunc_logbl:
1190  case LibFunc_logf:
1191  case LibFunc_logl:
1192  case LibFunc_nearbyint:
1193  case LibFunc_nearbyintf:
1194  case LibFunc_nearbyintl:
1195  case LibFunc_pow:
1196  case LibFunc_powf:
1197  case LibFunc_powl:
1198  case LibFunc_rint:
1199  case LibFunc_rintf:
1200  case LibFunc_rintl:
1201  case LibFunc_round:
1202  case LibFunc_roundf:
1203  case LibFunc_roundl:
1204  case LibFunc_sin:
1205  case LibFunc_sincospif_stret:
1206  case LibFunc_sinf:
1207  case LibFunc_sinh:
1208  case LibFunc_sinhf:
1209  case LibFunc_sinhl:
1210  case LibFunc_sinl:
1211  case LibFunc_sinpi:
1212  case LibFunc_sinpif:
1213  case LibFunc_sqrt:
1214  case LibFunc_sqrtf:
1215  case LibFunc_sqrtl:
1216  case LibFunc_tan:
1217  case LibFunc_tanf:
1218  case LibFunc_tanh:
1219  case LibFunc_tanhf:
1220  case LibFunc_tanhl:
1221  case LibFunc_tanl:
1222  case LibFunc_toascii:
1223  case LibFunc_trunc:
1224  case LibFunc_truncf:
1225  case LibFunc_truncl:
1226  Changed |= setDoesNotThrow(F);
1227  Changed |= setDoesNotFreeMemory(F);
1228  Changed |= setOnlyWritesMemory(F);
1229  Changed |= setWillReturn(F);
1230  return Changed;
1231  default:
1232  // FIXME: It'd be really nice to cover all the library functions we're
1233  // aware of here.
1234  return false;
1235  }
1236 }
1237 
1238 static void setArgExtAttr(Function &F, unsigned ArgNo,
1239  const TargetLibraryInfo &TLI, bool Signed = true) {
1241  if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr))
1242  F.addParamAttr(ArgNo, ExtAttr);
1243 }
1244 
1245 // Modeled after X86TargetLowering::markLibCallAttributes.
1247  if (!F->arg_size() || F->isVarArg())
1248  return;
1249 
1250  const CallingConv::ID CC = F->getCallingConv();
1251  if (CC != CallingConv::C && CC != CallingConv::X86_StdCall)
1252  return;
1253 
1254  const Module *M = F->getParent();
1255  unsigned N = M->getNumberRegisterParameters();
1256  if (!N)
1257  return;
1258 
1259  const DataLayout &DL = M->getDataLayout();
1260 
1261  for (Argument &A : F->args()) {
1262  Type *T = A.getType();
1263  if (!T->isIntOrPtrTy())
1264  continue;
1265 
1266  const TypeSize &TS = DL.getTypeAllocSize(T);
1267  if (TS > 8)
1268  continue;
1269 
1270  assert(TS <= 4 && "Need to account for parameters larger than word size");
1271  const unsigned NumRegs = TS > 4 ? 2 : 1;
1272  if (N < NumRegs)
1273  return;
1274 
1275  N -= NumRegs;
1276  F->addParamAttr(A.getArgNo(), Attribute::InReg);
1277  }
1278 }
1279 
1281  LibFunc TheLibFunc, FunctionType *T,
1283  assert(TLI.has(TheLibFunc) &&
1284  "Creating call to non-existing library function.");
1285  StringRef Name = TLI.getName(TheLibFunc);
1286  FunctionCallee C = M->getOrInsertFunction(Name, T, AttributeList);
1287 
1288  // Make sure any mandatory argument attributes are added.
1289 
1290  // Any outgoing i32 argument should be handled with setArgExtAttr() which
1291  // will add an extension attribute if the target ABI requires it. Adding
1292  // argument extensions is typically done by the front end but when an
1293  // optimizer is building a library call on its own it has to take care of
1294  // this. Each such generated function must be handled here with sign or
1295  // zero extensions as needed. F is retreived with cast<> because we demand
1296  // of the caller to have called isLibFuncEmittable() first.
1297  Function *F = cast<Function>(C.getCallee());
1298  assert(F->getFunctionType() == T && "Function type does not match.");
1299  switch (TheLibFunc) {
1300  case LibFunc_fputc:
1301  case LibFunc_putchar:
1302  setArgExtAttr(*F, 0, TLI);
1303  break;
1304  case LibFunc_ldexp:
1305  case LibFunc_ldexpf:
1306  case LibFunc_ldexpl:
1307  case LibFunc_memchr:
1308  case LibFunc_memrchr:
1309  case LibFunc_strchr:
1310  setArgExtAttr(*F, 1, TLI);
1311  break;
1312  case LibFunc_memccpy:
1313  setArgExtAttr(*F, 2, TLI);
1314  break;
1315 
1316  // These are functions that are known to not need any argument extension
1317  // on any target: A size_t argument (which may be an i32 on some targets)
1318  // should not trigger the assert below.
1319  case LibFunc_bcmp:
1320  case LibFunc_calloc:
1321  case LibFunc_fwrite:
1322  case LibFunc_malloc:
1323  case LibFunc_memcmp:
1324  case LibFunc_memcpy_chk:
1325  case LibFunc_mempcpy:
1326  case LibFunc_memset_pattern16:
1327  case LibFunc_snprintf:
1328  case LibFunc_stpncpy:
1329  case LibFunc_strlcat:
1330  case LibFunc_strlcpy:
1331  case LibFunc_strncat:
1332  case LibFunc_strncmp:
1333  case LibFunc_strncpy:
1334  case LibFunc_vsnprintf:
1335  break;
1336 
1337  default:
1338 #ifndef NDEBUG
1339  for (unsigned i = 0; i < T->getNumParams(); i++)
1340  assert(!isa<IntegerType>(T->getParamType(i)) &&
1341  "Unhandled integer argument.");
1342 #endif
1343  break;
1344  }
1345 
1347 
1348  return C;
1349 }
1350 
1352  LibFunc TheLibFunc, FunctionType *T) {
1353  return getOrInsertLibFunc(M, TLI, TheLibFunc, T, AttributeList());
1354 }
1355 
1357  LibFunc TheLibFunc) {
1358  StringRef FuncName = TLI->getName(TheLibFunc);
1359  if (!TLI->has(TheLibFunc))
1360  return false;
1361 
1362  // Check if the Module already has a GlobalValue with the same name, in
1363  // which case it must be a Function with the expected type.
1364  if (GlobalValue *GV = M->getNamedValue(FuncName)) {
1365  if (auto *F = dyn_cast<Function>(GV))
1366  return TLI->isValidProtoForLibFunc(*F->getFunctionType(), TheLibFunc, *M);
1367  return false;
1368  }
1369 
1370  return true;
1371 }
1372 
1374  StringRef Name) {
1375  LibFunc TheLibFunc;
1376  return TLI->getLibFunc(Name, TheLibFunc) &&
1377  isLibFuncEmittable(M, TLI, TheLibFunc);
1378 }
1379 
1380 bool llvm::hasFloatFn(const Module *M, const TargetLibraryInfo *TLI, Type *Ty,
1381  LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
1382  switch (Ty->getTypeID()) {
1383  case Type::HalfTyID:
1384  return false;
1385  case Type::FloatTyID:
1386  return isLibFuncEmittable(M, TLI, FloatFn);
1387  case Type::DoubleTyID:
1388  return isLibFuncEmittable(M, TLI, DoubleFn);
1389  default:
1390  return isLibFuncEmittable(M, TLI, LongDoubleFn);
1391  }
1392 }
1393 
1395  Type *Ty, LibFunc DoubleFn, LibFunc FloatFn,
1396  LibFunc LongDoubleFn, LibFunc &TheLibFunc) {
1397  assert(hasFloatFn(M, TLI, Ty, DoubleFn, FloatFn, LongDoubleFn) &&
1398  "Cannot get name for unavailable function!");
1399 
1400  switch (Ty->getTypeID()) {
1401  case Type::HalfTyID:
1402  llvm_unreachable("No name for HalfTy!");
1403  case Type::FloatTyID:
1404  TheLibFunc = FloatFn;
1405  return TLI->getName(FloatFn);
1406  case Type::DoubleTyID:
1407  TheLibFunc = DoubleFn;
1408  return TLI->getName(DoubleFn);
1409  default:
1410  TheLibFunc = LongDoubleFn;
1411  return TLI->getName(LongDoubleFn);
1412  }
1413 }
1414 
1415 //- Emit LibCalls ------------------------------------------------------------//
1416 
1418  unsigned AS = V->getType()->getPointerAddressSpace();
1419  return B.CreateBitCast(V, B.getInt8PtrTy(AS), "cstr");
1420 }
1421 
1422 static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
1423  ArrayRef<Type *> ParamTypes,
1425  const TargetLibraryInfo *TLI,
1426  bool IsVaArgs = false) {
1427  Module *M = B.GetInsertBlock()->getModule();
1428  if (!isLibFuncEmittable(M, TLI, TheLibFunc))
1429  return nullptr;
1430 
1431  StringRef FuncName = TLI->getName(TheLibFunc);
1432  FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1433  FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, FuncType);
1434  inferNonMandatoryLibFuncAttrs(M, FuncName, *TLI);
1435  CallInst *CI = B.CreateCall(Callee, Operands, FuncName);
1436  if (const Function *F =
1437  dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1438  CI->setCallingConv(F->getCallingConv());
1439  return CI;
1440 }
1441 
1443  const TargetLibraryInfo *TLI) {
1444  LLVMContext &Context = B.GetInsertBlock()->getContext();
1445  return emitLibCall(LibFunc_strlen, DL.getIntPtrType(Context),
1446  B.getInt8PtrTy(), castToCStr(Ptr, B), B, TLI);
1447 }
1448 
1450  const TargetLibraryInfo *TLI) {
1451  return emitLibCall(LibFunc_strdup, B.getInt8PtrTy(), B.getInt8PtrTy(),
1452  castToCStr(Ptr, B), B, TLI);
1453 }
1454 
1456  const TargetLibraryInfo *TLI) {
1457  Type *I8Ptr = B.getInt8PtrTy();
1458  Type *I32Ty = B.getInt32Ty();
1459  return emitLibCall(LibFunc_strchr, I8Ptr, {I8Ptr, I32Ty},
1460  {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, B, TLI);
1461 }
1462 
1464  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1465  LLVMContext &Context = B.GetInsertBlock()->getContext();
1466  return emitLibCall(
1467  LibFunc_strncmp, B.getInt32Ty(),
1468  {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
1469  {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
1470 }
1471 
1473  const TargetLibraryInfo *TLI) {
1474  Type *I8Ptr = Dst->getType();
1475  return emitLibCall(LibFunc_strcpy, I8Ptr, {I8Ptr, I8Ptr},
1476  {castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI);
1477 }
1478 
1480  const TargetLibraryInfo *TLI) {
1481  Type *I8Ptr = B.getInt8PtrTy();
1482  return emitLibCall(LibFunc_stpcpy, I8Ptr, {I8Ptr, I8Ptr},
1483  {castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI);
1484 }
1485 
1487  const TargetLibraryInfo *TLI) {
1488  Type *I8Ptr = B.getInt8PtrTy();
1489  return emitLibCall(LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType()},
1490  {castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
1491 }
1492 
1494  const TargetLibraryInfo *TLI) {
1495  Type *I8Ptr = B.getInt8PtrTy();
1496  return emitLibCall(LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType()},
1497  {castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
1498 }
1499 
1500 Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
1501  IRBuilderBase &B, const DataLayout &DL,
1502  const TargetLibraryInfo *TLI) {
1503  Module *M = B.GetInsertBlock()->getModule();
1504  if (!isLibFuncEmittable(M, TLI, LibFunc_memcpy_chk))
1505  return nullptr;
1506 
1507  AttributeList AS;
1509  Attribute::NoUnwind);
1510  LLVMContext &Context = B.GetInsertBlock()->getContext();
1511  FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
1512  AttributeList::get(M->getContext(), AS), B.getInt8PtrTy(),
1513  B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context),
1514  DL.getIntPtrType(Context));
1515  Dst = castToCStr(Dst, B);
1516  Src = castToCStr(Src, B);
1517  CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1518  if (const Function *F =
1519  dyn_cast<Function>(MemCpy.getCallee()->stripPointerCasts()))
1520  CI->setCallingConv(F->getCallingConv());
1521  return CI;
1522 }
1523 
1525  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1526  LLVMContext &Context = B.GetInsertBlock()->getContext();
1527  return emitLibCall(
1528  LibFunc_mempcpy, B.getInt8PtrTy(),
1529  {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
1530  {Dst, Src, Len}, B, TLI);
1531 }
1532 
1534  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1535  LLVMContext &Context = B.GetInsertBlock()->getContext();
1536  return emitLibCall(
1537  LibFunc_memchr, B.getInt8PtrTy(),
1538  {B.getInt8PtrTy(), B.getInt32Ty(), DL.getIntPtrType(Context)},
1539  {castToCStr(Ptr, B), Val, Len}, B, TLI);
1540 }
1541 
1543  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1544  LLVMContext &Context = B.GetInsertBlock()->getContext();
1545  return emitLibCall(
1546  LibFunc_memrchr, B.getInt8PtrTy(),
1547  {B.getInt8PtrTy(), B.getInt32Ty(), DL.getIntPtrType(Context)},
1548  {castToCStr(Ptr, B), Val, Len}, B, TLI);
1549 }
1550 
1552  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1553  LLVMContext &Context = B.GetInsertBlock()->getContext();
1554  return emitLibCall(
1555  LibFunc_memcmp, B.getInt32Ty(),
1556  {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
1557  {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
1558 }
1559 
1561  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1562  LLVMContext &Context = B.GetInsertBlock()->getContext();
1563  return emitLibCall(
1564  LibFunc_bcmp, B.getInt32Ty(),
1565  {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
1566  {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
1567 }
1568 
1569 Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
1570  IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1571  return emitLibCall(
1572  LibFunc_memccpy, B.getInt8PtrTy(),
1573  {B.getInt8PtrTy(), B.getInt8PtrTy(), B.getInt32Ty(), Len->getType()},
1574  {Ptr1, Ptr2, Val, Len}, B, TLI);
1575 }
1576 
1578  ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1579  const TargetLibraryInfo *TLI) {
1580  SmallVector<Value *, 8> Args{castToCStr(Dest, B), Size, castToCStr(Fmt, B)};
1581  llvm::append_range(Args, VariadicArgs);
1582  return emitLibCall(LibFunc_snprintf, B.getInt32Ty(),
1583  {B.getInt8PtrTy(), Size->getType(), B.getInt8PtrTy()},
1584  Args, B, TLI, /*IsVaArgs=*/true);
1585 }
1586 
1588  ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1589  const TargetLibraryInfo *TLI) {
1591  llvm::append_range(Args, VariadicArgs);
1592  return emitLibCall(LibFunc_sprintf, B.getInt32Ty(),
1593  {B.getInt8PtrTy(), B.getInt8PtrTy()}, Args, B, TLI,
1594  /*IsVaArgs=*/true);
1595 }
1596 
1598  const TargetLibraryInfo *TLI) {
1599  return emitLibCall(LibFunc_strcat, B.getInt8PtrTy(),
1600  {B.getInt8PtrTy(), B.getInt8PtrTy()},
1601  {castToCStr(Dest, B), castToCStr(Src, B)}, B, TLI);
1602 }
1603 
1605  const TargetLibraryInfo *TLI) {
1606  return emitLibCall(LibFunc_strlcpy, Size->getType(),
1607  {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
1608  {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
1609 }
1610 
1612  const TargetLibraryInfo *TLI) {
1613  return emitLibCall(LibFunc_strlcat, Size->getType(),
1614  {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
1615  {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
1616 }
1617 
1619  const TargetLibraryInfo *TLI) {
1620  return emitLibCall(LibFunc_strncat, B.getInt8PtrTy(),
1621  {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
1622  {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
1623 }
1624 
1625 Value *llvm::emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList,
1626  IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1627  return emitLibCall(
1628  LibFunc_vsnprintf, B.getInt32Ty(),
1629  {B.getInt8PtrTy(), Size->getType(), B.getInt8PtrTy(), VAList->getType()},
1630  {castToCStr(Dest, B), Size, castToCStr(Fmt, B), VAList}, B, TLI);
1631 }
1632 
1633 Value *llvm::emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList,
1634  IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1635  return emitLibCall(LibFunc_vsprintf, B.getInt32Ty(),
1636  {B.getInt8PtrTy(), B.getInt8PtrTy(), VAList->getType()},
1637  {castToCStr(Dest, B), castToCStr(Fmt, B), VAList}, B, TLI);
1638 }
1639 
1640 /// Append a suffix to the function name according to the type of 'Op'.
1642  SmallString<20> &NameBuffer) {
1643  if (!Op->getType()->isDoubleTy()) {
1644  NameBuffer += Name;
1645 
1646  if (Op->getType()->isFloatTy())
1647  NameBuffer += 'f';
1648  else
1649  NameBuffer += 'l';
1650 
1651  Name = NameBuffer;
1652  }
1653 }
1654 
1657  const AttributeList &Attrs,
1658  const TargetLibraryInfo *TLI) {
1659  assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
1660 
1661  Module *M = B.GetInsertBlock()->getModule();
1662  FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op->getType(),
1663  Op->getType());
1664  CallInst *CI = B.CreateCall(Callee, Op, Name);
1665 
1666  // The incoming attribute set may have come from a speculatable intrinsic, but
1667  // is being replaced with a library call which is not allowed to be
1668  // speculatable.
1669  CI->setAttributes(
1670  Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1671  if (const Function *F =
1672  dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1673  CI->setCallingConv(F->getCallingConv());
1674 
1675  return CI;
1676 }
1677 
1680  const AttributeList &Attrs) {
1681  SmallString<20> NameBuffer;
1682  appendTypeSuffix(Op, Name, NameBuffer);
1683 
1684  LibFunc TheLibFunc;
1685  TLI->getLibFunc(Name, TheLibFunc);
1686 
1687  return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1688 }
1689 
1691  LibFunc DoubleFn, LibFunc FloatFn,
1692  LibFunc LongDoubleFn, IRBuilderBase &B,
1693  const AttributeList &Attrs) {
1694  // Get the name of the function according to TLI.
1695  Module *M = B.GetInsertBlock()->getModule();
1696  LibFunc TheLibFunc;
1697  StringRef Name = getFloatFn(M, TLI, Op->getType(), DoubleFn, FloatFn,
1698  LongDoubleFn, TheLibFunc);
1699 
1700  return emitUnaryFloatFnCallHelper(Op, TheLibFunc, Name, B, Attrs, TLI);
1701 }
1702 
1704  LibFunc TheLibFunc,
1706  const AttributeList &Attrs,
1707  const TargetLibraryInfo *TLI) {
1708  assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1709 
1710  Module *M = B.GetInsertBlock()->getModule();
1711  FunctionCallee Callee = getOrInsertLibFunc(M, *TLI, TheLibFunc, Op1->getType(),
1712  Op1->getType(), Op2->getType());
1714  CallInst *CI = B.CreateCall(Callee, { Op1, Op2 }, Name);
1715 
1716  // The incoming attribute set may have come from a speculatable intrinsic, but
1717  // is being replaced with a library call which is not allowed to be
1718  // speculatable.
1719  CI->setAttributes(
1720  Attrs.removeFnAttribute(B.getContext(), Attribute::Speculatable));
1721  if (const Function *F =
1722  dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1723  CI->setCallingConv(F->getCallingConv());
1724 
1725  return CI;
1726 }
1727 
1729  const TargetLibraryInfo *TLI,
1731  const AttributeList &Attrs) {
1732  assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1733 
1734  SmallString<20> NameBuffer;
1735  appendTypeSuffix(Op1, Name, NameBuffer);
1736 
1737  LibFunc TheLibFunc;
1738  TLI->getLibFunc(Name, TheLibFunc);
1739 
1740  return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
1741 }
1742 
1744  const TargetLibraryInfo *TLI,
1745  LibFunc DoubleFn, LibFunc FloatFn,
1746  LibFunc LongDoubleFn, IRBuilderBase &B,
1747  const AttributeList &Attrs) {
1748  // Get the name of the function according to TLI.
1749  Module *M = B.GetInsertBlock()->getModule();
1750  LibFunc TheLibFunc;
1751  StringRef Name = getFloatFn(M, TLI, Op1->getType(), DoubleFn, FloatFn,
1752  LongDoubleFn, TheLibFunc);
1753 
1754  return emitBinaryFloatFnCallHelper(Op1, Op2, TheLibFunc, Name, B, Attrs, TLI);
1755 }
1756 
1758  const TargetLibraryInfo *TLI) {
1759  Module *M = B.GetInsertBlock()->getModule();
1760  if (!isLibFuncEmittable(M, TLI, LibFunc_putchar))
1761  return nullptr;
1762 
1763  StringRef PutCharName = TLI->getName(LibFunc_putchar);
1764  FunctionCallee PutChar = getOrInsertLibFunc(M, *TLI, LibFunc_putchar,
1765  B.getInt32Ty(), B.getInt32Ty());
1766  inferNonMandatoryLibFuncAttrs(M, PutCharName, *TLI);
1767  CallInst *CI = B.CreateCall(PutChar,
1768  B.CreateIntCast(Char,
1769  B.getInt32Ty(),
1770  /*isSigned*/true,
1771  "chari"),
1772  PutCharName);
1773 
1774  if (const Function *F =
1775  dyn_cast<Function>(PutChar.getCallee()->stripPointerCasts()))
1776  CI->setCallingConv(F->getCallingConv());
1777  return CI;
1778 }
1779 
1781  const TargetLibraryInfo *TLI) {
1782  Module *M = B.GetInsertBlock()->getModule();
1783  if (!isLibFuncEmittable(M, TLI, LibFunc_puts))
1784  return nullptr;
1785 
1786  StringRef PutsName = TLI->getName(LibFunc_puts);
1787  FunctionCallee PutS = getOrInsertLibFunc(M, *TLI, LibFunc_puts, B.getInt32Ty(),
1788  B.getInt8PtrTy());
1789  inferNonMandatoryLibFuncAttrs(M, PutsName, *TLI);
1790  CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), PutsName);
1791  if (const Function *F =
1792  dyn_cast<Function>(PutS.getCallee()->stripPointerCasts()))
1793  CI->setCallingConv(F->getCallingConv());
1794  return CI;
1795 }
1796 
1798  const TargetLibraryInfo *TLI) {
1799  Module *M = B.GetInsertBlock()->getModule();
1800  if (!isLibFuncEmittable(M, TLI, LibFunc_fputc))
1801  return nullptr;
1802 
1803  StringRef FPutcName = TLI->getName(LibFunc_fputc);
1804  FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputc, B.getInt32Ty(),
1805  B.getInt32Ty(), File->getType());
1806  if (File->getType()->isPointerTy())
1807  inferNonMandatoryLibFuncAttrs(M, FPutcName, *TLI);
1808  Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
1809  "chari");
1810  CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName);
1811 
1812  if (const Function *Fn =
1813  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1814  CI->setCallingConv(Fn->getCallingConv());
1815  return CI;
1816 }
1817 
1819  const TargetLibraryInfo *TLI) {
1820  Module *M = B.GetInsertBlock()->getModule();
1821  if (!isLibFuncEmittable(M, TLI, LibFunc_fputs))
1822  return nullptr;
1823 
1824  StringRef FPutsName = TLI->getName(LibFunc_fputs);
1825  FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputs, B.getInt32Ty(),
1826  B.getInt8PtrTy(), File->getType());
1827  if (File->getType()->isPointerTy())
1828  inferNonMandatoryLibFuncAttrs(M, FPutsName, *TLI);
1829  CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsName);
1830 
1831  if (const Function *Fn =
1832  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1833  CI->setCallingConv(Fn->getCallingConv());
1834  return CI;
1835 }
1836 
1838  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1839  Module *M = B.GetInsertBlock()->getModule();
1840  if (!isLibFuncEmittable(M, TLI, LibFunc_fwrite))
1841  return nullptr;
1842 
1843  LLVMContext &Context = B.GetInsertBlock()->getContext();
1844  StringRef FWriteName = TLI->getName(LibFunc_fwrite);
1845  FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fwrite,
1846  DL.getIntPtrType(Context), B.getInt8PtrTy(), DL.getIntPtrType(Context),
1847  DL.getIntPtrType(Context), File->getType());
1848 
1849  if (File->getType()->isPointerTy())
1850  inferNonMandatoryLibFuncAttrs(M, FWriteName, *TLI);
1851  CallInst *CI =
1852  B.CreateCall(F, {castToCStr(Ptr, B), Size,
1853  ConstantInt::get(DL.getIntPtrType(Context), 1), File});
1854 
1855  if (const Function *Fn =
1856  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1857  CI->setCallingConv(Fn->getCallingConv());
1858  return CI;
1859 }
1860 
1862  const TargetLibraryInfo *TLI) {
1863  Module *M = B.GetInsertBlock()->getModule();
1864  if (!isLibFuncEmittable(M, TLI, LibFunc_malloc))
1865  return nullptr;
1866 
1867  StringRef MallocName = TLI->getName(LibFunc_malloc);
1868  LLVMContext &Context = B.GetInsertBlock()->getContext();
1869  FunctionCallee Malloc = getOrInsertLibFunc(M, *TLI, LibFunc_malloc,
1870  B.getInt8PtrTy(), DL.getIntPtrType(Context));
1871  inferNonMandatoryLibFuncAttrs(M, MallocName, *TLI);
1872  CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
1873 
1874  if (const Function *F =
1875  dyn_cast<Function>(Malloc.getCallee()->stripPointerCasts()))
1876  CI->setCallingConv(F->getCallingConv());
1877 
1878  return CI;
1879 }
1880 
1882  const TargetLibraryInfo &TLI) {
1883  Module *M = B.GetInsertBlock()->getModule();
1884  if (!isLibFuncEmittable(M, &TLI, LibFunc_calloc))
1885  return nullptr;
1886 
1887  StringRef CallocName = TLI.getName(LibFunc_calloc);
1888  const DataLayout &DL = M->getDataLayout();
1889  IntegerType *PtrType = DL.getIntPtrType((B.GetInsertBlock()->getContext()));
1890  FunctionCallee Calloc = getOrInsertLibFunc(M, TLI, LibFunc_calloc,
1891  B.getInt8PtrTy(), PtrType, PtrType);
1892  inferNonMandatoryLibFuncAttrs(M, CallocName, TLI);
1893  CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
1894 
1895  if (const auto *F =
1896  dyn_cast<Function>(Calloc.getCallee()->stripPointerCasts()))
1897  CI->setCallingConv(F->getCallingConv());
1898 
1899  return CI;
1900 }
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:1655
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:4637
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:17
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:1881
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:1678
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:1551
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:1837
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:1641
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:1569
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:387
llvm::AllocFnKind::Alloc
@ Alloc
llvm::Optional< unsigned >
setArgExtAttr
static void setArgExtAttr(Function &F, unsigned ArgNo, const TargetLibraryInfo &TLI, bool Signed=true)
Definition: BuildLibCalls.cpp:1238
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:1422
F
#define F(x, y, z)
Definition: MD5.cpp:55
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
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:1449
llvm::emitFPutC
Value * emitFPutC(Value *Char, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
Definition: BuildLibCalls.cpp:1797
Constants.h
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:1597
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:1604
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:294
emitBinaryFloatFnCallHelper
static Value * emitBinaryFloatFnCallHelper(Value *Op1, Value *Op2, LibFunc TheLibFunc, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs, const TargetLibraryInfo *TLI)
Definition: BuildLibCalls.cpp:1703
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 integer.
Definition: BuildLibCalls.cpp:1757
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:374
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:1542
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:1463
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:1246
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::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:1394
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:1587
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:1500
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:1380
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
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:1611
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:1280
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:1560
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:1524
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:1493
llvm::TargetLibraryInfo::has
bool has(LibFunc F) const
Tests whether a library function is available.
Definition: TargetLibraryInfo.h:328
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:1618
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
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
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:58
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:1823
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:1479
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:1442
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:1472
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:280
setRetDoesNotAlias
static bool setRetDoesNotAlias(Function &F)
Definition: BuildLibCalls.cpp:112
llvm::Value::stripPointerCasts
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:682
llvm::FunctionCallee::getCallee
Value * getCallee()
Definition: DerivedTypes.h:184
Argument.h
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:186
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:1356
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::CallingConv::X86_StdCall
@ X86_StdCall
X86_StdCall - stdcall is the calling conventions mostly used by the Win32 API.
Definition: CallingConv.h:102
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:222
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:285
llvm::emitFPutS
Value * emitFPutS(Value *Str, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
Definition: BuildLibCalls.cpp:1818
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:1861
llvm::castToCStr
Value * castToCStr(Value *V, IRBuilderBase &B)
Return V if it is an i8*, otherwise cast it to i8*.
Definition: BuildLibCalls.cpp:1417
setDoesNotThrow
static bool setDoesNotThrow(Function &F)
Definition: BuildLibCalls.cpp:104
llvm::AttributeList::FunctionIndex
@ FunctionIndex
Definition: Attributes.h:429
llvm::isReallocLikeFn
bool isReallocLikeFn(const Value *V, const TargetLibraryInfo *TLI)
Tests if a value is a call or invoke to a library function that reallocates memory (e....
Definition: MemoryBuiltins.cpp:312
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:1486
N
#define N
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:1728
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:1577
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:1780
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:1455
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1471
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:512
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:1633
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:1625
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:1533
llvm::CallBase::setCallingConv
void setCallingConv(CallingConv::ID CC)
Definition: InstrTypes.h:1459
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:103