Pārlūkot izejas kodu

Extend function attributes bitset size from 64 to 96.

Summary: We are going to add a function attribute number 64.

Reviewers: pcc, jdoerfert, lebedev.ri

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D64663

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365980 91177308-0d34-0410-b5e6-96231b3b80d8
Evgeniy Stepanov 6 gadi atpakaļ
vecāks
revīzija
e88e617b46
2 mainītis faili ar 18 papildinājumiem un 11 dzēšanām
  1. 6 6
      lib/IR/AttributeImpl.h
  2. 12 5
      lib/IR/Attributes.cpp

+ 6 - 6
lib/IR/AttributeImpl.h

@@ -179,9 +179,9 @@ class AttributeSetNode final
       private TrailingObjects<AttributeSetNode, Attribute> {
       private TrailingObjects<AttributeSetNode, Attribute> {
   friend TrailingObjects;
   friend TrailingObjects;
 
 
-  /// Bitset with a bit for each available attribute Attribute::AttrKind.
-  uint64_t AvailableAttrs;
   unsigned NumAttrs; ///< Number of attributes in this node.
   unsigned NumAttrs; ///< Number of attributes in this node.
+  /// Bitset with a bit for each available attribute Attribute::AttrKind.
+  uint8_t AvailableAttrs[12] = {};
 
 
   AttributeSetNode(ArrayRef<Attribute> Attrs);
   AttributeSetNode(ArrayRef<Attribute> Attrs);
 
 
@@ -200,7 +200,7 @@ public:
   unsigned getNumAttributes() const { return NumAttrs; }
   unsigned getNumAttributes() const { return NumAttrs; }
 
 
   bool hasAttribute(Attribute::AttrKind Kind) const {
   bool hasAttribute(Attribute::AttrKind Kind) const {
-    return AvailableAttrs & ((uint64_t)1) << Kind;
+    return AvailableAttrs[Kind / 8] & ((uint64_t)1) << (Kind % 8);
   }
   }
   bool hasAttribute(StringRef Kind) const;
   bool hasAttribute(StringRef Kind) const;
   bool hasAttributes() const { return NumAttrs != 0; }
   bool hasAttributes() const { return NumAttrs != 0; }
@@ -244,10 +244,10 @@ class AttributeListImpl final
   friend TrailingObjects;
   friend TrailingObjects;
 
 
 private:
 private:
-  /// Bitset with a bit for each available attribute Attribute::AttrKind.
-  uint64_t AvailableFunctionAttrs;
   LLVMContext &Context;
   LLVMContext &Context;
   unsigned NumAttrSets; ///< Number of entries in this set.
   unsigned NumAttrSets; ///< Number of entries in this set.
+  /// Bitset with a bit for each available attribute Attribute::AttrKind.
+  uint8_t AvailableFunctionAttrs[12] = {};
 
 
   // Helper fn for TrailingObjects class.
   // Helper fn for TrailingObjects class.
   size_t numTrailingObjects(OverloadToken<AttributeSet>) { return NumAttrSets; }
   size_t numTrailingObjects(OverloadToken<AttributeSet>) { return NumAttrSets; }
@@ -267,7 +267,7 @@ public:
   /// Return true if the AttributeSet or the FunctionIndex has an
   /// Return true if the AttributeSet or the FunctionIndex has an
   /// enum attribute of the given kind.
   /// enum attribute of the given kind.
   bool hasFnAttribute(Attribute::AttrKind Kind) const {
   bool hasFnAttribute(Attribute::AttrKind Kind) const {
-    return AvailableFunctionAttrs & ((uint64_t)1) << Kind;
+    return AvailableFunctionAttrs[Kind / 8] & ((uint64_t)1) << (Kind % 8);
   }
   }
 
 
   using iterator = const AttributeSet *;
   using iterator = const AttributeSet *;

+ 12 - 5
lib/IR/Attributes.cpp

@@ -718,13 +718,18 @@ LLVM_DUMP_METHOD void AttributeSet::dump() const {
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
 
 
 AttributeSetNode::AttributeSetNode(ArrayRef<Attribute> Attrs)
 AttributeSetNode::AttributeSetNode(ArrayRef<Attribute> Attrs)
-    : AvailableAttrs(0), NumAttrs(Attrs.size()) {
+    : NumAttrs(Attrs.size()) {
   // There's memory after the node where we can store the entries in.
   // There's memory after the node where we can store the entries in.
   llvm::copy(Attrs, getTrailingObjects<Attribute>());
   llvm::copy(Attrs, getTrailingObjects<Attribute>());
 
 
+  static_assert(Attribute::EndAttrKinds <=
+                    sizeof(AvailableAttrs) * CHAR_BIT,
+                "Too many attributes");
+
   for (const auto I : *this) {
   for (const auto I : *this) {
     if (!I.isStringAttribute()) {
     if (!I.isStringAttribute()) {
-      AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum();
+      Attribute::AttrKind Kind = I.getKindAsEnum();
+      AvailableAttrs[Kind / 8] |= 1ULL << (Kind % 8);
     }
     }
   }
   }
 }
 }
@@ -896,7 +901,7 @@ static constexpr unsigned attrIdxToArrayIdx(unsigned Index) {
 
 
 AttributeListImpl::AttributeListImpl(LLVMContext &C,
 AttributeListImpl::AttributeListImpl(LLVMContext &C,
                                      ArrayRef<AttributeSet> Sets)
                                      ArrayRef<AttributeSet> Sets)
-    : AvailableFunctionAttrs(0), Context(C), NumAttrSets(Sets.size()) {
+    : Context(C), NumAttrSets(Sets.size()) {
   assert(!Sets.empty() && "pointless AttributeListImpl");
   assert(!Sets.empty() && "pointless AttributeListImpl");
 
 
   // There's memory after the node where we can store the entries in.
   // There's memory after the node where we can store the entries in.
@@ -909,8 +914,10 @@ AttributeListImpl::AttributeListImpl(LLVMContext &C,
   static_assert(attrIdxToArrayIdx(AttributeList::FunctionIndex) == 0U,
   static_assert(attrIdxToArrayIdx(AttributeList::FunctionIndex) == 0U,
                 "function should be stored in slot 0");
                 "function should be stored in slot 0");
   for (const auto I : Sets[0]) {
   for (const auto I : Sets[0]) {
-    if (!I.isStringAttribute())
-      AvailableFunctionAttrs |= 1ULL << I.getKindAsEnum();
+    if (!I.isStringAttribute()) {
+      Attribute::AttrKind Kind = I.getKindAsEnum();
+      AvailableFunctionAttrs[Kind / 8] |= 1ULL << (Kind % 8);
+    }
   }
   }
 }
 }