Coverage Report

Created: 2017-04-11 02:14

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/IR/AttributeSetNode.h
Line
Count
Source (jump to first uncovered line)
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
  AttributeSetNode(ArrayRef<Attribute> Attrs)
47
407k
    : NumAttrs(Attrs.size()), AvailableAttrs(0) {
48
407k
    static_assert(Attribute::EndAttrKinds <= sizeof(AvailableAttrs) * CHAR_BIT,
49
407k
                  "Too many attributes for AvailableAttrs");
50
407k
    // There's memory after the node where we can store the entries in.
51
407k
    std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>());
52
407k
53
1.97M
    for (Attribute I : *this) {
54
1.97M
      if (
!I.isStringAttribute()1.97M
)
{606k
55
606k
        AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum();
56
606k
      }
57
1.97M
    }
58
407k
  }
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
97.6k
  void operator delete(void *p) { ::operator delete(p); }
66
67
  static AttributeSetNode *get(LLVMContext &C, ArrayRef<Attribute> Attrs);
68
69
8
  static AttributeSetNode *get(AttributeList AS, unsigned Index) {
70
8
    return AS.getAttributes(Index);
71
8
  }
72
73
  /// \brief Return the number of attributes this AttributeList contains.
74
0
  unsigned getNumAttributes() const { return NumAttrs; }
75
76
1.24G
  bool hasAttribute(Attribute::AttrKind Kind) const {
77
1.24G
    return AvailableAttrs & ((uint64_t)1) << Kind;
78
1.24G
  }
79
  bool hasAttribute(StringRef Kind) const;
80
2.18M
  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
729M
  iterator begin() const { return getTrailingObjects<Attribute>(); }
94
364M
  iterator end() const { return begin() + NumAttrs; }
95
96
6.52M
  void Profile(FoldingSetNodeID &ID) const {
97
6.52M
    Profile(ID, makeArrayRef(begin(), end()));
98
6.52M
  }
99
6.52M
  static void Profile(FoldingSetNodeID &ID, ArrayRef<Attribute> AttrList) {
100
6.52M
    for (const auto &Attr : AttrList)
101
23.7M
      Attr.Profile(ID);
102
6.52M
  }
103
};
104
105
} // end namespace llvm
106
107
#endif // LLVM_IR_ATTRIBUTESETNODE_H