LLVM  mainline
BuildLibCalls.cpp
Go to the documentation of this file.
00001 //===- BuildLibCalls.cpp - Utility builder for libcalls -------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements some functions that will create standard C libcalls.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Transforms/Utils/BuildLibCalls.h"
00015 #include "llvm/ADT/SmallString.h"
00016 #include "llvm/IR/Constants.h"
00017 #include "llvm/IR/DataLayout.h"
00018 #include "llvm/IR/Function.h"
00019 #include "llvm/IR/IRBuilder.h"
00020 #include "llvm/IR/Intrinsics.h"
00021 #include "llvm/IR/LLVMContext.h"
00022 #include "llvm/IR/Module.h"
00023 #include "llvm/IR/Type.h"
00024 #include "llvm/Analysis/TargetLibraryInfo.h"
00025 
00026 using namespace llvm;
00027 
00028 /// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*.
00029 Value *llvm::CastToCStr(Value *V, IRBuilder<> &B) {
00030   unsigned AS = V->getType()->getPointerAddressSpace();
00031   return B.CreateBitCast(V, B.getInt8PtrTy(AS), "cstr");
00032 }
00033 
00034 /// EmitStrLen - Emit a call to the strlen function to the builder, for the
00035 /// specified pointer.  This always returns an integer value of size intptr_t.
00036 Value *llvm::EmitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL,
00037                         const TargetLibraryInfo *TLI) {
00038   if (!TLI->has(LibFunc::strlen))
00039     return nullptr;
00040 
00041   Module *M = B.GetInsertBlock()->getParent()->getParent();
00042   AttributeSet AS[2];
00043   AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
00044   Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
00045   AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
00046 
00047   LLVMContext &Context = B.GetInsertBlock()->getContext();
00048   Constant *StrLen = M->getOrInsertFunction(
00049       "strlen", AttributeSet::get(M->getContext(), AS),
00050       DL.getIntPtrType(Context), B.getInt8PtrTy(), nullptr);
00051   CallInst *CI = B.CreateCall(StrLen, CastToCStr(Ptr, B), "strlen");
00052   if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts()))
00053     CI->setCallingConv(F->getCallingConv());
00054 
00055   return CI;
00056 }
00057 
00058 /// EmitStrNLen - Emit a call to the strnlen function to the builder, for the
00059 /// specified pointer.  Ptr is required to be some pointer type, MaxLen must
00060 /// be of size_t type, and the return value has 'intptr_t' type.
00061 Value *llvm::EmitStrNLen(Value *Ptr, Value *MaxLen, IRBuilder<> &B,
00062                          const DataLayout &DL, const TargetLibraryInfo *TLI) {
00063   if (!TLI->has(LibFunc::strnlen))
00064     return nullptr;
00065 
00066   Module *M = B.GetInsertBlock()->getParent()->getParent();
00067   AttributeSet AS[2];
00068   AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
00069   Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
00070   AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
00071 
00072   LLVMContext &Context = B.GetInsertBlock()->getContext();
00073   Constant *StrNLen =
00074       M->getOrInsertFunction("strnlen", AttributeSet::get(M->getContext(), AS),
00075                              DL.getIntPtrType(Context), B.getInt8PtrTy(),
00076                              DL.getIntPtrType(Context), nullptr);
00077   CallInst *CI = B.CreateCall(StrNLen, {CastToCStr(Ptr, B), MaxLen}, "strnlen");
00078   if (const Function *F = dyn_cast<Function>(StrNLen->stripPointerCasts()))
00079     CI->setCallingConv(F->getCallingConv());
00080 
00081   return CI;
00082 }
00083 
00084 /// EmitStrChr - Emit a call to the strchr function to the builder, for the
00085 /// specified pointer and character.  Ptr is required to be some pointer type,
00086 /// and the return value has 'i8*' type.
00087 Value *llvm::EmitStrChr(Value *Ptr, char C, IRBuilder<> &B,
00088                         const TargetLibraryInfo *TLI) {
00089   if (!TLI->has(LibFunc::strchr))
00090     return nullptr;
00091 
00092   Module *M = B.GetInsertBlock()->getParent()->getParent();
00093   Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
00094   AttributeSet AS =
00095     AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
00096 
00097   Type *I8Ptr = B.getInt8PtrTy();
00098   Type *I32Ty = B.getInt32Ty();
00099   Constant *StrChr = M->getOrInsertFunction("strchr",
00100                                             AttributeSet::get(M->getContext(),
00101                                                              AS),
00102                                             I8Ptr, I8Ptr, I32Ty, nullptr);
00103   CallInst *CI = B.CreateCall(
00104       StrChr, {CastToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, "strchr");
00105   if (const Function *F = dyn_cast<Function>(StrChr->stripPointerCasts()))
00106     CI->setCallingConv(F->getCallingConv());
00107   return CI;
00108 }
00109 
00110 /// EmitStrNCmp - Emit a call to the strncmp function to the builder.
00111 Value *llvm::EmitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
00112                          const DataLayout &DL, const TargetLibraryInfo *TLI) {
00113   if (!TLI->has(LibFunc::strncmp))
00114     return nullptr;
00115 
00116   Module *M = B.GetInsertBlock()->getParent()->getParent();
00117   AttributeSet AS[3];
00118   AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
00119   AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
00120   Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
00121   AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
00122 
00123   LLVMContext &Context = B.GetInsertBlock()->getContext();
00124   Value *StrNCmp = M->getOrInsertFunction(
00125       "strncmp", AttributeSet::get(M->getContext(), AS), B.getInt32Ty(),
00126       B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context), nullptr);
00127   CallInst *CI = B.CreateCall(
00128       StrNCmp, {CastToCStr(Ptr1, B), CastToCStr(Ptr2, B), Len}, "strncmp");
00129 
00130   if (const Function *F = dyn_cast<Function>(StrNCmp->stripPointerCasts()))
00131     CI->setCallingConv(F->getCallingConv());
00132 
00133   return CI;
00134 }
00135 
00136 /// EmitStrCpy - Emit a call to the strcpy function to the builder, for the
00137 /// specified pointer arguments.
00138 Value *llvm::EmitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B,
00139                         const TargetLibraryInfo *TLI, StringRef Name) {
00140   if (!TLI->has(LibFunc::strcpy))
00141     return nullptr;
00142 
00143   Module *M = B.GetInsertBlock()->getParent()->getParent();
00144   AttributeSet AS[2];
00145   AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
00146   AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
00147                             Attribute::NoUnwind);
00148   Type *I8Ptr = B.getInt8PtrTy();
00149   Value *StrCpy = M->getOrInsertFunction(Name,
00150                                          AttributeSet::get(M->getContext(), AS),
00151                                          I8Ptr, I8Ptr, I8Ptr, nullptr);
00152   CallInst *CI =
00153       B.CreateCall(StrCpy, {CastToCStr(Dst, B), CastToCStr(Src, B)}, Name);
00154   if (const Function *F = dyn_cast<Function>(StrCpy->stripPointerCasts()))
00155     CI->setCallingConv(F->getCallingConv());
00156   return CI;
00157 }
00158 
00159 /// EmitStrNCpy - Emit a call to the strncpy function to the builder, for the
00160 /// specified pointer arguments.
00161 Value *llvm::EmitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B,
00162                          const TargetLibraryInfo *TLI, StringRef Name) {
00163   if (!TLI->has(LibFunc::strncpy))
00164     return nullptr;
00165 
00166   Module *M = B.GetInsertBlock()->getParent()->getParent();
00167   AttributeSet AS[2];
00168   AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
00169   AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
00170                             Attribute::NoUnwind);
00171   Type *I8Ptr = B.getInt8PtrTy();
00172   Value *StrNCpy = M->getOrInsertFunction(Name,
00173                                           AttributeSet::get(M->getContext(),
00174                                                             AS),
00175                                           I8Ptr, I8Ptr, I8Ptr,
00176                                           Len->getType(), nullptr);
00177   CallInst *CI = B.CreateCall(
00178       StrNCpy, {CastToCStr(Dst, B), CastToCStr(Src, B), Len}, "strncpy");
00179   if (const Function *F = dyn_cast<Function>(StrNCpy->stripPointerCasts()))
00180     CI->setCallingConv(F->getCallingConv());
00181   return CI;
00182 }
00183 
00184 /// EmitMemCpyChk - Emit a call to the __memcpy_chk function to the builder.
00185 /// This expects that the Len and ObjSize have type 'intptr_t' and Dst/Src
00186 /// are pointers.
00187 Value *llvm::EmitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
00188                            IRBuilder<> &B, const DataLayout &DL,
00189                            const TargetLibraryInfo *TLI) {
00190   if (!TLI->has(LibFunc::memcpy_chk))
00191     return nullptr;
00192 
00193   Module *M = B.GetInsertBlock()->getParent()->getParent();
00194   AttributeSet AS;
00195   AS = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
00196                          Attribute::NoUnwind);
00197   LLVMContext &Context = B.GetInsertBlock()->getContext();
00198   Value *MemCpy = M->getOrInsertFunction(
00199       "__memcpy_chk", AttributeSet::get(M->getContext(), AS), B.getInt8PtrTy(),
00200       B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context),
00201       DL.getIntPtrType(Context), nullptr);
00202   Dst = CastToCStr(Dst, B);
00203   Src = CastToCStr(Src, B);
00204   CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
00205   if (const Function *F = dyn_cast<Function>(MemCpy->stripPointerCasts()))
00206     CI->setCallingConv(F->getCallingConv());
00207   return CI;
00208 }
00209 
00210 /// EmitMemChr - Emit a call to the memchr function.  This assumes that Ptr is
00211 /// a pointer, Val is an i32 value, and Len is an 'intptr_t' value.
00212 Value *llvm::EmitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B,
00213                         const DataLayout &DL, const TargetLibraryInfo *TLI) {
00214   if (!TLI->has(LibFunc::memchr))
00215     return nullptr;
00216 
00217   Module *M = B.GetInsertBlock()->getParent()->getParent();
00218   AttributeSet AS;
00219   Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
00220   AS = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
00221   LLVMContext &Context = B.GetInsertBlock()->getContext();
00222   Value *MemChr = M->getOrInsertFunction(
00223       "memchr", AttributeSet::get(M->getContext(), AS), B.getInt8PtrTy(),
00224       B.getInt8PtrTy(), B.getInt32Ty(), DL.getIntPtrType(Context), nullptr);
00225   CallInst *CI = B.CreateCall(MemChr, {CastToCStr(Ptr, B), Val, Len}, "memchr");
00226 
00227   if (const Function *F = dyn_cast<Function>(MemChr->stripPointerCasts()))
00228     CI->setCallingConv(F->getCallingConv());
00229 
00230   return CI;
00231 }
00232 
00233 /// EmitMemCmp - Emit a call to the memcmp function.
00234 Value *llvm::EmitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
00235                         const DataLayout &DL, const TargetLibraryInfo *TLI) {
00236   if (!TLI->has(LibFunc::memcmp))
00237     return nullptr;
00238 
00239   Module *M = B.GetInsertBlock()->getParent()->getParent();
00240   AttributeSet AS[3];
00241   AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
00242   AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
00243   Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
00244   AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
00245 
00246   LLVMContext &Context = B.GetInsertBlock()->getContext();
00247   Value *MemCmp = M->getOrInsertFunction(
00248       "memcmp", AttributeSet::get(M->getContext(), AS), B.getInt32Ty(),
00249       B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context), nullptr);
00250   CallInst *CI = B.CreateCall(
00251       MemCmp, {CastToCStr(Ptr1, B), CastToCStr(Ptr2, B), Len}, "memcmp");
00252 
00253   if (const Function *F = dyn_cast<Function>(MemCmp->stripPointerCasts()))
00254     CI->setCallingConv(F->getCallingConv());
00255 
00256   return CI;
00257 }
00258 
00259 /// Append a suffix to the function name according to the type of 'Op'.
00260 static void AppendTypeSuffix(Value *Op, StringRef &Name, SmallString<20> &NameBuffer) {
00261   if (!Op->getType()->isDoubleTy()) {
00262       NameBuffer += Name;
00263 
00264     if (Op->getType()->isFloatTy())
00265       NameBuffer += 'f';
00266     else
00267       NameBuffer += 'l';
00268 
00269     Name = NameBuffer;
00270   }  
00271   return;
00272 }
00273 
00274 /// EmitUnaryFloatFnCall - Emit a call to the unary function named 'Name' (e.g.
00275 /// 'floor').  This function is known to take a single of type matching 'Op' and
00276 /// returns one value with the same type.  If 'Op' is a long double, 'l' is
00277 /// added as the suffix of name, if 'Op' is a float, we add a 'f' suffix.
00278 Value *llvm::EmitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B,
00279                                   const AttributeSet &Attrs) {
00280   SmallString<20> NameBuffer;
00281   AppendTypeSuffix(Op, Name, NameBuffer);   
00282 
00283   Module *M = B.GetInsertBlock()->getParent()->getParent();
00284   Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
00285                                          Op->getType(), nullptr);
00286   CallInst *CI = B.CreateCall(Callee, Op, Name);
00287   CI->setAttributes(Attrs);
00288   if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
00289     CI->setCallingConv(F->getCallingConv());
00290 
00291   return CI;
00292 }
00293 
00294 /// EmitBinaryFloatFnCall - Emit a call to the binary function named 'Name'
00295 /// (e.g. 'fmin').  This function is known to take type matching 'Op1' and 'Op2'
00296 /// and return one value with the same type.  If 'Op1/Op2' are long double, 'l'
00297 /// is added as the suffix of name, if 'Op1/Op2' is a float, we add a 'f'
00298 /// suffix.
00299 Value *llvm::EmitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
00300                                   IRBuilder<> &B, const AttributeSet &Attrs) {
00301   SmallString<20> NameBuffer;
00302   AppendTypeSuffix(Op1, Name, NameBuffer);   
00303 
00304   Module *M = B.GetInsertBlock()->getParent()->getParent();
00305   Value *Callee = M->getOrInsertFunction(Name, Op1->getType(),
00306                                          Op1->getType(), Op2->getType(), nullptr);
00307   CallInst *CI = B.CreateCall(Callee, {Op1, Op2}, Name);
00308   CI->setAttributes(Attrs);
00309   if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
00310     CI->setCallingConv(F->getCallingConv());
00311 
00312   return CI;
00313 }
00314 
00315 /// EmitPutChar - Emit a call to the putchar function.  This assumes that Char
00316 /// is an integer.
00317 Value *llvm::EmitPutChar(Value *Char, IRBuilder<> &B,
00318                          const TargetLibraryInfo *TLI) {
00319   if (!TLI->has(LibFunc::putchar))
00320     return nullptr;
00321 
00322   Module *M = B.GetInsertBlock()->getParent()->getParent();
00323   Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(),
00324                                           B.getInt32Ty(), nullptr);
00325   CallInst *CI = B.CreateCall(PutChar,
00326                               B.CreateIntCast(Char,
00327                               B.getInt32Ty(),
00328                               /*isSigned*/true,
00329                               "chari"),
00330                               "putchar");
00331 
00332   if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts()))
00333     CI->setCallingConv(F->getCallingConv());
00334   return CI;
00335 }
00336 
00337 /// EmitPutS - Emit a call to the puts function.  This assumes that Str is
00338 /// some pointer.
00339 Value *llvm::EmitPutS(Value *Str, IRBuilder<> &B,
00340                       const TargetLibraryInfo *TLI) {
00341   if (!TLI->has(LibFunc::puts))
00342     return nullptr;
00343 
00344   Module *M = B.GetInsertBlock()->getParent()->getParent();
00345   AttributeSet AS[2];
00346   AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
00347   AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
00348                             Attribute::NoUnwind);
00349 
00350   Value *PutS = M->getOrInsertFunction("puts",
00351                                        AttributeSet::get(M->getContext(), AS),
00352                                        B.getInt32Ty(),
00353                                        B.getInt8PtrTy(),
00354                                        nullptr);
00355   CallInst *CI = B.CreateCall(PutS, CastToCStr(Str, B), "puts");
00356   if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts()))
00357     CI->setCallingConv(F->getCallingConv());
00358   return CI;
00359 }
00360 
00361 /// EmitFPutC - Emit a call to the fputc function.  This assumes that Char is
00362 /// an integer and File is a pointer to FILE.
00363 Value *llvm::EmitFPutC(Value *Char, Value *File, IRBuilder<> &B,
00364                        const TargetLibraryInfo *TLI) {
00365   if (!TLI->has(LibFunc::fputc))
00366     return nullptr;
00367 
00368   Module *M = B.GetInsertBlock()->getParent()->getParent();
00369   AttributeSet AS[2];
00370   AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
00371   AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
00372                             Attribute::NoUnwind);
00373   Constant *F;
00374   if (File->getType()->isPointerTy())
00375     F = M->getOrInsertFunction("fputc",
00376                                AttributeSet::get(M->getContext(), AS),
00377                                B.getInt32Ty(),
00378                                B.getInt32Ty(), File->getType(),
00379                                nullptr);
00380   else
00381     F = M->getOrInsertFunction("fputc",
00382                                B.getInt32Ty(),
00383                                B.getInt32Ty(),
00384                                File->getType(), nullptr);
00385   Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
00386                          "chari");
00387   CallInst *CI = B.CreateCall(F, {Char, File}, "fputc");
00388 
00389   if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
00390     CI->setCallingConv(Fn->getCallingConv());
00391   return CI;
00392 }
00393 
00394 /// EmitFPutS - Emit a call to the puts function.  Str is required to be a
00395 /// pointer and File is a pointer to FILE.
00396 Value *llvm::EmitFPutS(Value *Str, Value *File, IRBuilder<> &B,
00397                        const TargetLibraryInfo *TLI) {
00398   if (!TLI->has(LibFunc::fputs))
00399     return nullptr;
00400 
00401   Module *M = B.GetInsertBlock()->getParent()->getParent();
00402   AttributeSet AS[3];
00403   AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
00404   AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
00405   AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
00406                             Attribute::NoUnwind);
00407   StringRef FPutsName = TLI->getName(LibFunc::fputs);
00408   Constant *F;
00409   if (File->getType()->isPointerTy())
00410     F = M->getOrInsertFunction(FPutsName,
00411                                AttributeSet::get(M->getContext(), AS),
00412                                B.getInt32Ty(),
00413                                B.getInt8PtrTy(),
00414                                File->getType(), nullptr);
00415   else
00416     F = M->getOrInsertFunction(FPutsName, B.getInt32Ty(),
00417                                B.getInt8PtrTy(),
00418                                File->getType(), nullptr);
00419   CallInst *CI = B.CreateCall(F, {CastToCStr(Str, B), File}, "fputs");
00420 
00421   if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
00422     CI->setCallingConv(Fn->getCallingConv());
00423   return CI;
00424 }
00425 
00426 /// EmitFWrite - Emit a call to the fwrite function.  This assumes that Ptr is
00427 /// a pointer, Size is an 'intptr_t', and File is a pointer to FILE.
00428 Value *llvm::EmitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,
00429                         const DataLayout &DL, const TargetLibraryInfo *TLI) {
00430   if (!TLI->has(LibFunc::fwrite))
00431     return nullptr;
00432 
00433   Module *M = B.GetInsertBlock()->getParent()->getParent();
00434   AttributeSet AS[3];
00435   AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
00436   AS[1] = AttributeSet::get(M->getContext(), 4, Attribute::NoCapture);
00437   AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
00438                             Attribute::NoUnwind);
00439   LLVMContext &Context = B.GetInsertBlock()->getContext();
00440   StringRef FWriteName = TLI->getName(LibFunc::fwrite);
00441   Constant *F;
00442   if (File->getType()->isPointerTy())
00443     F = M->getOrInsertFunction(
00444         FWriteName, AttributeSet::get(M->getContext(), AS),
00445         DL.getIntPtrType(Context), B.getInt8PtrTy(), DL.getIntPtrType(Context),
00446         DL.getIntPtrType(Context), File->getType(), nullptr);
00447   else
00448     F = M->getOrInsertFunction(FWriteName, DL.getIntPtrType(Context),
00449                                B.getInt8PtrTy(), DL.getIntPtrType(Context),
00450                                DL.getIntPtrType(Context), File->getType(),
00451                                nullptr);
00452   CallInst *CI =
00453       B.CreateCall(F, {CastToCStr(Ptr, B), Size,
00454                        ConstantInt::get(DL.getIntPtrType(Context), 1), File});
00455 
00456   if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
00457     CI->setCallingConv(Fn->getCallingConv());
00458   return CI;
00459 }