Value *llvm::emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL,
const TargetLibraryInfo *TLI) {
LLVMContext &Context = B.GetInsertBlock()->getContext();
- return emitLibCall(LibFunc_strlen, DL.getIntPtrType(Context),
+ Type *SizeTTy = DL.getIntPtrType(Context);
+ return emitLibCall(LibFunc_strlen, SizeTTy,
B.getInt8PtrTy(), castToCStr(Ptr, B), B, TLI);
}
Value *llvm::emitStrChr(Value *Ptr, char C, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
Type *I8Ptr = B.getInt8PtrTy();
- Type *I32Ty = B.getInt32Ty();
- return emitLibCall(LibFunc_strchr, I8Ptr, {I8Ptr, I32Ty},
- {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, B, TLI);
+ Type *IntTy = B.getInt32Ty();
+ return emitLibCall(LibFunc_strchr, I8Ptr, {I8Ptr, IntTy},
+ {castToCStr(Ptr, B), ConstantInt::get(IntTy, C)}, B, TLI);
}
Value *llvm::emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
LLVMContext &Context = B.GetInsertBlock()->getContext();
+ Type *SizeTTy = DL.getIntPtrType(Context);
+ Type *IntTy = B.getInt32Ty();
return emitLibCall(
- LibFunc_strncmp, B.getInt32Ty(),
- {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
+ LibFunc_strncmp, IntTy,
+ {B.getInt8PtrTy(), B.getInt8PtrTy(), SizeTTy},
{castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
}
Value *llvm::emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
Type *I8Ptr = B.getInt8PtrTy();
- return emitLibCall(LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType()},
+ Type *SizeTTy = Len->getType();
+ return emitLibCall(LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
{castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
}
Value *llvm::emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
Type *I8Ptr = B.getInt8PtrTy();
- return emitLibCall(LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType()},
+ Type *SizeTTy = Len->getType();
+ return emitLibCall(LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
{castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
}
AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
Attribute::NoUnwind);
LLVMContext &Context = B.GetInsertBlock()->getContext();
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *SizeTTy = DL.getIntPtrType(Context);
FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
- AttributeList::get(M->getContext(), AS), B.getInt8PtrTy(),
- B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context),
- DL.getIntPtrType(Context));
+ AttributeList::get(M->getContext(), AS), I8Ptr,
+ I8Ptr, I8Ptr, SizeTTy, SizeTTy);
Dst = castToCStr(Dst, B);
Src = castToCStr(Src, B);
CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
Value *llvm::emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
LLVMContext &Context = B.GetInsertBlock()->getContext();
- return emitLibCall(
- LibFunc_mempcpy, B.getInt8PtrTy(),
- {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
- {Dst, Src, Len}, B, TLI);
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *SizeTTy = DL.getIntPtrType(Context);
+ return emitLibCall(LibFunc_mempcpy, I8Ptr,
+ {I8Ptr, I8Ptr, SizeTTy},
+ {Dst, Src, Len}, B, TLI);
}
Value *llvm::emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
LLVMContext &Context = B.GetInsertBlock()->getContext();
- return emitLibCall(
- LibFunc_memchr, B.getInt8PtrTy(),
- {B.getInt8PtrTy(), B.getInt32Ty(), DL.getIntPtrType(Context)},
- {castToCStr(Ptr, B), Val, Len}, B, TLI);
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *IntTy = B.getInt32Ty();
+ Type *SizeTTy = DL.getIntPtrType(Context);
+ return emitLibCall(LibFunc_memchr, I8Ptr,
+ {I8Ptr, IntTy, SizeTTy},
+ {castToCStr(Ptr, B), Val, Len}, B, TLI);
}
Value *llvm::emitMemRChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
LLVMContext &Context = B.GetInsertBlock()->getContext();
- return emitLibCall(
- LibFunc_memrchr, B.getInt8PtrTy(),
- {B.getInt8PtrTy(), B.getInt32Ty(), DL.getIntPtrType(Context)},
- {castToCStr(Ptr, B), Val, Len}, B, TLI);
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *IntTy = B.getInt32Ty();
+ Type *SizeTTy = DL.getIntPtrType(Context);
+ return emitLibCall(LibFunc_memrchr, I8Ptr,
+ {I8Ptr, IntTy, SizeTTy},
+ {castToCStr(Ptr, B), Val, Len}, B, TLI);
}
Value *llvm::emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
LLVMContext &Context = B.GetInsertBlock()->getContext();
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *IntTy = B.getInt32Ty();
+ Type *SizeTTy = DL.getIntPtrType(Context);
return emitLibCall(
- LibFunc_memcmp, B.getInt32Ty(),
- {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
+ LibFunc_memcmp, IntTy,
+ {I8Ptr, I8Ptr, SizeTTy},
{castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
}
Value *llvm::emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
LLVMContext &Context = B.GetInsertBlock()->getContext();
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *IntTy = B.getInt32Ty();
+ Type *SizeTTy = DL.getIntPtrType(Context);
return emitLibCall(
- LibFunc_bcmp, B.getInt32Ty(),
- {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)},
+ LibFunc_bcmp, IntTy,
+ {I8Ptr, I8Ptr, SizeTTy},
{castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
}
Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *IntTy = B.getInt32Ty();
+ Type *SizeTTy = Len->getType();
return emitLibCall(
- LibFunc_memccpy, B.getInt8PtrTy(),
- {B.getInt8PtrTy(), B.getInt8PtrTy(), B.getInt32Ty(), Len->getType()},
+ LibFunc_memccpy, I8Ptr,
+ {I8Ptr, I8Ptr, IntTy, SizeTTy},
{Ptr1, Ptr2, Val, Len}, B, TLI);
}
Value *llvm::emitSNPrintf(Value *Dest, Value *Size, Value *Fmt,
ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *IntTy = B.getInt32Ty();
+ Type *SizeTTy = Size->getType();
SmallVector<Value *, 8> Args{castToCStr(Dest, B), Size, castToCStr(Fmt, B)};
llvm::append_range(Args, VariadicArgs);
- return emitLibCall(LibFunc_snprintf, B.getInt32Ty(),
- {B.getInt8PtrTy(), Size->getType(), B.getInt8PtrTy()},
+ return emitLibCall(LibFunc_snprintf, IntTy,
+ {I8Ptr, SizeTTy, I8Ptr},
Args, B, TLI, /*IsVaArgs=*/true);
}
Value *llvm::emitSPrintf(Value *Dest, Value *Fmt,
ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *IntTy = B.getInt32Ty();
SmallVector<Value *, 8> Args{castToCStr(Dest, B), castToCStr(Fmt, B)};
llvm::append_range(Args, VariadicArgs);
- return emitLibCall(LibFunc_sprintf, B.getInt32Ty(),
- {B.getInt8PtrTy(), B.getInt8PtrTy()}, Args, B, TLI,
+ return emitLibCall(LibFunc_sprintf, IntTy,
+ {I8Ptr, I8Ptr}, Args, B, TLI,
/*IsVaArgs=*/true);
}
Value *llvm::emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
- return emitLibCall(LibFunc_strlcpy, Size->getType(),
- {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *SizeTTy = Size->getType();
+ return emitLibCall(LibFunc_strlcpy, SizeTTy,
+ {I8Ptr, I8Ptr, SizeTTy},
{castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
}
Value *llvm::emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
- return emitLibCall(LibFunc_strlcat, Size->getType(),
- {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *SizeTTy = Size->getType();
+ return emitLibCall(LibFunc_strlcat, SizeTTy,
+ {I8Ptr, I8Ptr, SizeTTy},
{castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
}
Value *llvm::emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
- return emitLibCall(LibFunc_strncat, B.getInt8PtrTy(),
- {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()},
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *SizeTTy = Size->getType();
+ return emitLibCall(LibFunc_strncat, I8Ptr,
+ {I8Ptr, I8Ptr, SizeTTy},
{castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
}
Value *llvm::emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList,
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *IntTy = B.getInt32Ty();
+ Type *SizeTTy = Size->getType();
return emitLibCall(
- LibFunc_vsnprintf, B.getInt32Ty(),
- {B.getInt8PtrTy(), Size->getType(), B.getInt8PtrTy(), VAList->getType()},
+ LibFunc_vsnprintf, IntTy,
+ {I8Ptr, SizeTTy, I8Ptr, VAList->getType()},
{castToCStr(Dest, B), Size, castToCStr(Fmt, B), VAList}, B, TLI);
}
Value *llvm::emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList,
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
- return emitLibCall(LibFunc_vsprintf, B.getInt32Ty(),
- {B.getInt8PtrTy(), B.getInt8PtrTy(), VAList->getType()},
+ Type *I8Ptr = B.getInt8PtrTy();
+ Type *IntTy = B.getInt32Ty();
+ return emitLibCall(LibFunc_vsprintf, IntTy,
+ {I8Ptr, I8Ptr, VAList->getType()},
{castToCStr(Dest, B), castToCStr(Fmt, B), VAList}, B, TLI);
}
if (!isLibFuncEmittable(M, TLI, LibFunc_putchar))
return nullptr;
- Type *Ty = Char->getType();
+ Type *IntTy = Char->getType();
StringRef PutCharName = TLI->getName(LibFunc_putchar);
- FunctionCallee PutChar = getOrInsertLibFunc(M, *TLI, LibFunc_putchar, Ty, Ty);
+ FunctionCallee PutChar = getOrInsertLibFunc(M, *TLI, LibFunc_putchar,
+ IntTy, IntTy);
inferNonMandatoryLibFuncAttrs(M, PutCharName, *TLI);
CallInst *CI = B.CreateCall(PutChar, Char, PutCharName);
if (!isLibFuncEmittable(M, TLI, LibFunc_puts))
return nullptr;
+ Type *IntTy = B.getInt32Ty();
StringRef PutsName = TLI->getName(LibFunc_puts);
- FunctionCallee PutS = getOrInsertLibFunc(M, *TLI, LibFunc_puts, B.getInt32Ty(),
+ FunctionCallee PutS = getOrInsertLibFunc(M, *TLI, LibFunc_puts, IntTy,
B.getInt8PtrTy());
inferNonMandatoryLibFuncAttrs(M, PutsName, *TLI);
CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), PutsName);
if (!isLibFuncEmittable(M, TLI, LibFunc_fputc))
return nullptr;
+ Type *IntTy = B.getInt32Ty();
StringRef FPutcName = TLI->getName(LibFunc_fputc);
- FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputc, B.getInt32Ty(),
- B.getInt32Ty(), File->getType());
+ FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputc, IntTy,
+ IntTy, File->getType());
if (File->getType()->isPointerTy())
inferNonMandatoryLibFuncAttrs(M, FPutcName, *TLI);
- Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
+ Char = B.CreateIntCast(Char, IntTy, /*isSigned*/true,
"chari");
CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName);
if (!isLibFuncEmittable(M, TLI, LibFunc_fputs))
return nullptr;
+ Type *IntTy = B.getInt32Ty();
StringRef FPutsName = TLI->getName(LibFunc_fputs);
- FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputs, B.getInt32Ty(),
+ FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputs, IntTy,
B.getInt8PtrTy(), File->getType());
if (File->getType()->isPointerTy())
inferNonMandatoryLibFuncAttrs(M, FPutsName, *TLI);
return nullptr;
LLVMContext &Context = B.GetInsertBlock()->getContext();
+ Type *SizeTTy = DL.getIntPtrType(Context);
StringRef FWriteName = TLI->getName(LibFunc_fwrite);
FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fwrite,
- DL.getIntPtrType(Context), B.getInt8PtrTy(), DL.getIntPtrType(Context),
- DL.getIntPtrType(Context), File->getType());
+ SizeTTy, B.getInt8PtrTy(), SizeTTy,
+ SizeTTy, File->getType());
if (File->getType()->isPointerTy())
inferNonMandatoryLibFuncAttrs(M, FWriteName, *TLI);
StringRef MallocName = TLI->getName(LibFunc_malloc);
LLVMContext &Context = B.GetInsertBlock()->getContext();
+ Type *SizeTTy = DL.getIntPtrType(Context);
FunctionCallee Malloc = getOrInsertLibFunc(M, *TLI, LibFunc_malloc,
- B.getInt8PtrTy(), DL.getIntPtrType(Context));
+ B.getInt8PtrTy(), SizeTTy);
inferNonMandatoryLibFuncAttrs(M, MallocName, *TLI);
CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
return nullptr;
StringRef CallocName = TLI.getName(LibFunc_calloc);
+ LLVMContext &Context = B.GetInsertBlock()->getContext();
const DataLayout &DL = M->getDataLayout();
- IntegerType *PtrType = DL.getIntPtrType((B.GetInsertBlock()->getContext()));
+ Type *SizeTTy = DL.getIntPtrType(Context);
FunctionCallee Calloc = getOrInsertLibFunc(M, TLI, LibFunc_calloc,
- B.getInt8PtrTy(), PtrType, PtrType);
+ B.getInt8PtrTy(), SizeTTy, SizeTTy);
inferNonMandatoryLibFuncAttrs(M, CallocName, TLI);
CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);