Skip to content

Commit 6ebde2f

Browse files
committed
[IRBuilder] Use AAMDNodes helper class in CreateMem* routines [nfc-ish]
I'm not 100% sure this is NFC because we have the possibility we're propagating additional metadata we'd missed before. We don't see any test changes resulting from this though.
1 parent 8c43588 commit 6ebde2f

File tree

4 files changed

+65
-181
lines changed

4 files changed

+65
-181
lines changed

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 39 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -613,38 +613,30 @@ class IRBuilderBase {
613613
/// and noalias tags.
614614
CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size,
615615
MaybeAlign Align, bool isVolatile = false,
616-
MDNode *TBAATag = nullptr, MDNode *ScopeTag = nullptr,
617-
MDNode *NoAliasTag = nullptr) {
618-
return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile,
619-
TBAATag, ScopeTag, NoAliasTag);
616+
const AAMDNodes &AAInfo = AAMDNodes()) {
617+
return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile, AAInfo);
620618
}
621619

622620
CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, MaybeAlign Align,
623-
bool isVolatile = false, MDNode *TBAATag = nullptr,
624-
MDNode *ScopeTag = nullptr,
625-
MDNode *NoAliasTag = nullptr);
621+
bool isVolatile = false,
622+
const AAMDNodes &AAInfo = AAMDNodes());
626623

627624
CallInst *CreateMemSetInline(Value *Dst, MaybeAlign DstAlign, Value *Val,
628625
Value *Size, bool IsVolatile = false,
629-
MDNode *TBAATag = nullptr,
630-
MDNode *ScopeTag = nullptr,
631-
MDNode *NoAliasTag = nullptr);
626+
const AAMDNodes &AAInfo = AAMDNodes());
632627

633628
/// Create and insert an element unordered-atomic memset of the region of
634629
/// memory starting at the given pointer to the given value.
635630
///
636631
/// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
637632
/// specified, it will be added to the instruction. Likewise with alias.scope
638633
/// and noalias tags.
639-
CallInst *CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val,
640-
uint64_t Size, Align Alignment,
641-
uint32_t ElementSize,
642-
MDNode *TBAATag = nullptr,
643-
MDNode *ScopeTag = nullptr,
644-
MDNode *NoAliasTag = nullptr) {
645-
return CreateElementUnorderedAtomicMemSet(Ptr, Val, getInt64(Size),
646-
Align(Alignment), ElementSize,
647-
TBAATag, ScopeTag, NoAliasTag);
634+
CallInst *
635+
CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, uint64_t Size,
636+
Align Alignment, uint32_t ElementSize,
637+
const AAMDNodes &AAInfo = AAMDNodes()) {
638+
return CreateElementUnorderedAtomicMemSet(
639+
Ptr, Val, getInt64(Size), Align(Alignment), ElementSize, AAInfo);
648640
}
649641

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

665-
CallInst *CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val,
666-
Value *Size, Align Alignment,
667-
uint32_t ElementSize,
668-
MDNode *TBAATag = nullptr,
669-
MDNode *ScopeTag = nullptr,
670-
MDNode *NoAliasTag = nullptr);
657+
CallInst *
658+
CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, Value *Size,
659+
Align Alignment, uint32_t ElementSize,
660+
const AAMDNodes &AAInfo = AAMDNodes());
671661

672662
/// Create and insert a memcpy between the specified pointers.
673663
///
@@ -676,40 +666,32 @@ class IRBuilderBase {
676666
/// and noalias tags.
677667
CallInst *CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src,
678668
MaybeAlign SrcAlign, uint64_t Size,
679-
bool isVolatile = false, MDNode *TBAATag = nullptr,
680-
MDNode *TBAAStructTag = nullptr,
681-
MDNode *ScopeTag = nullptr,
682-
MDNode *NoAliasTag = nullptr) {
669+
bool isVolatile = false,
670+
const AAMDNodes &AAInfo = AAMDNodes()) {
683671
return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
684-
isVolatile, TBAATag, TBAAStructTag, ScopeTag,
685-
NoAliasTag);
672+
isVolatile, AAInfo);
686673
}
687674

