Author: hans Date: Mon Jul 25 12:37:43 2016 New Revision: 276663 URL: http://llvm.org/viewvc/llvm-project?rev=276663&view=rev Log: Merging r276236 and r276237: ------------------------------------------------------------------------ r276236 | deadalnix | 2016-07-20 21:25:06 -0700 (Wed, 20 Jul 2016) | 9 lines
Expose AttributeSetNode, use it to provide aggregate getter for attribute in the C API. Summary: See D19181 for context. Reviewers: whitequark, Wallbraker, jyknight, echristo, bkramer, void Subscribers: mehdi_amini Differential Revision: http://reviews.llvm.org/D21265 ------------------------------------------------------------------------ ------------------------------------------------------------------------ r276237 | deadalnix | 2016-07-20 21:31:38 -0700 (Wed, 20 Jul 2016) | 1 line Add missing import to fix the build ------------------------------------------------------------------------ Added: llvm/branches/release_39/lib/IR/AttributeSetNode.h - copied, changed from r276236, llvm/trunk/lib/IR/AttributeSetNode.h Modified: llvm/branches/release_39/ (props changed) llvm/branches/release_39/include/llvm-c/Core.h llvm/branches/release_39/include/llvm/IR/Attributes.h llvm/branches/release_39/lib/IR/AttributeImpl.h llvm/branches/release_39/lib/IR/Core.cpp Propchange: llvm/branches/release_39/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Mon Jul 25 12:37:43 2016 @@ -1,3 +1,3 @@ /llvm/branches/Apple/Pertwee:110850,110961 /llvm/branches/type-system-rewrite:133420-134817 -/llvm/trunk:155241,275870,275879,275898,275935,275946,276181,276358,276364,276368,276389,276479 +/llvm/trunk:155241,275870,275879,275898,275935,275946,276181,276236-276237,276358,276364,276368,276389,276479 Modified: llvm/branches/release_39/include/llvm-c/Core.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/include/llvm-c/Core.h?rev=276663&r1=276662&r2=276663&view=diff ============================================================================== --- llvm/branches/release_39/include/llvm-c/Core.h (original) +++ llvm/branches/release_39/include/llvm-c/Core.h Mon Jul 25 12:37:43 2016 @@ -2014,6 +2014,9 @@ void LLVMAddFunctionAttr(LLVMValueRef Fn void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, LLVMAttributeRef A); +unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx); +void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, + LLVMAttributeRef *Attrs); LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, unsigned KindID); @@ -2600,6 +2603,9 @@ void LLVMSetInstrParamAlignment(LLVMValu void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, LLVMAttributeRef A); +unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, LLVMAttributeIndex Idx); +void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx, + LLVMAttributeRef *Attrs); LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID); Modified: llvm/branches/release_39/include/llvm/IR/Attributes.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/include/llvm/IR/Attributes.h?rev=276663&r1=276662&r2=276663&view=diff ============================================================================== --- llvm/branches/release_39/include/llvm/IR/Attributes.h (original) +++ llvm/branches/release_39/include/llvm/IR/Attributes.h Mon Jul 25 12:37:43 2016 @@ -210,6 +210,7 @@ public: private: friend class AttrBuilder; friend class AttributeSetImpl; + friend class AttributeSetNode; template <typename Ty> friend struct DenseMapInfo; /// \brief The attributes that we are managing. This can be null to represent Modified: llvm/branches/release_39/lib/IR/AttributeImpl.h URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/lib/IR/AttributeImpl.h?rev=276663&r1=276662&r2=276663&view=diff ============================================================================== --- llvm/branches/release_39/lib/IR/AttributeImpl.h (original) +++ llvm/branches/release_39/lib/IR/AttributeImpl.h Mon Jul 25 12:37:43 2016 @@ -19,8 +19,8 @@ #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/Optional.h" #include "llvm/IR/Attributes.h" +#include "AttributeSetNode.h" #include "llvm/Support/DataTypes.h" -#include "llvm/Support/TrailingObjects.h" #include <climits> #include <string> @@ -142,73 +142,6 @@ public: StringRef getStringValue() const { return Val; } }; -//===----------------------------------------------------------------------===// -/// \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; - - unsigned NumAttrs; ///< Number of attributes in this node. - /// Bitset with a bit for each available attribute Attribute::AttrKind. - uint64_t AvailableAttrs; - - AttributeSetNode(ArrayRef<Attribute> Attrs) - : NumAttrs(Attrs.size()), AvailableAttrs(0) { - static_assert(Attribute::EndAttrKinds <= sizeof(AvailableAttrs) * CHAR_BIT, - "Too many attributes for AvailableAttrs"); - // There's memory after the node where we can store the entries in. - std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>()); - - for (Attribute I : *this) { - if (!I.isStringAttribute()) { - AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum(); - } - } - } - - // AttributesSetNode is uniqued, these should not be publicly available. - void operator=(const AttributeSetNode &) = delete; - AttributeSetNode(const AttributeSetNode &) = delete; -public: - void operator delete(void *p) { ::operator delete(p); } - - static AttributeSetNode *get(LLVMContext &C, ArrayRef<Attribute> Attrs); - - /// \brief Return the number of attributes this AttributeSet 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 (unsigned I = 0, E = AttrList.size(); I != E; ++I) - AttrList[I].Profile(ID); - } -}; - typedef std::pair<unsigned, AttributeSetNode *> IndexAttrPair; //===----------------------------------------------------------------------===// Copied: llvm/branches/release_39/lib/IR/AttributeSetNode.h (from r276236, llvm/trunk/lib/IR/AttributeSetNode.h) URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/lib/IR/AttributeSetNode.h?p2=llvm/branches/release_39/lib/IR/AttributeSetNode.h&p1=llvm/trunk/lib/IR/AttributeSetNode.h&r1=276236&r2=276663&rev=276663&view=diff ============================================================================== --- llvm/trunk/lib/IR/AttributeSetNode.h (original) +++ llvm/branches/release_39/lib/IR/AttributeSetNode.h Mon Jul 25 12:37:43 2016 @@ -18,6 +18,7 @@ #include "llvm/ADT/FoldingSet.h" #include "llvm/IR/Attributes.h" #include "llvm/Support/TrailingObjects.h" +#include <climits> namespace llvm { Modified: llvm/branches/release_39/lib/IR/Core.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_39/lib/IR/Core.cpp?rev=276663&r1=276662&r2=276663&view=diff ============================================================================== --- llvm/branches/release_39/lib/IR/Core.cpp (original) +++ llvm/branches/release_39/lib/IR/Core.cpp Mon Jul 25 12:37:43 2016 @@ -16,6 +16,7 @@ #include "llvm/ADT/StringSwitch.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/IR/Attributes.h" +#include "AttributeSetNode.h" #include "llvm/IR/CallSite.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" @@ -1844,6 +1845,18 @@ void LLVMAddAttributeAtIndex(LLVMValueRe unwrap<Function>(F)->addAttribute(Idx, unwrap(A)); } +unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx) { + auto *ASN = AttributeSetNode::get(unwrap<Function>(F)->getAttributes(), Idx); + return ASN->getNumAttributes(); +} + +void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, + LLVMAttributeRef *Attrs) { + auto *ASN = AttributeSetNode::get(unwrap<Function>(F)->getAttributes(), Idx); + for (auto A: make_range(ASN->begin(), ASN->end())) + *Attrs++ = wrap(A); +} + LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, unsigned KindID) { @@ -2216,6 +2229,21 @@ void LLVMAddCallSiteAttribute(LLVMValueR CallSite(unwrap<Instruction>(C)).addAttribute(Idx, unwrap(A)); } +unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, + LLVMAttributeIndex Idx) { + auto CS = CallSite(unwrap<Instruction>(C)); + auto *ASN = AttributeSetNode::get(CS.getAttributes(), Idx); + return ASN->getNumAttributes(); +} + +void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx, + LLVMAttributeRef *Attrs) { + auto CS = CallSite(unwrap<Instruction>(C)); + auto *ASN = AttributeSetNode::get(CS.getAttributes(), Idx); + for (auto A: make_range(ASN->begin(), ASN->end())) + *Attrs++ = wrap(A); +} + LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID) { _______________________________________________ llvm-branch-commits mailing list [email protected] http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
