LLVM  7.0.0svn
BuildLibCalls.h
Go to the documentation of this file.
1 //===- BuildLibCalls.h - Utility builder for libcalls -----------*- C++ -*-===//
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 exposes an interface to build some C language libcalls for
11 // optimization passes that need to call the various functions.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_TRANSFORMS_UTILS_BUILDLIBCALLS_H
16 #define LLVM_TRANSFORMS_UTILS_BUILDLIBCALLS_H
17 
19 #include "llvm/IR/IRBuilder.h"
20 
21 namespace llvm {
22  class Value;
23  class DataLayout;
24  class TargetLibraryInfo;
25 
26  /// Analyze the name and prototype of the given function and set any
27  /// applicable attributes.
28  /// If the library function is unavailable, this doesn't modify it.
29  ///
30  /// Returns true if any attributes were set and false otherwise.
31  bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI);
32 
33  /// Check whether the overloaded unary floating point function
34  /// corresponding to \a Ty is available.
35  bool hasUnaryFloatFn(const TargetLibraryInfo *TLI, Type *Ty,
36  LibFunc DoubleFn, LibFunc FloatFn,
37  LibFunc LongDoubleFn);
38 
39  /// Return V if it is an i8*, otherwise cast it to i8*.
40  Value *castToCStr(Value *V, IRBuilder<> &B);
41 
42  /// Emit a call to the strlen function to the builder, for the specified
43  /// pointer. Ptr is required to be some pointer type, and the return value has
44  /// 'intptr_t' type.
45  Value *emitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL,
46  const TargetLibraryInfo *TLI);
47 
48  /// Emit a call to the strnlen function to the builder, for the specified
49  /// pointer. Ptr is required to be some pointer type, MaxLen must be of size_t
50  /// type, and the return value has 'intptr_t' type.
51  Value *emitStrNLen(Value *Ptr, Value *MaxLen, IRBuilder<> &B,
52  const DataLayout &DL, const TargetLibraryInfo *TLI);
53 
54  /// Emit a call to the strchr function to the builder, for the specified
55  /// pointer and character. Ptr is required to be some pointer type, and the
56  /// return value has 'i8*' type.
57  Value *emitStrChr(Value *Ptr, char C, IRBuilder<> &B,
58  const TargetLibraryInfo *TLI);
59 
60  /// Emit a call to the strncmp function to the builder.
61  Value *emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
62  const DataLayout &DL, const TargetLibraryInfo *TLI);
63 
64  /// Emit a call to the strcpy function to the builder, for the specified
65  /// pointer arguments.
66  Value *emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B,
67  const TargetLibraryInfo *TLI, StringRef Name = "strcpy");
68 
69  /// Emit a call to the strncpy function to the builder, for the specified
70  /// pointer arguments and length.
71  Value *emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B,
72  const TargetLibraryInfo *TLI, StringRef Name = "strncpy");
73 
74  /// Emit a call to the __memcpy_chk function to the builder. This expects that
75  /// the Len and ObjSize have type 'intptr_t' and Dst/Src are pointers.
76  Value *emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
77  IRBuilder<> &B, const DataLayout &DL,
78  const TargetLibraryInfo *TLI);
79 
80  /// Emit a call to the memchr function. This assumes that Ptr is a pointer,
81  /// Val is an i32 value, and Len is an 'intptr_t' value.
82  Value *emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B,
83  const DataLayout &DL, const TargetLibraryInfo *TLI);
84 
85  /// Emit a call to the memcmp function.
86  Value *emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
87  const DataLayout &DL, const TargetLibraryInfo *TLI);
88 
89  /// Emit a call to the unary function named 'Name' (e.g. 'floor'). This
90  /// function is known to take a single of type matching 'Op' and returns one
91  /// value with the same type. If 'Op' is a long double, 'l' is added as the
92  /// suffix of name, if 'Op' is a float, we add a 'f' suffix.
93  Value *emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B,
94  const AttributeList &Attrs);
95 
96  /// Emit a call to the binary function named 'Name' (e.g. 'fmin'). This
97  /// function is known to take type matching 'Op1' and 'Op2' and return one
98  /// value with the same type. If 'Op1/Op2' are long double, 'l' is added as
99  /// the suffix of name, if 'Op1/Op2' are float, we add a 'f' suffix.
100  Value *emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
101  IRBuilder<> &B, const AttributeList &Attrs);
102 
103  /// Emit a call to the putchar function. This assumes that Char is an integer.
104  Value *emitPutChar(Value *Char, IRBuilder<> &B, const TargetLibraryInfo *TLI);
105 
106  /// Emit a call to the puts function. This assumes that Str is some pointer.
107  Value *emitPutS(Value *Str, IRBuilder<> &B, const TargetLibraryInfo *TLI);
108 
109  /// Emit a call to the fputc function. This assumes that Char is an i32, and
110  /// File is a pointer to FILE.
111  Value *emitFPutC(Value *Char, Value *File, IRBuilder<> &B,
112  const TargetLibraryInfo *TLI);
113 
114  /// Emit a call to the fputc_unlocked function. This assumes that Char is an
115  /// i32, and File is a pointer to FILE.
116  Value *emitFPutCUnlocked(Value *Char, Value *File, IRBuilder<> &B,
117  const TargetLibraryInfo *TLI);
118 
119  /// Emit a call to the fputs function. Str is required to be a pointer and
120  /// File is a pointer to FILE.
121  Value *emitFPutS(Value *Str, Value *File, IRBuilder<> &B,
122  const TargetLibraryInfo *TLI);
123 
124  /// Emit a call to the fputs_unlocked function. Str is required to be a
125  /// pointer and File is a pointer to FILE.
126  Value *emitFPutSUnlocked(Value *Str, Value *File, IRBuilder<> &B,
127  const TargetLibraryInfo *TLI);
128 
129  /// Emit a call to the fwrite function. This assumes that Ptr is a pointer,
130  /// Size is an 'intptr_t', and File is a pointer to FILE.
131  Value *emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,
132  const DataLayout &DL, const TargetLibraryInfo *TLI);
133 
134  /// Emit a call to the malloc function.
135  Value *emitMalloc(Value *Num, IRBuilder<> &B, const DataLayout &DL,
136  const TargetLibraryInfo *TLI);
137 
138  /// Emit a call to the calloc function.
139  Value *emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs,
140  IRBuilder<> &B, const TargetLibraryInfo &TLI);
141 
142  /// Emit a call to the fwrite_unlocked function. This assumes that Ptr is a
143  /// pointer, Size is an 'intptr_t', N is nmemb and File is a pointer to FILE.
144  Value *emitFWriteUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,
145  IRBuilder<> &B, const DataLayout &DL,
146  const TargetLibraryInfo *TLI);
147 
148  /// Emit a call to the fgetc_unlocked function. File is a pointer to FILE.
149  Value *emitFGetCUnlocked(Value *File, IRBuilder<> &B,
150  const TargetLibraryInfo *TLI);
151 
152  /// Emit a call to the fgets_unlocked function. Str is required to be a
153  /// pointer, Size is an i32 and File is a pointer to FILE.
154  Value *emitFGetSUnlocked(Value *Str, Value *Size, Value *File, IRBuilder<> &B,
155  const TargetLibraryInfo *TLI);
156 
157  /// Emit a call to the fread_unlocked function. This assumes that Ptr is a
158  /// pointer, Size is an 'intptr_t', N is nmemb and File is a pointer to FILE.
159  Value *emitFReadUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,
160  IRBuilder<> &B, const DataLayout &DL,
161  const TargetLibraryInfo *TLI);
162 }
163 
164 #endif
uint64_t CallInst * C
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
F(f)
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...
Value * emitFPutSUnlocked(Value *Str, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs_unlocked function.
Value * emitMalloc(Value *Num, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
Value * emitPutChar(Value *Char, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the putchar function. This assumes that Char is an integer.
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.
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.
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.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
Value * emitFPutS(Value *Str, Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Value * castToCStr(Value *V, IRBuilder<> &B)
Return V if it is an i8*, otherwise cast it to i8*.
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.
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 * emitFGetCUnlocked(Value *File, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the fgetc_unlocked function. File is a pointer to FILE.
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.
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.
#define N
Value * emitStrNLen(Value *Ptr, Value *MaxLen, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strnlen function to the builder, for the specified pointer.
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.
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.
Value * emitPutS(Value *Str, IRBuilder<> &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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.
bool hasUnaryFloatFn(const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Check whether the overloaded unary floating point function corresponding to Ty is available...