Skip to content

Commit 551a4d6

Browse files
author
Daniel Neilson
committed
Add IRBuilder API to create memcpy/memmove calls with differing source and dest alignments
Summary: This change is step two in the series of changes to remove alignment argument from memcpy/memmove/memset in favour of alignment attributes. Steps: Step 1) Remove alignment parameter and create alignment parameter attributes for memcpy/memmove/memset. ( rL322965 ) Step 2) Expand the IRBuilder API to allow creation of memcpy/memmove with differing source and dest alignments. Step 3) Update Clang to use the new IRBuilder API. Step 4) Update Polly to use the new IRBuilder API. 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 getDestAlignment() and getSourceAlignment() instead. 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: 323597
1 parent c131a3e commit 551a4d6

File tree

3 files changed

+63
-21
lines changed

3 files changed

+63
-21
lines changed

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,20 +420,42 @@ class IRBuilderBase {
420420
/// If the pointers aren't i8*, they will be converted. If a TBAA tag is
421421
/// specified, it will be added to the instruction. Likewise with alias.scope
422422
/// and noalias tags.
423+
CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
424+
unsigned SrcAlign, uint64_t Size,
425+
bool isVolatile = false, MDNode *TBAATag = nullptr,
426+
MDNode *TBAAStructTag = nullptr,
427+
MDNode *ScopeTag = nullptr,
428+
MDNode *NoAliasTag = nullptr) {
429+
return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
430+
isVolatile, TBAATag, TBAAStructTag, ScopeTag,
431+
NoAliasTag);
432+
}
433+
434+
CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
435+
unsigned SrcAlign, Value *Size,
436+
bool isVolatile = false, MDNode *TBAATag = nullptr,
437+
MDNode *TBAAStructTag = nullptr,
438+
MDNode *ScopeTag = nullptr,
439+
MDNode *NoAliasTag = nullptr);
440+
441+
// TODO: Old API. Remove this when no longer used.
423442
CallInst *CreateMemCpy(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
424443
bool isVolatile = false, MDNode *TBAATag = nullptr,
425444
MDNode *TBAAStructTag = nullptr,
426445
MDNode *ScopeTag = nullptr,
427446
MDNode *NoAliasTag = nullptr) {
428-
return CreateMemCpy(Dst, Src, getInt64(Size), Align, isVolatile, TBAATag,
447+
return CreateMemCpy(Dst, Align, Src, Align, getInt64(Size), isVolatile, TBAATag,
429448
TBAAStructTag, ScopeTag, NoAliasTag);
430449
}
431-
450+
// TODO: Old API. Remove this when no longer used.
432451
CallInst *CreateMemCpy(Value *Dst, Value *Src, Value *Size, unsigned Align,
433452
bool isVolatile = false, MDNode *TBAATag = nullptr,
434453
MDNode *TBAAStructTag = nullptr,
435454
MDNode *ScopeTag = nullptr,
436-
MDNode *NoAliasTag = nullptr);
455+
MDNode *NoAliasTag = nullptr) {
456+
return CreateMemCpy(Dst, Align, Src, Align, Size, isVolatile, TBAATag,
457+
TBAAStructTag, ScopeTag, NoAliasTag);
458+
}
437459

438460
/// \brief Create and insert an element unordered-atomic memcpy between the
439461
/// specified pointers.
@@ -465,18 +487,35 @@ class IRBuilderBase {
465487
/// If the pointers aren't i8*, they will be converted. If a TBAA tag is
466488
/// specified, it will be added to the instruction. Likewise with alias.scope
467489
/// and noalias tags.
490+
CallInst *CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
491+
uint64_t Size, bool isVolatile = false,
492+
MDNode *TBAATag = nullptr, MDNode *ScopeTag = nullptr,
493+
MDNode *NoAliasTag = nullptr) {
494+
return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size), isVolatile,
495+
TBAATag, ScopeTag, NoAliasTag);
496+
}
497+
498+
CallInst *CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
499+
Value *Size, bool isVolatile = false, MDNode *TBAATag = nullptr,
500+
MDNode *ScopeTag = nullptr,
501+
MDNode *NoAliasTag = nullptr);
502+
503+
// TODO: Old API. Remove this when no longer used.
468504
CallInst *CreateMemMove(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
469505
bool isVolatile = false, MDNode *TBAATag = nullptr,
470506
MDNode *ScopeTag = nullptr,
471507
MDNode *NoAliasTag = nullptr) {
472-
return CreateMemMove(Dst, Src, getInt64(Size), Align, isVolatile,
508+
return CreateMemMove(Dst, Align, Src, Align, getInt64(Size), isVolatile,
473509
TBAATag, ScopeTag, NoAliasTag);
474510
}
475-
511+
// TODO: Old API. Remove this when no longer used.
476512
CallInst *CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align,
477513
bool isVolatile = false, MDNode *TBAATag = nullptr,
478514
MDNode *ScopeTag = nullptr,
479-
MDNode *NoAliasTag = nullptr);
515+
MDNode *NoAliasTag = nullptr) {
516+
return CreateMemMove(Dst, Align, Src, Align, Size, isVolatile, TBAATag,
517+
ScopeTag, NoAliasTag);
518+
}
480519

