]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.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 TRANSFORMS_UTILS_BUILDLIBCALLS_H
16 #define TRANSFORMS_UTILS_BUILDLIBCALLS_H
17
18 #include "llvm/Support/IRBuilder.h"
19
20 namespace llvm {
21   class Value;
22   class TargetData;
23   
24   /// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*.
25   Value *CastToCStr(Value *V, IRBuilder<> &B);
26
27   /// EmitStrLen - Emit a call to the strlen function to the builder, for the
28   /// specified pointer.  Ptr is required to be some pointer type, and the
29   /// return value has 'intptr_t' type.
30   Value *EmitStrLen(Value *Ptr, IRBuilder<> &B, const TargetData *TD);
31
32   /// EmitStrChr - Emit a call to the strchr function to the builder, for the
33   /// specified pointer and character.  Ptr is required to be some pointer type,
34   /// and the return value has 'i8*' type.
35   Value *EmitStrChr(Value *Ptr, char C, IRBuilder<> &B, const TargetData *TD);
36
37   /// EmitStrNCmp - Emit a call to the strncmp function to the builder.
38   Value *EmitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
39                      const TargetData *TD);
40
41   /// EmitStrCpy - Emit a call to the strcpy function to the builder, for the
42   /// specified pointer arguments.
43   Value *EmitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B,
44                     const TargetData *TD, StringRef Name = "strcpy");
45
46   /// EmitStrNCpy - Emit a call to the strncpy function to the builder, for the
47   /// specified pointer arguments and length.
48   Value *EmitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B,
49                     const TargetData *TD, StringRef Name = "strncpy");
50
51   /// EmitMemCpyChk - Emit a call to the __memcpy_chk function to the builder.
52   /// This expects that the Len and ObjSize have type 'intptr_t' and Dst/Src
53   /// are pointers.
54   Value *EmitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
55                        IRBuilder<> &B, const TargetData *TD);
56
57   /// EmitMemChr - Emit a call to the memchr function.  This assumes that Ptr is
58   /// a pointer, Val is an i32 value, and Len is an 'intptr_t' value.
59   Value *EmitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B,
60                     const TargetData *TD);
61
62   /// EmitMemCmp - Emit a call to the memcmp function.
63   Value *EmitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
64                     const TargetData *TD);
65
66   /// EmitUnaryFloatFnCall - Emit a call to the unary function named 'Name'
67   /// (e.g.  'floor').  This function is known to take a single of type matching
68   /// 'Op' and returns one value with the same type.  If 'Op' is a long double,
69   /// 'l' is added as the suffix of name, if 'Op' is a float, we add a 'f'
70   /// suffix.
71   Value *EmitUnaryFloatFnCall(Value *Op, const char *Name, IRBuilder<> &B,
72                               const AttrListPtr &Attrs);
73
74   /// EmitPutChar - Emit a call to the putchar function.  This assumes that Char
75   /// is an integer.
76   Value *EmitPutChar(Value *Char, IRBuilder<> &B, const TargetData *TD);
77
78   /// EmitPutS - Emit a call to the puts function.  This assumes that Str is
79   /// some pointer.
80   void EmitPutS(Value *Str, IRBuilder<> &B, const TargetData *TD);
81
82   /// EmitFPutC - Emit a call to the fputc function.  This assumes that Char is
83   /// an i32, and File is a pointer to FILE.
84   void EmitFPutC(Value *Char, Value *File, IRBuilder<> &B,
85                  const TargetData *TD);
86
87   /// EmitFPutS - Emit a call to the puts function.  Str is required to be a
88   /// pointer and File is a pointer to FILE.
89   void EmitFPutS(Value *Str, Value *File, IRBuilder<> &B, const TargetData *TD);
90
91   /// EmitFWrite - Emit a call to the fwrite function.  This assumes that Ptr is
92   /// a pointer, Size is an 'intptr_t', and File is a pointer to FILE.
93   void EmitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,
94                   const TargetData *TD);
95
96   /// SimplifyFortifiedLibCalls - Helper class for folding checked library
97   /// calls (e.g. __strcpy_chk) into their unchecked counterparts.
98   class SimplifyFortifiedLibCalls {
99   protected:
100     CallInst *CI;
101     virtual void replaceCall(Value *With) = 0;
102     virtual bool isFoldable(unsigned SizeCIOp, unsigned SizeArgOp,
103                             bool isString) const = 0;
104   public:
105     virtual ~SimplifyFortifiedLibCalls();
106     bool fold(CallInst *CI, const TargetData *TD);
107   };
108 }
109
110 #endif