summaryrefslogtreecommitdiff
path: root/lib/IR/AttributeImpl.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/IR/AttributeImpl.h')
-rw-r--r--lib/IR/AttributeImpl.h147
1 files changed, 83 insertions, 64 deletions
diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h
index d0d27101aa867..09f037365793d 100644
--- a/lib/IR/AttributeImpl.h
+++ b/lib/IR/AttributeImpl.h
@@ -16,7 +16,6 @@
#ifndef LLVM_LIB_IR_ATTRIBUTEIMPL_H
#define LLVM_LIB_IR_ATTRIBUTEIMPL_H
-#include "AttributeSetNode.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/StringRef.h"
@@ -144,16 +143,74 @@ public:
StringRef getStringValue() const { return Val; }
};
-typedef std::pair<unsigned, AttributeSetNode *> IndexAttrPair;
+//===----------------------------------------------------------------------===//
+/// \class
+/// \brief This class represents a group of attributes that apply to one
+/// element: function, return type, or parameter.
+class AttributeSetNode final
+ : public FoldingSetNode,
+ private TrailingObjects<AttributeSetNode, Attribute> {
+ friend TrailingObjects;
+
+ /// Bitset with a bit for each available attribute Attribute::AttrKind.
+ uint64_t AvailableAttrs;
+ unsigned NumAttrs; ///< Number of attributes in this node.
+
+ AttributeSetNode(ArrayRef<Attribute> Attrs);
+
+public:
+ // AttributesSetNode is uniqued, these should not be available.
+ AttributeSetNode(const AttributeSetNode &) = delete;
+ AttributeSetNode &operator=(const AttributeSetNode &) = delete;
+
+ void operator delete(void *p) { ::operator delete(p); }
+
+ static AttributeSetNode *get(LLVMContext &C, const AttrBuilder &B);
+
+ static AttributeSetNode *get(LLVMContext &C, ArrayRef<Attribute> Attrs);
+
+ /// \brief Return the number of attributes this AttributeList contains.
+ unsigned getNumAttributes() const { return NumAttrs; }
+
+ bool hasAttribute(Attribute::AttrKind Kind) const {
+ return AvailableAttrs & ((uint64_t)1) << Kind;
+ }
+ bool hasAttribute(StringRef Kind) const;
+ bool hasAttributes() const { return NumAttrs != 0; }
+
+ Attribute getAttribute(Attribute::AttrKind Kind) const;
+ Attribute getAttribute(StringRef Kind) const;
+
+ unsigned getAlignment() const;
+ unsigned getStackAlignment() const;
+ uint64_t getDereferenceableBytes() const;
+ uint64_t getDereferenceableOrNullBytes() const;
+ std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
+ std::string getAsString(bool InAttrGrp) const;
+
+ typedef const Attribute *iterator;
+ iterator begin() const { return getTrailingObjects<Attribute>(); }
+ iterator end() const { return begin() + NumAttrs; }
+
+ void Profile(FoldingSetNodeID &ID) const {
+ Profile(ID, makeArrayRef(begin(), end()));
+ }
+ static void Profile(FoldingSetNodeID &ID, ArrayRef<Attribute> AttrList) {
+ for (const auto &Attr : AttrList)
+ Attr.Profile(ID);
+ }
+};
+
+typedef std::pair<unsigned, AttributeSet> IndexAttrPair;
//===----------------------------------------------------------------------===//
/// \class
/// \brief This class represents a set of attributes that apply to the function,
/// return type, and parameters.
-class AttributeSetImpl final
+class AttributeListImpl final
: public FoldingSetNode,
- private TrailingObjects<AttributeSetImpl, IndexAttrPair> {
- friend class AttributeSet;
+ private TrailingObjects<AttributeListImpl, IndexAttrPair> {
+ friend class AttributeList;
friend TrailingObjects;
private:
@@ -166,52 +223,21 @@ private:
size_t numTrailingObjects(OverloadToken<IndexAttrPair>) { return NumSlots; }
/// \brief Return a pointer to the IndexAttrPair for the specified slot.
- const IndexAttrPair *getNode(unsigned Slot) const {
+ const IndexAttrPair *getSlotPair(unsigned Slot) const {
return getTrailingObjects<IndexAttrPair>() + Slot;
}
public:
- AttributeSetImpl(LLVMContext &C,
- ArrayRef<std::pair<unsigned, AttributeSetNode *>> Slots)
- : Context(C), NumSlots(Slots.size()), AvailableFunctionAttrs(0) {
- static_assert(Attribute::EndAttrKinds <=
- sizeof(AvailableFunctionAttrs) * CHAR_BIT,
- "Too many attributes");
-
-#ifndef NDEBUG
- if (Slots.size() >= 2) {
- for (const std::pair<unsigned, AttributeSetNode *> *i = Slots.begin() + 1,
- *e = Slots.end();
- i != e; ++i) {
- assert((i-1)->first <= i->first && "Attribute set not ordered!");
- }
- }
-#endif
- // There's memory after the node where we can store the entries in.
- std::copy(Slots.begin(), Slots.end(), getTrailingObjects<IndexAttrPair>());
-
- // Initialize AvailableFunctionAttrs summary bitset.
- if (NumSlots > 0) {
- static_assert(AttributeSet::FunctionIndex == ~0u,
- "FunctionIndex should be biggest possible index");
- const std::pair<unsigned, AttributeSetNode *> &Last = Slots.back();
- if (Last.first == AttributeSet::FunctionIndex) {
- const AttributeSetNode *Node = Last.second;
- for (Attribute I : *Node) {
- if (!I.isStringAttribute())
- AvailableFunctionAttrs |= ((uint64_t)1) << I.getKindAsEnum();
- }
- }
- }
- }
+ AttributeListImpl(LLVMContext &C,
+ ArrayRef<std::pair<unsigned, AttributeSet>> Slots);
// AttributesSetImpt is uniqued, these should not be available.
- AttributeSetImpl(const AttributeSetImpl &) = delete;
- AttributeSetImpl &operator=(const AttributeSetImpl &) = delete;
+ AttributeListImpl(const AttributeListImpl &) = delete;
+ AttributeListImpl &operator=(const AttributeListImpl &) = delete;
void operator delete(void *p) { ::operator delete(p); }
- /// \brief Get the context that created this AttributeSetImpl.
+ /// \brief Get the context that created this AttributeListImpl.
LLVMContext &getContext() { return Context; }
/// \brief Return the number of slots used in this attribute list. This is
@@ -224,42 +250,35 @@ public:
/// attributes are applied to, not the index into the AttrNodes list where the
/// attributes reside.
unsigned getSlotIndex(unsigned Slot) const {
- return getNode(Slot)->first;
+ return getSlotPair(Slot)->first;
+ }
+
+ /// \brief Retrieve the attribute set node for the given "slot" in the
+ /// AttrNode list.
+ AttributeSet getSlotNode(unsigned Slot) const {
+ return getSlotPair(Slot)->second;
}
/// \brief Retrieve the attributes for the given "slot" in the AttrNode list.
/// \p Slot is an index into the AttrNodes list, not the index of the return /
/// parameter/ function which the attributes apply to.
- AttributeSet getSlotAttributes(unsigned Slot) const {
- return AttributeSet::get(Context, *getNode(Slot));
+ AttributeList getSlotAttributes(unsigned Slot) const {
+ return AttributeList::get(Context, *getSlotPair(Slot));
}
- /// \brief Retrieve the attribute set node for the given "slot" in the
- /// AttrNode list.
- AttributeSetNode *getSlotNode(unsigned Slot) const {
- return getNode(Slot)->second;
- }
-
- /// \brief Return true if the AttributeSetNode for the FunctionIndex has an
+ /// \brief Return true if the AttributeSet or the FunctionIndex has an
/// enum attribute of the given kind.
bool hasFnAttribute(Attribute::AttrKind Kind) const {
return AvailableFunctionAttrs & ((uint64_t)1) << Kind;
}
- typedef AttributeSetNode::iterator iterator;
- iterator begin(unsigned Slot) const { return getSlotNode(Slot)->begin(); }
- iterator end(unsigned Slot) const { return getSlotNode(Slot)->end(); }
+ typedef AttributeSet::iterator iterator;
+ iterator begin(unsigned Slot) const { return getSlotNode(Slot).begin(); }
+ iterator end(unsigned Slot) const { return getSlotNode(Slot).end(); }
- void Profile(FoldingSetNodeID &ID) const {
- Profile(ID, makeArrayRef(getNode(0), getNumSlots()));
- }
+ void Profile(FoldingSetNodeID &ID) const;
static void Profile(FoldingSetNodeID &ID,
- ArrayRef<std::pair<unsigned, AttributeSetNode*>> Nodes) {
- for (const auto &Node : Nodes) {
- ID.AddInteger(Node.first);
- ID.AddPointer(Node.second);
- }
- }
+ ArrayRef<std::pair<unsigned, AttributeSet>> Nodes);
void dump() const;
};