forked from OSchip/llvm-project
[Alignment][NFC] Adding Align compatible methods to IntrinsicInst/IRBuilder
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D71420
This commit is contained in:
parent
a3d3d17be3
commit
dbc5acf8ce
|
@ -107,7 +107,7 @@ public:
|
|||
llvm::StoreInst *CreateStore(llvm::Value *Val, Address Addr,
|
||||
bool IsVolatile = false) {
|
||||
return CreateAlignedStore(Val, Addr.getPointer(),
|
||||
Addr.getAlignment().getQuantity(), IsVolatile);
|
||||
Addr.getAlignment().getAsAlign(), IsVolatile);
|
||||
}
|
||||
|
||||
using CGBuilderBaseTy::CreateAlignedStore;
|
||||
|
@ -273,22 +273,22 @@ public:
|
|||
using CGBuilderBaseTy::CreateMemCpy;
|
||||
llvm::CallInst *CreateMemCpy(Address Dest, Address Src, llvm::Value *Size,
|
||||
bool IsVolatile = false) {
|
||||
return CreateMemCpy(Dest.getPointer(), Dest.getAlignment().getQuantity(),
|
||||
Src.getPointer(), Src.getAlignment().getQuantity(),
|
||||
Size,IsVolatile);
|
||||
return CreateMemCpy(Dest.getPointer(), Dest.getAlignment().getAsAlign(),
|
||||
Src.getPointer(), Src.getAlignment().getAsAlign(), Size,
|
||||
IsVolatile);
|
||||
}
|
||||
llvm::CallInst *CreateMemCpy(Address Dest, Address Src, uint64_t Size,
|
||||
bool IsVolatile = false) {
|
||||
return CreateMemCpy(Dest.getPointer(), Dest.getAlignment().getQuantity(),
|
||||
Src.getPointer(), Src.getAlignment().getQuantity(),
|
||||
Size, IsVolatile);
|
||||
return CreateMemCpy(Dest.getPointer(), Dest.getAlignment().getAsAlign(),
|
||||
Src.getPointer(), Src.getAlignment().getAsAlign(), Size,
|
||||
IsVolatile);
|
||||
}
|
||||
|
||||
using CGBuilderBaseTy::CreateMemMove;
|
||||
llvm::CallInst *CreateMemMove(Address Dest, Address Src, llvm::Value *Size,
|
||||
bool IsVolatile = false) {
|
||||
return CreateMemMove(Dest.getPointer(), Dest.getAlignment().getQuantity(),
|
||||
Src.getPointer(), Src.getAlignment().getQuantity(),
|
||||
return CreateMemMove(Dest.getPointer(), Dest.getAlignment().getAsAlign(),
|
||||
Src.getPointer(), Src.getAlignment().getAsAlign(),
|
||||
Size, IsVolatile);
|
||||
}
|
||||
|
||||
|
|
|
@ -491,28 +491,32 @@ public:
|
|||
/// If the pointers aren't i8*, they will be converted. If a TBAA tag is
|
||||
/// specified, it will be added to the instruction. Likewise with alias.scope
|
||||
/// and noalias tags.
|
||||
/// FIXME: Remove this function once transition to Align is over.
|
||||
/// Use the version that takes MaybeAlign instead of this one.
|
||||
CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
|
||||
unsigned SrcAlign, uint64_t Size,
|
||||
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
||||
MDNode *TBAAStructTag = nullptr,
|
||||
MDNode *ScopeTag = nullptr,
|
||||
MDNode *NoAliasTag = nullptr) {
|
||||
return CreateMemCpy(Dst, MaybeAlign(DstAlign), Src, MaybeAlign(SrcAlign),
|
||||
getInt64(Size), isVolatile, TBAATag, TBAAStructTag,
|
||||
ScopeTag, NoAliasTag);
|
||||
}
|
||||
|
||||
CallInst *CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src,
|
||||
MaybeAlign SrcAlign, uint64_t Size,
|
||||
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
||||
MDNode *TBAAStructTag = nullptr,
|
||||
MDNode *ScopeTag = nullptr,
|
||||
MDNode *NoAliasTag = nullptr) {
|
||||
return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
|
||||
isVolatile, TBAATag, TBAAStructTag, ScopeTag,
|
||||
NoAliasTag);
|
||||
}
|
||||
CallInst *CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src,
|
||||
MaybeAlign SrcAlign, uint64_t Size,
|
||||
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
||||
MDNode *TBAAStructTag = nullptr,
|
||||
MDNode *ScopeTag = nullptr,
|
||||
MDNode *NoAliasTag = nullptr) {
|
||||
return CreateMemCpy(Dst, DstAlign ? DstAlign->value() : 0, Src,
|
||||
SrcAlign ? SrcAlign->value() : 0, getInt64(Size),
|
||||
isVolatile, TBAATag, TBAAStructTag, ScopeTag,
|
||||
NoAliasTag);
|
||||
}
|
||||
|
||||
/// FIXME: Remove this function once transition to Align is over.
|
||||
/// Use the version that takes MaybeAlign instead of this one.
|
||||
CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
|
||||
unsigned SrcAlign, Value *Size,
|
||||
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
||||
|
@ -524,11 +528,7 @@ public:
|
|||
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
||||
MDNode *TBAAStructTag = nullptr,
|
||||
MDNode *ScopeTag = nullptr,
|
||||
MDNode *NoAliasTag = nullptr) {
|
||||
return CreateMemCpy(Dst, DstAlign ? DstAlign->value() : 0, Src,
|
||||
SrcAlign ? SrcAlign->value() : 0, Size, isVolatile,
|
||||
TBAATag, TBAAStructTag, ScopeTag, NoAliasTag);
|
||||
}
|
||||
MDNode *NoAliasTag = nullptr);
|
||||
|
||||
/// Create and insert an element unordered-atomic memcpy between the
|
||||
/// specified pointers.
|
||||
|
@ -560,6 +560,8 @@ public:
|
|||
/// If the pointers aren't i8*, they will be converted. If a TBAA tag is
|
||||
/// specified, it will be added to the instruction. Likewise with alias.scope
|
||||
/// and noalias tags.
|
||||
/// FIXME: Remove this function once transition to Align is over.
|
||||
/// Use the version that takes MaybeAlign instead of this one.
|
||||
CallInst *CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
|
||||
uint64_t Size, bool isVolatile = false,
|
||||
MDNode *TBAATag = nullptr, MDNode *ScopeTag = nullptr,
|
||||
|
@ -567,9 +569,27 @@ public:
|
|||
return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size), isVolatile,
|
||||
TBAATag, ScopeTag, NoAliasTag);
|
||||
}
|
||||
|
||||
CallInst *CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
|
||||
Value *Size, bool isVolatile = false, MDNode *TBAATag = nullptr,
|
||||
CallInst *CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src,
|
||||
MaybeAlign SrcAlign, uint64_t Size,
|
||||
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
||||
MDNode *ScopeTag = nullptr,
|
||||
MDNode *NoAliasTag = nullptr) {
|
||||
return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
|
||||
isVolatile, TBAATag, ScopeTag, NoAliasTag);
|
||||
}
|
||||
/// FIXME: Remove this function once transition to Align is over.
|
||||
/// Use the version that takes MaybeAlign instead of this one.
|
||||
CallInst *CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src,
|
||||
unsigned SrcAlign, Value *Size,
|
||||
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
||||
MDNode *ScopeTag = nullptr,
|
||||
MDNode *NoAliasTag = nullptr) {
|
||||
return CreateMemMove(Dst, MaybeAlign(DstAlign), Src, MaybeAlign(SrcAlign),
|
||||
Size, isVolatile, TBAATag, ScopeTag, NoAliasTag);
|
||||
}
|
||||
CallInst *CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src,
|
||||
MaybeAlign SrcAlign, Value *Size,
|
||||
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
||||
MDNode *ScopeTag = nullptr,
|
||||
MDNode *NoAliasTag = nullptr);
|
||||
|
||||
|
@ -1636,33 +1656,42 @@ public:
|
|||
/// Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")'
|
||||
/// correctly, instead of converting the string to 'bool' for the isVolatile
|
||||
/// parameter.
|
||||
/// FIXME: Remove this function once transition to Align is over.
|
||||
/// Use the version that takes MaybeAlign instead of this one.
|
||||
LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align,
|
||||
const char *Name) {
|
||||
return CreateAlignedLoad(Ty, Ptr, MaybeAlign(Align), Name);
|
||||
}
|
||||
LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align,
|
||||
const char *Name) {
|
||||
LoadInst *LI = CreateLoad(Ty, Ptr, Name);
|
||||
LI->setAlignment(MaybeAlign(Align));
|
||||
LI->setAlignment(Align);
|
||||
return LI;
|
||||
}
|
||||
/// FIXME: Remove this function once transition to Align is over.
|
||||
/// Use the version that takes MaybeAlign instead of this one.
|
||||
LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align,
|
||||
const Twine &Name = "") {
|
||||
LoadInst *LI = CreateLoad(Ty, Ptr, Name);
|
||||
LI->setAlignment(MaybeAlign(Align));
|
||||
return LI;
|
||||
return CreateAlignedLoad(Ty, Ptr, MaybeAlign(Align), Name);
|
||||
}
|
||||
LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align,
|
||||
const Twine &Name = "") {
|
||||
return CreateAlignedLoad(Ty, Ptr, Align ? Align->value() : 0, Name);
|
||||
LoadInst *LI = CreateLoad(Ty, Ptr, Name);
|
||||
LI->setAlignment(Align);
|
||||
return LI;
|
||||
}
|
||||
/// FIXME: Remove this function once transition to Align is over.
|
||||
/// Use the version that takes MaybeAlign instead of this one.
|
||||
LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align,
|
||||
bool isVolatile, const Twine &Name = "") {
|
||||
return CreateAlignedLoad(Ty, Ptr, MaybeAlign(Align), isVolatile, Name);
|
||||
}
|
||||
LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align,
|
||||
bool isVolatile, const Twine &Name = "") {
|
||||
LoadInst *LI = CreateLoad(Ty, Ptr, isVolatile, Name);
|
||||
LI->setAlignment(MaybeAlign(Align));
|
||||
LI->setAlignment(Align);
|
||||
return LI;
|
||||
}
|
||||
LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align,
|
||||
bool isVolatile, const Twine &Name = "") {
|
||||
return CreateAlignedLoad(Ty, Ptr, Align ? Align->value() : 0, isVolatile,
|
||||
Name);
|
||||
}
|
||||
|
||||
// Deprecated [opaque pointer types]
|
||||
LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name) {
|
||||
|
@ -1681,6 +1710,23 @@ public:
|
|||
return CreateAlignedLoad(Ptr->getType()->getPointerElementType(), Ptr,
|
||||
Align, isVolatile, Name);
|
||||
}
|
||||
// Deprecated [opaque pointer types]
|
||||
LoadInst *CreateAlignedLoad(Value *Ptr, MaybeAlign Align, const char *Name) {
|
||||
return CreateAlignedLoad(Ptr->getType()->getPointerElementType(), Ptr,
|
||||
Align, Name);
|
||||
}
|
||||
// Deprecated [opaque pointer types]
|
||||
LoadInst *CreateAlignedLoad(Value *Ptr, MaybeAlign Align,
|
||||
const Twine &Name = "") {
|
||||
return CreateAlignedLoad(Ptr->getType()->getPointerElementType(), Ptr,
|
||||
Align, Name);
|
||||
}
|
||||
// Deprecated [opaque pointer types]
|
||||
LoadInst *CreateAlignedLoad(Value *Ptr, MaybeAlign Align, bool isVolatile,
|
||||
const Twine &Name = "") {
|
||||
return CreateAlignedLoad(Ptr->getType()->getPointerElementType(), Ptr,
|
||||
Align, isVolatile, Name);
|
||||
}
|
||||
|
||||
StoreInst *CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align,
|
||||
bool isVolatile = false) {
|
||||
|
|
|
@ -357,14 +357,21 @@ namespace llvm {
|
|||
setArgOperand(ARG_DEST, Ptr);
|
||||
}
|
||||
|
||||
/// FIXME: Remove this function once transition to Align is over.
|
||||
/// Use the version that takes MaybeAlign instead of this one.
|
||||
void setDestAlignment(unsigned Alignment) {
|
||||
removeParamAttr(ARG_DEST, Attribute::Alignment);
|
||||
if (Alignment > 0)
|
||||
addParamAttr(ARG_DEST, Attribute::getWithAlignment(getContext(),
|
||||
Align(Alignment)));
|
||||
setDestAlignment(MaybeAlign(Alignment));
|
||||
}
|
||||
void setDestAlignment(MaybeAlign Align) {
|
||||
setDestAlignment(Align ? Align->value() : 0);
|
||||
void setDestAlignment(MaybeAlign Alignment) {
|
||||
removeParamAttr(ARG_DEST, Attribute::Alignment);
|
||||
if (Alignment)
|
||||
addParamAttr(ARG_DEST,
|
||||
Attribute::getWithAlignment(getContext(), *Alignment));
|
||||
}
|
||||
void setDestAlignment(Align Alignment) {
|
||||
removeParamAttr(ARG_DEST, Attribute::Alignment);
|
||||
addParamAttr(ARG_DEST,
|
||||
Attribute::getWithAlignment(getContext(), Alignment));
|
||||
}
|
||||
|
||||
void setLength(Value *L) {
|
||||
|
@ -409,15 +416,21 @@ namespace llvm {
|
|||
BaseCL::setArgOperand(ARG_SOURCE, Ptr);
|
||||
}
|
||||
|
||||
/// FIXME: Remove this function once transition to Align is over.
|
||||
/// Use the version that takes MaybeAlign instead of this one.
|
||||
void setSourceAlignment(unsigned Alignment) {
|
||||
BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
|
||||
if (Alignment > 0)
|
||||
BaseCL::addParamAttr(ARG_SOURCE,
|
||||
Attribute::getWithAlignment(BaseCL::getContext(),
|
||||
Align(Alignment)));
|
||||
setSourceAlignment(MaybeAlign(Alignment));
|
||||
}
|
||||
void setSourceAlignment(MaybeAlign Align) {
|
||||
setSourceAlignment(Align ? Align->value() : 0);
|
||||
void setSourceAlignment(MaybeAlign Alignment) {
|
||||
BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
|
||||
if (Alignment)
|
||||
BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
|
||||
BaseCL::getContext(), *Alignment));
|
||||
}
|
||||
void setSourceAlignment(Align Alignment) {
|
||||
BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment);
|
||||
BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment(
|
||||
BaseCL::getContext(), Alignment));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -154,12 +154,21 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemSet(
|
|||
return CI;
|
||||
}
|
||||
|
||||
CallInst *IRBuilderBase::
|
||||
CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
|
||||
Value *Size, bool isVolatile, MDNode *TBAATag,
|
||||
MDNode *TBAAStructTag, MDNode *ScopeTag, MDNode *NoAliasTag) {
|
||||
assert((DstAlign == 0 || isPowerOf2_32(DstAlign)) && "Must be 0 or a power of 2");
|
||||
assert((SrcAlign == 0 || isPowerOf2_32(SrcAlign)) && "Must be 0 or a power of 2");
|
||||
CallInst *IRBuilderBase::CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
|
||||
unsigned SrcAlign, Value *Size,
|
||||
bool isVolatile, MDNode *TBAATag,
|
||||
MDNode *TBAAStructTag, MDNode *ScopeTag,
|
||||
MDNode *NoAliasTag) {
|
||||
return CreateMemCpy(Dst, MaybeAlign(DstAlign), Src, MaybeAlign(SrcAlign),
|
||||
Size, isVolatile, TBAATag, TBAAStructTag, ScopeTag,
|
||||
NoAliasTag);
|
||||
}
|
||||
|
||||
CallInst *IRBuilderBase::CreateMemCpy(Value *Dst, MaybeAlign DstAlign,
|
||||
Value *Src, MaybeAlign SrcAlign,
|
||||
Value *Size, bool isVolatile,
|
||||
MDNode *TBAATag, MDNode *TBAAStructTag,
|
||||
MDNode *ScopeTag, MDNode *NoAliasTag) {
|
||||
Dst = getCastedInt8PtrValue(Dst);
|
||||
Src = getCastedInt8PtrValue(Src);
|
||||
|
||||
|
@ -171,10 +180,10 @@ CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
|
|||
CallInst *CI = createCallHelper(TheFn, Ops, this);
|
||||
|
||||
auto* MCI = cast<MemCpyInst>(CI);
|
||||
if (DstAlign > 0)
|
||||
MCI->setDestAlignment(DstAlign);
|
||||
if (SrcAlign > 0)
|
||||
MCI->setSourceAlignment(SrcAlign);
|
||||
if (DstAlign)
|
||||
MCI->setDestAlignment(*DstAlign);
|
||||
if (SrcAlign)
|
||||
MCI->setSourceAlignment(*SrcAlign);
|
||||
|
||||
// Set the TBAA info if present.
|
||||
if (TBAATag)
|
||||
|
@ -234,12 +243,11 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemCpy(
|
|||
return CI;
|
||||
}
|
||||
|
||||
CallInst *IRBuilderBase::
|
||||
CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
|
||||
Value *Size, bool isVolatile, MDNode *TBAATag, MDNode *ScopeTag,
|
||||
MDNode *NoAliasTag) {
|
||||
assert((DstAlign == 0 || isPowerOf2_32(DstAlign)) && "Must be 0 or a power of 2");
|
||||
assert((SrcAlign == 0 || isPowerOf2_32(SrcAlign)) && "Must be 0 or a power of 2");
|
||||
CallInst *IRBuilderBase::CreateMemMove(Value *Dst, MaybeAlign DstAlign,
|
||||
Value *Src, MaybeAlign SrcAlign,
|
||||
Value *Size, bool isVolatile,
|
||||
MDNode *TBAATag, MDNode *ScopeTag,
|
||||
MDNode *NoAliasTag) {
|
||||
Dst = getCastedInt8PtrValue(Dst);
|
||||
Src = getCastedInt8PtrValue(Src);
|
||||
|
||||
|
@ -251,10 +259,10 @@ CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
|
|||
CallInst *CI = createCallHelper(TheFn, Ops, this);
|
||||
|
||||
auto *MMI = cast<MemMoveInst>(CI);
|
||||
if (DstAlign > 0)
|
||||
MMI->setDestAlignment(DstAlign);
|
||||
if (SrcAlign > 0)
|
||||
MMI->setSourceAlignment(SrcAlign);
|
||||
if (DstAlign)
|
||||
MMI->setDestAlignment(*DstAlign);
|
||||
if (SrcAlign)
|
||||
MMI->setSourceAlignment(*SrcAlign);
|
||||
|
||||
// Set the TBAA info if present.
|
||||
if (TBAATag)
|
||||
|
|
Loading…
Reference in New Issue