X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FAttributeImpl.h;h=659f9568b7c6cf0ca96617c7003547ea7a7226df;hb=e0d5233e365fe138f0afd9860ca11e0dd5bf0039;hp=dbd7d63a892bced249156c3eb74dd5b8647de30d;hpb=5a6ea245b00004cc0e44ce3afee16322a0a34509;p=oota-llvm.git diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h index dbd7d63a892..659f9568b7c 100644 --- a/lib/IR/AttributeImpl.h +++ b/lib/IR/AttributeImpl.h @@ -18,6 +18,7 @@ #include "llvm/ADT/FoldingSet.h" #include "llvm/IR/Attributes.h" +#include "llvm/Support/TrailingObjects.h" #include namespace llvm { @@ -141,13 +142,16 @@ 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. @@ -170,7 +174,7 @@ public: 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 { @@ -182,21 +186,28 @@ 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. @@ -206,6 +217,7 @@ 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, @@ -216,8 +228,7 @@ public: } #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.