Deleted Added
full compact
AttributeImpl.h (256281) AttributeImpl.h (263508)
1//===-- AttributeImpl.h - Attribute Internals -------------------*- 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//===----------------------------------------------------------------------===//

--- 13 unchanged lines hidden (view full) ---

22
23namespace llvm {
24
25class Constant;
26class LLVMContext;
27
28//===----------------------------------------------------------------------===//
29/// \class
1//===-- AttributeImpl.h - Attribute Internals -------------------*- 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//===----------------------------------------------------------------------===//

--- 13 unchanged lines hidden (view full) ---

22
23namespace llvm {
24
25class Constant;
26class LLVMContext;
27
28//===----------------------------------------------------------------------===//
29/// \class
30/// \brief A set of classes that contain the kind and (optional) value of the
31/// attribute object. There are three main categories: enum attribute entries,
32/// represented by Attribute::AttrKind; alignment attribute entries; and string
33/// attribute enties, which are for target-dependent attributes.
34class AttributeEntry {
35 unsigned char KindID;
30/// \brief This class represents a single, uniqued attribute. That attribute
31/// could be a single enum, a tuple, or a string.
32class AttributeImpl : public FoldingSetNode {
33 unsigned char KindID; ///< Holds the AttrEntryKind of the attribute
34
35 // AttributesImpl is uniqued, these should not be publicly available.
36 void operator=(const AttributeImpl &) LLVM_DELETED_FUNCTION;
37 AttributeImpl(const AttributeImpl &) LLVM_DELETED_FUNCTION;
38
36protected:
37 enum AttrEntryKind {
38 EnumAttrEntry,
39 AlignAttrEntry,
40 StringAttrEntry
41 };
39protected:
40 enum AttrEntryKind {
41 EnumAttrEntry,
42 AlignAttrEntry,
43 StringAttrEntry
44 };
42public:
43 AttributeEntry(AttrEntryKind Kind)
44 : KindID(Kind) {}
45 virtual ~AttributeEntry() {}
46
45
47 unsigned getKindID() const { return KindID; }
46 AttributeImpl(AttrEntryKind KindID) : KindID(KindID) {}
48
47
49 static inline bool classof(const AttributeEntry *) { return true; }
50};
51
52class EnumAttributeEntry : public AttributeEntry {
53 Attribute::AttrKind Kind;
54public:
48public:
55 EnumAttributeEntry(Attribute::AttrKind Kind)
56 : AttributeEntry(EnumAttrEntry), Kind(Kind) {}
49 virtual ~AttributeImpl();
57
50
58 Attribute::AttrKind getEnumKind() const { return Kind; }
51 bool isEnumAttribute() const { return KindID == EnumAttrEntry; }
52 bool isAlignAttribute() const { return KindID == AlignAttrEntry; }
53 bool isStringAttribute() const { return KindID == StringAttrEntry; }
59
54
60 static inline bool classof(const AttributeEntry *AE) {
61 return AE->getKindID() == EnumAttrEntry;
62 }
63 static inline bool classof(const EnumAttributeEntry *) { return true; }
64};
65
66class AlignAttributeEntry : public AttributeEntry {
67 Attribute::AttrKind Kind;
68 unsigned Align;
69public:
70 AlignAttributeEntry(Attribute::AttrKind Kind, unsigned Align)
71 : AttributeEntry(AlignAttrEntry), Kind(Kind), Align(Align) {}
72
73 Attribute::AttrKind getEnumKind() const { return Kind; }
74 unsigned getAlignment() const { return Align; }
75
76 static inline bool classof(const AttributeEntry *AE) {
77 return AE->getKindID() == AlignAttrEntry;
78 }
79 static inline bool classof(const AlignAttributeEntry *) { return true; }
80};
81
82class StringAttributeEntry : public AttributeEntry {
83 std::string Kind;
84 std::string Val;
85public:
86 StringAttributeEntry(StringRef Kind, StringRef Val = StringRef())
87 : AttributeEntry(StringAttrEntry), Kind(Kind), Val(Val) {}
88
89 StringRef getStringKind() const { return Kind; }
90 StringRef getStringValue() const { return Val; }
91
92 static inline bool classof(const AttributeEntry *AE) {
93 return AE->getKindID() == StringAttrEntry;
94 }
95 static inline bool classof(const StringAttributeEntry *) { return true; }
96};
97
98//===----------------------------------------------------------------------===//
99/// \class
100/// \brief This class represents a single, uniqued attribute. That attribute
101/// could be a single enum, a tuple, or a string.
102class AttributeImpl : public FoldingSetNode {
103 LLVMContext &Context; ///< Global context for uniquing objects
104
105 AttributeEntry *Entry; ///< Holds the kind and value of the attribute
106
107 // AttributesImpl is uniqued, these should not be publicly available.
108 void operator=(const AttributeImpl &) LLVM_DELETED_FUNCTION;
109 AttributeImpl(const AttributeImpl &) LLVM_DELETED_FUNCTION;
110public:
111 AttributeImpl(LLVMContext &C, Attribute::AttrKind Kind);
112 AttributeImpl(LLVMContext &C, Attribute::AttrKind Kind, unsigned Align);
113 AttributeImpl(LLVMContext &C, StringRef Kind, StringRef Val = StringRef());
114 ~AttributeImpl();
115
116 LLVMContext &getContext() { return Context; }
117
118 bool isEnumAttribute() const;
119 bool isAlignAttribute() const;
120 bool isStringAttribute() const;
121
122 bool hasAttribute(Attribute::AttrKind A) const;
123 bool hasAttribute(StringRef Kind) const;
124
125 Attribute::AttrKind getKindAsEnum() const;
126 uint64_t getValueAsInt() const;
127
128 StringRef getKindAsString() const;
129 StringRef getValueAsString() const;

--- 20 unchanged lines hidden (view full) ---

150 }
151
152 // FIXME: Remove this!
153 static uint64_t getAttrMask(Attribute::AttrKind Val);
154};
155
156//===----------------------------------------------------------------------===//
157/// \class
55 bool hasAttribute(Attribute::AttrKind A) const;
56 bool hasAttribute(StringRef Kind) const;
57
58 Attribute::AttrKind getKindAsEnum() const;
59 uint64_t getValueAsInt() const;
60
61 StringRef getKindAsString() const;
62 StringRef getValueAsString() const;

--- 20 unchanged lines hidden (view full) ---

83 }
84
85 // FIXME: Remove this!
86 static uint64_t getAttrMask(Attribute::AttrKind Val);
87};
88
89//===----------------------------------------------------------------------===//
90/// \class
91/// \brief A set of classes that contain the value of the
92/// attribute object. There are three main categories: enum attribute entries,
93/// represented by Attribute::AttrKind; alignment attribute entries; and string
94/// attribute enties, which are for target-dependent attributes.
95
96class EnumAttributeImpl : public AttributeImpl {
97 virtual void anchor();
98 Attribute::AttrKind Kind;
99
100protected:
101 EnumAttributeImpl(AttrEntryKind ID, Attribute::AttrKind Kind)
102 : AttributeImpl(ID), Kind(Kind) {}
103
104public:
105 EnumAttributeImpl(Attribute::AttrKind Kind)
106 : AttributeImpl(EnumAttrEntry), Kind(Kind) {}
107
108 Attribute::AttrKind getEnumKind() const { return Kind; }
109};
110
111class AlignAttributeImpl : public EnumAttributeImpl {
112 virtual void anchor();
113 unsigned Align;
114
115public:
116 AlignAttributeImpl(Attribute::AttrKind Kind, unsigned Align)
117 : EnumAttributeImpl(AlignAttrEntry, Kind), Align(Align) {
118 assert(
119 (Kind == Attribute::Alignment || Kind == Attribute::StackAlignment) &&
120 "Wrong kind for alignment attribute!");
121 }
122
123 unsigned getAlignment() const { return Align; }
124};
125
126class StringAttributeImpl : public AttributeImpl {
127 virtual void anchor();
128 std::string Kind;
129 std::string Val;
130
131public:
132 StringAttributeImpl(StringRef Kind, StringRef Val = StringRef())
133 : AttributeImpl(StringAttrEntry), Kind(Kind), Val(Val) {}
134
135 StringRef getStringKind() const { return Kind; }
136 StringRef getStringValue() const { return Val; }
137};
138
139//===----------------------------------------------------------------------===//
140/// \class
158/// \brief This class represents a group of attributes that apply to one
159/// element: function, return type, or parameter.
160class AttributeSetNode : public FoldingSetNode {
141/// \brief This class represents a group of attributes that apply to one
142/// element: function, return type, or parameter.
143class AttributeSetNode : public FoldingSetNode {
161 SmallVector<Attribute, 4> AttrList;
144 unsigned NumAttrs; ///< Number of attributes in this node.
162
145
163 AttributeSetNode(ArrayRef Attrs)
164 : AttrList(Attrs.begin(), Attrs.end()) {}
146 AttributeSetNode(ArrayRef<Attribute> Attrs) : NumAttrs(Attrs.size()) {
147 // There's memory after the node where we can store the entries in.
148 std::copy(Attrs.begin(), Attrs.end(),
149 reinterpret_cast<Attribute *>(this + 1));
150 }
165
166 // AttributesSetNode is uniqued, these should not be publicly available.
167 void operator=(const AttributeSetNode &) LLVM_DELETED_FUNCTION;
168 AttributeSetNode(const AttributeSetNode &) LLVM_DELETED_FUNCTION;
169public:
170 static AttributeSetNode *get(LLVMContext &C, ArrayRef<Attribute> Attrs);
171
172 bool hasAttribute(Attribute::AttrKind Kind) const;
173 bool hasAttribute(StringRef Kind) const;
151
152 // AttributesSetNode is uniqued, these should not be publicly available.
153 void operator=(const AttributeSetNode &) LLVM_DELETED_FUNCTION;
154 AttributeSetNode(const AttributeSetNode &) LLVM_DELETED_FUNCTION;
155public:
156 static AttributeSetNode *get(LLVMContext &C, ArrayRef<Attribute> Attrs);
157
158 bool hasAttribute(Attribute::AttrKind Kind) const;
159 bool hasAttribute(StringRef Kind) const;
174 bool hasAttributes() const { return !AttrList.empty(); }
160 bool hasAttributes() const { return NumAttrs != 0; }
175
176 Attribute getAttribute(Attribute::AttrKind Kind) const;
177 Attribute getAttribute(StringRef Kind) const;
178
179 unsigned getAlignment() const;
180 unsigned getStackAlignment() const;
181 std::string getAsString(bool InAttrGrp) const;
182
161
162 Attribute getAttribute(Attribute::AttrKind Kind) const;
163 Attribute getAttribute(StringRef Kind) const;
164
165 unsigned getAlignment() const;
166 unsigned getStackAlignment() const;
167 std::string getAsString(bool InAttrGrp) const;
168
183 typedef SmallVectorImpl<Attribute>::iterator iterator;
184 typedef SmallVectorImpl<Attribute>::const_iterator const_iterator;
169 typedef const Attribute *iterator;
170 iterator begin() const { return reinterpret_cast<iterator>(this + 1); }
171 iterator end() const { return begin() + NumAttrs; }
185
172
186 iterator begin() { return AttrList.begin(); }
187 iterator end() { return AttrList.end(); }
188
189 const_iterator begin() const { return AttrList.begin(); }
190 const_iterator end() const { return AttrList.end(); }
191
192 void Profile(FoldingSetNodeID &ID) const {
173 void Profile(FoldingSetNodeID &ID) const {
193 Profile(ID, AttrList);
174 Profile(ID, makeArrayRef(begin(), end()));
194 }
195 static void Profile(FoldingSetNodeID &ID, ArrayRef<Attribute> AttrList) {
196 for (unsigned I = 0, E = AttrList.size(); I != E; ++I)
197 AttrList[I].Profile(ID);
198 }
199};
200
201//===----------------------------------------------------------------------===//
202/// \class
203/// \brief This class represents a set of attributes that apply to the function,
204/// return type, and parameters.
205class AttributeSetImpl : public FoldingSetNode {
206 friend class AttributeSet;
207
208 LLVMContext &Context;
209
210 typedef std::pair<unsigned, AttributeSetNode*> IndexAttrPair;
175 }
176 static void Profile(FoldingSetNodeID &ID, ArrayRef<Attribute> AttrList) {
177 for (unsigned I = 0, E = AttrList.size(); I != E; ++I)
178 AttrList[I].Profile(ID);
179 }
180};
181
182//===----------------------------------------------------------------------===//
183/// \class
184/// \brief This class represents a set of attributes that apply to the function,
185/// return type, and parameters.
186class AttributeSetImpl : public FoldingSetNode {
187 friend class AttributeSet;
188
189 LLVMContext &Context;
190
191 typedef std::pair<unsigned, AttributeSetNode*> IndexAttrPair;
211 SmallVector<IndexAttrPair, 4> AttrNodes;
192 unsigned NumAttrs; ///< Number of entries in this set.
212
193
194 /// \brief Return a pointer to the IndexAttrPair for the specified slot.
195 const IndexAttrPair *getNode(unsigned Slot) const {
196 return reinterpret_cast<const IndexAttrPair *>(this + 1) + Slot;
197 }
198
213 // AttributesSet is uniqued, these should not be publicly available.
214 void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
215 AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
216public:
217 AttributeSetImpl(LLVMContext &C,
199 // AttributesSet is uniqued, these should not be publicly available.
200 void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
201 AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
202public:
203 AttributeSetImpl(LLVMContext &C,
218 ArrayRef<std::pair<unsigned, AttributeSetNode*> > attrs)
219 : Context(C), AttrNodes(attrs.begin(), attrs.end()) {}
204 ArrayRef<std::pair<unsigned, AttributeSetNode *> > Attrs)
205 : Context(C), NumAttrs(Attrs.size()) {
206#ifndef NDEBUG
207 if (Attrs.size() >= 2) {
208 for (const std::pair<unsigned, AttributeSetNode *> *i = Attrs.begin() + 1,
209 *e = Attrs.end();
210 i != e; ++i) {
211 assert((i-1)->first <= i->first && "Attribute set not ordered!");
212 }
213 }
214#endif
215 // There's memory after the node where we can store the entries in.
216 std::copy(Attrs.begin(), Attrs.end(),
217 reinterpret_cast<IndexAttrPair *>(this + 1));
218 }
220
221 /// \brief Get the context that created this AttributeSetImpl.
222 LLVMContext &getContext() { return Context; }
223
224 /// \brief Return the number of attributes this AttributeSet contains.
219
220 /// \brief Get the context that created this AttributeSetImpl.
221 LLVMContext &getContext() { return Context; }
222
223 /// \brief Return the number of attributes this AttributeSet contains.
225 unsigned getNumAttributes() const { return AttrNodes.size(); }
224 unsigned getNumAttributes() const { return NumAttrs; }
226
227 /// \brief Get the index of the given "slot" in the AttrNodes list. This index
228 /// is the index of the return, parameter, or function object that the
229 /// attributes are applied to, not the index into the AttrNodes list where the
230 /// attributes reside.
231 unsigned getSlotIndex(unsigned Slot) const {
225
226 /// \brief Get the index of the given "slot" in the AttrNodes list. This index
227 /// is the index of the return, parameter, or function object that the
228 /// attributes are applied to, not the index into the AttrNodes list where the
229 /// attributes reside.
230 unsigned getSlotIndex(unsigned Slot) const {
232 return AttrNodes[Slot].first;
231 return getNode(Slot)->first;
233 }
234
235 /// \brief Retrieve the attributes for the given "slot" in the AttrNode list.
236 /// \p Slot is an index into the AttrNodes list, not the index of the return /
237 /// parameter/ function which the attributes apply to.
238 AttributeSet getSlotAttributes(unsigned Slot) const {
232 }
233
234 /// \brief Retrieve the attributes for the given "slot" in the AttrNode list.
235 /// \p Slot is an index into the AttrNodes list, not the index of the return /
236 /// parameter/ function which the attributes apply to.
237 AttributeSet getSlotAttributes(unsigned Slot) const {
239 return AttributeSet::get(Context, AttrNodes[Slot]);
238 return AttributeSet::get(Context, *getNode(Slot));
240 }
241
242 /// \brief Retrieve the attribute set node for the given "slot" in the
243 /// AttrNode list.
244 AttributeSetNode *getSlotNode(unsigned Slot) const {
239 }
240
241 /// \brief Retrieve the attribute set node for the given "slot" in the
242 /// AttrNode list.
243 AttributeSetNode *getSlotNode(unsigned Slot) const {
245 return AttrNodes[Slot].second;
244 return getNode(Slot)->second;
246 }
247
245 }
246
248 typedef AttributeSetNode::iterator iterator;
249 typedef AttributeSetNode::const_iterator const_iterator;
247 typedef AttributeSetNode::iterator iterator;
248 iterator begin(unsigned Slot) const { return getSlotNode(Slot)->begin(); }
249 iterator end(unsigned Slot) const { return getSlotNode(Slot)->end(); }
250
250
251 iterator begin(unsigned Slot)
252 { return AttrNodes[Slot].second->begin(); }
253 iterator end(unsigned Slot)
254 { return AttrNodes[Slot].second->end(); }
255
256 const_iterator begin(unsigned Slot) const
257 { return AttrNodes[Slot].second->begin(); }
258 const_iterator end(unsigned Slot) const
259 { return AttrNodes[Slot].second->end(); }
260
261 void Profile(FoldingSetNodeID &ID) const {
251 void Profile(FoldingSetNodeID &ID) const {
262 Profile(ID, AttrNodes);
252 Profile(ID, makeArrayRef(getNode(0), getNumAttributes()));
263 }
264 static void Profile(FoldingSetNodeID &ID,
265 ArrayRef<std::pair<unsigned, AttributeSetNode*> > Nodes) {
266 for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
267 ID.AddInteger(Nodes[i].first);
268 ID.AddPointer(Nodes[i].second);
269 }
270 }
271
272 // FIXME: This atrocity is temporary.
273 uint64_t Raw(unsigned Index) const;
253 }
254 static void Profile(FoldingSetNodeID &ID,
255 ArrayRef<std::pair<unsigned, AttributeSetNode*> > Nodes) {
256 for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
257 ID.AddInteger(Nodes[i].first);
258 ID.AddPointer(Nodes[i].second);
259 }
260 }
261
262 // FIXME: This atrocity is temporary.
263 uint64_t Raw(unsigned Index) const;
264
265 void dump() const;
274};
275
276} // end llvm namespace
277
278#endif
266};
267
268} // end llvm namespace
269
270#endif