481520
/// \brief Create a vector fadd reduction intrinsic of the source vector.
482521
/// The first parameter is a scalar accumulator value for ordered reductions.

llvm/lib/IR/IRBuilder.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
108108
}
109109

110110
CallInst *IRBuilderBase::
111-
CreateMemCpy(Value *Dst, Value *Src, Value *Size, unsigned Align,
112-
bool isVolatile, MDNode *TBAATag, MDNode *TBAAStructTag,
113-
MDNode *ScopeTag, MDNode *NoAliasTag) {
114-
assert((Align == 0 || isPowerOf2_32(Align)) && "Must be 0 or a power of 2");
111+
CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
112+
Value *Size, bool isVolatile, MDNode *TBAATag,
113+
MDNode *TBAAStructTag, MDNode *ScopeTag, MDNode *NoAliasTag) {
114+
assert((DstAlign == 0 || isPowerOf2_32(DstAlign)) && "Must be 0 or a power of 2");
115+
assert((SrcAlign == 0 || isPowerOf2_32(SrcAlign)) && "Must be 0 or a power of 2");
115116
Dst = getCastedInt8PtrValue(Dst);
116117
Src = getCastedInt8PtrValue(Src);
117118

@@ -122,8 +123,11 @@ CreateMemCpy(Value *Dst, Value *Src, Value *Size, unsigned Align,
122123

123124
CallInst *CI = createCallHelper(TheFn, Ops, this);
124125

125-
if (Align > 0)
126-
cast<MemCpyInst>(CI)->setAlignment(Align);
126+
auto* MCI = cast<MemCpyInst>(CI);
127+
if (DstAlign > 0)
128+
MCI->setDestAlignment(DstAlign);
129+
if (SrcAlign > 0)
130+
MCI->setSourceAlignment(SrcAlign);
127131

128132
// Set the TBAA info if present.
129133
if (TBAATag)
@@ -184,10 +188,11 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemCpy(
184188
}
185189

186190
CallInst *IRBuilderBase::
187-
CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align,
188-
bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag,
191+
CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
192+
Value *Size, bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag,
189193
MDNode *NoAliasTag) {
190-
assert((Align == 0 || isPowerOf2_32(Align)) && "Must be 0 or a power of 2");
194+
assert((DstAlign == 0 || isPowerOf2_32(DstAlign)) && "Must be 0 or a power of 2");
195+
assert((SrcAlign == 0 || isPowerOf2_32(SrcAlign)) && "Must be 0 or a power of 2");
191196
Dst = getCastedInt8PtrValue(Dst);
192197
Src = getCastedInt8PtrValue(Src);
193198

@@ -199,8 +204,10 @@ CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align,
199204
CallInst *CI = createCallHelper(TheFn, Ops, this);
200205

201206
auto *MMI = cast<MemMoveInst>(CI);
202-
if (Align > 0)
203-
MMI->setAlignment(Align);
207+
if (DstAlign > 0)
208+
MMI->setDestAlignment(DstAlign);
209+
if (SrcAlign > 0)
210+
MMI->setSourceAlignment(SrcAlign);
204211

205212
// Set the TBAA info if present.
206213
if (TBAATag)

llvm/lib/IR/Verifier.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4064,10 +4064,6 @@ void Verifier::visitIntrinsicCallSite(Intrinsic::ID ID, CallSite CS) {
40644064
Assert(IsValidAlignment(MTI->getSourceAlignment()),
40654065
"alignment of arg 1 of memory intrinsic must be 0 or a power of 2",
40664066
CS);
4067-
// TODO: Remove this assert when we enhance IRBuilder API to create
4068-
// memcpy/memmove with separate source & dest alignments.
4069-
Assert(MTI->getSourceAlignment() == MTI->getDestAlignment(),
4070-
"TEMPORARY: source and dest alignments must be the same");
40714067
}
40724068
Assert(isa<ConstantInt>(CS.getArgOperand(3)),
40734069
"isvolatile argument of memory intrinsics must be a constant int",

0 commit comments

Comments
 (0)