Skip to content

Commit f205950

Browse files
committed
[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.
1 parent 06a65ce commit f205950

File tree

1 file changed

+62
-60
lines changed

1 file changed

+62
-60
lines changed

llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,62 +1456,63 @@ static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
14561456

14571457
Value *llvm::emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL,
14581458
const TargetLibraryInfo *TLI) {
1459+
Type *CharPtrTy = B.getPtrTy();
14591460
Type *SizeTTy = getSizeTTy(B, TLI);
1460-
return emitLibCall(LibFunc_strlen, SizeTTy,
1461-
B.getInt8PtrTy(), Ptr, B, TLI);
1461+
return emitLibCall(LibFunc_strlen, SizeTTy, CharPtrTy, Ptr, B, TLI);
14621462
}
14631463

14641464
Value *llvm::emitStrDup(Value *Ptr, IRBuilderBase &B,
14651465
const TargetLibraryInfo *TLI) {
1466-
return emitLibCall(LibFunc_strdup, B.getInt8PtrTy(), B.getInt8PtrTy(),
1467-
Ptr, B, TLI);
1466+
Type *CharPtrTy = B.getPtrTy();
1467+
return emitLibCall(LibFunc_strdup, CharPtrTy, CharPtrTy, Ptr, B, TLI);
14681468
}
14691469

14701470
Value *llvm::emitStrChr(Value *Ptr, char C, IRBuilderBase &B,
14711471
const TargetLibraryInfo *TLI) {
1472-
Type *I8Ptr = B.getInt8PtrTy();
1472+
Type *CharPtrTy = B.getPtrTy();
14731473
Type *IntTy = getIntTy(B, TLI);
1474-
return emitLibCall(LibFunc_strchr, I8Ptr, {I8Ptr, IntTy},
1474+
return emitLibCall(LibFunc_strchr, CharPtrTy, {CharPtrTy, IntTy},
14751475
{Ptr, ConstantInt::get(IntTy, C)}, B, TLI);
14761476
}
14771477

14781478
Value *llvm::emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
14791479
const DataLayout &DL, const TargetLibraryInfo *TLI) {
1480+
Type *CharPtrTy = B.getPtrTy();
14801481
Type *IntTy = getIntTy(B, TLI);
14811482
Type *SizeTTy = getSizeTTy(B, TLI);
14821483
return emitLibCall(
14831484
LibFunc_strncmp, IntTy,
1484-
{B.getInt8PtrTy(), B.getInt8PtrTy(), SizeTTy},
1485+
{CharPtrTy, CharPtrTy, SizeTTy},
14851486
{Ptr1, Ptr2, Len}, B, TLI);
14861487
}
14871488

14881489
Value *llvm::emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B,
14891490
const TargetLibraryInfo *TLI) {
1490-
Type *I8Ptr = Dst->getType();
1491-
return emitLibCall(LibFunc_strcpy, I8Ptr, {I8Ptr, I8Ptr},
1491+
Type *CharPtrTy = Dst->getType();
1492+
return emitLibCall(LibFunc_strcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
14921493
{Dst, Src}, B, TLI);
14931494
}
14941495

14951496
Value *llvm::emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B,
14961497
const TargetLibraryInfo *TLI) {
1497-
Type *I8Ptr = B.getInt8PtrTy();
1498-
return emitLibCall(LibFunc_stpcpy, I8Ptr, {I8Ptr, I8Ptr},
1498+
Type *CharPtrTy = B.getPtrTy();
1499+
return emitLibCall(LibFunc_stpcpy, CharPtrTy, {CharPtrTy, CharPtrTy},
14991500
{Dst, Src}, B, TLI);
15001501
}
15011502

15021503
Value *llvm::emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
15031504
const TargetLibraryInfo *TLI) {
1504-
Type *I8Ptr = B.getInt8PtrTy();
1505+
Type *CharPtrTy = B.getPtrTy();
15051506
Type *SizeTTy = getSizeTTy(B, TLI);
1506-
return emitLibCall(LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
1507+
return emitLibCall(LibFunc_strncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
15071508
{Dst, Src, Len}, B, TLI);
15081509
}
15091510

15101511
Value *llvm::emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
15111512
const TargetLibraryInfo *TLI) {
1512-
Type *I8Ptr = B.getInt8PtrTy();
1513+
Type *CharPtrTy = B.getPtrTy();
15131514
Type *SizeTTy = getSizeTTy(B, TLI);
1514-
return emitLibCall(LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
1515+
return emitLibCall(LibFunc_stpncpy, CharPtrTy, {CharPtrTy, CharPtrTy, SizeTTy},
15151516
{Dst, Src, Len}, B, TLI);
15161517
}
15171518

@@ -1525,11 +1526,11 @@ Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
15251526
AttributeList AS;
15261527
AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
15271528
Attribute::NoUnwind);
1528-
Type *I8Ptr = B.getInt8PtrTy();
1529+
Type *VoidPtrTy = B.getPtrTy();
15291530
Type *SizeTTy = getSizeTTy(B, TLI);
15301531
FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
1531-
AttributeList::get(M->getContext(), AS), I8Ptr,
1532-
I8Ptr, I8Ptr, SizeTTy, SizeTTy);
1532+
AttributeList::get(M->getContext(), AS), VoidPtrTy,
1533+
VoidPtrTy, VoidPtrTy, SizeTTy, SizeTTy);
15331534
CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize});
15341535
if (const Function *F =
15351536
dyn_cast<Function>(MemCpy.getCallee()->stripPointerCasts()))
@@ -1539,139 +1540,140 @@ Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
15391540