688-
CallInst *CreateMemTransferInst(
689-
Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src,
690-
MaybeAlign SrcAlign, Value *Size, bool isVolatile = false,
691-
MDNode *TBAATag = nullptr, MDNode *TBAAStructTag = nullptr,
692-
MDNode *ScopeTag = nullptr, MDNode *NoAliasTag = nullptr);
675+
CallInst *CreateMemTransferInst(Intrinsic::ID IntrID, Value *Dst,
676+
MaybeAlign DstAlign, Value *Src,
677+
MaybeAlign SrcAlign, Value *Size,
678+
bool isVolatile = false,
679+
const AAMDNodes &AAInfo = AAMDNodes());
693680

694681
CallInst *CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src,
695682
MaybeAlign SrcAlign, Value *Size,
696-
bool isVolatile = false, MDNode *TBAATag = nullptr,
697-
MDNode *TBAAStructTag = nullptr,
698-
MDNode *ScopeTag = nullptr,
699-
MDNode *NoAliasTag = nullptr) {
683+
bool isVolatile = false,
684+
const AAMDNodes &AAInfo = AAMDNodes()) {
700685
return CreateMemTransferInst(Intrinsic::memcpy, Dst, DstAlign, Src,
701-
SrcAlign, Size, isVolatile, TBAATag,
702-
TBAAStructTag, ScopeTag, NoAliasTag);
686+
SrcAlign, Size, isVolatile, AAInfo);
703687
}
704688

705-
CallInst *
706-
CreateMemCpyInline(Value *Dst, MaybeAlign DstAlign, Value *Src,
707-
MaybeAlign SrcAlign, Value *Size, bool isVolatile = false,
708-
MDNode *TBAATag = nullptr, MDNode *TBAAStructTag = nullptr,
709-
MDNode *ScopeTag = nullptr, MDNode *NoAliasTag = nullptr) {
689+
CallInst *CreateMemCpyInline(Value *Dst, MaybeAlign DstAlign, Value *Src,
690+
MaybeAlign SrcAlign, Value *Size,
691+
bool isVolatile = false,
692+
const AAMDNodes &AAInfo = AAMDNodes()) {
710693
return CreateMemTransferInst(Intrinsic::memcpy_inline, Dst, DstAlign, Src,
711-
SrcAlign, Size, isVolatile, TBAATag,
712-
TBAAStructTag, ScopeTag, NoAliasTag);
694+
SrcAlign, Size, isVolatile, AAInfo);
713695
}
714696

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

729709
CallInst *CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src,
730710
MaybeAlign SrcAlign, uint64_t Size,
731-
bool isVolatile = false, MDNode *TBAATag = nullptr,
732-
MDNode *ScopeTag = nullptr,
733-
MDNode *NoAliasTag = nullptr) {
711+
bool isVolatile = false,
712+
const AAMDNodes &AAInfo = AAMDNodes()) {
734713
return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
735-
isVolatile, TBAATag, ScopeTag, NoAliasTag);
714+
isVolatile, AAInfo);
736715
}
737716

738717
CallInst *CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src,
739718
MaybeAlign SrcAlign, Value *Size,
740-
bool isVolatile = false, MDNode *TBAATag = nullptr,
741-
MDNode *ScopeTag = nullptr,
742-
MDNode *NoAliasTag = nullptr) {
719+
bool isVolatile = false,
720+
const AAMDNodes &AAInfo = AAMDNodes()) {
743721
return CreateMemTransferInst(Intrinsic::memmove, Dst, DstAlign, Src,
744-
SrcAlign, Size, isVolatile, TBAATag,
745-
/*TBAAStructTag=*/nullptr, ScopeTag,
746-
NoAliasTag);
722+
SrcAlign, Size, isVolatile, AAInfo);
747723
}
748724

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

764738
private:
765739
CallInst *getReductionIntrinsic(Intrinsic::ID ID, Value *Src);

llvm/lib/IR/IRBuilder.cpp

Lines changed: 17 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -169,58 +169,36 @@ Value *IRBuilderBase::CreateStepVector(Type *DstType, const Twine &Name) {
169169

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

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

179178
if (Align)
180179
cast<MemSetInst>(CI)->setDestAlignment(*Align);
181-
182-
// Set the TBAA info if present.
183-
if (TBAATag)
184-
CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
185-
186-
if (ScopeTag)
187-
CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
188-
189-
if (NoAliasTag)
190-
CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
191-
180+
CI->setAAMetadata(AAInfo);
192181
return CI;
193182
}
194183

