aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/AttributeImpl.h
diff options
context:
space:
mode:
authorHaopeng Liu <153236845+haopliu@users.noreply.github.com>2024-06-21 12:09:00 -0700
committerGitHub <noreply@github.com>2024-06-21 12:09:00 -0700
commit5ece35df8586d0cb8c104a9f44eaae771de025f5 (patch)
treeb1c14e2f040a5282bb7f3a3a2ea73927df22e2cb /llvm/lib/IR/AttributeImpl.h
parentf1f3c34b4770437bdb022737918603b4bbeb523e (diff)
downloadllvm-5ece35df8586d0cb8c104a9f44eaae771de025f5.zip
llvm-5ece35df8586d0cb8c104a9f44eaae771de025f5.tar.gz
llvm-5ece35df8586d0cb8c104a9f44eaae771de025f5.tar.bz2
Add the 'initializes' attribute langref and support (#84803)
We propose adding a new LLVM attribute, `initializes((Lo1,Hi1),(Lo2,Hi2),...)`, which expresses the notion of memory space (i.e., intervals, in bytes) that the argument pointing to is initialized in the function. Will commit the attribute inferring in the follow-up PRs. https://discourse.llvm.org/t/rfc-llvm-new-initialized-parameter-attribute-for-improved-interprocedural-dse/77337
Diffstat (limited to 'llvm/lib/IR/AttributeImpl.h')
-rw-r--r--llvm/lib/IR/AttributeImpl.h53
1 files changed, 52 insertions, 1 deletions
diff --git a/llvm/lib/IR/AttributeImpl.h b/llvm/lib/IR/AttributeImpl.h
index dc5b80b..b944172 100644
--- a/llvm/lib/IR/AttributeImpl.h
+++ b/llvm/lib/IR/AttributeImpl.h
@@ -21,6 +21,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/ConstantRange.h"
+#include "llvm/IR/ConstantRangeList.h"
#include "llvm/Support/TrailingObjects.h"
#include <cassert>
#include <cstddef>
@@ -48,6 +49,7 @@ protected:
StringAttrEntry,
TypeAttrEntry,
ConstantRangeAttrEntry,
+ ConstantRangeListAttrEntry,
};
AttributeImpl(AttrEntryKind KindID) : KindID(KindID) {}
@@ -64,6 +66,9 @@ public:
bool isConstantRangeAttribute() const {
return KindID == ConstantRangeAttrEntry;
}
+ bool isConstantRangeListAttribute() const {
+ return KindID == ConstantRangeListAttrEntry;
+ }
bool hasAttribute(Attribute::AttrKind A) const;
bool hasAttribute(StringRef Kind) const;
@@ -79,6 +84,8 @@ public:
const ConstantRange &getValueAsConstantRange() const;
+ ArrayRef<ConstantRange> getValueAsConstantRangeList() const;
+
/// Used when sorting the attributes.
bool operator<(const AttributeImpl &AI) const;
@@ -91,8 +98,10 @@ public:
Profile(ID, getKindAsString(), getValueAsString());
else if (isTypeAttribute())
Profile(ID, getKindAsEnum(), getValueAsType());
- else
+ else if (isConstantRangeAttribute())
Profile(ID, getKindAsEnum(), getValueAsConstantRange());
+ else
+ Profile(ID, getKindAsEnum(), getValueAsConstantRangeList());
}
static void Profile(FoldingSetNodeID &ID, Attribute::AttrKind Kind) {
@@ -124,6 +133,16 @@ public:
CR.getLower().Profile(ID);
CR.getUpper().Profile(ID);
}
+
+ static void Profile(FoldingSetNodeID &ID, Attribute::AttrKind Kind,
+ ArrayRef<ConstantRange> Val) {
+ ID.AddInteger(Kind);
+ ID.AddInteger(Val.size());
+ for (auto &CR : Val) {
+ CR.getLower().Profile(ID);
+ CR.getUpper().Profile(ID);
+ }
+ }
};
static_assert(std::is_trivially_destructible<AttributeImpl>::value,
@@ -222,6 +241,38 @@ public:
const ConstantRange &getConstantRangeValue() const { return CR; }
};
+class ConstantRangeListAttributeImpl final
+ : public EnumAttributeImpl,
+ private TrailingObjects<ConstantRangeListAttributeImpl, ConstantRange> {
+ friend TrailingObjects;
+
+ unsigned Size;
+ size_t numTrailingObjects(OverloadToken<ConstantRange>) const { return Size; }
+
+public:
+ ConstantRangeListAttributeImpl(Attribute::AttrKind Kind,
+ ArrayRef<ConstantRange> Val)
+ : EnumAttributeImpl(ConstantRangeListAttrEntry, Kind), Size(Val.size()) {
+ assert(Size > 0);
+ ConstantRange *TrailingCR = getTrailingObjects<ConstantRange>();
+ std::uninitialized_copy(Val.begin(), Val.end(), TrailingCR);
+ }
+
+ ~ConstantRangeListAttributeImpl() {
+ ConstantRange *TrailingCR = getTrailingObjects<ConstantRange>();
+ for (unsigned I = 0; I != Size; ++I)
+ TrailingCR[I].~ConstantRange();
+ }
+
+ ArrayRef<ConstantRange> getConstantRangeListValue() const {
+ return ArrayRef(getTrailingObjects<ConstantRange>(), Size);
+ }
+
+ static size_t totalSizeToAlloc(ArrayRef<ConstantRange> Val) {
+ return TrailingObjects::totalSizeToAlloc<ConstantRange>(Val.size());
+ }
+};
+
class AttributeBitSet {
/// Bitset with a bit for each available attribute Attribute::AttrKind.
uint8_t AvailableAttrs[12] = {};