X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FAttributeImpl.h;h=659f9568b7c6cf0ca96617c7003547ea7a7226df;hb=9b627286bc1350e25f0ecdd8a76955e54d333ff6;hp=5a72c37505e1769e25ad4cbc91f579b385007430;hpb=e22cde01a63c907cb23f425ba4f4f16ede754dbe;p=oota-llvm.git diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h index 5a72c37505e..659f9568b7c 100644 --- a/lib/IR/AttributeImpl.h +++ b/lib/IR/AttributeImpl.h @@ -13,11 +13,12 @@ /// //===----------------------------------------------------------------------===// -#ifndef LLVM_ATTRIBUTESIMPL_H -#define LLVM_ATTRIBUTESIMPL_H +#ifndef LLVM_LIB_IR_ATTRIBUTEIMPL_H +#define LLVM_LIB_IR_ATTRIBUTEIMPL_H #include "llvm/ADT/FoldingSet.h" #include "llvm/IR/Attributes.h" +#include "llvm/Support/TrailingObjects.h" #include namespace llvm { @@ -33,13 +34,13 @@ class AttributeImpl : public FoldingSetNode { unsigned char KindID; ///< Holds the AttrEntryKind of the attribute // AttributesImpl is uniqued, these should not be publicly available. - void operator=(const AttributeImpl &) LLVM_DELETED_FUNCTION; - AttributeImpl(const AttributeImpl &) LLVM_DELETED_FUNCTION; + void operator=(const AttributeImpl &) = delete; + AttributeImpl(const AttributeImpl &) = delete; protected: enum AttrEntryKind { EnumAttrEntry, - AlignAttrEntry, + IntAttrEntry, StringAttrEntry }; @@ -49,7 +50,7 @@ public: virtual ~AttributeImpl(); bool isEnumAttribute() const { return KindID == EnumAttrEntry; } - bool isAlignAttribute() const { return KindID == AlignAttrEntry; } + bool isIntAttribute() const { return KindID == IntAttrEntry; } bool isStringAttribute() const { return KindID == StringAttrEntry; } bool hasAttribute(Attribute::AttrKind A) const; @@ -67,7 +68,7 @@ public: void Profile(FoldingSetNodeID &ID) const { if (isEnumAttribute()) Profile(ID, getKindAsEnum(), 0); - else if (isAlignAttribute()) + else if (isIntAttribute()) Profile(ID, getKindAsEnum(), getValueAsInt()); else Profile(ID, getKindAsString(), getValueAsString()); @@ -94,6 +95,7 @@ public: /// attribute enties, which are for target-dependent attributes. class EnumAttributeImpl : public AttributeImpl { + virtual void anchor(); Attribute::AttrKind Kind; protected: @@ -107,21 +109,24 @@ public: Attribute::AttrKind getEnumKind() const { return Kind; } }; -class AlignAttributeImpl : public EnumAttributeImpl { - unsigned Align; +class IntAttributeImpl : public EnumAttributeImpl { + void anchor() override; + uint64_t Val; public: - AlignAttributeImpl(Attribute::AttrKind Kind, unsigned Align) - : EnumAttributeImpl(AlignAttrEntry, Kind), Align(Align) { - assert( - (Kind == Attribute::Alignment || Kind == Attribute::StackAlignment) && - "Wrong kind for alignment attribute!"); + IntAttributeImpl(Attribute::AttrKind Kind, uint64_t Val) + : EnumAttributeImpl(IntAttrEntry, Kind), Val(Val) { + assert((Kind == Attribute::Alignment || Kind == Attribute::StackAlignment || + Kind == Attribute::Dereferenceable || + Kind == Attribute::DereferenceableOrNull) && + "Wrong kind for int attribute!"); } - unsigned getAlignment() const { return Align; } + uint64_t getValue() const { return Val; } }; class StringAttributeImpl : public AttributeImpl { + virtual void anchor(); std::string Kind; std::string Val; @@ -137,18 +142,21 @@ public: /// \class /// \brief This class represents a group of attributes that apply to one /// element: function, return type, or parameter. -class AttributeSetNode : public FoldingSetNode { +class AttributeSetNode final + : public FoldingSetNode, + private TrailingObjects { + friend TrailingObjects; + unsigned NumAttrs; ///< Number of attributes in this node. AttributeSetNode(ArrayRef Attrs) : NumAttrs(Attrs.size()) { // There's memory after the node where we can store the entries in. - std::copy(Attrs.begin(), Attrs.end(), - reinterpret_cast(this + 1)); + std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects()); } // AttributesSetNode is uniqued, these should not be publicly available. - void operator=(const AttributeSetNode &) LLVM_DELETED_FUNCTION; - AttributeSetNode(const AttributeSetNode &) LLVM_DELETED_FUNCTION; + void operator=(const AttributeSetNode &) = delete; + AttributeSetNode(const AttributeSetNode &) = delete; public: static AttributeSetNode *get(LLVMContext &C, ArrayRef Attrs); @@ -161,10 +169,12 @@ public: unsigned getAlignment() const; unsigned getStackAlignment() const; + uint64_t getDereferenceableBytes() const; + uint64_t getDereferenceableOrNullBytes() const; std::string getAsString(bool InAttrGrp) const; typedef const Attribute *iterator; - iterator begin() const { return reinterpret_cast(this + 1); } + iterator begin() const { return getTrailingObjects(); } iterator end() const { return begin() + NumAttrs; } void Profile(FoldingSetNodeID &ID) const { @@ -176,33 +186,49 @@ public: } }; +typedef std::pair IndexAttrPair; + //===----------------------------------------------------------------------===// /// \class /// \brief This class represents a set of attributes that apply to the function, /// return type, and parameters. -class AttributeSetImpl : public FoldingSetNode { +class AttributeSetImpl final + : public FoldingSetNode, + private TrailingObjects { friend class AttributeSet; + friend TrailingObjects; +private: LLVMContext &Context; - - typedef std::pair IndexAttrPair; unsigned NumAttrs; ///< Number of entries in this set. + // Helper fn for TrailingObjects class. + size_t numTrailingObjects(OverloadToken) { return NumAttrs; } + /// \brief Return a pointer to the IndexAttrPair for the specified slot. const IndexAttrPair *getNode(unsigned Slot) const { - return reinterpret_cast(this + 1) + Slot; + return getTrailingObjects() + Slot; } // AttributesSet is uniqued, these should not be publicly available. - void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION; - AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION; + void operator=(const AttributeSetImpl &) = delete; + AttributeSetImpl(const AttributeSetImpl &) = delete; public: AttributeSetImpl(LLVMContext &C, ArrayRef > Attrs) : Context(C), NumAttrs(Attrs.size()) { + +#ifndef NDEBUG + if (Attrs.size() >= 2) { + for (const std::pair *i = Attrs.begin() + 1, + *e = Attrs.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(Attrs.begin(), Attrs.end(), - reinterpret_cast(this + 1)); + std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects()); } /// \brief Get the context that created this AttributeSetImpl. @@ -249,6 +275,8 @@ public: // FIXME: This atrocity is temporary. uint64_t Raw(unsigned Index) const; + + void dump() const; }; } // end llvm namespace