LLVM  4.0.0
Attributes.h
Go to the documentation of this file.
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/Optional.h"
22 #include "llvm/Support/Compiler.h"
24 #include "llvm-c/Types.h"
25 #include <bitset>
26 #include <cassert>
27 #include <map>
28 #include <string>
29 
30 namespace llvm {
31 
32 class AttrBuilder;
33 class AttributeImpl;
34 class AttributeSetImpl;
35 class AttributeSetNode;
36 class Constant;
37 template<typename T> struct DenseMapInfo;
38 class Function;
39 class LLVMContext;
40 class Type;
41 
42 //===----------------------------------------------------------------------===//
43 /// \class
44 /// \brief Functions, function parameters, and return types can have attributes
45 /// to indicate how they should be treated by optimizations and code
46 /// generation. This class represents one of those attributes. It's light-weight
47 /// and should be passed around by-value.
48 class Attribute {
49 public:
50  /// This enumeration lists the attributes that can be associated with
51  /// parameters, function results, or the function itself.
52  ///
53  /// Note: The `uwtable' attribute is about the ABI or the user mandating an
54  /// entry in the unwind table. The `nounwind' attribute is about an exception
55  /// passing by the function.
56  ///
57  /// In a theoretical system that uses tables for profiling and SjLj for
58  /// exceptions, they would be fully independent. In a normal system that uses
59  /// tables for both, the semantics are:
60  ///
61  /// nil = Needs an entry because an exception might pass by.
62  /// nounwind = No need for an entry
63  /// uwtable = Needs an entry because the ABI says so and because
64  /// an exception might pass by.
65  /// uwtable + nounwind = Needs an entry because the ABI says so.
66 
67  enum AttrKind {
68  // IR-Level Attributes
69  None, ///< No attributes have been set
70  #define GET_ATTR_ENUM
71  #include "llvm/IR/Attributes.gen"
72  EndAttrKinds ///< Sentinal value useful for loops
73  };
74 
75 private:
76  AttributeImpl *pImpl;
77  Attribute(AttributeImpl *A) : pImpl(A) {}
78 
79 public:
80  Attribute() : pImpl(nullptr) {}
81 
82  //===--------------------------------------------------------------------===//
83  // Attribute Construction
84  //===--------------------------------------------------------------------===//
85 
86  /// \brief Return a uniquified Attribute object.
87  static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val = 0);
89  StringRef Val = StringRef());
90 
91  /// \brief Return a uniquified Attribute object that has the specific
92  /// alignment set.
93  static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align);
94  static Attribute getWithStackAlignment(LLVMContext &Context, uint64_t Align);
96  uint64_t Bytes);
98  uint64_t Bytes);
100  unsigned ElemSizeArg,
101  const Optional<unsigned> &NumElemsArg);
102 
103  //===--------------------------------------------------------------------===//
104  // Attribute Accessors
105  //===--------------------------------------------------------------------===//
106 
107  /// \brief Return true if the attribute is an Attribute::AttrKind type.
108  bool isEnumAttribute() const;
109 
110  /// \brief Return true if the attribute is an integer attribute.
111  bool isIntAttribute() const;
112 
113  /// \brief Return true if the attribute is a string (target-dependent)
114  /// attribute.
115  bool isStringAttribute() const;
116 
117  /// \brief Return true if the attribute is present.
118  bool hasAttribute(AttrKind Val) const;
119 
120  /// \brief Return true if the target-dependent attribute is present.
121  bool hasAttribute(StringRef Val) const;
122 
123  /// \brief Return the attribute's kind as an enum (Attribute::AttrKind). This
124  /// requires the attribute to be an enum or integer attribute.
126 
127  /// \brief Return the attribute's value as an integer. This requires that the
128  /// attribute be an integer attribute.
129  uint64_t getValueAsInt() const;
130 
131  /// \brief Return the attribute's kind as a string. This requires the
132  /// attribute to be a string attribute.
133  StringRef getKindAsString() const;
134 
135  /// \brief Return the attribute's value as a string. This requires the
136  /// attribute to be a string attribute.
137  StringRef getValueAsString() const;
138 
139  /// \brief Returns the alignment field of an attribute as a byte alignment
140  /// value.
141  unsigned getAlignment() const;
142 
143  /// \brief Returns the stack alignment field of an attribute as a byte
144  /// alignment value.
145  unsigned getStackAlignment() const;
146 
147  /// \brief Returns the number of dereferenceable bytes from the
148  /// dereferenceable attribute.
149  uint64_t getDereferenceableBytes() const;
150 
151  /// \brief Returns the number of dereferenceable_or_null bytes from the
152  /// dereferenceable_or_null attribute.
153  uint64_t getDereferenceableOrNullBytes() const;
154 
155  /// Returns the argument numbers for the allocsize attribute (or pair(0, 0)
156  /// if not known).
157  std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
158 
159  /// \brief The Attribute is converted to a string of equivalent mnemonic. This
160  /// is, presumably, for writing out the mnemonics for the assembly writer.
161  std::string getAsString(bool InAttrGrp = false) const;
162 
163  /// \brief Equality and non-equality operators.
164  bool operator==(Attribute A) const { return pImpl == A.pImpl; }
165  bool operator!=(Attribute A) const { return pImpl != A.pImpl; }
166 
167  /// \brief Less-than operator. Useful for sorting the attributes list.
168  bool operator<(Attribute A) const;
169 
170  void Profile(FoldingSetNodeID &ID) const {
171  ID.AddPointer(pImpl);
172  }
173 
174  /// \brief Return a raw pointer that uniquely identifies this attribute.
175  void *getRawPointer() const {
176  return pImpl;
177  }
178 
179  /// \brief Get an attribute from a raw pointer created by getRawPointer.
180  static Attribute fromRawPointer(void *RawPtr) {
181  return Attribute(reinterpret_cast<AttributeImpl*>(RawPtr));
182  }
183 };
184 
185 // Specialized opaque value conversions.
187  return reinterpret_cast<LLVMAttributeRef>(Attr.getRawPointer());
188 }
189 
190 // Specialized opaque value conversions.
192  return Attribute::fromRawPointer(Attr);
193 }
194 
195 //===----------------------------------------------------------------------===//
196 /// \class
197 /// \brief This class holds the attributes for a function, its return value, and
198 /// its parameters. You access the attributes for each of them via an index into
199 /// the AttributeSet object. The function attributes are at index
200 /// `AttributeSet::FunctionIndex', the return value is at index
201 /// `AttributeSet::ReturnIndex', and the attributes for the parameters start at
202 /// index `1'.
204 public:
205  enum AttrIndex : unsigned {
208  };
209 
210 private:
211  friend class AttrBuilder;
212  friend class AttributeSetImpl;
213  friend class AttributeSetNode;
214  template <typename Ty> friend struct DenseMapInfo;
215 
216  /// \brief The attributes that we are managing. This can be null to represent
217  /// the empty attributes list.
218  AttributeSetImpl *pImpl;
219 
220  /// \brief The attributes for the specified index are returned.
221  AttributeSetNode *getAttributes(unsigned Index) const;
222 
223  /// \brief Create an AttributeSet with the specified parameters in it.
224  static AttributeSet get(LLVMContext &C,
226  static AttributeSet get(LLVMContext &C,
227  ArrayRef<std::pair<unsigned,
228  AttributeSetNode*> > Attrs);
229 
231  ArrayRef<std::pair<unsigned,
232  AttributeSetNode*> > Attrs);
233 
234  explicit AttributeSet(AttributeSetImpl *LI) : pImpl(LI) {}
235 
236 public:
237  AttributeSet() : pImpl(nullptr) {}
238 
239  //===--------------------------------------------------------------------===//
240  // AttributeSet Construction and Mutation
241  //===--------------------------------------------------------------------===//
242 
243  /// \brief Return an AttributeSet with the specified parameters in it.
244  static AttributeSet get(LLVMContext &C, ArrayRef<AttributeSet> Attrs);
245  static AttributeSet get(LLVMContext &C, unsigned Index,
247  static AttributeSet get(LLVMContext &C, unsigned Index,
249  static AttributeSet get(LLVMContext &C, unsigned Index, const AttrBuilder &B);
250 
251  /// \brief Add an attribute to the attribute set at the given index. Because
252  /// attribute sets are immutable, this returns a new set.
253  AttributeSet addAttribute(LLVMContext &C, unsigned Index,
254  Attribute::AttrKind Kind) const;
255 
256  /// \brief Add an attribute to the attribute set at the given index. Because
257  /// attribute sets are immutable, this returns a new set.
259  StringRef Value = StringRef()) const;
260 
261  /// Add an attribute to the attribute set at the given indices. Because
262  /// attribute sets are immutable, this returns a new set.
264  Attribute A) const;
265 
266  /// \brief Add attributes to the attribute set at the given index. Because
267  /// attribute sets are immutable, this returns a new set.
268  AttributeSet addAttributes(LLVMContext &C, unsigned Index,
269  AttributeSet Attrs) const;
270 
271  /// \brief Remove the specified attribute at the specified index from this
272  /// attribute list. Because attribute lists are immutable, this returns the
273  /// new list.
274  AttributeSet removeAttribute(LLVMContext &C, unsigned Index,
275  Attribute::AttrKind Kind) const;
276 
277  /// \brief Remove the specified attribute at the specified index from this
278  /// attribute list. Because attribute lists are immutable, this returns the
279  /// new list.
280  AttributeSet removeAttribute(LLVMContext &C, unsigned Index,
281  StringRef Kind) const;
282 
283  /// \brief Remove the specified attributes at the specified index from this
284  /// attribute list. Because attribute lists are immutable, this returns the
285  /// new list.
286  AttributeSet removeAttributes(LLVMContext &C, unsigned Index,
287  AttributeSet Attrs) const;
288 
289  /// \brief Remove the specified attributes at the specified index from this
290  /// attribute list. Because attribute lists are immutable, this returns the
291  /// new list.
292  AttributeSet removeAttributes(LLVMContext &C, unsigned Index,
293  const AttrBuilder &Attrs) const;
294 
295  /// \brief Add the dereferenceable attribute to the attribute set at the given
296  /// index. Because attribute sets are immutable, this returns a new set.
298  uint64_t Bytes) const;
299 
300  /// \brief Add the dereferenceable_or_null attribute to the attribute set at
301  /// the given index. Because attribute sets are immutable, this returns a new
302  /// set.
304  uint64_t Bytes) const;
305 
306  /// Add the allocsize attribute to the attribute set at the given index.
307  /// Because attribute sets are immutable, this returns a new set.
308  AttributeSet addAllocSizeAttr(LLVMContext &C, unsigned Index,
309  unsigned ElemSizeArg,
310  const Optional<unsigned> &NumElemsArg);
311 
312  //===--------------------------------------------------------------------===//
313  // AttributeSet Accessors
314  //===--------------------------------------------------------------------===//
315 
316  /// \brief Retrieve the LLVM context.
317  LLVMContext &getContext() const;
318 
319  /// \brief The attributes for the specified index are returned.
320  AttributeSet getParamAttributes(unsigned Index) const;
321 
322  /// \brief The attributes for the ret value are returned.
324 
325  /// \brief The function attributes are returned.
327 
328  /// \brief Return true if the attribute exists at the given index.
329  bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const;
330 
331  /// \brief Return true if the attribute exists at the given index.
332  bool hasAttribute(unsigned Index, StringRef Kind) const;
333 
334  /// \brief Return true if attribute exists at the given index.
335  bool hasAttributes(unsigned Index) const;
336 
337  /// \brief Equivalent to hasAttribute(AttributeSet::FunctionIndex, Kind) but
338  /// may be faster.
339  bool hasFnAttribute(Attribute::AttrKind Kind) const;
340 
341  /// \brief Equivalent to hasAttribute(AttributeSet::FunctionIndex, Kind) but
342  /// may be faster.
343  bool hasFnAttribute(StringRef Kind) const;
344 
345  /// \brief Return true if the specified attribute is set for at least one
346  /// parameter or for the return value. If Index is not nullptr, the index
347  /// of a parameter with the specified attribute is provided.
349  unsigned *Index = nullptr) const;
350 
351  /// \brief Return the attribute object that exists at the given index.
352  Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const;
353 
354  /// \brief Return the attribute object that exists at the given index.
355  Attribute getAttribute(unsigned Index, StringRef Kind) const;
356 
357  /// \brief Return the alignment for the specified function parameter.
358  unsigned getParamAlignment(unsigned Index) const;
359 
360  /// \brief Get the stack alignment.
361  unsigned getStackAlignment(unsigned Index) const;
362 
363  /// \brief Get the number of dereferenceable bytes (or zero if unknown).
364  uint64_t getDereferenceableBytes(unsigned Index) const;
365 
366  /// \brief Get the number of dereferenceable_or_null bytes (or zero if
367  /// unknown).
368  uint64_t getDereferenceableOrNullBytes(unsigned Index) const;
369 
370  /// Get the allocsize argument numbers (or pair(0, 0) if unknown).
371  std::pair<unsigned, Optional<unsigned>>
372  getAllocSizeArgs(unsigned Index) const;
373 
374  /// \brief Return the attributes at the index as a string.
375  std::string getAsString(unsigned Index, bool InAttrGrp = false) const;
376 
378 
379  iterator begin(unsigned Slot) const;
380  iterator end(unsigned Slot) const;
381 
382  /// operator==/!= - Provide equality predicates.
383  bool operator==(const AttributeSet &RHS) const {
384  return pImpl == RHS.pImpl;
385  }
386  bool operator!=(const AttributeSet &RHS) const {
387  return pImpl != RHS.pImpl;
388  }
389 
390  //===--------------------------------------------------------------------===//
391  // AttributeSet Introspection
392  //===--------------------------------------------------------------------===//
393 
394  /// \brief Return a raw pointer that uniquely identifies this attribute list.
395  void *getRawPointer() const {
396  return pImpl;
397  }
398 
399  /// \brief Return true if there are no attributes.
400  bool isEmpty() const {
401  return getNumSlots() == 0;
402  }
403 
404  /// \brief Return the number of slots used in this attribute list. This is
405  /// the number of arguments that have an attribute set on them (including the
406  /// function itself).
407  unsigned getNumSlots() const;
408 
409  /// \brief Return the index for the given slot.
410  unsigned getSlotIndex(unsigned Slot) const;
411 
412  /// \brief Return the attributes at the given slot.
413  AttributeSet getSlotAttributes(unsigned Slot) const;
414 
415  void dump() const;
416 };
417 
418 //===----------------------------------------------------------------------===//
419 /// \class
420 /// \brief Provide DenseMapInfo for AttributeSet.
421 template<> struct DenseMapInfo<AttributeSet> {
422  static inline AttributeSet getEmptyKey() {
423  uintptr_t Val = static_cast<uintptr_t>(-1);
424  Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
425  return AttributeSet(reinterpret_cast<AttributeSetImpl*>(Val));
426  }
427  static inline AttributeSet getTombstoneKey() {
428  uintptr_t Val = static_cast<uintptr_t>(-2);
429  Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
430  return AttributeSet(reinterpret_cast<AttributeSetImpl*>(Val));
431  }
432  static unsigned getHashValue(AttributeSet AS) {
433  return (unsigned((uintptr_t)AS.pImpl) >> 4) ^
434  (unsigned((uintptr_t)AS.pImpl) >> 9);
435  }
436  static bool isEqual(AttributeSet LHS, AttributeSet RHS) { return LHS == RHS; }
437 };
438 
439 //===----------------------------------------------------------------------===//
440 /// \class
441 /// \brief This class is used in conjunction with the Attribute::get method to
442 /// create an Attribute object. The object itself is uniquified. The Builder's
443 /// value, however, is not. So this can be used as a quick way to test for
444 /// equality, presence of attributes, etc.
445 class AttrBuilder {
446  std::bitset<Attribute::EndAttrKinds> Attrs;
447  std::map<std::string, std::string> TargetDepAttrs;
448  uint64_t Alignment;
449  uint64_t StackAlignment;
450  uint64_t DerefBytes;
451  uint64_t DerefOrNullBytes;
452  uint64_t AllocSizeArgs;
453 
454 public:
456  : Attrs(0), Alignment(0), StackAlignment(0), DerefBytes(0),
457  DerefOrNullBytes(0), AllocSizeArgs(0) {}
459  : Attrs(0), Alignment(0), StackAlignment(0), DerefBytes(0),
460  DerefOrNullBytes(0), AllocSizeArgs(0) {
461  addAttribute(A);
462  }
463  AttrBuilder(AttributeSet AS, unsigned Idx);
464 
465  void clear();
466 
467  /// \brief Add an attribute to the builder.
469 
470  /// \brief Add the Attribute object to the builder.
472 
473  /// \brief Add the target-dependent attribute to the builder.
475 
476  /// \brief Remove an attribute from the builder.
478 
479  /// \brief Remove the attributes from the builder.
480  AttrBuilder &removeAttributes(AttributeSet A, uint64_t Index);
481 
482  /// \brief Remove the target-dependent attribute to the builder.
484 
485  /// \brief Add the attributes from the builder.
486  AttrBuilder &merge(const AttrBuilder &B);
487 
488  /// \brief Remove the attributes from the builder.
489  AttrBuilder &remove(const AttrBuilder &B);
490 
491  /// \brief Return true if the builder has any attribute that's in the
492  /// specified builder.
493  bool overlaps(const AttrBuilder &B) const;
494 
495  /// \brief Return true if the builder has the specified attribute.
497  assert((unsigned)A < Attribute::EndAttrKinds && "Attribute out of range!");
498  return Attrs[A];
499  }
500 
501  /// \brief Return true if the builder has the specified target-dependent
502  /// attribute.
503  bool contains(StringRef A) const;
504 
505  /// \brief Return true if the builder has IR-level attributes.
506  bool hasAttributes() const;
507 
508  /// \brief Return true if the builder has any attribute that's in the
509  /// specified attribute.
510  bool hasAttributes(AttributeSet A, uint64_t Index) const;
511 
512  /// \brief Return true if the builder has an alignment attribute.
513  bool hasAlignmentAttr() const;
514 
515  /// \brief Retrieve the alignment attribute, if it exists.
516  uint64_t getAlignment() const { return Alignment; }
517 
518  /// \brief Retrieve the stack alignment attribute, if it exists.
519  uint64_t getStackAlignment() const { return StackAlignment; }
520 
521  /// \brief Retrieve the number of dereferenceable bytes, if the
522  /// dereferenceable attribute exists (zero is returned otherwise).
523  uint64_t getDereferenceableBytes() const { return DerefBytes; }
524 
525  /// \brief Retrieve the number of dereferenceable_or_null bytes, if the
526  /// dereferenceable_or_null attribute exists (zero is returned otherwise).
527  uint64_t getDereferenceableOrNullBytes() const { return DerefOrNullBytes; }
528 
529  /// Retrieve the allocsize args, if the allocsize attribute exists. If it
530  /// doesn't exist, pair(0, 0) is returned.
531  std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
532 
533  /// \brief This turns an int alignment (which must be a power of 2) into the
534  /// form used internally in Attribute.
535  AttrBuilder &addAlignmentAttr(unsigned Align);
536 
537  /// \brief This turns an int stack alignment (which must be a power of 2) into
538  /// the form used internally in Attribute.
539  AttrBuilder &addStackAlignmentAttr(unsigned Align);
540 
541  /// \brief This turns the number of dereferenceable bytes into the form used
542  /// internally in Attribute.
543  AttrBuilder &addDereferenceableAttr(uint64_t Bytes);
544 
545  /// \brief This turns the number of dereferenceable_or_null bytes into the
546  /// form used internally in Attribute.
547  AttrBuilder &addDereferenceableOrNullAttr(uint64_t Bytes);
548 
549  /// This turns one (or two) ints into the form used internally in Attribute.
550  AttrBuilder &addAllocSizeAttr(unsigned ElemSizeArg,
551  const Optional<unsigned> &NumElemsArg);
552 
553  /// Add an allocsize attribute, using the representation returned by
554  /// Attribute.getIntValue().
555  AttrBuilder &addAllocSizeAttrFromRawRepr(uint64_t RawAllocSizeRepr);
556 
557  /// \brief Return true if the builder contains no target-independent
558  /// attributes.
559  bool empty() const { return Attrs.none(); }
560 
561  // Iterators for target-dependent attributes.
562  typedef std::pair<std::string, std::string> td_type;
563  typedef std::map<std::string, std::string>::iterator td_iterator;
564  typedef std::map<std::string, std::string>::const_iterator td_const_iterator;
567 
568  td_iterator td_begin() { return TargetDepAttrs.begin(); }
569  td_iterator td_end() { return TargetDepAttrs.end(); }
570 
571  td_const_iterator td_begin() const { return TargetDepAttrs.begin(); }
572  td_const_iterator td_end() const { return TargetDepAttrs.end(); }
573 
576  return td_const_range(td_begin(), td_end());
577  }
578 
579  bool td_empty() const { return TargetDepAttrs.empty(); }
580 
581  bool operator==(const AttrBuilder &B);
582  bool operator!=(const AttrBuilder &B) {
583  return !(*this == B);
584  }
585 };
586 
587 namespace AttributeFuncs {
588 
589 /// \brief Which attributes cannot be applied to a type.
591 
592 /// \returns Return true if the two functions have compatible target-independent
593 /// attributes for inlining purposes.
594 bool areInlineCompatible(const Function &Caller, const Function &Callee);
595 
596 /// \brief Merge caller's and callee's attributes.
597 void mergeAttributesForInlining(Function &Caller, const Function &Callee);
598 
599 } // end AttributeFuncs namespace
600 
601 } // end llvm namespace
602 
603 #endif
void AddPointer(const void *Ptr)
Add* - Add various data types to Bit data.
Definition: FoldingSet.cpp:52
void * getRawPointer() const
Return a raw pointer that uniquely identifies this attribute list.
Definition: Attributes.h:395
static AttributeSet getEmptyKey()
Definition: Attributes.h:422
AttributeSet addAllocSizeAttr(LLVMContext &C, unsigned Index, unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Add the allocsize attribute to the attribute set at the given index.
Definition: Attributes.cpp:952
LLVMContext & Context
AttributeSet getParamAttributes(unsigned Index) const
The attributes for the specified index are returned.
Definition: Attributes.cpp:968
unsigned getStackAlignment(unsigned Index) const
Get the stack alignment.
std::string getAsString(unsigned Index, bool InAttrGrp=false) const
Return the attributes at the index as a string.
static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align)
Return a uniquified Attribute object that has the specific alignment set.
Definition: Attributes.cpp:108
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:121
static unsigned getHashValue(AttributeSet AS)
Definition: Attributes.h:432
td_iterator td_end()
Definition: Attributes.h:569
uint64_t getAlignment() const
Retrieve the alignment attribute, if it exists.
Definition: Attributes.h:516
uint64_t getDereferenceableOrNullBytes() const
Retrieve the number of dereferenceable_or_null bytes, if the dereferenceable_or_null attribute exists...
Definition: Attributes.h:527
uint64_t getValueAsInt() const
Return the attribute's value as an integer.
Definition: Attributes.cpp:164
iterator begin(unsigned Slot) const
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
unsigned getParamAlignment(unsigned Index) const
Return the alignment for the specified function parameter.
unsigned getAlignment() const
Returns the alignment field of an attribute as a byte alignment value.
Definition: Attributes.cpp:194
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
Definition: Attributes.cpp:994
bool hasAlignmentAttr() const
Return true if the builder has an alignment attribute.
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
Definition: Attributes.h:496
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
Definition: Attributes.cpp:185
bool areInlineCompatible(const Function &Caller, const Function &Callee)
AttributeSet getRetAttributes() const
The attributes for the ret value are returned.
Definition: Attributes.cpp:976
bool td_empty() const
Definition: Attributes.h:579
StringRef getKindAsString() const
Return the attribute's kind as a string.
Definition: Attributes.cpp:171
uint64_t getDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown).
std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
Definition: Attributes.cpp:226
AttrBuilder & addDereferenceableOrNullAttr(uint64_t Bytes)
This turns the number of dereferenceable_or_null bytes into the form used internally in Attribute...
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:191
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Returns the argument numbers for the allocsize attribute (or pair(0, 0) if not known).
Definition: Attributes.cpp:220
static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:127
AttrBuilder & addAllocSizeAttr(unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
This turns one (or two) ints into the form used internally in Attribute.
No attributes have been set.
Definition: Attributes.h:69
AttributeSet addDereferenceableAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given index.
Definition: Attributes.cpp:936
td_const_range td_attrs() const
Definition: Attributes.h:575
td_const_iterator td_begin() const
Definition: Attributes.h:571
std::map< std::string, std::string >::iterator td_iterator
Definition: Attributes.h:563
uint64_t getDereferenceableBytes() const
Retrieve the number of dereferenceable bytes, if the dereferenceable attribute exists (zero is return...
Definition: Attributes.h:523
static AttributeSet getTombstoneKey()
Definition: Attributes.h:427
llvm::iterator_range< td_const_iterator > td_const_range
Definition: Attributes.h:566
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs(unsigned Index) const
Get the allocsize argument numbers (or pair(0, 0) if unknown).
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
unsigned getStackAlignment() const
Returns the stack alignment field of an attribute as a byte alignment value.
Definition: Attributes.cpp:200
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
struct LLVMOpaqueAttributeRef * LLVMAttributeRef
Used to represent an attributes.
Definition: c/Types.h:116
AttrBuilder & addAllocSizeAttrFromRawRepr(uint64_t RawAllocSizeRepr)
Add an allocsize attribute, using the representation returned by Attribute.getIntValue().
static Attribute getWithStackAlignment(LLVMContext &Context, uint64_t Align)
Definition: Attributes.cpp:114
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:316
std::pair< std::string, std::string > td_type
Definition: Attributes.h:562
uint64_t getDereferenceableBytes() const
Returns the number of dereferenceable bytes from the dereferenceable attribute.
Definition: Attributes.cpp:206
unsigned getNumSlots() const
Return the number of slots used in this attribute list.
bool operator==(const AttrBuilder &B)
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
AttributeSet getSlotAttributes(unsigned Slot) const
Return the attributes at the given slot.
AttributeSet addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
Definition: Attributes.cpp:753
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Retrieve the allocsize args, if the allocsize attribute exists.
bool operator!=(const AttrBuilder &B)
Definition: Attributes.h:582
uint64_t getDereferenceableOrNullBytes(unsigned Index) const
Get the number of dereferenceable_or_null bytes (or zero if unknown).
td_iterator td_begin()
Definition: Attributes.h:568
void dump() const
bool overlaps(const AttrBuilder &B) const
Return true if the builder has any attribute that's in the specified builder.
bool isEnumAttribute() const
Return true if the attribute is an Attribute::AttrKind type.
Definition: Attributes.cpp:145
bool operator==(Attribute A) const
Equality and non-equality operators.
Definition: Attributes.h:164
Sentinal value useful for loops.
Definition: Attributes.h:72
uint64_t getDereferenceableOrNullBytes() const
Returns the number of dereferenceable_or_null bytes from the dereferenceable_or_null attribute...
Definition: Attributes.cpp:213
bool hasFnAttribute(Attribute::AttrKind Kind) const
Equivalent to hasAttribute(AttributeSet::FunctionIndex, Kind) but may be faster.
LLVMContext & getContext() const
Retrieve the LLVM context.
Definition: Attributes.cpp:964
void * getRawPointer() const
Return a raw pointer that uniquely identifies this attribute.
Definition: Attributes.h:175
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
Definition: Attributes.cpp:157
iterator end(unsigned Slot) const
void Profile(FoldingSetNodeID &ID) const
Definition: Attributes.h:170
bool isIntAttribute() const
Return true if the attribute is an integer attribute.
Definition: Attributes.cpp:149
bool empty() const
Return true if the builder contains no target-independent attributes.
Definition: Attributes.h:559
AttrBuilder(const Attribute &A)
Definition: Attributes.h:458
llvm::iterator_range< td_iterator > td_range
Definition: Attributes.h:565
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
void mergeAttributesForInlining(Function &Caller, const Function &Callee)
Merge caller's and callee's attributes.
AttributeSet removeAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const
Remove the specified attributes at the specified index from this attribute list.
Definition: Attributes.cpp:857
static Attribute fromRawPointer(void *RawPtr)
Get an attribute from a raw pointer created by getRawPointer.
Definition: Attributes.h:180
A range adaptor for a pair of iterators.
std::map< std::string, std::string >::const_iterator td_const_iterator
Definition: Attributes.h:564
bool operator<(Attribute A) const
Less-than operator. Useful for sorting the attributes list.
Definition: Attributes.cpp:402
AttributeSet removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
Definition: Attributes.cpp:845
bool operator==(const AttributeSet &RHS) const
operator==/!= - Provide equality predicates.
Definition: Attributes.h:383
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:186
unsigned getSlotIndex(unsigned Slot) const
Return the index for the given slot.
AttributeSet addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable_or_null attribute to the attribute set at the given index.
Definition: Attributes.cpp:943
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
ArrayRef< Attribute >::iterator iterator
Definition: Attributes.h:377
static Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Definition: Attributes.cpp:134
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value...
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:153
td_range td_attrs()
Definition: Attributes.h:574
AttributeSet getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
AttrBuilder & removeAttributes(AttributeSet A, uint64_t Index)
Remove the attributes from the builder.
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
AttrBuilder & merge(const AttrBuilder &B)
Add the attributes from the builder.
const unsigned Kind
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:178
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:71
bool hasAttributes() const
Return true if the builder has IR-level attributes.
AttrBuilder typeIncompatible(Type *Ty)
Which attributes cannot be applied to a type.
AttrBuilder & addStackAlignmentAttr(unsigned Align)
This turns an int stack alignment (which must be a power of 2) into the form used internally in Attri...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
AttrBuilder & addAlignmentAttr(unsigned Align)
This turns an int alignment (which must be a power of 2) into the form used internally in Attribute...
bool operator!=(Attribute A) const
Definition: Attributes.h:165
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const DataLayout *DL, DominatorTree *DT=nullptr)
This lazily constructs the LazyValueInfoImpl.
static bool isEqual(AttributeSet LHS, AttributeSet RHS)
Definition: Attributes.h:436
AttributeSet addAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const
Add attributes to the attribute set at the given index.
Definition: Attributes.cpp:796
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
td_const_iterator td_end() const
Definition: Attributes.h:572
bool isEmpty() const
Return true if there are no attributes.
Definition: Attributes.h:400
uint64_t getStackAlignment() const
Retrieve the stack alignment attribute, if it exists.
Definition: Attributes.h:519
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Definition: Attributes.h:67
AttributeSet getFnAttributes() const
The function attributes are returned.
Definition: Attributes.cpp:985
bool operator!=(const AttributeSet &RHS) const
Definition: Attributes.h:386