LLVM  13.0.0git
BuildLibCalls.h
Go to the documentation of this file.
1 //===- BuildLibCalls.h - Utility builder for libcalls -----------*- C++ -*-===//
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 exposes an interface to build some C language libcalls for
10 // optimization passes that need to call the various functions.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TRANSFORMS_UTILS_BUILDLIBCALLS_H
15 #define LLVM_TRANSFORMS_UTILS_BUILDLIBCALLS_H
16 
18 
19 namespace llvm {
20  class Value;
21  class DataLayout;
22  class IRBuilderBase;
23 
24  /// Analyze the name and prototype of the given function and set any
25  /// applicable attributes.
26  /// If the library function is unavailable, this doesn't modify it.
27  ///
28  /// Returns true if any attributes were set and false otherwise.
29  bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI);
30  bool inferLibFuncAttributes(Module *M, StringRef Name, const TargetLibraryInfo &TLI);
31 
32  /// Check whether the overloaded floating point function
33  /// corresponding to \a Ty is available.
34  bool hasFloatFn(const TargetLibraryInfo *TLI, Type *Ty,
35  LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn);
36 
37  /// Get the name of the overloaded floating point function
38  /// corresponding to \a Ty.
39  StringRef getFloatFnName(const TargetLibraryInfo *TLI, Type *Ty,
40  LibFunc DoubleFn, LibFunc FloatFn,
41  LibFunc LongDoubleFn);
42 
43  /// Return V if it is an i8*, otherwise cast it to i8*.
44  Value *castToCStr(Value *V, IRBuilderBase &B);
45 
46  /// Emit a call to the strlen function to the builder, for the specified
47  /// pointer. Ptr is required to be some pointer type, and the return value has
48  /// 'intptr_t' type.
49  Value *emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL,
50  const TargetLibraryInfo *TLI);
51 
52  /// Emit a call to the strdup function to the builder, for the specified
53  /// pointer. Ptr is required to be some pointer type, and the return value has
54  /// 'i8*' type.
55  Value *emitStrDup(Value *Ptr, IRBuilderBase &B, const TargetLibraryInfo *TLI);
56 
57  /// Emit a call to the strnlen function to the builder, for the specified
58  /// pointer. Ptr is required to be some pointer type, MaxLen must be of size_t
59  /// type, and the return value has 'intptr_t' type.
60  Value *emitStrNLen(Value *Ptr, Value *MaxLen, IRBuilderBase &B,
61  const DataLayout &DL, const TargetLibraryInfo *TLI);
62 
63  /// Emit a call to the strchr function to the builder, for the specified
64  /// pointer and character. Ptr is required to be some pointer type, and the
65  /// return value has 'i8*' type.
66  Value *emitStrChr(Value *Ptr, char C, IRBuilderBase &B,
67  const TargetLibraryInfo *TLI);
68 
69  /// Emit a call to the strncmp function to the builder.
70  Value *emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
71  const DataLayout &DL, const TargetLibraryInfo *TLI);
72 
73  /// Emit a call to the strcpy function to the builder, for the specified
74  /// pointer arguments.
75  Value *emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B,
76  const TargetLibraryInfo *TLI);
77 
78  /// Emit a call to the stpcpy function to the builder, for the specified
79  /// pointer arguments.
80  Value *emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B,
81  const TargetLibraryInfo *TLI);
82 
83  /// Emit a call to the strncpy function to the builder, for the specified
84  /// pointer arguments and length.
85  Value *emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
86  const TargetLibraryInfo *TLI);
87 
88  /// Emit a call to the stpncpy function to the builder, for the specified
89  /// pointer arguments and length.
90  Value *emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
91  const TargetLibraryInfo *TLI);
92 
93  /// Emit a call to the __memcpy_chk function to the builder. This expects that
94  /// the Len and ObjSize have type 'intptr_t' and Dst/Src are pointers.
95  Value *emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
96  IRBuilderBase &B, const DataLayout &DL,
97  const TargetLibraryInfo *TLI);
98 
99  /// Emit a call to the mempcpy function.
100  Value *emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
101  const DataLayout &DL, const TargetLibraryInfo *TLI);
102 
103  /// Emit a call to the memchr function. This assumes that Ptr is a pointer,
104  /// Val is an i32 value, and Len is an 'intptr_t' value.
105  Value *emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
106  const DataLayout &DL, const TargetLibraryInfo *TLI);
107 
108  /// Emit a call to the memcmp function.
109  Value *emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
110  const DataLayout &DL, const TargetLibraryInfo *TLI);
111 
112  /// Emit a call to the bcmp function.
113  Value *emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
114  const DataLayout &DL, const TargetLibraryInfo *TLI);
115 
116  /// Emit a call to the memccpy function.
117  Value *emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
118  IRBuilderBase &B, const TargetLibraryInfo *TLI);
119 
120  /// Emit a call to the snprintf function.
121  Value *emitSNPrintf(Value *Dest, Value *Size, Value *Fmt,
122  ArrayRef<Value *> Args, IRBuilderBase &B,
123  const TargetLibraryInfo *TLI);
124 
125  /// Emit a call to the sprintf function.
126  Value *emitSPrintf(Value *Dest, Value *Fmt, ArrayRef<Value *> VariadicArgs,
127  IRBuilderBase &B, const TargetLibraryInfo *TLI);
128 
129  /// Emit a call to the strcat function.
130  Value *emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B,
131  const TargetLibraryInfo *TLI);
132 
133  /// Emit a call to the strlcpy function.
134  Value *emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
135  const TargetLibraryInfo *TLI);
136 
137  /// Emit a call to the strlcat function.
138  Value *emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
139  const TargetLibraryInfo *TLI);
140 
141  /// Emit a call to the strncat function.
142  Value *emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
143  const TargetLibraryInfo *TLI);
144 
145  /// Emit a call to the vsnprintf function.
146  Value *emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList,
147  IRBuilderBase &B, const TargetLibraryInfo *TLI);
148 
149  /// Emit a call to the vsprintf function.
150  Value *emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList, IRBuilderBase &B,
151  const TargetLibraryInfo *TLI);
152 
153  /// Emit a call to the unary function named 'Name' (e.g. 'floor'). This
154  /// function is known to take a single of type matching 'Op' and returns one
155  /// value with the same type. If 'Op' is a long double, 'l' is added as the
156  /// suffix of name, if 'Op' is a float, we add a 'f' suffix.
157  Value *emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilderBase &B,
158  const AttributeList &Attrs);
159 
160  /// Emit a call to the unary function DoubleFn, FloatFn or LongDoubleFn,
161  /// depending of the type of Op.
162  Value *emitUnaryFloatFnCall(Value *Op, const TargetLibraryInfo *TLI,
163  LibFunc DoubleFn, LibFunc FloatFn,
164  LibFunc LongDoubleFn, IRBuilderBase &B,
165  const AttributeList &Attrs);
166 
167  /// Emit a call to the binary function named 'Name' (e.g. 'fmin'). This
168  /// function is known to take type matching 'Op1' and 'Op2' and return one
169  /// value with the same type. If 'Op1/Op2' are long double, 'l' is added as
170  /// the suffix of name, if 'Op1/Op2' are float, we add a 'f' suffix.
171  Value *emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
172  IRBuilderBase &B, const AttributeList &Attrs);
173 
174  /// Emit a call to the binary function DoubleFn, FloatFn or LongDoubleFn,
175  /// depending of the type of Op1.
177  const TargetLibraryInfo *TLI, LibFunc DoubleFn,
178  LibFunc FloatFn, LibFunc LongDoubleFn,
179  IRBuilderBase &B, const AttributeList &Attrs);
180 
181  /// Emit a call to the putchar function. This assumes that Char is an integer.
182  Value *emitPutChar(Value *Char, IRBuilderBase &B,
183  const TargetLibraryInfo *TLI);
184 
185  /// Emit a call to the puts function. This assumes that Str is some pointer.
186  Value *emitPutS(Value *Str, IRBuilderBase &B, const TargetLibraryInfo *TLI);
187 
188  /// Emit a call to the fputc function. This assumes that Char is an i32, and
189  /// File is a pointer to FILE.
190  Value *emitFPutC(Value *Char, Value *File, IRBuilderBase &B,
191  const TargetLibraryInfo *TLI);
192 
193  /// Emit a call to the fputs function. Str is required to be a pointer and
194  /// File is a pointer to FILE.
195  Value *emitFPutS(Value *Str, Value *File, IRBuilderBase &B,
196  const TargetLibraryInfo *TLI);
197 
198  /// Emit a call to the fwrite function. This assumes that Ptr is a pointer,
199  /// Size is an 'intptr_t', and File is a pointer to FILE.
200  Value *emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B,
201  const DataLayout &DL, const TargetLibraryInfo *TLI);
202 
203  /// Emit a call to the malloc function.
204  Value *emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL,
205  const TargetLibraryInfo *TLI);
206 
207  /// Emit a call to the calloc function.
208  Value *emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs,
209  IRBuilderBase &B, const TargetLibraryInfo &TLI);
210 }
211 
212 #endif
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::getFloatFnName
StringRef getFloatFnName(const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Get the name of the overloaded floating point function corresponding to Ty.
Definition: BuildLibCalls.cpp:1194
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::emitMemCmp
Value * emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memcmp function.
Definition: BuildLibCalls.cpp:1339
llvm::emitFWrite
Value * emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the fwrite function.
Definition: BuildLibCalls.cpp:1614
llvm::emitMemCCpy
Value * emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the memccpy function.
Definition: BuildLibCalls.cpp:1357
llvm::emitCalloc
Value * emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs, IRBuilderBase &B, const TargetLibraryInfo &TLI)
Emit a call to the calloc function.
Definition: BuildLibCalls.cpp:1658
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::emitStrDup
Value * emitStrDup(Value *Ptr, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strdup function to the builder, for the specified pointer.
Definition: BuildLibCalls.cpp:1246
llvm::emitFPutC
Value * emitFPutC(Value *Char, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
Definition: BuildLibCalls.cpp:1574
llvm::LibFunc
LibFunc
Definition: TargetLibraryInfo.h:34
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::emitStrCat
Value * emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcat function.
Definition: BuildLibCalls.cpp:1385
llvm::emitStrLCpy
Value * emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcpy function.
Definition: BuildLibCalls.cpp:1392
TargetLibraryInfo.h
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::emitPutChar
Value * emitPutChar(Value *Char, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the putchar function. This assumes that Char is an integer.
Definition: BuildLibCalls.cpp:1534
llvm::emitBinaryFloatFnCall
Value * emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the binary function named 'Name' (e.g.
Definition: BuildLibCalls.cpp:1511
llvm::emitStrNCmp
Value * emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strncmp function to the builder.
Definition: BuildLibCalls.cpp:1260
llvm::emitSPrintf
Value * emitSPrintf(Value *Dest, Value *Fmt, ArrayRef< Value * > VariadicArgs, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the sprintf function.
Definition: BuildLibCalls.cpp:1375
llvm::emitMemCpyChk
Value * emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the __memcpy_chk function to the builder.
Definition: BuildLibCalls.cpp:1297
llvm::emitStrLCat
Value * emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strlcat function.
Definition: BuildLibCalls.cpp:1399
TemplateParamKind::Type
@ Type
llvm::emitBCmp
Value * emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the bcmp function.
Definition: BuildLibCalls.cpp:1348
llvm::emitMemPCpy
Value * emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the mempcpy function.
Definition: BuildLibCalls.cpp:1321
llvm::emitStpNCpy
Value * emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the stpncpy function to the builder, for the specified pointer arguments and length.
Definition: BuildLibCalls.cpp:1290
llvm::emitStrNCat
Value * emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strncat function.
Definition: BuildLibCalls.cpp:1406
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::emitStpCpy
Value * emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the stpcpy function to the builder, for the specified pointer arguments.
Definition: BuildLibCalls.cpp:1276
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::emitStrLen
Value * emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strlen function to the builder, for the specified pointer.
Definition: BuildLibCalls.cpp:1239
llvm::emitStrCpy
Value * emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strcpy function to the builder, for the specified pointer arguments.
Definition: BuildLibCalls.cpp:1269
llvm::emitUnaryFloatFnCall
Value * emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilderBase &B, const AttributeList &Attrs)
Emit a call to the unary function named 'Name' (e.g.
Definition: BuildLibCalls.cpp:1466
llvm::hasFloatFn
bool hasFloatFn(const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Check whether the overloaded floating point function corresponding to Ty is available.
Definition: BuildLibCalls.cpp:1180
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:314
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::emitFPutS
Value * emitFPutS(Value *Str, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputs function.
Definition: BuildLibCalls.cpp:1595
llvm::emitMalloc
Value * emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
Definition: BuildLibCalls.cpp:1638
llvm::castToCStr
Value * castToCStr(Value *V, IRBuilderBase &B)
Return V if it is an i8*, otherwise cast it to i8*.
Definition: BuildLibCalls.cpp:1214
llvm::emitStrNCpy
Value * emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strncpy function to the builder, for the specified pointer arguments and length.
Definition: BuildLibCalls.cpp:1283
llvm::inferLibFuncAttributes
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
Definition: BuildLibCalls.cpp:218
llvm::emitSNPrintf
Value * emitSNPrintf(Value *Dest, Value *Size, Value *Fmt, ArrayRef< Value * > Args, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the snprintf function.
Definition: BuildLibCalls.cpp:1365
llvm::emitPutS
Value * emitPutS(Value *Str, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the puts function. This assumes that Str is some pointer.
Definition: BuildLibCalls.cpp:1557
llvm::emitStrChr
Value * emitStrChr(Value *Ptr, char C, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the strchr function to the builder, for the specified pointer and character.
Definition: BuildLibCalls.cpp:1252
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
llvm::emitStrNLen
Value * emitStrNLen(Value *Ptr, Value *MaxLen, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the strnlen function to the builder, for the specified pointer.
llvm::emitVSPrintf
Value * emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsprintf function.
Definition: BuildLibCalls.cpp:1421
llvm::emitVSNPrintf
Value * emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the vsnprintf function.
Definition: BuildLibCalls.cpp:1413
File
Instrumentation for Order File
Definition: InstrOrderFile.cpp:206
llvm::emitMemChr
Value * emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the memchr function.
Definition: BuildLibCalls.cpp:1330