Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 39 additions & 65 deletions llvm/include/llvm/IR/IRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,38 +613,30 @@ class IRBuilderBase {
/// and noalias tags.
CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size,
MaybeAlign Align, bool isVolatile = false,
MDNode *TBAATag = nullptr, MDNode *ScopeTag = nullptr,
MDNode *NoAliasTag = nullptr) {
return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile,
TBAATag, ScopeTag, NoAliasTag);
const AAMDNodes &AAInfo = AAMDNodes()) {
return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile, AAInfo);
}

CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, MaybeAlign Align,
bool isVolatile = false, MDNode *TBAATag = nullptr,
MDNode *ScopeTag = nullptr,
MDNode *NoAliasTag = nullptr);
bool isVolatile = false,
const AAMDNodes &AAInfo = AAMDNodes());

CallInst *CreateMemSetInline(Value *Dst, MaybeAlign DstAlign, Value *Val,
Value *Size, bool IsVolatile = false,
MDNode *TBAATag = nullptr,
MDNode *ScopeTag = nullptr,
MDNode *NoAliasTag = nullptr);
const AAMDNodes &AAInfo = AAMDNodes());

/// Create and insert an element unordered-atomic memset of the region of
/// memory starting at the given pointer to the given value.
///
/// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
/// specified, it will be added to the instruction. Likewise with alias.scope
/// and noalias tags.
CallInst *CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val,
uint64_t Size, Align Alignment,
uint32_t ElementSize,
MDNode *TBAATag = nullptr,
MDNode *ScopeTag = nullptr,
MDNode *NoAliasTag = nullptr) {
return CreateElementUnorderedAtomicMemSet(Ptr, Val, getInt64(Size),
Align(Alignment), ElementSize,
TBAATag, ScopeTag, NoAliasTag);
CallInst *
CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, uint64_t Size,
Align Alignment, uint32_t ElementSize,
const AAMDNodes &AAInfo = AAMDNodes()) {
return CreateElementUnorderedAtomicMemSet(
Ptr, Val, getInt64(Size), Align(Alignment), ElementSize, AAInfo);
}

CallInst *CreateMalloc(Type *IntPtrTy, Type *AllocTy, Value *AllocSize,
Expand All @@ -662,12 +654,10 @@ class IRBuilderBase {
/// Generate the IR for a call to the builtin free function.
CallInst *CreateFree(Value *Source, ArrayRef<OperandBundleDef> Bundles = {});

CallInst *CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val,
Value *Size, Align Alignment,
uint32_t ElementSize,
MDNode *TBAATag = nullptr,
MDNode *ScopeTag = nullptr,
MDNode *NoAliasTag = nullptr);
CallInst *
CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, Value *Size,
Align Alignment, uint32_t ElementSize,
const AAMDNodes &AAInfo = AAMDNodes());

/// Create and insert a memcpy between the specified pointers.
///
Expand All @@ -676,40 +666,32 @@ class IRBuilderBase {
/// and noalias tags.
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) {
bool isVolatile = false,
const AAMDNodes &AAInfo = AAMDNodes()) {
return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
isVolatile, TBAATag, TBAAStructTag, ScopeTag,
NoAliasTag);
isVolatile, AAInfo);
}

CallInst *CreateMemTransferInst(
Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src,
MaybeAlign SrcAlign, Value *Size, bool isVolatile = false,
MDNode *TBAATag = nullptr, MDNode *TBAAStructTag = nullptr,
MDNode *ScopeTag = nullptr, MDNode *NoAliasTag = nullptr);
CallInst *CreateMemTransferInst(Intrinsic::ID IntrID, Value *Dst,
MaybeAlign DstAlign, Value *Src,
MaybeAlign SrcAlign, Value *Size,
bool isVolatile = false,
const AAMDNodes &AAInfo = AAMDNodes());

