[SimplifyLibCalls] Update from deprecated IRBuilder API for creating memory intrinsics (NFC)

Summary:
This change is part of step five in the series of changes to remove alignment argument from
memcpy/memmove/memset in favour of alignment attributes. In particular, this changes the
SimplifyLibCalls pass to cease using the old IRBuilder createMemCpy/createMemMove
single-alignment APIs in favour of the new API that allows setting source and destination
alignments independently.

Steps:
Step 1) Remove alignment parameter and create alignment parameter attributes for
memcpy/memmove/memset. ( rL322965, rC322964, rL322963 )
Step 2) Expand the IRBuilder API to allow creation of memcpy/memmove with differing
source and dest alignments. ( rL323597 )
Step 3) Update Clang to use the new IRBuilder API. ( rC323617 )
Step 4) Update Polly to use the new IRBuilder API. ( rL323618 )
Step 5) Update LLVM passes that create memcpy/memmove calls to use the new IRBuilder API,
and those that use use MemIntrinsicInst::[get|set]Alignment() to use [get|set]DestAlignment()
and [get|set]SourceAlignment() instead. ( rL323886, rL323891, r3L24148 )
Step 6) Remove the single-alignment IRBuilder API for memcpy/memmove, and the
MemIntrinsicInst::[get|set]Alignment() methods.

Reference
   http://lists.llvm.org/pipermail/llvm-dev/2015-August/089384.html
   http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151109/312083.html

llvm-svn: 324273
This commit is contained in:
Daniel Neilson 2018-02-05 21:23:22 +00:00
parent 7a7a81d9d1
commit 8acd8b036c
1 changed files with 23 additions and 25 deletions

View File

