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