15401541
Value *llvm::emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
15411542
const DataLayout &DL, const TargetLibraryInfo *TLI) {
1542-
Type *I8Ptr = B.getInt8PtrTy();
1543+
Type *VoidPtrTy = B.getPtrTy();
15431544
Type *SizeTTy = getSizeTTy(B, TLI);
1544-
return emitLibCall(LibFunc_mempcpy, I8Ptr,
1545-
{I8Ptr, I8Ptr, SizeTTy},
1545+
return emitLibCall(LibFunc_mempcpy, VoidPtrTy,
1546+
{VoidPtrTy, VoidPtrTy, SizeTTy},
15461547
{Dst, Src, Len}, B, TLI);
15471548
}
15481549

15491550
Value *llvm::emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
15501551
const DataLayout &DL, const TargetLibraryInfo *TLI) {
1551-
Type *I8Ptr = B.getInt8PtrTy();
1552+
Type *VoidPtrTy = B.getPtrTy();
15521553
Type *IntTy = getIntTy(B, TLI);
15531554
Type *SizeTTy = getSizeTTy(B, TLI);
1554-
return emitLibCall(LibFunc_memchr, I8Ptr,
1555-
{I8Ptr, IntTy, SizeTTy},
1555+
return emitLibCall(LibFunc_memchr, VoidPtrTy,
1556+
{VoidPtrTy, IntTy, SizeTTy},
15561557
{Ptr, Val, Len}, B, TLI);
15571558
}
15581559

15591560
Value *llvm::emitMemRChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
15601561
const DataLayout &DL, const TargetLibraryInfo *TLI) {
1561-
Type *I8Ptr = B.getInt8PtrTy();
1562+
Type *VoidPtrTy = B.getPtrTy();
15621563
Type *IntTy = getIntTy(B, TLI);
15631564
Type *SizeTTy = getSizeTTy(B, TLI);
1564-
return emitLibCall(LibFunc_memrchr, I8Ptr,
1565-
{I8Ptr, IntTy, SizeTTy},
1565+
return emitLibCall(LibFunc_memrchr, VoidPtrTy,
1566+
{VoidPtrTy, IntTy, SizeTTy},
15661567
{Ptr, Val, Len}, B, TLI);
15671568
}
15681569

15691570
Value *llvm::emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
15701571
const DataLayout &DL, const TargetLibraryInfo *TLI) {
1571-
Type *I8Ptr = B.getInt8PtrTy();
1572+
Type *VoidPtrTy = B.getPtrTy();
15721573
Type *IntTy = getIntTy(B, TLI);
15731574
Type *SizeTTy = getSizeTTy(B, TLI);
15741575
return emitLibCall(LibFunc_memcmp, IntTy,
1575-
{I8Ptr, I8Ptr, SizeTTy},
1576+
{VoidPtrTy, VoidPtrTy, SizeTTy},
15761577
{Ptr1, Ptr2, Len}, B, TLI);
15771578
}
15781579

