Skip to content

Commit f0d7fea

Browse files
authored
[IRBuilder] Use AAMDNodes helper class in CreateMem* routines [nfc-ish] (#139950)
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 d6b73da commit f0d7fea

File tree

4 files changed

+81
-200
lines changed

4 files changed

+81
-200
lines changed

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 51 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -608,43 +608,33 @@ class IRBuilderBase {
608608
/// Create and insert a memset to the specified pointer and the
609609
/// specified value.
610610
///
611-
/// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
612-
/// specified, it will be added to the instruction. Likewise with alias.scope
613-
/// and noalias tags.
611+
/// If the pointer isn't an i8*, it will be converted. If alias metadata is
612+
/// specified, it will be added to the instruction.
614613
CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size,
615614
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);
615+
const AAMDNodes &AAInfo = AAMDNodes()) {
616+
return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile, AAInfo);
620617
}
621618

622619
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);
620+
bool isVolatile = false,
621+
const AAMDNodes &AAInfo = AAMDNodes());
626622

627623
CallInst *CreateMemSetInline(Value *Dst, MaybeAlign DstAlign, Value *Val,
628624
Value *Size, bool IsVolatile = false,
629-
MDNode *TBAATag = nullptr,
630-
MDNode *ScopeTag = nullptr,
631-
MDNode *NoAliasTag = nullptr);
625+
const AAMDNodes &AAInfo = AAMDNodes());
632626

633627
/// Create and insert an element unordered-atomic memset of the region of
634628
/// memory starting at the given pointer to the given value.
635629
///
636-
/// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
637-
/// specified, it will be added to the instruction. Likewise with alias.scope
638-
/// 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);
630+
/// If the pointer isn't an i8*, it will be converted. If alias metadata is
631+
/// specified, it will be added to the instruction.
632+
CallInst *
633+
CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, uint64_t Size,
634+
Align Alignment, uint32_t ElementSize,
635+
const AAMDNodes &AAInfo = AAMDNodes()) {
636+
return CreateElementUnorderedAtomicMemSet(
637+
Ptr, Val, getInt64(Size), Align(Alignment), ElementSize, AAInfo);
648638
}
649639

650640
CallInst *CreateMalloc(Type *IntPtrTy, Type *AllocTy, Value *AllocSize,
@@ -662,88 +652,72 @@ class IRBuilderBase {
662652
/// Generate the IR for a call to the builtin free function.
663653
CallInst *CreateFree(Value *Source, ArrayRef<OperandBundleDef> Bundles = {});
664654

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);
655+
CallInst *
656+
CreateElementUnorderedAtomicMemSet(Value *Ptr, Value *Val, Value *Size,
657+
Align Alignment, uint32_t ElementSize,
658+
const AAMDNodes &AAInfo = AAMDNodes());
671659

672660
/// Create and insert a memcpy between the specified pointers.
673661
///
674-
/// If the pointers aren't i8*, they will be converted. If a TBAA tag is
675-
/// specified, it will be added to the instruction. Likewise with alias.scope
662+
/// If the pointers aren't i8*, they will be converted. If alias metadata is
663+
/// specified, it will be added to the instruction.
676664
/// and noalias tags.
677665
CallInst *CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src,
678666
MaybeAlign SrcAlign, uint64_t Size,
679-
bool isVolatile = false, MDNode *TBAATag = nullptr,
680-
MDNode *TBAAStructTag = nullptr,
681-
MDNode *ScopeTag = nullptr,
682-
MDNode *NoAliasTag = nullptr) {
667+
bool isVolatile = false,
668+
const AAMDNodes &AAInfo = AAMDNodes()) {
683669
return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
684-
isVolatile, TBAATag, TBAAStructTag, ScopeTag,
685-
NoAliasTag);
670+
isVolatile, AAInfo);
686671
}
687672

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);
673+
CallInst *CreateMemTransferInst(Intrinsic::ID IntrID, Value *Dst,
674+
MaybeAlign DstAlign, Value *Src,
675+
MaybeAlign SrcAlign, Value *Size,
676+
bool isVolatile = false,
677+
const AAMDNodes &AAInfo = AAMDNodes());
693678

