LLVM  10.0.0svn
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(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 STATISTIC(NumReturnedArg, "Number of arguments inferred as returned");
42 
44  if (F.doesNotAccessMemory())
45  return false;
47  ++NumReadNone;
48  return true;
49 }
50 
51 static bool setOnlyReadsMemory(Function &F) {
52  if (F.onlyReadsMemory())
53  return false;
55  ++NumReadOnly;
56  return true;
57 }
58 
60  if (F.onlyAccessesArgMemory())
61  return false;
63  ++NumArgMemOnly;
64  return true;
65 }
66 
67 static bool setDoesNotThrow(Function &F) {
68  if (F.doesNotThrow())
69  return false;
70  F.setDoesNotThrow();
71  ++NumNoUnwind;
72  return true;
73 }
74 
75 static bool setRetDoesNotAlias(Function &F) {
77  return false;
79  ++NumNoAlias;
80  return true;
81 }
82 
83 static bool setDoesNotCapture(Function &F, unsigned ArgNo) {
84  if (F.hasParamAttribute(ArgNo, Attribute::NoCapture))
85  return false;
86  F.addParamAttr(ArgNo, Attribute::NoCapture);
87  ++NumNoCapture;
88  return true;
89 }
90 
91 static bool setDoesNotAlias(Function &F, unsigned ArgNo) {
93  return false;
95  ++NumNoAlias;
96  return true;
97 }
98 
99 static bool setOnlyReadsMemory(Function &F, unsigned ArgNo) {
100  if (F.hasParamAttribute(ArgNo, Attribute::ReadOnly))
101  return false;
102  F.addParamAttr(ArgNo, Attribute::ReadOnly);
103  ++NumReadOnlyArg;
104  return true;
105 }
106 
107 static bool setRetNonNull(Function &F) {
109  "nonnull applies only to pointers");
110  if (F.hasAttribute(AttributeList::ReturnIndex, Attribute::NonNull))
111  return false;
112  F.addAttribute(AttributeList::ReturnIndex, Attribute::NonNull);
113  ++NumNonNull;
114  return true;
115 }
116 
117 static bool setReturnedArg(Function &F, unsigned ArgNo) {
118  if (F.hasParamAttribute(ArgNo, Attribute::Returned))
119  return false;
120  F.addParamAttr(ArgNo, Attribute::Returned);
121  ++NumReturnedArg;
122  return true;
123 }
124 
125 static bool setNonLazyBind(Function &F) {
126  if (F.hasFnAttribute(Attribute::NonLazyBind))
127  return false;
128  F.addFnAttr(Attribute::NonLazyBind);
129  return true;
130 }
131 
133  if (F.hasFnAttribute(Attribute::NoFree))
134  return false;
135  F.addFnAttr(Attribute::NoFree);
136  return true;
137 }
138 
140  const TargetLibraryInfo &TLI) {
141  Function *F = M->getFunction(Name);
142  if (!F)
143  return false;
144  return inferLibFuncAttributes(*F, TLI);
145 }
146 
148  LibFunc TheLibFunc;
149  if (!(TLI.getLibFunc(F, TheLibFunc) && TLI.has(TheLibFunc)))
150  return false;
151 
152  bool Changed = false;
153 
154  if(!isLibFreeFunction(&F, TheLibFunc) && !isReallocLikeFn(&F, &TLI))
155  Changed |= setDoesNotFreeMemory(F);
156 
157  if (F.getParent() != nullptr && F.getParent()->getRtLibUseGOT())
158  Changed |= setNonLazyBind(F);
159 
160  switch (TheLibFunc) {
161  case LibFunc_strlen:
162  case LibFunc_wcslen:
163  Changed |= setOnlyReadsMemory(F);
164  Changed |= setDoesNotThrow(F);
165  Changed |= setOnlyAccessesArgMemory(F);
166  Changed |= setDoesNotCapture(F, 0);
167  return Changed;
168  case LibFunc_strchr:
169  case LibFunc_strrchr:
170  Changed |= setOnlyReadsMemory(F);
171  Changed |= setDoesNotThrow(F);
172  return Changed;
173  case LibFunc_strtol:
174  case LibFunc_strtod:
175  case LibFunc_strtof:
176  case LibFunc_strtoul:
177  case LibFunc_strtoll:
178  case LibFunc_strtold:
179  case LibFunc_strtoull:
180  Changed |= setDoesNotThrow(F);
181  Changed |= setDoesNotCapture(F, 1);
182  Changed |= setOnlyReadsMemory(F, 0);
183  return Changed;
184  case LibFunc_strcpy:
185  case LibFunc_strncpy:
186  Changed |= setDoesNotAlias(F, 0);
187  Changed |= setDoesNotAlias(F, 1);
189  case LibFunc_strcat:
190  case LibFunc_strncat:
191  Changed |= setReturnedArg(F, 0);
193  case LibFunc_stpcpy:
194  case LibFunc_stpncpy:
195  Changed |= setDoesNotThrow(F);
196  Changed |= setDoesNotCapture(F, 1);
197  Changed |= setOnlyReadsMemory(F, 1);
198  return Changed;
199  case LibFunc_strxfrm:
200  Changed |= setDoesNotThrow(F);
201  Changed |= setDoesNotCapture(F, 0);
202  Changed |= setDoesNotCapture(F, 1);
203  Changed |= setOnlyReadsMemory(F, 1);
204  return Changed;
205  case LibFunc_strcmp: // 0,1
206  case LibFunc_strspn: // 0,1
207  case LibFunc_strncmp: // 0,1
208  case LibFunc_strcspn: // 0,1
209  case LibFunc_strcoll: // 0,1
210  case LibFunc_strcasecmp: // 0,1
211  case LibFunc_strncasecmp: //
212  Changed |= setOnlyReadsMemory(F);
213  Changed |= setDoesNotThrow(F);
214  Changed |= setDoesNotCapture(F, 0);
215  Changed |= setDoesNotCapture(F, 1);
216  return Changed;
217  case LibFunc_strstr:
218  case LibFunc_strpbrk:
219  Changed |= setOnlyReadsMemory(F);
220  Changed |= setDoesNotThrow(F);
221  Changed |= setDoesNotCapture(F, 1);
222  return Changed;
223  case LibFunc_strtok:
224  case LibFunc_strtok_r:
225  Changed |= setDoesNotThrow(F);
226  Changed |= setDoesNotCapture(F, 1);
227  Changed |= setOnlyReadsMemory(F, 1);
228  return Changed;
229  case LibFunc_scanf:
230  Changed |= setDoesNotThrow(F);
231  Changed |= setDoesNotCapture(F, 0);
232  Changed |= setOnlyReadsMemory(F, 0);
233  return Changed;
234  case LibFunc_setbuf:
235  case LibFunc_setvbuf:
236  Changed |= setDoesNotThrow(F);
237  Changed |= setDoesNotCapture(F, 0);
238  return Changed;
239  case LibFunc_strdup:
240  case LibFunc_strndup:
241  Changed |= setDoesNotThrow(F);
242  Changed |= setRetDoesNotAlias(F);
243  Changed |= setDoesNotCapture(F, 0);
244  Changed |= setOnlyReadsMemory(F, 0);
245  return Changed;
246  case LibFunc_stat:
247  case LibFunc_statvfs:
248  Changed |= setDoesNotThrow(F);
249  Changed |= setDoesNotCapture(F, 0);
250  Changed |= setDoesNotCapture(F, 1);
251  Changed |= setOnlyReadsMemory(F, 0);
252  return Changed;
253  case LibFunc_sscanf:
254  Changed |= setDoesNotThrow(F);
255  Changed |= setDoesNotCapture(F, 0);
256  Changed |= setDoesNotCapture(F, 1);
257  Changed |= setOnlyReadsMemory(F, 0);
258  Changed |= setOnlyReadsMemory(F, 1);
259  return Changed;
260  case LibFunc_sprintf:
261  Changed |= setDoesNotThrow(F);
262  Changed |= setDoesNotCapture(F, 0);
263  Changed |= setDoesNotAlias(F, 0);
264  Changed |= setDoesNotCapture(F, 1);
265  Changed |= setOnlyReadsMemory(F, 1);
266  return Changed;
267  case LibFunc_snprintf:
268  Changed |= setDoesNotThrow(F);
269  Changed |= setDoesNotCapture(F, 0);
270  Changed |= setDoesNotAlias(F, 0);
271  Changed |= setDoesNotCapture(F, 2);
272  Changed |= setOnlyReadsMemory(F, 2);
273  return Changed;
274  case LibFunc_setitimer:
275  Changed |= setDoesNotThrow(F);
276  Changed |= setDoesNotCapture(F, 1);
277  Changed |= setDoesNotCapture(F, 2);
278  Changed |= setOnlyReadsMemory(F, 1);
279  return Changed;
280  case LibFunc_system:
281  // May throw; "system" is a valid pthread cancellation point.
282  Changed |= setDoesNotCapture(F, 0);
283  Changed |= setOnlyReadsMemory(F, 0);
284  return Changed;
285  case LibFunc_malloc:
286  Changed |= setDoesNotThrow(F);
287  Changed |= setRetDoesNotAlias(F);
288  return Changed;
289  case LibFunc_memcmp:
290  Changed |= setOnlyReadsMemory(F);
291  Changed |= setDoesNotThrow(F);
292  Changed |= setDoesNotCapture(F, 0);
293  Changed |= setDoesNotCapture(F, 1);
294  return Changed;
295  case LibFunc_memchr:
296  case LibFunc_memrchr:
297  Changed |= setOnlyReadsMemory(F);
298  Changed |= setDoesNotThrow(F);
299  return Changed;
300  case LibFunc_modf:
301  case LibFunc_modff:
302  case LibFunc_modfl:
303  Changed |= setDoesNotThrow(F);
304  Changed |= setDoesNotCapture(F, 1);
305  return Changed;
306  case LibFunc_memcpy:
307  Changed |= setDoesNotAlias(F, 0);
308  Changed |= setDoesNotAlias(F, 1);
310  case LibFunc_memmove:
311  Changed |= setReturnedArg(F, 0);
313  case LibFunc_mempcpy:
314  case LibFunc_memccpy:
315  Changed |= setDoesNotThrow(F);
316  Changed |= setDoesNotCapture(F, 1);
317  Changed |= setOnlyReadsMemory(F, 1);
318  return Changed;
319  case LibFunc_memcpy_chk:
320  Changed |= setDoesNotThrow(F);
321  return Changed;
322  case LibFunc_memalign:
323  Changed |= setRetDoesNotAlias(F);
324  return Changed;
325  case LibFunc_mkdir:
326  Changed |= setDoesNotThrow(F);
327  Changed |= setDoesNotCapture(F, 0);
328  Changed |= setOnlyReadsMemory(F, 0);
329  return Changed;
330  case LibFunc_mktime:
331  Changed |= setDoesNotThrow(F);
332  Changed |= setDoesNotCapture(F, 0);
333  return Changed;
334  case LibFunc_realloc:
335  Changed |= setDoesNotThrow(F);
336  Changed |= setRetDoesNotAlias(F);
337  Changed |= setDoesNotCapture(F, 0);
338  return Changed;
339  case LibFunc_read:
340  // May throw; "read" is a valid pthread cancellation point.
341  Changed |= setDoesNotCapture(F, 1);
342  return Changed;
343  case LibFunc_rewind:
344  Changed |= setDoesNotThrow(F);
345  Changed |= setDoesNotCapture(F, 0);
346  return Changed;
347  case LibFunc_rmdir:
348  case LibFunc_remove:
349  case LibFunc_realpath:
350  Changed |= setDoesNotThrow(F);
351  Changed |= setDoesNotCapture(F, 0);
352  Changed |= setOnlyReadsMemory(F, 0);
353  return Changed;
354  case LibFunc_rename:
355  Changed |= setDoesNotThrow(F);
356  Changed |= setDoesNotCapture(F, 0);
357  Changed |= setDoesNotCapture(F, 1);
358  Changed |= setOnlyReadsMemory(F, 0);
359  Changed |= setOnlyReadsMemory(F, 1);
360  return Changed;
361  case LibFunc_readlink:
362  Changed |= setDoesNotThrow(F);
363  Changed |= setDoesNotCapture(F, 0);
364  Changed |= setDoesNotCapture(F, 1);
365  Changed |= setOnlyReadsMemory(F, 0);
366  return Changed;
367  case LibFunc_write:
368  // May throw; "write" is a valid pthread cancellation point.
369  Changed |= setDoesNotCapture(F, 1);
370  Changed |= setOnlyReadsMemory(F, 1);
371  return Changed;
372  case LibFunc_bcopy:
373  Changed |= setDoesNotThrow(F);
374  Changed |= setDoesNotCapture(F, 0);
375  Changed |= setDoesNotCapture(F, 1);
376  Changed |= setOnlyReadsMemory(F, 0);
377  return Changed;
378  case LibFunc_bcmp:
379  Changed |= setDoesNotThrow(F);
380  Changed |= setOnlyReadsMemory(F);
381  Changed |= setDoesNotCapture(F, 0);
382  Changed |= setDoesNotCapture(F, 1);
383  return Changed;
384  case LibFunc_bzero:
385  Changed |= setDoesNotThrow(F);
386  Changed |= setDoesNotCapture(F, 0);
387  return Changed;
388  case LibFunc_calloc:
389  Changed |= setDoesNotThrow(F);
390  Changed |= setRetDoesNotAlias(F);
391  return Changed;
392  case LibFunc_chmod:
393  case LibFunc_chown:
394  Changed |= setDoesNotThrow(F);
395  Changed |= setDoesNotCapture(F, 0);
396  Changed |= setOnlyReadsMemory(F, 0);
397  return Changed;
398  case LibFunc_ctermid:
399  case LibFunc_clearerr:
400  case LibFunc_closedir:
401  Changed |= setDoesNotThrow(F);
402  Changed |= setDoesNotCapture(F, 0);
403  return Changed;
404  case LibFunc_atoi:
405  case LibFunc_atol:
406  case LibFunc_atof:
407  case LibFunc_atoll:
408  Changed |= setDoesNotThrow(F);
409  Changed |= setOnlyReadsMemory(F);
410  Changed |= setDoesNotCapture(F, 0);
411  return Changed;
412  case LibFunc_access:
413  Changed |= setDoesNotThrow(F);
414  Changed |= setDoesNotCapture(F, 0);
415  Changed |= setOnlyReadsMemory(F, 0);
416  return Changed;
417  case LibFunc_fopen:
418  Changed |= setDoesNotThrow(F);
419  Changed |= setRetDoesNotAlias(F);
420  Changed |= setDoesNotCapture(F, 0);
421  Changed |= setDoesNotCapture(F, 1);
422  Changed |= setOnlyReadsMemory(F, 0);
423  Changed |= setOnlyReadsMemory(F, 1);
424  return Changed;
425  case LibFunc_fdopen:
426  Changed |= setDoesNotThrow(F);
427  Changed |= setRetDoesNotAlias(F);
428  Changed |= setDoesNotCapture(F, 1);
429  Changed |= setOnlyReadsMemory(F, 1);
430  return Changed;
431  case LibFunc_feof:
432  case LibFunc_free:
433  case LibFunc_fseek:
434  case LibFunc_ftell:
435  case LibFunc_fgetc:
436  case LibFunc_fgetc_unlocked:
437  case LibFunc_fseeko:
438  case LibFunc_ftello:
439  case LibFunc_fileno:
440  case LibFunc_fflush:
441  case LibFunc_fclose:
442  case LibFunc_fsetpos:
443  case LibFunc_flockfile:
444  case LibFunc_funlockfile:
445  case LibFunc_ftrylockfile:
446  Changed |= setDoesNotThrow(F);
447  Changed |= setDoesNotCapture(F, 0);
448  return Changed;
449  case LibFunc_ferror:
450  Changed |= setDoesNotThrow(F);
451  Changed |= setDoesNotCapture(F, 0);
452  Changed |= setOnlyReadsMemory(F);
453  return Changed;
454  case LibFunc_fputc:
455  case LibFunc_fputc_unlocked:
456  case LibFunc_fstat:
457  case LibFunc_frexp:
458  case LibFunc_frexpf:
459  case LibFunc_frexpl:
460  case LibFunc_fstatvfs:
461  Changed |= setDoesNotThrow(F);
462  Changed |= setDoesNotCapture(F, 1);
463  return Changed;
464  case LibFunc_fgets:
465  case LibFunc_fgets_unlocked:
466  Changed |= setDoesNotThrow(F);
467  Changed |= setDoesNotCapture(F, 2);
468  return Changed;
469  case LibFunc_fread:
470  case LibFunc_fread_unlocked:
471  Changed |= setDoesNotThrow(F);
472  Changed |= setDoesNotCapture(F, 0);
473  Changed |= setDoesNotCapture(F, 3);
474  return Changed;
475  case LibFunc_fwrite:
476  case LibFunc_fwrite_unlocked:
477  Changed |= setDoesNotThrow(F);
478  Changed |= setDoesNotCapture(F, 0);
479  Changed |= setDoesNotCapture(F, 3);
480  // FIXME: readonly #1?
481  return Changed;
482  case LibFunc_fputs:
483  case LibFunc_fputs_unlocked:
484  Changed |= setDoesNotThrow(F);
485  Changed |= setDoesNotCapture(F, 0);
486  Changed |= setDoesNotCapture(F, 1);
487  Changed |= setOnlyReadsMemory(F, 0);
488  return Changed;
489  case LibFunc_fscanf:
490  case LibFunc_fprintf:
491  Changed |= setDoesNotThrow(F);
492  Changed |= setDoesNotCapture(F, 0);
493  Changed |= setDoesNotCapture(F, 1);
494  Changed |= setOnlyReadsMemory(F, 1);
495  return Changed;
496  case LibFunc_fgetpos:
497  Changed |= setDoesNotThrow(F);
498  Changed |= setDoesNotCapture(F, 0);
499  Changed |= setDoesNotCapture(F, 1);
500  return Changed;
501  case LibFunc_getc:
502  case LibFunc_getlogin_r:
503  case LibFunc_getc_unlocked:
504  Changed |= setDoesNotThrow(F);
505  Changed |= setDoesNotCapture(F, 0);
506  return Changed;
507  case LibFunc_getenv:
508  Changed |= setDoesNotThrow(F);
509  Changed |= setOnlyReadsMemory(F);
510  Changed |= setDoesNotCapture(F, 0);
511  return Changed;
512  case LibFunc_gets:
513  case LibFunc_getchar:
514  case LibFunc_getchar_unlocked:
515  Changed |= setDoesNotThrow(F);
516  return Changed;
517  case LibFunc_getitimer:
518  Changed |= setDoesNotThrow(F);
519  Changed |= setDoesNotCapture(F, 1);
520  return Changed;
521  case LibFunc_getpwnam:
522  Changed |= setDoesNotThrow(F);
523  Changed |= setDoesNotCapture(F, 0);
524  Changed |= setOnlyReadsMemory(F, 0);
525  return Changed;
526  case LibFunc_ungetc:
527  Changed |= setDoesNotThrow(F);
528  Changed |= setDoesNotCapture(F, 1);
529  return Changed;
530  case LibFunc_uname:
531  Changed |= setDoesNotThrow(F);
532  Changed |= setDoesNotCapture(F, 0);
533  return Changed;
534  case LibFunc_unlink:
535  Changed |= setDoesNotThrow(F);
536  Changed |= setDoesNotCapture(F, 0);
537  Changed |= setOnlyReadsMemory(F, 0);
538  return Changed;
539  case LibFunc_unsetenv:
540  Changed |= setDoesNotThrow(F);
541  Changed |= setDoesNotCapture(F, 0);
542  Changed |= setOnlyReadsMemory(F, 0);
543  return Changed;
544  case LibFunc_utime:
545  case LibFunc_utimes:
546  Changed |= setDoesNotThrow(F);
547  Changed |= setDoesNotCapture(F, 0);
548  Changed |= setDoesNotCapture(F, 1);
549  Changed |= setOnlyReadsMemory(F, 0);
550  Changed |= setOnlyReadsMemory(F, 1);
551  return Changed;
552  case LibFunc_putc:
553  case LibFunc_putc_unlocked:
554  Changed |= setDoesNotThrow(F);
555  Changed |= setDoesNotCapture(F, 1);
556  return Changed;
557  case LibFunc_puts:
558  case LibFunc_printf:
559  case LibFunc_perror:
560  Changed |= setDoesNotThrow(F);
561  Changed |= setDoesNotCapture(F, 0);
562  Changed |= setOnlyReadsMemory(F, 0);
563  return Changed;
564  case LibFunc_pread:
565  // May throw; "pread" is a valid pthread cancellation point.
566  Changed |= setDoesNotCapture(F, 1);
567  return Changed;
568  case LibFunc_pwrite:
569  // May throw; "pwrite" is a valid pthread cancellation point.
570  Changed |= setDoesNotCapture(F, 1);
571  Changed |= setOnlyReadsMemory(F, 1);
572  return Changed;
573  case LibFunc_putchar:
574  case LibFunc_putchar_unlocked:
575  Changed |= setDoesNotThrow(F);
576  return Changed;
577  case LibFunc_popen:
578  Changed |= setDoesNotThrow(F);
579  Changed |= setRetDoesNotAlias(F);
580  Changed |= setDoesNotCapture(F, 0);
581  Changed |= setDoesNotCapture(F, 1);
582  Changed |= setOnlyReadsMemory(F, 0);
583  Changed |= setOnlyReadsMemory(F, 1);
584  return Changed;
585  case LibFunc_pclose:
586  Changed |= setDoesNotThrow(F);
587  Changed |= setDoesNotCapture(F, 0);
588  return Changed;
589  case LibFunc_vscanf:
590  Changed |= setDoesNotThrow(F);
591  Changed |= setDoesNotCapture(F, 0);
592  Changed |= setOnlyReadsMemory(F, 0);
593  return Changed;
594  case LibFunc_vsscanf:
595  Changed |= setDoesNotThrow(F);
596  Changed |= setDoesNotCapture(F, 0);
597  Changed |= setDoesNotCapture(F, 1);
598  Changed |= setOnlyReadsMemory(F, 0);
599  Changed |= setOnlyReadsMemory(F, 1);
600  return Changed;
601  case LibFunc_vfscanf:
602  Changed |= setDoesNotThrow(F);
603  Changed |= setDoesNotCapture(F, 0);
604  Changed |= setDoesNotCapture(F, 1);
605  Changed |= setOnlyReadsMemory(F, 1);
606  return Changed;
607  case LibFunc_valloc:
608  Changed |= setDoesNotThrow(F);
609  Changed |= setRetDoesNotAlias(F);
610  return Changed;
611  case LibFunc_vprintf:
612  Changed |= setDoesNotThrow(F);
613  Changed |= setDoesNotCapture(F, 0);
614  Changed |= setOnlyReadsMemory(F, 0);
615  return Changed;
616  case LibFunc_vfprintf:
617  case LibFunc_vsprintf:
618  Changed |= setDoesNotThrow(F);
619  Changed |= setDoesNotCapture(F, 0);
620  Changed |= setDoesNotCapture(F, 1);
621  Changed |= setOnlyReadsMemory(F, 1);
622  return Changed;
623  case LibFunc_vsnprintf:
624  Changed |= setDoesNotThrow(F);
625  Changed |= setDoesNotCapture(F, 0);
626  Changed |= setDoesNotCapture(F, 2);
627  Changed |= setOnlyReadsMemory(F, 2);
628  return Changed;
629  case LibFunc_open:
630  // May throw; "open" is a valid pthread cancellation point.
631  Changed |= setDoesNotCapture(F, 0);
632  Changed |= setOnlyReadsMemory(F, 0);
633  return Changed;
634  case LibFunc_opendir:
635  Changed |= setDoesNotThrow(F);
636  Changed |= setRetDoesNotAlias(F);
637  Changed |= setDoesNotCapture(F, 0);
638  Changed |= setOnlyReadsMemory(F, 0);
639  return Changed;
640  case LibFunc_tmpfile:
641  Changed |= setDoesNotThrow(F);
642  Changed |= setRetDoesNotAlias(F);
643  return Changed;
644  case LibFunc_times:
645  Changed |= setDoesNotThrow(F);
646  Changed |= setDoesNotCapture(F, 0);
647  return Changed;
648  case LibFunc_htonl:
649  case LibFunc_htons:
650  case LibFunc_ntohl:
651  case LibFunc_ntohs:
652  Changed |= setDoesNotThrow(F);
653  Changed |= setDoesNotAccessMemory(F);
654  return Changed;
655  case LibFunc_lstat:
656  Changed |= setDoesNotThrow(F);
657  Changed |= setDoesNotCapture(F, 0);
658  Changed |= setDoesNotCapture(F, 1);
659  Changed |= setOnlyReadsMemory(F, 0);
660  return Changed;
661  case LibFunc_lchown:
662  Changed |= setDoesNotThrow(F);
663  Changed |= setDoesNotCapture(F, 0);
664  Changed |= setOnlyReadsMemory(F, 0);
665  return Changed;
666  case LibFunc_qsort:
667  // May throw; places call through function pointer.
668  Changed |= setDoesNotCapture(F, 3);
669  return Changed;
670  case LibFunc_dunder_strdup:
671  case LibFunc_dunder_strndup:
672  Changed |= setDoesNotThrow(F);
673  Changed |= setRetDoesNotAlias(F);
674  Changed |= setDoesNotCapture(F, 0);
675  Changed |= setOnlyReadsMemory(F, 0);
676  return Changed;
677  case LibFunc_dunder_strtok_r:
678  Changed |= setDoesNotThrow(F);
679  Changed |= setDoesNotCapture(F, 1);
680  Changed |= setOnlyReadsMemory(F, 1);
681  return Changed;
682  case LibFunc_under_IO_getc:
683  Changed |= setDoesNotThrow(F);
684  Changed |= setDoesNotCapture(F, 0);
685  return Changed;
686  case LibFunc_under_IO_putc:
687  Changed |= setDoesNotThrow(F);
688  Changed |= setDoesNotCapture(F, 1);
689  return Changed;
690  case LibFunc_dunder_isoc99_scanf:
691  Changed |= setDoesNotThrow(F);
692  Changed |= setDoesNotCapture(F, 0);
693  Changed |= setOnlyReadsMemory(F, 0);
694  return Changed;
695  case LibFunc_stat64:
696  case LibFunc_lstat64:
697  case LibFunc_statvfs64:
698  Changed |= setDoesNotThrow(F);
699  Changed |= setDoesNotCapture(F, 0);
700  Changed |= setDoesNotCapture(F, 1);
701  Changed |= setOnlyReadsMemory(F, 0);
702  return Changed;
703  case LibFunc_dunder_isoc99_sscanf:
704  Changed |= setDoesNotThrow(F);
705  Changed |= setDoesNotCapture(F, 0);
706  Changed |= setDoesNotCapture(F, 1);
707  Changed |= setOnlyReadsMemory(F, 0);
708  Changed |= setOnlyReadsMemory(F, 1);
709  return Changed;
710  case LibFunc_fopen64:
711  Changed |= setDoesNotThrow(F);
712  Changed |= setRetDoesNotAlias(F);
713  Changed |= setDoesNotCapture(F, 0);
714  Changed |= setDoesNotCapture(F, 1);
715  Changed |= setOnlyReadsMemory(F, 0);
716  Changed |= setOnlyReadsMemory(F, 1);
717  return Changed;
718  case LibFunc_fseeko64:
719  case LibFunc_ftello64:
720  Changed |= setDoesNotThrow(F);
721  Changed |= setDoesNotCapture(F, 0);
722  return Changed;
723  case LibFunc_tmpfile64:
724  Changed |= setDoesNotThrow(F);
725  Changed |= setRetDoesNotAlias(F);
726  return Changed;
727  case LibFunc_fstat64:
728  case LibFunc_fstatvfs64:
729  Changed |= setDoesNotThrow(F);
730  Changed |= setDoesNotCapture(F, 1);
731  return Changed;
732  case LibFunc_open64:
733  // May throw; "open" is a valid pthread cancellation point.
734  Changed |= setDoesNotCapture(F, 0);
735  Changed |= setOnlyReadsMemory(F, 0);
736  return Changed;
737  case LibFunc_gettimeofday:
738  // Currently some platforms have the restrict keyword on the arguments to
739  // gettimeofday. To be conservative, do not add noalias to gettimeofday's
740  // arguments.
741  Changed |= setDoesNotThrow(F);
742  Changed |= setDoesNotCapture(F, 0);
743  Changed |= setDoesNotCapture(F, 1);
744  return Changed;
745  case LibFunc_Znwj: // new(unsigned int)
746  case LibFunc_Znwm: // new(unsigned long)
747  case LibFunc_Znaj: // new[](unsigned int)
748  case LibFunc_Znam: // new[](unsigned long)
749  case LibFunc_msvc_new_int: // new(unsigned int)
750  case LibFunc_msvc_new_longlong: // new(unsigned long long)
751  case LibFunc_msvc_new_array_int: // new[](unsigned int)
752  case LibFunc_msvc_new_array_longlong: // new[](unsigned long long)
753  // Operator new always returns a nonnull noalias pointer
754  Changed |= setRetNonNull(F);
755  Changed |= setRetDoesNotAlias(F);
756  return Changed;
757  // TODO: add LibFunc entries for:
758  // case LibFunc_memset_pattern4:
759  // case LibFunc_memset_pattern8:
760  case LibFunc_memset_pattern16:
761  Changed |= setOnlyAccessesArgMemory(F);
762  Changed |= setDoesNotCapture(F, 0);
763  Changed |= setDoesNotCapture(F, 1);
764  Changed |= setOnlyReadsMemory(F, 1);
765  return Changed;
766  // int __nvvm_reflect(const char *)
767  case LibFunc_nvvm_reflect:
768  Changed |= setDoesNotAccessMemory(F);
769  Changed |= setDoesNotThrow(F);
770  return Changed;
771 
772  default:
773  // FIXME: It'd be really nice to cover all the library functions we're
774  // aware of here.
775  return false;
776  }
777 }
778 
780  LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn) {
781  switch (Ty->getTypeID()) {
782  case Type::HalfTyID:
783  return false;
784  case Type::FloatTyID:
785  return TLI->has(FloatFn);
786  case Type::DoubleTyID:
787  return TLI->has(DoubleFn);
788  default:
789  return TLI->has(LongDoubleFn);
790  }
791 }
792 
794  LibFunc DoubleFn, LibFunc FloatFn,
795  LibFunc LongDoubleFn) {
796  assert(hasFloatFn(TLI, Ty, DoubleFn, FloatFn, LongDoubleFn) &&
797  "Cannot get name for unavailable function!");
798 
799  switch (Ty->getTypeID()) {
800  case Type::HalfTyID:
801  llvm_unreachable("No name for HalfTy!");
802  case Type::FloatTyID:
803  return TLI->getName(FloatFn);
804  case Type::DoubleTyID:
805  return TLI->getName(DoubleFn);
806  default:
807  return TLI->getName(LongDoubleFn);
808  }
809 }
810 
811 //- Emit LibCalls ------------------------------------------------------------//
812 
814  unsigned AS = V->getType()->getPointerAddressSpace();
815  return B.CreateBitCast(V, B.getInt8PtrTy(AS), "cstr");
816 }
817 
818 static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
819  ArrayRef<Type *> ParamTypes,
821  const TargetLibraryInfo *TLI,
822  bool IsVaArgs = false) {
823  if (!TLI->has(TheLibFunc))
824  return nullptr;
825 
826  Module *M = B.GetInsertBlock()->getModule();
827  StringRef FuncName = TLI->getName(TheLibFunc);
828  FunctionType *FuncType = FunctionType::get(ReturnType, ParamTypes, IsVaArgs);
829  FunctionCallee Callee = M->getOrInsertFunction(FuncName, FuncType);
830  inferLibFuncAttributes(M, FuncName, *TLI);
831  CallInst *CI = B.CreateCall(Callee, Operands, FuncName);
832  if (const Function *F =
833  dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
834  CI->setCallingConv(F->getCallingConv());
835  return CI;
836 }
837 
839  const TargetLibraryInfo *TLI) {
841  return emitLibCall(LibFunc_strlen, DL.getIntPtrType(Context),
842  B.getInt8PtrTy(), castToCStr(Ptr, B), B, TLI);
843 }
844 
846  const TargetLibraryInfo *TLI) {
847  Type *I8Ptr = B.getInt8PtrTy();
848  Type *I32Ty = B.getInt32Ty();
849  return emitLibCall(LibFunc_strchr, I8Ptr, {I8Ptr, I32Ty},
850  {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, B, TLI);
851 }
852 
854  const DataLayout &DL, const TargetLibraryInfo *TLI) {
856  return emitLibCall(
857  LibFunc_strncmp, B.getInt32Ty(),
858  {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
859  {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
860 }
861 
863  const TargetLibraryInfo *TLI) {
864  Type *I8Ptr = B.getInt8PtrTy();
865  return emitLibCall(LibFunc_strcpy, I8Ptr, {I8Ptr, I8Ptr},
866  {castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI);
867 }
868 
870  const TargetLibraryInfo *TLI) {
871  Type *I8Ptr = B.getInt8PtrTy();
872  return emitLibCall(LibFunc_stpcpy, I8Ptr, {I8Ptr, I8Ptr},
873  {castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI);
874 }
875 
877  const TargetLibraryInfo *TLI) {
878  Type *I8Ptr = B.getInt8PtrTy();
879  return emitLibCall(LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType()},
880  {castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
881 }
882 
884  const TargetLibraryInfo *TLI) {
885  Type *I8Ptr = B.getInt8PtrTy();
886  return emitLibCall(LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType()},
887  {castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
888 }
889 
890 Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
891  IRBuilder<> &B, const DataLayout &DL,
892  const TargetLibraryInfo *TLI) {
893  if (!TLI->has(LibFunc_memcpy_chk))
894  return nullptr;
895 
896  Module *M = B.GetInsertBlock()->getModule();
897  AttributeList AS;
899  Attribute::NoUnwind);
902  "__memcpy_chk", AttributeList::get(M->getContext(), AS), B.getInt8PtrTy(),
903  B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context),
904  DL.getIntPtrType(Context));
905  Dst = castToCStr(Dst, B);
906  Src = castToCStr(Src, B);
907  CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
908  if (const Function *F =
909  dyn_cast<Function>(MemCpy.getCallee()->stripPointerCasts()))
910  CI->setCallingConv(F->getCallingConv());
911  return CI;
912 }
913 
915  const DataLayout &DL, const TargetLibraryInfo *TLI) {
917  return emitLibCall(
918  LibFunc_memchr, B.getInt8PtrTy(),
919  {B.getInt8PtrTy(), B.getInt32Ty(), DL.getIntPtrType(Context)},
920  {castToCStr(Ptr, B), Val, Len}, B, TLI);
921 }
922 
924  const DataLayout &DL, const TargetLibraryInfo *TLI) {
926  return emitLibCall(
927  LibFunc_memcmp, B.getInt32Ty(),
928  {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
929  {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
930 }
931 
933  const DataLayout &DL, const TargetLibraryInfo *TLI) {
935  return emitLibCall(
936  LibFunc_bcmp, B.getInt32Ty(),
937  {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
938  {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
939 }
940 
941 Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
942  IRBuilder<> &B, const TargetLibraryInfo *TLI) {
943  return emitLibCall(
944  LibFunc_memccpy, B.getInt8PtrTy(),
945  {B.getInt8PtrTy(), B.getInt8PtrTy(), B.getInt32Ty(), Len->getType()},
946  {Ptr1, Ptr2, Val, Len}, B, TLI);
947 }
948 
950  ArrayRef<Value *> VariadicArgs, IRBuilder<> &B,
951  const TargetLibraryInfo *TLI) {
953  Args.insert(Args.end(), VariadicArgs.begin(), VariadicArgs.end());
954  return emitLibCall(LibFunc_snprintf, B.getInt32Ty(),
955  {B.getInt8PtrTy(), Size->getType(), B.getInt8PtrTy()},
956  Args, B, TLI, /*IsVaArgs=*/true);
957 }
958 
960  ArrayRef<Value *> VariadicArgs, IRBuilder<> &B,
961  const TargetLibraryInfo *TLI) {
963  Args.insert(Args.end(), VariadicArgs.begin(), VariadicArgs.end());
964  return emitLibCall(LibFunc_sprintf, B.getInt32Ty(),
965  {B.getInt8PtrTy(), B.getInt8PtrTy()}, Args, B, TLI,
966  /*IsVaArgs=*/true);
967 }
968 
970  const TargetLibraryInfo *TLI) {
971  return emitLibCall(LibFunc_strcat, B.getInt8PtrTy(),
972  {B.getInt8PtrTy(), B.getInt8PtrTy()},
973  {castToCStr(Dest, B), castToCStr(Src, B)}, B, TLI);
974 }
975 
977  const TargetLibraryInfo *TLI) {
978  return emitLibCall(LibFunc_strlcpy, Size->getType(),
979  {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
980  {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
981 }
982 
984  const TargetLibraryInfo *TLI) {
985  return emitLibCall(LibFunc_strlcat, Size->getType(),
986  {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
987  {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
988 }
989 
991  const TargetLibraryInfo *TLI) {
992  return emitLibCall(LibFunc_strncat, B.getInt8PtrTy(),
993  {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
994  {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
995 }
996 
998  IRBuilder<> &B, const TargetLibraryInfo *TLI) {
999  return emitLibCall(
1000  LibFunc_vsnprintf, B.getInt32Ty(),
1001  {B.getInt8PtrTy(), Size->getType(), B.getInt8PtrTy(), VAList->getType()},
1002  {castToCStr(Dest, B), Size, castToCStr(Fmt, B), VAList}, B, TLI);
1003 }
1004 
1005 Value *llvm::emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList,
1006  IRBuilder<> &B, const TargetLibraryInfo *TLI) {
1007  return emitLibCall(LibFunc_vsprintf, B.getInt32Ty(),
1008  {B.getInt8PtrTy(), B.getInt8PtrTy(), VAList->getType()},
1009  {castToCStr(Dest, B), castToCStr(Fmt, B), VAList}, B, TLI);
1010 }
1011 
1012 /// Append a suffix to the function name according to the type of 'Op'.
1014  SmallString<20> &NameBuffer) {
1015  if (!Op->getType()->isDoubleTy()) {
1016  NameBuffer += Name;
1017 
1018  if (Op->getType()->isFloatTy())
1019  NameBuffer += 'f';
1020  else
1021  NameBuffer += 'l';
1022 
1023  Name = NameBuffer;
1024  }
1025 }
1026 
1028  IRBuilder<> &B,
1029  const AttributeList &Attrs) {
1030  assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall");
1031 
1032  Module *M = B.GetInsertBlock()->getModule();
1034  M->getOrInsertFunction(Name, Op->getType(), Op->getType());
1035  CallInst *CI = B.CreateCall(Callee, Op, Name);
1036 
1037  // The incoming attribute set may have come from a speculatable intrinsic, but
1038  // is being replaced with a library call which is not allowed to be
1039  // speculatable.
1042  Attribute::Speculatable));
1043  if (const Function *F =
1044  dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1045  CI->setCallingConv(F->getCallingConv());
1046 
1047  return CI;
1048 }
1049 
1051  const AttributeList &Attrs) {
1052  SmallString<20> NameBuffer;
1053  appendTypeSuffix(Op, Name, NameBuffer);
1054 
1055  return emitUnaryFloatFnCallHelper(Op, Name, B, Attrs);
1056 }
1057 
1059  LibFunc DoubleFn, LibFunc FloatFn,
1060  LibFunc LongDoubleFn, IRBuilder<> &B,
1061  const AttributeList &Attrs) {
1062  // Get the name of the function according to TLI.
1063  StringRef Name = getFloatFnName(TLI, Op->getType(),
1064  DoubleFn, FloatFn, LongDoubleFn);
1065 
1066  return emitUnaryFloatFnCallHelper(Op, Name, B, Attrs);
1067 }
1068 
1071  const AttributeList &Attrs) {
1072  assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1073 
1074  Module *M = B.GetInsertBlock()->getModule();
1076  Op1->getType(), Op2->getType());
1077  CallInst *CI = B.CreateCall(Callee, { Op1, Op2 }, Name);
1078 
1079  // The incoming attribute set may have come from a speculatable intrinsic, but
1080  // is being replaced with a library call which is not allowed to be
1081  // speculatable.
1084  Attribute::Speculatable));
1085  if (const Function *F =
1086  dyn_cast<Function>(Callee.getCallee()->stripPointerCasts()))
1087  CI->setCallingConv(F->getCallingConv());
1088 
1089  return CI;
1090 }
1091 
1093  IRBuilder<> &B, const AttributeList &Attrs) {
1094  assert((Name != "") && "Must specify Name to emitBinaryFloatFnCall");
1095 
1096  SmallString<20> NameBuffer;
1097  appendTypeSuffix(Op1, Name, NameBuffer);
1098 
1099  return emitBinaryFloatFnCallHelper(Op1, Op2, Name, B, Attrs);
1100 }
1101 
1103  const TargetLibraryInfo *TLI,
1104  LibFunc DoubleFn, LibFunc FloatFn,
1105  LibFunc LongDoubleFn, IRBuilder<> &B,
1106  const AttributeList &Attrs) {
1107  // Get the name of the function according to TLI.
1108  StringRef Name = getFloatFnName(TLI, Op1->getType(),
1109  DoubleFn, FloatFn, LongDoubleFn);
1110 
1111  return emitBinaryFloatFnCallHelper(Op1, Op2, Name, B, Attrs);
1112 }
1113 
1115  const TargetLibraryInfo *TLI) {
1116  if (!TLI->has(LibFunc_putchar))
1117  return nullptr;
1118 
1119  Module *M = B.GetInsertBlock()->getModule();
1120  StringRef PutCharName = TLI->getName(LibFunc_putchar);
1121  FunctionCallee PutChar =
1122  M->getOrInsertFunction(PutCharName, B.getInt32Ty(), B.getInt32Ty());
1123  inferLibFuncAttributes(M, PutCharName, *TLI);
1124  CallInst *CI = B.CreateCall(PutChar,
1125  B.CreateIntCast(Char,
1126  B.getInt32Ty(),
1127  /*isSigned*/true,
1128  "chari"),
1129  PutCharName);
1130 
1131  if (const Function *F =
1132  dyn_cast<Function>(PutChar.getCallee()->stripPointerCasts()))
1133  CI->setCallingConv(F->getCallingConv());
1134  return CI;
1135 }
1136 
1138  const TargetLibraryInfo *TLI) {
1139  if (!TLI->has(LibFunc_puts))
1140  return nullptr;
1141 
1142  Module *M = B.GetInsertBlock()->getModule();
1143  StringRef PutsName = TLI->getName(LibFunc_puts);
1144  FunctionCallee PutS =
1145  M->getOrInsertFunction(PutsName, B.getInt32Ty(), B.getInt8PtrTy());
1146  inferLibFuncAttributes(M, PutsName, *TLI);
1147  CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), PutsName);
1148  if (const Function *F =
1149  dyn_cast<Function>(PutS.getCallee()->stripPointerCasts()))
1150  CI->setCallingConv(F->getCallingConv());
1151  return CI;
1152 }
1153 
1155  const TargetLibraryInfo *TLI) {
1156  if (!TLI->has(LibFunc_fputc))
1157  return nullptr;
1158 
1159  Module *M = B.GetInsertBlock()->getModule();
1160  StringRef FPutcName = TLI->getName(LibFunc_fputc);
1161  FunctionCallee F = M->getOrInsertFunction(FPutcName, B.getInt32Ty(),
1162  B.getInt32Ty(), File->getType());
1163  if (File->getType()->isPointerTy())
1164  inferLibFuncAttributes(M, FPutcName, *TLI);
1165  Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
1166  "chari");
1167  CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName);
1168 
1169  if (const Function *Fn =
1170  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1171  CI->setCallingConv(Fn->getCallingConv());
1172  return CI;
1173 }
1174 
1176  const TargetLibraryInfo *TLI) {
1177  if (!TLI->has(LibFunc_fputc_unlocked))
1178  return nullptr;
1179 
1180  Module *M = B.GetInsertBlock()->getModule();
1181  StringRef FPutcUnlockedName = TLI->getName(LibFunc_fputc_unlocked);
1182  FunctionCallee F = M->getOrInsertFunction(FPutcUnlockedName, B.getInt32Ty(),
1183  B.getInt32Ty(), File->getType());
1184  if (File->getType()->isPointerTy())
1185  inferLibFuncAttributes(M, FPutcUnlockedName, *TLI);
1186  Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/ true, "chari");
1187  CallInst *CI = B.CreateCall(F, {Char, File}, FPutcUnlockedName);
1188 
1189  if (const Function *Fn =
1190  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1191  CI->setCallingConv(Fn->getCallingConv());
1192  return CI;
1193 }
1194 
1196  const TargetLibraryInfo *TLI) {
1197  if (!TLI->has(LibFunc_fputs))
1198  return nullptr;
1199 
1200  Module *M = B.GetInsertBlock()->getModule();
1201  StringRef FPutsName = TLI->getName(LibFunc_fputs);
1202  FunctionCallee F = M->getOrInsertFunction(FPutsName, B.getInt32Ty(),
1203  B.getInt8PtrTy(), File->getType());
1204  if (File->getType()->isPointerTy())
1205  inferLibFuncAttributes(M, FPutsName, *TLI);
1206  CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsName);
1207 
1208  if (const Function *Fn =
1209  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1210  CI->setCallingConv(Fn->getCallingConv());
1211  return CI;
1212 }
1213 
1215  const TargetLibraryInfo *TLI) {
1216  if (!TLI->has(LibFunc_fputs_unlocked))
1217  return nullptr;
1218 
1219  Module *M = B.GetInsertBlock()->getModule();
1220  StringRef FPutsUnlockedName = TLI->getName(LibFunc_fputs_unlocked);
1221  FunctionCallee F = M->getOrInsertFunction(FPutsUnlockedName, B.getInt32Ty(),
1222  B.getInt8PtrTy(), File->getType());
1223  if (File->getType()->isPointerTy())
1224  inferLibFuncAttributes(M, FPutsUnlockedName, *TLI);
1225  CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsUnlockedName);
1226 
1227  if (const Function *Fn =
1228  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1229  CI->setCallingConv(Fn->getCallingConv());
1230  return CI;
1231 }
1232 
1234  const DataLayout &DL, const TargetLibraryInfo *TLI) {
1235  if (!TLI->has(LibFunc_fwrite))
1236  return nullptr;
1237 
1238  Module *M = B.GetInsertBlock()->getModule();
1240  StringRef FWriteName = TLI->getName(LibFunc_fwrite);
1242  FWriteName, DL.getIntPtrType(Context), B.getInt8PtrTy(),
1243  DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
1244 
1245  if (File->getType()->isPointerTy())
1246  inferLibFuncAttributes(M, FWriteName, *TLI);
1247  CallInst *CI =
1248  B.CreateCall(F, {castToCStr(Ptr, B), Size,
1249  ConstantInt::get(DL.getIntPtrType(Context), 1), File});
1250 
1251  if (const Function *Fn =
1252  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1253  CI->setCallingConv(Fn->getCallingConv());
1254  return CI;
1255 }
1256 
1258  const TargetLibraryInfo *TLI) {
1259  if (!TLI->has(LibFunc_malloc))
1260  return nullptr;
1261 
1262  Module *M = B.GetInsertBlock()->getModule();
1263  StringRef MallocName = TLI->getName(LibFunc_malloc);
1265  FunctionCallee Malloc = M->getOrInsertFunction(MallocName, B.getInt8PtrTy(),
1266  DL.getIntPtrType(Context));
1267  inferLibFuncAttributes(M, MallocName, *TLI);
1268  CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
1269 
1270  if (const Function *F =
1271  dyn_cast<Function>(Malloc.getCallee()->stripPointerCasts()))
1272  CI->setCallingConv(F->getCallingConv());
1273 
1274  return CI;
1275 }
1276 
1278  IRBuilder<> &B, const TargetLibraryInfo &TLI) {
1279  if (!TLI.has(LibFunc_calloc))
1280  return nullptr;
1281 
1282  Module *M = B.GetInsertBlock()->getModule();
1283  StringRef CallocName = TLI.getName(LibFunc_calloc);
1284  const DataLayout &DL = M->getDataLayout();
1285  IntegerType *PtrType = DL.getIntPtrType((B.GetInsertBlock()->getContext()));
1286  FunctionCallee Calloc = M->getOrInsertFunction(
1287  CallocName, Attrs, B.getInt8PtrTy(), PtrType, PtrType);
1288  inferLibFuncAttributes(M, CallocName, TLI);
1289  CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
1290 
1291  if (const auto *F =
1292  dyn_cast<Function>(Calloc.getCallee()->stripPointerCasts()))
1293  CI->setCallingConv(F->getCallingConv());
1294 
1295  return CI;
1296 }
1297 
1299  IRBuilder<> &B, const DataLayout &DL,
1300  const TargetLibraryInfo *TLI) {
1301  if (!TLI->has(LibFunc_fwrite_unlocked))
1302  return nullptr;
1303 
1304  Module *M = B.GetInsertBlock()->getModule();
1306  StringRef FWriteUnlockedName = TLI->getName(LibFunc_fwrite_unlocked);
1308  FWriteUnlockedName, DL.getIntPtrType(Context), B.getInt8PtrTy(),
1309  DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
1310 
1311  if (File->getType()->isPointerTy())
1312  inferLibFuncAttributes(M, FWriteUnlockedName, *TLI);
1313  CallInst *CI = B.CreateCall(F, {castToCStr(Ptr, B), Size, N, File});
1314 
1315  if (const Function *Fn =
1316  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1317  CI->setCallingConv(Fn->getCallingConv());
1318  return CI;
1319 }
1320 
1322  const TargetLibraryInfo *TLI) {
1323  if (!TLI->has(LibFunc_fgetc_unlocked))
1324  return nullptr;
1325 
1326  Module *M = B.GetInsertBlock()->getModule();
1327  StringRef FGetCUnlockedName = TLI->getName(LibFunc_fgetc_unlocked);
1328  FunctionCallee F = M->getOrInsertFunction(FGetCUnlockedName, B.getInt32Ty(),
1329  File->getType());
1330  if (File->getType()->isPointerTy())
1331  inferLibFuncAttributes(M, FGetCUnlockedName, *TLI);
1332  CallInst *CI = B.CreateCall(F, File, FGetCUnlockedName);
1333 
1334  if (const Function *Fn =
1335  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1336  CI->setCallingConv(Fn->getCallingConv());
1337  return CI;
1338 }
1339 
1341  IRBuilder<> &B, const TargetLibraryInfo *TLI) {
1342  if (!TLI->has(LibFunc_fgets_unlocked))
1343  return nullptr;
1344 
1345  Module *M = B.GetInsertBlock()->getModule();
1346  StringRef FGetSUnlockedName = TLI->getName(LibFunc_fgets_unlocked);
1347  FunctionCallee F =
1348  M->getOrInsertFunction(FGetSUnlockedName, B.getInt8PtrTy(),
1349  B.getInt8PtrTy(), B.getInt32Ty(), File->getType());
1350  inferLibFuncAttributes(M, FGetSUnlockedName, *TLI);
1351  CallInst *CI =
1352  B.CreateCall(F, {castToCStr(Str, B), Size, File}, FGetSUnlockedName);
1353 
1354  if (const Function *Fn =
1355  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1356  CI->setCallingConv(Fn->getCallingConv());
1357  return CI;
1358 }
1359 
1361  IRBuilder<> &B, const DataLayout &DL,
1362  const TargetLibraryInfo *TLI) {
1363  if (!TLI->has(LibFunc_fread_unlocked))
1364  return nullptr;
1365 
1366  Module *M = B.GetInsertBlock()->getModule();
1368  StringRef FReadUnlockedName = TLI->getName(LibFunc_fread_unlocked);
1370  FReadUnlockedName, DL.getIntPtrType(Context), B.getInt8PtrTy(),
1371  DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
1372 
1373  if (File->getType()->isPointerTy())
1374  inferLibFuncAttributes(M, FReadUnlockedName, *TLI);
1375  CallInst *CI = B.CreateCall(F, {castToCStr(Ptr, B), Size, N, File});
1376 
1377  if (const Function *Fn =
1378  dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
1379  CI->setCallingConv(Fn->getCallingConv());
1380  return CI;
1381 }
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
Definition: Function.h:481
uint64_t CallInst * C
Value * emitStpCpy(Value *Dst, Value *Src, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the stpcpy function to the builder, for the specified pointer arguments.
static bool setReturnedArg(Function &F, unsigned ArgNo)
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
static bool setDoesNotCapture(Function &F, unsigned ArgNo)
LLVMContext & Context
LLVMContext & getContext() const
Definition: IRBuilder.h:128
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
adds the attribute to the list of attributes for the given arg.
Definition: Function.cpp:398
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
iterator begin() const
Definition: ArrayRef.h:136
2: 32-bit floating point type
Definition: Type.h:58
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:165
This class represents a function call, abstracting a target machine&#39;s calling convention.
Value * emitSNPrintf(Value *Dest, Value *Size, Value *Fmt, ArrayRef< Value *> Args, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the snprintf function.
The two locations do not alias at all.
Definition: AliasAnalysis.h:84
StringRef getName(LibFunc F) const
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:323
STATISTIC(NumFunctions, "Total number of functions")
F(f)
bool isLibFreeFunction(const Function *F, const LibFunc TLIFn)
isLibFreeFunction - Returns true if the function is a builtin free()
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:580
1: 16-bit floating point type
Definition: Type.h:57
Value * emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the memccpy function.
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...
Value * emitFPutSUnlocked(Value *Str, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs_unlocked function.
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:32
Value * emitMalloc(Value *Num, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
static bool setRetDoesNotAlias(Function &F)
void setDoesNotThrow()
Definition: Function.h:536
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition: IRBuilder.h:383
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
Definition: BasicBlock.cpp:133
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:369
static bool setNonLazyBind(Function &F)
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:137
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:244
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:779
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
Definition: Function.h:400
Value * emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcpy function.
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 * emitFPutCUnlocked(Value *Char, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc_unlocked function.
mir Rename Register Operands
static Value * emitUnaryFloatFnCallHelper(Value *Op, StringRef Name, IRBuilder<> &B, const AttributeList &Attrs)
Class to represent function types.
Definition: DerivedTypes.h:103
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Definition: IRBuilder.h:1964
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:126
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:395
bool has(LibFunc F) const
Tests whether a library function is available.
Value * emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the vsprintf function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:25
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
void setOnlyAccessesArgMemory()
Definition: Function.h:501
bool doesNotAccessMemory() const
Determine if the function does not access memory.
Definition: Function.h:473
Value * emitFPutS(Value *Str, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
bool isFloatTy() const
Return true if this is &#39;float&#39;, a 32-bit IEEE fp type.
Definition: Type.h:146
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:766
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:168
void setOnlyReadsMemory()
Definition: Function.h:484
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.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:64
Instrumentation for Order File
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:223
static bool setOnlyReadsMemory(Function &F)
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
Definition: Function.cpp:380
void setCallingConv(CallingConv::ID CC)
Definition: InstrTypes.h:1348
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:296
Class to represent integer types.
Definition: DerivedTypes.h:40
Value * castToCStr(Value *V, IRBuilder<> &B)
Return V if it is an i8*, otherwise cast it to i8*.
static bool setDoesNotAccessMemory(Function &F)
static bool setRetNonNull(Function &F)
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.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:525
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
Definition: IRBuilder.h:421
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool doesNotThrow() const
Determine if the function cannot unwind.
Definition: Function.h:533
Value * emitFWriteUnlocked(Value *Ptr, Value *Size, Value *N, Value *File, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite_unlocked function.
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.
Value * emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strncpy function to the builder, for the specified pointer arguments and length...
Value * emitFGetCUnlocked(Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fgetc_unlocked function. File is a pointer to FILE.
Value * emitStrCat(Value *Dest, Value *Src, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strcat function.
Value * emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strcpy function to the builder, for the specified pointer arguments.
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition: IRBuilder.h:2033
Value * emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the vsnprintf function.
Module.h This file contains the declarations for the Module class.
Provides information about what library functions are available for the current target.
iterator end() const
Definition: ArrayRef.h:137
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:653
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:143
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:174
amdgpu Simplify well known AMD library false FunctionCallee Callee
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
bool getRtLibUseGOT() const
Returns true if PLT should be avoided for RTLib calls.
Definition: Module.cpp:550
Value * emitFPutC(Value *Char, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
Value * emitFGetSUnlocked(Value *Str, Value *Size, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fgets_unlocked function.
void setDoesNotAccessMemory()
Definition: Function.h:476
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 setDoesNotAlias(Function &F, unsigned ArgNo)
LLVM_NODISCARD 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)
#define N
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
Definition: Function.h:498
Value * emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcat function.
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
Definition: InstrTypes.h:1370
uint32_t Size
Definition: Profile.cpp:46
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2237
Value * emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the bcmp function.
Value * emitSPrintf(Value *Dest, Value *Fmt, ArrayRef< Value *> VariadicArgs, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the sprintf function.
Value * emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite function.
static Value * emitLibCall(LibFunc TheLibFunc, Type *ReturnType, ArrayRef< Type *> ParamTypes, ArrayRef< Value *> Operands, IRBuilder<> &B, const TargetLibraryInfo *TLI, bool IsVaArgs=false)
3: 64-bit floating point type
Definition: Type.h:59
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())
static Value * emitBinaryFloatFnCallHelper(Value *Op1, Value *Op2, StringRef Name, IRBuilder<> &B, const AttributeList &Attrs)
Value * emitFReadUnlocked(Value *Ptr, Value *Size, Value *N, Value *File, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fread_unlocked function.
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
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 * emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the stpncpy function to the builder, for the specified pointer arguments and length...
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:265
Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
Value * emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs, IRBuilder<> &B, const TargetLibraryInfo &TLI)
Emit a call to the calloc function.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition: Function.h:229
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
static bool setDoesNotFreeMemory(Function &F)
bool isDoubleTy() const
Return true if this is &#39;double&#39;, a 64-bit IEEE fp type.
Definition: Type.h:149
Value * emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the strncat function.
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.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
Definition: Attributes.cpp:973