15791580
Value *llvm::emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
15801581
const DataLayout &DL, const TargetLibraryInfo *TLI) {
1581-
Type *I8Ptr = B.getInt8PtrTy();
1582+
Type *VoidPtrTy = B.getPtrTy();
15821583
Type *IntTy = getIntTy(B, TLI);
15831584
Type *SizeTTy = getSizeTTy(B, TLI);
15841585
return emitLibCall(LibFunc_bcmp, IntTy,
1585-
{I8Ptr, I8Ptr, SizeTTy},
1586+
{VoidPtrTy, VoidPtrTy, SizeTTy},
15861587
{Ptr1, Ptr2, Len}, B, TLI);
15871588
}
15881589

15891590
Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
15901591
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1591-
Type *I8Ptr = B.getInt8PtrTy();
1592+
Type *VoidPtrTy = B.getPtrTy();
15921593
Type *IntTy = getIntTy(B, TLI);
15931594
Type *SizeTTy = getSizeTTy(B, TLI);
1594-
return emitLibCall(LibFunc_memccpy, I8Ptr,
1595-
{I8Ptr, I8Ptr, IntTy, SizeTTy},
1595+
return emitLibCall(LibFunc_memccpy, VoidPtrTy,
1596+
{VoidPtrTy, VoidPtrTy, IntTy, SizeTTy},
15961597
{Ptr1, Ptr2, Val, Len}, B, TLI);
15971598
}
15981599

15991600
Value *llvm::emitSNPrintf(Value *Dest, Value *Size, Value *Fmt,
16001601
ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
16011602
const TargetLibraryInfo *TLI) {
1602-
Type *I8Ptr = B.getInt8PtrTy();
1603+
Type *CharPtrTy = B.getPtrTy();
16031604
Type *IntTy = getIntTy(B, TLI);
16041605
Type *SizeTTy = getSizeTTy(B, TLI);
16051606
SmallVector<Value *, 8> Args{Dest, Size, Fmt};
16061607
llvm::append_range(Args, VariadicArgs);
16071608
return emitLibCall(LibFunc_snprintf, IntTy,
1608-
{I8Ptr, SizeTTy, I8Ptr},
1609+
{CharPtrTy, SizeTTy, CharPtrTy},
16091610
Args, B, TLI, /*IsVaArgs=*/true);
16101611
}
16111612

16121613
Value *llvm::emitSPrintf(Value *Dest, Value *Fmt,
16131614
ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
16141615
const TargetLibraryInfo *TLI) {
1615-
Type *I8Ptr = B.getInt8PtrTy();
1616+
Type *CharPtrTy = B.getPtrTy();
16161617
Type *IntTy = getIntTy(B, TLI);
16171618
SmallVector<Value *, 8> Args{Dest, Fmt};
16181619
llvm::append_range(Args, VariadicArgs);
16191620
return emitLibCall(LibFunc_sprintf, IntTy,
1620-
{I8Ptr, I8Ptr}, Args, B, TLI,
1621+
{CharPtrTy, CharPtrTy}, Args, B, TLI,
16211622
/*IsVaArgs=*/true);
16221623
}
16231624

16241625
Value *llvm::emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B,
16251626
const TargetLibraryInfo *TLI) {
1626-
return emitLibCall(LibFunc_strcat, B.getInt8PtrTy(),
1627-
{B.getInt8PtrTy(), B.getInt8PtrTy()},
1627+
Type *CharPtrTy = B.getPtrTy();
1628+
return emitLibCall(LibFunc_strcat, CharPtrTy,
1629+
{CharPtrTy, CharPtrTy},
16281630
{Dest, Src}, B, TLI);
16291631
}
16301632

16311633
Value *llvm::emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
16321634
const TargetLibraryInfo *TLI) {
1633-
Type *I8Ptr = B.getInt8PtrTy();
1635+
Type *CharPtrTy = B.getPtrTy();
16341636
Type *SizeTTy = getSizeTTy(B, TLI);
16351637
return emitLibCall(LibFunc_strlcpy, SizeTTy,
1636-
{I8Ptr, I8Ptr, SizeTTy},
1638+
{CharPtrTy, CharPtrTy, SizeTTy},
16371639
{Dest, Src, Size}, B, TLI);
16381640
}
16391641