694679
CallInst *CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src,
695680
MaybeAlign SrcAlign, Value *Size,
696-
bool isVolatile = false, MDNode *TBAATag = nullptr,
697-
MDNode *TBAAStructTag = nullptr,
698-
MDNode *ScopeTag = nullptr,
699-
MDNode *NoAliasTag = nullptr) {
681+
bool isVolatile = false,
682+
const AAMDNodes &AAInfo = AAMDNodes()) {
700683
return CreateMemTransferInst(Intrinsic::memcpy, Dst, DstAlign, Src,
701-
SrcAlign, Size, isVolatile, TBAATag,
702-
TBAAStructTag, ScopeTag, NoAliasTag);
684+
SrcAlign, Size, isVolatile, AAInfo);
703685
}
704686

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) {
687+
CallInst *CreateMemCpyInline(Value *Dst, MaybeAlign DstAlign, Value *Src,
688+
MaybeAlign SrcAlign, Value *Size,
689+
bool isVolatile = false,
690+
const AAMDNodes &AAInfo = AAMDNodes()) {
710691
return CreateMemTransferInst(Intrinsic::memcpy_inline, Dst, DstAlign, Src,
711-
SrcAlign, Size, isVolatile, TBAATag,
712-
TBAAStructTag, ScopeTag, NoAliasTag);
692+
SrcAlign, Size, isVolatile, AAInfo);
713693
}
714694

715695
/// Create and insert an element unordered-atomic memcpy between the
716696
/// specified pointers.
717697
///
718-
/// DstAlign/SrcAlign are the alignments of the Dst/Src pointers, respectively.
698+
/// DstAlign/SrcAlign are the alignments of the Dst/Src pointers,
699+
/// respectively.
719700
///
720-
/// If the pointers aren't i8*, they will be converted. If a TBAA tag is
721-
/// specified, it will be added to the instruction. Likewise with alias.scope
722-
/// and noalias tags.
701+
/// If the pointers aren't i8*, they will be converted. If alias metadata is
702+
/// specified, it will be added to the instruction.
723703
CallInst *CreateElementUnorderedAtomicMemCpy(
724704
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);
705+
uint32_t ElementSize, const AAMDNodes &AAInfo = AAMDNodes());
728706

729707
CallInst *CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src,
730708
MaybeAlign SrcAlign, uint64_t Size,
731-
bool isVolatile = false, MDNode *TBAATag = nullptr,
732-
MDNode *ScopeTag = nullptr,
733-
MDNode *NoAliasTag = nullptr) {
709+
bool isVolatile = false,
710+
const AAMDNodes &AAInfo = AAMDNodes()) {
734711
return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
735-
isVolatile, TBAATag, ScopeTag, NoAliasTag);
712+
isVolatile, AAInfo);
736713
}
737714

738715
CallInst *CreateMemMove(Value *Dst, MaybeAlign DstAlign, Value *Src,
739716
MaybeAlign SrcAlign, Value *Size,
740-
bool isVolatile = false, MDNode *TBAATag = nullptr,
741-
MDNode *ScopeTag = nullptr,
742-
MDNode *NoAliasTag = nullptr) {
717+
bool isVolatile = false,
718+
const AAMDNodes &AAInfo = AAMDNodes()) {
743719
return CreateMemTransferInst(Intrinsic::memmove, Dst, DstAlign, Src,
744-
SrcAlign, Size, isVolatile, TBAATag,
745-
/*TBAAStructTag=*/nullptr, ScopeTag,
746-
NoAliasTag);
720+
SrcAlign, Size, isVolatile, AAInfo);
747721
}
748722

749723
/// \brief Create and insert an element unordered-atomic memmove between the
@@ -752,14 +726,11 @@ class IRBuilderBase {
752726
/// DstAlign/SrcAlign are the alignments of the Dst/Src pointers,
753727
/// respectively.
754728
///
755-
/// If the pointers aren't i8*, they will be converted. If a TBAA tag is
756-
/// specified, it will be added to the instruction. Likewise with alias.scope
757-
/// and noalias tags.
729+
/// If the pointers aren't i8*, they will be converted. If alias metadata is
730+
/// specified, it will be added to the instruction.
758731
CallInst *CreateElementUnorderedAtomicMemMove(
759732
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);
733+
uint32_t ElementSize, const AAMDNodes &AAInfo = AAMDNodes());
763734

764735
private:
765736
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

0 commit comments

Comments
 (0)