annotate lib/IR/AttributeImpl.h @ 121:803732b1fca8

LLVM 5.0
author kono
date Fri, 27 Oct 2017 17:07:41 +0900
parents 1172e4bd9c6f
children c2174574ed3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1 //===- AttributeImpl.h - Attribute Internals --------------------*- C++ -*-===//
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 ///
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 /// \file
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 /// \brief This file defines various helper methods and classes used by
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 /// LLVMContextImpl for creating and managing attributes.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 ///
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
16 #ifndef LLVM_LIB_IR_ATTRIBUTEIMPL_H
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
17 #define LLVM_LIB_IR_ATTRIBUTEIMPL_H
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
19 #include "llvm/ADT/ArrayRef.h"
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #include "llvm/ADT/FoldingSet.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
21 #include "llvm/ADT/StringRef.h"
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "llvm/IR/Attributes.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
23 #include "llvm/Support/TrailingObjects.h"
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
24 #include <cassert>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
25 #include <cstddef>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
26 #include <cstdint>
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include <string>
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
28 #include <utility>
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 namespace llvm {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 class LLVMContext;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 /// \class
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 /// \brief This class represents a single, uniqued attribute. That attribute
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 /// could be a single enum, a tuple, or a string.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 class AttributeImpl : public FoldingSetNode {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 unsigned char KindID; ///< Holds the AttrEntryKind of the attribute
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 protected:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 enum AttrEntryKind {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 EnumAttrEntry,
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
44 IntAttrEntry,
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 StringAttrEntry
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 AttributeImpl(AttrEntryKind KindID) : KindID(KindID) {}
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 public:
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
51 // AttributesImpl is uniqued, these should not be available.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
52 AttributeImpl(const AttributeImpl &) = delete;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
53 AttributeImpl &operator=(const AttributeImpl &) = delete;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
54
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 virtual ~AttributeImpl();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 bool isEnumAttribute() const { return KindID == EnumAttrEntry; }
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
58 bool isIntAttribute() const { return KindID == IntAttrEntry; }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 bool isStringAttribute() const { return KindID == StringAttrEntry; }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 bool hasAttribute(Attribute::AttrKind A) const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 bool hasAttribute(StringRef Kind) const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 Attribute::AttrKind getKindAsEnum() const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 uint64_t getValueAsInt() const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 StringRef getKindAsString() const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 StringRef getValueAsString() const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 /// \brief Used when sorting the attributes.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 bool operator<(const AttributeImpl &AI) const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 void Profile(FoldingSetNodeID &ID) const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 if (isEnumAttribute())
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 Profile(ID, getKindAsEnum(), 0);
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
76 else if (isIntAttribute())
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 Profile(ID, getKindAsEnum(), getValueAsInt());
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 else
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 Profile(ID, getKindAsString(), getValueAsString());
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 }
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
81
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 static void Profile(FoldingSetNodeID &ID, Attribute::AttrKind Kind,
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 uint64_t Val) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 ID.AddInteger(Kind);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 if (Val) ID.AddInteger(Val);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 }
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
87
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 static void Profile(FoldingSetNodeID &ID, StringRef Kind, StringRef Values) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 ID.AddString(Kind);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 if (!Values.empty()) ID.AddString(Values);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 /// \class
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 /// \brief A set of classes that contain the value of the
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 /// attribute object. There are three main categories: enum attribute entries,
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 /// represented by Attribute::AttrKind; alignment attribute entries; and string
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 /// attribute enties, which are for target-dependent attributes.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 class EnumAttributeImpl : public AttributeImpl {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 virtual void anchor();
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
103
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 Attribute::AttrKind Kind;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 protected:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 EnumAttributeImpl(AttrEntryKind ID, Attribute::AttrKind Kind)
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 : AttributeImpl(ID), Kind(Kind) {}
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 public:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 EnumAttributeImpl(Attribute::AttrKind Kind)
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 : AttributeImpl(EnumAttrEntry), Kind(Kind) {}
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 Attribute::AttrKind getEnumKind() const { return Kind; }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
117 class IntAttributeImpl : public EnumAttributeImpl {
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
118 uint64_t Val;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
119
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
120 void anchor() override;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 public:
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
123 IntAttributeImpl(Attribute::AttrKind Kind, uint64_t Val)
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
124 : EnumAttributeImpl(IntAttrEntry, Kind), Val(Val) {
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
125 assert((Kind == Attribute::Alignment || Kind == Attribute::StackAlignment ||
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
126 Kind == Attribute::Dereferenceable ||
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
127 Kind == Attribute::DereferenceableOrNull ||
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
128 Kind == Attribute::AllocSize) &&
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
129 "Wrong kind for int attribute!");
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
132 uint64_t getValue() const { return Val; }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 class StringAttributeImpl : public AttributeImpl {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 virtual void anchor();
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
137
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 std::string Kind;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 std::string Val;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 public:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 StringAttributeImpl(StringRef Kind, StringRef Val = StringRef())
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 : AttributeImpl(StringAttrEntry), Kind(Kind), Val(Val) {}
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 StringRef getStringKind() const { return Kind; }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 StringRef getStringValue() const { return Val; }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
149 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
150 /// \class
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
151 /// \brief This class represents a group of attributes that apply to one
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
152 /// element: function, return type, or parameter.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
153 class AttributeSetNode final
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
154 : public FoldingSetNode,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
155 private TrailingObjects<AttributeSetNode, Attribute> {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
156 friend TrailingObjects;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
157
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
158 /// Bitset with a bit for each available attribute Attribute::AttrKind.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
159 uint64_t AvailableAttrs;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
160 unsigned NumAttrs; ///< Number of attributes in this node.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
161
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
162 AttributeSetNode(ArrayRef<Attribute> Attrs);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
163
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
164 public:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
165 // AttributesSetNode is uniqued, these should not be available.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
166 AttributeSetNode(const AttributeSetNode &) = delete;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
167 AttributeSetNode &operator=(const AttributeSetNode &) = delete;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
168
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
169 void operator delete(void *p) { ::operator delete(p); }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
170
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
171 static AttributeSetNode *get(LLVMContext &C, const AttrBuilder &B);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
172
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
173 static AttributeSetNode *get(LLVMContext &C, ArrayRef<Attribute> Attrs);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
174
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
175 /// \brief Return the number of attributes this AttributeList contains.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
176 unsigned getNumAttributes() const { return NumAttrs; }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
177
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
178 bool hasAttribute(Attribute::AttrKind Kind) const {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
179 return AvailableAttrs & ((uint64_t)1) << Kind;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
180 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
181 bool hasAttribute(StringRef Kind) const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
182 bool hasAttributes() const { return NumAttrs != 0; }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
183
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
184 Attribute getAttribute(Attribute::AttrKind Kind) const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
185 Attribute getAttribute(StringRef Kind) const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
186
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
187 unsigned getAlignment() const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
188 unsigned getStackAlignment() const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
189 uint64_t getDereferenceableBytes() const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
190 uint64_t getDereferenceableOrNullBytes() const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
191 std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
192 std::string getAsString(bool InAttrGrp) const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
193
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
194 using iterator = const Attribute *;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
195
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
196 iterator begin() const { return getTrailingObjects<Attribute>(); }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
197 iterator end() const { return begin() + NumAttrs; }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
198
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
199 void Profile(FoldingSetNodeID &ID) const {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
200 Profile(ID, makeArrayRef(begin(), end()));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
201 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
202
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
203 static void Profile(FoldingSetNodeID &ID, ArrayRef<Attribute> AttrList) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
204 for (const auto &Attr : AttrList)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
205 Attr.Profile(ID);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
206 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
207 };
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
208
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
209 using IndexAttrPair = std::pair<unsigned, AttributeSet>;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
210
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 /// \class
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 /// \brief This class represents a set of attributes that apply to the function,
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 /// return type, and parameters.
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
215 class AttributeListImpl final
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
216 : public FoldingSetNode,
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
217 private TrailingObjects<AttributeListImpl, AttributeSet> {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
218 friend class AttributeList;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
219 friend TrailingObjects;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
221 private:
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
222 /// Bitset with a bit for each available attribute Attribute::AttrKind.
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
223 uint64_t AvailableFunctionAttrs;
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
224 LLVMContext &Context;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
225 unsigned NumAttrSets; ///< Number of entries in this set.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
227 // Helper fn for TrailingObjects class.
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
228 size_t numTrailingObjects(OverloadToken<AttributeSet>) { return NumAttrSets; }
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
229
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
230 public:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
231 AttributeListImpl(LLVMContext &C, ArrayRef<AttributeSet> Sets);
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
232
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
233 // AttributesSetImpt is uniqued, these should not be available.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
234 AttributeListImpl(const AttributeListImpl &) = delete;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
235 AttributeListImpl &operator=(const AttributeListImpl &) = delete;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
237 void operator delete(void *p) { ::operator delete(p); }
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
238
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
239 /// \brief Get the context that created this AttributeListImpl.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 LLVMContext &getContext() { return Context; }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
242 /// \brief Return true if the AttributeSet or the FunctionIndex has an
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
243 /// enum attribute of the given kind.
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
244 bool hasFnAttribute(Attribute::AttrKind Kind) const {
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
245 return AvailableFunctionAttrs & ((uint64_t)1) << Kind;
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
246 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
247
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
248 using iterator = const AttributeSet *;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
250 iterator begin() const { return getTrailingObjects<AttributeSet>(); }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
251 iterator end() const { return begin() + NumAttrSets; }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
252
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
253 void Profile(FoldingSetNodeID &ID) const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
254 static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeSet> Nodes);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 void dump() const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
259 } // end namespace llvm
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
261 #endif // LLVM_LIB_IR_ATTRIBUTEIMPL_H