16401642
Value *llvm::emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
16411643
const TargetLibraryInfo *TLI) {
1642-
Type *I8Ptr = B.getInt8PtrTy();
1644+
Type *CharPtrTy = B.getPtrTy();
16431645
Type *SizeTTy = getSizeTTy(B, TLI);
16441646
return emitLibCall(LibFunc_strlcat, SizeTTy,
1645-
{I8Ptr, I8Ptr, SizeTTy},
1647+
{CharPtrTy, CharPtrTy, SizeTTy},
16461648
{Dest, Src, Size}, B, TLI);
16471649
}
16481650

16491651
Value *llvm::emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
16501652
const TargetLibraryInfo *TLI) {
1651-
Type *I8Ptr = B.getInt8PtrTy();
1653+
Type *CharPtrTy = B.getPtrTy();
16521654
Type *SizeTTy = getSizeTTy(B, TLI);
1653-
return emitLibCall(LibFunc_strncat, I8Ptr,
1654-
{I8Ptr, I8Ptr, SizeTTy},
1655+
return emitLibCall(LibFunc_strncat, CharPtrTy,
1656+
{CharPtrTy, CharPtrTy, SizeTTy},
16551657
{Dest, Src, Size}, B, TLI);
16561658
}
16571659

16581660
Value *llvm::emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList,
16591661
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1660-
Type *I8Ptr = B.getInt8PtrTy();
1662+
Type *CharPtrTy = B.getPtrTy();
16611663
Type *IntTy = getIntTy(B, TLI);
16621664
Type *SizeTTy = getSizeTTy(B, TLI);
16631665
return emitLibCall(
16641666
LibFunc_vsnprintf, IntTy,
1665-
{I8Ptr, SizeTTy, I8Ptr, VAList->getType()},
1667+
{CharPtrTy, SizeTTy, CharPtrTy, VAList->getType()},
16661668
{Dest, Size, Fmt, VAList}, B, TLI);
16671669
}
16681670

16691671
Value *llvm::emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList,
16701672
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1671-
Type *I8Ptr = B.getInt8PtrTy();
1673+
Type *CharPtrTy = B.getPtrTy();
16721674
Type *IntTy = getIntTy(B, TLI);
16731675
return emitLibCall(LibFunc_vsprintf, IntTy,
1674-
{I8Ptr, I8Ptr, VAList->getType()},
1676+
{CharPtrTy, CharPtrTy, VAList->getType()},
16751677
{Dest, Fmt, VAList}, B, TLI);
16761678
}
16771679

@@ -1822,7 +1824,7 @@ Value *llvm::emitPutS(Value *Str, IRBuilderBase &B,
18221824
Type *IntTy = getIntTy(B, TLI);
18231825
StringRef PutsName = TLI->getName(LibFunc_puts);
18241826
FunctionCallee PutS = getOrInsertLibFunc(M, *TLI, LibFunc_puts, IntTy,
1825-
B.getInt8PtrTy());
1827+
B.getPtrTy());
18261828
inferNonMandatoryLibFuncAttrs(M, PutsName, *TLI);
18271829
CallInst *CI = B.CreateCall(PutS, Str, PutsName);
18281830
if (const Function *F =
@@ -1860,7 +1862,7 @@ Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilderBase &B,
18601862
Type *IntTy = getIntTy(B, TLI);
18611863
StringRef FPutsName = TLI->getName(LibFunc_fputs);
18621864
FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputs, IntTy,
1863-
B.getInt8PtrTy(), File->getType());
1865+
B.getPtrTy(), File->getType());
18641866
if (File->getType()->isPointerTy())
18651867
inferNonMandatoryLibFuncAttrs(M, FPutsName, *TLI);
18661868
CallInst *CI = B.CreateCall(F, {Str, File}, FPutsName);
@@ -1880,7 +1882,7 @@ Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B,
18801882
Type *SizeTTy = getSizeTTy(B, TLI);
18811883
StringRef FWriteName = TLI->getName(LibFunc_fwrite);
18821884
FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fwrite,
1883-
SizeTTy, B.getInt8PtrTy(), SizeTTy,
1885+
SizeTTy, B.getPtrTy(), SizeTTy,
18841886
SizeTTy, File->getType());
18851887

