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