195184
CallInst *IRBuilderBase::CreateMemSetInline(Value *Dst, MaybeAlign DstAlign,
196185
Value *Val, Value *Size,
197-
bool IsVolatile, MDNode *TBAATag,
198-
MDNode *ScopeTag,
199-
MDNode *NoAliasTag) {
186+
bool IsVolatile,
187+
const AAMDNodes &AAInfo) {
200188
Value *Ops[] = {Dst, Val, Size, getInt1(IsVolatile)};
201189
Type *Tys[] = {Dst->getType(), Size->getType()};
202190

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

205193
if (DstAlign)
206194
cast<MemSetInst>(CI)->setDestAlignment(*DstAlign);
207-
208-
// Set the TBAA info if present.
209-
if (TBAATag)
210-
CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
211-
212-
if (ScopeTag)
213-
CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
214-
215-
if (NoAliasTag)
216-
CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
217-
195+
CI->setAAMetadata(AAInfo);
218196
return CI;
219197
}
220198

221199
CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemSet(
222200
Value *Ptr, Value *Val, Value *Size, Align Alignment, uint32_t ElementSize,
223-
MDNode *TBAATag, MDNode *ScopeTag, MDNode *NoAliasTag) {
201+
const AAMDNodes &AAInfo) {
224202

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

231209
cast<AnyMemSetInst>(CI)->setDestAlignment(Alignment);
232-
233-
// Set the TBAA info if present.
234-
if (TBAATag)
235-
CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
236-
237-
if (ScopeTag)
238-
CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
239-
240-
if (NoAliasTag)
241-
CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
242-
210+
CI->setAAMetadata(AAInfo);
243211
return CI;
244212
}
245213

