]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/IR/Attributes.h
Merge ^/head r317503 through r317807.
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / IR / Attributes.h
1 //===- llvm/Attributes.h - Container for Attributes -------------*- 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 contains the simple types necessary to represent the
12 /// attributes associated with functions and their calls.
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_IR_ATTRIBUTES_H
17 #define LLVM_IR_ATTRIBUTES_H
18
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/FoldingSet.h"
21 #include "llvm/ADT/iterator_range.h"
22 #include "llvm/ADT/Optional.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Support/PointerLikeTypeTraits.h"
25 #include "llvm-c/Types.h"
26 #include <bitset>
27 #include <cassert>
28 #include <cstdint>
29 #include <map>
30 #include <string>
31 #include <utility>
32
33 namespace llvm {
34
35 class AttrBuilder;
36 class AttributeImpl;
37 class AttributeListImpl;
38 class AttributeSetNode;
39 template<typename T> struct DenseMapInfo;
40 class Function;
41 class LLVMContext;
42 class Type;
43
44 //===----------------------------------------------------------------------===//
45 /// \class
46 /// \brief Functions, function parameters, and return types can have attributes
47 /// to indicate how they should be treated by optimizations and code
48 /// generation. This class represents one of those attributes. It's light-weight
49 /// and should be passed around by-value.
50 class Attribute {
51 public:
52   /// This enumeration lists the attributes that can be associated with
53   /// parameters, function results, or the function itself.
54   ///
55   /// Note: The `uwtable' attribute is about the ABI or the user mandating an
56   /// entry in the unwind table. The `nounwind' attribute is about an exception
57   /// passing by the function.
58   ///
59   /// In a theoretical system that uses tables for profiling and SjLj for
60   /// exceptions, they would be fully independent. In a normal system that uses
61   /// tables for both, the semantics are:
62   ///
63   /// nil                = Needs an entry because an exception might pass by.
64   /// nounwind           = No need for an entry
65   /// uwtable            = Needs an entry because the ABI says so and because
66   ///                      an exception might pass by.
67   /// uwtable + nounwind = Needs an entry because the ABI says so.
68
69   enum AttrKind {
70     // IR-Level Attributes
71     None,                  ///< No attributes have been set
72     #define GET_ATTR_ENUM
73     #include "llvm/IR/Attributes.gen"
74     EndAttrKinds           ///< Sentinal value useful for loops
75   };
76
77 private:
78   AttributeImpl *pImpl = nullptr;
79
80   Attribute(AttributeImpl *A) : pImpl(A) {}
81
82 public:
83   Attribute() = default;
84
85   //===--------------------------------------------------------------------===//
86   // Attribute Construction
87   //===--------------------------------------------------------------------===//
88
89   /// \brief Return a uniquified Attribute object.
90   static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val = 0);
91   static Attribute get(LLVMContext &Context, StringRef Kind,
92                        StringRef Val = StringRef());
93
94   /// \brief Return a uniquified Attribute object that has the specific
95   /// alignment set.
96   static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align);
97   static Attribute getWithStackAlignment(LLVMContext &Context, uint64_t Align);
98   static Attribute getWithDereferenceableBytes(LLVMContext &Context,
99                                               uint64_t Bytes);
100   static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context,
101                                                      uint64_t Bytes);
102   static Attribute getWithAllocSizeArgs(LLVMContext &Context,
103                                         unsigned ElemSizeArg,
104                                         const Optional<unsigned> &NumElemsArg);
105
106   //===--------------------------------------------------------------------===//
107   // Attribute Accessors
108   //===--------------------------------------------------------------------===//
109
110   /// \brief Return true if the attribute is an Attribute::AttrKind type.
111   bool isEnumAttribute() const;
112
113   /// \brief Return true if the attribute is an integer attribute.
114   bool isIntAttribute() const;
115
116   /// \brief Return true if the attribute is a string (target-dependent)
117   /// attribute.
118   bool isStringAttribute() const;
119
120   /// \brief Return true if the attribute is present.
121   bool hasAttribute(AttrKind Val) const;
122
123   /// \brief Return true if the target-dependent attribute is present.
124   bool hasAttribute(StringRef Val) const;
125
126   /// \brief Return the attribute's kind as an enum (Attribute::AttrKind). This
127   /// requires the attribute to be an enum or integer attribute.
128   Attribute::AttrKind getKindAsEnum() const;
129
130   /// \brief Return the attribute's value as an integer. This requires that the
131   /// attribute be an integer attribute.
132   uint64_t getValueAsInt() const;
133
134   /// \brief Return the attribute's kind as a string. This requires the
135   /// attribute to be a string attribute.
136   StringRef getKindAsString() const;
137
138   /// \brief Return the attribute's value as a string. This requires the
139   /// attribute to be a string attribute.
140   StringRef getValueAsString() const;
141
142   /// \brief Returns the alignment field of an attribute as a byte alignment
143   /// value.
144   unsigned getAlignment() const;
145
146   /// \brief Returns the stack alignment field of an attribute as a byte
147   /// alignment value.
148   unsigned getStackAlignment() const;
149
150   /// \brief Returns the number of dereferenceable bytes from the
151   /// dereferenceable attribute.
152   uint64_t getDereferenceableBytes() const;
153
154   /// \brief Returns the number of dereferenceable_or_null bytes from the
155   /// dereferenceable_or_null attribute.
156   uint64_t getDereferenceableOrNullBytes() const;
157
158   /// Returns the argument numbers for the allocsize attribute (or pair(0, 0)
159   /// if not known).
160   std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
161
162   /// \brief The Attribute is converted to a string of equivalent mnemonic. This
163   /// is, presumably, for writing out the mnemonics for the assembly writer.
164   std::string getAsString(bool InAttrGrp = false) const;
165
166   /// \brief Equality and non-equality operators.
167   bool operator==(Attribute A) const { return pImpl == A.pImpl; }
168   bool operator!=(Attribute A) const { return pImpl != A.pImpl; }
169
170   /// \brief Less-than operator. Useful for sorting the attributes list.
171   bool operator<(Attribute A) const;
172
173   void Profile(FoldingSetNodeID &ID) const {
174     ID.AddPointer(pImpl);
175   }
176
177   /// \brief Return a raw pointer that uniquely identifies this attribute.
178   void *getRawPointer() const {
179     return pImpl;
180   }
181
182   /// \brief Get an attribute from a raw pointer created by getRawPointer.
183   static Attribute fromRawPointer(void *RawPtr) {
184     return Attribute(reinterpret_cast<AttributeImpl*>(RawPtr));
185   }
186 };
187
188 // Specialized opaque value conversions.
189 inline LLVMAttributeRef wrap(Attribute Attr) {
190   return reinterpret_cast<LLVMAttributeRef>(Attr.getRawPointer());
191 }
192
193 // Specialized opaque value conversions.
194 inline Attribute unwrap(LLVMAttributeRef Attr) {
195   return Attribute::fromRawPointer(Attr);
196 }
197
198 //===----------------------------------------------------------------------===//
199 /// \class
200 /// This class holds the attributes for a particular argument, parameter,
201 /// function, or return value. It is an immutable value type that is cheap to
202 /// copy. Adding and removing enum attributes is intended to be fast, but adding
203 /// and removing string or integer attributes involves a FoldingSet lookup.
204 class AttributeSet {
205   // TODO: Extract AvailableAttrs from AttributeSetNode and store them here.
206   // This will allow an efficient implementation of addAttribute and
207   // removeAttribute for enum attrs.
208
209   /// Private implementation pointer.
210   AttributeSetNode *SetNode = nullptr;
211
212   friend AttributeListImpl;
213   template <typename Ty> friend struct DenseMapInfo;
214
215 private:
216   explicit AttributeSet(AttributeSetNode *ASN) : SetNode(ASN) {}
217
218 public:
219   /// AttributeSet is a trivially copyable value type.
220   AttributeSet() = default;
221   AttributeSet(const AttributeSet &) = default;
222   ~AttributeSet() = default;
223
224   static AttributeSet get(LLVMContext &C, const AttrBuilder &B);
225   static AttributeSet get(LLVMContext &C, ArrayRef<Attribute> Attrs);
226
227   bool operator==(const AttributeSet &O) { return SetNode == O.SetNode; }
228   bool operator!=(const AttributeSet &O) { return !(*this == O); }
229
230   unsigned getNumAttributes() const;
231
232   bool hasAttributes() const { return SetNode != nullptr; }
233
234   bool hasAttribute(Attribute::AttrKind Kind) const;
235   bool hasAttribute(StringRef Kind) const;
236
237   Attribute getAttribute(Attribute::AttrKind Kind) const;
238   Attribute getAttribute(StringRef Kind) const;
239
240   unsigned getAlignment() const;
241   unsigned getStackAlignment() const;
242   uint64_t getDereferenceableBytes() const;
243   uint64_t getDereferenceableOrNullBytes() const;
244   std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
245   std::string getAsString(bool InAttrGrp = false) const;
246
247   typedef const Attribute *iterator;
248   iterator begin() const;
249   iterator end() const;
250 };
251
252 //===----------------------------------------------------------------------===//
253 /// \class
254 /// \brief Provide DenseMapInfo for AttributeSet.
255 template <> struct DenseMapInfo<AttributeSet> {
256   static inline AttributeSet getEmptyKey() {
257     uintptr_t Val = static_cast<uintptr_t>(-1);
258     Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable;
259     return AttributeSet(reinterpret_cast<AttributeSetNode *>(Val));
260   }
261
262   static inline AttributeSet getTombstoneKey() {
263     uintptr_t Val = static_cast<uintptr_t>(-2);
264     Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable;
265     return AttributeSet(reinterpret_cast<AttributeSetNode *>(Val));
266   }
267
268   static unsigned getHashValue(AttributeSet AS) {
269     return (unsigned((uintptr_t)AS.SetNode) >> 4) ^
270            (unsigned((uintptr_t)AS.SetNode) >> 9);
271   }
272
273   static bool isEqual(AttributeSet LHS, AttributeSet RHS) { return LHS == RHS; }
274 };
275
276 //===----------------------------------------------------------------------===//
277 /// \class
278 /// \brief This class holds the attributes for a function, its return value, and
279 /// its parameters. You access the attributes for each of them via an index into
280 /// the AttributeList object. The function attributes are at index
281 /// `AttributeList::FunctionIndex', the return value is at index
282 /// `AttributeList::ReturnIndex', and the attributes for the parameters start at
283 /// index `1'.
284 class AttributeList {
285 public:
286   enum AttrIndex : unsigned {
287     ReturnIndex = 0U,
288     FunctionIndex = ~0U,
289     FirstArgIndex = 1,
290   };
291
292 private:
293   friend class AttrBuilder;
294   friend class AttributeListImpl;
295   friend class AttributeSet;
296   friend class AttributeSetNode;
297
298   template <typename Ty> friend struct DenseMapInfo;
299
300   /// \brief The attributes that we are managing. This can be null to represent
301   /// the empty attributes list.
302   AttributeListImpl *pImpl = nullptr;
303
304 public:
305   /// \brief Create an AttributeList with the specified parameters in it.
306   static AttributeList get(LLVMContext &C,
307                            ArrayRef<std::pair<unsigned, Attribute>> Attrs);
308   static AttributeList
309   get(LLVMContext &C, ArrayRef<std::pair<unsigned, AttributeSet>> Attrs);
310
311   /// \brief Create an AttributeList from attribute sets for a function, its
312   /// return value, and all of its arguments.
313   static AttributeList get(LLVMContext &C, AttributeSet FnAttrs,
314                            AttributeSet RetAttrs,
315                            ArrayRef<AttributeSet> ArgAttrs);
316
317   static AttributeList
318   getImpl(LLVMContext &C,
319           ArrayRef<std::pair<unsigned, AttributeSet>> Attrs);
320
321 private:
322   explicit AttributeList(AttributeListImpl *LI) : pImpl(LI) {}
323
324 public:
325   AttributeList() = default;
326
327   //===--------------------------------------------------------------------===//
328   // AttributeList Construction and Mutation
329   //===--------------------------------------------------------------------===//
330
331   /// \brief Return an AttributeList with the specified parameters in it.
332   static AttributeList get(LLVMContext &C, ArrayRef<AttributeList> Attrs);
333   static AttributeList get(LLVMContext &C, unsigned Index,
334                            ArrayRef<Attribute::AttrKind> Kinds);
335   static AttributeList get(LLVMContext &C, unsigned Index,
336                            ArrayRef<StringRef> Kind);
337   static AttributeList get(LLVMContext &C, unsigned Index,
338                            const AttrBuilder &B);
339
340   /// Add an argument attribute to the list. Returns a new list because
341   /// attribute lists are immutable.
342   AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo,
343                                   Attribute::AttrKind Kind) const {
344     return addAttribute(C, ArgNo + FirstArgIndex, Kind);
345   }
346
347   /// \brief Add an attribute to the attribute set at the given index. Because
348   /// attribute sets are immutable, this returns a new set.
349   AttributeList addAttribute(LLVMContext &C, unsigned Index,
350                              Attribute::AttrKind Kind) const;
351
352   /// \brief Add an attribute to the attribute set at the given index. Because
353   /// attribute sets are immutable, this returns a new set.
354   AttributeList addAttribute(LLVMContext &C, unsigned Index, StringRef Kind,
355                              StringRef Value = StringRef()) const;
356
357   /// Add an attribute to the attribute set at the given indices. Because
358   /// attribute sets are immutable, this returns a new set.
359   AttributeList addAttribute(LLVMContext &C, ArrayRef<unsigned> Indices,
360                              Attribute A) const;
361
362   /// \brief Add attributes to the attribute set at the given index. Because
363   /// attribute sets are immutable, this returns a new set.
364   AttributeList addAttributes(LLVMContext &C, unsigned Index,
365                               const AttrBuilder &B) const;
366
367   /// \brief Remove the specified attribute at the specified index from this
368   /// attribute list. Because attribute lists are immutable, this returns the
369   /// new list.
370   AttributeList removeAttribute(LLVMContext &C, unsigned Index,
371                                 Attribute::AttrKind Kind) const;
372
373   /// \brief Remove the specified attribute at the specified index from this
374   /// attribute list. Because attribute lists are immutable, this returns the
375   /// new list.
376   AttributeList removeAttribute(LLVMContext &C, unsigned Index,
377                                 StringRef Kind) const;
378
379   /// \brief Remove the specified attributes at the specified index from this
380   /// attribute list. Because attribute lists are immutable, this returns the
381   /// new list.
382   AttributeList removeAttributes(LLVMContext &C, unsigned Index,
383                                  const AttrBuilder &AttrsToRemove) const;
384
385   /// \brief Remove all attributes at the specified index from this
386   /// attribute list. Because attribute lists are immutable, this returns the
387   /// new list.
388   AttributeList removeAttributes(LLVMContext &C, unsigned Index) const;
389
390   /// \brief Add the dereferenceable attribute to the attribute set at the given
391   /// index. Because attribute sets are immutable, this returns a new set.
392   AttributeList addDereferenceableAttr(LLVMContext &C, unsigned Index,
393                                        uint64_t Bytes) const;
394
395   /// \brief Add the dereferenceable_or_null attribute to the attribute set at
396   /// the given index. Because attribute sets are immutable, this returns a new
397   /// set.
398   AttributeList addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index,
399                                              uint64_t Bytes) const;
400
401   /// Add the allocsize attribute to the attribute set at the given index.
402   /// Because attribute sets are immutable, this returns a new set.
403   AttributeList addAllocSizeAttr(LLVMContext &C, unsigned Index,
404                                  unsigned ElemSizeArg,
405                                  const Optional<unsigned> &NumElemsArg);
406
407   //===--------------------------------------------------------------------===//
408   // AttributeList Accessors
409   //===--------------------------------------------------------------------===//
410
411   /// \brief Retrieve the LLVM context.
412   LLVMContext &getContext() const;
413
414   /// \brief The attributes for the specified index are returned.
415   AttributeSet getAttributes(unsigned Index) const;
416
417   /// \brief The attributes for the argument or parameter at the given index are
418   /// returned.
419   AttributeSet getParamAttributes(unsigned ArgNo) const;
420
421   /// \brief The attributes for the ret value are returned.
422   AttributeSet getRetAttributes() const;
423
424   /// \brief The function attributes are returned.
425   AttributeSet getFnAttributes() const;
426
427   /// \brief Return true if the attribute exists at the given index.
428   bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const;
429
430   /// \brief Return true if the attribute exists at the given index.
431   bool hasAttribute(unsigned Index, StringRef Kind) const;
432
433   /// \brief Return true if attribute exists at the given index.
434   bool hasAttributes(unsigned Index) const;
435
436   /// \brief Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but
437   /// may be faster.
438   bool hasFnAttribute(Attribute::AttrKind Kind) const;
439
440   /// \brief Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but
441   /// may be faster.
442   bool hasFnAttribute(StringRef Kind) const;
443
444   /// \brief Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
445   bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const;
446
447   /// \brief Return true if the specified attribute is set for at least one
448   /// parameter or for the return value. If Index is not nullptr, the index
449   /// of a parameter with the specified attribute is provided.
450   bool hasAttrSomewhere(Attribute::AttrKind Kind,
451                         unsigned *Index = nullptr) const;
452
453   /// \brief Return the attribute object that exists at the given index.
454   Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const;
455
456   /// \brief Return the attribute object that exists at the given index.
457   Attribute getAttribute(unsigned Index, StringRef Kind) const;
458
459   /// \brief Return the alignment of the return value.
460   unsigned getRetAlignment() const;
461
462   /// \brief Return the alignment for the specified function parameter.
463   unsigned getParamAlignment(unsigned ArgNo) const;
464
465   /// \brief Get the stack alignment.
466   unsigned getStackAlignment(unsigned Index) const;
467
468   /// \brief Get the number of dereferenceable bytes (or zero if unknown).
469   uint64_t getDereferenceableBytes(unsigned Index) const;
470
471   /// \brief Get the number of dereferenceable_or_null bytes (or zero if
472   /// unknown).
473   uint64_t getDereferenceableOrNullBytes(unsigned Index) const;
474
475   /// Get the allocsize argument numbers (or pair(0, 0) if unknown).
476   std::pair<unsigned, Optional<unsigned>>
477   getAllocSizeArgs(unsigned Index) const;
478
479   /// \brief Return the attributes at the index as a string.
480   std::string getAsString(unsigned Index, bool InAttrGrp = false) const;
481
482   typedef ArrayRef<Attribute>::iterator iterator;
483
484   iterator begin(unsigned Slot) const;
485   iterator end(unsigned Slot) const;
486
487   /// operator==/!= - Provide equality predicates.
488   bool operator==(const AttributeList &RHS) const { return pImpl == RHS.pImpl; }
489   bool operator!=(const AttributeList &RHS) const { return pImpl != RHS.pImpl; }
490
491   //===--------------------------------------------------------------------===//
492   // AttributeList Introspection
493   //===--------------------------------------------------------------------===//
494
495   /// \brief Return a raw pointer that uniquely identifies this attribute list.
496   void *getRawPointer() const {
497     return pImpl;
498   }
499
500   /// \brief Return true if there are no attributes.
501   bool isEmpty() const {
502     return getNumSlots() == 0;
503   }
504
505   /// \brief Return the number of slots used in this attribute list.  This is
506   /// the number of arguments that have an attribute set on them (including the
507   /// function itself).
508   unsigned getNumSlots() const;
509
510   /// \brief Return the index for the given slot.
511   unsigned getSlotIndex(unsigned Slot) const;
512
513   /// \brief Return the attributes at the given slot.
514   AttributeSet getSlotAttributes(unsigned Slot) const;
515
516   void dump() const;
517 };
518
519 //===----------------------------------------------------------------------===//
520 /// \class
521 /// \brief Provide DenseMapInfo for AttributeList.
522 template <> struct DenseMapInfo<AttributeList> {
523   static inline AttributeList getEmptyKey() {
524     uintptr_t Val = static_cast<uintptr_t>(-1);
525     Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
526     return AttributeList(reinterpret_cast<AttributeListImpl *>(Val));
527   }
528
529   static inline AttributeList getTombstoneKey() {
530     uintptr_t Val = static_cast<uintptr_t>(-2);
531     Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
532     return AttributeList(reinterpret_cast<AttributeListImpl *>(Val));
533   }
534
535   static unsigned getHashValue(AttributeList AS) {
536     return (unsigned((uintptr_t)AS.pImpl) >> 4) ^
537            (unsigned((uintptr_t)AS.pImpl) >> 9);
538   }
539
540   static bool isEqual(AttributeList LHS, AttributeList RHS) {
541     return LHS == RHS;
542   }
543 };
544
545 //===----------------------------------------------------------------------===//
546 /// \class
547 /// \brief This class is used in conjunction with the Attribute::get method to
548 /// create an Attribute object. The object itself is uniquified. The Builder's
549 /// value, however, is not. So this can be used as a quick way to test for
550 /// equality, presence of attributes, etc.
551 class AttrBuilder {
552   std::bitset<Attribute::EndAttrKinds> Attrs;
553   std::map<std::string, std::string> TargetDepAttrs;
554   uint64_t Alignment = 0;
555   uint64_t StackAlignment = 0;
556   uint64_t DerefBytes = 0;
557   uint64_t DerefOrNullBytes = 0;
558   uint64_t AllocSizeArgs = 0;
559
560 public:
561   AttrBuilder() = default;
562   AttrBuilder(const Attribute &A) {
563     addAttribute(A);
564   }
565   AttrBuilder(AttributeList AS, unsigned Idx);
566   AttrBuilder(AttributeSet AS);
567
568   void clear();
569
570   /// \brief Add an attribute to the builder.
571   AttrBuilder &addAttribute(Attribute::AttrKind Val);
572
573   /// \brief Add the Attribute object to the builder.
574   AttrBuilder &addAttribute(Attribute A);
575
576   /// \brief Add the target-dependent attribute to the builder.
577   AttrBuilder &addAttribute(StringRef A, StringRef V = StringRef());
578
579   /// \brief Remove an attribute from the builder.
580   AttrBuilder &removeAttribute(Attribute::AttrKind Val);
581
582   /// \brief Remove the attributes from the builder.
583   AttrBuilder &removeAttributes(AttributeList A, uint64_t WithoutIndex);
584
585   /// \brief Remove the target-dependent attribute to the builder.
586   AttrBuilder &removeAttribute(StringRef A);
587
588   /// \brief Add the attributes from the builder.
589   AttrBuilder &merge(const AttrBuilder &B);
590
591   /// \brief Remove the attributes from the builder.
592   AttrBuilder &remove(const AttrBuilder &B);
593
594   /// \brief Return true if the builder has any attribute that's in the
595   /// specified builder.
596   bool overlaps(const AttrBuilder &B) const;
597
598   /// \brief Return true if the builder has the specified attribute.
599   bool contains(Attribute::AttrKind A) const {
600     assert((unsigned)A < Attribute::EndAttrKinds && "Attribute out of range!");
601     return Attrs[A];
602   }
603
604   /// \brief Return true if the builder has the specified target-dependent
605   /// attribute.
606   bool contains(StringRef A) const;
607
608   /// \brief Return true if the builder has IR-level attributes.
609   bool hasAttributes() const;
610
611   /// \brief Return true if the builder has any attribute that's in the
612   /// specified attribute.
613   bool hasAttributes(AttributeList A, uint64_t Index) const;
614
615   /// \brief Return true if the builder has an alignment attribute.
616   bool hasAlignmentAttr() const;
617
618   /// \brief Retrieve the alignment attribute, if it exists.
619   uint64_t getAlignment() const { return Alignment; }
620
621   /// \brief Retrieve the stack alignment attribute, if it exists.
622   uint64_t getStackAlignment() const { return StackAlignment; }
623
624   /// \brief Retrieve the number of dereferenceable bytes, if the
625   /// dereferenceable attribute exists (zero is returned otherwise).
626   uint64_t getDereferenceableBytes() const { return DerefBytes; }
627
628   /// \brief Retrieve the number of dereferenceable_or_null bytes, if the
629   /// dereferenceable_or_null attribute exists (zero is returned otherwise).
630   uint64_t getDereferenceableOrNullBytes() const { return DerefOrNullBytes; }
631
632   /// Retrieve the allocsize args, if the allocsize attribute exists.  If it
633   /// doesn't exist, pair(0, 0) is returned.
634   std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
635
636   /// \brief This turns an int alignment (which must be a power of 2) into the
637   /// form used internally in Attribute.
638   AttrBuilder &addAlignmentAttr(unsigned Align);
639
640   /// \brief This turns an int stack alignment (which must be a power of 2) into
641   /// the form used internally in Attribute.
642   AttrBuilder &addStackAlignmentAttr(unsigned Align);
643
644   /// \brief This turns the number of dereferenceable bytes into the form used
645   /// internally in Attribute.
646   AttrBuilder &addDereferenceableAttr(uint64_t Bytes);
647
648   /// \brief This turns the number of dereferenceable_or_null bytes into the
649   /// form used internally in Attribute.
650   AttrBuilder &addDereferenceableOrNullAttr(uint64_t Bytes);
651
652   /// This turns one (or two) ints into the form used internally in Attribute.
653   AttrBuilder &addAllocSizeAttr(unsigned ElemSizeArg,
654                                 const Optional<unsigned> &NumElemsArg);
655
656   /// Add an allocsize attribute, using the representation returned by
657   /// Attribute.getIntValue().
658   AttrBuilder &addAllocSizeAttrFromRawRepr(uint64_t RawAllocSizeRepr);
659
660   /// \brief Return true if the builder contains no target-independent
661   /// attributes.
662   bool empty() const { return Attrs.none(); }
663
664   // Iterators for target-dependent attributes.
665   typedef std::pair<std::string, std::string>                td_type;
666   typedef std::map<std::string, std::string>::iterator       td_iterator;
667   typedef std::map<std::string, std::string>::const_iterator td_const_iterator;
668   typedef iterator_range<td_iterator>                        td_range;
669   typedef iterator_range<td_const_iterator>                  td_const_range;
670
671   td_iterator td_begin()             { return TargetDepAttrs.begin(); }
672   td_iterator td_end()               { return TargetDepAttrs.end(); }
673
674   td_const_iterator td_begin() const { return TargetDepAttrs.begin(); }
675   td_const_iterator td_end() const   { return TargetDepAttrs.end(); }
676
677   td_range td_attrs() { return td_range(td_begin(), td_end()); }
678   td_const_range td_attrs() const {
679     return td_const_range(td_begin(), td_end());
680   }
681
682   bool td_empty() const              { return TargetDepAttrs.empty(); }
683
684   bool operator==(const AttrBuilder &B);
685   bool operator!=(const AttrBuilder &B) {
686     return !(*this == B);
687   }
688 };
689
690 namespace AttributeFuncs {
691
692 /// \brief Which attributes cannot be applied to a type.
693 AttrBuilder typeIncompatible(Type *Ty);
694
695 /// \returns Return true if the two functions have compatible target-independent
696 /// attributes for inlining purposes.
697 bool areInlineCompatible(const Function &Caller, const Function &Callee);
698
699 /// \brief Merge caller's and callee's attributes.
700 void mergeAttributesForInlining(Function &Caller, const Function &Callee);
701
702 } // end AttributeFuncs namespace
703
704 } // end llvm namespace
705
706 #endif // LLVM_IR_ATTRIBUTES_H