@ -141,9 +141,8 @@ Value *LibCallSimplifier::emitStrLenMemCpy(Value *Src, Value *Dst, uint64_t Len,
// We have enough information to now generate the memcpy call to do the // We have enough information to now generate the memcpy call to do the
// concatenation for us. Make a memcpy to copy the nul byte with align = 1. // concatenation for us. Make a memcpy to copy the nul byte with align = 1.
B.CreateMemCpy(CpyDst, Src, B.CreateMemCpy(CpyDst, 1, Src, 1,
ConstantInt::get(DL.getIntPtrType(Src->getContext()), Len + 1), ConstantInt::get(DL.getIntPtrType(Src->getContext()), Len + 1));
1);
return Dst; return Dst;
} }
@ -331,8 +330,8 @@ Value *LibCallSimplifier::optimizeStrCpy(CallInst *CI, IRBuilder<> &B) {
// We have enough information to now generate the memcpy call to do the // We have enough information to now generate the memcpy call to do the
// copy for us. Make a memcpy to copy the nul byte with align = 1. // copy for us. Make a memcpy to copy the nul byte with align = 1.
B.CreateMemCpy(Dst, Src, B.CreateMemCpy(Dst, 1, Src, 1,
ConstantInt::get(DL.getIntPtrType(CI->getContext()), Len), 1); ConstantInt::get(DL.getIntPtrType(CI->getContext()), Len));
return Dst; return Dst;
} }
@ -356,7 +355,7 @@ Value *LibCallSimplifier::optimizeStpCpy(CallInst *CI, IRBuilder<> &B) {
// We have enough information to now generate the memcpy call to do the // We have enough information to now generate the memcpy call to do the
// copy for us. Make a memcpy to copy the nul byte with align = 1. // copy for us. Make a memcpy to copy the nul byte with align = 1.
B.CreateMemCpy(Dst, Src, LenV, 1); B.CreateMemCpy(Dst, 1, Src, 1, LenV);
return DstEnd; return DstEnd;
} }
@ -373,7 +372,7 @@ Value *LibCallSimplifier::optimizeStrNCpy(CallInst *CI, IRBuilder<> &B) {
--SrcLen; --SrcLen;
if (SrcLen == 0) { if (SrcLen == 0) {
// strncpy(x, "", y) -> memset(x, '\0', y, 1) // strncpy(x, "", y) -> memset(align 1 x, '\0', y)
B.CreateMemSet(Dst, B.getInt8('\0'), LenOp, 1); B.CreateMemSet(Dst, B.getInt8('\0'), LenOp, 1);
return Dst; return Dst;
} }
@ -392,8 +391,8 @@ Value *LibCallSimplifier::optimizeStrNCpy(CallInst *CI, IRBuilder<> &B) {
return nullptr; return nullptr;
Type *PT = Callee->getFunctionType()->getParamType(0); Type *PT = Callee->getFunctionType()->getParamType(0);
// strncpy(x, s, c) -> memcpy(x, s, c, 1) [s and c are constant] // strncpy(x, s, c) -> memcpy(align 1 x, align 1 s, c) [s and c are constant]
B.CreateMemCpy(Dst, Src, ConstantInt::get(DL.getIntPtrType(PT), Len), 1); B.CreateMemCpy(Dst, 1, Src, 1, ConstantInt::get(DL.getIntPtrType(PT), Len));
return Dst; return Dst;
} }
@ -801,16 +800,16 @@ Value *LibCallSimplifier::optimizeMemCmp(CallInst *CI, IRBuilder<> &B) {
} }
Value *LibCallSimplifier::optimizeMemCpy(CallInst *CI, IRBuilder<> &B) { Value *LibCallSimplifier::optimizeMemCpy(CallInst *CI, IRBuilder<> &B) {
// memcpy(x, y, n) -> llvm.memcpy(x, y, n, 1) // memcpy(x, y, n) -> llvm.memcpy(align 1 x, align 1 y, n)
B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1), B.CreateMemCpy(CI->getArgOperand(0), 1, CI->getArgOperand(1), 1,
CI->getArgOperand(2), 1); CI->getArgOperand(2));
return CI->getArgOperand(0); return CI->getArgOperand(0);
} }
Value *LibCallSimplifier::optimizeMemMove(CallInst *CI, IRBuilder<> &B) { Value *LibCallSimplifier::optimizeMemMove(CallInst *CI, IRBuilder<> &B) {
// memmove(x, y, n) -> llvm.memmove(x, y, n, 1) // memmove(x, y, n) -> llvm.memmove(align 1 x, align 1 y, n)
B.CreateMemMove(CI->getArgOperand(0), CI->getArgOperand(1), B.CreateMemMove(CI->getArgOperand(0), 1, CI->getArgOperand(1), 1,
CI->getArgOperand(2), 1); CI->getArgOperand(2));
return CI->getArgOperand(0); return CI->getArgOperand(0);
} }
@ -886,7 +885,7 @@ Value *LibCallSimplifier::optimizeMemSet(CallInst *CI, IRBuilder<> &B) {
if (auto *Calloc = foldMallocMemset(CI, B, *TLI)) if (auto *Calloc = foldMallocMemset(CI, B, *TLI))
return Calloc; return Calloc;
// memset(p, v, n) -> llvm.memset(p, v, n, 1) // memset(p, v, n) -> llvm.memset(align 1 p, v, n)
Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false); Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false);
B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), 1); B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), 1);
return CI->getArgOperand(0); return CI->getArgOperand(0);
@ -1815,11 +1814,10 @@ Value *LibCallSimplifier::optimizeSPrintFString(CallInst *CI, IRBuilder<> &B) {
if (FormatStr[i] == '%') if (FormatStr[i] == '%')
return nullptr; // we found a format specifier, bail out. return nullptr; // we found a format specifier, bail out.
// sprintf(str, fmt) -> llvm.memcpy(str, fmt, strlen(fmt)+1, 1) // sprintf(str, fmt) -> llvm.memcpy(align 1 str, align 1 fmt, strlen(fmt)+1)
B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1), B.CreateMemCpy(CI->getArgOperand(0), 1, CI->getArgOperand(1), 1,
ConstantInt::get(DL.getIntPtrType(CI->getContext()), ConstantInt::get(DL.getIntPtrType(CI->getContext()),
FormatStr.size() + 1), FormatStr.size() + 1)); // Copy the null byte.
1); // Copy the null byte.
return ConstantInt::get(CI->getType(), FormatStr.size()); return ConstantInt::get(CI->getType(), FormatStr.size());
} }
@ -1853,7 +1851,7 @@ Value *LibCallSimplifier::optimizeSPrintFString(CallInst *CI, IRBuilder<> &B) {
return nullptr; return nullptr;
Value *IncLen = Value *IncLen =
B.CreateAdd(Len, ConstantInt::get(Len->getType(), 1), "leninc"); B.CreateAdd(Len, ConstantInt::get(Len->getType(), 1), "leninc");
B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(2), IncLen, 1); B.CreateMemCpy(CI->getArgOperand(0), 1, CI->getArgOperand(2), 1, IncLen);
// The sprintf result is the unincremented number of bytes in the string. // The sprintf result is the unincremented number of bytes in the string.
return B.CreateIntCast(Len, CI->getType(), false); return B.CreateIntCast(Len, CI->getType(), false);
@ -2378,8 +2376,8 @@ bool FortifiedLibCallSimplifier::isFortifiedCallFoldable(CallInst *CI,
Value *FortifiedLibCallSimplifier::optimizeMemCpyChk(CallInst *CI, Value *FortifiedLibCallSimplifier::optimizeMemCpyChk(CallInst *CI,
IRBuilder<> &B) { IRBuilder<> &B) {
if (isFortifiedCallFoldable(CI, 3, 2, false)) { if (isFortifiedCallFoldable(CI, 3, 2, false)) {
B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1), B.CreateMemCpy(CI->getArgOperand(0), 1, CI->getArgOperand(1), 1,
CI->getArgOperand(2), 1); CI->getArgOperand(2));
return CI->getArgOperand(0); return CI->getArgOperand(0);
} }
return nullptr; return nullptr;
@ -2388,8 +2386,8 @@ Value *FortifiedLibCallSimplifier::optimizeMemCpyChk(CallInst *CI,
Value *FortifiedLibCallSimplifier::optimizeMemMoveChk(CallInst *CI, Value *FortifiedLibCallSimplifier::optimizeMemMoveChk(CallInst *CI,
IRBuilder<> &B) { IRBuilder<> &B) {
if (isFortifiedCallFoldable(CI, 3, 2, false)) { if (isFortifiedCallFoldable(CI, 3, 2, false)) {
B.CreateMemMove(CI->getArgOperand(0), CI->getArgOperand(1), B.CreateMemMove(CI->getArgOperand(0), 1, CI->getArgOperand(1), 1,
CI->getArgOperand(2), 1); CI->getArgOperand(2));
return CI->getArgOperand(0); return CI->getArgOperand(0);
} }
return nullptr; return nullptr;