Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 1 | //===- BuildLibCalls.cpp - Utility builder for libcalls -------------------===// |
| 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 implements some functions that will create standard C libcalls. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/Transforms/Utils/BuildLibCalls.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/SmallString.h" |
Weiming Zhao | 45d4cb9 | 2015-11-24 18:57:06 +0000 | [diff] [blame^] | 16 | #include "llvm/Analysis/TargetLibraryInfo.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 17 | #include "llvm/IR/Constants.h" |
| 18 | #include "llvm/IR/DataLayout.h" |
| 19 | #include "llvm/IR/Function.h" |
| 20 | #include "llvm/IR/IRBuilder.h" |
| 21 | #include "llvm/IR/Intrinsics.h" |
| 22 | #include "llvm/IR/LLVMContext.h" |
| 23 | #include "llvm/IR/Module.h" |
| 24 | #include "llvm/IR/Type.h" |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 25 | |
| 26 | using namespace llvm; |
| 27 | |
| 28 | /// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*. |
| 29 | Value *llvm::CastToCStr(Value *V, IRBuilder<> &B) { |
Matt Arsenault | be55888 | 2014-04-23 20:58:57 +0000 | [diff] [blame] | 30 | unsigned AS = V->getType()->getPointerAddressSpace(); |
| 31 | return B.CreateBitCast(V, B.getInt8PtrTy(AS), "cstr"); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | /// EmitStrLen - Emit a call to the strlen function to the builder, for the |
| 35 | /// specified pointer. This always returns an integer value of size intptr_t. |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 36 | Value *llvm::EmitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL, |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 37 | const TargetLibraryInfo *TLI) { |
| 38 | if (!TLI->has(LibFunc::strlen)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 39 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 40 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 41 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 42 | AttributeSet AS[2]; |
| 43 | AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture); |
Bill Wendling | c79e42c | 2012-12-22 00:37:52 +0000 | [diff] [blame] | 44 | Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind }; |
Craig Topper | e1d1294 | 2014-08-27 05:25:25 +0000 | [diff] [blame] | 45 | AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 46 | |
Chandler Carruth | 7ec5085 | 2012-11-01 08:07:29 +0000 | [diff] [blame] | 47 | LLVMContext &Context = B.GetInsertBlock()->getContext(); |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 48 | Constant *StrLen = M->getOrInsertFunction( |
| 49 | "strlen", AttributeSet::get(M->getContext(), AS), |
| 50 | DL.getIntPtrType(Context), B.getInt8PtrTy(), nullptr); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 51 | CallInst *CI = B.CreateCall(StrLen, CastToCStr(Ptr, B), "strlen"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 52 | if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts())) |
| 53 | CI->setCallingConv(F->getCallingConv()); |
| 54 | |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 55 | return CI; |
| 56 | } |
| 57 | |
| 58 | /// EmitStrChr - Emit a call to the strchr function to the builder, for the |
| 59 | /// specified pointer and character. Ptr is required to be some pointer type, |
| 60 | /// and the return value has 'i8*' type. |
| 61 | Value *llvm::EmitStrChr(Value *Ptr, char C, IRBuilder<> &B, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 62 | const TargetLibraryInfo *TLI) { |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 63 | if (!TLI->has(LibFunc::strchr)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 64 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 65 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 66 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Bill Wendling | c79e42c | 2012-12-22 00:37:52 +0000 | [diff] [blame] | 67 | Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind }; |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 68 | AttributeSet AS = |
Craig Topper | e1d1294 | 2014-08-27 05:25:25 +0000 | [diff] [blame] | 69 | AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 70 | |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 71 | Type *I8Ptr = B.getInt8PtrTy(); |
| 72 | Type *I32Ty = B.getInt32Ty(); |
Bill Wendling | f86efb9 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 73 | Constant *StrChr = M->getOrInsertFunction("strchr", |
Bill Wendling | e94d843 | 2012-12-07 23:16:57 +0000 | [diff] [blame] | 74 | AttributeSet::get(M->getContext(), |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 75 | AS), |
Reid Kleckner | 971c3ea | 2014-11-13 22:55:19 +0000 | [diff] [blame] | 76 | I8Ptr, I8Ptr, I32Ty, nullptr); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 77 | CallInst *CI = B.CreateCall( |
| 78 | StrChr, {CastToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, "strchr"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 79 | if (const Function *F = dyn_cast<Function>(StrChr->stripPointerCasts())) |
| 80 | CI->setCallingConv(F->getCallingConv()); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 81 | return CI; |
| 82 | } |
| 83 | |
Benjamin Kramer | 1118860 | 2010-06-15 21:34:25 +0000 | [diff] [blame] | 84 | /// EmitStrNCmp - Emit a call to the strncmp function to the builder. |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 85 | Value *llvm::EmitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, |
| 86 | const DataLayout &DL, const TargetLibraryInfo *TLI) { |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 87 | if (!TLI->has(LibFunc::strncmp)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 88 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 89 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 90 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 91 | AttributeSet AS[3]; |
| 92 | AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture); |
| 93 | AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture); |
Bill Wendling | c79e42c | 2012-12-22 00:37:52 +0000 | [diff] [blame] | 94 | Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind }; |
Craig Topper | e1d1294 | 2014-08-27 05:25:25 +0000 | [diff] [blame] | 95 | AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs); |
Benjamin Kramer | 1118860 | 2010-06-15 21:34:25 +0000 | [diff] [blame] | 96 | |
Chandler Carruth | 7ec5085 | 2012-11-01 08:07:29 +0000 | [diff] [blame] | 97 | LLVMContext &Context = B.GetInsertBlock()->getContext(); |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 98 | Value *StrNCmp = M->getOrInsertFunction( |
| 99 | "strncmp", AttributeSet::get(M->getContext(), AS), B.getInt32Ty(), |
| 100 | B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context), nullptr); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 101 | CallInst *CI = B.CreateCall( |
| 102 | StrNCmp, {CastToCStr(Ptr1, B), CastToCStr(Ptr2, B), Len}, "strncmp"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 103 | |
| 104 | if (const Function *F = dyn_cast<Function>(StrNCmp->stripPointerCasts())) |
| 105 | CI->setCallingConv(F->getCallingConv()); |
| 106 | |
Benjamin Kramer | 1118860 | 2010-06-15 21:34:25 +0000 | [diff] [blame] | 107 | return CI; |
| 108 | } |
| 109 | |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 110 | /// EmitStrCpy - Emit a call to the strcpy function to the builder, for the |
| 111 | /// specified pointer arguments. |
| 112 | Value *llvm::EmitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 113 | const TargetLibraryInfo *TLI, StringRef Name) { |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 114 | if (!TLI->has(LibFunc::strcpy)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 115 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 116 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 117 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 118 | AttributeSet AS[2]; |
| 119 | AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture); |
| 120 | AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, |
| 121 | Attribute::NoUnwind); |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 122 | Type *I8Ptr = B.getInt8PtrTy(); |
Bill Wendling | f86efb9 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 123 | Value *StrCpy = M->getOrInsertFunction(Name, |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 124 | AttributeSet::get(M->getContext(), AS), |
Reid Kleckner | 971c3ea | 2014-11-13 22:55:19 +0000 | [diff] [blame] | 125 | I8Ptr, I8Ptr, I8Ptr, nullptr); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 126 | CallInst *CI = |
| 127 | B.CreateCall(StrCpy, {CastToCStr(Dst, B), CastToCStr(Src, B)}, Name); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 128 | if (const Function *F = dyn_cast<Function>(StrCpy->stripPointerCasts())) |
| 129 | CI->setCallingConv(F->getCallingConv()); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 130 | return CI; |
| 131 | } |
| 132 | |
Eric Christopher | 103e3ef | 2010-03-11 17:45:38 +0000 | [diff] [blame] | 133 | /// EmitStrNCpy - Emit a call to the strncpy function to the builder, for the |
Eric Christopher | 43dc11c | 2010-03-11 01:25:07 +0000 | [diff] [blame] | 134 | /// specified pointer arguments. |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 135 | Value *llvm::EmitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B, |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 136 | const TargetLibraryInfo *TLI, StringRef Name) { |
| 137 | if (!TLI->has(LibFunc::strncpy)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 138 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 139 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 140 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 141 | AttributeSet AS[2]; |
| 142 | AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture); |
| 143 | AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, |
| 144 | Attribute::NoUnwind); |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 145 | Type *I8Ptr = B.getInt8PtrTy(); |
Bill Wendling | f86efb9 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 146 | Value *StrNCpy = M->getOrInsertFunction(Name, |
Bill Wendling | e94d843 | 2012-12-07 23:16:57 +0000 | [diff] [blame] | 147 | AttributeSet::get(M->getContext(), |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 148 | AS), |
Eric Christopher | e8b281c | 2010-04-07 23:00:07 +0000 | [diff] [blame] | 149 | I8Ptr, I8Ptr, I8Ptr, |
Reid Kleckner | 971c3ea | 2014-11-13 22:55:19 +0000 | [diff] [blame] | 150 | Len->getType(), nullptr); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 151 | CallInst *CI = B.CreateCall( |
| 152 | StrNCpy, {CastToCStr(Dst, B), CastToCStr(Src, B), Len}, "strncpy"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 153 | if (const Function *F = dyn_cast<Function>(StrNCpy->stripPointerCasts())) |
| 154 | CI->setCallingConv(F->getCallingConv()); |
Eric Christopher | 43dc11c | 2010-03-11 01:25:07 +0000 | [diff] [blame] | 155 | return CI; |
| 156 | } |
| 157 | |
Evan Cheng | d9e8223 | 2010-03-23 15:48:04 +0000 | [diff] [blame] | 158 | /// EmitMemCpyChk - Emit a call to the __memcpy_chk function to the builder. |
| 159 | /// This expects that the Len and ObjSize have type 'intptr_t' and Dst/Src |
| 160 | /// are pointers. |
| 161 | Value *llvm::EmitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 162 | IRBuilder<> &B, const DataLayout &DL, |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 163 | const TargetLibraryInfo *TLI) { |
| 164 | if (!TLI->has(LibFunc::memcpy_chk)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 165 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 166 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 167 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 168 | AttributeSet AS; |
| 169 | AS = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, |
| 170 | Attribute::NoUnwind); |
Chandler Carruth | 7ec5085 | 2012-11-01 08:07:29 +0000 | [diff] [blame] | 171 | LLVMContext &Context = B.GetInsertBlock()->getContext(); |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 172 | Value *MemCpy = M->getOrInsertFunction( |
| 173 | "__memcpy_chk", AttributeSet::get(M->getContext(), AS), B.getInt8PtrTy(), |
| 174 | B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context), |
| 175 | DL.getIntPtrType(Context), nullptr); |
Evan Cheng | d9e8223 | 2010-03-23 15:48:04 +0000 | [diff] [blame] | 176 | Dst = CastToCStr(Dst, B); |
| 177 | Src = CastToCStr(Src, B); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 178 | CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize}); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 179 | if (const Function *F = dyn_cast<Function>(MemCpy->stripPointerCasts())) |
| 180 | CI->setCallingConv(F->getCallingConv()); |
Evan Cheng | d9e8223 | 2010-03-23 15:48:04 +0000 | [diff] [blame] | 181 | return CI; |
| 182 | } |
| 183 | |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 184 | /// EmitMemChr - Emit a call to the memchr function. This assumes that Ptr is |
| 185 | /// a pointer, Val is an i32 value, and Len is an 'intptr_t' value. |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 186 | Value *llvm::EmitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B, |
| 187 | const DataLayout &DL, const TargetLibraryInfo *TLI) { |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 188 | if (!TLI->has(LibFunc::memchr)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 189 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 190 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 191 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 192 | AttributeSet AS; |
Bill Wendling | c79e42c | 2012-12-22 00:37:52 +0000 | [diff] [blame] | 193 | Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind }; |
Craig Topper | e1d1294 | 2014-08-27 05:25:25 +0000 | [diff] [blame] | 194 | AS = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs); |
Chandler Carruth | 7ec5085 | 2012-11-01 08:07:29 +0000 | [diff] [blame] | 195 | LLVMContext &Context = B.GetInsertBlock()->getContext(); |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 196 | Value *MemChr = M->getOrInsertFunction( |
| 197 | "memchr", AttributeSet::get(M->getContext(), AS), B.getInt8PtrTy(), |
| 198 | B.getInt8PtrTy(), B.getInt32Ty(), DL.getIntPtrType(Context), nullptr); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 199 | CallInst *CI = B.CreateCall(MemChr, {CastToCStr(Ptr, B), Val, Len}, "memchr"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 200 | |
| 201 | if (const Function *F = dyn_cast<Function>(MemChr->stripPointerCasts())) |
| 202 | CI->setCallingConv(F->getCallingConv()); |
| 203 | |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 204 | return CI; |
| 205 | } |
| 206 | |
| 207 | /// EmitMemCmp - Emit a call to the memcmp function. |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 208 | Value *llvm::EmitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, |
| 209 | const DataLayout &DL, const TargetLibraryInfo *TLI) { |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 210 | if (!TLI->has(LibFunc::memcmp)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 211 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 212 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 213 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 214 | AttributeSet AS[3]; |
| 215 | AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture); |
| 216 | AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture); |
Bill Wendling | c79e42c | 2012-12-22 00:37:52 +0000 | [diff] [blame] | 217 | Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind }; |
Craig Topper | e1d1294 | 2014-08-27 05:25:25 +0000 | [diff] [blame] | 218 | AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 219 | |
Chandler Carruth | 7ec5085 | 2012-11-01 08:07:29 +0000 | [diff] [blame] | 220 | LLVMContext &Context = B.GetInsertBlock()->getContext(); |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 221 | Value *MemCmp = M->getOrInsertFunction( |
| 222 | "memcmp", AttributeSet::get(M->getContext(), AS), B.getInt32Ty(), |
| 223 | B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context), nullptr); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 224 | CallInst *CI = B.CreateCall( |
| 225 | MemCmp, {CastToCStr(Ptr1, B), CastToCStr(Ptr2, B), Len}, "memcmp"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 226 | |
| 227 | if (const Function *F = dyn_cast<Function>(MemCmp->stripPointerCasts())) |
| 228 | CI->setCallingConv(F->getCallingConv()); |
| 229 | |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 230 | return CI; |
| 231 | } |
| 232 | |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 233 | /// Append a suffix to the function name according to the type of 'Op'. |
| 234 | static void AppendTypeSuffix(Value *Op, StringRef &Name, SmallString<20> &NameBuffer) { |
| 235 | if (!Op->getType()->isDoubleTy()) { |
| 236 | NameBuffer += Name; |
| 237 | |
| 238 | if (Op->getType()->isFloatTy()) |
| 239 | NameBuffer += 'f'; |
| 240 | else |
| 241 | NameBuffer += 'l'; |
| 242 | |
| 243 | Name = NameBuffer; |
| 244 | } |
| 245 | return; |
| 246 | } |
| 247 | |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 248 | /// EmitUnaryFloatFnCall - Emit a call to the unary function named 'Name' (e.g. |
| 249 | /// 'floor'). This function is known to take a single of type matching 'Op' and |
| 250 | /// returns one value with the same type. If 'Op' is a long double, 'l' is |
| 251 | /// added as the suffix of name, if 'Op' is a float, we add a 'f' suffix. |
Benjamin Kramer | b106bcc | 2011-11-15 19:12:09 +0000 | [diff] [blame] | 252 | Value *llvm::EmitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B, |
Bill Wendling | e94d843 | 2012-12-07 23:16:57 +0000 | [diff] [blame] | 253 | const AttributeSet &Attrs) { |
Benjamin Kramer | b106bcc | 2011-11-15 19:12:09 +0000 | [diff] [blame] | 254 | SmallString<20> NameBuffer; |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 255 | AppendTypeSuffix(Op, Name, NameBuffer); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 256 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 257 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 258 | Value *Callee = M->getOrInsertFunction(Name, Op->getType(), |
Reid Kleckner | 971c3ea | 2014-11-13 22:55:19 +0000 | [diff] [blame] | 259 | Op->getType(), nullptr); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 260 | CallInst *CI = B.CreateCall(Callee, Op, Name); |
| 261 | CI->setAttributes(Attrs); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 262 | if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts())) |
| 263 | CI->setCallingConv(F->getCallingConv()); |
| 264 | |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 265 | return CI; |
| 266 | } |
| 267 | |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 268 | /// EmitBinaryFloatFnCall - Emit a call to the binary function named 'Name' |
| 269 | /// (e.g. 'fmin'). This function is known to take type matching 'Op1' and 'Op2' |
| 270 | /// and return one value with the same type. If 'Op1/Op2' are long double, 'l' |
| 271 | /// is added as the suffix of name, if 'Op1/Op2' is a float, we add a 'f' |
| 272 | /// suffix. |
| 273 | Value *llvm::EmitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name, |
| 274 | IRBuilder<> &B, const AttributeSet &Attrs) { |
| 275 | SmallString<20> NameBuffer; |
| 276 | AppendTypeSuffix(Op1, Name, NameBuffer); |
| 277 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 278 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 279 | Value *Callee = M->getOrInsertFunction(Name, Op1->getType(), |
Reid Kleckner | 971c3ea | 2014-11-13 22:55:19 +0000 | [diff] [blame] | 280 | Op1->getType(), Op2->getType(), nullptr); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 281 | CallInst *CI = B.CreateCall(Callee, {Op1, Op2}, Name); |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 282 | CI->setAttributes(Attrs); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 283 | if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts())) |
| 284 | CI->setCallingConv(F->getCallingConv()); |
| 285 | |
Yi Jiang | 6ab044e | 2013-12-16 22:42:40 +0000 | [diff] [blame] | 286 | return CI; |
| 287 | } |
| 288 | |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 289 | /// EmitPutChar - Emit a call to the putchar function. This assumes that Char |
| 290 | /// is an integer. |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 291 | Value *llvm::EmitPutChar(Value *Char, IRBuilder<> &B, |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 292 | const TargetLibraryInfo *TLI) { |
| 293 | if (!TLI->has(LibFunc::putchar)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 294 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 295 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 296 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 297 | Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(), |
Reid Kleckner | 971c3ea | 2014-11-13 22:55:19 +0000 | [diff] [blame] | 298 | B.getInt32Ty(), nullptr); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 299 | CallInst *CI = B.CreateCall(PutChar, |
| 300 | B.CreateIntCast(Char, |
| 301 | B.getInt32Ty(), |
| 302 | /*isSigned*/true, |
| 303 | "chari"), |
| 304 | "putchar"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 305 | |
| 306 | if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts())) |
| 307 | CI->setCallingConv(F->getCallingConv()); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 308 | return CI; |
| 309 | } |
| 310 | |
| 311 | /// EmitPutS - Emit a call to the puts function. This assumes that Str is |
| 312 | /// some pointer. |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 313 | Value *llvm::EmitPutS(Value *Str, IRBuilder<> &B, |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 314 | const TargetLibraryInfo *TLI) { |
| 315 | if (!TLI->has(LibFunc::puts)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 316 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 317 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 318 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 319 | AttributeSet AS[2]; |
| 320 | AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture); |
| 321 | AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, |
| 322 | Attribute::NoUnwind); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 323 | |
Bill Wendling | f86efb9 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 324 | Value *PutS = M->getOrInsertFunction("puts", |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 325 | AttributeSet::get(M->getContext(), AS), |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 326 | B.getInt32Ty(), |
| 327 | B.getInt8PtrTy(), |
Reid Kleckner | 971c3ea | 2014-11-13 22:55:19 +0000 | [diff] [blame] | 328 | nullptr); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 329 | CallInst *CI = B.CreateCall(PutS, CastToCStr(Str, B), "puts"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 330 | if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts())) |
| 331 | CI->setCallingConv(F->getCallingConv()); |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 332 | return CI; |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /// EmitFPutC - Emit a call to the fputc function. This assumes that Char is |
| 336 | /// an integer and File is a pointer to FILE. |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 337 | Value *llvm::EmitFPutC(Value *Char, Value *File, IRBuilder<> &B, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 338 | const TargetLibraryInfo *TLI) { |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 339 | if (!TLI->has(LibFunc::fputc)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 340 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 341 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 342 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 343 | AttributeSet AS[2]; |
| 344 | AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture); |
| 345 | AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, |
| 346 | Attribute::NoUnwind); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 347 | Constant *F; |
| 348 | if (File->getType()->isPointerTy()) |
Bill Wendling | f86efb9 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 349 | F = M->getOrInsertFunction("fputc", |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 350 | AttributeSet::get(M->getContext(), AS), |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 351 | B.getInt32Ty(), |
| 352 | B.getInt32Ty(), File->getType(), |
Reid Kleckner | 971c3ea | 2014-11-13 22:55:19 +0000 | [diff] [blame] | 353 | nullptr); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 354 | else |
| 355 | F = M->getOrInsertFunction("fputc", |
| 356 | B.getInt32Ty(), |
| 357 | B.getInt32Ty(), |
Reid Kleckner | 971c3ea | 2014-11-13 22:55:19 +0000 | [diff] [blame] | 358 | File->getType(), nullptr); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 359 | Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true, |
| 360 | "chari"); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 361 | CallInst *CI = B.CreateCall(F, {Char, File}, "fputc"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 362 | |
| 363 | if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) |
| 364 | CI->setCallingConv(Fn->getCallingConv()); |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 365 | return CI; |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | /// EmitFPutS - Emit a call to the puts function. Str is required to be a |
| 369 | /// pointer and File is a pointer to FILE. |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 370 | Value *llvm::EmitFPutS(Value *Str, Value *File, IRBuilder<> &B, |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 371 | const TargetLibraryInfo *TLI) { |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 372 | if (!TLI->has(LibFunc::fputs)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 373 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 374 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 375 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 376 | AttributeSet AS[3]; |
| 377 | AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture); |
| 378 | AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture); |
| 379 | AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, |
| 380 | Attribute::NoUnwind); |
Eli Friedman | 489c0ff | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 381 | StringRef FPutsName = TLI->getName(LibFunc::fputs); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 382 | Constant *F; |
| 383 | if (File->getType()->isPointerTy()) |
Bill Wendling | f86efb9 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 384 | F = M->getOrInsertFunction(FPutsName, |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 385 | AttributeSet::get(M->getContext(), AS), |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 386 | B.getInt32Ty(), |
| 387 | B.getInt8PtrTy(), |
Reid Kleckner | 971c3ea | 2014-11-13 22:55:19 +0000 | [diff] [blame] | 388 | File->getType(), nullptr); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 389 | else |
Eli Friedman | 489c0ff | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 390 | F = M->getOrInsertFunction(FPutsName, B.getInt32Ty(), |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 391 | B.getInt8PtrTy(), |
Reid Kleckner | 971c3ea | 2014-11-13 22:55:19 +0000 | [diff] [blame] | 392 | File->getType(), nullptr); |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 393 | CallInst *CI = B.CreateCall(F, {CastToCStr(Str, B), File}, "fputs"); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 394 | |
| 395 | if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) |
| 396 | CI->setCallingConv(Fn->getCallingConv()); |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 397 | return CI; |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | /// EmitFWrite - Emit a call to the fwrite function. This assumes that Ptr is |
| 401 | /// a pointer, Size is an 'intptr_t', and File is a pointer to FILE. |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 402 | Value *llvm::EmitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B, |
| 403 | const DataLayout &DL, const TargetLibraryInfo *TLI) { |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 404 | if (!TLI->has(LibFunc::fwrite)) |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 405 | return nullptr; |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 406 | |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 407 | Module *M = B.GetInsertBlock()->getParent()->getParent(); |
Bill Wendling | 201d7b2 | 2013-01-26 00:03:11 +0000 | [diff] [blame] | 408 | AttributeSet AS[3]; |
| 409 | AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture); |
| 410 | AS[1] = AttributeSet::get(M->getContext(), 4, Attribute::NoCapture); |
| 411 | AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, |
| 412 | Attribute::NoUnwind); |
Chandler Carruth | 7ec5085 | 2012-11-01 08:07:29 +0000 | [diff] [blame] | 413 | LLVMContext &Context = B.GetInsertBlock()->getContext(); |
Eli Friedman | 489c0ff | 2011-11-17 01:27:36 +0000 | [diff] [blame] | 414 | StringRef FWriteName = TLI->getName(LibFunc::fwrite); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 415 | Constant *F; |
| 416 | if (File->getType()->isPointerTy()) |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 417 | F = M->getOrInsertFunction( |
| 418 | FWriteName, AttributeSet::get(M->getContext(), AS), |
| 419 | DL.getIntPtrType(Context), B.getInt8PtrTy(), DL.getIntPtrType(Context), |
| 420 | DL.getIntPtrType(Context), File->getType(), nullptr); |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 421 | else |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 422 | F = M->getOrInsertFunction(FWriteName, DL.getIntPtrType(Context), |
| 423 | B.getInt8PtrTy(), DL.getIntPtrType(Context), |
| 424 | DL.getIntPtrType(Context), File->getType(), |
| 425 | nullptr); |
| 426 | CallInst *CI = |
David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 427 | B.CreateCall(F, {CastToCStr(Ptr, B), Size, |
| 428 | ConstantInt::get(DL.getIntPtrType(Context), 1), File}); |
Evan Cheng | ad6efbf | 2014-03-12 18:09:37 +0000 | [diff] [blame] | 429 | |
| 430 | if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) |
| 431 | CI->setCallingConv(Fn->getCallingConv()); |
Nuno Lopes | 89702e9 | 2012-07-25 16:46:31 +0000 | [diff] [blame] | 432 | return CI; |
Eric Christopher | 87abfc5 | 2010-03-05 22:25:30 +0000 | [diff] [blame] | 433 | } |