LLVM  13.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"
17 #include "llvm/IR/Constants.h"
18 #include "llvm/IR/DataLayout.h"
19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/IRBuilder.h"
21 #include "llvm/IR/Intrinsics.h"
22 #include "llvm/IR/LLVMContext.h"
23 #include "llvm/IR/Module.h"
24 #include "llvm/IR/Type.h"
26 
27 using namespace llvm;
28 
29 #define DEBUG_TYPE "build-libcalls"
30 
31 //- Infer Attributes ---------------------------------------------------------//
32 
33 STATISTIC(NumReadNone, "Number of functions inferred as readnone");
34 STATISTIC(NumInaccessibleMemOnly,
35  "Number of functions inferred as inaccessiblememonly");
36 STATISTIC(NumReadOnly, "Number of functions inferred as readonly");
37 STATISTIC(NumArgMemOnly, "Number of functions inferred as argmemonly");
38 STATISTIC(NumInaccessibleMemOrArgMemOnly,
39  "Number of functions inferred as inaccessiblemem_or_argmemonly");
40 STATISTIC(NumNoUnwind, "Number of functions inferred as nounwind");
41 STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture");
42 STATISTIC(NumWriteOnlyArg, "Number of arguments inferred as writeonly");
43 STATISTIC(NumSExtArg, "Number of arguments inferred as signext");
44 STATISTIC(NumReadOnlyArg, "Number of arguments inferred as readonly");
45 STATISTIC(NumNoAlias, "Number of function returns inferred as noalias");
46 STATISTIC(NumNoUndef, "Number of function returns inferred as noundef returns");
47 STATISTIC(NumNonNull, "Number of function returns inferred as nonnull 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.onlyAccessesArgMemory())
77  return false;
78  F.setOnlyAccessesArgMemory();
79  ++NumArgMemOnly;
80  return true;
81 }
82 
84  if (F.onlyAccessesInaccessibleMemOrArgMem())
85  return false;
86  F.setOnlyAccessesInaccessibleMemOrArgMem();
87  ++NumInaccessibleMemOrArgMemOnly;
88  return true;
89 }
90 
91 static bool setDoesNotThrow(Function &F) {
92  if (F.doesNotThrow())
93  return false;
94  F.setDoesNotThrow();
95  ++NumNoUnwind;
96  return true;
97 }
98 
99 static bool setRetDoesNotAlias(Function &F) {
100  if (F.hasAttribute(AttributeList::ReturnIndex, Attribute::NoAlias))
101  return false;
102  F.addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
103  ++NumNoAlias;
104  return true;
105 }
106 
107 static bool setDoesNotCapture(Function &F, unsigned ArgNo) {
108  if (F.hasParamAttribute(ArgNo, Attribute::NoCapture))
109  return false;
110  F.addParamAttr(ArgNo, Attribute::NoCapture);
111  ++NumNoCapture;
112  return true;
113 }
114 
115 static bool setDoesNotAlias(Function &F, unsigned ArgNo) {
116  if (F.hasParamAttribute(ArgNo, Attribute::NoAlias))
117  return false;
118  F.addParamAttr(ArgNo, Attribute::NoAlias);
119  ++NumNoAlias;
120  return true;
121 }
122 
123 static bool setOnlyReadsMemory(Function &F, unsigned ArgNo) {
124  if (F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
125  return false;
126  F.addParamAttr(ArgNo, Attribute::ReadOnly);
127  ++NumReadOnlyArg;
128  return true;
129 }
130 
131 static bool setOnlyWritesMemory(Function &F, unsigned ArgNo) {
132  if (F.hasParamAttribute(ArgNo, Attribute::WriteOnly))
133  return false;
134  F.addParamAttr(ArgNo, Attribute::WriteOnly);
135  ++NumWriteOnlyArg;
136  return true;
137 }
138 
139 static bool setSignExtendedArg(Function &F, unsigned ArgNo) {
140  if (F.hasParamAttribute(ArgNo, Attribute::SExt))
141  return false;
142  F.addParamAttr(ArgNo, Attribute::SExt);
143  ++NumSExtArg;
144  return true;
145 }
146 
147 static bool setRetNoUndef(Function &F) {
148  if (!F.getReturnType()->isVoidTy() &&
149  !F.hasAttribute(AttributeList::ReturnIndex, Attribute::NoUndef)) {
150  F.addAttribute(AttributeList::ReturnIndex, Attribute::NoUndef);
151  ++NumNoUndef;
152  return true;
153  }
154  return false;
155 }
156 
157 static bool setArgsNoUndef(Function &F) {
158  bool Changed = false;
159  for (unsigned ArgNo = 0; ArgNo < F.arg_size(); ++ArgNo) {
160  if (!F.hasParamAttribute(ArgNo, Attribute::NoUndef)) {
161  F.addParamAttr(ArgNo, Attribute::NoUndef);
162  ++NumNoUndef;
163  Changed = true;
164  }
165  }
166  return Changed;
167 }
168 
169 static bool setArgNoUndef(Function &F, unsigned ArgNo) {
170  if (F.hasParamAttribute(ArgNo, Attribute::NoUndef))
171  return false;
172  F.addParamAttr(ArgNo, Attribute::NoUndef);
173  ++NumNoUndef;
174  return true;
175 }
176 
178  return setRetNoUndef(F) | setArgsNoUndef(F);
179 }
180 
181 static bool setReturnedArg(Function &F, unsigned ArgNo) {
182  if (F.hasParamAttribute(ArgNo, Attribute::Returned))
183  return false;
184  F.addParamAttr(ArgNo, Attribute::Returned);
185  ++NumReturnedArg;
186  return true;
187 }
188 
189 static bool setNonLazyBind(Function &F) {
190  if (F.hasFnAttribute(Attribute::NonLazyBind))
191  return false;
192  F.addFnAttr(Attribute::NonLazyBind);
193  return true;
194 }
195 
197  if (F.hasFnAttribute(Attribute::NoFree))
198  return false;
199  F.addFnAttr(Attribute::NoFree);
200  return true;
201 }
202 
203 static bool setWillReturn(Function &F) {
204  if (F.hasFnAttribute(Attribute::WillReturn))
205  return false;
206  F.addFnAttr(Attribute::WillReturn);
207  ++NumWillReturn;
208  return true;
209 }
210 
212  const TargetLibraryInfo &TLI) {
213  Function *F = M->getFunction(Name);
214  if (!F)
215  return false;
216  return inferLibFuncAttributes(*F, TLI);
217 }
218 
220  LibFunc TheLibFunc;
221  if (!(TLI.getLibFunc(F, TheLibFunc) && TLI.has(TheLibFunc)))
222  return false;
223 
224  bool Changed = false;
225 
226  if(!isLibFreeFunction(&F, TheLibFunc) && !isReallocLikeFn(&F, &TLI))
227  Changed |= setDoesNotFreeMemory(F);
228 
229  if (F.getParent() != nullptr && F.getParent()->getRtLibUseGOT())
230  Changed |= setNonLazyBind(F);
231 
232  switch (TheLibFunc) {
233  case LibFunc_strlen:
234  case LibFunc_wcslen:
235  Changed |= setOnlyReadsMemory(F);
236  Changed |= setDoesNotThrow(F);
237  Changed |= setOnlyAccessesArgMemory(F);
238  Changed |= setWillReturn(F);
239  Changed |= setDoesNotCapture(F, 0);
240  return Changed;
241  case LibFunc_strchr:
242  case LibFunc_strrchr:
243  Changed |= setOnlyAccessesArgMemory(F);
244  Changed |= setOnlyReadsMemory(F);
245  Changed |= setDoesNotThrow(F);
246  Changed |= setWillReturn(F);
247  return Changed;
248  case LibFunc_strtol:
249  case LibFunc_strtod:
250  case LibFunc_strtof:
251  case LibFunc_strtoul:
252  case LibFunc_strtoll:
253  case LibFunc_strtold:
254  case LibFunc_strtoull:
255  Changed |= setDoesNotThrow(F);
256  Changed |= setWillReturn(F);
257  Changed |= setDoesNotCapture(F, 1);
258  Changed |= setOnlyReadsMemory(F, 0);
259  return Changed;
260  case LibFunc_strcat:
261  case LibFunc_strncat:
262  Changed |= setOnlyAccessesArgMemory(F);
263  Changed |= setDoesNotThrow(F);
264  Changed |= setWillReturn(F);
265  Changed |= setReturnedArg(F, 0);
266  Changed |= setDoesNotCapture(F, 1);
267  Changed |= setOnlyReadsMemory(F, 1);
268  Changed |= setDoesNotAlias(F, 0);
269  Changed |= setDoesNotAlias(F, 1);
270  return Changed;
271  case LibFunc_strcpy:
272  case LibFunc_strncpy:
273  Changed |= setReturnedArg(F, 0);
275  case LibFunc_stpcpy:
276  case LibFunc_stpncpy:
277  Changed |= setOnlyAccessesArgMemory(F);
278  Changed |= setDoesNotThrow(F);
279  Changed |= setWillReturn(F);
280  Changed |= setDoesNotCapture(F, 1);
281  Changed |= setOnlyWritesMemory(F, 0);
282  Changed |= setOnlyReadsMemory(F, 1);
283  Changed |= setDoesNotAlias(F, 0);
284  Changed |= setDoesNotAlias(F, 1);
285  return Changed;
286  case LibFunc_strxfrm:
287  Changed |= setDoesNotThrow(F);
288  Changed |= setWillReturn(F);
289  Changed |= setDoesNotCapture(F, 0);
290  Changed |= setDoesNotCapture(F, 1);
291  Changed |= setOnlyReadsMemory(F, 1);
292  return Changed;
293  case LibFunc_strcmp: // 0,1
294  case LibFunc_strspn: // 0,1
295  case LibFunc_strncmp: // 0,1
296  case LibFunc_strcspn: // 0,1
297  Changed |= setDoesNotThrow(F);
298  Changed |= setOnlyAccessesArgMemory(F);
299  Changed |= setWillReturn(F);
300  Changed |= setOnlyReadsMemory(F);
301  Changed |= setDoesNotCapture(F, 0);
302  Changed |= setDoesNotCapture(F, 1);
303  return Changed;
304  case LibFunc_strcoll:
305  case LibFunc_strcasecmp: // 0,1
306  case LibFunc_strncasecmp: //
307  // Those functions may depend on the locale, which may be accessed through
308  // global memory.
309  Changed |= setOnlyReadsMemory(F);
310  Changed |= setDoesNotThrow(F);
311  Changed |= setWillReturn(F);
312  Changed |= setDoesNotCapture(F, 0);
313  Changed |= setDoesNotCapture(F, 1);
314  return Changed;
315  case LibFunc_strstr:
316  case LibFunc_strpbrk:
317  Changed |= setOnlyAccessesArgMemory(F);
318  Changed |= setOnlyReadsMemory(F);
319  Changed |= setDoesNotThrow(F);
320  Changed |= setWillReturn(F);
321  Changed |= setDoesNotCapture(F, 1);
322  return Changed;
323  case LibFunc_strtok:
324  case LibFunc_strtok_r:
325  Changed |= setDoesNotThrow(F);
326  Changed |= setWillReturn(F);
327  Changed |= setDoesNotCapture(F, 1);
328  Changed |= setOnlyReadsMemory(F, 1);
329  return Changed;
330  case LibFunc_scanf:
331  Changed |= setRetAndArgsNoUndef(F);
332  Changed |= setDoesNotThrow(F);
333  Changed |= setDoesNotCapture(F, 0);
334  Changed |= setOnlyReadsMemory(F, 0);
335  return Changed;
336  case LibFunc_setbuf:
337  case LibFunc_setvbuf:
338  Changed |= setRetAndArgsNoUndef(F);
339  Changed |= setDoesNotThrow(F);
340  Changed |= setDoesNotCapture(F, 0);
341  return Changed;
342  case LibFunc_strndup:
343  Changed |= setArgNoUndef(F, 1);
345  case LibFunc_strdup:
347  Changed |= setDoesNotThrow(F);
348  Changed |= setRetDoesNotAlias(F);
349  Changed |= setWillReturn(F);
350  Changed |= setDoesNotCapture(F, 0);
351  Changed |= setOnlyReadsMemory(F, 0);
352  return Changed;
353  case LibFunc_stat:
354  case LibFunc_statvfs:
355  Changed |= setRetAndArgsNoUndef(F);
356  Changed |= setDoesNotThrow(F);
357  Changed |= setDoesNotCapture(F, 0);
358  Changed |= setDoesNotCapture(F, 1);
359  Changed |= setOnlyReadsMemory(F, 0);
360  return Changed;
361  case LibFunc_sscanf:
362  Changed |= setRetAndArgsNoUndef(F);
363  Changed |= setDoesNotThrow(F);
364  Changed |= setDoesNotCapture(F, 0);
365  Changed |= setDoesNotCapture(F, 1);
366  Changed |= setOnlyReadsMemory(F, 0);
367  Changed |= setOnlyReadsMemory(F, 1);
368  return Changed;
369  case LibFunc_sprintf:
370  Changed |= setRetAndArgsNoUndef(F);
371  Changed |= setDoesNotThrow(F);
372  Changed |= setDoesNotCapture(F, 0);
373  Changed |= setDoesNotAlias(F, 0);
374  Changed |= setOnlyWritesMemory(F, 0);
375  Changed |= setDoesNotCapture(F, 1);
376  Changed |= setOnlyReadsMemory(F, 1);
377  return Changed;
378  case LibFunc_snprintf:
379  Changed |= setRetAndArgsNoUndef(F);
380  Changed |= setDoesNotThrow(F);
381  Changed |= setDoesNotCapture(F, 0);
382  Changed |= setDoesNotAlias(F, 0);
383  Changed |= setOnlyWritesMemory(F, 0);
384  Changed |= setDoesNotCapture(F, 2);
385  Changed |= setOnlyReadsMemory(F, 2);
386  return Changed;
387  case LibFunc_setitimer:
388  Changed |= setRetAndArgsNoUndef(F);
389  Changed |= setDoesNotThrow(F);
390  Changed |= setWillReturn(F);
391  Changed |= setDoesNotCapture(F, 1);
392  Changed |= setDoesNotCapture(F, 2);
393  Changed |= setOnlyReadsMemory(F, 1);
394  return Changed;
395  case LibFunc_system:
396  // May throw; "system" is a valid pthread cancellation point.
397  Changed |= setRetAndArgsNoUndef(F);
398  Changed |= setDoesNotCapture(F, 0);
399  Changed |= setOnlyReadsMemory(F, 0);
400  return Changed;
401  case LibFunc_malloc:
402  case LibFunc_vec_malloc:
404  Changed |= setRetAndArgsNoUndef(F);
405  Changed |= setDoesNotThrow(F);
406  Changed |= setRetDoesNotAlias(F);
407  Changed |= setWillReturn(F);
408  return Changed;
409  case LibFunc_memcmp:
410  Changed |= setOnlyAccessesArgMemory(F);
411  Changed |= setOnlyReadsMemory(F);
412  Changed |= setDoesNotThrow(F);
413  Changed |= setWillReturn(F);
414  Changed |= setDoesNotCapture(F, 0);
415  Changed |= setDoesNotCapture(F, 1);
416  return Changed;
417  case LibFunc_memchr:
418  case LibFunc_memrchr:
419  Changed |= setDoesNotThrow(F);
420  Changed |= setOnlyAccessesArgMemory(F);
421  Changed |= setOnlyReadsMemory(F);
422  Changed |= setWillReturn(F);
423  return Changed;
424  case LibFunc_modf:
425  case LibFunc_modff:
426  case LibFunc_modfl:
427  Changed |= setDoesNotThrow(F);
428  Changed |= setWillReturn(F);
429  Changed |= setDoesNotCapture(F, 1);
430  return Changed;
431  case LibFunc_memcpy:
432  Changed |= setDoesNotThrow(F);
433  Changed |= setOnlyAccessesArgMemory(F);
434  Changed |= setWillReturn(F);
435  Changed |= setDoesNotAlias(F, 0);
436  Changed |= setReturnedArg(F, 0);
437  Changed |= setOnlyWritesMemory(F, 0);
438  Changed |= setDoesNotAlias(F, 1);
439  Changed |= setDoesNotCapture(F, 1);
440  Changed |= setOnlyReadsMemory(F, 1);
441  return Changed;
442  case LibFunc_memmove:
443  Changed |= setDoesNotThrow(F);
444  Changed |= setOnlyAccessesArgMemory(F);
445  Changed |= setWillReturn(F);
446  Changed |= setReturnedArg(F, 0);
447  Changed |= setOnlyWritesMemory(F, 0);
448  Changed |= setDoesNotCapture(F, 1);
449  Changed |= setOnlyReadsMemory(F, 1);
450  return Changed;
451  case LibFunc_mempcpy:
452  case LibFunc_memccpy:
453  Changed |= setDoesNotThrow(F);
454  Changed |= setOnlyAccessesArgMemory(F);
455  Changed |= setWillReturn(F);
456  Changed |= setDoesNotAlias(F, 0);
457  Changed |= setOnlyWritesMemory(F, 0);
458  Changed |= setDoesNotAlias(F, 1);
459  Changed |= setDoesNotCapture(F, 1);
460  Changed |= setOnlyReadsMemory(F, 1);
461  return Changed;
462  case LibFunc_memcpy_chk:
463  Changed |= setDoesNotThrow(F);
464  return Changed;
465  case LibFunc_memalign:
467  Changed |= setRetNoUndef(F);
468  Changed |= setDoesNotThrow(F);
469  Changed |= setRetDoesNotAlias(F);
470  Changed |= setWillReturn(F);
471  return Changed;
472  case LibFunc_mkdir:
473  Changed |= setRetAndArgsNoUndef(F);
474  Changed |= setDoesNotThrow(F);
475  Changed |= setDoesNotCapture(F, 0);
476  Changed |= setOnlyReadsMemory(F, 0);
477  return Changed;
478  case LibFunc_mktime:
479  Changed |= setRetAndArgsNoUndef(F);
480  Changed |= setDoesNotThrow(F);
481  Changed |= setWillReturn(F);
482  Changed |= setDoesNotCapture(F, 0);
483  return Changed;
484  case LibFunc_realloc:
485  case LibFunc_vec_realloc:
487  Changed |= setRetNoUndef(F);
488  Changed |= setDoesNotThrow(F);
489  Changed |= setRetDoesNotAlias(F);
490  Changed |= setWillReturn(F);
491  Changed |= setDoesNotCapture(F, 0);
492  Changed |= setArgNoUndef(F, 1);
493  return Changed;
494  case LibFunc_reallocf:
495  Changed |= setRetNoUndef(F);
496  Changed |= setWillReturn(F);
497  Changed |= setArgNoUndef(F, 1);
498  return Changed;
499  case LibFunc_read:
500  // May throw; "read" is a valid pthread cancellation point.
501  Changed |= setRetAndArgsNoUndef(F);
502  Changed |= setDoesNotCapture(F, 1);
503  return Changed;
504  case LibFunc_rewind:
505  Changed |= setRetAndArgsNoUndef(F);
506  Changed |= setDoesNotThrow(F);
507  Changed |= setDoesNotCapture(F, 0);
508  return Changed;
509  case LibFunc_rmdir:
510  case LibFunc_remove:
511  case LibFunc_realpath:
512  Changed |= setRetAndArgsNoUndef(F);
513  Changed |= setDoesNotThrow(F);
514  Changed |= setDoesNotCapture(F, 0);
515  Changed |= setOnlyReadsMemory(F, 0);
516  return Changed;
517  case LibFunc_rename:
518  Changed |= setRetAndArgsNoUndef(F);
519  Changed |= setDoesNotThrow(F);
520  Changed |= setDoesNotCapture(F, 0);
521  Changed |= setDoesNotCapture(F, 1);
522  Changed |= setOnlyReadsMemory(F, 0);
523  Changed |= setOnlyReadsMemory(F, 1);
524  return Changed;
525  case LibFunc_readlink:
526  Changed |= setRetAndArgsNoUndef(F);
527  Changed |= setDoesNotThrow(F);
528  Changed |= setDoesNotCapture(F, 0);
529  Changed |= setDoesNotCapture(F, 1);
530  Changed |= setOnlyReadsMemory(F, 0);
531  return Changed;
532  case LibFunc_write:
533  // May throw; "write" is a valid pthread cancellation point.
534  Changed |= setRetAndArgsNoUndef(F);
535  Changed |= setDoesNotCapture(F, 1);
536  Changed |= setOnlyReadsMemory(F, 1);
537  return Changed;
538  case LibFunc_aligned_alloc:
540  Changed |= setRetAndArgsNoUndef(F);
541  Changed |= setDoesNotThrow(F);
542  Changed |= setRetDoesNotAlias(F);
543  Changed |= setWillReturn(F);
544  return Changed;
545  case LibFunc_bcopy:
546  Changed |= setDoesNotThrow(F);
547  Changed |= setOnlyAccessesArgMemory(F);
548  Changed |= setWillReturn(F);
549  Changed |= setDoesNotCapture(F, 0);
550  Changed |= setOnlyReadsMemory(F, 0);
551  Changed |= setOnlyWritesMemory(F, 1);
552  Changed |= setDoesNotCapture(F, 1);
553  return Changed;
554  case LibFunc_bcmp:
555  Changed |= setDoesNotThrow(F);
556  Changed |= setOnlyAccessesArgMemory(F);
557  Changed |= setOnlyReadsMemory(F);
558  Changed |= setWillReturn(F);
559  Changed |= setDoesNotCapture(F, 0);
560  Changed |= setDoesNotCapture(F, 1);
561  return Changed;
562  case LibFunc_bzero:
563  Changed |= setDoesNotThrow(F);
564  Changed |= setOnlyAccessesArgMemory(F);
565  Changed |= setWillReturn(F);
566  Changed |= setDoesNotCapture(F, 0);
567  Changed |= setOnlyWritesMemory(F, 0);
568  return Changed;
569  case LibFunc_calloc:
570  case LibFunc_vec_calloc:
572  Changed |= setRetAndArgsNoUndef(F);
573  Changed |= setDoesNotThrow(F);
574  Changed |= setRetDoesNotAlias(F);
575  Changed |= setWillReturn(F);
576  return Changed;
577  case LibFunc_chmod:
578  case LibFunc_chown:
579  Changed |= setRetAndArgsNoUndef(F);
580  Changed |= setDoesNotThrow(F);
581  Changed |= setDoesNotCapture(F, 0);
582  Changed |= setOnlyReadsMemory(F, 0);
583  return Changed;
584  case LibFunc_ctermid:
585  case LibFunc_clearerr:
586  case LibFunc_closedir:
587  Changed |= setRetAndArgsNoUndef(F);
588  Changed |= setDoesNotThrow(F);
589  Changed |= setDoesNotCapture(F, 0);
590  return Changed;
591  case LibFunc_atoi:
592  case LibFunc_atol:
593  case LibFunc_atof:
594  case LibFunc_atoll:
595  Changed |= setDoesNotThrow(F);
596  Changed |= setOnlyReadsMemory(F);
597  Changed |= setWillReturn(F);
598  Changed |= setDoesNotCapture(F, 0);
599  return Changed;
600  case LibFunc_access:
601  Changed |= setRetAndArgsNoUndef(F);
602  Changed |= setDoesNotThrow(F);
603  Changed |= setDoesNotCapture(F, 0);
604  Changed |= setOnlyReadsMemory(F, 0);
605  return Changed;
606  case LibFunc_fopen:
607  Changed |= setRetAndArgsNoUndef(F);
608  Changed |= setDoesNotThrow(F);
609  Changed |= setRetDoesNotAlias(F);
610  Changed |= setDoesNotCapture(F, 0);
611  Changed |= setDoesNotCapture(F, 1);
612  Changed |= setOnlyReadsMemory(F, 0);
613  Changed |= setOnlyReadsMemory(F, 1);
614  return Changed;
615  case LibFunc_fdopen:
616  Changed |= setRetAndArgsNoUndef(F);
617  Changed |= setDoesNotThrow(F);
618  Changed |= setRetDoesNotAlias(F);
619  Changed |= setDoesNotCapture(F, 1);
620  Changed |= setOnlyReadsMemory(F, 1);
621  return Changed;
622  case LibFunc_feof:
623  Changed |= setRetAndArgsNoUndef(F);
624  Changed |= setDoesNotThrow(F);
625  Changed |= setDoesNotCapture(F, 0);
626  return Changed;
627  case LibFunc_free:
628  case LibFunc_vec_free:
630  Changed |= setArgsNoUndef(F);
631  Changed |= setDoesNotThrow(F);
632  Changed |= setWillReturn(F);
633  Changed |= setDoesNotCapture(F, 0);
634  return Changed;
635  case LibFunc_fseek:
636  case LibFunc_ftell:
637  case LibFunc_fgetc:
638  case LibFunc_fgetc_unlocked:
639  case LibFunc_fseeko:
640  case LibFunc_ftello:
641  case LibFunc_fileno:
642  case LibFunc_fflush:
643  case LibFunc_fclose:
644  case LibFunc_fsetpos:
645  case LibFunc_flockfile:
646  case LibFunc_funlockfile:
647  case LibFunc_ftrylockfile:
648  Changed |= setRetAndArgsNoUndef(F);
649  Changed |= setDoesNotThrow(F);
650  Changed |= setDoesNotCapture(F, 0);
651  return Changed;
652  case LibFunc_ferror:
653  Changed |= setRetAndArgsNoUndef(F);
654  Changed |= setDoesNotThrow(F);
655  Changed |= setDoesNotCapture(F, 0);
656  Changed |= setOnlyReadsMemory(F);
657  return Changed;
658  case LibFunc_fputc:
659  case LibFunc_fputc_unlocked:
660  case LibFunc_fstat:
661  Changed |= setRetAndArgsNoUndef(F);
662  Changed |= setDoesNotThrow(F);
663  Changed |= setDoesNotCapture(F, 1);
664  return Changed;
665  case LibFunc_frexp:
666  case LibFunc_frexpf:
667  case LibFunc_frexpl:
668  Changed |= setDoesNotThrow(F);
669  Changed |= setWillReturn(F);
670  Changed |= setDoesNotCapture(F, 1);
671  return Changed;
672  case LibFunc_fstatvfs:
673  Changed |= setRetAndArgsNoUndef(F);
674  Changed |= setDoesNotThrow(F);
675  Changed |= setDoesNotCapture(F, 1);
676  return Changed;
677  case LibFunc_fgets:
678  case LibFunc_fgets_unlocked:
679  Changed |= setRetAndArgsNoUndef(F);
680  Changed |= setDoesNotThrow(F);
681  Changed |= setDoesNotCapture(F, 2);
682  return Changed;
683  case LibFunc_fread:
684  case LibFunc_fread_unlocked:
685  Changed |= setRetAndArgsNoUndef(F);
686  Changed |= setDoesNotThrow(F);
687  Changed |= setDoesNotCapture(F, 0);
688  Changed |= setDoesNotCapture(F, 3);
689  return Changed;
690  case LibFunc_fwrite:
691  case LibFunc_fwrite_unlocked:
692  Changed |= setRetAndArgsNoUndef(F);
693  Changed |= setDoesNotThrow(F);
694  Changed |= setDoesNotCapture(F, 0);
695  Changed |= setDoesNotCapture(F, 3);
696  // FIXME: readonly #1?
697  return Changed;
698  case LibFunc_fputs:
699  case LibFunc_fputs_unlocked:
700  Changed |= setRetAndArgsNoUndef(F);
701  Changed |= setDoesNotThrow(F);
702  Changed |= setDoesNotCapture(F, 0);
703  Changed |= setDoesNotCapture(F, 1);
704  Changed |= setOnlyReadsMemory(F, 0);
705  return Changed;
706  case LibFunc_fscanf:
707  case LibFunc_fprintf:
708  Changed |= setRetAndArgsNoUndef(F);
709  Changed |= setDoesNotThrow(F);
710  Changed |= setDoesNotCapture(F, 0);
711  Changed |= setDoesNotCapture(F, 1);
712  Changed |= setOnlyReadsMemory(F, 1);
713  return Changed;
714  case LibFunc_fgetpos:
715  Changed |= setRetAndArgsNoUndef(F);
716  Changed |= setDoesNotThrow(F);
717  Changed |= setDoesNotCapture(F, 0);
718  Changed |= setDoesNotCapture(F, 1);
719  return Changed;
720  case LibFunc_getc:
721  Changed |= setRetAndArgsNoUndef(F);
722  Changed |= setDoesNotThrow(F);
723  Changed |= setDoesNotCapture(F, 0);
724  return Changed;
725  case LibFunc_getlogin_r:
726  Changed |= setRetAndArgsNoUndef(F);
727  Changed |= setDoesNotThrow(F);
728  Changed |= setDoesNotCapture(F, 0);
729  return Changed;
730  case LibFunc_getc_unlocked:
731  Changed |= setRetAndArgsNoUndef(F);
732  Changed |= setDoesNotThrow(F);
733  Changed |= setDoesNotCapture(F, 0);
734  return Changed;
735  case LibFunc_getenv:
736  Changed |= setRetAndArgsNoUndef(F);
737  Changed |= setDoesNotThrow(F);
738  Changed |= setOnlyReadsMemory(F);
739  Changed |= setDoesNotCapture(F, 0);
740  return Changed;
741  case LibFunc_gets:
742  case LibFunc_getchar:
743  case LibFunc_getchar_unlocked:
744  Changed |= setRetAndArgsNoUndef(F);
745  Changed |= setDoesNotThrow(F);
746  return Changed;
747  case LibFunc_getitimer:
748  Changed |= setRetAndArgsNoUndef(F);
749  Changed |= setDoesNotThrow(F);
750  Changed |= setDoesNotCapture(F, 1);
751  return Changed;
752  case LibFunc_getpwnam:
753  Changed |= setRetAndArgsNoUndef(F);
754  Changed |= setDoesNotThrow(F);
755  Changed |= setDoesNotCapture(F, 0);
756  Changed |= setOnlyReadsMemory(F, 0);
757  return Changed;
758  case LibFunc_ungetc:
759  Changed |= setRetAndArgsNoUndef(F);
760  Changed |= setDoesNotThrow(F);
761  Changed |= setDoesNotCapture(F, 1);
762  return Changed;
763  case LibFunc_uname:
764  Changed |= setRetAndArgsNoUndef(F);
765  Changed |= setDoesNotThrow(F);
766  Changed |= setDoesNotCapture(F, 0);
767  return Changed;
768  case LibFunc_unlink:
769  Changed |= setRetAndArgsNoUndef(F);
770  Changed |= setDoesNotThrow(F);
771  Changed |= setDoesNotCapture(F, 0);
772  Changed |= setOnlyReadsMemory(F, 0);
773  return Changed;
774  case LibFunc_unsetenv:
775  Changed |= setRetAndArgsNoUndef(F);
776  Changed |= setDoesNotThrow(F);
777  Changed |= setDoesNotCapture(F, 0);
778  Changed |= setOnlyReadsMemory(F, 0);
779  return Changed;
780  case LibFunc_utime:
781  case LibFunc_utimes:
782  Changed |= setRetAndArgsNoUndef(F);
783  Changed |= setDoesNotThrow(F);
784  Changed |= setDoesNotCapture(F, 0);
785  Changed |= setDoesNotCapture(F, 1);
786  Changed |= setOnlyReadsMemory(F, 0);
787  Changed |= setOnlyReadsMemory(F, 1);
788  return Changed;
789  case LibFunc_putc:
790  case LibFunc_putc_unlocked:
791  Changed |= setRetAndArgsNoUndef(F);
792  Changed |= setDoesNotThrow(F);
793  Changed |= setDoesNotCapture(F, 1);
794  return Changed;
795  case LibFunc_puts:
796  case LibFunc_printf:
797  case LibFunc_perror:
798  Changed |= setRetAndArgsNoUndef(F);
799  Changed |= setDoesNotThrow(F);
800  Changed |= setDoesNotCapture(F, 0);
801  Changed |= setOnlyReadsMemory(F, 0);
802  return Changed;
803  case LibFunc_pread:
804  // May throw; "pread" is a valid pthread cancellation point.
805  Changed |= setRetAndArgsNoUndef(F);
806  Changed |= setDoesNotCapture(F, 1);
807  return Changed;
808  case LibFunc_pwrite:
809  // May throw; "pwrite" is a valid pthread cancellation point.
810  Changed |= setRetAndArgsNoUndef(F);
811  Changed |= setDoesNotCapture(F, 1);
812  Changed |= setOnlyReadsMemory(F, 1);
813  return Changed;
814  case LibFunc_putchar:
815  case LibFunc_putchar_unlocked:
816  Changed |= setRetAndArgsNoUndef(F);
817  Changed |= setDoesNotThrow(F);
818  return Changed;
819  case LibFunc_popen:
820  Changed |= setRetAndArgsNoUndef(F);
821  Changed |= setDoesNotThrow(F);
822  Changed |= setRetDoesNotAlias(F);
823  Changed |= setDoesNotCapture(F, 0);
824  Changed |= setDoesNotCapture(F, 1);
825  Changed |= setOnlyReadsMemory(F, 0);
826  Changed |= setOnlyReadsMemory(F, 1);
827  return Changed;
828  case LibFunc_pclose:
829  Changed |= setRetAndArgsNoUndef(F);
830  Changed |= setDoesNotThrow(F);
831  Changed |= setDoesNotCapture(F, 0);
832  return Changed;
833  case LibFunc_vscanf:
834  Changed |= setRetAndArgsNoUndef(F);
835  Changed |= setDoesNotThrow(F);
836  Changed |= setDoesNotCapture(F, 0);
837  Changed |= setOnlyReadsMemory(F, 0);
838  return Changed;
839  case LibFunc_vsscanf:
840  Changed |= setRetAndArgsNoUndef(F);
841  Changed |= setDoesNotThrow(F);
842  Changed |= setDoesNotCapture(F, 0);
843  Changed |= setDoesNotCapture(F, 1);
844  Changed |= setOnlyReadsMemory(F, 0);
845  Changed |= setOnlyReadsMemory(F, 1);
846  return Changed;
847  case LibFunc_vfscanf:
848  Changed |= setRetAndArgsNoUndef(F);
849  Changed |= setDoesNotThrow(F);
850  Changed |= setDoesNotCapture(F, 0);
851  Changed |= setDoesNotCapture(F, 1);
852  Changed |= setOnlyReadsMemory(F, 1);
853  return Changed;
854  case LibFunc_valloc:
856  Changed |= setRetAndArgsNoUndef(F);
857  Changed |= setDoesNotThrow(F);
858  Changed |= setRetDoesNotAlias(F);
859  Changed |= setWillReturn(F);
860  return Changed;
861  case LibFunc_vprintf:
862  Changed |= setRetAndArgsNoUndef(F);
863  Changed |= setDoesNotThrow(F);
864  Changed |= setDoesNotCapture(F, 0);
865  Changed |= setOnlyReadsMemory(F, 0);
866  return Changed;
867  case LibFunc_vfprintf:
868  case LibFunc_vsprintf:
869  Changed |= setRetAndArgsNoUndef(F);
870  Changed |= setDoesNotThrow(F);
871  Changed |= setDoesNotCapture(F, 0);
872  Changed |= setDoesNotCapture(F, 1);
873  Changed |= setOnlyReadsMemory(F, 1);
874  return Changed;
875  case LibFunc_vsnprintf:
876  Changed |= setRetAndArgsNoUndef(F);
877  Changed |= setDoesNotThrow(F);
878  Changed |= setDoesNotCapture(F, 0);
879  Changed |= setDoesNotCapture(F, 2);
880  Changed |= setOnlyReadsMemory(F, 2);
881  return Changed;
882  case LibFunc_open:
883  // May throw; "open" is a valid pthread cancellation point.
884  Changed |= setRetAndArgsNoUndef(F);
885  Changed |= setDoesNotCapture(F, 0);
886  Changed |= setOnlyReadsMemory(F, 0);
887  return Changed;
888  case LibFunc_opendir:
889  Changed |= setRetAndArgsNoUndef(F);
890  Changed |= setDoesNotThrow(F);
891  Changed |= setRetDoesNotAlias(F);
892  Changed |= setDoesNotCapture(F, 0);
893  Changed |= setOnlyReadsMemory(F, 0);
894  return Changed;
895  case LibFunc_tmpfile:
896  Changed |= setRetAndArgsNoUndef(F);
897  Changed |= setDoesNotThrow(F);
898  Changed |= setRetDoesNotAlias(F);
899  return Changed;
900  case LibFunc_times:
901  Changed |= setRetAndArgsNoUndef(F);
902  Changed |= setDoesNotThrow(F);
903  Changed |= setDoesNotCapture(F, 0);
904  return Changed;
905  case LibFunc_htonl:
906  case LibFunc_htons:
907  case LibFunc_ntohl:
908  case LibFunc_ntohs:
909  Changed |= setDoesNotThrow(F);
910  Changed |= setDoesNotAccessMemory(F);
911  return Changed;
912  case LibFunc_lstat:
913  Changed |= setRetAndArgsNoUndef(F);
914  Changed |= setDoesNotThrow(F);
915  Changed |= setDoesNotCapture(F, 0);
916  Changed |= setDoesNotCapture(F, 1);
917  Changed |= setOnlyReadsMemory(F, 0);
918  return Changed;
919  case LibFunc_lchown:
920  Changed |= setRetAndArgsNoUndef(F);
921  Changed |= setDoesNotThrow(F);
922  Changed |= setDoesNotCapture(F, 0);
923  Changed |= setOnlyReadsMemory(F, 0);
924  return Changed;
925  case LibFunc_qsort:
926  // May throw; places call through function pointer.
927  // Cannot give undef pointer/size
928  Changed |= setRetAndArgsNoUndef(F);
929  Changed |= setDoesNotCapture(F, 3);
930  return Changed;
931  case LibFunc_dunder_strndup:
932  Changed |= setArgNoUndef(F, 1);
934  case LibFunc_dunder_strdup:
935  Changed |= setDoesNotThrow(F);
936  Changed |= setRetDoesNotAlias(F);
937  Changed |= setWillReturn(F);
938  Changed |= setDoesNotCapture(F, 0);
939  Changed |= setOnlyReadsMemory(F, 0);
940  return Changed;
941  case LibFunc_dunder_strtok_r:
942  Changed |= setDoesNotThrow(F);
943  Changed |= setDoesNotCapture(F, 1);
944  Changed |= setOnlyReadsMemory(F, 1);
945  return Changed;
946  case LibFunc_under_IO_getc:
947  Changed |= setRetAndArgsNoUndef(F);
948  Changed |= setDoesNotThrow(F);
949  Changed |= setDoesNotCapture(F, 0);
950  return Changed;
951  case LibFunc_under_IO_putc:
952  Changed |= setRetAndArgsNoUndef(F);
953  Changed |= setDoesNotThrow(F);
954  Changed |= setDoesNotCapture(F, 1);
955  return Changed;
956  case LibFunc_dunder_isoc99_scanf:
957  Changed |= setRetAndArgsNoUndef(F);
958  Changed |= setDoesNotThrow(F);
959  Changed |= setDoesNotCapture(F, 0);
960  Changed |= setOnlyReadsMemory(F, 0);
961  return Changed;
962  case LibFunc_stat64:
963  case LibFunc_lstat64:
964  case LibFunc_statvfs64:
965  Changed |= setRetAndArgsNoUndef(F);
966  Changed |= setDoesNotThrow(F);
967  Changed |= setDoesNotCapture(F, 0);
968  Changed |= setDoesNotCapture(F, 1);
969  Changed |= setOnlyReadsMemory(F, 0);
970  return Changed;
971  case LibFunc_dunder_isoc99_sscanf:
972  Changed |= setRetAndArgsNoUndef(F);
973  Changed |= setDoesNotThrow(F);
974  Changed |= setDoesNotCapture(F, 0);
975  Changed |= setDoesNotCapture(F, 1);
976  Changed |= setOnlyReadsMemory(F, 0);
977  Changed |= setOnlyReadsMemory(F, 1);
978  return Changed;
979  case LibFunc_fopen64:
980  Changed |= setRetAndArgsNoUndef(F);
981  Changed |= setDoesNotThrow(F);
982  Changed |= setRetDoesNotAlias(F);
983  Changed |= setDoesNotCapture(F, 0);
984  Changed |= setDoesNotCapture(F, 1);
985  Changed |= setOnlyReadsMemory(F, 0);
986  Changed |= setOnlyReadsMemory(F, 1);
987  return Changed;
988  case LibFunc_fseeko64:
989  case LibFunc_ftello64:
990  Changed |= setRetAndArgsNoUndef(F);
991  Changed |= setDoesNotThrow(F);
992  Changed |= setDoesNotCapture(F, 0);
993  return Changed;
994  case LibFunc_tmpfile64:
995  Changed |= setRetAndArgsNoUndef(F);
996  Changed |= setDoesNotThrow(F);
997  Changed |= setRetDoesNotAlias(F);
998  return Changed;
999  case LibFunc_fstat64:
1000  case LibFunc_fstatvfs64:
1001  Changed |= setRetAndArgsNoUndef(F);
1002  Changed |= setDoesNotThrow(F);
1003  Changed |= setDoesNotCapture(F, 1);
1004  return Changed;
1005  case LibFunc_open64:
1006  // May throw; "open" is a valid pthread cancellation point.
1007  Changed |= setRetAndArgsNoUndef(F);
1008  Changed |= setDoesNotCapture(F, 0);
1009  Changed |= setOnlyReadsMemory(F, 0);
1010  return Changed;
1011  case LibFunc_gettimeofday:
1012  // Currently some platforms have the restrict keyword on the arguments to
1013  // gettimeofday. To be conservative, do not add noalias to gettimeofday's
1014  // arguments.
1015  Changed |= setRetAndArgsNoUndef(F);
1016  Changed |= setDoesNotThrow(F);
1017  Changed |= setDoesNotCapture(F, 0);
1018  Changed |= setDoesNotCapture(F, 1);
1019  return Changed;
1020  // TODO: add LibFunc entries for:
1021  // case LibFunc_memset_pattern4:
1022  // case LibFunc_memset_pattern8:
1023  case LibFunc_memset_pattern16:
1024  Changed |= setOnlyAccessesArgMemory(F);
1025  Changed |= setDoesNotCapture(F, 0);
1026  Changed |= setOnlyWritesMemory(F, 0);
1027  Changed |= setDoesNotCapture(F, 1);
1028  Changed |= setOnlyReadsMemory(F, 1);
1029  return Changed;
1030  case LibFunc_memset:
1031  Changed |= setOnlyAccessesArgMemory(F);
1032  Changed |= setWillReturn(F);
1033  Changed |= setDoesNotThrow(F);
1034  Changed |= setOnlyWritesMemory(F, 0);
1035  return Changed;
1036  // int __nvvm_reflect(const char *)
1037  case LibFunc_nvvm_reflect:
1038  Changed |= setRetAndArgsNoUndef(F);
1039  Changed |= setDoesNotAccessMemory(F);
1040  Changed |= setDoesNotThrow(F);
1041  return Changed;
1042  case LibFunc_ldexp:
1043  case LibFunc_ldexpf:
1044  case LibFunc_ldexpl:
1045  Changed |= setSignExtendedArg(F, 1);
1046  Changed |= setWillReturn(F);
1047  return Changed;
1048  case LibFunc_abs:
1049  case LibFunc_acos:
1050  case LibFunc_acosf:
1051  case LibFunc_acosh:
1052  case LibFunc_acoshf:
1053  case LibFunc_acoshl:
1054  case LibFunc_acosl:
1055  case LibFunc_asin:
1056  case LibFunc_asinf:
1057  case LibFunc_asinh:
1058  case LibFunc_asinhf:
1059  case LibFunc_asinhl:
1060  case LibFunc_asinl:
1061  case LibFunc_atan:
1062  case LibFunc_atan2:
1063  case LibFunc_atan2f:
1064  case LibFunc_atan2l:
1065  case LibFunc_atanf:
1066  case LibFunc_atanh:
1067  case LibFunc_atanhf:
1068  case LibFunc_atanhl:
1069  case LibFunc_atanl:
1070  case LibFunc_cbrt:
1071  case LibFunc_cbrtf:
1072  case LibFunc_cbrtl:
1073  case LibFunc_ceil:
1074  case LibFunc_ceilf:
1075  case LibFunc_ceill:
1076  case LibFunc_copysign:
1077  case LibFunc_copysignf:
1078  case LibFunc_copysignl:
1079  case LibFunc_cos:
1080  case LibFunc_cosh:
1081  case LibFunc_coshf:
1082  case LibFunc_coshl:
1083  case LibFunc_cosf:
1084  case LibFunc_cosl:
1085  case LibFunc_cospi:
1086  case LibFunc_cospif:
1087  case LibFunc_exp:
1088  case LibFunc_expf:
1089  case LibFunc_expl:
1090  case LibFunc_exp2:
1091  case LibFunc_exp2f:
1092  case LibFunc_exp2l:
1093  case LibFunc_expm1:
1094  case LibFunc_expm1f:
1095  case LibFunc_expm1l:
1096  case LibFunc_fabs:
1097  case LibFunc_fabsf:
1098  case LibFunc_fabsl:
1099  case LibFunc_ffs:
1100  case LibFunc_ffsl:
1101  case LibFunc_ffsll:
1102  case LibFunc_floor:
1103  case LibFunc_floorf:
1104  case LibFunc_floorl:
1105  case LibFunc_fls:
1106  case LibFunc_flsl:
1107  case LibFunc_flsll:
1108  case LibFunc_fmax:
1109  case LibFunc_fmaxf:
1110  case LibFunc_fmaxl:
1111  case LibFunc_fmin:
1112  case LibFunc_fminf:
1113  case LibFunc_fminl:
1114  case LibFunc_fmod:
1115  case LibFunc_fmodf:
1116  case LibFunc_fmodl:
1117  case LibFunc_isascii:
1118  case LibFunc_isdigit:
1119  case LibFunc_labs:
1120  case LibFunc_llabs:
1121  case LibFunc_log:
1122  case LibFunc_log10:
1123  case LibFunc_log10f:
1124  case LibFunc_log10l:
1125  case LibFunc_log1p:
1126  case LibFunc_log1pf:
1127  case LibFunc_log1pl:
1128  case LibFunc_log2:
1129  case LibFunc_log2f:
1130  case LibFunc_log2l:
1131  case LibFunc_logb:
1132  case LibFunc_logbf:
1133  case LibFunc_logbl:
1134  case LibFunc_logf:
1135  case LibFunc_logl:
1136  case LibFunc_nearbyint:
1137  case LibFunc_nearbyintf:
1138  case LibFunc_nearbyintl:
1139  case LibFunc_pow:
1140  case LibFunc_powf:
1141  case LibFunc_powl:
1142  case LibFunc_rint:
1143  case LibFunc_rintf:
1144  case LibFunc_rintl:
1145  case LibFunc_round:
1146  case LibFunc_roundf:
1147  case LibFunc_roundl:
1148  case LibFunc_sin:
1149  case LibFunc_sincospif_stret:
1150  case LibFunc_sinf:
1151  case LibFunc_sinh:
1152  case LibFunc_sinhf:
1153  case LibFunc_sinhl:
1154  case LibFunc_sinl:
1155  case LibFunc_sinpi:
1156  case LibFunc_sinpif:
1157  case LibFunc_sqrt:
1158  case LibFunc_sqrtf:
1159  case LibFunc_sqrtl:
1160  case LibFunc_strnlen:
1161  case LibFunc_tan:
1162  case LibFunc_tanf:
1163  case LibFunc_tanh:
1164  case LibFunc_tanhf:
1165  case LibFunc_tanhl:
1166  case LibFunc_tanl:
1167  case LibFunc_toascii:
1168  case LibFunc_trunc:
1169  case LibFunc_truncf:
1170  case LibFunc_truncl:
1171  Changed |= setDoesNotThrow(F);
1172  Changed |= setDoesNotFreeMemory(F);
1173  Changed |= setWillReturn(F);
1174  return Changed;
1175  default:
1176  // FIXME: It'd be really nice to cover all the library functions we're
1177  // aware of here.
1178  return false;
1179  }
1180 }
1181 
1183  LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
1184  switch (Ty->getTypeID()) {
1185  case Type::HalfTyID:
1186  return false;
1187  case Type::FloatTyID:
1188  return TLI->has(FloatFn);
1189  case Type::DoubleTyID:
1190  return TLI->has(DoubleFn);
1191  default:
1192  return TLI->has(LongDoubleFn);
1193  }
1194 }
1195 
1197  LibFunc DoubleFn, LibFunc FloatFn,
1198  LibFunc LongDoubleFn) {
1199  assert(hasFloatFn(TLI, Ty, DoubleFn, FloatFn, LongDoubleFn) &&
1200  "Cannot get name for unavailable function!");
1201 
1202  switch (Ty->getTypeID()) {
1203  case Type::HalfTyID:
1204  llvm_unreachable("No name for HalfTy!");
1205  case Type::FloatTyID:
1206  return TLI->getName(FloatFn);
1207  case Type::DoubleTyID:
1208  return TLI->getName(DoubleFn);
1209  default:
1210  return TLI->getName(LongDoubleFn);
1211  }
1212 }
1213 
1214 //- Emit LibCalls ------------------------------------------------------------//
1215 
1217  unsigned AS = V->getType()->getPointerAddressSpace();
1218  return B.CreateBitCast(V, B.getInt8PtrTy(AS), "cstr");
1219 }
1220 
1221 static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
1222  ArrayRef<Type *> ParamTypes,
1224  const TargetLibraryInfo *TLI,
1225  bool IsVaArgs = false) {
1226  if (!TLI->has(TheLibFunc))
1227  return nullptr;
1228 
1229  Module *M = B.GetInsertBlock()->getModule();
1230  StringRef FuncName = TLI->getName(TheLibFunc);
1231  FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
1232  FunctionCallee Callee = M->getOrInsertFunction(FuncName, FuncType);
1233  inferLibFuncAttributes(M, FuncName, *TLI);
1234  CallInst *CI = B.CreateCall(Callee, Operands, FuncName);
1235  if (const Function *F =
1236  dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1237  CI->setCallingConv(F->getCallingConv());
1238  return CI;
1239 }
1240 
1242  const TargetLibraryInfo *TLI) {
1243  LLVMContext &Context = B.GetInsertBlock()->getContext();
1244  return emitLibCall(LibFunc_strlen, DL.getIntPtrType(Context),
1245  B.getInt8PtrTy(), castToCStr(Ptr, B), B, TLI);
1246 }
1247 
1249  const TargetLibraryInfo *TLI) {
1250  return emitLibCall(LibFunc_strdup, B.getInt8PtrTy(), B.getInt8PtrTy(),
1251  castToCStr(Ptr, B), B, TLI);
1252 }
1253 
1255  const TargetLibraryInfo *TLI) {
1256  Type *I8Ptr = B.getInt8PtrTy();
1257  Type *I32Ty = B.getInt32Ty();
1258  return emitLibCall(LibFunc_strchr, I8Ptr, {I8Ptr, I32Ty},
1259  {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, B, TLI);
1260 }
1261 
1263  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1264  LLVMContext &Context = B.GetInsertBlock()->getContext();
1265  return emitLibCall(
1266  LibFunc_strncmp, B.getInt32Ty(),
1267  {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
1268  {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
1269 }
1270 
1272  const TargetLibraryInfo *TLI) {
1273  Type *I8Ptr = B.getInt8PtrTy();
1274  return emitLibCall(LibFunc_strcpy, I8Ptr, {I8Ptr, I8Ptr},
1275  {castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI);
1276 }
1277 
1279  const TargetLibraryInfo *TLI) {
1280  Type *I8Ptr = B.getInt8PtrTy();
1281  return emitLibCall(LibFunc_stpcpy, I8Ptr, {I8Ptr, I8Ptr},
1282  {castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI);
1283 }
1284 
1286  const TargetLibraryInfo *TLI) {
1287  Type *I8Ptr = B.getInt8PtrTy();
1288  return emitLibCall(LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType()},
1289  {castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
1290 }
1291 
1293  const TargetLibraryInfo *TLI) {
1294  Type *I8Ptr = B.getInt8PtrTy();
1295  return emitLibCall(LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType()},
1296  {castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
1297 }
1298 
1299 Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
1300  IRBuilderBase &B, const DataLayout &DL,
1301  const TargetLibraryInfo *TLI) {
1302  if (!TLI->has(LibFunc_memcpy_chk))
1303  return nullptr;
1304 
1305  Module *M = B.GetInsertBlock()->getModule();
1306  AttributeList AS;
1308  Attribute::NoUnwind);
1309  LLVMContext &Context = B.GetInsertBlock()->getContext();
1310  FunctionCallee MemCpy = M->getOrInsertFunction(
1311  "__memcpy_chk", AttributeList::get(M->getContext(), AS), B.getInt8PtrTy(),
1312  B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context),
1313  DL.getIntPtrType(Context));
1314  Dst = castToCStr(Dst, B);
1315  Src = castToCStr(Src, B);
1316  CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
1317  if (const Function *F =
1318  dyn_cast<Function>(MemCpy.getCallee()->stripPointerCasts()))
1319  CI->setCallingConv(F->getCallingConv());
1320  return CI;
1321 }
1322 
1324  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1325  LLVMContext &Context = B.GetInsertBlock()->getContext();
1326  return emitLibCall(
1327  LibFunc_mempcpy, B.getInt8PtrTy(),
1328  {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
1329  {Dst, Src, Len}, B, TLI);
1330 }
1331 
1333  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1334  LLVMContext &Context = B.GetInsertBlock()->getContext();
1335  return emitLibCall(
1336  LibFunc_memchr, B.getInt8PtrTy(),
1337  {B.getInt8PtrTy(), B.getInt32Ty(), DL.getIntPtrType(Context)},
1338  {castToCStr(Ptr, B), Val, Len}, B, TLI);
1339 }
1340 
1342  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1343  LLVMContext &Context = B.GetInsertBlock()->getContext();
1344  return emitLibCall(
1345  LibFunc_memcmp, B.getInt32Ty(),
1346  {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
1347  {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
1348 }
1349 
1351  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1352  LLVMContext &Context = B.GetInsertBlock()->getContext();
1353  return emitLibCall(
1354  LibFunc_bcmp, B.getInt32Ty(),
1355  {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
1356  {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
1357 }
1358 
1359 Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
1360  IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1361  return emitLibCall(
1362  LibFunc_memccpy, B.getInt8PtrTy(),
1363  {B.getInt8PtrTy(), B.getInt8PtrTy(), B.getInt32Ty(), Len->getType()},
1364  {Ptr1, Ptr2, Val, Len}, B, TLI);
1365 }
1366 
1368  ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1369  const TargetLibraryInfo *TLI) {
1371  llvm::append_range(Args, VariadicArgs);
1372  return emitLibCall(LibFunc_snprintf, B.getInt32Ty(),
1373  {B.getInt8PtrTy(), Size->getType(), B.getInt8PtrTy()},
1374  Args, B, TLI, /*IsVaArgs=*/true);
1375 }
1376 
1378  ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
1379  const TargetLibraryInfo *TLI) {
1381  llvm::append_range(Args, VariadicArgs);
1382  return emitLibCall(LibFunc_sprintf, B.getInt32Ty(),
1383  {B.getInt8PtrTy(), B.getInt8PtrTy()}, Args, B, TLI,
1384  /*IsVaArgs=*/true);
1385 }
1386 
1388  const TargetLibraryInfo *TLI) {
1389  return emitLibCall(LibFunc_strcat, B.getInt8PtrTy(),
1390  {B.getInt8PtrTy(), B.getInt8PtrTy()},
1391  {castToCStr(Dest, B), castToCStr(Src, B)}, B, TLI);
1392 }
1393 
1395  const TargetLibraryInfo *TLI) {
1396  return emitLibCall(LibFunc_strlcpy, Size->getType(),
1397  {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
1398  {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
1399 }
1400 
1402  const TargetLibraryInfo *TLI) {
1403  return emitLibCall(LibFunc_strlcat, Size->getType(),
1404  {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
1405  {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
1406 }
1407 
1409  const TargetLibraryInfo *TLI) {
1410  return emitLibCall(LibFunc_strncat, B.getInt8PtrTy(),
1411  {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
1412  {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
1413 }
1414 
1416  IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1417  return emitLibCall(
1418  LibFunc_vsnprintf, B.getInt32Ty(),
1419  {B.getInt8PtrTy(), Size->getType(), B.getInt8PtrTy(), VAList->getType()},
1420  {castToCStr(Dest, B), Size, castToCStr(Fmt, B), VAList}, B, TLI);
1421 }
1422 
1423 Value *llvm::emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList,
1424  IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1425  return emitLibCall(LibFunc_vsprintf, B.getInt32Ty(),
1426  {B.getInt8PtrTy(), B.getInt8PtrTy(), VAList->getType()},
1427  {castToCStr(Dest, B), castToCStr(Fmt, B), VAList}, B, TLI);
1428 }
1429 
1430 /// Append a suffix to the function name according to the type of 'Op'.
1432  SmallString<20> &NameBuffer) {
1433  if (!Op->getType()->isDoubleTy()) {
1434  NameBuffer += Name;
1435 
1436  if (Op->getType()->isFloatTy())
1437  NameBuffer += 'f';
1438  else
1439  NameBuffer += 'l';
1440 
1441  Name = NameBuffer;
1442  }
1443 }
1444 
1446  IRBuilderBase &B,
1447  const AttributeList &Attrs) {
1448  assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
1449 
1450  Module *M = B.GetInsertBlock()->getModule();
1452  M->getOrInsertFunction(Name, Op->getType(), Op->getType());
1453  CallInst *CI = B.CreateCall(Callee, Op, Name);
1454 
1455  // The incoming attribute set may have come from a speculatable intrinsic, but
1456  // is being replaced with a library call which is not allowed to be
1457  // speculatable.
1458  CI->setAttributes(Attrs.removeAttribute(B.getContext(),
1460  Attribute::Speculatable));
1461  if (const Function *F =
1462  dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1463  CI->setCallingConv(F->getCallingConv());
1464 
1465  return CI;
1466 }
1467 
1469  const AttributeList &Attrs) {
1470  SmallString<20> NameBuffer;
1471  appendTypeSuffix(Op, Name, NameBuffer);
1472 
1474 }
1475 
1477  LibFunc DoubleFn, LibFunc FloatFn,
1478  LibFunc LongDoubleFn, IRBuilderBase &B,
1479  const AttributeList &Attrs) {
1480  // Get the name of the function according to TLI.
1481  StringRef Name = getFloatFnName(TLI, Op->getType(),
1482  DoubleFn, FloatFn, LongDoubleFn);
1483 
1485 }
1486 
1489  const AttributeList &Attrs,
1490  const TargetLibraryInfo *TLI = nullptr) {
1491  assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1492 
1493  Module *M = B.GetInsertBlock()->getModule();
1494  FunctionCallee Callee = M->getOrInsertFunction(Name, Op1->getType(),
1495  Op1->getType(), Op2->getType());
1496  if (TLI != nullptr)
1497  inferLibFuncAttributes(M, Name, *TLI);
1498  CallInst *CI = B.CreateCall(Callee, { Op1, Op2 }, Name);
1499 
1500  // The incoming attribute set may have come from a speculatable intrinsic, but
1501  // is being replaced with a library call which is not allowed to be
1502  // speculatable.
1503  CI->setAttributes(Attrs.removeAttribute(B.getContext(),
1505  Attribute::Speculatable));
1506  if (const Function *F =
1507  dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1508  CI->setCallingConv(F->getCallingConv());
1509 
1510  return CI;
1511 }
1512 
1514  IRBuilderBase &B,
1515  const AttributeList &Attrs) {
1516  assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1517 
1518  SmallString<20> NameBuffer;
1519  appendTypeSuffix(Op1, Name, NameBuffer);
1520 
1521  return emitBinaryFloatFnCallHelper(Op1, Op2, Name, B, Attrs);
1522 }
1523 
1525  const TargetLibraryInfo *TLI,
1526  LibFunc DoubleFn, LibFunc FloatFn,
1527  LibFunc LongDoubleFn, IRBuilderBase &B,
1528  const AttributeList &Attrs) {
1529  // Get the name of the function according to TLI.
1530  StringRef Name = getFloatFnName(TLI, Op1->getType(),
1531  DoubleFn, FloatFn, LongDoubleFn);
1532 
1533  return emitBinaryFloatFnCallHelper(Op1, Op2, Name, B, Attrs, TLI);
1534 }
1535 
1537  const TargetLibraryInfo *TLI) {
1538  if (!TLI->has(LibFunc_putchar))
1539  return nullptr;
1540 
1541  Module *M = B.GetInsertBlock()->getModule();
1542  StringRef PutCharName = TLI->getName(LibFunc_putchar);
1543  FunctionCallee PutChar =
1544  M->getOrInsertFunction(PutCharName, B.getInt32Ty(), B.getInt32Ty());
1545  inferLibFuncAttributes(M, PutCharName, *TLI);
1546  CallInst *CI = B.CreateCall(PutChar,
1547  B.CreateIntCast(Char,
1548  B.getInt32Ty(),
1549  /*isSigned*/true,
1550  "chari"),
1551  PutCharName);
1552 
1553  if (const Function *F =
1554  dyn_cast<Function>(PutChar.getCallee()->stripPointerCasts()))
1555  CI->setCallingConv(F->getCallingConv());
1556  return CI;
1557 }
1558 
1560  const TargetLibraryInfo *TLI) {
1561  if (!TLI->has(LibFunc_puts))
1562  return nullptr;
1563 
1564  Module *M = B.GetInsertBlock()->getModule();
1565  StringRef PutsName = TLI->getName(LibFunc_puts);
1566  FunctionCallee PutS =
1567  M->getOrInsertFunction(PutsName, B.getInt32Ty(), B.getInt8PtrTy());
1568  inferLibFuncAttributes(M, PutsName, *TLI);
1569  CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), PutsName);
1570  if (const Function *F =
1571  dyn_cast<Function>(PutS.getCallee()->stripPointerCasts()))
1572  CI->setCallingConv(F->getCallingConv());
1573  return CI;
1574 }
1575 
1577  const TargetLibraryInfo *TLI) {
1578  if (!TLI->has(LibFunc_fputc))
1579  return nullptr;
1580 
1581  Module *M = B.GetInsertBlock()->getModule();
1582  StringRef FPutcName = TLI->getName(LibFunc_fputc);
1583  FunctionCallee F = M->getOrInsertFunction(FPutcName, B.getInt32Ty(),
1584  B.getInt32Ty(), File->getType());
1585  if (File->getType()->isPointerTy())
1586  inferLibFuncAttributes(M, FPutcName, *TLI);
1587  Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
1588  "chari");
1589  CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName);
1590 
1591  if (const Function *Fn =
1592  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1593  CI->setCallingConv(Fn->getCallingConv());
1594  return CI;
1595 }
1596 
1598  const TargetLibraryInfo *TLI) {
1599  if (!TLI->has(LibFunc_fputs))
1600  return nullptr;
1601 
1602  Module *M = B.GetInsertBlock()->getModule();
1603  StringRef FPutsName = TLI->getName(LibFunc_fputs);
1604  FunctionCallee F = M->getOrInsertFunction(FPutsName, B.getInt32Ty(),
1605  B.getInt8PtrTy(), File->getType());
1606  if (File->getType()->isPointerTy())
1607  inferLibFuncAttributes(M, FPutsName, *TLI);
1608  CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsName);
1609 
1610  if (const Function *Fn =
1611  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1612  CI->setCallingConv(Fn->getCallingConv());
1613  return CI;
1614 }
1615 
1617  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1618  if (!TLI->has(LibFunc_fwrite))
1619  return nullptr;
1620 
1621  Module *M = B.GetInsertBlock()->getModule();
1622  LLVMContext &Context = B.GetInsertBlock()->getContext();
1623  StringRef FWriteName = TLI->getName(LibFunc_fwrite);
1624  FunctionCallee F = M->getOrInsertFunction(
1625  FWriteName, DL.getIntPtrType(Context), B.getInt8PtrTy(),
1626  DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
1627 
1628  if (File->getType()->isPointerTy())
1629  inferLibFuncAttributes(M, FWriteName, *TLI);
1630  CallInst *CI =
1631  B.CreateCall(F, {castToCStr(Ptr, B), Size,
1632  ConstantInt::get(DL.getIntPtrType(Context), 1), File});
1633 
1634  if (const Function *Fn =
1635  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1636  CI->setCallingConv(Fn->getCallingConv());
1637  return CI;
1638 }
1639 
1641  const TargetLibraryInfo *TLI) {
1642  if (!TLI->has(LibFunc_malloc))
1643  return nullptr;
1644 
1645  Module *M = B.GetInsertBlock()->getModule();
1646  StringRef MallocName = TLI->getName(LibFunc_malloc);
1647  LLVMContext &Context = B.GetInsertBlock()->getContext();
1648  FunctionCallee Malloc = M->getOrInsertFunction(MallocName, B.getInt8PtrTy(),
1649  DL.getIntPtrType(Context));
1650  inferLibFuncAttributes(M, MallocName, *TLI);
1651  CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
1652 
1653  if (const Function *F =
1654  dyn_cast<Function>(Malloc.getCallee()->stripPointerCasts()))
1655  CI->setCallingConv(F->getCallingConv());
1656 
1657  return CI;
1658 }
1659 
1661  IRBuilderBase &B, const TargetLibraryInfo &TLI) {
1662  if (!TLI.has(LibFunc_calloc))
1663  return nullptr;
1664 
1665  Module *M = B.GetInsertBlock()->getModule();
1666  StringRef CallocName = TLI.getName(LibFunc_calloc);
1667  const DataLayout &DL = M->getDataLayout();
1668  IntegerType *PtrType = DL.getIntPtrType((B.GetInsertBlock()->getContext()));
1669  FunctionCallee Calloc = M->getOrInsertFunction(
1670  CallocName, Attrs, B.getInt8PtrTy(), PtrType, PtrType);
1671  inferLibFuncAttributes(M, CallocName, TLI);
1672  CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
1673 
1674  if (const auto *F =
1675  dyn_cast<Function>(Calloc.getCallee()->stripPointerCasts()))
1676  CI->setCallingConv(F->getCallingConv());
1677 
1678  return CI;
1679 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
setSignExtendedArg
static bool setSignExtendedArg(Function &F, unsigned ArgNo)
Definition: BuildLibCalls.cpp:139
llvm::getFloatFnName
StringRef getFloatFnName(const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Get the name of the overloaded floating point function corresponding to Ty.
Definition: BuildLibCalls.cpp:1196
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm::Type::FloatTyID
@ FloatTyID
32-bit floating point type
Definition: Type.h:59
llvm::Type::DoubleTyID
@ DoubleTyID
64-bit floating point type
Definition: Type.h:60
llvm
Definition: AllocatorList.h:23
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:112
llvm::Function
Definition: Function.h:61
llvm::SmallVector< Value *, 8 >
Statistic.h
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:1341
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:1616
llvm::Type::getPointerAddressSpace
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:693
setOnlyAccessesArgMemory
static bool setOnlyAccessesArgMemory(Function &F)
Definition: BuildLibCalls.cpp:75
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:1431
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:1359
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:328
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:1203
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:107
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
Module.h
setOnlyReadsMemory
static bool setOnlyReadsMemory(Function &F)
Definition: BuildLibCalls.cpp:67
setArgNoUndef
static bool setArgNoUndef(Function &F, unsigned ArgNo)
Definition: BuildLibCalls.cpp:169
MemoryBuiltins.h
llvm::AttributeList
Definition: Attributes.h:385
llvm::emitCalloc
Value * emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs, IRBuilderBase &B, const TargetLibraryInfo &TLI)
Emit a call to the calloc function.
Definition: BuildLibCalls.cpp:1660
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:1221
F
#define F(x, y, z)
Definition: MD5.cpp:56
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
setWillReturn
static bool setWillReturn(Function &F)
Definition: BuildLibCalls.cpp:203
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:1248
llvm::emitFPutC
Value * emitFPutC(Value *Char, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
Definition: BuildLibCalls.cpp:1576
Constants.h
SmallString.h
setRetNoUndef
static bool setRetNoUndef(Function &F)
Definition: BuildLibCalls.cpp:147
llvm::LibFunc
LibFunc
Definition: TargetLibraryInfo.h:34
Intrinsics.h
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:1476
llvm::emitStrCat
Value * emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcat function.
Definition: BuildLibCalls.cpp:1387
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:1394
TargetLibraryInfo.h
emitBinaryFloatFnCallHelper
static Value * emitBinaryFloatFnCallHelper(Value *Op1, Value *Op2, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs, const TargetLibraryInfo *TLI=nullptr)
Definition: BuildLibCalls.cpp:1487
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:277
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:1536
emitUnaryFloatFnCallHelper
static Value * emitUnaryFloatFnCallHelper(Value *Op, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Definition: BuildLibCalls.cpp:1445
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:885
llvm::isReallocLikeFn
bool isReallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that reallocates memory (e....
Definition: MemoryBuiltins.cpp:312
llvm::TargetLibraryInfo::getName
StringRef getName(LibFunc F) const
Definition: TargetLibraryInfo.h:357
llvm::emitBinaryFloatFnCall
Value * emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the binary function named 'Name' (e.g.
Definition: BuildLibCalls.cpp:1513
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:1262
Type.h
llvm::SmallString
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:25
Operands
mir Rename Register Operands
Definition: MIRNamerPass.cpp:78
setOnlyWritesMemory
static bool setOnlyWritesMemory(Function &F, unsigned ArgNo)
Definition: BuildLibCalls.cpp:131
setDoesNotAlias
static bool setDoesNotAlias(Function &F, unsigned ArgNo)
Definition: BuildLibCalls.cpp:115
llvm::AttributeList::ReturnIndex
@ ReturnIndex
Definition: Attributes.h:388
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:1377
llvm::Function::removeAttribute
void removeAttribute(unsigned i, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
Definition: Function.cpp:540
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:1299
setReturnedArg
static bool setReturnedArg(Function &F, unsigned ArgNo)
Definition: BuildLibCalls.cpp:181
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:1401
setOnlyAccessesInaccessibleMemory
static bool setOnlyAccessesInaccessibleMemory(Function &F)
Definition: BuildLibCalls.cpp:59
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:1350
IRBuilder.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
setArgsNoUndef
static bool setArgsNoUndef(Function &F)
Definition: BuildLibCalls.cpp:157
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:1323
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:1292
llvm::TargetLibraryInfo::has
bool has(LibFunc F) const
Tests whether a library function is available.
Definition: TargetLibraryInfo.h:311
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:1408
setDoesNotFreeMemory
static bool setDoesNotFreeMemory(Function &F)
Definition: BuildLibCalls.cpp:196
setRetAndArgsNoUndef
static bool setRetAndArgsNoUndef(Function &F)
Definition: BuildLibCalls.cpp:177
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::ARM::WinEH::ReturnType
ReturnType
Definition: ARMWinEH.h:25
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:33
setOnlyAccessesInaccessibleMemOrArgMem
static bool setOnlyAccessesInaccessibleMemOrArgMem(Function &F)
Definition: BuildLibCalls.cpp:83
DataLayout.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:1690
llvm::IRBuilderBase
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:95
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:1278
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:1241
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:1271
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:281
llvm::emitUnaryFloatFnCall
Value * emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
Definition: BuildLibCalls.cpp:1468
setRetDoesNotAlias
static bool setRetDoesNotAlias(Function &F)
Definition: BuildLibCalls.cpp:99
llvm::Value::stripPointerCasts
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:636
llvm::FunctionCallee::getCallee
Value * getCallee()
Definition: DerivedTypes.h:183
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:205
llvm::hasFloatFn
bool hasFloatFn(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:1182
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:314
Function.h
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:207
llvm::emitFPutS
Value * emitFPutS(Value *Str, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
Definition: BuildLibCalls.cpp:1597
llvm::orc::ReadOnly
static constexpr sys::Memory::ProtectionFlags ReadOnly
Definition: DebugObjectManagerPlugin.cpp:111
llvm::emitMalloc
Value * emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
Definition: BuildLibCalls.cpp:1640
llvm::castToCStr
Value * castToCStr(Value *V, IRBuilderBase &B)
Return V if it is an i8*, otherwise cast it to i8*.
Definition: BuildLibCalls.cpp:1216
setDoesNotThrow
static bool setDoesNotThrow(Function &F)
Definition: BuildLibCalls.cpp:91
llvm::AttributeList::FunctionIndex
@ FunctionIndex
Definition: Attributes.h:389
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:1285
llvm::inferLibFuncAttributes
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
Definition: BuildLibCalls.cpp:219
llvm::FunctionCallee
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:164
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:1367
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:1559
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:1254
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1450
LLVMContext.h
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
llvm::isLibFreeFunction
bool isLibFreeFunction(const Function *F, const LibFunc TLIFn)
isLibFreeFunction - Returns true if the function is a builtin free()
Definition: MemoryBuiltins.cpp:433
setNonLazyBind
static bool setNonLazyBind(Function &F)
Definition: BuildLibCalls.cpp:189
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:1423
BuildLibCalls.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
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:1415
llvm::Type::HalfTyID
@ HalfTyID
16-bit floating point type
Definition: Type.h:57
File
Instrumentation for Order File
Definition: InstrOrderFile.cpp:206
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:1332
llvm::CallBase::setCallingConv
void setCallingConv(CallingConv::ID CC)
Definition: InstrTypes.h:1457
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:102