LLVM  14.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 strchr function to the builder, for the specified
58  /// pointer and character. Ptr is required to be some pointer type, and the
59  /// return value has 'i8*' type.
60  Value *emitStrChr(Value *Ptr, char C, IRBuilderBase &B,
61  const TargetLibraryInfo *TLI);
62 
63  /// Emit a call to the strncmp function to the builder.
64  Value *emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
65  const DataLayout &DL, const TargetLibraryInfo *TLI);
66 
67  /// Emit a call to the strcpy function to the builder, for the specified
68  /// pointer arguments.
69  Value *emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B,
70  const TargetLibraryInfo *TLI);
71 
72  /// Emit a call to the stpcpy function to the builder, for the specified
73  /// pointer arguments.
74  Value *emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B,
75  const TargetLibraryInfo *TLI);
76 
77  /// Emit a call to the strncpy function to the builder, for the specified
78  /// pointer arguments and length.
79  Value *emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
80  const TargetLibraryInfo *TLI);
81 
82  /// Emit a call to the stpncpy function to the builder, for the specified
83  /// pointer arguments and length.
84  Value *emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
85  const TargetLibraryInfo *TLI);
86 
87  /// Emit a call to the __memcpy_chk function to the builder. This expects that
88  /// the Len and ObjSize have type 'intptr_t' and Dst/Src are pointers.
89  Value *emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
90  IRBuilderBase &B, const DataLayout &DL,
91  const TargetLibraryInfo *TLI);
92 
93  /// Emit a call to the mempcpy function.
94  Value *emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
95  const DataLayout &DL, const TargetLibraryInfo *TLI);
96 
97  /// Emit a call to the memchr function. This assumes that Ptr is a pointer,
98  /// Val is an i32 value, and Len is an 'intptr_t' value.
99  Value *emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
100  const DataLayout &DL, const TargetLibraryInfo *TLI);
101 
102  /// Emit a call to the memcmp function.
103  Value *emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
104  const DataLayout &DL, const TargetLibraryInfo *TLI);
105 
106  /// Emit a call to the bcmp function.
107  Value *emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
108  const DataLayout &DL, const TargetLibraryInfo *TLI);
109 
110  /// Emit a call to the memccpy function.
111  Value *emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
112  IRBuilderBase &B, const TargetLibraryInfo *TLI);
113 
114  /// Emit a call to the snprintf function.
115  Value *emitSNPrintf(Value *Dest, Value *Size, Value *Fmt,
116  ArrayRef<Value *> Args, IRBuilderBase &B,
117  const TargetLibraryInfo *TLI);
118 
119  /// Emit a call to the sprintf function.
120  Value *emitSPrintf(Value *Dest, Value *Fmt, ArrayRef<Value *> VariadicArgs,
121  IRBuilderBase &B, const TargetLibraryInfo *TLI);
122 
123  /// Emit a call to the strcat function.
124  Value *emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B,
125  const TargetLibraryInfo *TLI);
126 
127  /// Emit a call to the strlcpy function.
128  Value *emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
129  const TargetLibraryInfo *TLI);
130 
131  /// Emit a call to the strlcat function.
132  Value *emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
133  const TargetLibraryInfo *TLI);
134 
135  /// Emit a call to the strncat function.
136  Value *emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
137  const TargetLibraryInfo *TLI);
138 
139  /// Emit a call to the vsnprintf function.
140  Value *emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList,
141  IRBuilderBase &B, const TargetLibraryInfo *TLI);
142 
143  /// Emit a call to the vsprintf function.
144  Value *emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList, IRBuilderBase &B,
145  const TargetLibraryInfo *TLI);
146 
147  /// Emit a call to the unary function named 'Name' (e.g. 'floor'). This
148  /// function is known to take a single of type matching 'Op' and returns one
149  /// value with the same type. If 'Op' is a long double, 'l' is added as the
150  /// suffix of name, if 'Op' is a float, we add a 'f' suffix.
151  Value *emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilderBase &B,
152  const AttributeList &Attrs);
153 
154  /// Emit a call to the unary function DoubleFn, FloatFn or LongDoubleFn,
155  /// depending of the type of Op.
156  Value *emitUnaryFloatFnCall(Value *Op, const TargetLibraryInfo *TLI,
157  LibFunc DoubleFn, LibFunc FloatFn,
158  LibFunc LongDoubleFn, IRBuilderBase &B,
159  const AttributeList &Attrs);
160 
161  /// Emit a call to the binary function named 'Name' (e.g. 'fmin'). This
162  /// function is known to take type matching 'Op1' and 'Op2' and return one
163  /// value with the same type. If 'Op1/Op2' are long double, 'l' is added as
164  /// the suffix of name, if 'Op1/Op2' are float, we add a 'f' suffix.
165  Value *emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
166  IRBuilderBase &B, const AttributeList &Attrs);
167 
168  /// Emit a call to the binary function DoubleFn, FloatFn or LongDoubleFn,
169  /// depending of the type of Op1.
171  const TargetLibraryInfo *TLI, LibFunc DoubleFn,
172  LibFunc FloatFn, LibFunc LongDoubleFn,
173  IRBuilderBase &B, const AttributeList &Attrs);
174 
175  /// Emit a call to the putchar function. This assumes that Char is an integer.
176  Value *emitPutChar(Value *Char, IRBuilderBase &B,
177  const TargetLibraryInfo *TLI);
178 
179  /// Emit a call to the puts function. This assumes that Str is some pointer.
180  Value *emitPutS(Value *Str, IRBuilderBase &B, const TargetLibraryInfo *TLI);
181 
182  /// Emit a call to the fputc function. This assumes that Char is an i32, and
183  /// File is a pointer to FILE.
184  Value *emitFPutC(Value *Char, Value *File, IRBuilderBase &B,
185  const TargetLibraryInfo *TLI);
186 
187  /// Emit a call to the fputs function. Str is required to be a pointer and
188  /// File is a pointer to FILE.
189  Value *emitFPutS(Value *Str, Value *File, IRBuilderBase &B,
190  const TargetLibraryInfo *TLI);
191 
192  /// Emit a call to the fwrite function. This assumes that Ptr is a pointer,
193  /// Size is an 'intptr_t', and File is a pointer to FILE.
194  Value *emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B,
195  const DataLayout &DL, const TargetLibraryInfo *TLI);
196 
197  /// Emit a call to the malloc function.
198  Value *emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL,
199  const TargetLibraryInfo *TLI);
200 
201  /// Emit a call to the calloc function.
202  Value *emitCalloc(Value *Num, Value *Size, IRBuilderBase &B,
203  const TargetLibraryInfo &TLI);
204 }
205 
206 #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:1197
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm
This file implements support for optimizing divisions by a constant.
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::emitCalloc
Value * emitCalloc(Value *Num, Value *Size, IRBuilderBase &B, const TargetLibraryInfo &TLI)
Emit a call to the calloc function.
Definition: BuildLibCalls.cpp:1659
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:1342
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:1615
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:1360
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:1249
llvm::emitFPutC
Value * emitFPutC(Value *Char, Value *File, IRBuilderBase &B, const TargetLibraryInfo *TLI)
Emit a call to the fputc function.
Definition: BuildLibCalls.cpp:1575
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:1388
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:1395
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:1535
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:1512
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:1263
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:1378
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:1300
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:1402
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:1351
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:1324
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:1293
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:1409
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:1279
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:1242
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:1272
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:1468
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:1183
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:324
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:1596
llvm::emitMalloc
Value * emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the malloc function.
Definition: BuildLibCalls.cpp:1639
llvm::castToCStr
Value * castToCStr(Value *V, IRBuilderBase &B)
Return V if it is an i8*, otherwise cast it to i8*.
Definition: BuildLibCalls.cpp:1217
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:1286
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:221
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:1368
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:1558
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:1255
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
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:1424
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:1416
File
Instrumentation for Order File
Definition: InstrOrderFile.cpp:205
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:1333