LLVM 24.0.0git
Attributes.h
Go to the documentation of this file.
1//===- llvm/Attributes.h - Container for Attributes -------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// This file contains the simple types necessary to represent the
11/// attributes associated with functions and their calls.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_IR_ATTRIBUTES_H
16#define LLVM_IR_ATTRIBUTES_H
17
18#include "llvm-c/Types.h"
19#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/Hashing.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/Config/llvm-config.h"
27#include "llvm/Support/ModRef.h"
29#include <cassert>
30#include <climits>
31#include <cstdint>
32#include <optional>
33#include <string>
34#include <type_traits>
35#include <utility>
36
37namespace llvm {
38
39class AttrBuilder;
40class AttributeMask;
41class AttributeImpl;
44class ConstantRange;
46class Function;
47class LLVMContext;
48class Instruction;
49class Type;
50class raw_ostream;
51enum FPClassTest : unsigned;
52struct DenormalFPEnv;
53
54enum class AllocFnKind : uint64_t {
56 Alloc = 1 << 0, // Allocator function returns a new allocation
57 Realloc = 1 << 1, // Allocator function resizes the `allocptr` argument
58 Free = 1 << 2, // Allocator function frees the `allocptr` argument
59 Uninitialized = 1 << 3, // Allocator function returns uninitialized memory
60 Zeroed = 1 << 4, // Allocator function returns zeroed memory
61 Aligned = 1 << 5, // Allocator function aligns allocations per the
62 // `allocalign` argument
63 LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ Aligned)
64};
65
67public:
68 DeadOnReturnInfo() : DeadBytes(std::nullopt) {}
69 DeadOnReturnInfo(uint64_t DeadOnReturnBytes) : DeadBytes(DeadOnReturnBytes) {}
70
72 assert(DeadBytes.has_value() &&
73 "This attribute does not specify a byte count. Did you forget to "
74 "check if the attribute covers all reachable memory?");
75 return DeadBytes.value();
76 }
77
78 bool coversAllReachableMemory() const { return !DeadBytes.has_value(); }
79
81 if (Data == std::numeric_limits<uint64_t>::max())
82 return DeadOnReturnInfo();
83 return DeadOnReturnInfo(Data);
84 }
85
87 if (DeadBytes.has_value())
88 return DeadBytes.value();
89 return std::numeric_limits<uint64_t>::max();
90 }
91
92 bool isZeroSized() const {
93 return DeadBytes.has_value() && DeadBytes.value() == 0;
94 }
95
96private:
97 std::optional<uint64_t> DeadBytes;
98};
99
100//===----------------------------------------------------------------------===//
101/// \class
102/// Functions, function parameters, and return types can have attributes
103/// to indicate how they should be treated by optimizations and code
104/// generation. This class represents one of those attributes. It's light-weight
105/// and should be passed around by-value.
106class Attribute {
107public:
108 /// This enumeration lists the attributes that can be associated with
109 /// parameters, function results, or the function itself.
110 ///
111 /// Note: The `uwtable' attribute is about the ABI or the user mandating an
112 /// entry in the unwind table. The `nounwind' attribute is about an exception
113 /// passing by the function.
114 ///
115 /// In a theoretical system that uses tables for profiling and SjLj for
116 /// exceptions, they would be fully independent. In a normal system that uses
117 /// tables for both, the semantics are:
118 ///
119 /// nil = Needs an entry because an exception might pass by.
120 /// nounwind = No need for an entry
121 /// uwtable = Needs an entry because the ABI says so and because
122 /// an exception might pass by.
123 /// uwtable + nounwind = Needs an entry because the ABI says so.
124
125 enum AttrKind : unsigned {
126 // IR-Level Attributes
127 None, ///< No attributes have been set
128#define GET_ATTR_ENUM
129 #include "llvm/IR/Attributes.inc"
130 EndAttrKinds, ///< Sentinel value useful for loops
131 };
132
133 static const unsigned NumEnumAttrKinds = LastEnumAttr - FirstEnumAttr + 1;
134 static const unsigned NumIntAttrKinds = LastIntAttr - FirstIntAttr + 1;
135 static const unsigned NumTypeAttrKinds = LastTypeAttr - FirstTypeAttr + 1;
136
137 static bool isEnumAttrKind(AttrKind Kind) {
138 return Kind >= FirstEnumAttr && Kind <= LastEnumAttr;
139 }
140 static bool isIntAttrKind(AttrKind Kind) {
141 return Kind >= FirstIntAttr && Kind <= LastIntAttr;
142 }
143 static bool isTypeAttrKind(AttrKind Kind) {
144 return Kind >= FirstTypeAttr && Kind <= LastTypeAttr;
145 }
147 return Kind >= FirstConstantRangeAttr && Kind <= LastConstantRangeAttr;
148 }
150 return Kind >= FirstConstantRangeListAttr &&
151 Kind <= LastConstantRangeListAttr;
152 }
153
154 LLVM_ABI static bool canUseAsFnAttr(AttrKind Kind);
155 LLVM_ABI static bool canUseAsParamAttr(AttrKind Kind);
156 LLVM_ABI static bool canUseAsRetAttr(AttrKind Kind);
157
158 LLVM_ABI static bool intersectMustPreserve(AttrKind Kind);
159 LLVM_ABI static bool intersectWithAnd(AttrKind Kind);
160 LLVM_ABI static bool intersectWithMin(AttrKind Kind);
161 LLVM_ABI static bool intersectWithCustom(AttrKind Kind);
162
163 /// Whether this is an ABI attribute (for returns or arguments).
164 LLVM_ABI static bool isABIAttr(AttrKind Kind);
165
166private:
167 AttributeImpl *pImpl = nullptr;
168
169 Attribute(AttributeImpl *A) : pImpl(A) {}
170
171public:
172 Attribute() = default;
173
174 //===--------------------------------------------------------------------===//
175 // Attribute Construction
176 //===--------------------------------------------------------------------===//
177
178 /// Return a uniquified Attribute object.
179 LLVM_ABI static Attribute get(LLVMContext &Context, AttrKind Kind,
180 uint64_t Val = 0);
181 LLVM_ABI static Attribute get(LLVMContext &Context, StringRef Kind,
182 StringRef Val = StringRef());
183 LLVM_ABI static Attribute get(LLVMContext &Context, AttrKind Kind, Type *Ty);
184 LLVM_ABI static Attribute get(LLVMContext &Context, AttrKind Kind,
185 const ConstantRange &CR);
186 LLVM_ABI static Attribute get(LLVMContext &Context, AttrKind Kind,
188
189 /// Return a uniquified Attribute object that has the specific
190 /// alignment set.
192 Align Alignment);
194 Align Alignment);
196 uint64_t Bytes);
197 LLVM_ABI static Attribute
199 LLVM_ABI static Attribute
200 getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg,
201 const std::optional<unsigned> &NumElemsArg);
203 AllocFnKind Kind);
205 unsigned MinValue,
206 unsigned MaxValue);
207 LLVM_ABI static Attribute getWithByValType(LLVMContext &Context, Type *Ty);
209 Type *Ty);
210 LLVM_ABI static Attribute getWithByRefType(LLVMContext &Context, Type *Ty);
212 Type *Ty);
213 LLVM_ABI static Attribute getWithInAllocaType(LLVMContext &Context, Type *Ty);
215 UWTableKind Kind);
217 MemoryEffects ME);
219 FPClassTest Mask);
223 CaptureInfo CI);
224
225 /// For a typed attribute, return the equivalent attribute with the type
226 /// changed to \p ReplacementTy.
227 Attribute getWithNewType(LLVMContext &Context, Type *ReplacementTy) {
228 assert(isTypeAttribute() && "this requires a typed attribute");
229 return get(Context, getKindAsEnum(), ReplacementTy);
230 }
231
233
235
236 //===--------------------------------------------------------------------===//
237 // Attribute Accessors
238 //===--------------------------------------------------------------------===//
239
240 /// Return true if the attribute is an Attribute::AttrKind type.
241 LLVM_ABI bool isEnumAttribute() const;
242
243 /// Return true if the attribute is an integer attribute.
244 LLVM_ABI bool isIntAttribute() const;
245
246 /// Return true if the attribute is a string (target-dependent)
247 /// attribute.
248 LLVM_ABI bool isStringAttribute() const;
249
250 /// Return true if the attribute is a type attribute.
251 LLVM_ABI bool isTypeAttribute() const;
252
253 /// Return true if the attribute is a ConstantRange attribute.
255
256 /// Return true if the attribute is a ConstantRangeList attribute.
258
259 /// Return true if the attribute is any kind of attribute.
260 bool isValid() const { return pImpl; }
261
262 /// Return true if the attribute is present.
263 LLVM_ABI bool hasAttribute(AttrKind Val) const;
264
265 /// Return true if the target-dependent attribute is present.
266 LLVM_ABI bool hasAttribute(StringRef Val) const;
267
268 /// Returns true if the attribute's kind can be represented as an enum (Enum,
269 /// Integer, Type, ConstantRange, or ConstantRangeList attribute).
270 bool hasKindAsEnum() const { return !isStringAttribute(); }
271
272 /// Return the attribute's kind as an enum (Attribute::AttrKind). This
273 /// requires the attribute be representable as an enum (see: `hasKindAsEnum`).
275
276 /// Return the attribute's value as an integer. This requires that the
277 /// attribute be an integer attribute.
279
280 /// Return the attribute's value as a boolean. This requires that the
281 /// attribute be a string attribute.
282 LLVM_ABI bool getValueAsBool() const;
283
284 /// Return the attribute's kind as a string. This requires the
285 /// attribute to be a string attribute.
287
288 /// Return the attribute's value as a string. This requires the
289 /// attribute to be a string attribute.
291
292 /// Return the attribute's value as a Type. This requires the attribute to be
293 /// a type attribute.
295
296 /// Return the attribute's value as a ConstantRange. This requires the
297 /// attribute to be a ConstantRange attribute.
299
300 /// Return the attribute's value as a ConstantRange array. This requires the
301 /// attribute to be a ConstantRangeList attribute.
303
304 /// Returns the alignment field of an attribute as a byte alignment
305 /// value.
307
308 /// Returns the stack alignment field of an attribute as a byte
309 /// alignment value.
311
312 /// Returns the number of dereferenceable bytes from the
313 /// dereferenceable attribute.
315
316 /// Returns the number of dead_on_return bytes from the dead_on_return
317 /// attribute, or std::nullopt if all memory reachable through the pointer is
318 /// marked dead on return.
320
321 /// Returns the number of dereferenceable_or_null bytes from the
322 /// dereferenceable_or_null attribute.
324
325 /// Returns the argument numbers for the allocsize attribute.
326 LLVM_ABI std::pair<unsigned, std::optional<unsigned>>
327 getAllocSizeArgs() const;
328
329 /// Returns the minimum value for the vscale_range attribute.
330 LLVM_ABI unsigned getVScaleRangeMin() const;
331
332 /// Returns the maximum value for the vscale_range attribute or std::nullopt
333 /// when unknown.
334 LLVM_ABI std::optional<unsigned> getVScaleRangeMax() const;
335
336 // Returns the unwind table kind.
338
339 // Returns the allocator function kind.
341
342 /// Returns memory effects.
344
345 /// Returns denormal_fpenv.
347
348 /// Returns information from captures attribute.
350
351 /// Return the FPClassTest for nofpclass
353
354 /// Returns the value of the range attribute.
355 LLVM_ABI const ConstantRange &getRange() const;
356
357 /// Returns the value of the initializes attribute.
359
360 /// The Attribute is converted to a string of equivalent mnemonic. This
361 /// is, presumably, for writing out the mnemonics for the assembly writer.
362 LLVM_ABI std::string getAsString(bool InAttrGrp = false) const;
363
364 /// Return true if this attribute belongs to the LLVMContext.
366
367 /// Equality and non-equality operators.
368 bool operator==(Attribute A) const { return pImpl == A.pImpl; }
369 bool operator!=(Attribute A) const { return pImpl != A.pImpl; }
370
371 /// Used to sort attribute by kind.
372 LLVM_ABI int cmpKind(Attribute A) const;
373
374 /// Less-than operator. Useful for sorting the attributes list.
375 LLVM_ABI bool operator<(Attribute A) const;
376
377 /// Return a raw pointer that uniquely identifies this attribute.
378 void *getRawPointer() const {
379 return pImpl;
380 }
381
382 /// Get an attribute from a raw pointer created by getRawPointer.
383 static Attribute fromRawPointer(void *RawPtr) {
384 return Attribute(reinterpret_cast<AttributeImpl*>(RawPtr));
385 }
386};
387
388// Specialized opaque value conversions.
390 return reinterpret_cast<LLVMAttributeRef>(Attr.getRawPointer());
391}
392
393// Specialized opaque value conversions.
395 return Attribute::fromRawPointer(Attr);
396}
397
398/// A bitset with a bit for each enum attribute kind.
400 uint8_t AvailableAttrs[16] = {};
401 static_assert(Attribute::EndAttrKinds <= sizeof(AvailableAttrs) * CHAR_BIT,
402 "Too many attributes");
403
404public:
406 return AvailableAttrs[Kind / 8] & (1 << (Kind % 8));
407 }
408
410 AvailableAttrs[Kind / 8] |= 1 << (Kind % 8);
411 }
412};
413
414/// The enum attributes available in an AttributeSetNode, so that AttributeSet
415/// can query them inline.
417protected:
419
420public:
422 return AvailableAttrs.hasAttribute(Kind);
423 }
424};
425
426/// The enum function attributes available in an AttributeListImpl, so that
427/// AttributeList can query them inline.
429protected:
431
432public:
433 /// Return true if the function has an enum attribute of the given kind.
435 return AvailableFunctionAttrs.hasAttribute(Kind);
436 }
437};
438
439//===----------------------------------------------------------------------===//
440/// \class
441/// This class holds the attributes for a particular argument, parameter,
442/// function, or return value. It is an immutable value type that is cheap to
443/// copy. Adding and removing enum attributes is intended to be fast, but adding
444/// and removing string or integer attributes involves a FoldingSet lookup.
445class AttributeSet {
446 friend AttributeListImpl;
447 template <typename Ty, typename Enable> friend struct DenseMapInfo;
448
449 // TODO: Extract AvailableAttrs from AttributeSetNode and store them here.
450 // This will allow an efficient implementation of addAttribute and
451 // removeAttribute for enum attrs.
452
453 /// Private implementation pointer.
454 AttributeSetNodeBase *SetNode = nullptr;
455
456private:
458
459 /// Return the implementation of this set.
460 AttributeSetNode *getNode() const;
461
462public:
463 /// AttributeSet is a trivially copyable value type.
464 AttributeSet() = default;
465 AttributeSet(const AttributeSet &) = default;
466 ~AttributeSet() = default;
467
468 LLVM_ABI static AttributeSet get(LLVMContext &C, const AttrBuilder &B);
469 LLVM_ABI static AttributeSet get(LLVMContext &C, ArrayRef<Attribute> Attrs);
470
471 bool operator==(const AttributeSet &O) const { return SetNode == O.SetNode; }
472 bool operator!=(const AttributeSet &O) const { return !(*this == O); }
473
474 /// Add an argument attribute. Returns a new set because attribute sets are
475 /// immutable.
476 [[nodiscard]] LLVM_ABI AttributeSet
478
479 /// Add a target-dependent attribute. Returns a new set because attribute sets
480 /// are immutable.
481 [[nodiscard]] LLVM_ABI AttributeSet addAttribute(
482 LLVMContext &C, StringRef Kind, StringRef Value = StringRef()) const;
483
484 /// Add attributes to the attribute set. Returns a new set because attribute
485 /// sets are immutable.
487 AttributeSet AS) const;
488
489 /// Add attributes to the attribute set. Returns a new set because attribute
490 /// sets are immutable.
492 const AttrBuilder &B) const;
493
494 /// Add attributes to the attribute set, replacing attributes of the same
495 /// kind. \p Attrs must be sorted like an attribute set, with at most one
496 /// attribute of each kind. Returns a new set because attribute sets are
497 /// immutable.
498 [[nodiscard]] LLVM_ABI AttributeSet
500
501 /// Remove the specified attribute from this set. Returns a new set because
502 /// attribute sets are immutable.
503 [[nodiscard]] LLVM_ABI AttributeSet
505
506 /// Remove the specified attribute from this set. Returns a new set because
507 /// attribute sets are immutable.
509 StringRef Kind) const;
510
511 /// Remove the specified attributes from this set. Returns a new set because
512 /// attribute sets are immutable.
513 [[nodiscard]] LLVM_ABI AttributeSet
514 removeAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const;
515
516 /// Try to intersect this AttributeSet with Other. Returns std::nullopt if
517 /// the two lists are inherently incompatible (imply different behavior, not
518 /// just analysis).
519 [[nodiscard]] LLVM_ABI std::optional<AttributeSet>
521
522 /// Return the number of attributes in this set.
523 LLVM_ABI unsigned getNumAttributes() const;
524
525 /// Return true if attributes exists in this set.
526 bool hasAttributes() const { return SetNode != nullptr; }
527
528 /// Return true if the attribute exists in this set.
530 return SetNode && SetNode->hasAttribute(Kind);
531 }
532
533 /// Return true if the attribute exists in this set.
534 LLVM_ABI bool hasAttribute(StringRef Kind) const;
535
536 /// Return the attribute object.
538
539 /// Return the target-dependent attribute object.
541
547 LLVM_ABI Type *getByValType() const;
549 LLVM_ABI Type *getByRefType() const;
553 LLVM_ABI std::optional<std::pair<unsigned, std::optional<unsigned>>>
554 getAllocSizeArgs() const;
555 LLVM_ABI unsigned getVScaleRangeMin() const;
556 LLVM_ABI std::optional<unsigned> getVScaleRangeMax() const;
562 LLVM_ABI std::string getAsString(bool InAttrGrp = false) const;
563
564 /// Return true if this attribute set belongs to the LLVMContext.
566
567 using iterator = const Attribute *;
568
569 LLVM_ABI iterator begin() const;
570 LLVM_ABI iterator end() const;
571#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
572 void dump() const;
573#endif
574};
575
576//===----------------------------------------------------------------------===//
577/// \class
578/// Provide DenseMapInfo for AttributeSet.
579template <> struct DenseMapInfo<AttributeSet, void> {
580 static unsigned getHashValue(AttributeSet AS) {
582 }
583
584 static bool isEqual(AttributeSet LHS, AttributeSet RHS) { return LHS == RHS; }
585};
586
587namespace hashing::detail {
588// Attribute and AttributeSet are trivial wrappers whose operator== is pointer
589// equality, so hashing the bytes is equivalent to hashing the values. Define
590// is_hashable_data to pick the contiguous hash_combine_range path.
591template <> struct is_hashable_data<Attribute> : std::true_type {};
592template <> struct is_hashable_data<AttributeSet> : std::true_type {};
593static_assert(std::has_unique_object_representations_v<Attribute> &&
594 std::has_unique_object_representations_v<AttributeSet>,
595 "hashing the bytes requires unique object representations");
596} // namespace hashing::detail
597
598//===----------------------------------------------------------------------===//
599/// \class
600/// This class holds the attributes for a function, its return value, and
601/// its parameters. You access the attributes for each of them via an index into
602/// the AttributeList object. The function attributes are at index
603/// `AttributeList::FunctionIndex', the return value is at index
604/// `AttributeList::ReturnIndex', and the attributes for the parameters start at
605/// index `AttributeList::FirstArgIndex'.
606class AttributeList {
607public:
608 enum AttrIndex : unsigned {
609 ReturnIndex = 0U,
610 FunctionIndex = ~0U,
611 FirstArgIndex = 1,
612 };
613
614private:
615 friend class AttrBuilder;
616 friend class AttributeListImpl;
617 friend class AttributeSet;
618 friend class AttributeSetNode;
619 template <typename Ty, typename Enable> friend struct DenseMapInfo;
620
621 /// The attributes that we are managing. This can be null to represent
622 /// the empty attributes list.
623 AttributeListImplBase *pImpl = nullptr;
624
625 /// Return the implementation of this list.
626 AttributeListImpl *getListImpl() const;
627
628public:
629 /// Create an AttributeList with the specified parameters in it.
631 get(LLVMContext &C, ArrayRef<std::pair<unsigned, Attribute>> Attrs);
633 get(LLVMContext &C, ArrayRef<std::pair<unsigned, AttributeSet>> Attrs);
634
635 /// Create an AttributeList from attribute sets for a function, its
636 /// return value, and all of its arguments.
638 AttributeSet RetAttrs,
639 ArrayRef<AttributeSet> ArgAttrs);
640
641private:
643
644 static AttributeList getImpl(LLVMContext &C, ArrayRef<AttributeSet> AttrSets);
645
646public:
647 AttributeList() = default;
648
649 //===--------------------------------------------------------------------===//
650 // AttributeList Construction and Mutation
651 //===--------------------------------------------------------------------===//
652
653 /// Return an AttributeList with the specified parameters in it.
656 LLVM_ABI static AttributeList get(LLVMContext &C, unsigned Index,
658 LLVM_ABI static AttributeList get(LLVMContext &C, unsigned Index,
661 LLVM_ABI static AttributeList get(LLVMContext &C, unsigned Index,
663 LLVM_ABI static AttributeList get(LLVMContext &C, unsigned Index,
664 AttributeSet Attrs);
665 LLVM_ABI static AttributeList get(LLVMContext &C, unsigned Index,
666 const AttrBuilder &B);
667
668 /// Set the attribute set at the given index.
669 /// Returns a new list because attribute lists are immutable.
670 [[nodiscard]] LLVM_ABI AttributeList setAttributesAtIndex(
671 LLVMContext &C, unsigned Index, AttributeSet Attrs) const;
672
673 // TODO: remove non-AtIndex versions of these methods.
674 /// Add an attribute to the attribute set at the given index.
675 /// Returns a new list because attribute lists are immutable.
676 [[nodiscard]] LLVM_ABI AttributeList addAttributeAtIndex(
677 LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const;
678
679 /// Add an attribute to the attribute set at the given index.
680 /// Returns a new list because attribute lists are immutable.
681 [[nodiscard]] LLVM_ABI AttributeList
682 addAttributeAtIndex(LLVMContext &C, unsigned Index, StringRef Kind,
683 StringRef Value = StringRef()) const;
684
685 /// Add an attribute to the attribute set at the given index.
686 /// Returns a new list because attribute lists are immutable.
687 [[nodiscard]] LLVM_ABI AttributeList addAttributeAtIndex(LLVMContext &C,
688 unsigned Index,
689 Attribute A) const;
690
691 /// Add attributes to the attribute set at the given index.
692 /// Returns a new list because attribute lists are immutable.
693 [[nodiscard]] LLVM_ABI AttributeList addAttributesAtIndex(
694 LLVMContext &C, unsigned Index, const AttrBuilder &B) const;
695
696 /// Add attributes to the attribute set at the given index, as
697 /// AttributeSet::addAttributes does. Returns a new list because attribute
698 /// lists are immutable.
699 [[nodiscard]] LLVM_ABI AttributeList addSortedAttributesAtIndex(
700 LLVMContext &C, unsigned Index, ArrayRef<Attribute> Attrs) const;
701
702 /// Add a function attribute to the list. Returns a new list because
703 /// attribute lists are immutable.
704 [[nodiscard]] AttributeList addFnAttribute(LLVMContext &C,
705 Attribute::AttrKind Kind) const {
706 return addAttributeAtIndex(C, FunctionIndex, Kind);
707 }
708
709 /// Add a function attribute to the list. Returns a new list because
710 /// attribute lists are immutable.
711 [[nodiscard]] AttributeList addFnAttribute(LLVMContext &C,
712 Attribute Attr) const {
713 return addAttributeAtIndex(C, FunctionIndex, Attr);
714 }
715
716 /// Add a function attribute to the list. Returns a new list because
717 /// attribute lists are immutable.
718 [[nodiscard]] AttributeList
719 addFnAttribute(LLVMContext &C, StringRef Kind,
720 StringRef Value = StringRef()) const {
721 return addAttributeAtIndex(C, FunctionIndex, Kind, Value);
722 }
723
724 /// Add function attribute to the list. Returns a new list because
725 /// attribute lists are immutable.
726 [[nodiscard]] AttributeList addFnAttributes(LLVMContext &C,
727 const AttrBuilder &B) const {
728 return addAttributesAtIndex(C, FunctionIndex, B);
729 }
730
731 /// Add a return value attribute to the list. Returns a new list because
732 /// attribute lists are immutable.
733 [[nodiscard]] AttributeList addRetAttribute(LLVMContext &C,
734 Attribute::AttrKind Kind) const {
735 return addAttributeAtIndex(C, ReturnIndex, Kind);
736 }
737
738 /// Add a return value attribute to the list. Returns a new list because
739 /// attribute lists are immutable.
740 [[nodiscard]] AttributeList addRetAttribute(LLVMContext &C,
741 Attribute Attr) const {
742 return addAttributeAtIndex(C, ReturnIndex, Attr);
743 }
744
745 /// Add a return value attribute to the list. Returns a new list because
746 /// attribute lists are immutable.
747 [[nodiscard]] AttributeList addRetAttributes(LLVMContext &C,
748 const AttrBuilder &B) const {
749 return addAttributesAtIndex(C, ReturnIndex, B);
750 }
751
752 /// Add a return value attribute to the list. Returns a new list because
753 /// attribute lists are immutable.
754 [[nodiscard]] AttributeList
755 maybeAddRetAttribute(LLVMContext &C, Attribute::AttrKind Kind) const {
756 if (Kind != Attribute::AttrKind::None)
757 return addAttributeAtIndex(C, ReturnIndex, Kind);
758 return *this;
759 }
760
761 /// Add an argument attribute to the list. Returns a new list because
762 /// attribute lists are immutable.
763 [[nodiscard]] AttributeList
764 addParamAttribute(LLVMContext &C, unsigned ArgNo,
765 Attribute::AttrKind Kind) const {
766 return addAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind);
767 }
768
769 /// Add an argument attribute to the list. Returns a new list because
770 /// attribute lists are immutable.
771 [[nodiscard]] AttributeList
772 addParamAttribute(LLVMContext &C, unsigned ArgNo, StringRef Kind,
773 StringRef Value = StringRef()) const {
774 return addAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind, Value);
775 }
776
777 /// Add an attribute to the attribute list at the given arg indices. Returns a
778 /// new list because attribute lists are immutable.
779 [[nodiscard]] LLVM_ABI AttributeList addParamAttribute(
780 LLVMContext &C, ArrayRef<unsigned> ArgNos, Attribute A) const;
781
782 /// Add an argument attribute to the list. Returns a new list because
783 /// attribute lists are immutable.
784 [[nodiscard]] AttributeList addParamAttributes(LLVMContext &C, unsigned ArgNo,
785 const AttrBuilder &B) const {
786 return addAttributesAtIndex(C, ArgNo + FirstArgIndex, B);
787 }
788
789 /// Add an argument attribute to the list. Returns a new list because
790 /// attribute lists are immutable.
791 [[nodiscard]] AttributeList
792 maybeAddParamAttribute(LLVMContext &C, unsigned ArgNo,
793 Attribute::AttrKind Kind) const {
794 if (Kind != Attribute::AttrKind::None)
795 return addParamAttribute(C, ArgNo, Kind);
796 return *this;
797 }
798
799 /// Remove the specified attribute at the specified index from this
800 /// attribute list. Returns a new list because attribute lists are immutable.
801 [[nodiscard]] LLVM_ABI AttributeList removeAttributeAtIndex(
802 LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const;
803
804 /// Remove the specified attribute at the specified index from this
805 /// attribute list. Returns a new list because attribute lists are immutable.
806 [[nodiscard]] LLVM_ABI AttributeList
807 removeAttributeAtIndex(LLVMContext &C, unsigned Index, StringRef Kind) const;
808 [[nodiscard]] AttributeList removeAttribute(LLVMContext &C, unsigned Index,
809 StringRef Kind) const {
810 return removeAttributeAtIndex(C, Index, Kind);
811 }
812
813 /// Remove the specified attributes at the specified index from this
814 /// attribute list. Returns a new list because attribute lists are immutable.
815 [[nodiscard]] LLVM_ABI AttributeList removeAttributesAtIndex(
816 LLVMContext &C, unsigned Index, const AttributeMask &AttrsToRemove) const;
817
818 /// Remove all attributes at the specified index from this
819 /// attribute list. Returns a new list because attribute lists are immutable.
820 [[nodiscard]] LLVM_ABI AttributeList
821 removeAttributesAtIndex(LLVMContext &C, unsigned Index) const;
822
823 /// Remove the specified attribute at the function index from this
824 /// attribute list. Returns a new list because attribute lists are immutable.
825 [[nodiscard]] AttributeList
826 removeFnAttribute(LLVMContext &C, Attribute::AttrKind Kind) const {
827 return removeAttributeAtIndex(C, FunctionIndex, Kind);
828 }
829
830 /// Remove the specified attribute at the function index from this
831 /// attribute list. Returns a new list because attribute lists are immutable.
832 [[nodiscard]] AttributeList removeFnAttribute(LLVMContext &C,
833 StringRef Kind) const {
834 return removeAttributeAtIndex(C, FunctionIndex, Kind);
835 }
836
837 /// Remove the specified attribute at the function index from this
838 /// attribute list. Returns a new list because attribute lists are immutable.
839 [[nodiscard]] AttributeList
840 removeFnAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const {
841 return removeAttributesAtIndex(C, FunctionIndex, AttrsToRemove);
842 }
843
844 /// Remove the attributes at the function index from this
845 /// attribute list. Returns a new list because attribute lists are immutable.
846 [[nodiscard]] AttributeList removeFnAttributes(LLVMContext &C) const {
847 return removeAttributesAtIndex(C, FunctionIndex);
848 }
849
850 /// Remove the specified attribute at the return value index from this
851 /// attribute list. Returns a new list because attribute lists are immutable.
852 [[nodiscard]] AttributeList
853 removeRetAttribute(LLVMContext &C, Attribute::AttrKind Kind) const {
854 return removeAttributeAtIndex(C, ReturnIndex, Kind);
855 }
856
857 /// Remove the specified attribute at the return value index from this
858 /// attribute list. Returns a new list because attribute lists are immutable.
859 [[nodiscard]] AttributeList removeRetAttribute(LLVMContext &C,
860 StringRef Kind) const {
861 return removeAttributeAtIndex(C, ReturnIndex, Kind);
862 }
863
864 /// Remove the specified attribute at the return value index from this
865 /// attribute list. Returns a new list because attribute lists are immutable.
866 [[nodiscard]] AttributeList
867 removeRetAttributes(LLVMContext &C,
868 const AttributeMask &AttrsToRemove) const {
869 return removeAttributesAtIndex(C, ReturnIndex, AttrsToRemove);
870 }
871
872 /// Remove the specified attribute at the specified arg index from this
873 /// attribute list. Returns a new list because attribute lists are immutable.
874 [[nodiscard]] AttributeList
875 removeParamAttribute(LLVMContext &C, unsigned ArgNo,
876 Attribute::AttrKind Kind) const {
877 return removeAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind);
878 }
879
880 /// Remove the specified attribute at the specified arg index from this
881 /// attribute list. Returns a new list because attribute lists are immutable.
882 [[nodiscard]] AttributeList
883 removeParamAttribute(LLVMContext &C, unsigned ArgNo, StringRef Kind) const {
884 return removeAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind);
885 }
886
887 /// Remove the specified attribute at the specified arg index from this
888 /// attribute list. Returns a new list because attribute lists are immutable.
889 [[nodiscard]] AttributeList
890 removeParamAttributes(LLVMContext &C, unsigned ArgNo,
891 const AttributeMask &AttrsToRemove) const {
892 return removeAttributesAtIndex(C, ArgNo + FirstArgIndex, AttrsToRemove);
893 }
894
895 /// Remove all attributes at the specified arg index from this
896 /// attribute list. Returns a new list because attribute lists are immutable.
897 [[nodiscard]] AttributeList removeParamAttributes(LLVMContext &C,
898 unsigned ArgNo) const {
899 return removeAttributesAtIndex(C, ArgNo + FirstArgIndex);
900 }
901
902 /// Replace the type contained by attribute \p AttrKind at index \p ArgNo wih
903 /// \p ReplacementTy, preserving all other attributes.
904 [[nodiscard]] AttributeList
905 replaceAttributeTypeAtIndex(LLVMContext &C, unsigned ArgNo,
906 Attribute::AttrKind Kind,
907 Type *ReplacementTy) const {
908 Attribute Attr = getAttributeAtIndex(ArgNo, Kind);
909 auto Attrs = removeAttributeAtIndex(C, ArgNo, Kind);
910 return Attrs.addAttributeAtIndex(C, ArgNo,
911 Attr.getWithNewType(C, ReplacementTy));
912 }
913
914 /// \brief Add the dereferenceable attribute to the attribute set at the given
915 /// index. Returns a new list because attribute lists are immutable.
916 [[nodiscard]] LLVM_ABI AttributeList
917 addDereferenceableRetAttr(LLVMContext &C, uint64_t Bytes) const;
918
919 /// \brief Add the dereferenceable attribute to the attribute set at the given
920 /// arg index. Returns a new list because attribute lists are immutable.
921 [[nodiscard]] LLVM_ABI AttributeList addDereferenceableParamAttr(
922 LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const;
923
924 /// Add the dereferenceable_or_null attribute to the attribute set at
925 /// the given arg index. Returns a new list because attribute lists are
926 /// immutable.
927 [[nodiscard]] LLVM_ABI AttributeList addDereferenceableOrNullParamAttr(
928 LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const;
929
930 /// Add the range attribute to the attribute set at the return value index.
931 /// Returns a new list because attribute lists are immutable.
932 [[nodiscard]] LLVM_ABI AttributeList
933 addRangeRetAttr(LLVMContext &C, const ConstantRange &CR) const;
934
935 /// Add the allocsize attribute to the attribute set at the given arg index.
936 /// Returns a new list because attribute lists are immutable.
937 [[nodiscard]] LLVM_ABI AttributeList
938 addAllocSizeParamAttr(LLVMContext &C, unsigned ArgNo, unsigned ElemSizeArg,
939 const std::optional<unsigned> &NumElemsArg) const;
940
941 /// Try to intersect this AttributeList with Other. Returns std::nullopt if
942 /// the two lists are inherently incompatible (imply different behavior, not
943 /// just analysis).
944 [[nodiscard]] LLVM_ABI std::optional<AttributeList>
945 intersectWith(LLVMContext &C, AttributeList Other) const;
946
947 //===--------------------------------------------------------------------===//
948 // AttributeList Accessors
949 //===--------------------------------------------------------------------===//
950
951 /// The attributes for the specified index are returned.
952 LLVM_ABI AttributeSet getAttributes(unsigned Index) const;
953
954 /// The attributes for the argument or parameter at the given index are
955 /// returned.
956 LLVM_ABI AttributeSet getParamAttrs(unsigned ArgNo) const;
957
958 /// The attributes for the ret value are returned.
959 LLVM_ABI AttributeSet getRetAttrs() const;
960
961 /// The function attributes are returned.
962 LLVM_ABI AttributeSet getFnAttrs() const;
963
964 /// Return true if the attribute exists at the given index.
965 LLVM_ABI bool hasAttributeAtIndex(unsigned Index,
966 Attribute::AttrKind Kind) const;
967
968 /// Return true if the attribute exists at the given index.
969 LLVM_ABI bool hasAttributeAtIndex(unsigned Index, StringRef Kind) const;
970
971 /// Return true if attribute exists at the given index.
972 LLVM_ABI bool hasAttributesAtIndex(unsigned Index) const;
973
974 /// Return true if the attribute exists for the given argument
975 bool hasParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
976 return hasAttributeAtIndex(ArgNo + FirstArgIndex, Kind);
977 }
978
979 /// Return true if the attribute exists for the given argument
980 bool hasParamAttr(unsigned ArgNo, StringRef Kind) const {
981 return hasAttributeAtIndex(ArgNo + FirstArgIndex, Kind);
982 }
983
984 /// Return true if attributes exists for the given argument
985 bool hasParamAttrs(unsigned ArgNo) const {
986 return hasAttributesAtIndex(ArgNo + FirstArgIndex);
987 }
988
989 /// Return true if the attribute exists for the return value.
990 bool hasRetAttr(Attribute::AttrKind Kind) const {
991 return hasAttributeAtIndex(ReturnIndex, Kind);
992 }
993
994 /// Return true if the attribute exists for the return value.
995 bool hasRetAttr(StringRef Kind) const {
996 return hasAttributeAtIndex(ReturnIndex, Kind);
997 }
998
999 /// Return true if attributes exist for the return value.
1000 bool hasRetAttrs() const { return hasAttributesAtIndex(ReturnIndex); }
1001
1002 /// Return true if the attribute exists for the function.
1003 bool hasFnAttr(Attribute::AttrKind Kind) const {
1004 return pImpl && pImpl->hasFnAttribute(Kind);
1005 }
1006
1007 /// Return true if the attribute exists for the function.
1008 LLVM_ABI bool hasFnAttr(StringRef Kind) const;
1009
1010 /// Return true the attributes exist for the function.
1011 bool hasFnAttrs() const { return hasAttributesAtIndex(FunctionIndex); }
1012
1013 /// Return true if the specified attribute is set for at least one
1014 /// parameter or for the return value. If Index is not nullptr, the index
1015 /// of a parameter with the specified attribute is provided.
1016 LLVM_ABI bool hasAttrSomewhere(Attribute::AttrKind Kind,
1017 unsigned *Index = nullptr) const;
1018
1019 /// Return the attribute object that exists at the given index.
1020 LLVM_ABI Attribute getAttributeAtIndex(unsigned Index,
1021 Attribute::AttrKind Kind) const;
1022
1023 /// Return the attribute object that exists at the given index.
1024 LLVM_ABI Attribute getAttributeAtIndex(unsigned Index, StringRef Kind) const;
1025
1026 /// Return the attribute object that exists at the arg index.
1027 Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
1028 return getAttributeAtIndex(ArgNo + FirstArgIndex, Kind);
1029 }
1030
1031 /// Return the attribute object that exists at the given index.
1032 Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const {
1033 return getAttributeAtIndex(ArgNo + FirstArgIndex, Kind);
1034 }
1035
1036 /// Return the attribute object that exists for the function.
1037 Attribute getFnAttr(Attribute::AttrKind Kind) const {
1038 return getAttributeAtIndex(FunctionIndex, Kind);
1039 }
1040
1041 /// Return the attribute object that exists for the function.
1042 Attribute getFnAttr(StringRef Kind) const {
1043 return getAttributeAtIndex(FunctionIndex, Kind);
1044 }
1045
1046 /// Return the attribute for the given attribute kind for the return value.
1047 Attribute getRetAttr(Attribute::AttrKind Kind) const {
1048 return getAttributeAtIndex(ReturnIndex, Kind);
1049 }
1050
1051 /// Return the alignment of the return value.
1052 LLVM_ABI MaybeAlign getRetAlignment() const;
1053
1054 /// Return the alignment for the specified function parameter.
1055 LLVM_ABI MaybeAlign getParamAlignment(unsigned ArgNo) const;
1056
1057 /// Return the stack alignment for the specified function parameter.
1058 LLVM_ABI MaybeAlign getParamStackAlignment(unsigned ArgNo) const;
1059
1060 /// Return the byval type for the specified function parameter.
1061 LLVM_ABI Type *getParamByValType(unsigned ArgNo) const;
1062
1063 /// Return the sret type for the specified function parameter.
1064 LLVM_ABI Type *getParamStructRetType(unsigned ArgNo) const;
1065
1066 /// Return the byref type for the specified function parameter.
1067 LLVM_ABI Type *getParamByRefType(unsigned ArgNo) const;
1068
1069 /// Return the preallocated type for the specified function parameter.
1070 LLVM_ABI Type *getParamPreallocatedType(unsigned ArgNo) const;
1071
1072 /// Return the inalloca type for the specified function parameter.
1073 LLVM_ABI Type *getParamInAllocaType(unsigned ArgNo) const;
1074
1075 /// Return the elementtype type for the specified function parameter.
1076 LLVM_ABI Type *getParamElementType(unsigned ArgNo) const;
1077
1078 /// Get the stack alignment of the function.
1079 LLVM_ABI MaybeAlign getFnStackAlignment() const;
1080
1081 /// Get the stack alignment of the return value.
1082 LLVM_ABI MaybeAlign getRetStackAlignment() const;
1083
1084 /// Get the number of dereferenceable bytes (or zero if unknown) of the return
1085 /// value.
1086 LLVM_ABI uint64_t getRetDereferenceableBytes() const;
1087
1088 /// Get the number of dereferenceable bytes (or zero if unknown) of an arg.
1089 LLVM_ABI uint64_t getParamDereferenceableBytes(unsigned Index) const;
1090
1091 /// Get the number of dereferenceable_or_null bytes (or zero if unknown) of
1092 /// the return value.
1093 LLVM_ABI uint64_t getRetDereferenceableOrNullBytes() const;
1094
1095 /// Get the number of dead_on_return bytes (or zero if unknown) of an arg.
1096 LLVM_ABI DeadOnReturnInfo getDeadOnReturnInfo(unsigned Index) const;
1097
1098 /// Get the number of dereferenceable_or_null bytes (or zero if unknown) of an
1099 /// arg.
1100 LLVM_ABI uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const;
1101
1102 /// Get range (or std::nullopt if unknown) of an arg.
1103 LLVM_ABI std::optional<ConstantRange> getParamRange(unsigned ArgNo) const;
1104
1105 /// Get the disallowed floating-point classes of the return value.
1106 LLVM_ABI FPClassTest getRetNoFPClass() const;
1107
1108 /// Get the disallowed floating-point classes of the argument value.
1109 LLVM_ABI FPClassTest getParamNoFPClass(unsigned ArgNo) const;
1110
1111 /// Get the unwind table kind requested for the function.
1112 LLVM_ABI UWTableKind getUWTableKind() const;
1113
1114 LLVM_ABI AllocFnKind getAllocKind() const;
1115
1116 /// Returns memory effects of the function.
1117 LLVM_ABI MemoryEffects getMemoryEffects() const;
1118
1119 /// Return the attributes at the index as a string.
1120 LLVM_ABI std::string getAsString(unsigned Index,
1121 bool InAttrGrp = false) const;
1122
1123 /// Return true if this attribute list belongs to the LLVMContext.
1124 LLVM_ABI bool hasParentContext(LLVMContext &C) const;
1125
1126 //===--------------------------------------------------------------------===//
1127 // AttributeList Introspection
1128 //===--------------------------------------------------------------------===//
1129
1130 using iterator = const AttributeSet *;
1131
1132 LLVM_ABI iterator begin() const;
1133 LLVM_ABI iterator end() const;
1134
1135 LLVM_ABI unsigned getNumAttrSets() const;
1136
1137 // Implementation of indexes(). Produces iterators that wrap an index. Mostly
1138 // to hide the awkwardness of unsigned wrapping when iterating over valid
1139 // indexes.
1140 struct index_iterator {
1141 unsigned NumAttrSets;
1142 index_iterator(int NumAttrSets) : NumAttrSets(NumAttrSets) {}
1143 struct int_wrapper {
1144 int_wrapper(unsigned i) : i(i) {}
1145 unsigned i;
1146 unsigned operator*() { return i; }
1147 bool operator!=(const int_wrapper &Other) { return i != Other.i; }
1148 int_wrapper &operator++() {
1149 // This is expected to undergo unsigned wrapping since FunctionIndex is
1150 // ~0 and that's where we start.
1151 ++i;
1152 return *this;
1153 }
1154 };
1155
1156 int_wrapper begin() { return int_wrapper(AttributeList::FunctionIndex); }
1157
1158 int_wrapper end() { return int_wrapper(NumAttrSets - 1); }
1159 };
1160
1161 /// Use this to iterate over the valid attribute indexes.
1162 index_iterator indexes() const { return index_iterator(getNumAttrSets()); }
1163
1164 /// operator==/!= - Provide equality predicates.
1165 bool operator==(const AttributeList &RHS) const { return pImpl == RHS.pImpl; }
1166 bool operator!=(const AttributeList &RHS) const { return pImpl != RHS.pImpl; }
1167
1168 /// Return a raw pointer that uniquely identifies this attribute list.
1169 void *getRawPointer() const {
1170 return pImpl;
1171 }
1172
1173 /// Return true if there are no attributes.
1174 bool isEmpty() const { return pImpl == nullptr; }
1175
1176 LLVM_ABI void print(raw_ostream &O) const;
1177
1178 LLVM_ABI void dump() const;
1179};
1180
1181//===----------------------------------------------------------------------===//
1182/// \class
1183/// Provide DenseMapInfo for AttributeList.
1184template <> struct DenseMapInfo<AttributeList, void> {
1185 static unsigned getHashValue(AttributeList AS) {
1186 return DenseMapInfo<const void *>::getHashValue(AS.pImpl);
1187 }
1188
1189 static bool isEqual(AttributeList LHS, AttributeList RHS) {
1190 return LHS == RHS;
1191 }
1192};
1193
1194//===----------------------------------------------------------------------===//
1195/// \class
1196/// This class is used in conjunction with the Attribute::get method to
1197/// create an Attribute object. The object itself is uniquified. The Builder's
1198/// value, however, is not. So this can be used as a quick way to test for
1199/// equality, presence of attributes, etc.
1200class AttrBuilder {
1201 LLVMContext &Ctx;
1202 SmallVector<Attribute, 8> Attrs;
1203
1204public:
1205 AttrBuilder(LLVMContext &Ctx) : Ctx(Ctx) {}
1206 AttrBuilder(const AttrBuilder &) = delete;
1207 AttrBuilder(AttrBuilder &&) = default;
1208
1209 AttrBuilder(LLVMContext &Ctx, const Attribute &A) : Ctx(Ctx) {
1210 addAttribute(A);
1211 }
1212
1213 LLVM_ABI AttrBuilder(LLVMContext &Ctx, AttributeSet AS);
1214
1215 LLVM_ABI void clear();
1216
1217 /// Add an attribute to the builder.
1218 LLVM_ABI AttrBuilder &addAttribute(Attribute::AttrKind Val);
1219
1220 /// Add the Attribute object to the builder.
1221 LLVM_ABI AttrBuilder &addAttribute(Attribute A);
1222
1223 /// Add the target-dependent attribute to the builder.
1224 LLVM_ABI AttrBuilder &addAttribute(StringRef A, StringRef V = StringRef());
1225
1226 /// Remove an attribute from the builder.
1227 LLVM_ABI AttrBuilder &removeAttribute(Attribute::AttrKind Val);
1228
1229 /// Remove the target-dependent attribute from the builder.
1230 LLVM_ABI AttrBuilder &removeAttribute(StringRef A);
1231
1232 /// Remove the target-dependent attribute from the builder.
1233 AttrBuilder &removeAttribute(Attribute A) {
1234 if (A.isStringAttribute())
1235 return removeAttribute(A.getKindAsString());
1236 else
1237 return removeAttribute(A.getKindAsEnum());
1238 }
1239
1240 /// Add the attributes from the builder. Attributes in the passed builder
1241 /// overwrite attributes in this builder if they have the same key.
1242 LLVM_ABI AttrBuilder &merge(const AttrBuilder &B);
1243
1244 /// Remove the attributes from the builder.
1245 LLVM_ABI AttrBuilder &remove(const AttributeMask &AM);
1246
1247 /// Return true if the builder has any attribute that's in the
1248 /// specified builder.
1249 LLVM_ABI bool overlaps(const AttributeMask &AM) const;
1250
1251 /// Return true if the builder has the specified attribute.
1252 LLVM_ABI bool contains(Attribute::AttrKind A) const;
1253
1254 /// Return true if the builder has the specified target-dependent
1255 /// attribute.
1256 LLVM_ABI bool contains(StringRef A) const;
1257
1258 /// Return true if the builder has IR-level attributes.
1259 bool hasAttributes() const { return !Attrs.empty(); }
1260
1261 /// Return Attribute with the given Kind. The returned attribute will be
1262 /// invalid if the Kind is not present in the builder.
1263 LLVM_ABI Attribute getAttribute(Attribute::AttrKind Kind) const;
1264
1265 /// Return Attribute with the given Kind. The returned attribute will be
1266 /// invalid if the Kind is not present in the builder.
1267 LLVM_ABI Attribute getAttribute(StringRef Kind) const;
1268
1269 /// Retrieve the range if the attribute exists (std::nullopt is returned
1270 /// otherwise).
1271 LLVM_ABI std::optional<ConstantRange> getRange() const;
1272
1273 /// Return raw (possibly packed/encoded) value of integer attribute or
1274 /// std::nullopt if not set.
1275 LLVM_ABI std::optional<uint64_t>
1276 getRawIntAttr(Attribute::AttrKind Kind) const;
1277
1278 /// Retrieve the alignment attribute, if it exists.
1279 MaybeAlign getAlignment() const {
1280 return MaybeAlign(getRawIntAttr(Attribute::Alignment).value_or(0));
1281 }
1282
1283 /// Retrieve the stack alignment attribute, if it exists.
1284 MaybeAlign getStackAlignment() const {
1285 return MaybeAlign(getRawIntAttr(Attribute::StackAlignment).value_or(0));
1286 }
1287
1288 /// Retrieve the number of dereferenceable bytes, if the
1289 /// dereferenceable attribute exists (zero is returned otherwise).
1290 uint64_t getDereferenceableBytes() const {
1291 return getRawIntAttr(Attribute::Dereferenceable).value_or(0);
1292 }
1293
1294 /// Retrieve the number of dereferenceable_or_null bytes, if the
1295 /// dereferenceable_or_null attribute exists (zero is returned otherwise).
1296 uint64_t getDereferenceableOrNullBytes() const {
1297 return getRawIntAttr(Attribute::DereferenceableOrNull).value_or(0);
1298 }
1299
1300 /// Retrieve the bitmask for nofpclass, if the nofpclass attribute exists
1301 /// (fcNone is returned otherwise).
1302 FPClassTest getNoFPClass() const {
1303 std::optional<uint64_t> Raw = getRawIntAttr(Attribute::NoFPClass);
1304 return static_cast<FPClassTest>(Raw.value_or(0));
1305 }
1306
1307 /// Retrieve type for the given type attribute.
1308 LLVM_ABI Type *getTypeAttr(Attribute::AttrKind Kind) const;
1309
1310 /// Retrieve the byval type.
1311 Type *getByValType() const { return getTypeAttr(Attribute::ByVal); }
1312
1313 /// Retrieve the sret type.
1314 Type *getStructRetType() const { return getTypeAttr(Attribute::StructRet); }
1315
1316 /// Retrieve the byref type.
1317 Type *getByRefType() const { return getTypeAttr(Attribute::ByRef); }
1318
1319 /// Retrieve the preallocated type.
1320 Type *getPreallocatedType() const {
1321 return getTypeAttr(Attribute::Preallocated);
1322 }
1323
1324 /// Retrieve the inalloca type.
1325 Type *getInAllocaType() const { return getTypeAttr(Attribute::InAlloca); }
1326
1327 /// Retrieve the allocsize args, or std::nullopt if the attribute does not
1328 /// exist.
1329 LLVM_ABI std::optional<std::pair<unsigned, std::optional<unsigned>>>
1330 getAllocSizeArgs() const;
1331
1332 /// Add integer attribute with raw value (packed/encoded if necessary).
1333 LLVM_ABI AttrBuilder &addRawIntAttr(Attribute::AttrKind Kind, uint64_t Value);
1334
1335 /// This turns an alignment into the form used internally in Attribute.
1336 /// This call has no effect if Align is not set.
1337 LLVM_ABI AttrBuilder &addAlignmentAttr(MaybeAlign Align);
1338
1339 /// This turns an int alignment (which must be a power of 2) into the
1340 /// form used internally in Attribute.
1341 /// This call has no effect if Align is 0.
1342 /// Deprecated, use the version using a MaybeAlign.
1343 inline AttrBuilder &addAlignmentAttr(unsigned Align) {
1344 return addAlignmentAttr(MaybeAlign(Align));
1345 }
1346
1347 /// This turns a stack alignment into the form used internally in Attribute.
1348 /// This call has no effect if Align is not set.
1349 LLVM_ABI AttrBuilder &addStackAlignmentAttr(MaybeAlign Align);
1350
1351 /// This turns an int stack alignment (which must be a power of 2) into
1352 /// the form used internally in Attribute.
1353 /// This call has no effect if Align is 0.
1354 /// Deprecated, use the version using a MaybeAlign.
1355 inline AttrBuilder &addStackAlignmentAttr(unsigned Align) {
1356 return addStackAlignmentAttr(MaybeAlign(Align));
1357 }
1358
1359 /// This turns the number of dereferenceable bytes into the form used
1360 /// internally in Attribute.
1361 LLVM_ABI AttrBuilder &addDereferenceableAttr(uint64_t Bytes);
1362
1363 /// This turns the number of dead_on_return bytes into the form used
1364 /// internally in Attribute.
1365 LLVM_ABI AttrBuilder &addDeadOnReturnAttr(DeadOnReturnInfo Info);
1366
1367 /// This turns the number of dereferenceable_or_null bytes into the
1368 /// form used internally in Attribute.
1369 LLVM_ABI AttrBuilder &addDereferenceableOrNullAttr(uint64_t Bytes);
1370
1371 /// This turns one (or two) ints into the form used internally in Attribute.
1372 LLVM_ABI AttrBuilder &
1373 addAllocSizeAttr(unsigned ElemSizeArg,
1374 const std::optional<unsigned> &NumElemsArg);
1375
1376 /// This turns two ints into the form used internally in Attribute.
1377 LLVM_ABI AttrBuilder &addVScaleRangeAttr(unsigned MinValue,
1378 std::optional<unsigned> MaxValue);
1379
1380 /// Add a type attribute with the given type.
1381 LLVM_ABI AttrBuilder &addTypeAttr(Attribute::AttrKind Kind, Type *Ty);
1382
1383 /// This turns a byval type into the form used internally in Attribute.
1384 LLVM_ABI AttrBuilder &addByValAttr(Type *Ty);
1385
1386 /// This turns a sret type into the form used internally in Attribute.
1387 LLVM_ABI AttrBuilder &addStructRetAttr(Type *Ty);
1388
1389 /// This turns a byref type into the form used internally in Attribute.
1390 LLVM_ABI AttrBuilder &addByRefAttr(Type *Ty);
1391
1392 /// This turns a preallocated type into the form used internally in Attribute.
1393 LLVM_ABI AttrBuilder &addPreallocatedAttr(Type *Ty);
1394
1395 /// This turns an inalloca type into the form used internally in Attribute.
1396 LLVM_ABI AttrBuilder &addInAllocaAttr(Type *Ty);
1397
1398 /// Add an allocsize attribute, using the representation returned by
1399 /// Attribute.getIntValue().
1400 LLVM_ABI AttrBuilder &addAllocSizeAttrFromRawRepr(uint64_t RawAllocSizeRepr);
1401
1402 /// Add a vscale_range attribute, using the representation returned by
1403 /// Attribute.getIntValue().
1404 LLVM_ABI AttrBuilder &
1405 addVScaleRangeAttrFromRawRepr(uint64_t RawVScaleRangeRepr);
1406
1407 /// This turns the unwind table kind into the form used internally in
1408 /// Attribute.
1409 LLVM_ABI AttrBuilder &addUWTableAttr(UWTableKind Kind);
1410
1411 // This turns the allocator kind into the form used internally in Attribute.
1412 LLVM_ABI AttrBuilder &addAllocKindAttr(AllocFnKind Kind);
1413
1414 /// Add memory effect attribute.
1415 LLVM_ABI AttrBuilder &addMemoryAttr(MemoryEffects ME);
1416
1417 /// Add captures attribute.
1418 LLVM_ABI AttrBuilder &addCapturesAttr(CaptureInfo CI);
1419
1420 /// Add denormal_fpenv attribute.
1421 LLVM_ABI AttrBuilder &addDenormalFPEnvAttr(DenormalFPEnv Mode);
1422
1423 // Add nofpclass attribute
1424 LLVM_ABI AttrBuilder &addNoFPClassAttr(FPClassTest NoFPClassMask);
1425
1426 /// Add a ConstantRange attribute with the given range.
1427 LLVM_ABI AttrBuilder &addConstantRangeAttr(Attribute::AttrKind Kind,
1428 const ConstantRange &CR);
1429
1430 /// Add range attribute.
1431 LLVM_ABI AttrBuilder &addRangeAttr(const ConstantRange &CR);
1432
1433 /// Add a ConstantRangeList attribute with the given ranges.
1434 LLVM_ABI AttrBuilder &addConstantRangeListAttr(Attribute::AttrKind Kind,
1435 ArrayRef<ConstantRange> Val);
1436
1437 /// Add initializes attribute.
1438 LLVM_ABI AttrBuilder &addInitializesAttr(const ConstantRangeList &CRL);
1439
1440 /// Add 0 or more parameter attributes which are equivalent to metadata
1441 /// attached to \p I. e.g. !align -> align. This assumes the argument type is
1442 /// the same as the original instruction and the attribute is compatible.
1443 LLVM_ABI AttrBuilder &addFromEquivalentMetadata(const Instruction &I);
1444
1445 ArrayRef<Attribute> attrs() const { return Attrs; }
1446
1447 LLVM_ABI bool operator==(const AttrBuilder &B) const;
1448 bool operator!=(const AttrBuilder &B) const { return !(*this == B); }
1449};
1450
1451namespace AttributeFuncs {
1452
1453enum AttributeSafetyKind : uint8_t {
1454 ASK_SAFE_TO_DROP = 1,
1455 ASK_UNSAFE_TO_DROP = 2,
1456 ASK_ALL = ASK_SAFE_TO_DROP | ASK_UNSAFE_TO_DROP,
1457};
1458
1459/// Returns true if this is a type legal for the 'nofpclass' attribute. This
1460/// follows the same type rules as FPMathOperator.
1461LLVM_ABI bool isNoFPClassCompatibleType(Type *Ty);
1462
1463/// Which attributes cannot be applied to a type. The argument \p AS
1464/// is used as a hint for the attributes whose compatibility is being
1465/// checked against \p Ty. This does not mean the return will be a
1466/// subset of \p AS, just that attributes that have specific dynamic
1467/// type compatibilities (i.e `range`) will be checked against what is
1468/// contained in \p AS. The argument \p ASK indicates, if only
1469/// attributes that are known to be safely droppable are contained in
1470/// the mask; only attributes that might be unsafe to drop (e.g.,
1471/// ABI-related attributes) are in the mask; or both.
1472LLVM_ABI AttributeMask typeIncompatible(Type *Ty, AttributeSet AS,
1473 AttributeSafetyKind ASK = ASK_ALL);
1474
1475/// Get param/return attributes which imply immediate undefined behavior if an
1476/// invalid value is passed. For example, this includes noundef (where undef
1477/// implies UB), but not nonnull (where null implies poison). It also does not
1478/// include attributes like nocapture, which constrain the function
1479/// implementation rather than the passed value.
1480LLVM_ABI AttributeMask getUBImplyingAttributes();
1481
1482/// Get param/return attributes which make an invalid value poison, e.g.,
1483/// nonnull, where null becomes poison.
1485
1486/// \returns Return true if the two functions have compatible target-independent
1487/// attributes for inlining purposes.
1489 const Function &Callee);
1490
1491/// \returns Return false if callee is strictfp and caller is not. Return true
1492/// otherwise.
1494 const Function &Callee);
1495
1496/// Checks if there are any incompatible function attributes between
1497/// \p A and \p B.
1498///
1499/// \param [in] A - The first function to be compared with.
1500/// \param [in] B - The second function to be compared with.
1501/// \returns true if the functions have compatible attributes.
1502LLVM_ABI bool areOutlineCompatible(const Function &A, const Function &B);
1503
1504/// Merge caller's and callee's attributes.
1506 const Function &Callee);
1507
1508/// Merges the functions attributes from \p ToMerge into function \p Base.
1509///
1510/// \param [in,out] Base - The function being merged into.
1511/// \param [in] ToMerge - The function to merge attributes from.
1513 const Function &ToMerge);
1514
1515/// Update min-legal-vector-width if it is in Attribute and less than Width.
1517
1518/// Adjust the parameter attributes \p ParamAttrs for a function or call site
1519/// whose return type becomes \p RetTy. If the new return type is no longer a
1520/// pointer, a function parameter cannot be captured through the return value
1521/// anymore. Thus, strip the return-only components from its captures attribute.
1523 LLVMContext &C, AttributeSet ParamAttrs, Type *RetTy);
1524} // end namespace AttributeFuncs
1525
1526} // end namespace llvm
1527
1528#endif // LLVM_IR_ATTRIBUTES_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
static msgpack::DocNode getNode(msgpack::DocNode DN, msgpack::Type Type, MCValue Val)
uint64_t uint64_t
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static DenormalFPEnv getDenormalFPEnv(AttributeSet FnAttrs)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
static std::optional< ConstantRange > getRange(Value *V, const InstrInfoQuery &IIQ)
Helper method to get range from metadata or attribute.
static LoopDeletionResult merge(LoopDeletionResult A, LoopDeletionResult B)
#define I(x, y, z)
Definition MD5.cpp:57
static Align getFnStackAlignment(const TargetSubtargetInfo &STI, const Function &F)
bool operator==(const MergedFunctionsInfo &LHS, const MergedFunctionsInfo &RHS)
return !CalleeAttrs getByValType()||CalleeAttrs.getAlignment()
II addRangeRetAttr(Range)
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:479
static FPClassTest getNoFPClass(const Instruction &I)
static uint32_t getAlignment(const MCSectionCOFF &Sec)
Value * RHS
Value * LHS
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A bitset with a bit for each enum attribute kind.
Definition Attributes.h:399
void addAttribute(Attribute::AttrKind Kind)
Definition Attributes.h:409
bool hasAttribute(Attribute::AttrKind Kind) const
Definition Attributes.h:405
This class represents a single, uniqued attribute.
The enum function attributes available in an AttributeListImpl, so that AttributeList can query them ...
Definition Attributes.h:428
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has an enum attribute of the given kind.
Definition Attributes.h:434
AttributeBitSet AvailableFunctionAttrs
Definition Attributes.h:430
This class represents a set of attributes that apply to the function, return type,...
This class stores enough information to efficiently remove some attributes from an existing AttrBuild...
The enum attributes available in an AttributeSetNode, so that AttributeSet can query them inline.
Definition Attributes.h:416
bool hasAttribute(Attribute::AttrKind Kind) const
Definition Attributes.h:421
AttributeBitSet AvailableAttrs
Definition Attributes.h:418
This class represents a group of attributes that apply to one element: function, return type,...
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:445
LLVM_ABI AllocFnKind getAllocKind() const
bool hasAttributes() const
Return true if attributes exists in this set.
Definition Attributes.h:526
const Attribute * iterator
Definition Attributes.h:567
LLVM_ABI AttributeSet removeAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute from this set.
LLVM_ABI Type * getInAllocaType() const
LLVM_ABI Type * getByValType() const
LLVM_ABI DeadOnReturnInfo getDeadOnReturnInfo() const
bool operator!=(const AttributeSet &O) const
Definition Attributes.h:472
LLVM_ABI AttributeSet addAttributes(LLVMContext &C, AttributeSet AS) const
Add attributes to the attribute set.
LLVM_ABI MemoryEffects getMemoryEffects() const
bool operator==(const AttributeSet &O) const
Definition Attributes.h:471
LLVM_ABI std::optional< AttributeSet > intersectWith(LLVMContext &C, AttributeSet Other) const
Try to intersect this AttributeSet with Other.
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
Definition Attributes.h:529
LLVM_ABI Type * getStructRetType() const
LLVM_ABI std::string getAsString(bool InAttrGrp=false) const
~AttributeSet()=default
LLVM_ABI unsigned getVScaleRangeMin() const
LLVM_ABI std::optional< std::pair< unsigned, std::optional< unsigned > > > getAllocSizeArgs() const
LLVM_ABI UWTableKind getUWTableKind() const
LLVM_ABI bool hasParentContext(LLVMContext &C) const
Return true if this attribute set belongs to the LLVMContext.
LLVM_ABI iterator begin() const
LLVM_ABI iterator end() const
LLVM_ABI AttributeSet addSortedAttributes(LLVMContext &C, ArrayRef< Attribute > Attrs) const
Add attributes to the attribute set, replacing attributes of the same kind.
LLVM_ABI AttributeSet removeAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const
Remove the specified attributes from this set.
LLVM_ABI std::optional< unsigned > getVScaleRangeMax() const
LLVM_ABI MaybeAlign getStackAlignment() const
LLVM_ABI Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
LLVM_ABI Type * getPreallocatedType() const
LLVM_ABI uint64_t getDereferenceableBytes() const
LLVM_ABI MaybeAlign getAlignment() const
LLVM_ABI FPClassTest getNoFPClass() const
friend struct DenseMapInfo
Definition Attributes.h:447
AttributeSet(const AttributeSet &)=default
LLVM_ABI Type * getElementType() const
LLVM_ABI Type * getByRefType() const
LLVM_ABI CaptureInfo getCaptureInfo() const
AttributeSet()=default
AttributeSet is a trivially copyable value type.
static LLVM_ABI AttributeSet get(LLVMContext &C, const AttrBuilder &B)
LLVM_ABI uint64_t getDereferenceableOrNullBytes() const
LLVM_ABI unsigned getNumAttributes() const
Return the number of attributes in this set.
LLVM_ABI AttributeSet addAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add an argument attribute.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:106
static const unsigned NumTypeAttrKinds
Definition Attributes.h:135
LLVM_ABI bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
static LLVM_ABI Attribute getWithStructRetType(LLVMContext &Context, Type *Ty)
static LLVM_ABI bool isABIAttr(AttrKind Kind)
Whether this is an ABI attribute (for returns or arguments).
bool operator==(Attribute A) const
Equality and non-equality operators.
Definition Attributes.h:368
static LLVM_ABI Attribute::AttrKind getAttrKindFromName(StringRef AttrName)
static const unsigned NumEnumAttrKinds
Definition Attributes.h:133
LLVM_ABI bool isEnumAttribute() const
Return true if the attribute is an Attribute::AttrKind type.
static LLVM_ABI Attribute getWithStackAlignment(LLVMContext &Context, Align Alignment)
LLVM_ABI const ConstantRange & getRange() const
Returns the value of the range attribute.
static LLVM_ABI bool intersectWithCustom(AttrKind Kind)
LLVM_ABI bool isIntAttribute() const
Return true if the attribute is an integer attribute.
static LLVM_ABI Attribute getWithByRefType(LLVMContext &Context, Type *Ty)
LLVM_ABI std::optional< unsigned > getVScaleRangeMax() const
Returns the maximum value for the vscale_range attribute or std::nullopt when unknown.
LLVM_ABI uint64_t getValueAsInt() const
Return the attribute's value as an integer.
LLVM_ABI unsigned getVScaleRangeMin() const
Returns the minimum value for the vscale_range attribute.
LLVM_ABI AllocFnKind getAllocKind() const
LLVM_ABI bool isConstantRangeAttribute() const
Return true if the attribute is a ConstantRange attribute.
static LLVM_ABI Attribute getWithAllocKind(LLVMContext &Context, AllocFnKind Kind)
LLVM_ABI StringRef getKindAsString() const
Return the attribute's kind as a string.
static LLVM_ABI Attribute getWithPreallocatedType(LLVMContext &Context, Type *Ty)
static LLVM_ABI bool intersectWithMin(AttrKind Kind)
static LLVM_ABI Attribute getWithDeadOnReturnInfo(LLVMContext &Context, DeadOnReturnInfo DI)
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static LLVM_ABI bool canUseAsRetAttr(AttrKind Kind)
static bool isTypeAttrKind(AttrKind Kind)
Definition Attributes.h:143
LLVM_ABI std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
LLVM_ABI uint64_t getDereferenceableOrNullBytes() const
Returns the number of dereferenceable_or_null bytes from the dereferenceable_or_null attribute.
static LLVM_ABI Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
LLVM_ABI std::pair< unsigned, std::optional< unsigned > > getAllocSizeArgs() const
Returns the argument numbers for the allocsize attribute.
static LLVM_ABI Attribute getWithUWTableKind(LLVMContext &Context, UWTableKind Kind)
bool operator!=(Attribute A) const
Definition Attributes.h:369
LLVM_ABI FPClassTest getNoFPClass() const
Return the FPClassTest for nofpclass.
static LLVM_ABI Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
LLVM_ABI Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
Attribute()=default
LLVM_ABI bool getValueAsBool() const
Return the attribute's value as a boolean.
LLVM_ABI ArrayRef< ConstantRange > getInitializes() const
Returns the value of the initializes attribute.
LLVM_ABI const ConstantRange & getValueAsConstantRange() const
Return the attribute's value as a ConstantRange.
LLVM_ABI uint64_t getDereferenceableBytes() const
Returns the number of dereferenceable bytes from the dereferenceable attribute.
static LLVM_ABI Attribute getWithVScaleRangeArgs(LLVMContext &Context, unsigned MinValue, unsigned MaxValue)
LLVM_ABI MemoryEffects getMemoryEffects() const
Returns memory effects.
LLVM_ABI UWTableKind getUWTableKind() const
static LLVM_ABI Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes)
LLVM_ABI ArrayRef< ConstantRange > getValueAsConstantRangeList() const
Return the attribute's value as a ConstantRange array.
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
bool hasKindAsEnum() const
Returns true if the attribute's kind can be represented as an enum (Enum, Integer,...
Definition Attributes.h:270
static LLVM_ABI StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind)
static LLVM_ABI bool canUseAsFnAttr(AttrKind Kind)
static LLVM_ABI bool intersectWithAnd(AttrKind Kind)
static LLVM_ABI Attribute getWithNoFPClass(LLVMContext &Context, FPClassTest Mask)
static bool isConstantRangeAttrKind(AttrKind Kind)
Definition Attributes.h:146
void * getRawPointer() const
Return a raw pointer that uniquely identifies this attribute.
Definition Attributes.h:378
LLVM_ABI bool hasParentContext(LLVMContext &C) const
Return true if this attribute belongs to the LLVMContext.
LLVM_ABI bool isTypeAttribute() const
Return true if the attribute is a type attribute.
static LLVM_ABI Attribute getWithCaptureInfo(LLVMContext &Context, CaptureInfo CI)
static LLVM_ABI Attribute getWithInAllocaType(LLVMContext &Context, Type *Ty)
static bool isIntAttrKind(AttrKind Kind)
Definition Attributes.h:140
static bool isConstantRangeListAttrKind(AttrKind Kind)
Definition Attributes.h:149
LLVM_ABI bool isConstantRangeListAttribute() const
Return true if the attribute is a ConstantRangeList attribute.
static LLVM_ABI Attribute getWithByValType(LLVMContext &Context, Type *Ty)
Attribute getWithNewType(LLVMContext &Context, Type *ReplacementTy)
For a typed attribute, return the equivalent attribute with the type changed to ReplacementTy.
Definition Attributes.h:227
LLVM_ABI bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
static bool isEnumAttrKind(AttrKind Kind)
Definition Attributes.h:137
static LLVM_ABI Attribute getWithMemoryEffects(LLVMContext &Context, MemoryEffects ME)
static LLVM_ABI bool canUseAsParamAttr(AttrKind Kind)
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition Attributes.h:260
LLVM_ABI MaybeAlign getStackAlignment() const
Returns the stack alignment field of an attribute as a byte alignment value.
static Attribute fromRawPointer(void *RawPtr)
Get an attribute from a raw pointer created by getRawPointer.
Definition Attributes.h:383
static const unsigned NumIntAttrKinds
Definition Attributes.h:134
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:125
@ None
No attributes have been set.
Definition Attributes.h:127
@ EndAttrKinds
Sentinel value useful for loops.
Definition Attributes.h:130
LLVM_ABI MaybeAlign getAlignment() const
Returns the alignment field of an attribute as a byte alignment value.
LLVM_ABI CaptureInfo getCaptureInfo() const
Returns information from captures attribute.
static LLVM_ABI bool intersectMustPreserve(AttrKind Kind)
LLVM_ABI int cmpKind(Attribute A) const
Used to sort attribute by kind.
LLVM_ABI bool operator<(Attribute A) const
Less-than operator. Useful for sorting the attributes list.
static LLVM_ABI Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
LLVM_ABI DeadOnReturnInfo getDeadOnReturnInfo() const
Returns the number of dead_on_return bytes from the dead_on_return attribute, or std::nullopt if all ...
LLVM_ABI Type * getValueAsType() const
Return the attribute's value as a Type.
Represents which components of the pointer may be captured in which location.
Definition ModRef.h:414
This class represents a list of constant ranges.
This class represents a range of values.
static DeadOnReturnInfo createFromIntValue(uint64_t Data)
Definition Attributes.h:80
bool coversAllReachableMemory() const
Definition Attributes.h:78
uint64_t toIntValue() const
Definition Attributes.h:86
DeadOnReturnInfo(uint64_t DeadOnReturnBytes)
Definition Attributes.h:69
bool isZeroSized() const
Definition Attributes.h:92
uint64_t getNumberOfDeadBytes() const
Definition Attributes.h:71
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
struct LLVMOpaqueAttributeRef * LLVMAttributeRef
Used to represent an attributes.
Definition Types.h:145
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
LLVM_ABI AttributeList getAttributes(LLVMContext &C, ID id, FunctionType *FT)
Return the attributes for an intrinsic.
Align getStackAlignment(ABI TargetABI)
Attribute
Attributes.
Definition Dwarf.h:125
iterator end() const
Definition BasicBlock.h:89
BBIterator iterator
Definition BasicBlock.h:87
LLVM_ABI iterator begin() const
LLVM_ABI std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
LLVM_ABI AttributeMask getPoisonGeneratingAttributes()
Get param/return attributes which make an invalid value poison, e.g., nonnull, where null becomes poi...
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
@ Unknown
Not known to have no common set bits.
@ Uninitialized
Definition Threading.h:60
APInt operator*(APInt a, uint64_t RHS)
Definition APInt.h:2261
AllocFnKind
Definition Attributes.h:54
bool operator!=(uint64_t V1, const APInt &V2)
Definition APInt.h:2139
LLVM_ABI AttributeMask typeIncompatible(Type *Ty, AttributeSet AS, AttributeSafetyKind ASK=ASK_ALL)
This class holds the attributes for a function, its return value, and its parameters.
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
Definition ModRef.h:356
LLVM_ABI AttributeSet dropRetOnlyCaptureComponents(LLVMContext &C, AttributeSet ParamAttrs, Type *RetTy)
Adjust the parameter attributes ParamAttrs for a function or call site whose return type becomes RetT...
UWTableKind
Definition CodeGen.h:362
LLVM_ABI bool isStrictFPInlineCompatible(const Function &Caller, const Function &Callee)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
@ Other
Any other memory.
Definition ModRef.h:68
Attribute unwrap(LLVMAttributeRef Attr)
Definition Attributes.h:394
LLVM_ABI void mergeAttributesForOutlining(Function &Base, const Function &ToMerge)
Merges the functions attributes from ToMerge into function Base.
LLVMAttributeRef wrap(Attribute Attr)
Definition Attributes.h:389
LLVM_ABI bool areInlineCompatible(const Function &Caller, const Function &Callee)
LLVM_ABI void updateMinLegalVectorWidthAttr(Function &Fn, uint64_t Width)
Update min-legal-vector-width if it is in Attribute and less than Width.
LLVM_ABI void mergeAttributesForInlining(Function &Caller, const Function &Callee)
Merge caller's and callee's attributes.
LLVM_ABI bool areOutlineCompatible(const Function &A, const Function &B)
Checks if there are any incompatible function attributes between A and B.
LLVM_ABI AttributeMask getUBImplyingAttributes()
Get param/return attributes which imply immediate undefined behavior if an invalid value is passed.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Represents the full denormal controls for a function, including the default mode and the f32 specific...
static bool isEqual(AttributeSet LHS, AttributeSet RHS)
Definition Attributes.h:584
static unsigned getHashValue(AttributeSet AS)
Definition Attributes.h:580
An information struct used to provide DenseMap with the various necessary components for a given valu...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:111
Trait to indicate whether a type's bits can be hashed directly.
Definition Hashing.h:180