Skip to content

Commit a2ab8fc

Browse files
committed
[Attributes] Add additional MemoryEffects APIs (NFC)
This adds the usual complement of APIs for creating and fetching a non-trivial attribute. Split out from D135780.
1 parent df23ede commit a2ab8fc

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

llvm/include/llvm/IR/Attributes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class Attribute {
146146
static Attribute getWithPreallocatedType(LLVMContext &Context, Type *Ty);
147147
static Attribute getWithInAllocaType(LLVMContext &Context, Type *Ty);
148148
static Attribute getWithUWTableKind(LLVMContext &Context, UWTableKind Kind);
149+
static Attribute getWithMemoryEffects(LLVMContext &Context, MemoryEffects ME);
149150

150151
/// For a typed attribute, return the equivalent attribute with the type
151152
/// changed to \p ReplacementTy.
@@ -379,6 +380,7 @@ class AttributeSet {
379380
Optional<unsigned> getVScaleRangeMax() const;
380381
UWTableKind getUWTableKind() const;
381382
AllocFnKind getAllocKind() const;
383+
MemoryEffects getMemoryEffects() const;
382384
std::string getAsString(bool InAttrGrp = false) const;
383385

384386
/// Return true if this attribute set belongs to the LLVMContext.
@@ -878,6 +880,9 @@ class AttributeList {
878880

879881
AllocFnKind getAllocKind() const;
880882

883+
/// Returns memory effects of the function.
884+
MemoryEffects getMemoryEffects() const;
885+
881886
/// Return the attributes at the index as a string.
882887
std::string getAsString(unsigned Index, bool InAttrGrp = false) const;
883888

llvm/lib/IR/AttributeImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class AttributeSetNode final
263263
Optional<unsigned> getVScaleRangeMax() const;
264264
UWTableKind getUWTableKind() const;
265265
AllocFnKind getAllocKind() const;
266+
MemoryEffects getMemoryEffects() const;
266267
std::string getAsString(bool InAttrGrp) const;
267268
Type *getAttributeType(Attribute::AttrKind Kind) const;
268269

llvm/lib/IR/Attributes.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ Attribute Attribute::getWithUWTableKind(LLVMContext &Context,
211211
return get(Context, UWTable, uint64_t(Kind));
212212
}
213213

214+
Attribute Attribute::getWithMemoryEffects(LLVMContext &Context,
215+
MemoryEffects ME) {
216+
return get(Context, Memory, ME.toIntValue());
217+
}
218+
214219
Attribute
215220
Attribute::getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg,
216221
const Optional<unsigned> &NumElemsArg) {
@@ -831,6 +836,10 @@ AllocFnKind AttributeSet::getAllocKind() const {
831836
return SetNode ? SetNode->getAllocKind() : AllocFnKind::Unknown;
832837
}
833838

839+
MemoryEffects AttributeSet::getMemoryEffects() const {
840+
return SetNode ? SetNode->getMemoryEffects() : MemoryEffects::unknown();
841+
}
842+
834843
std::string AttributeSet::getAsString(bool InAttrGrp) const {
835844
return SetNode ? SetNode->getAsString(InAttrGrp) : "";
836845
}
@@ -1009,6 +1018,12 @@ AllocFnKind AttributeSetNode::getAllocKind() const {
10091018
return AllocFnKind::Unknown;
10101019
}
10111020

1021+
MemoryEffects AttributeSetNode::getMemoryEffects() const {
1022+
if (auto A = findEnumAttribute(Attribute::Memory))
1023+
return A->getMemoryEffects();
1024+
return MemoryEffects::unknown();
1025+
}
1026+
10121027
std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
10131028
std::string Str;
10141029
for (iterator I = begin(), E = end(); I != E; ++I) {
@@ -1561,6 +1576,10 @@ AllocFnKind AttributeList::getAllocKind() const {
15611576
return getFnAttrs().getAllocKind();
15621577
}
15631578

1579+
MemoryEffects AttributeList::getMemoryEffects() const {
1580+
return getFnAttrs().getMemoryEffects();
1581+
}
1582+
15641583
std::string AttributeList::getAsString(unsigned Index, bool InAttrGrp) const {
15651584
return getAttributes(Index).getAsString(InAttrGrp);
15661585
}

0 commit comments

Comments
 (0)