[llvm] f205950 - [BuildLibCalls] Use getPtrTy instead of getInt8PtrTy
Bjorn Pettersson via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 15 12:17:01 PST 2023
Author: Bjorn Pettersson
Date: 2023-11-15T21:16:32+01:00
New Revision: f205950e5ca6dc98ce839af9e7ab0ffe767dbe55
URL: https://github.com/llvm/llvm-project/commit/f205950e5ca6dc98ce839af9e7ab0ffe767dbe55
DIFF: https://github.com/llvm/llvm-project/commit/f205950e5ca6dc98ce839af9e7ab0ffe767dbe55.diff
LOG: [BuildLibCalls] Use getPtrTy instead of getInt8PtrTy
Stop using getInt8PtrTy() when referring to char* types when
building libcalls. As in many other files we can simply use
getPtrTy() instead, as part of transition into opaque pointers.
This patch is using thing like
Type *CharPtrTy = B.getPtrTy();
Type *VoidPtrTy = B.getPtrTy();
in several places, to give the pointer type a name.
The idea is to make the mapping to the libc function prototypes clear.
Added:
Modified:
llvm/lib/Transforms/Utils/BuildLibCalls.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index 594a5709ca12874..12741dc5af5a1d5 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -1456,62 +1456,63 @@ static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
Value *llvm::emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL,
const TargetLibraryInfo *TLI) {
+ Type *CharPtrTy = B.getPtrTy();
Type *SizeTTy = getSizeTTy(B, TLI);
- return emitLibCall(LibFunc_strlen, SizeTTy,
- B.getInt8PtrTy(), Ptr, B, TLI);
+ return emitLibCall(LibFunc_strlen, SizeTTy, CharPtrTy, Ptr, B, TLI);
}
Value *llvm::emitStrDup(Value *Ptr, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
- return emitLibCall(LibFunc_strdup, B.getInt8PtrTy(), B.getInt8PtrTy(),
- Ptr, B, TLI);
+ Type *CharPtrTy = B.getPtrTy();
+ return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy, Ptr, B, TLI);
}
Value *llvm::emitStrChr(Value *Ptr, char C, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *CharPtrTy = B.getPtrTy();
Type *IntTy = getIntTy(B, TLI);
- return emitLibCall(LibFunc_strchr, I8Ptr, {I8Ptr, IntTy},
+ return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
{Ptr, ConstantInt::get(IntTy, C)}, B, TLI);
}
Value *llvm::emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
+ Type *CharPtrTy = B.getPtrTy();
Type *IntTy = getIntTy(B, TLI);
Type *SizeTTy = getSizeTTy(B, TLI);
return emitLibCall(
LibFunc_strncmp, IntTy,
- {B.getInt8PtrTy(), B.getInt8PtrTy(), SizeTTy},
+ {CharPtrTy, CharPtrTy, SizeTTy},
{Ptr1, Ptr2, Len}, B, TLI);
}
Value *llvm::emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
- Type *I8Ptr = Dst->getType();
- return emitLibCall(LibFunc_strcpy, I8Ptr, {I8Ptr, I8Ptr},
+ Type *CharPtrTy = Dst->getType();
+ return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
{Dst, Src}, B, TLI);
}
Value *llvm::emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
- return emitLibCall(LibFunc_stpcpy, I8Ptr, {I8Ptr, I8Ptr},
+ Type *CharPtrTy = B.getPtrTy();
+ return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
{Dst, Src}, B, TLI);
}
Value *llvm::emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *CharPtrTy = B.getPtrTy();
Type *SizeTTy = getSizeTTy(B, TLI);
- return emitLibCall(LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
+ return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
{Dst, Src, Len}, B, TLI);
}
Value *llvm::emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *CharPtrTy = B.getPtrTy();
Type *SizeTTy = getSizeTTy(B, TLI);
- return emitLibCall(LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
+ return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
{Dst, Src, Len}, B, TLI);
}
@@ -1525,11 +1526,11 @@ Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
AttributeList AS;
AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
Attribute::NoUnwind);
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *VoidPtrTy = B.getPtrTy();
Type *SizeTTy = getSizeTTy(B, TLI);
FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
- AttributeList::get(M->getContext(), AS), I8Ptr,
- I8Ptr, I8Ptr, SizeTTy, SizeTTy);
+ AttributeList::get(M->getContext(), AS), VoidPtrTy,
+ VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
if (const Function *F =
dyn_cast<Function>(MemCpy.getCallee()->stripPointerCasts()))
@@ -1539,139 +1540,140 @@ Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
Value *llvm::emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *VoidPtrTy = B.getPtrTy();
Type *SizeTTy = getSizeTTy(B, TLI);
- return emitLibCall(LibFunc_mempcpy, I8Ptr,
- {I8Ptr, I8Ptr, SizeTTy},
+ return emitLibCall(LibFunc_mempcpy, VoidPtrTy,
+ {VoidPtrTy, VoidPtrTy, SizeTTy},
{Dst, Src, Len}, B, TLI);
}
Value *llvm::emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *VoidPtrTy = B.getPtrTy();
Type *IntTy = getIntTy(B, TLI);
Type *SizeTTy = getSizeTTy(B, TLI);
- return emitLibCall(LibFunc_memchr, I8Ptr,
- {I8Ptr, IntTy, SizeTTy},
+ return emitLibCall(LibFunc_memchr, VoidPtrTy,
+ {VoidPtrTy, IntTy, SizeTTy},
{Ptr, Val, Len}, B, TLI);
}
Value *llvm::emitMemRChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *VoidPtrTy = B.getPtrTy();
Type *IntTy = getIntTy(B, TLI);
Type *SizeTTy = getSizeTTy(B, TLI);
- return emitLibCall(LibFunc_memrchr, I8Ptr,
- {I8Ptr, IntTy, SizeTTy},
+ return emitLibCall(LibFunc_memrchr, VoidPtrTy,
+ {VoidPtrTy, IntTy, SizeTTy},
{Ptr, Val, Len}, B, TLI);
}
Value *llvm::emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *VoidPtrTy = B.getPtrTy();
Type *IntTy = getIntTy(B, TLI);
Type *SizeTTy = getSizeTTy(B, TLI);
return emitLibCall(LibFunc_memcmp, IntTy,
- {I8Ptr, I8Ptr, SizeTTy},
+ {VoidPtrTy, VoidPtrTy, SizeTTy},
{Ptr1, Ptr2, Len}, B, TLI);
}
Value *llvm::emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *VoidPtrTy = B.getPtrTy();
Type *IntTy = getIntTy(B, TLI);
Type *SizeTTy = getSizeTTy(B, TLI);
return emitLibCall(LibFunc_bcmp, IntTy,
- {I8Ptr, I8Ptr, SizeTTy},
+ {VoidPtrTy, VoidPtrTy, SizeTTy},
{Ptr1, Ptr2, Len}, B, TLI);
}
Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *VoidPtrTy = B.getPtrTy();
Type *IntTy = getIntTy(B, TLI);
Type *SizeTTy = getSizeTTy(B, TLI);
- return emitLibCall(LibFunc_memccpy, I8Ptr,
- {I8Ptr, I8Ptr, IntTy, SizeTTy},
+ return emitLibCall(LibFunc_memccpy, VoidPtrTy,
+ {VoidPtrTy, VoidPtrTy, 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 *CharPtrTy = B.getPtrTy();
Type *IntTy = getIntTy(B, TLI);
Type *SizeTTy = getSizeTTy(B, TLI);
SmallVector<Value *, 8> Args{Dest, Size, Fmt};
llvm::append_range(Args, VariadicArgs);
return emitLibCall(LibFunc_snprintf, IntTy,
- {I8Ptr, SizeTTy, I8Ptr},
+ {CharPtrTy, SizeTTy, CharPtrTy},
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 *CharPtrTy = B.getPtrTy();
Type *IntTy = getIntTy(B, TLI);
SmallVector<Value *, 8> Args{Dest, Fmt};
llvm::append_range(Args, VariadicArgs);
return emitLibCall(LibFunc_sprintf, IntTy,
- {I8Ptr, I8Ptr}, Args, B, TLI,
+ {CharPtrTy, CharPtrTy}, Args, B, TLI,
/*IsVaArgs=*/true);
}
Value *llvm::emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
- return emitLibCall(LibFunc_strcat, B.getInt8PtrTy(),
- {B.getInt8PtrTy(), B.getInt8PtrTy()},
+ Type *CharPtrTy = B.getPtrTy();
+ return emitLibCall(LibFunc_strcat, CharPtrTy,
+ {CharPtrTy, CharPtrTy},
{Dest, Src}, B, TLI);
}
Value *llvm::emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *CharPtrTy = B.getPtrTy();
Type *SizeTTy = getSizeTTy(B, TLI);
return emitLibCall(LibFunc_strlcpy, SizeTTy,
- {I8Ptr, I8Ptr, SizeTTy},
+ {CharPtrTy, CharPtrTy, SizeTTy},
{Dest, Src, Size}, B, TLI);
}
Value *llvm::emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *CharPtrTy = B.getPtrTy();
Type *SizeTTy = getSizeTTy(B, TLI);
return emitLibCall(LibFunc_strlcat, SizeTTy,
- {I8Ptr, I8Ptr, SizeTTy},
+ {CharPtrTy, CharPtrTy, SizeTTy},
{Dest, Src, Size}, B, TLI);
}
Value *llvm::emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *CharPtrTy = B.getPtrTy();
Type *SizeTTy = getSizeTTy(B, TLI);
- return emitLibCall(LibFunc_strncat, I8Ptr,
- {I8Ptr, I8Ptr, SizeTTy},
+ return emitLibCall(LibFunc_strncat, CharPtrTy,
+ {CharPtrTy, CharPtrTy, SizeTTy},
{Dest, Src, Size}, B, TLI);
}
Value *llvm::emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList,
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *CharPtrTy = B.getPtrTy();
Type *IntTy = getIntTy(B, TLI);
Type *SizeTTy = getSizeTTy(B, TLI);
return emitLibCall(
LibFunc_vsnprintf, IntTy,
- {I8Ptr, SizeTTy, I8Ptr, VAList->getType()},
+ {CharPtrTy, SizeTTy, CharPtrTy, VAList->getType()},
{Dest, Size, Fmt, VAList}, B, TLI);
}
Value *llvm::emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList,
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
- Type *I8Ptr = B.getInt8PtrTy();
+ Type *CharPtrTy = B.getPtrTy();
Type *IntTy = getIntTy(B, TLI);
return emitLibCall(LibFunc_vsprintf, IntTy,
- {I8Ptr, I8Ptr, VAList->getType()},
+ {CharPtrTy, CharPtrTy, VAList->getType()},
{Dest, Fmt, VAList}, B, TLI);
}
@@ -1822,7 +1824,7 @@ Value *llvm::emitPutS(Value *Str, IRBuilderBase &B,
Type *IntTy = getIntTy(B, TLI);
StringRef PutsName = TLI->getName(LibFunc_puts);
FunctionCallee PutS = getOrInsertLibFunc(M, *TLI, LibFunc_puts, IntTy,
- B.getInt8PtrTy());
+ B.getPtrTy());
inferNonMandatoryLibFuncAttrs(M, PutsName, *TLI);
CallInst *CI = B.CreateCall(PutS, Str, PutsName);
if (const Function *F =
@@ -1860,7 +1862,7 @@ Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilderBase &B,
Type *IntTy = getIntTy(B, TLI);
StringRef FPutsName = TLI->getName(LibFunc_fputs);
FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputs, IntTy,
- B.getInt8PtrTy(), File->getType());
+ B.getPtrTy(), File->getType());
if (File->getType()->isPointerTy())
inferNonMandatoryLibFuncAttrs(M, FPutsName, *TLI);
CallInst *CI = B.CreateCall(F, {Str, File}, FPutsName);
@@ -1880,7 +1882,7 @@ Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B,
Type *SizeTTy = getSizeTTy(B, TLI);
StringRef FWriteName = TLI->getName(LibFunc_fwrite);
FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fwrite,
- SizeTTy, B.getInt8PtrTy(), SizeTTy,
+ SizeTTy, B.getPtrTy(), SizeTTy,
SizeTTy, File->getType());
if (File->getType()->isPointerTy())
@@ -1904,7 +1906,7 @@ Value *llvm::emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL,
StringRef MallocName = TLI->getName(LibFunc_malloc);
Type *SizeTTy = getSizeTTy(B, TLI);
FunctionCallee Malloc = getOrInsertLibFunc(M, *TLI, LibFunc_malloc,
- B.getInt8PtrTy(), SizeTTy);
+ B.getPtrTy(), SizeTTy);
inferNonMandatoryLibFuncAttrs(M, MallocName, *TLI);
CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
@@ -1924,7 +1926,7 @@ Value *llvm::emitCalloc(Value *Num, Value *Size, IRBuilderBase &B,
StringRef CallocName = TLI.getName(LibFunc_calloc);
Type *SizeTTy = getSizeTTy(B, &TLI);
FunctionCallee Calloc = getOrInsertLibFunc(M, TLI, LibFunc_calloc,
- B.getInt8PtrTy(), SizeTTy, SizeTTy);
+ B.getPtrTy(), SizeTTy, SizeTTy);
inferNonMandatoryLibFuncAttrs(M, CallocName, TLI);
CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
@@ -1943,7 +1945,7 @@ Value *llvm::emitHotColdNew(Value *Num, IRBuilderBase &B,
return nullptr;
StringRef Name = TLI->getName(NewFunc);
- FunctionCallee Func = M->getOrInsertFunction(Name, B.getInt8PtrTy(),
+ FunctionCallee Func = M->getOrInsertFunction(Name, B.getPtrTy(),
Num->getType(), B.getInt8Ty());
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
CallInst *CI = B.CreateCall(Func, {Num, B.getInt8(HotCold)}, Name);
@@ -1964,7 +1966,7 @@ Value *llvm::emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B,
StringRef Name = TLI->getName(NewFunc);
FunctionCallee Func =
- M->getOrInsertFunction(Name, B.getInt8PtrTy(), Num->getType(),
+ M->getOrInsertFunction(Name, B.getPtrTy(), Num->getType(),
NoThrow->getType(), B.getInt8Ty());
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
CallInst *CI = B.CreateCall(Func, {Num, NoThrow, B.getInt8(HotCold)}, Name);
@@ -1985,7 +1987,7 @@ Value *llvm::emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B,
StringRef Name = TLI->getName(NewFunc);
FunctionCallee Func = M->getOrInsertFunction(
- Name, B.getInt8PtrTy(), Num->getType(), Align->getType(), B.getInt8Ty());
+ Name, B.getPtrTy(), Num->getType(), Align->getType(), B.getInt8Ty());
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
CallInst *CI = B.CreateCall(Func, {Num, Align, B.getInt8(HotCold)}, Name);
@@ -2006,7 +2008,7 @@ Value *llvm::emitHotColdNewAlignedNoThrow(Value *Num, Value *Align,
StringRef Name = TLI->getName(NewFunc);
FunctionCallee Func = M->getOrInsertFunction(
- Name, B.getInt8PtrTy(), Num->getType(), Align->getType(),
+ Name, B.getPtrTy(), Num->getType(), Align->getType(),
NoThrow->getType(), B.getInt8Ty());
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
CallInst *CI =
More information about the llvm-commits
mailing list