18861888
if (File->getType()->isPointerTy())
@@ -1904,7 +1906,7 @@ Value *llvm::emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL,
19041906
StringRef MallocName = TLI->getName(LibFunc_malloc);
19051907
Type *SizeTTy = getSizeTTy(B, TLI);
19061908
FunctionCallee Malloc = getOrInsertLibFunc(M, *TLI, LibFunc_malloc,
1907-
B.getInt8PtrTy(), SizeTTy);
1909+
B.getPtrTy(), SizeTTy);
19081910
inferNonMandatoryLibFuncAttrs(M, MallocName, *TLI);
19091911
CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
19101912

@@ -1924,7 +1926,7 @@ Value *llvm::emitCalloc(Value *Num, Value *Size, IRBuilderBase &B,
19241926
StringRef CallocName = TLI.getName(LibFunc_calloc);
19251927
Type *SizeTTy = getSizeTTy(B, &TLI);
19261928
FunctionCallee Calloc = getOrInsertLibFunc(M, TLI, LibFunc_calloc,
1927-
B.getInt8PtrTy(), SizeTTy, SizeTTy);
1929+
B.getPtrTy(), SizeTTy, SizeTTy);
19281930
inferNonMandatoryLibFuncAttrs(M, CallocName, TLI);
19291931
CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
19301932

@@ -1943,7 +1945,7 @@ Value *llvm::emitHotColdNew(Value *Num, IRBuilderBase &B,
19431945
return nullptr;
19441946

19451947
StringRef Name = TLI->getName(NewFunc);
1946-
FunctionCallee Func = M->getOrInsertFunction(Name, B.getInt8PtrTy(),
1948+
FunctionCallee Func = M->getOrInsertFunction(Name, B.getPtrTy(),
19471949
Num->getType(), B.getInt8Ty());
19481950
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
19491951
CallInst *CI = B.CreateCall(Func, {Num, B.getInt8(HotCold)}, Name);
@@ -1964,7 +1966,7 @@ Value *llvm::emitHotColdNewNoThrow(Value *Num, Value *NoThrow, IRBuilderBase &B,
19641966

19651967
StringRef Name = TLI->getName(NewFunc);
19661968
FunctionCallee Func =
1967-
M->getOrInsertFunction(Name, B.getInt8PtrTy(), Num->getType(),
1969+
M->getOrInsertFunction(Name, B.getPtrTy(), Num->getType(),
19681970
NoThrow->getType(), B.getInt8Ty());
19691971
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
19701972
CallInst *CI = B.CreateCall(Func, {Num, NoThrow, B.getInt8(HotCold)}, Name);
@@ -1985,7 +1987,7 @@ Value *llvm::emitHotColdNewAligned(Value *Num, Value *Align, IRBuilderBase &B,
19851987

19861988
StringRef Name = TLI->getName(NewFunc);
19871989
FunctionCallee Func = M->getOrInsertFunction(
1988-
Name, B.getInt8PtrTy(), Num->getType(), Align->getType(), B.getInt8Ty());
1990+
Name, B.getPtrTy(), Num->getType(), Align->getType(), B.getInt8Ty());
19891991
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
19901992
CallInst *CI = B.CreateCall(Func, {Num, Align, B.getInt8(HotCold)}, Name);
19911993

@@ -2006,7 +2008,7 @@ Value *llvm::emitHotColdNewAlignedNoThrow(Value *Num, Value *Align,
20062008

20072009
StringRef Name = TLI->getName(NewFunc);
20082010
FunctionCallee Func = M->getOrInsertFunction(
2009-
Name, B.getInt8PtrTy(), Num->getType(), Align->getType(),
2011+
Name, B.getPtrTy(), Num->getType(), Align->getType(),
20102012
NoThrow->getType(), B.getInt8Ty());
20112013
inferNonMandatoryLibFuncAttrs(M, Name, *TLI);
20122014
CallInst *CI =

0 commit comments

Comments
 (0)