LLVM  9.0.0svn
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 #include "llvm/IR/IRBuilder.h"
19 
20 namespace llvm {
21  class Value;
22  class DataLayout;
23  class TargetLibraryInfo;
24 
25  /// Analyze the name and prototype of the given function and set any
26  /// applicable attributes.
27  /// If the library function is unavailable, this doesn't modify it.
28  ///
29  /// Returns true if any attributes were set and false otherwise.
30  bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI);
31  bool inferLibFuncAttributes(Module *M, StringRef Name, 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  /// Get the name of the overloaded unary floating point function
40  /// corresponding to \a Ty.
41  StringRef getUnaryFloatFn(const TargetLibraryInfo *TLI, Type *Ty,
42  LibFunc DoubleFn, LibFunc FloatFn,
43  LibFunc LongDoubleFn);
44 
45  /// Return V if it is an i8*, otherwise cast it to i8*.
46  Value *castToCStr(Value *V, IRBuilder<> &B);
47 
48  /// Emit a call to the strlen function to the builder, for the specified
49  /// pointer. Ptr is required to be some pointer type, and the return value has
50  /// 'intptr_t' type.
51  Value *emitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL,
52  const TargetLibraryInfo *TLI);
53 
54  /// Emit a call to the strnlen function to the builder, for the specified
55  /// pointer. Ptr is required to be some pointer type, MaxLen must be of size_t
56  /// type, and the return value has 'intptr_t' type.
57  Value *emitStrNLen(Value *Ptr, Value *MaxLen, IRBuilder<> &B,
58  const DataLayout &DL, const TargetLibraryInfo *TLI);
59 
60  /// Emit a call to the strchr function to the builder, for the specified
61  /// pointer and character. Ptr is required to be some pointer type, and the
62  /// return value has 'i8*' type.
63  Value *emitStrChr(Value *Ptr, char C, IRBuilder<> &B,
64  const TargetLibraryInfo *TLI);
65 
66  /// Emit a call to the strncmp function to the builder.
67  Value *emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
68  const DataLayout &DL, const TargetLibraryInfo *TLI);
69 
70  /// Emit a call to the strcpy function to the builder, for the specified
71  /// pointer arguments.
72  Value *emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B,
73  const TargetLibraryInfo *TLI, StringRef Name = "strcpy");
74 
75  /// Emit a call to the strncpy function to the builder, for the specified
76  /// pointer arguments and length.
77  Value *emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B,
78  const TargetLibraryInfo *TLI, StringRef Name = "strncpy");
79 
80  /// Emit a call to the __memcpy_chk function to the builder. This expects that
81  /// the Len and ObjSize have type 'intptr_t' and Dst/Src are pointers.
82  Value *emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
83  IRBuilder<> &B, const DataLayout &DL,
84  const TargetLibraryInfo *TLI);
85 
86  /// Emit a call to the memchr function. This assumes that Ptr is a pointer,
87  /// Val is an i32 value, and Len is an 'intptr_t' value.
88  Value *emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B,
89  const DataLayout &DL, const TargetLibraryInfo *TLI);
90 
91  /// Emit a call to the memcmp function.
92  Value *emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
93  const DataLayout &DL, const TargetLibraryInfo *TLI);
94 
95  /// Emit a call to the bcmp function.
96  Value *emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
97  const DataLayout &DL, const TargetLibraryInfo *TLI);
98 
99  /// Emit a call to the unary function named 'Name' (e.g. 'floor'). This
100  /// function is known to take a single of type matching 'Op' and returns one
101  /// value with the same type. If 'Op' is a long double, 'l' is added as the
102  /// suffix of name, if 'Op' is a float, we add a 'f' suffix.
103  Value *emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B,
104  const AttributeList &Attrs);
105 
106  /// Emit a call to the unary function DoubleFn, FloatFn or LongDoubleFn,
107  /// depending of the type of Op.
108  Value *emitUnaryFloatFnCall(Value *Op, const TargetLibraryInfo *TLI,
109  LibFunc DoubleFn, LibFunc FloatFn,
110  LibFunc LongDoubleFn, IRBuilder<> &B,
111  const AttributeList &Attrs);
112 
113  /// Emit a call to the binary function named 'Name' (e.g. 'fmin'). This
114  /// function is known to take type matching 'Op1' and 'Op2' and return one
115  /// value with the same type. If 'Op1/Op2' are long double, 'l' is added as
116  /// the suffix of name, if 'Op1/Op2' are float, we add a 'f' suffix.
117  Value *emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
118  IRBuilder<> &B, const AttributeList &Attrs);
119 
120  /// Emit a call to the putchar function. This assumes that Char is an integer.
121  Value *emitPutChar(Value *Char, IRBuilder<> &B, const TargetLibraryInfo *TLI);
122 
123  /// Emit a call to the puts function. This assumes that Str is some pointer.
124  Value *emitPutS(Value *Str, IRBuilder<> &B, const TargetLibraryInfo *TLI);
125 
126  /// Emit a call to the fputc function. This assumes that Char is an i32, and
127  /// File is a pointer to FILE.
128  Value *emitFPutC(Value *Char, Value *File, IRBuilder<> &B,
129  const TargetLibraryInfo *TLI);
130 
131  /// Emit a call to the fputc_unlocked function. This assumes that Char is an
132  /// i32, and File is a pointer to FILE.
133  Value *emitFPutCUnlocked(Value *Char, Value *File, IRBuilder<> &B,
134  const TargetLibraryInfo *TLI);
135 
136  /// Emit a call to the fputs function. Str is required to be a pointer and
137  /// File is a pointer to FILE.
138  Value *emitFPutS(Value *Str, Value *File, IRBuilder<> &B,
139  const TargetLibraryInfo *TLI);
140 
141  /// Emit a call to the fputs_unlocked function. Str is required to be a
142  /// pointer and File is a pointer to FILE.
143  Value *emitFPutSUnlocked(Value *Str, Value *File, IRBuilder<> &B,
144  const TargetLibraryInfo *TLI);
145 
146  /// Emit a call to the fwrite function. This assumes that Ptr is a pointer,
147  /// Size is an 'intptr_t', and File is a pointer to FILE.
148  Value *emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,
149  const DataLayout &DL, const TargetLibraryInfo *TLI);
150 
151  /// Emit a call to the malloc function.
152  Value *emitMalloc(Value *Num, IRBuilder<> &B, const DataLayout &DL,
153  const TargetLibraryInfo *TLI);
154 
155  /// Emit a call to the calloc function.
156  Value *emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs,
157  IRBuilder<> &B, const TargetLibraryInfo &TLI);
158 
159  /// Emit a call to the fwrite_unlocked function. This assumes that Ptr is a
160  /// pointer, Size is an 'intptr_t', N is nmemb and File is a pointer to FILE.
161  Value *emitFWriteUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,
162  IRBuilder<> &B, const DataLayout &DL,
163  const TargetLibraryInfo *TLI);
164 
165  /// Emit a call to the fgetc_unlocked function. File is a pointer to FILE.
166  Value *emitFGetCUnlocked(Value *File, IRBuilder<> &B,
167  const TargetLibraryInfo *TLI);
168 
169  /// Emit a call to the fgets_unlocked function. Str is required to be a
170  /// pointer, Size is an i32 and File is a pointer to FILE.
171  Value *emitFGetSUnlocked(Value *Str, Value *Size, Value *File, IRBuilder<> &B,
172  const TargetLibraryInfo *TLI);
173 
174  /// Emit a call to the fread_unlocked function. This assumes that Ptr is a
175  /// pointer, Size is an 'intptr_t', N is nmemb and File is a pointer to FILE.
176  Value *emitFReadUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,
177  IRBuilder<> &B, const DataLayout &DL,
178  const TargetLibraryInfo *TLI);
179 }
180 
181 #endif
uint64_t CallInst * C
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:48
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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.
StringRef getUnaryFloatFn(const TargetLibraryInfo *TLI, Type *Ty, LibFunc DoubleFn, LibFunc FloatFn, LibFunc LongDoubleFn)
Get the name of the overloaded unary floating point function corresponding to Ty. ...
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")
Instrumentation for Order File
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.
uint32_t Size
Definition: Profile.cpp:46
Value * emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, const DataLayout &DL, const TargetLibraryInfo *TLI)
Emit a call to the bcmp function.
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.
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...