LLVM  6.0.0svn
BuildLibCalls.cpp
Go to the documentation of this file.
1 //===- BuildLibCalls.cpp - Utility builder for libcalls -------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements some functions that will create standard C libcalls.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/ADT/Statistic.h"
18 #include "llvm/IR/Constants.h"
19 #include "llvm/IR/DataLayout.h"
20 #include "llvm/IR/Function.h"
21 #include "llvm/IR/IRBuilder.h"
22 #include "llvm/IR/Intrinsics.h"
23 #include "llvm/IR/LLVMContext.h"
24 #include "llvm/IR/Module.h"
25 #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(NumReadOnly, "Number of functions inferred as readonly");
35 STATISTIC(NumArgMemOnly, "Number of functions inferred as argmemonly");
36 STATISTIC(NumNoUnwind, "Number of functions inferred as nounwind");
37 STATISTIC(NumNoCapture, "Number of arguments inferred as nocapture");
38 STATISTIC(NumReadOnlyArg, "Number of arguments inferred as readonly");
39 STATISTIC(NumNoAlias, "Number of function returns inferred as noalias");
40 STATISTIC(NumNonNull, "Number of function returns inferred as nonnull returns");
41 
43  if (F.doesNotAccessMemory())
44  return false;
46  ++NumReadNone;
47  return true;
48 }
49 
50 static bool setOnlyReadsMemory(Function &F) {
51  if (F.onlyReadsMemory())
52  return false;
54  ++NumReadOnly;
55  return true;
56 }
57 
59  if (F.onlyAccessesArgMemory())
60  return false;
62  ++NumArgMemOnly;
63  return true;
64 }
65 
66 static bool setDoesNotThrow(Function &F) {
67  if (F.doesNotThrow())
68  return false;
69  F.setDoesNotThrow();
70  ++NumNoUnwind;
71  return true;
72 }
73 
74 static bool setRetDoesNotAlias(Function &F) {
76  return false;
78  ++NumNoAlias;
79  return true;
80 }
81 
82 static bool setDoesNotCapture(Function &F, unsigned ArgNo) {
83  if (F.hasParamAttribute(ArgNo, Attribute::NoCapture))
84  return false;
85  F.addParamAttr(ArgNo, Attribute::NoCapture);
86  ++NumNoCapture;
87  return true;
88 }
89 
90 static bool setOnlyReadsMemory(Function &F, unsigned ArgNo) {
91  if (F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
92  return false;
93  F.addParamAttr(ArgNo, Attribute::ReadOnly);
94  ++NumReadOnlyArg;
95  return true;
96 }
97 
98 static bool setRetNonNull(Function &F) {
100  "nonnull applies only to pointers");
101  if (F.hasAttribute(AttributeList::ReturnIndex, Attribute::NonNull))
102  return false;
103  F.addAttribute(AttributeList::ReturnIndex, Attribute::NonNull);
104  ++NumNonNull;
105  return true;
106 }
107 
109  LibFunc TheLibFunc;
110  if (!(TLI.getLibFunc(F, TheLibFunc) && TLI.has(TheLibFunc)))
111  return false;
112 
113  bool Changed = false;
114  switch (TheLibFunc) {
115  case LibFunc_strlen:
116  case LibFunc_wcslen:
117  Changed |= setOnlyReadsMemory(F);
118  Changed |= setDoesNotThrow(F);
119  Changed |= setOnlyAccessesArgMemory(F);
120  Changed |= setDoesNotCapture(F, 0);
121  return Changed;
122  case LibFunc_strchr:
123  case LibFunc_strrchr:
124  Changed |= setOnlyReadsMemory(F);
125  Changed |= setDoesNotThrow(F);
126  return Changed;
127  case LibFunc_strtol:
128  case LibFunc_strtod:
129  case LibFunc_strtof:
130  case LibFunc_strtoul:
131  case LibFunc_strtoll:
132  case LibFunc_strtold:
133  case LibFunc_strtoull:
134  Changed |= setDoesNotThrow(F);
135  Changed |= setDoesNotCapture(F, 1);
136  Changed |= setOnlyReadsMemory(F, 0);
137  return Changed;
138  case LibFunc_strcpy:
139  case LibFunc_stpcpy:
140  case LibFunc_strcat:
141  case LibFunc_strncat:
142  case LibFunc_strncpy:
143  case LibFunc_stpncpy:
144  Changed |= setDoesNotThrow(F);
145  Changed |= setDoesNotCapture(F, 1);
146  Changed |= setOnlyReadsMemory(F, 1);
147  return Changed;
148  case LibFunc_strxfrm:
149  Changed |= setDoesNotThrow(F);
150  Changed |= setDoesNotCapture(F, 0);
151  Changed |= setDoesNotCapture(F, 1);
152  Changed |= setOnlyReadsMemory(F, 1);
153  return Changed;
154  case LibFunc_strcmp: // 0,1
155  case LibFunc_strspn: // 0,1
156  case LibFunc_strncmp: // 0,1
157  case LibFunc_strcspn: // 0,1
158  case LibFunc_strcoll: // 0,1
159  case LibFunc_strcasecmp: // 0,1
160  case LibFunc_strncasecmp: //
161  Changed |= setOnlyReadsMemory(F);
162  Changed |= setDoesNotThrow(F);
163  Changed |= setDoesNotCapture(F, 0);
164  Changed |= setDoesNotCapture(F, 1);
165  return Changed;
166  case LibFunc_strstr:
167  case LibFunc_strpbrk:
168  Changed |= setOnlyReadsMemory(F);
169  Changed |= setDoesNotThrow(F);
170  Changed |= setDoesNotCapture(F, 1);
171  return Changed;
172  case LibFunc_strtok:
173  case LibFunc_strtok_r:
174  Changed |= setDoesNotThrow(F);
175  Changed |= setDoesNotCapture(F, 1);
176  Changed |= setOnlyReadsMemory(F, 1);
177  return Changed;
178  case LibFunc_scanf:
179  Changed |= setDoesNotThrow(F);
180  Changed |= setDoesNotCapture(F, 0);
181  Changed |= setOnlyReadsMemory(F, 0);
182  return Changed;
183  case LibFunc_setbuf:
184  case LibFunc_setvbuf:
185  Changed |= setDoesNotThrow(F);
186  Changed |= setDoesNotCapture(F, 0);
187  return Changed;
188  case LibFunc_strdup:
189  case LibFunc_strndup:
190  Changed |= setDoesNotThrow(F);
191  Changed |= setRetDoesNotAlias(F);
192  Changed |= setDoesNotCapture(F, 0);
193  Changed |= setOnlyReadsMemory(F, 0);
194  return Changed;
195  case LibFunc_stat:
196  case LibFunc_statvfs:
197  Changed |= setDoesNotThrow(F);
198  Changed |= setDoesNotCapture(F, 0);
199  Changed |= setDoesNotCapture(F, 1);
200  Changed |= setOnlyReadsMemory(F, 0);
201  return Changed;
202  case LibFunc_sscanf:
203  Changed |= setDoesNotThrow(F);
204  Changed |= setDoesNotCapture(F, 0);
205  Changed |= setDoesNotCapture(F, 1);
206  Changed |= setOnlyReadsMemory(F, 0);
207  Changed |= setOnlyReadsMemory(F, 1);
208  return Changed;
209  case LibFunc_sprintf:
210  Changed |= setDoesNotThrow(F);
211  Changed |= setDoesNotCapture(F, 0);
212  Changed |= setDoesNotCapture(F, 1);
213  Changed |= setOnlyReadsMemory(F, 1);
214  return Changed;
215  case LibFunc_snprintf:
216  Changed |= setDoesNotThrow(F);
217  Changed |= setDoesNotCapture(F, 0);
218  Changed |= setDoesNotCapture(F, 2);
219  Changed |= setOnlyReadsMemory(F, 2);
220  return Changed;
221  case LibFunc_setitimer:
222  Changed |= setDoesNotThrow(F);
223  Changed |= setDoesNotCapture(F, 1);
224  Changed |= setDoesNotCapture(F, 2);
225  Changed |= setOnlyReadsMemory(F, 1);
226  return Changed;
227  case LibFunc_system:
228  // May throw; "system" is a valid pthread cancellation point.
229  Changed |= setDoesNotCapture(F, 0);
230  Changed |= setOnlyReadsMemory(F, 0);
231  return Changed;
232  case LibFunc_malloc:
233  Changed |= setDoesNotThrow(F);
234  Changed |= setRetDoesNotAlias(F);
235  return Changed;
236  case LibFunc_memcmp:
237  Changed |= setOnlyReadsMemory(F);
238  Changed |= setDoesNotThrow(F);
239  Changed |= setDoesNotCapture(F, 0);
240  Changed |= setDoesNotCapture(F, 1);
241  return Changed;
242  case LibFunc_memchr:
243  case LibFunc_memrchr:
244  Changed |= setOnlyReadsMemory(F);
245  Changed |= setDoesNotThrow(F);
246  return Changed;
247  case LibFunc_modf:
248  case LibFunc_modff:
249  case LibFunc_modfl:
250  Changed |= setDoesNotThrow(F);
251  Changed |= setDoesNotCapture(F, 1);
252  return Changed;
253  case LibFunc_memcpy:
254  case LibFunc_mempcpy:
255  case LibFunc_memccpy:
256  case LibFunc_memmove:
257  Changed |= setDoesNotThrow(F);
258  Changed |= setDoesNotCapture(F, 1);
259  Changed |= setOnlyReadsMemory(F, 1);
260  return Changed;
261  case LibFunc_memcpy_chk:
262  Changed |= setDoesNotThrow(F);
263  return Changed;
264  case LibFunc_memalign:
265  Changed |= setRetDoesNotAlias(F);
266  return Changed;
267  case LibFunc_mkdir:
268  Changed |= setDoesNotThrow(F);
269  Changed |= setDoesNotCapture(F, 0);
270  Changed |= setOnlyReadsMemory(F, 0);
271  return Changed;
272  case LibFunc_mktime:
273  Changed |= setDoesNotThrow(F);
274  Changed |= setDoesNotCapture(F, 0);
275  return Changed;
276  case LibFunc_realloc:
277  Changed |= setDoesNotThrow(F);
278  Changed |= setRetDoesNotAlias(F);
279  Changed |= setDoesNotCapture(F, 0);
280  return Changed;
281  case LibFunc_read:
282  // May throw; "read" is a valid pthread cancellation point.
283  Changed |= setDoesNotCapture(F, 1);
284  return Changed;
285  case LibFunc_rewind:
286  Changed |= setDoesNotThrow(F);
287  Changed |= setDoesNotCapture(F, 0);
288  return Changed;
289  case LibFunc_rmdir:
290  case LibFunc_remove:
291  case LibFunc_realpath:
292  Changed |= setDoesNotThrow(F);
293  Changed |= setDoesNotCapture(F, 0);
294  Changed |= setOnlyReadsMemory(F, 0);
295  return Changed;
296  case LibFunc_rename:
297  Changed |= setDoesNotThrow(F);
298  Changed |= setDoesNotCapture(F, 0);
299  Changed |= setDoesNotCapture(F, 1);
300  Changed |= setOnlyReadsMemory(F, 0);
301  Changed |= setOnlyReadsMemory(F, 1);
302  return Changed;
303  case LibFunc_readlink:
304  Changed |= setDoesNotThrow(F);
305  Changed |= setDoesNotCapture(F, 0);
306  Changed |= setDoesNotCapture(F, 1);
307  Changed |= setOnlyReadsMemory(F, 0);
308  return Changed;
309  case LibFunc_write:
310  // May throw; "write" is a valid pthread cancellation point.
311  Changed |= setDoesNotCapture(F, 1);
312  Changed |= setOnlyReadsMemory(F, 1);
313  return Changed;
314  case LibFunc_bcopy:
315  Changed |= setDoesNotThrow(F);
316  Changed |= setDoesNotCapture(F, 0);
317  Changed |= setDoesNotCapture(F, 1);
318  Changed |= setOnlyReadsMemory(F, 0);
319  return Changed;
320  case LibFunc_bcmp:
321  Changed |= setDoesNotThrow(F);
322  Changed |= setOnlyReadsMemory(F);
323  Changed |= setDoesNotCapture(F, 0);
324  Changed |= setDoesNotCapture(F, 1);
325  return Changed;
326  case LibFunc_bzero:
327  Changed |= setDoesNotThrow(F);
328  Changed |= setDoesNotCapture(F, 0);
329  return Changed;
330  case LibFunc_calloc:
331  Changed |= setDoesNotThrow(F);
332  Changed |= setRetDoesNotAlias(F);
333  return Changed;
334  case LibFunc_chmod:
335  case LibFunc_chown:
336  Changed |= setDoesNotThrow(F);
337  Changed |= setDoesNotCapture(F, 0);
338  Changed |= setOnlyReadsMemory(F, 0);
339  return Changed;
340  case LibFunc_ctermid:
341  case LibFunc_clearerr:
342  case LibFunc_closedir:
343  Changed |= setDoesNotThrow(F);
344  Changed |= setDoesNotCapture(F, 0);
345  return Changed;
346  case LibFunc_atoi:
347  case LibFunc_atol:
348  case LibFunc_atof:
349  case LibFunc_atoll:
350  Changed |= setDoesNotThrow(F);
351  Changed |= setOnlyReadsMemory(F);
352  Changed |= setDoesNotCapture(F, 0);
353  return Changed;
354  case LibFunc_access:
355  Changed |= setDoesNotThrow(F);
356  Changed |= setDoesNotCapture(F, 0);
357  Changed |= setOnlyReadsMemory(F, 0);
358  return Changed;
359  case LibFunc_fopen:
360  Changed |= setDoesNotThrow(F);
361  Changed |= setRetDoesNotAlias(F);
362  Changed |= setDoesNotCapture(F, 0);
363  Changed |= setDoesNotCapture(F, 1);
364  Changed |= setOnlyReadsMemory(F, 0);
365  Changed |= setOnlyReadsMemory(F, 1);
366  return Changed;
367  case LibFunc_fdopen:
368  Changed |= setDoesNotThrow(F);
369  Changed |= setRetDoesNotAlias(F);
370  Changed |= setDoesNotCapture(F, 1);
371  Changed |= setOnlyReadsMemory(F, 1);
372  return Changed;
373  case LibFunc_feof:
374  case LibFunc_free:
375  case LibFunc_fseek:
376  case LibFunc_ftell:
377  case LibFunc_fgetc:
378  case LibFunc_fseeko:
379  case LibFunc_ftello:
380  case LibFunc_fileno:
381  case LibFunc_fflush:
382  case LibFunc_fclose:
383  case LibFunc_fsetpos:
384  case LibFunc_flockfile:
385  case LibFunc_funlockfile:
386  case LibFunc_ftrylockfile:
387  Changed |= setDoesNotThrow(F);
388  Changed |= setDoesNotCapture(F, 0);
389  return Changed;
390  case LibFunc_ferror:
391  Changed |= setDoesNotThrow(F);
392  Changed |= setDoesNotCapture(F, 0);
393  Changed |= setOnlyReadsMemory(F);
394  return Changed;
395  case LibFunc_fputc:
396  case LibFunc_fstat:
397  case LibFunc_frexp:
398  case LibFunc_frexpf:
399  case LibFunc_frexpl:
400  case LibFunc_fstatvfs:
401  Changed |= setDoesNotThrow(F);
402  Changed |= setDoesNotCapture(F, 1);
403  return Changed;
404  case LibFunc_fgets:
405  Changed |= setDoesNotThrow(F);
406  Changed |= setDoesNotCapture(F, 2);
407  return Changed;
408  case LibFunc_fread:
409  Changed |= setDoesNotThrow(F);
410  Changed |= setDoesNotCapture(F, 0);
411  Changed |= setDoesNotCapture(F, 3);
412  return Changed;
413  case LibFunc_fwrite:
414  Changed |= setDoesNotThrow(F);
415  Changed |= setDoesNotCapture(F, 0);
416  Changed |= setDoesNotCapture(F, 3);
417  // FIXME: readonly #1?
418  return Changed;
419  case LibFunc_fputs:
420  Changed |= setDoesNotThrow(F);
421  Changed |= setDoesNotCapture(F, 0);
422  Changed |= setDoesNotCapture(F, 1);
423  Changed |= setOnlyReadsMemory(F, 0);
424  return Changed;
425  case LibFunc_fscanf:
426  case LibFunc_fprintf:
427  Changed |= setDoesNotThrow(F);
428  Changed |= setDoesNotCapture(F, 0);
429  Changed |= setDoesNotCapture(F, 1);
430  Changed |= setOnlyReadsMemory(F, 1);
431  return Changed;
432  case LibFunc_fgetpos:
433  Changed |= setDoesNotThrow(F);
434  Changed |= setDoesNotCapture(F, 0);
435  Changed |= setDoesNotCapture(F, 1);
436  return Changed;
437  case LibFunc_getc:
438  case LibFunc_getlogin_r:
439  case LibFunc_getc_unlocked:
440  Changed |= setDoesNotThrow(F);
441  Changed |= setDoesNotCapture(F, 0);
442  return Changed;
443  case LibFunc_getenv:
444  Changed |= setDoesNotThrow(F);
445  Changed |= setOnlyReadsMemory(F);
446  Changed |= setDoesNotCapture(F, 0);
447  return Changed;
448  case LibFunc_gets:
449  case LibFunc_getchar:
450  Changed |= setDoesNotThrow(F);
451  return Changed;
452  case LibFunc_getitimer:
453  Changed |= setDoesNotThrow(F);
454  Changed |= setDoesNotCapture(F, 1);
455  return Changed;
456  case LibFunc_getpwnam:
457  Changed |= setDoesNotThrow(F);
458  Changed |= setDoesNotCapture(F, 0);
459  Changed |= setOnlyReadsMemory(F, 0);
460  return Changed;
461  case LibFunc_ungetc:
462  Changed |= setDoesNotThrow(F);
463  Changed |= setDoesNotCapture(F, 1);
464  return Changed;
465  case LibFunc_uname:
466  Changed |= setDoesNotThrow(F);
467  Changed |= setDoesNotCapture(F, 0);
468  return Changed;
469  case LibFunc_unlink:
470  Changed |= setDoesNotThrow(F);
471  Changed |= setDoesNotCapture(F, 0);
472  Changed |= setOnlyReadsMemory(F, 0);
473  return Changed;
474  case LibFunc_unsetenv:
475  Changed |= setDoesNotThrow(F);
476  Changed |= setDoesNotCapture(F, 0);
477  Changed |= setOnlyReadsMemory(F, 0);
478  return Changed;
479  case LibFunc_utime:
480  case LibFunc_utimes:
481  Changed |= setDoesNotThrow(F);
482  Changed |= setDoesNotCapture(F, 0);
483  Changed |= setDoesNotCapture(F, 1);
484  Changed |= setOnlyReadsMemory(F, 0);
485  Changed |= setOnlyReadsMemory(F, 1);
486  return Changed;
487  case LibFunc_putc:
488  Changed |= setDoesNotThrow(F);
489  Changed |= setDoesNotCapture(F, 1);
490  return Changed;
491  case LibFunc_puts:
492  case LibFunc_printf:
493  case LibFunc_perror:
494  Changed |= setDoesNotThrow(F);
495  Changed |= setDoesNotCapture(F, 0);
496  Changed |= setOnlyReadsMemory(F, 0);
497  return Changed;
498  case LibFunc_pread:
499  // May throw; "pread" is a valid pthread cancellation point.
500  Changed |= setDoesNotCapture(F, 1);
501  return Changed;
502  case LibFunc_pwrite:
503  // May throw; "pwrite" is a valid pthread cancellation point.
504  Changed |= setDoesNotCapture(F, 1);
505  Changed |= setOnlyReadsMemory(F, 1);
506  return Changed;
507  case LibFunc_putchar:
508  Changed |= setDoesNotThrow(F);
509  return Changed;
510  case LibFunc_popen:
511  Changed |= setDoesNotThrow(F);
512  Changed |= setRetDoesNotAlias(F);
513  Changed |= setDoesNotCapture(F, 0);
514  Changed |= setDoesNotCapture(F, 1);
515  Changed |= setOnlyReadsMemory(F, 0);
516  Changed |= setOnlyReadsMemory(F, 1);
517  return Changed;
518  case LibFunc_pclose:
519  Changed |= setDoesNotThrow(F);
520  Changed |= setDoesNotCapture(F, 0);
521  return Changed;
522  case LibFunc_vscanf:
523  Changed |= setDoesNotThrow(F);
524  Changed |= setDoesNotCapture(F, 0);
525  Changed |= setOnlyReadsMemory(F, 0);
526  return Changed;
527  case LibFunc_vsscanf:
528  Changed |= setDoesNotThrow(F);
529  Changed |= setDoesNotCapture(F, 0);
530  Changed |= setDoesNotCapture(F, 1);
531  Changed |= setOnlyReadsMemory(F, 0);
532  Changed |= setOnlyReadsMemory(F, 1);
533  return Changed;
534  case LibFunc_vfscanf:
535  Changed |= setDoesNotThrow(F);
536  Changed |= setDoesNotCapture(F, 0);
537  Changed |= setDoesNotCapture(F, 1);
538  Changed |= setOnlyReadsMemory(F, 1);
539  return Changed;
540  case LibFunc_valloc:
541  Changed |= setDoesNotThrow(F);
542  Changed |= setRetDoesNotAlias(F);
543  return Changed;
544  case LibFunc_vprintf:
545  Changed |= setDoesNotThrow(F);
546  Changed |= setDoesNotCapture(F, 0);
547  Changed |= setOnlyReadsMemory(F, 0);
548  return Changed;
549  case LibFunc_vfprintf:
550  case LibFunc_vsprintf:
551  Changed |= setDoesNotThrow(F);
552  Changed |= setDoesNotCapture(F, 0);
553  Changed |= setDoesNotCapture(F, 1);
554  Changed |= setOnlyReadsMemory(F, 1);
555  return Changed;
556  case LibFunc_vsnprintf:
557  Changed |= setDoesNotThrow(F);
558  Changed |= setDoesNotCapture(F, 0);
559  Changed |= setDoesNotCapture(F, 2);
560  Changed |= setOnlyReadsMemory(F, 2);
561  return Changed;
562  case LibFunc_open:
563  // May throw; "open" is a valid pthread cancellation point.
564  Changed |= setDoesNotCapture(F, 0);
565  Changed |= setOnlyReadsMemory(F, 0);
566  return Changed;
567  case LibFunc_opendir:
568  Changed |= setDoesNotThrow(F);
569  Changed |= setRetDoesNotAlias(F);
570  Changed |= setDoesNotCapture(F, 0);
571  Changed |= setOnlyReadsMemory(F, 0);
572  return Changed;
573  case LibFunc_tmpfile:
574  Changed |= setDoesNotThrow(F);
575  Changed |= setRetDoesNotAlias(F);
576  return Changed;
577  case LibFunc_times:
578  Changed |= setDoesNotThrow(F);
579  Changed |= setDoesNotCapture(F, 0);
580  return Changed;
581  case LibFunc_htonl:
582  case LibFunc_htons:
583  case LibFunc_ntohl:
584  case LibFunc_ntohs:
585  Changed |= setDoesNotThrow(F);
586  Changed |= setDoesNotAccessMemory(F);
587  return Changed;
588  case LibFunc_lstat:
589  Changed |= setDoesNotThrow(F);
590  Changed |= setDoesNotCapture(F, 0);
591  Changed |= setDoesNotCapture(F, 1);
592  Changed |= setOnlyReadsMemory(F, 0);
593  return Changed;
594  case LibFunc_lchown:
595  Changed |= setDoesNotThrow(F);
596  Changed |= setDoesNotCapture(F, 0);
597  Changed |= setOnlyReadsMemory(F, 0);
598  return Changed;
599  case LibFunc_qsort:
600  // May throw; places call through function pointer.
601  Changed |= setDoesNotCapture(F, 3);
602  return Changed;
603  case LibFunc_dunder_strdup:
604  case LibFunc_dunder_strndup:
605  Changed |= setDoesNotThrow(F);
606  Changed |= setRetDoesNotAlias(F);
607  Changed |= setDoesNotCapture(F, 0);
608  Changed |= setOnlyReadsMemory(F, 0);
609  return Changed;
610  case LibFunc_dunder_strtok_r:
611  Changed |= setDoesNotThrow(F);
612  Changed |= setDoesNotCapture(F, 1);
613  Changed |= setOnlyReadsMemory(F, 1);
614  return Changed;
615  case LibFunc_under_IO_getc:
616  Changed |= setDoesNotThrow(F);
617  Changed |= setDoesNotCapture(F, 0);
618  return Changed;
619  case LibFunc_under_IO_putc:
620  Changed |= setDoesNotThrow(F);
621  Changed |= setDoesNotCapture(F, 1);
622  return Changed;
623  case LibFunc_dunder_isoc99_scanf:
624  Changed |= setDoesNotThrow(F);
625  Changed |= setDoesNotCapture(F, 0);
626  Changed |= setOnlyReadsMemory(F, 0);
627  return Changed;
628  case LibFunc_stat64:
629  case LibFunc_lstat64:
630  case LibFunc_statvfs64:
631  Changed |= setDoesNotThrow(F);
632  Changed |= setDoesNotCapture(F, 0);
633  Changed |= setDoesNotCapture(F, 1);
634  Changed |= setOnlyReadsMemory(F, 0);
635  return Changed;
636  case LibFunc_dunder_isoc99_sscanf:
637  Changed |= setDoesNotThrow(F);
638  Changed |= setDoesNotCapture(F, 0);
639  Changed |= setDoesNotCapture(F, 1);
640  Changed |= setOnlyReadsMemory(F, 0);
641  Changed |= setOnlyReadsMemory(F, 1);
642  return Changed;
643  case LibFunc_fopen64:
644  Changed |= setDoesNotThrow(F);
645  Changed |= setRetDoesNotAlias(F);
646  Changed |= setDoesNotCapture(F, 0);
647  Changed |= setDoesNotCapture(F, 1);
648  Changed |= setOnlyReadsMemory(F, 0);
649  Changed |= setOnlyReadsMemory(F, 1);
650  return Changed;
651  case LibFunc_fseeko64:
652  case LibFunc_ftello64:
653  Changed |= setDoesNotThrow(F);
654  Changed |= setDoesNotCapture(F, 0);
655  return Changed;
656  case LibFunc_tmpfile64:
657  Changed |= setDoesNotThrow(F);
658  Changed |= setRetDoesNotAlias(F);
659  return Changed;
660  case LibFunc_fstat64:
661  case LibFunc_fstatvfs64:
662  Changed |= setDoesNotThrow(F);
663  Changed |= setDoesNotCapture(F, 1);
664  return Changed;
665  case LibFunc_open64:
666  // May throw; "open" is a valid pthread cancellation point.
667  Changed |= setDoesNotCapture(F, 0);
668  Changed |= setOnlyReadsMemory(F, 0);
669  return Changed;
670  case LibFunc_gettimeofday:
671  // Currently some platforms have the restrict keyword on the arguments to
672  // gettimeofday. To be conservative, do not add noalias to gettimeofday's
673  // arguments.
674  Changed |= setDoesNotThrow(F);
675  Changed |= setDoesNotCapture(F, 0);
676  Changed |= setDoesNotCapture(F, 1);
677  return Changed;
678  case LibFunc_Znwj: // new(unsigned int)
679  case LibFunc_Znwm: // new(unsigned long)
680  case LibFunc_Znaj: // new[](unsigned int)
681  case LibFunc_Znam: // new[](unsigned long)
682  case LibFunc_msvc_new_int: // new(unsigned int)
683  case LibFunc_msvc_new_longlong: // new(unsigned long long)
684  case LibFunc_msvc_new_array_int: // new[](unsigned int)
685  case LibFunc_msvc_new_array_longlong: // new[](unsigned long long)
686  // Operator new always returns a nonnull noalias pointer
687  Changed |= setRetNonNull(F);
688  Changed |= setRetDoesNotAlias(F);
689  return Changed;
690  //TODO: add LibFunc entries for:
691  //case LibFunc_memset_pattern4:
692  //case LibFunc_memset_pattern8:
693  case LibFunc_memset_pattern16:
694  Changed |= setOnlyAccessesArgMemory(F);
695  Changed |= setDoesNotCapture(F, 0);
696  Changed |= setDoesNotCapture(F, 1);
697  Changed |= setOnlyReadsMemory(F, 1);
698  return Changed;
699  // int __nvvm_reflect(const char *)
700  case LibFunc_nvvm_reflect:
701  Changed |= setDoesNotAccessMemory(F);
702  Changed |= setDoesNotThrow(F);
703  return Changed;
704 
705  default:
706  // FIXME: It'd be really nice to cover all the library functions we're
707  // aware of here.
708  return false;
709  }
710 }
711 
712 //- Emit LibCalls ------------------------------------------------------------//
713 
715  unsigned AS = V->getType()->getPointerAddressSpace();
716  return B.CreateBitCast(V, B.getInt8PtrTy(AS), "cstr");
717 }
718 
720  const TargetLibraryInfo *TLI) {
721  if (!TLI->has(LibFunc_strlen))
722  return nullptr;
723 
724  Module *M = B.GetInsertBlock()->getModule();
726  Constant *StrLen = M->getOrInsertFunction("strlen", DL.getIntPtrType(Context),
727  B.getInt8PtrTy());
728  inferLibFuncAttributes(*M->getFunction("strlen"), *TLI);
729  CallInst *CI = B.CreateCall(StrLen, castToCStr(Ptr, B), "strlen");
730  if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts()))
731  CI->setCallingConv(F->getCallingConv());
732 
733  return CI;
734 }
735 
737  const TargetLibraryInfo *TLI) {
738  if (!TLI->has(LibFunc_strchr))
739  return nullptr;
740 
741  Module *M = B.GetInsertBlock()->getModule();
742  Type *I8Ptr = B.getInt8PtrTy();
743  Type *I32Ty = B.getInt32Ty();
744  Constant *StrChr =
745  M->getOrInsertFunction("strchr", I8Ptr, I8Ptr, I32Ty);
746  inferLibFuncAttributes(*M->getFunction("strchr"), *TLI);
747  CallInst *CI = B.CreateCall(
748  StrChr, {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, "strchr");
749  if (const Function *F = dyn_cast<Function>(StrChr->stripPointerCasts()))
750  CI->setCallingConv(F->getCallingConv());
751  return CI;
752 }
753 
755  const DataLayout &DL, const TargetLibraryInfo *TLI) {
756  if (!TLI->has(LibFunc_strncmp))
757  return nullptr;
758 
759  Module *M = B.GetInsertBlock()->getModule();
761  Value *StrNCmp = M->getOrInsertFunction("strncmp", B.getInt32Ty(),
762  B.getInt8PtrTy(), B.getInt8PtrTy(),
763  DL.getIntPtrType(Context));
764  inferLibFuncAttributes(*M->getFunction("strncmp"), *TLI);
765  CallInst *CI = B.CreateCall(
766  StrNCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "strncmp");
767 
768  if (const Function *F = dyn_cast<Function>(StrNCmp->stripPointerCasts()))
769  CI->setCallingConv(F->getCallingConv());
770 
771  return CI;
772 }
773 
775  const TargetLibraryInfo *TLI, StringRef Name) {
776  if (!TLI->has(LibFunc_strcpy))
777  return nullptr;
778 
779  Module *M = B.GetInsertBlock()->getModule();
780  Type *I8Ptr = B.getInt8PtrTy();
781  Value *StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr);
782  inferLibFuncAttributes(*M->getFunction(Name), *TLI);
783  CallInst *CI =
784  B.CreateCall(StrCpy, {castToCStr(Dst, B), castToCStr(Src, B)}, Name);
785  if (const Function *F = dyn_cast<Function>(StrCpy->stripPointerCasts()))
786  CI->setCallingConv(F->getCallingConv());
787  return CI;
788 }
789 
791  const TargetLibraryInfo *TLI, StringRef Name) {
792  if (!TLI->has(LibFunc_strncpy))
793  return nullptr;
794 
795  Module *M = B.GetInsertBlock()->getModule();
796  Type *I8Ptr = B.getInt8PtrTy();
797  Value *StrNCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr,
798  Len->getType());
799  inferLibFuncAttributes(*M->getFunction(Name), *TLI);
800  CallInst *CI = B.CreateCall(
801  StrNCpy, {castToCStr(Dst, B), castToCStr(Src, B), Len}, "strncpy");
802  if (const Function *F = dyn_cast<Function>(StrNCpy->stripPointerCasts()))
803  CI->setCallingConv(F->getCallingConv());
804  return CI;
805 }
806 
807 Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
808  IRBuilder<> &B, const DataLayout &DL,
809  const TargetLibraryInfo *TLI) {
810  if (!TLI->has(LibFunc_memcpy_chk))
811  return nullptr;
812 
813  Module *M = B.GetInsertBlock()->getModule();
816  Attribute::NoUnwind);
818  Value *MemCpy = M->getOrInsertFunction(
819  "__memcpy_chk", AttributeList::get(M->getContext(), AS), B.getInt8PtrTy(),
820  B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context),
821  DL.getIntPtrType(Context));
822  Dst = castToCStr(Dst, B);
823  Src = castToCStr(Src, B);
824  CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
825  if (const Function *F = dyn_cast<Function>(MemCpy->stripPointerCasts()))
826  CI->setCallingConv(F->getCallingConv());
827  return CI;
828 }
829 
831  const DataLayout &DL, const TargetLibraryInfo *TLI) {
832  if (!TLI->has(LibFunc_memchr))
833  return nullptr;
834 
835  Module *M = B.GetInsertBlock()->getModule();
837  Value *MemChr = M->getOrInsertFunction("memchr", B.getInt8PtrTy(),
838  B.getInt8PtrTy(), B.getInt32Ty(),
839  DL.getIntPtrType(Context));
840  inferLibFuncAttributes(*M->getFunction("memchr"), *TLI);
841  CallInst *CI = B.CreateCall(MemChr, {castToCStr(Ptr, B), Val, Len}, "memchr");
842 
843  if (const Function *F = dyn_cast<Function>(MemChr->stripPointerCasts()))
844  CI->setCallingConv(F->getCallingConv());
845 
846  return CI;
847 }
848 
850  const DataLayout &DL, const TargetLibraryInfo *TLI) {
851  if (!TLI->has(LibFunc_memcmp))
852  return nullptr;
853 
854  Module *M = B.GetInsertBlock()->getModule();
856  Value *MemCmp = M->getOrInsertFunction("memcmp", B.getInt32Ty(),
857  B.getInt8PtrTy(), B.getInt8PtrTy(),
858  DL.getIntPtrType(Context));
859  inferLibFuncAttributes(*M->getFunction("memcmp"), *TLI);
860  CallInst *CI = B.CreateCall(
861  MemCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "memcmp");
862 
863  if (const Function *F = dyn_cast<Function>(MemCmp->stripPointerCasts()))
864  CI->setCallingConv(F->getCallingConv());
865 
866  return CI;
867 }
868 
869 /// Append a suffix to the function name according to the type of 'Op'.
871  SmallString<20> &NameBuffer) {
872  if (!Op->getType()->isDoubleTy()) {
873  NameBuffer += Name;
874 
875  if (Op->getType()->isFloatTy())
876  NameBuffer += 'f';
877  else
878  NameBuffer += 'l';
879 
880  Name = NameBuffer;
881  }
882 }
883 
885  const AttributeList &Attrs) {
886  SmallString<20> NameBuffer;
887  appendTypeSuffix(Op, Name, NameBuffer);
888 
889  Module *M = B.GetInsertBlock()->getModule();
890  Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
891  Op->getType());
892  CallInst *CI = B.CreateCall(Callee, Op, Name);
893 
894  // The incoming attribute set may have come from a speculatable intrinsic, but
895  // is being replaced with a library call which is not allowed to be
896  // speculatable.
899  Attribute::Speculatable));
900  if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
901  CI->setCallingConv(F->getCallingConv());
902 
903  return CI;
904 }
905 
907  IRBuilder<> &B, const AttributeList &Attrs) {
908  SmallString<20> NameBuffer;
909  appendTypeSuffix(Op1, Name, NameBuffer);
910 
911  Module *M = B.GetInsertBlock()->getModule();
912  Value *Callee = M->getOrInsertFunction(Name, Op1->getType(), Op1->getType(),
913  Op2->getType());
914  CallInst *CI = B.CreateCall(Callee, {Op1, Op2}, Name);
915  CI->setAttributes(Attrs);
916  if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
917  CI->setCallingConv(F->getCallingConv());
918 
919  return CI;
920 }
921 
923  const TargetLibraryInfo *TLI) {
924  if (!TLI->has(LibFunc_putchar))
925  return nullptr;
926 
927  Module *M = B.GetInsertBlock()->getModule();
928  Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(), B.getInt32Ty());
929  inferLibFuncAttributes(*M->getFunction("putchar"), *TLI);
930  CallInst *CI = B.CreateCall(PutChar,
931  B.CreateIntCast(Char,
932  B.getInt32Ty(),
933  /*isSigned*/true,
934  "chari"),
935  "putchar");
936 
937  if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts()))
938  CI->setCallingConv(F->getCallingConv());
939  return CI;
940 }
941 
943  const TargetLibraryInfo *TLI) {
944  if (!TLI->has(LibFunc_puts))
945  return nullptr;
946 
947  Module *M = B.GetInsertBlock()->getModule();
948  Value *PutS =
949  M->getOrInsertFunction("puts", B.getInt32Ty(), B.getInt8PtrTy());
950  inferLibFuncAttributes(*M->getFunction("puts"), *TLI);
951  CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), "puts");
952  if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts()))
953  CI->setCallingConv(F->getCallingConv());
954  return CI;
955 }
956 
958  const TargetLibraryInfo *TLI) {
959  if (!TLI->has(LibFunc_fputc))
960  return nullptr;
961 
962  Module *M = B.GetInsertBlock()->getModule();
963  Constant *F = M->getOrInsertFunction("fputc", B.getInt32Ty(), B.getInt32Ty(),
964  File->getType());
965  if (File->getType()->isPointerTy())
966  inferLibFuncAttributes(*M->getFunction("fputc"), *TLI);
967  Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
968  "chari");
969  CallInst *CI = B.CreateCall(F, {Char, File}, "fputc");
970 
971  if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
972  CI->setCallingConv(Fn->getCallingConv());
973  return CI;
974 }
975 
977  const TargetLibraryInfo *TLI) {
978  if (!TLI->has(LibFunc_fputs))
979  return nullptr;
980 
981  Module *M = B.GetInsertBlock()->getModule();
982  StringRef FPutsName = TLI->getName(LibFunc_fputs);
984  FPutsName, B.getInt32Ty(), B.getInt8PtrTy(), File->getType());
985  if (File->getType()->isPointerTy())
986  inferLibFuncAttributes(*M->getFunction(FPutsName), *TLI);
987  CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, "fputs");
988 
989  if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
990  CI->setCallingConv(Fn->getCallingConv());
991  return CI;
992 }
993 
995  const DataLayout &DL, const TargetLibraryInfo *TLI) {
996  if (!TLI->has(LibFunc_fwrite))
997  return nullptr;
998 
999  Module *M = B.GetInsertBlock()->getModule();
1001  StringRef FWriteName = TLI->getName(LibFunc_fwrite);
1003  FWriteName, DL.getIntPtrType(Context), B.getInt8PtrTy(),
1004  DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
1005 
1006  if (File->getType()->isPointerTy())
1007  inferLibFuncAttributes(*M->getFunction(FWriteName), *TLI);
1008  CallInst *CI =
1009  B.CreateCall(F, {castToCStr(Ptr, B), Size,
1010  ConstantInt::get(DL.getIntPtrType(Context), 1), File});
1011 
1012  if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
1013  CI->setCallingConv(Fn->getCallingConv());
1014  return CI;
1015 }
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
Definition: Function.h:395
uint64_t CallInst * C
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
static bool setDoesNotCapture(Function &F, unsigned ArgNo)
LLVMContext & Context
LLVMContext & getContext() const
Definition: IRBuilder.h:124
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:142
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
adds the attribute to the list of attributes for the given arg.
Definition: Function.cpp:365
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
This class represents a function call, abstracting a target machine&#39;s calling convention.
StringRef getName(LibFunc F) const
STATISTIC(NumFunctions, "Total number of functions")
The two locations do not alias at all.
Definition: AliasAnalysis.h:79
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:503
Value * emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B, const TargetLibraryInfo *TLI, StringRef Name="strncpy")
Emit a call to the strncpy function to the builder, for the specified pointer arguments and length...
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:33
static bool setRetDoesNotAlias(Function &F)
void setCallingConv(CallingConv::ID CC)
void setDoesNotThrow()
Definition: Function.h:447
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition: IRBuilder.h:348
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
Definition: BasicBlock.cpp:116
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:237
Value * emitPutChar(Value *Char, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the putchar function. This assumes that Char is an integer.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:664
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
Definition: Function.h:327
Value * emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B, const AttributeList &Attrs)
Emit a call to the unary function named &#39;Name&#39; (e.g.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1444
#define F(x, y, z)
Definition: MD5.cpp:55
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
static bool setDoesNotThrow(Function &F)
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:122
Value * emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the __memcpy_chk function to the builder.
bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
Definition: Function.h:322
bool has(LibFunc F) const
Tests whether a library function is available.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
Value * emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B, const TargetLibraryInfo *TLI, StringRef Name="strcpy")
Emit a call to the strcpy function to the builder, for the specified pointer arguments.
const char * Name
void setOnlyAccessesArgMemory()
Definition: Function.h:415
bool doesNotAccessMemory() const
Determine if the function does not access memory.
Definition: Function.h:387
Value * emitFPutS(Value *Str, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function.
bool isFloatTy() const
Return true if this is &#39;float&#39;, a 32-bit IEEE fp type.
Definition: Type.h:147
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
Definition: DataLayout.cpp:702
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:142
void setOnlyReadsMemory()
Definition: Function.h:398
static void appendTypeSuffix(Value *Op, StringRef &Name, SmallString< 20 > &NameBuffer)
Append a suffix to the function name according to the type of &#39;Op&#39;.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
This is an important base class in LLVM.
Definition: Constant.h:42
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:221
static bool setOnlyReadsMemory(Function &F)
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
Definition: Function.cpp:347
Value * castToCStr(Value *V, IRBuilder<> &B)
Return V if it is an i8*, otherwise cast it to i8*.
static bool setDoesNotAccessMemory(Function &F)
const Constant * stripPointerCasts() const
Definition: Constant.h:153
const AMDGPUAS & AS
static bool setRetNonNull(Function &F)
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
Definition: Value.cpp:527
Value * emitStrChr(Value *Ptr, char C, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strchr function to the builder, for the specified pointer and character.
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
Definition: IRBuilder.h:386
bool doesNotThrow() const
Determine if the function cannot unwind.
Definition: Function.h:444
Value * emitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strlen function to the builder, for the specified pointer.
Value * emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name, IRBuilder<> &B, const AttributeList &Attrs)
Emit a call to the binary function named &#39;Name&#39; (e.g.
#define B
Definition: LargeTest.cpp:24
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition: IRBuilder.h:1507
Module.h This file contains the declarations for the Module class.
Provides information about what library functions are available for the current target.
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:560
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:172
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Value * emitFPutC(Value *Char, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
void setDoesNotAccessMemory()
Definition: Function.h:390
Value * emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strncmp function to the builder.
AttributeList removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
static bool setOnlyAccessesArgMemory(Function &F)
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
Definition: Function.h:412
Value * emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite function.
Value * emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memcmp function.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
Value * emitPutS(Value *Str, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
int * Ptr
bool isDoubleTy() const
Return true if this is &#39;double&#39;, a 64-bit IEEE fp type.
Definition: Type.h:150
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
Definition: Attributes.cpp:868
CallInst * CreateCall(Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1659