]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
MFV r338092: ntp 4.2.8p12.
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / Transforms / Utils / BuildLibCalls.h
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
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
32   /// Return V if it is an i8*, otherwise cast it to i8*.
33   Value *castToCStr(Value *V, IRBuilder<> &B);
34
35   /// Emit a call to the strlen function to the builder, for the specified
36   /// pointer. Ptr is required to be some pointer type, and the return value has
37   /// 'intptr_t' type.
38   Value *emitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL,
39                     const TargetLibraryInfo *TLI);
40
41   /// Emit a call to the strnlen function to the builder, for the specified
42   /// pointer. Ptr is required to be some pointer type, MaxLen must be of size_t
43   /// type, and the return value has 'intptr_t' type.
44   Value *emitStrNLen(Value *Ptr, Value *MaxLen, IRBuilder<> &B,
45                      const DataLayout &DL, const TargetLibraryInfo *TLI);
46
47   /// Emit a call to the strchr function to the builder, for the specified
48   /// pointer and character. Ptr is required to be some pointer type, and the
49   /// return value has 'i8*' type.
50   Value *emitStrChr(Value *Ptr, char C, IRBuilder<> &B,
51                     const TargetLibraryInfo *TLI);
52
53   /// Emit a call to the strncmp function to the builder.
54   Value *emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
55                      const DataLayout &DL, const TargetLibraryInfo *TLI);
56
57   /// Emit a call to the strcpy function to the builder, for the specified
58   /// pointer arguments.
59   Value *emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B,
60                     const TargetLibraryInfo *TLI, StringRef Name = "strcpy");
61
62   /// Emit a call to the strncpy function to the builder, for the specified
63   /// pointer arguments and length.
64   Value *emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B,
65                      const TargetLibraryInfo *TLI, StringRef Name = "strncpy");
66
67   /// Emit a call to the __memcpy_chk function to the builder. This expects that
68   /// the Len and ObjSize have type 'intptr_t' and Dst/Src are pointers.
69   Value *emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
70                        IRBuilder<> &B, const DataLayout &DL,
71                        const TargetLibraryInfo *TLI);
72
73   /// Emit a call to the memchr function. This assumes that Ptr is a pointer,
74   /// Val is an i32 value, and Len is an 'intptr_t' value.
75   Value *emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B,
76                     const DataLayout &DL, const TargetLibraryInfo *TLI);
77
78   /// Emit a call to the memcmp function.
79   Value *emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
80                     const DataLayout &DL, const TargetLibraryInfo *TLI);
81
82   /// Emit a call to the unary function named 'Name' (e.g.  'floor'). This
83   /// function is known to take a single of type matching 'Op' and returns one
84   /// value with the same type. If 'Op' is a long double, 'l' is added as the
85   /// suffix of name, if 'Op' is a float, we add a 'f' suffix.
86   Value *emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B,
87                               const AttributeList &Attrs);
88
89   /// Emit a call to the binary function named 'Name' (e.g. 'fmin'). This
90   /// function is known to take type matching 'Op1' and 'Op2' and return one
91   /// value with the same type. If 'Op1/Op2' are long double, 'l' is added as
92   /// the suffix of name, if 'Op1/Op2' are float, we add a 'f' suffix.
93   Value *emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
94                                IRBuilder<> &B, const AttributeList &Attrs);
95
96   /// Emit a call to the putchar function. This assumes that Char is an integer.
97   Value *emitPutChar(Value *Char, IRBuilder<> &B, const TargetLibraryInfo *TLI);
98
99   /// Emit a call to the puts function. This assumes that Str is some pointer.
100   Value *emitPutS(Value *Str, IRBuilder<> &B, const TargetLibraryInfo *TLI);
101
102   /// Emit a call to the fputc function. This assumes that Char is an i32, and
103   /// File is a pointer to FILE.
104   Value *emitFPutC(Value *Char, Value *File, IRBuilder<> &B,
105                    const TargetLibraryInfo *TLI);
106
107   /// Emit a call to the puts function. Str is required to be a pointer and
108   /// File is a pointer to FILE.
109   Value *emitFPutS(Value *Str, Value *File, IRBuilder<> &B,
110                    const TargetLibraryInfo *TLI);
111
112   /// Emit a call to the fwrite function. This assumes that Ptr is a pointer,
113   /// Size is an 'intptr_t', and File is a pointer to FILE.
114   Value *emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,
115                     const DataLayout &DL, const TargetLibraryInfo *TLI);
116 }
117
118 #endif