CallInst *CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src,
MaybeAlign SrcAlign, Value *Size,
bool isVolatile = false, MDNode *TBAATag = nullptr,
MDNode *TBAAStructTag = nullptr,
MDNode *ScopeTag = nullptr,
MDNode *NoAliasTag = nullptr) {
bool isVolatile = false,
const AAMDNodes &AAInfo = AAMDNodes()) {
return CreateMemTransferInst(Intrinsic::memcpy, Dst, DstAlign, Src,
SrcAlign, Size, isVolatile, TBAATag,
TBAAStructTag, ScopeTag, NoAliasTag);
SrcAlign, Size, isVolatile, AAInfo);
}

CallInst *
CreateMemCpyInline(Value *Dst, MaybeAlign DstAlign, Value *Src,
MaybeAlign SrcAlign, Value *Size, bool isVolatile = false,
MDNode *TBAATag = nullptr, MDNode *TBAAStructTag = nullptr,
MDNode *ScopeTag = nullptr, MDNode *NoAliasTag = nullptr) {
CallInst *CreateMemCpyInline(Value *Dst, MaybeAlign DstAlign, Value *Src,
MaybeAlign SrcAlign, Value *Size,
bool isVolatile = false,
const AAMDNodes &AAInfo = AAMDNodes()) {
return CreateMemTransferInst(Intrinsic::memcpy_inline, Dst, DstAlign, Src,
SrcAlign, Size, isVolatile, TBAATag,
TBAAStructTag, ScopeTag, NoAliasTag);
SrcAlign, Size, isVolatile, AAInfo);
}

/// Create and insert an element unordered-atomic memcpy between the
Expand All @@ -722,28 +704,22 @@ class IRBuilderBase {
/// and noalias tags.
CallInst *CreateElementUnorderedAtomicMemCpy(
Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
uint32_t ElementSize, MDNode *TBAATag = nullptr,
MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
MDNode *NoAliasTag = nullptr);
uint32_t ElementSize, const AAMDNodes &AAInfo = AAMDNodes());

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) {
bool isVolatile = false,
const AAMDNodes &AAInfo = AAMDNodes()) {
return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
isVolatile, TBAATag, ScopeTag, NoAliasTag);
isVolatile, AAInfo);
}

CallInst *CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src,
MaybeAlign SrcAlign, Value *Size,
bool isVolatile = false, MDNode *TBAATag = nullptr,
MDNode *ScopeTag = nullptr,
MDNode *NoAliasTag = nullptr) {
bool isVolatile = false,
const AAMDNodes &AAInfo = AAMDNodes()) {
return CreateMemTransferInst(Intrinsic::memmove, Dst, DstAlign, Src,
SrcAlign, Size, isVolatile, TBAATag,
/*TBAAStructTag=*/nullptr, ScopeTag,
NoAliasTag);
SrcAlign, Size, isVolatile, AAInfo);
}

/// \brief Create and insert an element unordered-atomic memmove between the
Expand All @@ -757,9 +733,7 @@ class IRBuilderBase {
/// and noalias tags.
CallInst *CreateElementUnorderedAtomicMemMove(
Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
uint32_t ElementSize, MDNode *TBAATag = nullptr,
MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
MDNode *NoAliasTag = nullptr);
uint32_t ElementSize, const AAMDNodes &AAInfo = AAMDNodes());

private:
CallInst *getReductionIntrinsic(Intrinsic::ID ID, Value *Src);
Expand Down
109 changes: 17 additions & 92 deletions llvm/lib/IR/IRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,58 +169,36 @@ Value *IRBuilderBase::CreateStepVector(Type *DstType, const Twine &Name) {

CallInst *IRBuilderBase::CreateMemSet(Value *Ptr, Value *Val, Value *Size,
MaybeAlign Align, bool isVolatile,
MDNode *TBAATag, MDNode *ScopeTag,
MDNode *NoAliasTag) {
const AAMDNodes &AAInfo) {
Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)};
Type *Tys[] = {Ptr->getType(), Size->getType()};

