LCOV - code coverage report
Current view: top level - lib/IR - AttributeSetNode.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 17 17 100.0 %
Date: 2017-04-11 06:33:34 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- AttributeSetNode.h - AttributeList Internal Node ---------*- C++
       2             : //-*-===//
       3             : //
       4             : //                     The LLVM Compiler Infrastructure
       5             : //
       6             : // This file is distributed under the University of Illinois Open Source
       7             : // License. See LICENSE.TXT for details.
       8             : //
       9             : //===----------------------------------------------------------------------===//
      10             : ///
      11             : /// \file
      12             : /// \brief This file defines the node class used internally by AttributeList.
      13             : ///
      14             : //===----------------------------------------------------------------------===//
      15             : 
      16             : #ifndef LLVM_IR_ATTRIBUTESETNODE_H
      17             : #define LLVM_IR_ATTRIBUTESETNODE_H
      18             : 
      19             : #include "llvm/ADT/ArrayRef.h"
      20             : #include "llvm/ADT/FoldingSet.h"
      21             : #include "llvm/ADT/Optional.h"
      22             : #include "llvm/ADT/StringRef.h"
      23             : #include "llvm/IR/Attributes.h"
      24             : #include "llvm/Support/TrailingObjects.h"
      25             : #include <algorithm>
      26             : #include <climits>
      27             : #include <cstdint>
      28             : #include <string>
      29             : #include <utility>
      30             : 
      31             : namespace llvm {
      32             : 
      33             : //===----------------------------------------------------------------------===//
      34             : /// \class
      35             : /// \brief This class represents a group of attributes that apply to one
      36             : /// element: function, return type, or parameter.
      37             : class AttributeSetNode final
      38             :     : public FoldingSetNode,
      39             :       private TrailingObjects<AttributeSetNode, Attribute> {
      40             :   friend TrailingObjects;
      41             : 
      42             :   unsigned NumAttrs; ///< Number of attributes in this node.
      43             :   /// Bitset with a bit for each available attribute Attribute::AttrKind.
      44             :   uint64_t AvailableAttrs;
      45             : 
      46      104671 :   AttributeSetNode(ArrayRef<Attribute> Attrs)
      47      314013 :     : NumAttrs(Attrs.size()), AvailableAttrs(0) {
      48             :     static_assert(Attribute::EndAttrKinds <= sizeof(AvailableAttrs) * CHAR_BIT,
      49             :                   "Too many attributes for AvailableAttrs");
      50             :     // There's memory after the node where we can store the entries in.
      51      314013 :     std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>());
      52             : 
      53      776087 :     for (Attribute I : *this) {
      54      462074 :       if (!I.isStringAttribute()) {
      55      129492 :         AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum();
      56             :       }
      57             :     }
      58      104671 :   }
      59             : 
      60             : public:
      61             :   // AttributesSetNode is uniqued, these should not be available.
      62             :   AttributeSetNode(const AttributeSetNode &) = delete;
      63             :   AttributeSetNode &operator=(const AttributeSetNode &) = delete;
      64             : 
      65       97939 :   void operator delete(void *p) { ::operator delete(p); }
      66             : 
      67             :   static AttributeSetNode *get(LLVMContext &C, ArrayRef<Attribute> Attrs);
      68             : 
      69             :   static AttributeSetNode *get(AttributeList AS, unsigned Index) {
      70           8 :     return AS.getAttributes(Index);
      71             :   }
      72             : 
      73             :   /// \brief Return the number of attributes this AttributeList contains.
      74             :   unsigned getNumAttributes() const { return NumAttrs; }
      75             : 
      76             :   bool hasAttribute(Attribute::AttrKind Kind) const {
      77   155602459 :     return AvailableAttrs & ((uint64_t)1) << Kind;
      78             :   }
      79             :   bool hasAttribute(StringRef Kind) const;
      80             :   bool hasAttributes() const { return NumAttrs != 0; }
      81             : 
      82             :   Attribute getAttribute(Attribute::AttrKind Kind) const;
      83             :   Attribute getAttribute(StringRef Kind) const;
      84             : 
      85             :   unsigned getAlignment() const;
      86             :   unsigned getStackAlignment() const;
      87             :   uint64_t getDereferenceableBytes() const;
      88             :   uint64_t getDereferenceableOrNullBytes() const;
      89             :   std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
      90             :   std::string getAsString(bool InAttrGrp) const;
      91             : 
      92             :   typedef const Attribute *iterator;
      93    56243133 :   iterator begin() const { return getTrailingObjects<Attribute>(); }
      94    28041155 :   iterator end() const { return begin() + NumAttrs; }
      95             : 
      96     1856304 :   void Profile(FoldingSetNodeID &ID) const {
      97     7425216 :     Profile(ID, makeArrayRef(begin(), end()));
      98     1856304 :   }
      99             :   static void Profile(FoldingSetNodeID &ID, ArrayRef<Attribute> AttrList) {
     100    11767370 :     for (const auto &Attr : AttrList)
     101     8054762 :       Attr.Profile(ID);
     102             :   }
     103             : };
     104             : 
     105             : } // end namespace llvm
     106             : 
     107             : #endif // LLVM_IR_ATTRIBUTESETNODE_H

Generated by: LCOV version 1.13