LLVM  4.0.0
AttributeSetNode.h
Go to the documentation of this file.
1 //===-- AttributeSetNode.h - AttributeSet Internal Node ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief This file defines the node class used internally by AttributeSet.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_IR_ATTRIBUTESETNODE_H
16 #define LLVM_IR_ATTRIBUTESETNODE_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/FoldingSet.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/IR/Attributes.h"
24 #include <algorithm>
25 #include <climits>
26 #include <cstdint>
27 #include <string>
28 #include <utility>
29 
30 namespace llvm {
31 
32 //===----------------------------------------------------------------------===//
33 /// \class
34 /// \brief This class represents a group of attributes that apply to one
35 /// element: function, return type, or parameter.
36 class AttributeSetNode final
37  : public FoldingSetNode,
38  private TrailingObjects<AttributeSetNode, Attribute> {
39  friend TrailingObjects;
40 
41  unsigned NumAttrs; ///< Number of attributes in this node.
42  /// Bitset with a bit for each available attribute Attribute::AttrKind.
43  uint64_t AvailableAttrs;
44 
46  : NumAttrs(Attrs.size()), AvailableAttrs(0) {
47  static_assert(Attribute::EndAttrKinds <= sizeof(AvailableAttrs) * CHAR_BIT,
48  "Too many attributes for AvailableAttrs");
49  // There's memory after the node where we can store the entries in.
50  std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>());
51 
52  for (Attribute I : *this) {
53  if (!I.isStringAttribute()) {
54  AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum();
55  }
56  }
57  }
58 
59 public:
60  // AttributesSetNode is uniqued, these should not be available.
61  AttributeSetNode(const AttributeSetNode &) = delete;
62  AttributeSetNode &operator=(const AttributeSetNode &) = delete;
63 
64  void operator delete(void *p) { ::operator delete(p); }
65 
67 
68  static AttributeSetNode *get(AttributeSet AS, unsigned Index) {
69  return AS.getAttributes(Index);
70  }
71 
72  /// \brief Return the number of attributes this AttributeSet contains.
73  unsigned getNumAttributes() const { return NumAttrs; }
74 
76  return AvailableAttrs & ((uint64_t)1) << Kind;
77  }
78  bool hasAttribute(StringRef Kind) const;
79  bool hasAttributes() const { return NumAttrs != 0; }
80 
83 
84  unsigned getAlignment() const;
85  unsigned getStackAlignment() const;
86  uint64_t getDereferenceableBytes() const;
87  uint64_t getDereferenceableOrNullBytes() const;
88  std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
89  std::string getAsString(bool InAttrGrp) const;
90 
91  typedef const Attribute *iterator;
92  iterator begin() const { return getTrailingObjects<Attribute>(); }
93  iterator end() const { return begin() + NumAttrs; }
94 
95  void Profile(FoldingSetNodeID &ID) const {
96  Profile(ID, makeArrayRef(begin(), end()));
97  }
98  static void Profile(FoldingSetNodeID &ID, ArrayRef<Attribute> AttrList) {
99  for (const auto &Attr : AttrList)
100  Attr.Profile(ID);
101  }
102 };
103 
104 } // end namespace llvm
105 
106 #endif // LLVM_IR_ATTRIBUTESETNODE_H
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Definition: Attributes.cpp:563
uint64_t getDereferenceableBytes() const
Definition: Attributes.cpp:548
AttributeSetNode & operator=(const AttributeSetNode &)=delete
std::string getAsString(bool InAttrGrp) const
Definition: Attributes.cpp:570
iterator begin() const
iterator end() const
Definition: ArrayRef.h:130
iterator end() const
static void Profile(FoldingSetNodeID &ID, ArrayRef< Attribute > AttrList)
bool hasAttributes() const
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:440
This file contains the simple types necessary to represent the attributes associated with functions a...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:141
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:316
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
unsigned getAlignment() const
Definition: Attributes.cpp:534
See the file comment for details on the usage of the TrailingObjects type.
iterator begin() const
Definition: ArrayRef.h:129
Sentinal value useful for loops.
Definition: Attributes.h:72
bool hasAttribute(Attribute::AttrKind Kind) const
Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
Definition: Attributes.cpp:157
const Attribute * iterator
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
Node - This class is used to maintain the singly linked bucket list in a folding set.
Definition: FoldingSet.h:139
unsigned getNumAttributes() const
Return the number of attributes this AttributeSet contains.
unsigned getStackAlignment() const
Definition: Attributes.cpp:541
#define I(x, y, z)
Definition: MD5.cpp:54
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:153
uint64_t getDereferenceableOrNullBytes() const
Definition: Attributes.cpp:555
const unsigned Kind
void Profile(FoldingSetNodeID &ID) const
This header defines support for implementing classes that have some trailing object (or arrays of obj...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
Attribute getAttribute(Attribute::AttrKind Kind) const
Definition: Attributes.cpp:518
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:67