diff --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h --- a/clang/lib/CodeGen/CGBuilder.h +++ b/clang/lib/CodeGen/CGBuilder.h @@ -107,7 +107,7 @@ 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 @@ 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); } diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -491,28 +491,32 @@ /// 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, DstAlign, Src, SrcAlign, getInt64(Size), - isVolatile, TBAATag, TBAAStructTag, ScopeTag, - NoAliasTag); + 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 ? DstAlign->value() : 0, Src, - SrcAlign ? SrcAlign->value() : 0, getInt64(Size), + return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, 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 @@ 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 @@ /// 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 @@ 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,32 +1656,41 @@ /// 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 = "") { - LoadInst *LI = CreateLoad(Ty, Ptr, isVolatile, Name); - LI->setAlignment(MaybeAlign(Align)); - return LI; + return CreateAlignedLoad(Ty, Ptr, MaybeAlign(Align), isVolatile, Name); } LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, bool isVolatile, const Twine &Name = "") { - return CreateAlignedLoad(Ty, Ptr, Align ? Align->value() : 0, isVolatile, - Name); + LoadInst *LI = CreateLoad(Ty, Ptr, isVolatile, Name); + LI->setAlignment(Align); + return LI; } // Deprecated [opaque pointer types] @@ -1681,6 +1710,23 @@ 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) { diff --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h --- a/llvm/include/llvm/IR/IntrinsicInst.h +++ b/llvm/include/llvm/IR/IntrinsicInst.h @@ -357,14 +357,21 @@ 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) { + setDestAlignment(MaybeAlign(Alignment)); + } + void setDestAlignment(MaybeAlign Alignment) { removeParamAttr(ARG_DEST, Attribute::Alignment); - if (Alignment > 0) - addParamAttr(ARG_DEST, Attribute::getWithAlignment(getContext(), - Align(Alignment))); + if (Alignment) + addParamAttr(ARG_DEST, + Attribute::getWithAlignment(getContext(), *Alignment)); } - void setDestAlignment(MaybeAlign Align) { - setDestAlignment(Align ? Align->value() : 0); + void setDestAlignment(Align Alignment) { + removeParamAttr(ARG_DEST, Attribute::Alignment); + addParamAttr(ARG_DEST, + Attribute::getWithAlignment(getContext(), Alignment)); } void setLength(Value *L) { @@ -409,15 +416,21 @@ 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) { + setSourceAlignment(MaybeAlign(Alignment)); + } + void setSourceAlignment(MaybeAlign Alignment) { BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment); - if (Alignment > 0) - BaseCL::addParamAttr(ARG_SOURCE, - Attribute::getWithAlignment(BaseCL::getContext(), - Align(Alignment))); + if (Alignment) + BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment( + BaseCL::getContext(), *Alignment)); } - void setSourceAlignment(MaybeAlign Align) { - setSourceAlignment(Align ? Align->value() : 0); + void setSourceAlignment(Align Alignment) { + BaseCL::removeParamAttr(ARG_SOURCE, Attribute::Alignment); + BaseCL::addParamAttr(ARG_SOURCE, Attribute::getWithAlignment( + BaseCL::getContext(), Alignment)); } }; diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp --- a/llvm/lib/IR/IRBuilder.cpp +++ b/llvm/lib/IR/IRBuilder.cpp @@ -154,12 +154,21 @@ 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 @@ CallInst *CI = createCallHelper(TheFn, Ops, this); auto* MCI = cast(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 @@ 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 @@ CallInst *CI = createCallHelper(TheFn, Ops, this); auto *MMI = cast(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)