[clang] dbc5acf - [Alignment][NFC] Adding Align compatible methods to IntrinsicInst/IRBuilder
Guillaume Chatelet via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 12 07:36:35 PST 2019
Author: Guillaume Chatelet
Date: 2019-12-12T16:22:15+01:00
New Revision: dbc5acf8ce8ae7b9adfa61e8133b50f2b82e4cde
URL: https://github.com/llvm/llvm-project/commit/dbc5acf8ce8ae7b9adfa61e8133b50f2b82e4cde
DIFF: https://github.com/llvm/llvm-project/commit/dbc5acf8ce8ae7b9adfa61e8133b50f2b82e4cde.diff
LOG: [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
Added:
Modified:
clang/lib/CodeGen/CGBuilder.h
llvm/include/llvm/IR/IRBuilder.h
llvm/include/llvm/IR/IntrinsicInst.h
llvm/lib/IR/IRBuilder.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 746053f43e36..107c9275431c 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -107,7 +107,7 @@ class CGBuilderTy : public CGBuilderBaseTy {
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 @@ class CGBuilderTy : public CGBuilderBaseTy {
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
index b15940b371ef..fdc4f5bdbf0f 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -491,28 +491,32 @@ class IRBuilderBase {
/// 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 @@ class IRBuilderBase {
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 @@ class IRBuilderBase {
/// 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 @@ class IRBuilderBase {
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 @@ class IRBuilder : public IRBuilderBase, public Inserter {
/// 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 @@ class IRBuilder : public IRBuilderBase, public Inserter {
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
index 4a2a8bc9d0f7..bd05e06d5249 100644
--- a/llvm/include/llvm/IR/IntrinsicInst.h
+++ b/llvm/include/llvm/IR/IntrinsicInst.h
@@ -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) {
+ 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 @@ 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) {
+ 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
index c424e845f480..1be5e40220d2 100644
--- a/llvm/lib/IR/IRBuilder.cpp
+++ b/llvm/lib/IR/IRBuilder.cpp
@@ -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)
More information about the cfe-commits
mailing list