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