246-
CallInst *IRBuilderBase::CreateMemTransferInst(
247-
Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src,
248-
MaybeAlign SrcAlign, Value *Size, bool isVolatile, MDNode *TBAATag,
249-
MDNode *TBAAStructTag, MDNode *ScopeTag, MDNode *NoAliasTag) {
214+
CallInst *IRBuilderBase::CreateMemTransferInst(Intrinsic::ID IntrID, Value *Dst,
215+
MaybeAlign DstAlign, Value *Src,
216+
MaybeAlign SrcAlign, Value *Size,
217+
bool isVolatile,
218+
const AAMDNodes &AAInfo) {
250219
assert((IntrID == Intrinsic::memcpy || IntrID == Intrinsic::memcpy_inline ||
251220
IntrID == Intrinsic::memmove) &&
252221
"Unexpected intrinsic ID");
@@ -260,28 +229,13 @@ CallInst *IRBuilderBase::CreateMemTransferInst(
260229
MCI->setDestAlignment(*DstAlign);
261230
if (SrcAlign)
262231
MCI->setSourceAlignment(*SrcAlign);
263-
264-
// Set the TBAA info if present.
265-
if (TBAATag)
266-
CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
267-
268-
// Set the TBAA Struct info if present.
269-
if (TBAAStructTag)
270-
CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
271-
272-
if (ScopeTag)
273-
CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
274-
275-
if (NoAliasTag)
276-
CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
277-
232+
MCI->setAAMetadata(AAInfo);
278233
return CI;
279234
}
280235

281236
CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemCpy(
282237
Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
283-
uint32_t ElementSize, MDNode *TBAATag, MDNode *TBAAStructTag,
284-
MDNode *ScopeTag, MDNode *NoAliasTag) {
238+
uint32_t ElementSize, const AAMDNodes &AAInfo) {
285239
assert(DstAlign >= ElementSize &&
286240
"Pointer alignment must be at least element size");
287241
assert(SrcAlign >= ElementSize &&
@@ -296,21 +250,7 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemCpy(
296250
auto *AMCI = cast<AnyMemCpyInst>(CI);
297251
AMCI->setDestAlignment(DstAlign);
298252
AMCI->setSourceAlignment(SrcAlign);
299-
300-
// Set the TBAA info if present.
301-
if (TBAATag)
302-
CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
303-
304-
// Set the TBAA Struct info if present.
305-
if (TBAAStructTag)
306-
CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
307-
308-
if (ScopeTag)
309-
CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
310-
311-
if (NoAliasTag)
312-
CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
313-
253+
AMCI->setAAMetadata(AAInfo);
314254
return CI;
315255
}
316256

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

395335
CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemMove(
396336
Value *Dst, Align DstAlign, Value *Src, Align SrcAlign, Value *Size,
397-
uint32_t ElementSize, MDNode *TBAATag, MDNode *TBAAStructTag,
398-
MDNode *ScopeTag, MDNode *NoAliasTag) {
337+
uint32_t ElementSize, const AAMDNodes &AAInfo) {
399338
assert(DstAlign >= ElementSize &&
400339
"Pointer alignment must be at least element size");
401340
assert(SrcAlign >= ElementSize &&
@@ -409,21 +348,7 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemMove(
409348
// Set the alignment of the pointer args.
410349
CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), DstAlign));
411350
CI->addParamAttr(1, Attribute::getWithAlignment(CI->getContext(), SrcAlign));
412-
413-
// Set the TBAA info if present.
414-
if (TBAATag)
415-
CI->setMetadata(LLVMContext::MD_tbaa, TBAATag);
416-
417-
// Set the TBAA Struct info if present.
418-
if (TBAAStructTag)
419-
CI->setMetadata(LLVMContext::MD_tbaa_struct, TBAAStructTag);
420-
421-
if (ScopeTag)
422-
CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag);
423-
424-
if (NoAliasTag)
425-
CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag);
426-
351+
CI->setAAMetadata(AAInfo);
427352
return CI;
428353
}
429354

llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,14 +1123,10 @@ static bool replaceIfSimplePointerUse(const TargetTransformInfo &TTI,
11231123
static bool handleMemIntrinsicPtrUse(MemIntrinsic *MI, Value *OldV,
11241124
Value *NewV) {
11251125
IRBuilder<> B(MI);
1126-
MDNode *TBAA = MI->getMetadata(LLVMContext::MD_tbaa);
1127-
MDNode *ScopeMD = MI->getMetadata(LLVMContext::MD_alias_scope);
1128-
MDNode *NoAliasMD = MI->getMetadata(LLVMContext::MD_noalias);
1129-
11301126
if (auto *MSI = dyn_cast<MemSetInst>(MI)) {
11311127
B.CreateMemSet(NewV, MSI->getValue(), MSI->getLength(), MSI->getDestAlign(),
11321128
false, // isVolatile
1133-
TBAA, ScopeMD, NoAliasMD);
1129+
MI->getAAMetadata());
11341130
} else if (auto *MTI = dyn_cast<MemTransferInst>(MI)) {
11351131
Value *Src = MTI->getRawSource();
11361132
Value *Dest = MTI->getRawDest();
@@ -1143,23 +1139,22 @@ static bool handleMemIntrinsicPtrUse(MemIntrinsic *MI, Value *OldV,
11431139
Dest = NewV;
11441140

11451141
if (auto *MCI = dyn_cast<MemCpyInst>(MTI)) {
1146-
MDNode *TBAAStruct = MTI->getMetadata(LLVMContext::MD_tbaa_struct);
11471142
if (MCI->isForceInlined())
11481143
B.CreateMemCpyInline(Dest, MTI->getDestAlign(), Src,
11491144
MTI->getSourceAlign(), MTI->getLength(),
11501145
false, // isVolatile
1151-
TBAA, TBAAStruct, ScopeMD, NoAliasMD);
1146+
MI->getAAMetadata());
11521147
else
11531148
B.CreateMemCpy(Dest, MTI->getDestAlign(), Src, MTI->getSourceAlign(),
11541149
MTI->getLength(),
11551150
false, // isVolatile
1156-
TBAA, TBAAStruct, ScopeMD, NoAliasMD);
1151+
MI->getAAMetadata());
11571152
} else {
11581153
assert(isa<MemMoveInst>(MTI));
11591154
B.CreateMemMove(Dest, MTI->getDestAlign(), Src, MTI->getSourceAlign(),
11601155
MTI->getLength(),
11611156
false, // isVolatile
1162-
TBAA, ScopeMD, NoAliasMD);
1157+
MI->getAAMetadata());
11631158
}
11641159
} else
11651160
llvm_unreachable("unhandled MemIntrinsic");

0 commit comments

Comments
 (0)