Mercurial > hg > CbC > CbC_llvm
comparison lib/IR/AttributeImpl.h @ 95:afa8332a0e37 LLVM3.8
LLVM 3.8
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Oct 2015 17:48:58 +0900 |
parents | 60c9769439b8 |
children | 1172e4bd9c6f |
comparison
equal
deleted
inserted
replaced
84:f3e34b893a5f | 95:afa8332a0e37 |
---|---|
16 #ifndef LLVM_LIB_IR_ATTRIBUTEIMPL_H | 16 #ifndef LLVM_LIB_IR_ATTRIBUTEIMPL_H |
17 #define LLVM_LIB_IR_ATTRIBUTEIMPL_H | 17 #define LLVM_LIB_IR_ATTRIBUTEIMPL_H |
18 | 18 |
19 #include "llvm/ADT/FoldingSet.h" | 19 #include "llvm/ADT/FoldingSet.h" |
20 #include "llvm/IR/Attributes.h" | 20 #include "llvm/IR/Attributes.h" |
21 #include "llvm/Support/TrailingObjects.h" | |
21 #include <string> | 22 #include <string> |
22 | 23 |
23 namespace llvm { | 24 namespace llvm { |
24 | 25 |
25 class Constant; | 26 class Constant; |
113 uint64_t Val; | 114 uint64_t Val; |
114 | 115 |
115 public: | 116 public: |
116 IntAttributeImpl(Attribute::AttrKind Kind, uint64_t Val) | 117 IntAttributeImpl(Attribute::AttrKind Kind, uint64_t Val) |
117 : EnumAttributeImpl(IntAttrEntry, Kind), Val(Val) { | 118 : EnumAttributeImpl(IntAttrEntry, Kind), Val(Val) { |
118 assert( | 119 assert((Kind == Attribute::Alignment || Kind == Attribute::StackAlignment || |
119 (Kind == Attribute::Alignment || Kind == Attribute::StackAlignment || | 120 Kind == Attribute::Dereferenceable || |
120 Kind == Attribute::Dereferenceable) && | 121 Kind == Attribute::DereferenceableOrNull) && |
121 "Wrong kind for int attribute!"); | 122 "Wrong kind for int attribute!"); |
122 } | 123 } |
123 | 124 |
124 uint64_t getValue() const { return Val; } | 125 uint64_t getValue() const { return Val; } |
125 }; | 126 }; |
126 | 127 |
139 | 140 |
140 //===----------------------------------------------------------------------===// | 141 //===----------------------------------------------------------------------===// |
141 /// \class | 142 /// \class |
142 /// \brief This class represents a group of attributes that apply to one | 143 /// \brief This class represents a group of attributes that apply to one |
143 /// element: function, return type, or parameter. | 144 /// element: function, return type, or parameter. |
144 class AttributeSetNode : public FoldingSetNode { | 145 class AttributeSetNode final |
146 : public FoldingSetNode, | |
147 private TrailingObjects<AttributeSetNode, Attribute> { | |
148 friend TrailingObjects; | |
149 | |
145 unsigned NumAttrs; ///< Number of attributes in this node. | 150 unsigned NumAttrs; ///< Number of attributes in this node. |
146 | 151 |
147 AttributeSetNode(ArrayRef<Attribute> Attrs) : NumAttrs(Attrs.size()) { | 152 AttributeSetNode(ArrayRef<Attribute> Attrs) : NumAttrs(Attrs.size()) { |
148 // There's memory after the node where we can store the entries in. | 153 // There's memory after the node where we can store the entries in. |
149 std::copy(Attrs.begin(), Attrs.end(), | 154 std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>()); |
150 reinterpret_cast<Attribute *>(this + 1)); | |
151 } | 155 } |
152 | 156 |
153 // AttributesSetNode is uniqued, these should not be publicly available. | 157 // AttributesSetNode is uniqued, these should not be publicly available. |
154 void operator=(const AttributeSetNode &) = delete; | 158 void operator=(const AttributeSetNode &) = delete; |
155 AttributeSetNode(const AttributeSetNode &) = delete; | 159 AttributeSetNode(const AttributeSetNode &) = delete; |
164 Attribute getAttribute(StringRef Kind) const; | 168 Attribute getAttribute(StringRef Kind) const; |
165 | 169 |
166 unsigned getAlignment() const; | 170 unsigned getAlignment() const; |
167 unsigned getStackAlignment() const; | 171 unsigned getStackAlignment() const; |
168 uint64_t getDereferenceableBytes() const; | 172 uint64_t getDereferenceableBytes() const; |
173 uint64_t getDereferenceableOrNullBytes() const; | |
169 std::string getAsString(bool InAttrGrp) const; | 174 std::string getAsString(bool InAttrGrp) const; |
170 | 175 |
171 typedef const Attribute *iterator; | 176 typedef const Attribute *iterator; |
172 iterator begin() const { return reinterpret_cast<iterator>(this + 1); } | 177 iterator begin() const { return getTrailingObjects<Attribute>(); } |
173 iterator end() const { return begin() + NumAttrs; } | 178 iterator end() const { return begin() + NumAttrs; } |
174 | 179 |
175 void Profile(FoldingSetNodeID &ID) const { | 180 void Profile(FoldingSetNodeID &ID) const { |
176 Profile(ID, makeArrayRef(begin(), end())); | 181 Profile(ID, makeArrayRef(begin(), end())); |
177 } | 182 } |
179 for (unsigned I = 0, E = AttrList.size(); I != E; ++I) | 184 for (unsigned I = 0, E = AttrList.size(); I != E; ++I) |
180 AttrList[I].Profile(ID); | 185 AttrList[I].Profile(ID); |
181 } | 186 } |
182 }; | 187 }; |
183 | 188 |
189 typedef std::pair<unsigned, AttributeSetNode *> IndexAttrPair; | |
190 | |
184 //===----------------------------------------------------------------------===// | 191 //===----------------------------------------------------------------------===// |
185 /// \class | 192 /// \class |
186 /// \brief This class represents a set of attributes that apply to the function, | 193 /// \brief This class represents a set of attributes that apply to the function, |
187 /// return type, and parameters. | 194 /// return type, and parameters. |
188 class AttributeSetImpl : public FoldingSetNode { | 195 class AttributeSetImpl final |
196 : public FoldingSetNode, | |
197 private TrailingObjects<AttributeSetImpl, IndexAttrPair> { | |
189 friend class AttributeSet; | 198 friend class AttributeSet; |
190 | 199 friend TrailingObjects; |
200 | |
201 private: | |
191 LLVMContext &Context; | 202 LLVMContext &Context; |
192 | |
193 typedef std::pair<unsigned, AttributeSetNode*> IndexAttrPair; | |
194 unsigned NumAttrs; ///< Number of entries in this set. | 203 unsigned NumAttrs; ///< Number of entries in this set. |
204 | |
205 // Helper fn for TrailingObjects class. | |
206 size_t numTrailingObjects(OverloadToken<IndexAttrPair>) { return NumAttrs; } | |
195 | 207 |
196 /// \brief Return a pointer to the IndexAttrPair for the specified slot. | 208 /// \brief Return a pointer to the IndexAttrPair for the specified slot. |
197 const IndexAttrPair *getNode(unsigned Slot) const { | 209 const IndexAttrPair *getNode(unsigned Slot) const { |
198 return reinterpret_cast<const IndexAttrPair *>(this + 1) + Slot; | 210 return getTrailingObjects<IndexAttrPair>() + Slot; |
199 } | 211 } |
200 | 212 |
201 // AttributesSet is uniqued, these should not be publicly available. | 213 // AttributesSet is uniqued, these should not be publicly available. |
202 void operator=(const AttributeSetImpl &) = delete; | 214 void operator=(const AttributeSetImpl &) = delete; |
203 AttributeSetImpl(const AttributeSetImpl &) = delete; | 215 AttributeSetImpl(const AttributeSetImpl &) = delete; |
204 public: | 216 public: |
205 AttributeSetImpl(LLVMContext &C, | 217 AttributeSetImpl(LLVMContext &C, |
206 ArrayRef<std::pair<unsigned, AttributeSetNode *> > Attrs) | 218 ArrayRef<std::pair<unsigned, AttributeSetNode *> > Attrs) |
207 : Context(C), NumAttrs(Attrs.size()) { | 219 : Context(C), NumAttrs(Attrs.size()) { |
220 | |
208 #ifndef NDEBUG | 221 #ifndef NDEBUG |
209 if (Attrs.size() >= 2) { | 222 if (Attrs.size() >= 2) { |
210 for (const std::pair<unsigned, AttributeSetNode *> *i = Attrs.begin() + 1, | 223 for (const std::pair<unsigned, AttributeSetNode *> *i = Attrs.begin() + 1, |
211 *e = Attrs.end(); | 224 *e = Attrs.end(); |
212 i != e; ++i) { | 225 i != e; ++i) { |
213 assert((i-1)->first <= i->first && "Attribute set not ordered!"); | 226 assert((i-1)->first <= i->first && "Attribute set not ordered!"); |
214 } | 227 } |
215 } | 228 } |
216 #endif | 229 #endif |
217 // There's memory after the node where we can store the entries in. | 230 // There's memory after the node where we can store the entries in. |
218 std::copy(Attrs.begin(), Attrs.end(), | 231 std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<IndexAttrPair>()); |
219 reinterpret_cast<IndexAttrPair *>(this + 1)); | |
220 } | 232 } |
221 | 233 |
222 /// \brief Get the context that created this AttributeSetImpl. | 234 /// \brief Get the context that created this AttributeSetImpl. |
223 LLVMContext &getContext() { return Context; } | 235 LLVMContext &getContext() { return Context; } |
224 | 236 |