LLVM  4.0.0
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 setDoesNotCapture(Function &F, unsigned n) {
75  if (F.doesNotCapture(n))
76  return false;
77  F.setDoesNotCapture(n);
78  ++NumNoCapture;
79  return true;
80 }
81 
82 static bool setOnlyReadsMemory(Function &F, unsigned n) {
83  if (F.onlyReadsMemory(n))
84  return false;
85  F.setOnlyReadsMemory(n);
86  ++NumReadOnlyArg;
87  return true;
88 }
89 
90 static bool setDoesNotAlias(Function &F, unsigned n) {
91  if (F.doesNotAlias(n))
92  return false;
93  F.setDoesNotAlias(n);
94  ++NumNoAlias;
95  return true;
96 }
97 
98 static bool setNonNull(Function &F, unsigned n) {
100  F.getReturnType()->isPointerTy()) &&
101  "nonnull applies only to pointers");
102  if (F.getAttributes().hasAttribute(n, Attribute::NonNull))
103  return false;
104  F.addAttribute(n, Attribute::NonNull);
105  ++NumNonNull;
106  return true;
107 }
108 
110  LibFunc::Func TheLibFunc;
111  if (!(TLI.getLibFunc(F, TheLibFunc) && TLI.has(TheLibFunc)))
112  return false;
113 
114  bool Changed = false;
115  switch (TheLibFunc) {
116  case LibFunc::strlen:
117  Changed |= setOnlyReadsMemory(F);
118  Changed |= setDoesNotThrow(F);
119  Changed |= setDoesNotCapture(F, 1);
120  return Changed;
121  case LibFunc::strchr:
122  case LibFunc::strrchr:
123  Changed |= setOnlyReadsMemory(F);
124  Changed |= setDoesNotThrow(F);
125  return Changed;
126  case LibFunc::strtol:
127  case LibFunc::strtod:
128  case LibFunc::strtof:
129  case LibFunc::strtoul:
130  case LibFunc::strtoll:
131  case LibFunc::strtold:
132  case LibFunc::strtoull:
133  Changed |= setDoesNotThrow(F);
134  Changed |= setDoesNotCapture(F, 2);
135  Changed |= setOnlyReadsMemory(F, 1);
136  return Changed;
137  case LibFunc::strcpy:
138  case LibFunc::stpcpy:
139  case LibFunc::strcat:
140  case LibFunc::strncat:
141  case LibFunc::strncpy:
142  case LibFunc::stpncpy:
143  Changed |= setDoesNotThrow(F);
144  Changed |= setDoesNotCapture(F, 2);
145  Changed |= setOnlyReadsMemory(F, 2);
146  return Changed;
147  case LibFunc::strxfrm:
148  Changed |= setDoesNotThrow(F);
149  Changed |= setDoesNotCapture(F, 1);
150  Changed |= setDoesNotCapture(F, 2);
151  Changed |= setOnlyReadsMemory(F, 2);
152  return Changed;
153  case LibFunc::strcmp: // 0,1
154  case LibFunc::strspn: // 0,1
155  case LibFunc::strncmp: // 0,1
156  case LibFunc::strcspn: // 0,1
157  case LibFunc::strcoll: // 0,1
158  case LibFunc::strcasecmp: // 0,1
159  case LibFunc::strncasecmp: //
160  Changed |= setOnlyReadsMemory(F);
161  Changed |= setDoesNotThrow(F);
162  Changed |= setDoesNotCapture(F, 1);
163  Changed |= setDoesNotCapture(F, 2);
164  return Changed;
165  case LibFunc::strstr:
166  case LibFunc::strpbrk:
167  Changed |= setOnlyReadsMemory(F);
168  Changed |= setDoesNotThrow(F);
169  Changed |= setDoesNotCapture(F, 2);
170  return Changed;
171  case LibFunc::strtok:
172  case LibFunc::strtok_r:
173  Changed |= setDoesNotThrow(F);
174  Changed |= setDoesNotCapture(F, 2);
175  Changed |= setOnlyReadsMemory(F, 2);
176  return Changed;
177  case LibFunc::scanf:
178  Changed |= setDoesNotThrow(F);
179  Changed |= setDoesNotCapture(F, 1);
180  Changed |= setOnlyReadsMemory(F, 1);
181  return Changed;
182  case LibFunc::setbuf:
183  case LibFunc::setvbuf:
184  Changed |= setDoesNotThrow(F);
185  Changed |= setDoesNotCapture(F, 1);
186  return Changed;
187  case LibFunc::strdup:
188  case LibFunc::strndup:
189  Changed |= setDoesNotThrow(F);
190  Changed |= setDoesNotAlias(F, 0);
191  Changed |= setDoesNotCapture(F, 1);
192  Changed |= setOnlyReadsMemory(F, 1);
193  return Changed;
194  case LibFunc::stat:
195  case LibFunc::statvfs:
196  Changed |= setDoesNotThrow(F);
197  Changed |= setDoesNotCapture(F, 1);
198  Changed |= setDoesNotCapture(F, 2);
199  Changed |= setOnlyReadsMemory(F, 1);
200  return Changed;
201  case LibFunc::sscanf:
202  Changed |= setDoesNotThrow(F);
203  Changed |= setDoesNotCapture(F, 1);
204  Changed |= setDoesNotCapture(F, 2);
205  Changed |= setOnlyReadsMemory(F, 1);
206  Changed |= setOnlyReadsMemory(F, 2);
207  return Changed;
208  case LibFunc::sprintf:
209  Changed |= setDoesNotThrow(F);
210  Changed |= setDoesNotCapture(F, 1);
211  Changed |= setDoesNotCapture(F, 2);
212  Changed |= setOnlyReadsMemory(F, 2);
213  return Changed;
214  case LibFunc::snprintf:
215  Changed |= setDoesNotThrow(F);
216  Changed |= setDoesNotCapture(F, 1);
217  Changed |= setDoesNotCapture(F, 3);
218  Changed |= setOnlyReadsMemory(F, 3);
219  return Changed;
220  case LibFunc::setitimer:
221  Changed |= setDoesNotThrow(F);
222  Changed |= setDoesNotCapture(F, 2);
223  Changed |= setDoesNotCapture(F, 3);
224  Changed |= setOnlyReadsMemory(F, 2);
225  return Changed;
226  case LibFunc::system:
227  // May throw; "system" is a valid pthread cancellation point.
228  Changed |= setDoesNotCapture(F, 1);
229  Changed |= setOnlyReadsMemory(F, 1);
230  return Changed;
231  case LibFunc::malloc:
232  Changed |= setDoesNotThrow(F);
233  Changed |= setDoesNotAlias(F, 0);
234  return Changed;
235  case LibFunc::memcmp:
236  Changed |= setOnlyReadsMemory(F);
237  Changed |= setDoesNotThrow(F);
238  Changed |= setDoesNotCapture(F, 1);
239  Changed |= setDoesNotCapture(F, 2);
240  return Changed;
241  case LibFunc::memchr:
242  case LibFunc::memrchr:
243  Changed |= setOnlyReadsMemory(F);
244  Changed |= setDoesNotThrow(F);
245  return Changed;
246  case LibFunc::modf:
247  case LibFunc::modff:
248  case LibFunc::modfl:
249  Changed |= setDoesNotThrow(F);
250  Changed |= setDoesNotCapture(F, 2);
251  return Changed;
252  case LibFunc::memcpy:
253  case LibFunc::mempcpy:
254  case LibFunc::memccpy:
255  case LibFunc::memmove:
256  Changed |= setDoesNotThrow(F);
257  Changed |= setDoesNotCapture(F, 2);
258  Changed |= setOnlyReadsMemory(F, 2);
259  return Changed;
260  case LibFunc::memcpy_chk:
261  Changed |= setDoesNotThrow(F);
262  return Changed;
263  case LibFunc::memalign:
264  Changed |= setDoesNotAlias(F, 0);
265  return Changed;
266  case LibFunc::mkdir:
267  Changed |= setDoesNotThrow(F);
268  Changed |= setDoesNotCapture(F, 1);
269  Changed |= setOnlyReadsMemory(F, 1);
270  return Changed;
271  case LibFunc::mktime:
272  Changed |= setDoesNotThrow(F);
273  Changed |= setDoesNotCapture(F, 1);
274  return Changed;
275  case LibFunc::realloc:
276  Changed |= setDoesNotThrow(F);
277  Changed |= setDoesNotAlias(F, 0);
278  Changed |= setDoesNotCapture(F, 1);
279  return Changed;
280  case LibFunc::read:
281  // May throw; "read" is a valid pthread cancellation point.
282  Changed |= setDoesNotCapture(F, 2);
283  return Changed;
284  case LibFunc::rewind:
285  Changed |= setDoesNotThrow(F);
286  Changed |= setDoesNotCapture(F, 1);
287  return Changed;
288  case LibFunc::rmdir:
289  case LibFunc::remove:
290  case LibFunc::realpath:
291  Changed |= setDoesNotThrow(F);
292  Changed |= setDoesNotCapture(F, 1);
293  Changed |= setOnlyReadsMemory(F, 1);
294  return Changed;
295  case LibFunc::rename:
296  Changed |= setDoesNotThrow(F);
297  Changed |= setDoesNotCapture(F, 1);
298  Changed |= setDoesNotCapture(F, 2);
299  Changed |= setOnlyReadsMemory(F, 1);
300  Changed |= setOnlyReadsMemory(F, 2);
301  return Changed;
302  case LibFunc::readlink:
303  Changed |= setDoesNotThrow(F);
304  Changed |= setDoesNotCapture(F, 1);
305  Changed |= setDoesNotCapture(F, 2);
306  Changed |= setOnlyReadsMemory(F, 1);
307  return Changed;
308  case LibFunc::write:
309  // May throw; "write" is a valid pthread cancellation point.
310  Changed |= setDoesNotCapture(F, 2);
311  Changed |= setOnlyReadsMemory(F, 2);
312  return Changed;
313  case LibFunc::bcopy:
314  Changed |= setDoesNotThrow(F);
315  Changed |= setDoesNotCapture(F, 1);
316  Changed |= setDoesNotCapture(F, 2);
317  Changed |= setOnlyReadsMemory(F, 1);
318  return Changed;
319  case LibFunc::bcmp:
320  Changed |= setDoesNotThrow(F);
321  Changed |= setOnlyReadsMemory(F);
322  Changed |= setDoesNotCapture(F, 1);
323  Changed |= setDoesNotCapture(F, 2);
324  return Changed;
325  case LibFunc::bzero:
326  Changed |= setDoesNotThrow(F);
327  Changed |= setDoesNotCapture(F, 1);
328  return Changed;
329  case LibFunc::calloc:
330  Changed |= setDoesNotThrow(F);
331  Changed |= setDoesNotAlias(F, 0);
332  return Changed;
333  case LibFunc::chmod:
334  case LibFunc::chown:
335  Changed |= setDoesNotThrow(F);
336  Changed |= setDoesNotCapture(F, 1);
337  Changed |= setOnlyReadsMemory(F, 1);
338  return Changed;
339  case LibFunc::ctermid:
340  case LibFunc::clearerr:
341  case LibFunc::closedir:
342  Changed |= setDoesNotThrow(F);
343  Changed |= setDoesNotCapture(F, 1);
344  return Changed;
345  case LibFunc::atoi:
346  case LibFunc::atol:
347  case LibFunc::atof:
348  case LibFunc::atoll:
349  Changed |= setDoesNotThrow(F);
350  Changed |= setOnlyReadsMemory(F);
351  Changed |= setDoesNotCapture(F, 1);
352  return Changed;
353  case LibFunc::access:
354  Changed |= setDoesNotThrow(F);
355  Changed |= setDoesNotCapture(F, 1);
356  Changed |= setOnlyReadsMemory(F, 1);
357  return Changed;
358  case LibFunc::fopen:
359  Changed |= setDoesNotThrow(F);
360  Changed |= setDoesNotAlias(F, 0);
361  Changed |= setDoesNotCapture(F, 1);
362  Changed |= setDoesNotCapture(F, 2);
363  Changed |= setOnlyReadsMemory(F, 1);
364  Changed |= setOnlyReadsMemory(F, 2);
365  return Changed;
366  case LibFunc::fdopen:
367  Changed |= setDoesNotThrow(F);
368  Changed |= setDoesNotAlias(F, 0);
369  Changed |= setDoesNotCapture(F, 2);
370  Changed |= setOnlyReadsMemory(F, 2);
371  return Changed;
372  case LibFunc::feof:
373  case LibFunc::free:
374  case LibFunc::fseek:
375  case LibFunc::ftell:
376  case LibFunc::fgetc:
377  case LibFunc::fseeko:
378  case LibFunc::ftello:
379  case LibFunc::fileno:
380  case LibFunc::fflush:
381  case LibFunc::fclose:
382  case LibFunc::fsetpos:
383  case LibFunc::flockfile:
384  case LibFunc::funlockfile:
385  case LibFunc::ftrylockfile:
386  Changed |= setDoesNotThrow(F);
387  Changed |= setDoesNotCapture(F, 1);
388  return Changed;
389  case LibFunc::ferror:
390  Changed |= setDoesNotThrow(F);
391  Changed |= setDoesNotCapture(F, 1);
392  Changed |= setOnlyReadsMemory(F);
393  return Changed;
394  case LibFunc::fputc:
395  case LibFunc::fstat:
396  case LibFunc::frexp:
397  case LibFunc::frexpf:
398  case LibFunc::frexpl:
399  case LibFunc::fstatvfs:
400  Changed |= setDoesNotThrow(F);
401  Changed |= setDoesNotCapture(F, 2);
402  return Changed;
403  case LibFunc::fgets:
404  Changed |= setDoesNotThrow(F);
405  Changed |= setDoesNotCapture(F, 3);
406  return Changed;
407  case LibFunc::fread:
408  Changed |= setDoesNotThrow(F);
409  Changed |= setDoesNotCapture(F, 1);
410  Changed |= setDoesNotCapture(F, 4);
411  return Changed;
412  case LibFunc::fwrite:
413  Changed |= setDoesNotThrow(F);
414  Changed |= setDoesNotCapture(F, 1);
415  Changed |= setDoesNotCapture(F, 4);
416  // FIXME: readonly #1?
417  return Changed;
418  case LibFunc::fputs:
419  Changed |= setDoesNotThrow(F);
420  Changed |= setDoesNotCapture(F, 1);
421  Changed |= setDoesNotCapture(F, 2);
422  Changed |= setOnlyReadsMemory(F, 1);
423  return Changed;
424  case LibFunc::fscanf:
425  case LibFunc::fprintf:
426  Changed |= setDoesNotThrow(F);
427  Changed |= setDoesNotCapture(F, 1);
428  Changed |= setDoesNotCapture(F, 2);
429  Changed |= setOnlyReadsMemory(F, 2);
430  return Changed;
431  case LibFunc::fgetpos:
432  Changed |= setDoesNotThrow(F);
433  Changed |= setDoesNotCapture(F, 1);
434  Changed |= setDoesNotCapture(F, 2);
435  return Changed;
436  case LibFunc::getc:
437  case LibFunc::getlogin_r:
438  case LibFunc::getc_unlocked:
439  Changed |= setDoesNotThrow(F);
440  Changed |= setDoesNotCapture(F, 1);
441  return Changed;
442  case LibFunc::getenv:
443  Changed |= setDoesNotThrow(F);
444  Changed |= setOnlyReadsMemory(F);
445  Changed |= setDoesNotCapture(F, 1);
446  return Changed;
447  case LibFunc::gets:
448  case LibFunc::getchar:
449  Changed |= setDoesNotThrow(F);
450  return Changed;
451  case LibFunc::getitimer:
452  Changed |= setDoesNotThrow(F);
453  Changed |= setDoesNotCapture(F, 2);
454  return Changed;
455  case LibFunc::getpwnam:
456  Changed |= setDoesNotThrow(F);
457  Changed |= setDoesNotCapture(F, 1);
458  Changed |= setOnlyReadsMemory(F, 1);
459  return Changed;
460  case LibFunc::ungetc:
461  Changed |= setDoesNotThrow(F);
462  Changed |= setDoesNotCapture(F, 2);
463  return Changed;
464  case LibFunc::uname:
465  Changed |= setDoesNotThrow(F);
466  Changed |= setDoesNotCapture(F, 1);
467  return Changed;
468  case LibFunc::unlink:
469  Changed |= setDoesNotThrow(F);
470  Changed |= setDoesNotCapture(F, 1);
471  Changed |= setOnlyReadsMemory(F, 1);
472  return Changed;
473  case LibFunc::unsetenv:
474  Changed |= setDoesNotThrow(F);
475  Changed |= setDoesNotCapture(F, 1);
476  Changed |= setOnlyReadsMemory(F, 1);
477  return Changed;
478  case LibFunc::utime:
479  case LibFunc::utimes:
480  Changed |= setDoesNotThrow(F);
481  Changed |= setDoesNotCapture(F, 1);
482  Changed |= setDoesNotCapture(F, 2);
483  Changed |= setOnlyReadsMemory(F, 1);
484  Changed |= setOnlyReadsMemory(F, 2);
485  return Changed;
486  case LibFunc::putc:
487  Changed |= setDoesNotThrow(F);
488  Changed |= setDoesNotCapture(F, 2);
489  return Changed;
490  case LibFunc::puts:
491  case LibFunc::printf:
492  case LibFunc::perror:
493  Changed |= setDoesNotThrow(F);
494  Changed |= setDoesNotCapture(F, 1);
495  Changed |= setOnlyReadsMemory(F, 1);
496  return Changed;
497  case LibFunc::pread:
498  // May throw; "pread" is a valid pthread cancellation point.
499  Changed |= setDoesNotCapture(F, 2);
500  return Changed;
501  case LibFunc::pwrite:
502  // May throw; "pwrite" is a valid pthread cancellation point.
503  Changed |= setDoesNotCapture(F, 2);
504  Changed |= setOnlyReadsMemory(F, 2);
505  return Changed;
506  case LibFunc::putchar:
507  Changed |= setDoesNotThrow(F);
508  return Changed;
509  case LibFunc::popen:
510  Changed |= setDoesNotThrow(F);
511  Changed |= setDoesNotAlias(F, 0);
512  Changed |= setDoesNotCapture(F, 1);
513  Changed |= setDoesNotCapture(F, 2);
514  Changed |= setOnlyReadsMemory(F, 1);
515  Changed |= setOnlyReadsMemory(F, 2);
516  return Changed;
517  case LibFunc::pclose:
518  Changed |= setDoesNotThrow(F);
519  Changed |= setDoesNotCapture(F, 1);
520  return Changed;
521  case LibFunc::vscanf:
522  Changed |= setDoesNotThrow(F);
523  Changed |= setDoesNotCapture(F, 1);
524  Changed |= setOnlyReadsMemory(F, 1);
525  return Changed;
526  case LibFunc::vsscanf:
527  Changed |= setDoesNotThrow(F);
528  Changed |= setDoesNotCapture(F, 1);
529  Changed |= setDoesNotCapture(F, 2);
530  Changed |= setOnlyReadsMemory(F, 1);
531  Changed |= setOnlyReadsMemory(F, 2);
532  return Changed;
533  case LibFunc::vfscanf:
534  Changed |= setDoesNotThrow(F);
535  Changed |= setDoesNotCapture(F, 1);
536  Changed |= setDoesNotCapture(F, 2);
537  Changed |= setOnlyReadsMemory(F, 2);
538  return Changed;
539  case LibFunc::valloc:
540  Changed |= setDoesNotThrow(F);
541  Changed |= setDoesNotAlias(F, 0);
542  return Changed;
543  case LibFunc::vprintf:
544  Changed |= setDoesNotThrow(F);
545  Changed |= setDoesNotCapture(F, 1);
546  Changed |= setOnlyReadsMemory(F, 1);
547  return Changed;
548  case LibFunc::vfprintf:
549  case LibFunc::vsprintf:
550  Changed |= setDoesNotThrow(F);
551  Changed |= setDoesNotCapture(F, 1);
552  Changed |= setDoesNotCapture(F, 2);
553  Changed |= setOnlyReadsMemory(F, 2);
554  return Changed;
555  case LibFunc::vsnprintf:
556  Changed |= setDoesNotThrow(F);
557  Changed |= setDoesNotCapture(F, 1);
558  Changed |= setDoesNotCapture(F, 3);
559  Changed |= setOnlyReadsMemory(F, 3);
560  return Changed;
561  case LibFunc::open:
562  // May throw; "open" is a valid pthread cancellation point.
563  Changed |= setDoesNotCapture(F, 1);
564  Changed |= setOnlyReadsMemory(F, 1);
565  return Changed;
566  case LibFunc::opendir:
567  Changed |= setDoesNotThrow(F);
568  Changed |= setDoesNotAlias(F, 0);
569  Changed |= setDoesNotCapture(F, 1);
570  Changed |= setOnlyReadsMemory(F, 1);
571  return Changed;
572  case LibFunc::tmpfile:
573  Changed |= setDoesNotThrow(F);
574  Changed |= setDoesNotAlias(F, 0);
575  return Changed;
576  case LibFunc::times:
577  Changed |= setDoesNotThrow(F);
578  Changed |= setDoesNotCapture(F, 1);
579  return Changed;
580  case LibFunc::htonl:
581  case LibFunc::htons:
582  case LibFunc::ntohl:
583  case LibFunc::ntohs:
584  Changed |= setDoesNotThrow(F);
585  Changed |= setDoesNotAccessMemory(F);
586  return Changed;
587  case LibFunc::lstat:
588  Changed |= setDoesNotThrow(F);
589  Changed |= setDoesNotCapture(F, 1);
590  Changed |= setDoesNotCapture(F, 2);
591  Changed |= setOnlyReadsMemory(F, 1);
592  return Changed;
593  case LibFunc::lchown:
594  Changed |= setDoesNotThrow(F);
595  Changed |= setDoesNotCapture(F, 1);
596  Changed |= setOnlyReadsMemory(F, 1);
597  return Changed;
598  case LibFunc::qsort:
599  // May throw; places call through function pointer.
600  Changed |= setDoesNotCapture(F, 4);
601  return Changed;
602  case LibFunc::dunder_strdup:
603  case LibFunc::dunder_strndup:
604  Changed |= setDoesNotThrow(F);
605  Changed |= setDoesNotAlias(F, 0);
606  Changed |= setDoesNotCapture(F, 1);
607  Changed |= setOnlyReadsMemory(F, 1);
608  return Changed;
609  case LibFunc::dunder_strtok_r:
610  Changed |= setDoesNotThrow(F);
611  Changed |= setDoesNotCapture(F, 2);
612  Changed |= setOnlyReadsMemory(F, 2);
613  return Changed;
614  case LibFunc::under_IO_getc:
615  Changed |= setDoesNotThrow(F);
616  Changed |= setDoesNotCapture(F, 1);
617  return Changed;
618  case LibFunc::under_IO_putc:
619  Changed |= setDoesNotThrow(F);
620  Changed |= setDoesNotCapture(F, 2);
621  return Changed;
622  case LibFunc::dunder_isoc99_scanf:
623  Changed |= setDoesNotThrow(F);
624  Changed |= setDoesNotCapture(F, 1);
625  Changed |= setOnlyReadsMemory(F, 1);
626  return Changed;
627  case LibFunc::stat64:
628  case LibFunc::lstat64:
629  case LibFunc::statvfs64:
630  Changed |= setDoesNotThrow(F);
631  Changed |= setDoesNotCapture(F, 1);
632  Changed |= setDoesNotCapture(F, 2);
633  Changed |= setOnlyReadsMemory(F, 1);
634  return Changed;
635  case LibFunc::dunder_isoc99_sscanf:
636  Changed |= setDoesNotThrow(F);
637  Changed |= setDoesNotCapture(F, 1);
638  Changed |= setDoesNotCapture(F, 2);
639  Changed |= setOnlyReadsMemory(F, 1);
640  Changed |= setOnlyReadsMemory(F, 2);
641  return Changed;
642  case LibFunc::fopen64:
643  Changed |= setDoesNotThrow(F);
644  Changed |= setDoesNotAlias(F, 0);
645  Changed |= setDoesNotCapture(F, 1);
646  Changed |= setDoesNotCapture(F, 2);
647  Changed |= setOnlyReadsMemory(F, 1);
648  Changed |= setOnlyReadsMemory(F, 2);
649  return Changed;
650  case LibFunc::fseeko64:
651  case LibFunc::ftello64:
652  Changed |= setDoesNotThrow(F);
653  Changed |= setDoesNotCapture(F, 1);
654  return Changed;
655  case LibFunc::tmpfile64:
656  Changed |= setDoesNotThrow(F);
657  Changed |= setDoesNotAlias(F, 0);
658  return Changed;
659  case LibFunc::fstat64:
660  case LibFunc::fstatvfs64:
661  Changed |= setDoesNotThrow(F);
662  Changed |= setDoesNotCapture(F, 2);
663  return Changed;
664  case LibFunc::open64:
665  // May throw; "open" is a valid pthread cancellation point.
666  Changed |= setDoesNotCapture(F, 1);
667  Changed |= setOnlyReadsMemory(F, 1);
668  return Changed;
669  case LibFunc::gettimeofday:
670  // Currently some platforms have the restrict keyword on the arguments to
671  // gettimeofday. To be conservative, do not add noalias to gettimeofday's
672  // arguments.
673  Changed |= setDoesNotThrow(F);
674  Changed |= setDoesNotCapture(F, 1);
675  Changed |= setDoesNotCapture(F, 2);
676  return Changed;
677  case LibFunc::Znwj: // new(unsigned int)
678  case LibFunc::Znwm: // new(unsigned long)
679  case LibFunc::Znaj: // new[](unsigned int)
680  case LibFunc::Znam: // new[](unsigned long)
681  case LibFunc::msvc_new_int: // new(unsigned int)
682  case LibFunc::msvc_new_longlong: // new(unsigned long long)
683  case LibFunc::msvc_new_array_int: // new[](unsigned int)
684  case LibFunc::msvc_new_array_longlong: // new[](unsigned long long)
685  // Operator new always returns a nonnull noalias pointer
686  Changed |= setNonNull(F, AttributeSet::ReturnIndex);
688  return Changed;
689  //TODO: add LibFunc entries for:
690  //case LibFunc::memset_pattern4:
691  //case LibFunc::memset_pattern8:
692  case LibFunc::memset_pattern16:
693  Changed |= setOnlyAccessesArgMemory(F);
694  Changed |= setDoesNotCapture(F, 1);
695  Changed |= setDoesNotCapture(F, 2);
696  Changed |= setOnlyReadsMemory(F, 2);
697  return Changed;
698  // int __nvvm_reflect(const char *)
699  case LibFunc::nvvm_reflect:
700  Changed |= setDoesNotAccessMemory(F);
701  Changed |= setDoesNotThrow(F);
702  return Changed;
703 
704  default:
705  // FIXME: It'd be really nice to cover all the library functions we're
706  // aware of here.
707  return false;
708  }
709 }
710 
711 //- Emit LibCalls ------------------------------------------------------------//
712 
714  unsigned AS = V->getType()->getPointerAddressSpace();
715  return B.CreateBitCast(V, B.getInt8PtrTy(AS), "cstr");
716 }
717 
719  const TargetLibraryInfo *TLI) {
720  if (!TLI->has(LibFunc::strlen))
721  return nullptr;
722 
723  Module *M = B.GetInsertBlock()->getModule();
725  Constant *StrLen = M->getOrInsertFunction("strlen", DL.getIntPtrType(Context),
726  B.getInt8PtrTy(), nullptr);
727  inferLibFuncAttributes(*M->getFunction("strlen"), *TLI);
728  CallInst *CI = B.CreateCall(StrLen, castToCStr(Ptr, B), "strlen");
729  if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts()))
730  CI->setCallingConv(F->getCallingConv());
731 
732  return CI;
733 }
734 
736  const TargetLibraryInfo *TLI) {
737  if (!TLI->has(LibFunc::strchr))
738  return nullptr;
739 
740  Module *M = B.GetInsertBlock()->getModule();
741  Type *I8Ptr = B.getInt8PtrTy();
742  Type *I32Ty = B.getInt32Ty();
743  Constant *StrChr =
744  M->getOrInsertFunction("strchr", I8Ptr, I8Ptr, I32Ty, nullptr);
745  inferLibFuncAttributes(*M->getFunction("strchr"), *TLI);
746  CallInst *CI = B.CreateCall(
747  StrChr, {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, "strchr");
748  if (const Function *F = dyn_cast<Function>(StrChr->stripPointerCasts()))
749  CI->setCallingConv(F->getCallingConv());
750  return CI;
751 }
752 
754  const DataLayout &DL, const TargetLibraryInfo *TLI) {
755  if (!TLI->has(LibFunc::strncmp))
756  return nullptr;
757 
758  Module *M = B.GetInsertBlock()->getModule();
760  Value *StrNCmp = M->getOrInsertFunction("strncmp", B.getInt32Ty(),
761  B.getInt8PtrTy(), B.getInt8PtrTy(),
762  DL.getIntPtrType(Context), nullptr);
763  inferLibFuncAttributes(*M->getFunction("strncmp"), *TLI);
764  CallInst *CI = B.CreateCall(
765  StrNCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "strncmp");
766 
767  if (const Function *F = dyn_cast<Function>(StrNCmp->stripPointerCasts()))
768  CI->setCallingConv(F->getCallingConv());
769 
770  return CI;
771 }
772 
774  const TargetLibraryInfo *TLI, StringRef Name) {
775  if (!TLI->has(LibFunc::strcpy))
776  return nullptr;
777 
778  Module *M = B.GetInsertBlock()->getModule();
779  Type *I8Ptr = B.getInt8PtrTy();
780  Value *StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr, nullptr);
781  inferLibFuncAttributes(*M->getFunction(Name), *TLI);
782  CallInst *CI =
783  B.CreateCall(StrCpy, {castToCStr(Dst, B), castToCStr(Src, B)}, Name);
784  if (const Function *F = dyn_cast<Function>(StrCpy->stripPointerCasts()))
785  CI->setCallingConv(F->getCallingConv());
786  return CI;
787 }
788 
790  const TargetLibraryInfo *TLI, StringRef Name) {
791  if (!TLI->has(LibFunc::strncpy))
792  return nullptr;
793 
794  Module *M = B.GetInsertBlock()->getModule();
795  Type *I8Ptr = B.getInt8PtrTy();
796  Value *StrNCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr,
797  Len->getType(), nullptr);
798  inferLibFuncAttributes(*M->getFunction(Name), *TLI);
799  CallInst *CI = B.CreateCall(
800  StrNCpy, {castToCStr(Dst, B), castToCStr(Src, B), Len}, "strncpy");
801  if (const Function *F = dyn_cast<Function>(StrNCpy->stripPointerCasts()))
802  CI->setCallingConv(F->getCallingConv());
803  return CI;
804 }
805 
806 Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
807  IRBuilder<> &B, const DataLayout &DL,
808  const TargetLibraryInfo *TLI) {
809  if (!TLI->has(LibFunc::memcpy_chk))
810  return nullptr;
811 
812  Module *M = B.GetInsertBlock()->getModule();
813  AttributeSet AS;
814  AS = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
815  Attribute::NoUnwind);
817  Value *MemCpy = M->getOrInsertFunction(
818  "__memcpy_chk", AttributeSet::get(M->getContext(), AS), B.getInt8PtrTy(),
819  B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context),
820  DL.getIntPtrType(Context), nullptr);
821  Dst = castToCStr(Dst, B);
822  Src = castToCStr(Src, B);
823  CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
824  if (const Function *F = dyn_cast<Function>(MemCpy->stripPointerCasts()))
825  CI->setCallingConv(F->getCallingConv());
826  return CI;
827 }
828 
830  const DataLayout &DL, const TargetLibraryInfo *TLI) {
831  if (!TLI->has(LibFunc::memchr))
832  return nullptr;
833 
834  Module *M = B.GetInsertBlock()->getModule();
836  Value *MemChr = M->getOrInsertFunction("memchr", B.getInt8PtrTy(),
837  B.getInt8PtrTy(), B.getInt32Ty(),
838  DL.getIntPtrType(Context), nullptr);
839  inferLibFuncAttributes(*M->getFunction("memchr"), *TLI);
840  CallInst *CI = B.CreateCall(MemChr, {castToCStr(Ptr, B), Val, Len}, "memchr");
841 
842  if (const Function *F = dyn_cast<Function>(MemChr->stripPointerCasts()))
843  CI->setCallingConv(F->getCallingConv());
844 
845  return CI;
846 }
847 
849  const DataLayout &DL, const TargetLibraryInfo *TLI) {
850  if (!TLI->has(LibFunc::memcmp))
851  return nullptr;
852 
853  Module *M = B.GetInsertBlock()->getModule();
855  Value *MemCmp = M->getOrInsertFunction("memcmp", B.getInt32Ty(),
856  B.getInt8PtrTy(), B.getInt8PtrTy(),
857  DL.getIntPtrType(Context), nullptr);
858  inferLibFuncAttributes(*M->getFunction("memcmp"), *TLI);
859  CallInst *CI = B.CreateCall(
860  MemCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "memcmp");
861 
862  if (const Function *F = dyn_cast<Function>(MemCmp->stripPointerCasts()))
863  CI->setCallingConv(F->getCallingConv());
864 
865  return CI;
866 }
867 
868 /// Append a suffix to the function name according to the type of 'Op'.
870  SmallString<20> &NameBuffer) {
871  if (!Op->getType()->isDoubleTy()) {
872  NameBuffer += Name;
873 
874  if (Op->getType()->isFloatTy())
875  NameBuffer += 'f';
876  else
877  NameBuffer += 'l';
878 
879  Name = NameBuffer;
880  }
881 }
882 
884  const AttributeSet &Attrs) {
885  SmallString<20> NameBuffer;
886  appendTypeSuffix(Op, Name, NameBuffer);
887 
888  Module *M = B.GetInsertBlock()->getModule();
889  Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
890  Op->getType(), nullptr);
891  CallInst *CI = B.CreateCall(Callee, Op, Name);
892  CI->setAttributes(Attrs);
893  if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
894  CI->setCallingConv(F->getCallingConv());
895 
896  return CI;
897 }
898 
900  IRBuilder<> &B, const AttributeSet &Attrs) {
901  SmallString<20> NameBuffer;
902  appendTypeSuffix(Op1, Name, NameBuffer);
903 
904  Module *M = B.GetInsertBlock()->getModule();
905  Value *Callee = M->getOrInsertFunction(Name, Op1->getType(), Op1->getType(),
906  Op2->getType(), nullptr);
907  CallInst *CI = B.CreateCall(Callee, {Op1, Op2}, Name);
908  CI->setAttributes(Attrs);
909  if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
910  CI->setCallingConv(F->getCallingConv());
911 
912  return CI;
913 }
914 
916  const TargetLibraryInfo *TLI) {
917  if (!TLI->has(LibFunc::putchar))
918  return nullptr;
919 
920  Module *M = B.GetInsertBlock()->getModule();
921  Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(),
922  B.getInt32Ty(), nullptr);
923  CallInst *CI = B.CreateCall(PutChar,
924  B.CreateIntCast(Char,
925  B.getInt32Ty(),
926  /*isSigned*/true,
927  "chari"),
928  "putchar");
929 
930  if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts()))
931  CI->setCallingConv(F->getCallingConv());
932  return CI;
933 }
934 
936  const TargetLibraryInfo *TLI) {
937  if (!TLI->has(LibFunc::puts))
938  return nullptr;
939 
940  Module *M = B.GetInsertBlock()->getModule();
941  Value *PutS =
942  M->getOrInsertFunction("puts", B.getInt32Ty(), B.getInt8PtrTy(), nullptr);
943  inferLibFuncAttributes(*M->getFunction("puts"), *TLI);
944  CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), "puts");
945  if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts()))
946  CI->setCallingConv(F->getCallingConv());
947  return CI;
948 }
949 
951  const TargetLibraryInfo *TLI) {
952  if (!TLI->has(LibFunc::fputc))
953  return nullptr;
954 
955  Module *M = B.GetInsertBlock()->getModule();
956  Constant *F = M->getOrInsertFunction("fputc", B.getInt32Ty(), B.getInt32Ty(),
957  File->getType(), nullptr);
958  if (File->getType()->isPointerTy())
959  inferLibFuncAttributes(*M->getFunction("fputc"), *TLI);
960  Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
961  "chari");
962  CallInst *CI = B.CreateCall(F, {Char, File}, "fputc");
963 
964  if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
965  CI->setCallingConv(Fn->getCallingConv());
966  return CI;
967 }
968 
970  const TargetLibraryInfo *TLI) {
971  if (!TLI->has(LibFunc::fputs))
972  return nullptr;
973 
974  Module *M = B.GetInsertBlock()->getModule();
975  StringRef FPutsName = TLI->getName(LibFunc::fputs);
977  FPutsName, B.getInt32Ty(), B.getInt8PtrTy(), File->getType(), nullptr);
978  if (File->getType()->isPointerTy())
979  inferLibFuncAttributes(*M->getFunction(FPutsName), *TLI);
980  CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, "fputs");
981 
982  if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
983  CI->setCallingConv(Fn->getCallingConv());
984  return CI;
985 }
986 
988  const DataLayout &DL, const TargetLibraryInfo *TLI) {
989  if (!TLI->has(LibFunc::fwrite))
990  return nullptr;
991 
992  Module *M = B.GetInsertBlock()->getModule();
994  StringRef FWriteName = TLI->getName(LibFunc::fwrite);
996  FWriteName, DL.getIntPtrType(Context), B.getInt8PtrTy(),
997  DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType(),
998  nullptr);
999  if (File->getType()->isPointerTy())
1000  inferLibFuncAttributes(*M->getFunction(FWriteName), *TLI);
1001  CallInst *CI =
1002  B.CreateCall(F, {castToCStr(Ptr, B), Size,
1003  ConstantInt::get(DL.getIntPtrType(Context), 1), File});
1004 
1005  if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
1006  CI->setCallingConv(Fn->getCallingConv());
1007  return CI;
1008 }
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:102
LLVMContext & Context
STATISTIC(NumFunctions,"Total number of functions")
value_type read(const void *memory)
Read a value of a particular endianness from memory.
Definition: Endian.h:48
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
Definition: Function.h:321
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:52
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
This class represents a function call, abstracting a target machine's calling convention.
interleaved access
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:148
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.cpp:238
Value * emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B, const AttributeSet &Attrs)
Emit a call to the unary function named 'Name' (e.g.
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...
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
Definition: Attributes.cpp:994
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with strcmp
bool doesNotAlias(unsigned n) const
Determine if the parameter or return value is marked with NoAlias attribute.
Definition: Function.h:429
void setCallingConv(CallingConv::ID CC)
void setDoesNotThrow()
Definition: Function.h:373
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition: IRBuilder.h:347
bool doesNotThrow() const
Determine if the function cannot unwind.
Definition: Function.h:370
bool has(LibFunc::Func F) const
Tests whether a library function is available.
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
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:588
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1362
#define F(x, y, z)
Definition: MD5.cpp:51
static bool setDoesNotThrow(Function &F)
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.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
IEEEFloat frexp(const IEEEFloat &Val, int &Exp, IEEEFloat::roundingMode RM)
Definition: APFloat.cpp:3839
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.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
bool doesNotAccessMemory() const
Determine if the function does not access memory.
Definition: Function.h:313
void setOnlyAccessesArgMemory()
Definition: Function.h:341
void setAttributes(AttributeSet Attrs)
Set the parameter attributes for this call.
void setDoesNotCapture(unsigned n)
Definition: Function.h:441
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:196
Value * emitFPutS(Value *Str, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function.
bool getLibFunc(StringRef funcName, LibFunc::Func &F) const
Searches for a particular function name.
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
void setOnlyReadsMemory()
Definition: Function.h:324
Constant * stripPointerCasts()
Definition: Constant.h:155
static void appendTypeSuffix(Value *Op, StringRef &Name, SmallString< 20 > &NameBuffer)
Append a suffix to the function name according to the type of 'Op'.
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:123
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
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 isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:145
static bool setOnlyReadsMemory(Function &F)
void setDoesNotAlias(unsigned n)
Definition: Function.h:432
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
Definition: Function.cpp:364
Value * castToCStr(Value *V, IRBuilder<> &B)
Return V if it is an i8*, otherwise cast it to i8*.
static bool setDoesNotAccessMemory(Function &F)
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:213
static void write(bool isBE, void *P, T V)
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:385
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
Definition: Function.h:338
static bool setNonNull(Function &F, unsigned n)
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:709
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 * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition: IRBuilder.h:1425
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
Provides information about what library functions are available for the current target.
BasicBlock * GetInsertBlock() const
Definition: IRBuilder.h:121
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
Definition: Value.cpp:490
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:558
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
AttributeSet getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:176
Value * emitFPutC(Value *Char, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
StringRef getName(LibFunc::Func F) const
void setDoesNotAccessMemory()
Definition: Function.h:316
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.
static bool setOnlyAccessesArgMemory(Function &F)
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1579
static void rename(GlobalValue *GV)
Definition: AutoUpgrade.cpp:34
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())
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:33
static bool setDoesNotCapture(Function &F, unsigned n)
LLVM Value Representation.
Definition: Value.h:71
bool doesNotCapture(unsigned n) const
Determine if the parameter can be captured.
Definition: Function.h:438
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:47
int * Ptr
Value * emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name, IRBuilder<> &B, const AttributeSet &Attrs)
Emit a call to the binary function named 'Name' (e.g.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:479
static bool setDoesNotAlias(Function &F, unsigned n)
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:222