CallInst *CI = CreateIntrinsic(Intrinsic::memset, Tys, Ops);

if (Align)
cast<MemSetInst>(CI)->setDestAlignment(*Align);

// Set the TBAA info if present.
if (TBAATag)
CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);

if (ScopeTag)
CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);

if (NoAliasTag)
CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);

CI->setAAMetadata(AAInfo);
return CI;
}

CallInst *IRBuilderBase::CreateMemSetInline(Value *Dst, MaybeAlign DstAlign,
Value *Val, Value *Size,
bool IsVolatile, MDNode *TBAATag,
MDNode *ScopeTag,
MDNode *NoAliasTag) {
bool IsVolatile,
const AAMDNodes &AAInfo) {
Value *Ops[] = {Dst, Val, Size, getInt1(IsVolatile)};
Type *Tys[] = {Dst->getType(), Size->getType()};

CallInst *CI = CreateIntrinsic(Intrinsic::memset_inline, Tys, Ops);

if (DstAlign)
cast<MemSetInst>(CI)->setDestAlignment(*DstAlign);

// Set the TBAA info if present.
if (TBAATag)
CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);

if (ScopeTag)
CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);

if (NoAliasTag)
CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);

CI->setAAMetadata(AAInfo);
return CI;
}

CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemSet(
Value *Ptr, Value *Val, Value *Size, Align Alignment, uint32_t ElementSize,
MDNode *TBAATag, MDNode *ScopeTag, MDNode *NoAliasTag) {
const AAMDNodes &AAInfo) {

Value *Ops[] = {Ptr, Val, Size, getInt32(ElementSize)};
Type *Tys[] = {Ptr->getType(), Size->getType()};
Expand All @@ -229,24 +207,15 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemSet(
CreateIntrinsic(Intrinsic::memset_element_unordered_atomic, Tys, Ops);

cast<AnyMemSetInst>(CI)->setDestAlignment(Alignment);

// Set the TBAA info if present.
if (TBAATag)
CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);

if (ScopeTag)
CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);

if (NoAliasTag)
CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);

CI->setAAMetadata(AAInfo);
return CI;
}

CallInst *IRBuilderBase::CreateMemTransferInst(
Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src,
MaybeAlign SrcAlign, Value *Size, bool isVolatile, MDNode *TBAATag,
MDNode *TBAAStructTag, MDNode *ScopeTag, MDNode *NoAliasTag) {
CallInst *IRBuilderBase::CreateMemTransferInst(Intrinsic::ID IntrID, Value *Dst,
MaybeAlign DstAlign, Value *Src,
MaybeAlign SrcAlign, Value *Size,
bool isVolatile,
const AAMDNodes &AAInfo) {
assert((IntrID == Intrinsic::memcpy || IntrID == Intrinsic::memcpy_inline ||
IntrID == Intrinsic::memmove) &&
"Unexpected intrinsic ID");
Expand All @@ -260,28 +229,13 @@ CallInst *IRBuilderBase::CreateMemTransferInst(
MCI->setDestAlignment(*DstAlign);
if (SrcAlign)
MCI->setSourceAlignment(*SrcAlign);

// Set the TBAA info if present.
if (TBAATag)
CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);

// Set the TBAA Struct info if present.
if (TBAAStructTag)
CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);

if (ScopeTag)
CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);

if (NoAliasTag)
CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);

MCI->setAAMetadata(AAInfo);
return CI;
}

CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemCpy(
Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
uint32_t ElementSize, MDNode *TBAATag, MDNode *TBAAStructTag,
MDNode *ScopeTag, MDNode *NoAliasTag) {
uint32_t ElementSize, const AAMDNodes &AAInfo) {
assert(DstAlign >= ElementSize &&
"Pointer alignment must be at least element size");
assert(SrcAlign >= ElementSize &&
Expand All @@ -296,21 +250,7 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemCpy(
auto *AMCI = cast<AnyMemCpyInst>(CI);
AMCI->setDestAlignment(DstAlign);
AMCI->setSourceAlignment(SrcAlign);

// Set the TBAA info if present.
if (TBAATag)
CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);

// Set the TBAA Struct info if present.
if (TBAAStructTag)
CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);

if (ScopeTag)
CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);

if (NoAliasTag)
CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);

AMCI->setAAMetadata(AAInfo);
return CI;
}

Expand Down Expand Up @@ -394,8 +334,7 @@ CallInst *IRBuilderBase::CreateFree(Value *Source,

CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemMove(
Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
uint32_t ElementSize, MDNode *TBAATag, MDNode *TBAAStructTag,
MDNode *ScopeTag, MDNode *NoAliasTag) {
uint32_t ElementSize, const AAMDNodes &AAInfo) {
assert(DstAlign >= ElementSize &&
"Pointer alignment must be at least element size");
assert(SrcAlign >= ElementSize &&
Expand All @@ -409,21 +348,7 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemMove(
// Set the alignment of the pointer args.
CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), DstAlign));
CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), SrcAlign));

// Set the TBAA info if present.
if (TBAATag)
CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);

// Set the TBAA Struct info if present.
if (TBAAStructTag)
CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);

if (ScopeTag)
CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);

if (NoAliasTag)
CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);

CI->setAAMetadata(AAInfo);
return CI;
}

Expand Down
13 changes: 4 additions & 9 deletions llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,14 +1123,10 @@ static bool replaceIfSimplePointerUse(const TargetTransformInfo &TTI,
static bool handleMemIntrinsicPtrUse(MemIntrinsic *MI, Value *OldV,
Value *NewV) {
IRBuilder<> B(MI);
MDNode *TBAA = MI->getMetadata(LLVMContext::MD_tbaa);
MDNode *ScopeMD = MI->getMetadata(LLVMContext::MD_alias_scope);
MDNode *NoAliasMD = MI->getMetadata(LLVMContext::MD_noalias);

if (auto *MSI = dyn_cast<MemSetInst>(MI)) {
B.CreateMemSet(NewV, MSI->getValue(), MSI->getLength(), MSI->getDestAlign(),
false, // isVolatile
TBAA, ScopeMD, NoAliasMD);
MI->getAAMetadata());
} else if (auto *MTI = dyn_cast<MemTransferInst>(MI)) {
Value *Src = MTI->getRawSource();
Value *Dest = MTI->getRawDest();
Expand All @@ -1143,23 +1139,22 @@ static bool handleMemIntrinsicPtrUse(MemIntrinsic *MI, Value *OldV,
Dest = NewV;

if (auto *MCI = dyn_cast<MemCpyInst>(MTI)) {
MDNode *TBAAStruct = MTI->getMetadata(LLVMContext::MD_tbaa_struct);
if (MCI->isForceInlined())
B.CreateMemCpyInline(Dest, MTI->getDestAlign(), Src,
MTI->getSourceAlign(), MTI->getLength(),
false, // isVolatile
TBAA, TBAAStruct, ScopeMD, NoAliasMD);
MI->getAAMetadata());
else
B.CreateMemCpy(Dest, MTI->getDestAlign(), Src, MTI->getSourceAlign(),
MTI->getLength(),
false, // isVolatile
TBAA, TBAAStruct, ScopeMD, NoAliasMD);
MI->getAAMetadata());
} else {
assert(isa<MemMoveInst>(MTI));
B.CreateMemMove(Dest, MTI->getDestAlign(), Src, MTI->getSourceAlign(),
MTI->getLength(),
false, // isVolatile
TBAA, ScopeMD, NoAliasMD);
MI->getAAMetadata());
}
} else
llvm_unreachable("unhandled MemIntrinsic");
Expand Down
Loading
Loading