LLVM 18.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"
25#include "llvm/Support/ModRef.h"
27#include <cassert>
28#include <cstdint>
29#include <optional>
30#include <string>
31#include <utility>
32
33namespace llvm {
34
35class AttrBuilder;
36class AttributeMask;
37class AttributeImpl;
38class AttributeListImpl;
39class AttributeSetNode;
40class FoldingSetNodeID;
41class Function;
42class LLVMContext;
43class Type;
44class raw_ostream;
46
47enum class AllocFnKind : uint64_t {
48 Unknown = 0,
49 Alloc = 1 << 0, // Allocator function returns a new allocation
50 Realloc = 1 << 1, // Allocator function resizes the `allocptr` argument
51 Free = 1 << 2, // Allocator function frees the `allocptr` argument
52 Uninitialized = 1 << 3, // Allocator function returns uninitialized memory
53 Zeroed = 1 << 4, // Allocator function returns zeroed memory
54 Aligned = 1 << 5, // Allocator function aligns allocations per the
55 // `allocalign` argument
56 LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ Aligned)
57};
58
59//===----------------------------------------------------------------------===//
60/// \class
61/// Functions, function parameters, and return types can have attributes
62/// to indicate how they should be treated by optimizations and code
63/// generation. This class represents one of those attributes. It's light-weight
64/// and should be passed around by-value.
65class Attribute {
66public:
67 /// This enumeration lists the attributes that can be associated with
68 /// parameters, function results, or the function itself.
69 ///
70 /// Note: The `uwtable' attribute is about the ABI or the user mandating an
71 /// entry in the unwind table. The `nounwind' attribute is about an exception
72 /// passing by the function.
73 ///
74 /// In a theoretical system that uses tables for profiling and SjLj for
75 /// exceptions, they would be fully independent. In a normal system that uses
76 /// tables for both, the semantics are:
77 ///
78 /// nil = Needs an entry because an exception might pass by.
79 /// nounwind = No need for an entry
80 /// uwtable = Needs an entry because the ABI says so and because
81 /// an exception might pass by.
82 /// uwtable + nounwind = Needs an entry because the ABI says so.
83
84 enum AttrKind {
85 // IR-Level Attributes
86 None, ///< No attributes have been set
87 #define GET_ATTR_ENUM
88 #include "llvm/IR/Attributes.inc"
89 EndAttrKinds, ///< Sentinal value useful for loops
90 EmptyKey, ///< Use as Empty key for DenseMap of AttrKind
91 TombstoneKey, ///< Use as Tombstone key for DenseMap of AttrKind
92 };
93
94 static const unsigned NumIntAttrKinds = LastIntAttr - FirstIntAttr + 1;
95 static const unsigned NumTypeAttrKinds = LastTypeAttr - FirstTypeAttr + 1;
96
97 static bool isEnumAttrKind(AttrKind Kind) {
98 return Kind >= FirstEnumAttr && Kind <= LastEnumAttr;
99 }
100 static bool isIntAttrKind(AttrKind Kind) {
101 return Kind >= FirstIntAttr && Kind <= LastIntAttr;
102 }
103 static bool isTypeAttrKind(AttrKind Kind) {
104 return Kind >= FirstTypeAttr && Kind <= LastTypeAttr;
105 }
106
107 static bool canUseAsFnAttr(AttrKind Kind);
108 static bool canUseAsParamAttr(AttrKind Kind);
109 static bool canUseAsRetAttr(AttrKind Kind);
110
111private:
112 AttributeImpl *pImpl = nullptr;
113
114 Attribute(AttributeImpl *A) : pImpl(A) {}
115
116public:
117 Attribute() = default;
118
119 //===--------------------------------------------------------------------===//
120 // Attribute Construction
121 //===--------------------------------------------------------------------===//
122
123 /// Return a uniquified Attribute object.
124 static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val = 0);
125 static Attribute get(LLVMContext &Context, StringRef Kind,
126 StringRef Val = StringRef());
127 static Attribute get(LLVMContext &Context, AttrKind Kind, Type *Ty);
128
129 /// Return a uniquified Attribute object that has the specific
130 /// alignment set.
131 static Attribute getWithAlignment(LLVMContext &Context, Align Alignment);
132 static Attribute getWithStackAlignment(LLVMContext &Context, Align Alignment);
134 uint64_t Bytes);
136 uint64_t Bytes);
138 LLVMContext &Context, unsigned ElemSizeArg,
139 const std::optional<unsigned> &NumElemsArg);
141 unsigned MinValue, unsigned MaxValue);
142 static Attribute getWithByValType(LLVMContext &Context, Type *Ty);
143 static Attribute getWithStructRetType(LLVMContext &Context, Type *Ty);
144 static Attribute getWithByRefType(LLVMContext &Context, Type *Ty);
146 static Attribute getWithInAllocaType(LLVMContext &Context, Type *Ty);
149 static Attribute getWithNoFPClass(LLVMContext &Context, FPClassTest Mask);
150
151 /// For a typed attribute, return the equivalent attribute with the type
152 /// changed to \p ReplacementTy.
153 Attribute getWithNewType(LLVMContext &Context, Type *ReplacementTy) {
154 assert(isTypeAttribute() && "this requires a typed attribute");
155 return get(Context, getKindAsEnum(), ReplacementTy);
156 }
157
159
161
162 /// Return true if the provided string matches the IR name of an attribute.
163 /// example: "noalias" return true but not "NoAlias"
165
166 //===--------------------------------------------------------------------===//
167 // Attribute Accessors
168 //===--------------------------------------------------------------------===//
169
170 /// Return true if the attribute is an Attribute::AttrKind type.
171 bool isEnumAttribute() const;
172
173 /// Return true if the attribute is an integer attribute.
174 bool isIntAttribute() const;
175
176 /// Return true if the attribute is a string (target-dependent)
177 /// attribute.
178 bool isStringAttribute() const;
179
180 /// Return true if the attribute is a type attribute.
181 bool isTypeAttribute() const;
182
183 /// Return true if the attribute is any kind of attribute.
184 bool isValid() const { return pImpl; }
185
186 /// Return true if the attribute is present.
187 bool hasAttribute(AttrKind Val) const;
188
189 /// Return true if the target-dependent attribute is present.
190 bool hasAttribute(StringRef Val) const;
191
192 /// Return the attribute's kind as an enum (Attribute::AttrKind). This
193 /// requires the attribute to be an enum, integer, or type attribute.
195
196 /// Return the attribute's value as an integer. This requires that the
197 /// attribute be an integer attribute.
198 uint64_t getValueAsInt() const;
199
200 /// Return the attribute's value as a boolean. This requires that the
201 /// attribute be a string attribute.
202 bool getValueAsBool() const;
203
204 /// Return the attribute's kind as a string. This requires the
205 /// attribute to be a string attribute.
207
208 /// Return the attribute's value as a string. This requires the
209 /// attribute to be a string attribute.
211
212 /// Return the attribute's value as a Type. This requires the attribute to be
213 /// a type attribute.
214 Type *getValueAsType() const;
215
216 /// Returns the alignment field of an attribute as a byte alignment
217 /// value.
218 MaybeAlign getAlignment() const;
219
220 /// Returns the stack alignment field of an attribute as a byte
221 /// alignment value.
223
224 /// Returns the number of dereferenceable bytes from the
225 /// dereferenceable attribute.
227
228 /// Returns the number of dereferenceable_or_null bytes from the
229 /// dereferenceable_or_null attribute.
231
232 /// Returns the argument numbers for the allocsize attribute.
233 std::pair<unsigned, std::optional<unsigned>> getAllocSizeArgs() const;
234
235 /// Returns the minimum value for the vscale_range attribute.
236 unsigned getVScaleRangeMin() const;
237
238 /// Returns the maximum value for the vscale_range attribute or std::nullopt
239 /// when unknown.
240 std::optional<unsigned> getVScaleRangeMax() const;
241
242 // Returns the unwind table kind.
244
245 // Returns the allocator function kind.
247
248 /// Returns memory effects.
250
251 /// Return the FPClassTest for nofpclass
253
254 /// The Attribute is converted to a string of equivalent mnemonic. This
255 /// is, presumably, for writing out the mnemonics for the assembly writer.
256 std::string getAsString(bool InAttrGrp = false) const;
257
258 /// Return true if this attribute belongs to the LLVMContext.
259 bool hasParentContext(LLVMContext &C) const;
260
261 /// Equality and non-equality operators.
262 bool operator==(Attribute A) const { return pImpl == A.pImpl; }
263 bool operator!=(Attribute A) const { return pImpl != A.pImpl; }
264
265 /// Less-than operator. Useful for sorting the attributes list.
266 bool operator<(Attribute A) const;
267
268 void Profile(FoldingSetNodeID &ID) const;
269
270 /// Return a raw pointer that uniquely identifies this attribute.
271 void *getRawPointer() const {
272 return pImpl;
273 }
274
275 /// Get an attribute from a raw pointer created by getRawPointer.
276 static Attribute fromRawPointer(void *RawPtr) {
277 return Attribute(reinterpret_cast<AttributeImpl*>(RawPtr));
278 }
279};
280
281// Specialized opaque value conversions.
283 return reinterpret_cast<LLVMAttributeRef>(Attr.getRawPointer());
284}
285
286// Specialized opaque value conversions.
288 return Attribute::fromRawPointer(Attr);
289}
290
291//===----------------------------------------------------------------------===//
292/// \class
293/// This class holds the attributes for a particular argument, parameter,
294/// function, or return value. It is an immutable value type that is cheap to
295/// copy. Adding and removing enum attributes is intended to be fast, but adding
296/// and removing string or integer attributes involves a FoldingSet lookup.
298 friend AttributeListImpl;
299 template <typename Ty, typename Enable> friend struct DenseMapInfo;
300
301 // TODO: Extract AvailableAttrs from AttributeSetNode and store them here.
302 // This will allow an efficient implementation of addAttribute and
303 // removeAttribute for enum attrs.
304
305 /// Private implementation pointer.
306 AttributeSetNode *SetNode = nullptr;
307
308private:
309 explicit AttributeSet(AttributeSetNode *ASN) : SetNode(ASN) {}
310
311public:
312 /// AttributeSet is a trivially copyable value type.
313 AttributeSet() = default;
314 AttributeSet(const AttributeSet &) = default;
315 ~AttributeSet() = default;
316
317 static AttributeSet get(LLVMContext &C, const AttrBuilder &B);
319
320 bool operator==(const AttributeSet &O) const { return SetNode == O.SetNode; }
321 bool operator!=(const AttributeSet &O) const { return !(*this == O); }
322
323 /// Add an argument attribute. Returns a new set because attribute sets are
324 /// immutable.
325 [[nodiscard]] AttributeSet addAttribute(LLVMContext &C,
326 Attribute::AttrKind Kind) const;
327
328 /// Add a target-dependent attribute. Returns a new set because attribute sets
329 /// are immutable.
330 [[nodiscard]] AttributeSet addAttribute(LLVMContext &C, StringRef Kind,
331 StringRef Value = StringRef()) const;
332
333 /// Add attributes to the attribute set. Returns a new set because attribute
334 /// sets are immutable.
336 AttributeSet AS) const;
337
338 /// Remove the specified attribute from this set. Returns a new set because
339 /// attribute sets are immutable.
341 Attribute::AttrKind Kind) const;
342
343 /// Remove the specified attribute from this set. Returns a new set because
344 /// attribute sets are immutable.
346 StringRef Kind) const;
347
348 /// Remove the specified attributes from this set. Returns a new set because
349 /// attribute sets are immutable.
350 [[nodiscard]] AttributeSet
351 removeAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const;
352
353 /// Return the number of attributes in this set.
354 unsigned getNumAttributes() const;
355
356 /// Return true if attributes exists in this set.
357 bool hasAttributes() const { return SetNode != nullptr; }
358
359 /// Return true if the attribute exists in this set.
360 bool hasAttribute(Attribute::AttrKind Kind) const;
361
362 /// Return true if the attribute exists in this set.
363 bool hasAttribute(StringRef Kind) const;
364
365 /// Return the attribute object.
367
368 /// Return the target-dependent attribute object.
369 Attribute getAttribute(StringRef Kind) const;
370
371 MaybeAlign getAlignment() const;
375 Type *getByValType() const;
376 Type *getStructRetType() const;
377 Type *getByRefType() const;
378 Type *getPreallocatedType() const;
379 Type *getInAllocaType() const;
380 Type *getElementType() const;
381 std::optional<std::pair<unsigned, std::optional<unsigned>>> getAllocSizeArgs()
382 const;
383 unsigned getVScaleRangeMin() const;
384 std::optional<unsigned> getVScaleRangeMax() const;
389 std::string getAsString(bool InAttrGrp = false) const;
390
391 /// Return true if this attribute set belongs to the LLVMContext.
392 bool hasParentContext(LLVMContext &C) const;
393
394 using iterator = const Attribute *;
395
396 iterator begin() const;
397 iterator end() const;
398#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
399 void dump() const;
400#endif
401};
402
403//===----------------------------------------------------------------------===//
404/// \class
405/// Provide DenseMapInfo for AttributeSet.
406template <> struct DenseMapInfo<AttributeSet, void> {
408 auto Val = static_cast<uintptr_t>(-1);
409 Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable;
410 return AttributeSet(reinterpret_cast<AttributeSetNode *>(Val));
411 }
412
414 auto Val = static_cast<uintptr_t>(-2);
415 Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable;
416 return AttributeSet(reinterpret_cast<AttributeSetNode *>(Val));
417 }
418
419 static unsigned getHashValue(AttributeSet AS) {
420 return (unsigned((uintptr_t)AS.SetNode) >> 4) ^
421 (unsigned((uintptr_t)AS.SetNode) >> 9);
422 }
423
424 static bool isEqual(AttributeSet LHS, AttributeSet RHS) { return LHS == RHS; }
425};
426
427//===----------------------------------------------------------------------===//
428/// \class
429/// This class holds the attributes for a function, its return value, and
430/// its parameters. You access the attributes for each of them via an index into
431/// the AttributeList object. The function attributes are at index
432/// `AttributeList::FunctionIndex', the return value is at index
433/// `AttributeList::ReturnIndex', and the attributes for the parameters start at
434/// index `AttributeList::FirstArgIndex'.
436public:
437 enum AttrIndex : unsigned {
441 };
442
443private:
444 friend class AttrBuilder;
445 friend class AttributeListImpl;
446 friend class AttributeSet;
447 friend class AttributeSetNode;
448 template <typename Ty, typename Enable> friend struct DenseMapInfo;
449
450 /// The attributes that we are managing. This can be null to represent
451 /// the empty attributes list.
452 AttributeListImpl *pImpl = nullptr;
453
454public:
455 /// Create an AttributeList with the specified parameters in it.
457 ArrayRef<std::pair<unsigned, Attribute>> Attrs);
459 ArrayRef<std::pair<unsigned, AttributeSet>> Attrs);
460
461 /// Create an AttributeList from attribute sets for a function, its
462 /// return value, and all of its arguments.
463 static AttributeList get(LLVMContext &C, AttributeSet FnAttrs,
464 AttributeSet RetAttrs,
465 ArrayRef<AttributeSet> ArgAttrs);
466
467private:
468 explicit AttributeList(AttributeListImpl *LI) : pImpl(LI) {}
469
470 static AttributeList getImpl(LLVMContext &C, ArrayRef<AttributeSet> AttrSets);
471
472 AttributeList setAttributesAtIndex(LLVMContext &C, unsigned Index,
473 AttributeSet Attrs) const;
474
475public:
476 AttributeList() = default;
477
478 //===--------------------------------------------------------------------===//
479 // AttributeList Construction and Mutation
480 //===--------------------------------------------------------------------===//
481
482 /// Return an AttributeList with the specified parameters in it.
484 static AttributeList get(LLVMContext &C, unsigned Index,
486 static AttributeList get(LLVMContext &C, unsigned Index,
488 ArrayRef<uint64_t> Values);
489 static AttributeList get(LLVMContext &C, unsigned Index,
491 static AttributeList get(LLVMContext &C, unsigned Index,
492 AttributeSet Attrs);
493 static AttributeList get(LLVMContext &C, unsigned Index,
494 const AttrBuilder &B);
495
496 // TODO: remove non-AtIndex versions of these methods.
497 /// Add an attribute to the attribute set at the given index.
498 /// Returns a new list because attribute lists are immutable.
499 [[nodiscard]] AttributeList
501 Attribute::AttrKind Kind) const;
502
503 /// Add an attribute to the attribute set at the given index.
504 /// Returns a new list because attribute lists are immutable.
505 [[nodiscard]] AttributeList
507 StringRef Value = StringRef()) const;
508
509 /// Add an attribute to the attribute set at the given index.
510 /// Returns a new list because attribute lists are immutable.
511 [[nodiscard]] AttributeList
513
514 /// Add attributes to the attribute set at the given index.
515 /// Returns a new list because attribute lists are immutable.
517 unsigned Index,
518 const AttrBuilder &B) const;
519
520 /// Add a function attribute to the list. Returns a new list because
521 /// attribute lists are immutable.
523 Attribute::AttrKind Kind) const {
524 return addAttributeAtIndex(C, FunctionIndex, Kind);
525 }
526
527 /// Add a function attribute to the list. Returns a new list because
528 /// attribute lists are immutable.
530 Attribute Attr) const {
531 return addAttributeAtIndex(C, FunctionIndex, Attr);
532 }
533
534 /// Add a function attribute to the list. Returns a new list because
535 /// attribute lists are immutable.
536 [[nodiscard]] AttributeList
538 StringRef Value = StringRef()) const {
540 }
541
542 /// Add function attribute to the list. Returns a new list because
543 /// attribute lists are immutable.
545 const AttrBuilder &B) const {
547 }
548
549 /// Add a return value attribute to the list. Returns a new list because
550 /// attribute lists are immutable.
552 Attribute::AttrKind Kind) const {
553 return addAttributeAtIndex(C, ReturnIndex, Kind);
554 }
555
556 /// Add a return value attribute to the list. Returns a new list because
557 /// attribute lists are immutable.
559 Attribute Attr) const {
560 return addAttributeAtIndex(C, ReturnIndex, Attr);
561 }
562
563 /// Add a return value attribute to the list. Returns a new list because
564 /// attribute lists are immutable.
566 const AttrBuilder &B) const {
568 }
569
570 /// Add an argument attribute to the list. Returns a new list because
571 /// attribute lists are immutable.
572 [[nodiscard]] AttributeList
574 Attribute::AttrKind Kind) const {
575 return addAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind);
576 }
577
578 /// Add an argument attribute to the list. Returns a new list because
579 /// attribute lists are immutable.
580 [[nodiscard]] AttributeList
581 addParamAttribute(LLVMContext &C, unsigned ArgNo, StringRef Kind,
582 StringRef Value = StringRef()) const {
583 return addAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind, Value);
584 }
585
586 /// Add an attribute to the attribute list at the given arg indices. Returns a
587 /// new list because attribute lists are immutable.
589 ArrayRef<unsigned> ArgNos,
590 Attribute A) const;
591
592 /// Add an argument attribute to the list. Returns a new list because
593 /// attribute lists are immutable.
594 [[nodiscard]] AttributeList addParamAttributes(LLVMContext &C, unsigned ArgNo,
595 const AttrBuilder &B) const {
596 return addAttributesAtIndex(C, ArgNo + FirstArgIndex, B);
597 }
598
599 /// Remove the specified attribute at the specified index from this
600 /// attribute list. Returns a new list because attribute lists are immutable.
601 [[nodiscard]] AttributeList
603 Attribute::AttrKind Kind) const;
604
605 /// Remove the specified attribute at the specified index from this
606 /// attribute list. Returns a new list because attribute lists are immutable.
607 [[nodiscard]] AttributeList
608 removeAttributeAtIndex(LLVMContext &C, unsigned Index, StringRef Kind) const;
610 StringRef Kind) const {
611 return removeAttributeAtIndex(C, Index, Kind);
612 }
613
614 /// Remove the specified attributes at the specified index from this
615 /// attribute list. Returns a new list because attribute lists are immutable.
616 [[nodiscard]] AttributeList
618 const AttributeMask &AttrsToRemove) const;
619
620 /// Remove all attributes at the specified index from this
621 /// attribute list. Returns a new list because attribute lists are immutable.
623 unsigned Index) const;
624
625 /// Remove the specified attribute at the function index from this
626 /// attribute list. Returns a new list because attribute lists are immutable.
627 [[nodiscard]] AttributeList
630 }
631
632 /// Remove the specified attribute at the function index from this
633 /// attribute list. Returns a new list because attribute lists are immutable.
635 StringRef Kind) const {
637 }
638
639 /// Remove the specified attribute at the function index from this
640 /// attribute list. Returns a new list because attribute lists are immutable.
641 [[nodiscard]] AttributeList
642 removeFnAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const {
643 return removeAttributesAtIndex(C, FunctionIndex, AttrsToRemove);
644 }
645
646 /// Remove the attributes at the function index from this
647 /// attribute list. Returns a new list because attribute lists are immutable.
650 }
651
652 /// Remove the specified attribute at the return value index from this
653 /// attribute list. Returns a new list because attribute lists are immutable.
654 [[nodiscard]] AttributeList
656 return removeAttributeAtIndex(C, ReturnIndex, Kind);
657 }
658
659 /// Remove the specified attribute at the return value index from this
660 /// attribute list. Returns a new list because attribute lists are immutable.
662 StringRef Kind) const {
663 return removeAttributeAtIndex(C, ReturnIndex, Kind);
664 }
665
666 /// Remove the specified attribute at the return value index from this
667 /// attribute list. Returns a new list because attribute lists are immutable.
668 [[nodiscard]] AttributeList
670 const AttributeMask &AttrsToRemove) const {
671 return removeAttributesAtIndex(C, ReturnIndex, AttrsToRemove);
672 }
673
674 /// Remove the specified attribute at the specified arg index from this
675 /// attribute list. Returns a new list because attribute lists are immutable.
676 [[nodiscard]] AttributeList
678 Attribute::AttrKind Kind) const {
679 return removeAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind);
680 }
681
682 /// Remove the specified attribute at the specified arg index from this
683 /// attribute list. Returns a new list because attribute lists are immutable.
684 [[nodiscard]] AttributeList
685 removeParamAttribute(LLVMContext &C, unsigned ArgNo, StringRef Kind) const {
686 return removeAttributeAtIndex(C, ArgNo + FirstArgIndex, Kind);
687 }
688
689 /// Remove the specified attribute at the specified arg index from this
690 /// attribute list. Returns a new list because attribute lists are immutable.
691 [[nodiscard]] AttributeList
693 const AttributeMask &AttrsToRemove) const {
694 return removeAttributesAtIndex(C, ArgNo + FirstArgIndex, AttrsToRemove);
695 }
696
697 /// Remove all attributes at the specified arg index from this
698 /// attribute list. Returns a new list because attribute lists are immutable.
700 unsigned ArgNo) const {
701 return removeAttributesAtIndex(C, ArgNo + FirstArgIndex);
702 }
703
704 /// Replace the type contained by attribute \p AttrKind at index \p ArgNo wih
705 /// \p ReplacementTy, preserving all other attributes.
706 [[nodiscard]] AttributeList
709 Type *ReplacementTy) const {
710 Attribute Attr = getAttributeAtIndex(ArgNo, Kind);
711 auto Attrs = removeAttributeAtIndex(C, ArgNo, Kind);
712 return Attrs.addAttributeAtIndex(C, ArgNo,
713 Attr.getWithNewType(C, ReplacementTy));
714 }
715
716 /// \brief Add the dereferenceable attribute to the attribute set at the given
717 /// index. Returns a new list because attribute lists are immutable.
719 uint64_t Bytes) const;
720
721 /// \brief Add the dereferenceable attribute to the attribute set at the given
722 /// arg index. Returns a new list because attribute lists are immutable.
724 unsigned ArgNo,
725 uint64_t Bytes) const;
726
727 /// Add the dereferenceable_or_null attribute to the attribute set at
728 /// the given arg index. Returns a new list because attribute lists are
729 /// immutable.
730 [[nodiscard]] AttributeList
732 uint64_t Bytes) const;
733
734 /// Add the allocsize attribute to the attribute set at the given arg index.
735 /// Returns a new list because attribute lists are immutable.
736 [[nodiscard]] AttributeList
737 addAllocSizeParamAttr(LLVMContext &C, unsigned ArgNo, unsigned ElemSizeArg,
738 const std::optional<unsigned> &NumElemsArg);
739
740 //===--------------------------------------------------------------------===//
741 // AttributeList Accessors
742 //===--------------------------------------------------------------------===//
743
744 /// The attributes for the specified index are returned.
745 AttributeSet getAttributes(unsigned Index) const;
746
747 /// The attributes for the argument or parameter at the given index are
748 /// returned.
749 AttributeSet getParamAttrs(unsigned ArgNo) const;
750
751 /// The attributes for the ret value are returned.
753
754 /// The function attributes are returned.
755 AttributeSet getFnAttrs() const;
756
757 /// Return true if the attribute exists at the given index.
758 bool hasAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const;
759
760 /// Return true if the attribute exists at the given index.
761 bool hasAttributeAtIndex(unsigned Index, StringRef Kind) const;
762
763 /// Return true if attribute exists at the given index.
764 bool hasAttributesAtIndex(unsigned Index) const;
765
766 /// Return true if the attribute exists for the given argument
767 bool hasParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
768 return hasAttributeAtIndex(ArgNo + FirstArgIndex, Kind);
769 }
770
771 /// Return true if the attribute exists for the given argument
772 bool hasParamAttr(unsigned ArgNo, StringRef Kind) const {
773 return hasAttributeAtIndex(ArgNo + FirstArgIndex, Kind);
774 }
775
776 /// Return true if attributes exists for the given argument
777 bool hasParamAttrs(unsigned ArgNo) const {
778 return hasAttributesAtIndex(ArgNo + FirstArgIndex);
779 }
780
781 /// Return true if the attribute exists for the return value.
783 return hasAttributeAtIndex(ReturnIndex, Kind);
784 }
785
786 /// Return true if the attribute exists for the return value.
787 bool hasRetAttr(StringRef Kind) const {
788 return hasAttributeAtIndex(ReturnIndex, Kind);
789 }
790
791 /// Return true if attributes exist for the return value.
793
794 /// Return true if the attribute exists for the function.
795 bool hasFnAttr(Attribute::AttrKind Kind) const;
796
797 /// Return true if the attribute exists for the function.
798 bool hasFnAttr(StringRef Kind) const;
799
800 /// Return true the attributes exist for the function.
802
803 /// Return true if the specified attribute is set for at least one
804 /// parameter or for the return value. If Index is not nullptr, the index
805 /// of a parameter with the specified attribute is provided.
807 unsigned *Index = nullptr) const;
808
809 /// Return the attribute object that exists at the given index.
811
812 /// Return the attribute object that exists at the given index.
813 Attribute getAttributeAtIndex(unsigned Index, StringRef Kind) const;
814
815 /// Return the attribute object that exists at the arg index.
816 Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
817 return getAttributeAtIndex(ArgNo + FirstArgIndex, Kind);
818 }
819
820 /// Return the attribute object that exists at the given index.
821 Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const {
822 return getAttributeAtIndex(ArgNo + FirstArgIndex, Kind);
823 }
824
825 /// Return the attribute object that exists for the function.
828 }
829
830 /// Return the attribute object that exists for the function.
833 }
834
835 /// Return the alignment of the return value.
837
838 /// Return the alignment for the specified function parameter.
839 MaybeAlign getParamAlignment(unsigned ArgNo) const;
840
841 /// Return the stack alignment for the specified function parameter.
842 MaybeAlign getParamStackAlignment(unsigned ArgNo) const;
843
844 /// Return the byval type for the specified function parameter.
845 Type *getParamByValType(unsigned ArgNo) const;
846
847 /// Return the sret type for the specified function parameter.
848 Type *getParamStructRetType(unsigned ArgNo) const;
849
850 /// Return the byref type for the specified function parameter.
851 Type *getParamByRefType(unsigned ArgNo) const;
852
853 /// Return the preallocated type for the specified function parameter.
854 Type *getParamPreallocatedType(unsigned ArgNo) const;
855
856 /// Return the inalloca type for the specified function parameter.
857 Type *getParamInAllocaType(unsigned ArgNo) const;
858
859 /// Return the elementtype type for the specified function parameter.
860 Type *getParamElementType(unsigned ArgNo) const;
861
862 /// Get the stack alignment of the function.
864
865 /// Get the stack alignment of the return value.
867
868 /// Get the number of dereferenceable bytes (or zero if unknown) of the return
869 /// value.
871
872 /// Get the number of dereferenceable bytes (or zero if unknown) of an arg.
874
875 /// Get the number of dereferenceable_or_null bytes (or zero if unknown) of
876 /// the return value.
878
879 /// Get the number of dereferenceable_or_null bytes (or zero if unknown) of an
880 /// arg.
881 uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const;
882
883 /// Get the disallowed floating-point classes of the return value.
885
886 /// Get the disallowed floating-point classes of the argument value.
887 FPClassTest getParamNoFPClass(unsigned ArgNo) const;
888
889 /// Get the unwind table kind requested for the function.
891
893
894 /// Returns memory effects of the function.
896
897 /// Return the attributes at the index as a string.
898 std::string getAsString(unsigned Index, bool InAttrGrp = false) const;
899
900 /// Return true if this attribute list belongs to the LLVMContext.
901 bool hasParentContext(LLVMContext &C) const;
902
903 //===--------------------------------------------------------------------===//
904 // AttributeList Introspection
905 //===--------------------------------------------------------------------===//
906
907 using iterator = const AttributeSet *;
908
909 iterator begin() const;
910 iterator end() const;
911
912 unsigned getNumAttrSets() const;
913
914 // Implementation of indexes(). Produces iterators that wrap an index. Mostly
915 // to hide the awkwardness of unsigned wrapping when iterating over valid
916 // indexes.
918 unsigned NumAttrSets;
920 struct int_wrapper {
921 int_wrapper(unsigned i) : i(i) {}
922 unsigned i;
923 unsigned operator*() { return i; }
924 bool operator!=(const int_wrapper &Other) { return i != Other.i; }
926 // This is expected to undergo unsigned wrapping since FunctionIndex is
927 // ~0 and that's where we start.
928 ++i;
929 return *this;
930 }
931 };
932
934
936 };
937
938 /// Use this to iterate over the valid attribute indexes.
940
941 /// operator==/!= - Provide equality predicates.
942 bool operator==(const AttributeList &RHS) const { return pImpl == RHS.pImpl; }
943 bool operator!=(const AttributeList &RHS) const { return pImpl != RHS.pImpl; }
944
945 /// Return a raw pointer that uniquely identifies this attribute list.
946 void *getRawPointer() const {
947 return pImpl;
948 }
949
950 /// Return true if there are no attributes.
951 bool isEmpty() const { return pImpl == nullptr; }
952
953 void print(raw_ostream &O) const;
954
955 void dump() const;
956};
957
958//===----------------------------------------------------------------------===//
959/// \class
960/// Provide DenseMapInfo for AttributeList.
961template <> struct DenseMapInfo<AttributeList, void> {
963 auto Val = static_cast<uintptr_t>(-1);
964 Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
965 return AttributeList(reinterpret_cast<AttributeListImpl *>(Val));
966 }
967
969 auto Val = static_cast<uintptr_t>(-2);
970 Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
971 return AttributeList(reinterpret_cast<AttributeListImpl *>(Val));
972 }
973
974 static unsigned getHashValue(AttributeList AS) {
975 return (unsigned((uintptr_t)AS.pImpl) >> 4) ^
976 (unsigned((uintptr_t)AS.pImpl) >> 9);
977 }
978
980 return LHS == RHS;
981 }
982};
983
984//===----------------------------------------------------------------------===//
985/// \class
986/// This class is used in conjunction with the Attribute::get method to
987/// create an Attribute object. The object itself is uniquified. The Builder's
988/// value, however, is not. So this can be used as a quick way to test for
989/// equality, presence of attributes, etc.
991 LLVMContext &Ctx;
993
994public:
995 AttrBuilder(LLVMContext &Ctx) : Ctx(Ctx) {}
996 AttrBuilder(const AttrBuilder &) = delete;
998
999 AttrBuilder(LLVMContext &Ctx, const Attribute &A) : Ctx(Ctx) {
1000 addAttribute(A);
1001 }
1002
1004
1005 void clear();
1006
1007 /// Add an attribute to the builder.
1009
1010 /// Add the Attribute object to the builder.
1012
1013 /// Add the target-dependent attribute to the builder.
1015
1016 /// Remove an attribute from the builder.
1018
1019 /// Remove the target-dependent attribute from the builder.
1021
1022 /// Remove the target-dependent attribute from the builder.
1024 if (A.isStringAttribute())
1025 return removeAttribute(A.getKindAsString());
1026 else
1027 return removeAttribute(A.getKindAsEnum());
1028 }
1029
1030 /// Add the attributes from the builder. Attributes in the passed builder
1031 /// overwrite attributes in this builder if they have the same key.
1032 AttrBuilder &merge(const AttrBuilder &B);
1033
1034 /// Remove the attributes from the builder.
1035 AttrBuilder &remove(const AttributeMask &AM);
1036
1037 /// Return true if the builder has any attribute that's in the
1038 /// specified builder.
1039 bool overlaps(const AttributeMask &AM) const;
1040
1041 /// Return true if the builder has the specified attribute.
1042 bool contains(Attribute::AttrKind A) const;
1043
1044 /// Return true if the builder has the specified target-dependent
1045 /// attribute.
1046 bool contains(StringRef A) const;
1047
1048 /// Return true if the builder has IR-level attributes.
1049 bool hasAttributes() const { return !Attrs.empty(); }
1050
1051 /// Return Attribute with the given Kind. The returned attribute will be
1052 /// invalid if the Kind is not present in the builder.
1054
1055 /// Return Attribute with the given Kind. The returned attribute will be
1056 /// invalid if the Kind is not present in the builder.
1057 Attribute getAttribute(StringRef Kind) const;
1058
1059 /// Return raw (possibly packed/encoded) value of integer attribute or
1060 /// std::nullopt if not set.
1061 std::optional<uint64_t> getRawIntAttr(Attribute::AttrKind Kind) const;
1062
1063 /// Retrieve the alignment attribute, if it exists.
1065 return MaybeAlign(getRawIntAttr(Attribute::Alignment).value_or(0));
1066 }
1067
1068 /// Retrieve the stack alignment attribute, if it exists.
1070 return MaybeAlign(getRawIntAttr(Attribute::StackAlignment).value_or(0));
1071 }
1072
1073 /// Retrieve the number of dereferenceable bytes, if the
1074 /// dereferenceable attribute exists (zero is returned otherwise).
1076 return getRawIntAttr(Attribute::Dereferenceable).value_or(0);
1077 }
1078
1079 /// Retrieve the number of dereferenceable_or_null bytes, if the
1080 /// dereferenceable_or_null attribute exists (zero is returned otherwise).
1082 return getRawIntAttr(Attribute::DereferenceableOrNull).value_or(0);
1083 }
1084
1085 /// Retrieve type for the given type attribute.
1087
1088 /// Retrieve the byval type.
1089 Type *getByValType() const { return getTypeAttr(Attribute::ByVal); }
1090
1091 /// Retrieve the sret type.
1092 Type *getStructRetType() const { return getTypeAttr(Attribute::StructRet); }
1093
1094 /// Retrieve the byref type.
1095 Type *getByRefType() const { return getTypeAttr(Attribute::ByRef); }
1096
1097 /// Retrieve the preallocated type.
1099 return getTypeAttr(Attribute::Preallocated);
1100 }
1101
1102 /// Retrieve the inalloca type.
1103 Type *getInAllocaType() const { return getTypeAttr(Attribute::InAlloca); }
1104
1105 /// Retrieve the allocsize args, or std::nullopt if the attribute does not
1106 /// exist.
1107 std::optional<std::pair<unsigned, std::optional<unsigned>>> getAllocSizeArgs()
1108 const;
1109
1110 /// Add integer attribute with raw value (packed/encoded if necessary).
1112
1113 /// This turns an alignment into the form used internally in Attribute.
1114 /// This call has no effect if Align is not set.
1116
1117 /// This turns an int alignment (which must be a power of 2) into the
1118 /// form used internally in Attribute.
1119 /// This call has no effect if Align is 0.
1120 /// Deprecated, use the version using a MaybeAlign.
1123 }
1124
1125 /// This turns a stack alignment into the form used internally in Attribute.
1126 /// This call has no effect if Align is not set.
1128
1129 /// This turns an int stack alignment (which must be a power of 2) into
1130 /// the form used internally in Attribute.
1131 /// This call has no effect if Align is 0.
1132 /// Deprecated, use the version using a MaybeAlign.
1135 }
1136
1137 /// This turns the number of dereferenceable bytes into the form used
1138 /// internally in Attribute.
1140
1141 /// This turns the number of dereferenceable_or_null bytes into the
1142 /// form used internally in Attribute.
1144
1145 /// This turns one (or two) ints into the form used internally in Attribute.
1146 AttrBuilder &addAllocSizeAttr(unsigned ElemSizeArg,
1147 const std::optional<unsigned> &NumElemsArg);
1148
1149 /// This turns two ints into the form used internally in Attribute.
1150 AttrBuilder &addVScaleRangeAttr(unsigned MinValue,
1151 std::optional<unsigned> MaxValue);
1152
1153 /// Add a type attribute with the given type.
1155
1156 /// This turns a byval type into the form used internally in Attribute.
1158
1159 /// This turns a sret type into the form used internally in Attribute.
1161
1162 /// This turns a byref type into the form used internally in Attribute.
1164
1165 /// This turns a preallocated type into the form used internally in Attribute.
1167
1168 /// This turns an inalloca type into the form used internally in Attribute.
1170
1171 /// Add an allocsize attribute, using the representation returned by
1172 /// Attribute.getIntValue().
1174
1175 /// Add a vscale_range attribute, using the representation returned by
1176 /// Attribute.getIntValue().
1178
1179 /// This turns the unwind table kind into the form used internally in
1180 /// Attribute.
1182
1183 // This turns the allocator kind into the form used internally in Attribute.
1185
1186 /// Add memory effect attribute.
1188
1189 // Add nofpclass attribute
1191
1192 ArrayRef<Attribute> attrs() const { return Attrs; }
1193
1194 bool operator==(const AttrBuilder &B) const;
1195 bool operator!=(const AttrBuilder &B) const { return !(*this == B); }
1196};
1197
1198namespace AttributeFuncs {
1199
1200enum AttributeSafetyKind : uint8_t {
1204};
1205
1206/// Returns true if this is a type legal for the 'nofpclass' attribute. This
1207/// follows the same type rules as FPMathOperator.
1209
1210/// Which attributes cannot be applied to a type. The argument \p ASK indicates,
1211/// if only attributes that are known to be safely droppable are contained in
1212/// the mask; only attributes that might be unsafe to drop (e.g., ABI-related
1213/// attributes) are in the mask; or both.
1215
1216/// Get param/return attributes which imply immediate undefined behavior if an
1217/// invalid value is passed. For example, this includes noundef (where undef
1218/// implies UB), but not nonnull (where null implies poison). It also does not
1219/// include attributes like nocapture, which constrain the function
1220/// implementation rather than the passed value.
1222
1223/// \returns Return true if the two functions have compatible target-independent
1224/// attributes for inlining purposes.
1225bool areInlineCompatible(const Function &Caller, const Function &Callee);
1226
1227
1228/// Checks if there are any incompatible function attributes between
1229/// \p A and \p B.
1230///
1231/// \param [in] A - The first function to be compared with.
1232/// \param [in] B - The second function to be compared with.
1233/// \returns true if the functions have compatible attributes.
1234bool areOutlineCompatible(const Function &A, const Function &B);
1235
1236/// Merge caller's and callee's attributes.
1237void mergeAttributesForInlining(Function &Caller, const Function &Callee);
1238
1239/// Merges the functions attributes from \p ToMerge into function \p Base.
1240///
1241/// \param [in,out] Base - The function being merged into.
1242/// \param [in] ToMerge - The function to merge attributes from.
1243void mergeAttributesForOutlining(Function &Base, const Function &ToMerge);
1244
1245/// Update min-legal-vector-width if it is in Attribute and less than Width.
1247
1248} // end namespace AttributeFuncs
1249
1250} // end namespace llvm
1251
1252#endif // LLVM_IR_ATTRIBUTES_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
RelocType Type
Definition: COFFYAML.cpp:391
std::string Name
Load MIR Sample Profile
LLVMContext & Context
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * RHS
Value * LHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
AttrBuilder & addStructRetAttr(Type *Ty)
This turns a sret type into the form used internally in Attribute.
AttrBuilder & addAlignmentAttr(MaybeAlign Align)
This turns an alignment into the form used internally in Attribute.
Type * getByValType() const
Retrieve the byval type.
Definition: Attributes.h:1089
AttrBuilder(AttrBuilder &&)=default
AttrBuilder & addVScaleRangeAttrFromRawRepr(uint64_t RawVScaleRangeRepr)
Add a vscale_range attribute, using the representation returned by Attribute.getIntValue().
AttrBuilder(const AttrBuilder &)=delete
std::optional< uint64_t > getRawIntAttr(Attribute::AttrKind Kind) const
Return raw (possibly packed/encoded) value of integer attribute or std::nullopt if not set.
AttrBuilder & addStackAlignmentAttr(unsigned Align)
This turns an int stack alignment (which must be a power of 2) into the form used internally in Attri...
Definition: Attributes.h:1133
AttrBuilder & addAllocKindAttr(AllocFnKind Kind)
Attribute getAttribute(Attribute::AttrKind Kind) const
Return Attribute with the given Kind.
AttrBuilder & addByRefAttr(Type *Ty)
This turns a byref type into the form used internally in Attribute.
AttrBuilder & addNoFPClassAttr(FPClassTest NoFPClassMask)
bool overlaps(const AttributeMask &AM) const
Return true if the builder has any attribute that's in the specified builder.
AttrBuilder & merge(const AttrBuilder &B)
Add the attributes from the builder.
MaybeAlign getStackAlignment() const
Retrieve the stack alignment attribute, if it exists.
Definition: Attributes.h:1069
Type * getByRefType() const
Retrieve the byref type.
Definition: Attributes.h:1095
AttrBuilder & addVScaleRangeAttr(unsigned MinValue, std::optional< unsigned > MaxValue)
This turns two ints into the form used internally in Attribute.
AttrBuilder(LLVMContext &Ctx)
Definition: Attributes.h:995
uint64_t getDereferenceableBytes() const
Retrieve the number of dereferenceable bytes, if the dereferenceable attribute exists (zero is return...
Definition: Attributes.h:1075
bool hasAttributes() const
Return true if the builder has IR-level attributes.
Definition: Attributes.h:1049
AttrBuilder & addRawIntAttr(Attribute::AttrKind Kind, uint64_t Value)
Add integer attribute with raw value (packed/encoded if necessary).
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
MaybeAlign getAlignment() const
Retrieve the alignment attribute, if it exists.
Definition: Attributes.h:1064
AttrBuilder & addByValAttr(Type *Ty)
This turns a byval type into the form used internally in Attribute.
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
Type * getPreallocatedType() const
Retrieve the preallocated type.
Definition: Attributes.h:1098
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
AttrBuilder & addMemoryAttr(MemoryEffects ME)
Add memory effect attribute.
AttrBuilder & addAllocSizeAttrFromRawRepr(uint64_t RawAllocSizeRepr)
Add an allocsize attribute, using the representation returned by Attribute.getIntValue().
AttrBuilder & addPreallocatedAttr(Type *Ty)
This turns a preallocated type into the form used internally in Attribute.
Type * getInAllocaType() const
Retrieve the inalloca type.
Definition: Attributes.h:1103
AttrBuilder & addStackAlignmentAttr(MaybeAlign Align)
This turns a stack alignment into the form used internally in Attribute.
AttrBuilder & removeAttribute(Attribute A)
Remove the target-dependent attribute from the builder.
Definition: Attributes.h:1023
uint64_t getDereferenceableOrNullBytes() const
Retrieve the number of dereferenceable_or_null bytes, if the dereferenceable_or_null attribute exists...
Definition: Attributes.h:1081
ArrayRef< Attribute > attrs() const
Definition: Attributes.h:1192
AttrBuilder & addInAllocaAttr(Type *Ty)
This turns an inalloca type into the form used internally in Attribute.
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
bool operator==(const AttrBuilder &B) const
Type * getTypeAttr(Attribute::AttrKind Kind) const
Retrieve type for the given type attribute.
AttrBuilder & remove(const AttributeMask &AM)
Remove the attributes from the builder.
AttrBuilder & addDereferenceableOrNullAttr(uint64_t Bytes)
This turns the number of dereferenceable_or_null bytes into the form used internally in Attribute.
AttrBuilder & addAlignmentAttr(unsigned Align)
This turns an int alignment (which must be a power of 2) into the form used internally in Attribute.
Definition: Attributes.h:1121
AttrBuilder & addTypeAttr(Attribute::AttrKind Kind, Type *Ty)
Add a type attribute with the given type.
std::optional< std::pair< unsigned, std::optional< unsigned > > > getAllocSizeArgs() const
Retrieve the allocsize args, or std::nullopt if the attribute does not exist.
AttrBuilder & addAllocSizeAttr(unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
This turns one (or two) ints into the form used internally in Attribute.
bool operator!=(const AttrBuilder &B) const
Definition: Attributes.h:1195
Type * getStructRetType() const
Retrieve the sret type.
Definition: Attributes.h:1092
AttrBuilder(LLVMContext &Ctx, const Attribute &A)
Definition: Attributes.h:999
AttrBuilder & addUWTableAttr(UWTableKind Kind)
This turns the unwind table kind into the form used internally in Attribute.
Attribute getFnAttr(StringRef Kind) const
Return the attribute object that exists for the function.
Definition: Attributes.h:831
bool operator==(const AttributeList &RHS) const
operator==/!= - Provide equality predicates.
Definition: Attributes.h:942
bool hasAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
Type * getParamStructRetType(unsigned ArgNo) const
Return the sret type for the specified function parameter.
AttributeList addDereferenceableParamAttr(LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given arg index.
AttributeList removeAttributeAtIndex(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
AttributeList removeParamAttributes(LLVMContext &C, unsigned ArgNo) const
Remove all attributes at the specified arg index from this attribute list.
Definition: Attributes.h:699
AttributeList removeParamAttributes(LLVMContext &C, unsigned ArgNo, const AttributeMask &AttrsToRemove) const
Remove the specified attribute at the specified arg index from this attribute list.
Definition: Attributes.h:692
bool hasAttributesAtIndex(unsigned Index) const
Return true if attribute exists at the given index.
AttributeList removeRetAttribute(LLVMContext &C, StringRef Kind) const
Remove the specified attribute at the return value index from this attribute list.
Definition: Attributes.h:661
bool hasRetAttr(StringRef Kind) const
Return true if the attribute exists for the return value.
Definition: Attributes.h:787
AttributeSet getFnAttrs() const
The function attributes are returned.
index_iterator indexes() const
Use this to iterate over the valid attribute indexes.
Definition: Attributes.h:939
AttributeList removeAttributesAtIndex(LLVMContext &C, unsigned Index, const AttributeMask &AttrsToRemove) const
Remove the specified attributes at the specified index from this attribute list.
AttributeList()=default
AttributeList addRetAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add a return value attribute to the list.
Definition: Attributes.h:551
AttributeList addAllocSizeParamAttr(LLVMContext &C, unsigned ArgNo, unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
Add the allocsize attribute to the attribute set at the given arg index.
iterator begin() const
bool hasParamAttrs(unsigned ArgNo) const
Return true if attributes exists for the given argument.
Definition: Attributes.h:777
MaybeAlign getRetStackAlignment() const
Get the stack alignment of the return value.
AttributeList addRetAttributes(LLVMContext &C, const AttrBuilder &B) const
Add a return value attribute to the list.
Definition: Attributes.h:565
void print(raw_ostream &O) const
AttributeList addDereferenceableRetAttr(LLVMContext &C, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given index.
AttributeList removeRetAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const
Remove the specified attribute at the return value index from this attribute list.
Definition: Attributes.h:669
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return the attribute object that exists at the arg index.
Definition: Attributes.h:816
AttributeList removeAttribute(LLVMContext &C, unsigned Index, StringRef Kind) const
Definition: Attributes.h:609
void * getRawPointer() const
Return a raw pointer that uniquely identifies this attribute list.
Definition: Attributes.h:946
AttributeList removeParamAttribute(LLVMContext &C, unsigned ArgNo, StringRef Kind) const
Remove the specified attribute at the specified arg index from this attribute list.
Definition: Attributes.h:685
AllocFnKind getAllocKind() const
bool isEmpty() const
Return true if there are no attributes.
Definition: Attributes.h:951
AttributeList addFnAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add a function attribute to the list.
Definition: Attributes.h:522
AttributeSet getRetAttrs() const
The attributes for the ret value are returned.
AttributeList addFnAttributes(LLVMContext &C, const AttrBuilder &B) const
Add function attribute to the list.
Definition: Attributes.h:544
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the function.
uint64_t getParamDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown) of an arg.
MaybeAlign getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
bool hasParamAttr(unsigned ArgNo, StringRef Kind) const
Return true if the attribute exists for the given argument.
Definition: Attributes.h:772
AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, StringRef Kind, StringRef Value=StringRef()) const
Add an argument attribute to the list.
Definition: Attributes.h:581
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value.
iterator end() const
Type * getParamInAllocaType(unsigned ArgNo) const
Return the inalloca type for the specified function parameter.
unsigned getNumAttrSets() const
bool operator!=(const AttributeList &RHS) const
Definition: Attributes.h:943
FPClassTest getRetNoFPClass() const
Get the disallowed floating-point classes of the return value.
Attribute getFnAttr(Attribute::AttrKind Kind) const
Return the attribute object that exists for the function.
Definition: Attributes.h:826
std::string getAsString(unsigned Index, bool InAttrGrp=false) const
Return the attributes at the index as a string.
UWTableKind getUWTableKind() const
Get the unwind table kind requested for the function.
MaybeAlign getRetAlignment() const
Return the alignment of the return value.
Type * getParamElementType(unsigned ArgNo) const
Return the elementtype type for the specified function parameter.
Attribute getAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
Type * getParamPreallocatedType(unsigned ArgNo) const
Return the preallocated type for the specified function parameter.
bool hasParentContext(LLVMContext &C) const
Return true if this attribute list belongs to the LLVMContext.
AttributeList removeParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified arg index from this attribute list.
Definition: Attributes.h:677
AttributeList addFnAttribute(LLVMContext &C, StringRef Kind, StringRef Value=StringRef()) const
Add a function attribute to the list.
Definition: Attributes.h:537
bool hasParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the attribute exists for the given argument.
Definition: Attributes.h:767
MaybeAlign getFnStackAlignment() const
Get the stack alignment of the function.
AttributeList addAttributesAtIndex(LLVMContext &C, unsigned Index, const AttrBuilder &B) const
Add attributes to the attribute set at the given index.
Type * getParamByValType(unsigned ArgNo) const
Return the byval type for the specified function parameter.
AttributeList removeFnAttributes(LLVMContext &C) const
Remove the attributes at the function index from this attribute list.
Definition: Attributes.h:648
MaybeAlign getParamStackAlignment(unsigned ArgNo) const
Return the stack alignment for the specified function parameter.
uint64_t getRetDereferenceableBytes() const
Get the number of dereferenceable bytes (or zero if unknown) of the return value.
Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const
Return the attribute object that exists at the given index.
Definition: Attributes.h:821
AttributeList removeFnAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute at the function index from this attribute list.
Definition: Attributes.h:628
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Get the number of dereferenceable_or_null bytes (or zero if unknown) of an arg.
bool hasRetAttrs() const
Return true if attributes exist for the return value.
Definition: Attributes.h:792
AttributeList addDereferenceableOrNullParamAttr(LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const
Add the dereferenceable_or_null attribute to the attribute set at the given arg index.
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
AttributeList addRetAttribute(LLVMContext &C, Attribute Attr) const
Add a return value attribute to the list.
Definition: Attributes.h:558
FPClassTest getParamNoFPClass(unsigned ArgNo) const
Get the disallowed floating-point classes of the argument value.
AttributeList removeFnAttribute(LLVMContext &C, StringRef Kind) const
Remove the specified attribute at the function index from this attribute list.
Definition: Attributes.h:634
AttributeList removeFnAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const
Remove the specified attribute at the function index from this attribute list.
Definition: Attributes.h:642
bool hasFnAttrs() const
Return true the attributes exist for the function.
Definition: Attributes.h:801
Type * getParamByRefType(unsigned ArgNo) const
Return the byref type for the specified function parameter.
AttributeList addAttributeAtIndex(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
AttributeSet getParamAttrs(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
AttributeList addParamAttributes(LLVMContext &C, unsigned ArgNo, const AttrBuilder &B) const
Add an argument attribute to the list.
Definition: Attributes.h:594
uint64_t getRetDereferenceableOrNullBytes() const
Get the number of dereferenceable_or_null bytes (or zero if unknown) of the return value.
AttributeList removeRetAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute at the return value index from this attribute list.
Definition: Attributes.h:655
AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
Definition: Attributes.h:573
AttributeList replaceAttributeTypeAtIndex(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind, Type *ReplacementTy) const
Replace the type contained by attribute AttrKind at index ArgNo wih ReplacementTy,...
Definition: Attributes.h:707
AttributeList addFnAttribute(LLVMContext &C, Attribute Attr) const
Add a function attribute to the list.
Definition: Attributes.h:529
MemoryEffects getMemoryEffects() const
Returns memory effects of the function.
bool hasRetAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the return value.
Definition: Attributes.h:782
AllocFnKind getAllocKind() const
Definition: Attributes.cpp:854
bool hasAttributes() const
Return true if attributes exists in this set.
Definition: Attributes.h:357
AttributeSet removeAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute from this set.
Definition: Attributes.cpp:748
Type * getInAllocaType() const
Definition: Attributes.cpp:827
Type * getByValType() const
Definition: Attributes.cpp:815
bool operator!=(const AttributeSet &O) const
Definition: Attributes.h:321
AttributeSet addAttributes(LLVMContext &C, AttributeSet AS) const
Add attributes to the attribute set.
Definition: Attributes.cpp:735
MemoryEffects getMemoryEffects() const
Definition: Attributes.cpp:858
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
Definition: Attributes.cpp:779
bool operator==(const AttributeSet &O) const
Definition: Attributes.h:320
Type * getStructRetType() const
Definition: Attributes.cpp:819
std::string getAsString(bool InAttrGrp=false) const
Definition: Attributes.cpp:866
~AttributeSet()=default
unsigned getVScaleRangeMin() const
Definition: Attributes.cpp:842
std::optional< std::pair< unsigned, std::optional< unsigned > > > getAllocSizeArgs() const
Definition: Attributes.cpp:836
UWTableKind getUWTableKind() const
Definition: Attributes.cpp:850
bool hasParentContext(LLVMContext &C) const
Return true if this attribute set belongs to the LLVMContext.
Definition: Attributes.cpp:870
iterator begin() const
Definition: Attributes.cpp:878
iterator end() const
Definition: Attributes.cpp:882
AttributeSet removeAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const
Remove the specified attributes from this set.
Definition: Attributes.cpp:764
std::optional< unsigned > getVScaleRangeMax() const
Definition: Attributes.cpp:846
MaybeAlign getStackAlignment() const
Definition: Attributes.cpp:799
Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
Definition: Attributes.cpp:787
Type * getPreallocatedType() const
Definition: Attributes.cpp:823
uint64_t getDereferenceableBytes() const
Definition: Attributes.cpp:803
MaybeAlign getAlignment() const
Definition: Attributes.cpp:795
FPClassTest getNoFPClass() const
Definition: Attributes.cpp:862
AttributeSet(const AttributeSet &)=default
Type * getElementType() const
Definition: Attributes.cpp:831
Type * getByRefType() const
Definition: Attributes.cpp:811
AttributeSet()=default
AttributeSet is a trivially copyable value type.
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
Definition: Attributes.cpp:712
uint64_t getDereferenceableOrNullBytes() const
Definition: Attributes.cpp:807
unsigned getNumAttributes() const
Return the number of attributes in this set.
Definition: Attributes.cpp:775
AttributeSet addAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add an argument attribute.
Definition: Attributes.cpp:720
void dump() const
Definition: Attributes.cpp:887
static const unsigned NumTypeAttrKinds
Definition: Attributes.h:95
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:282
static Attribute getWithStructRetType(LLVMContext &Context, Type *Ty)
Definition: Attributes.cpp:194
bool operator==(Attribute A) const
Equality and non-equality operators.
Definition: Attributes.h:262
static Attribute::AttrKind getAttrKindFromName(StringRef AttrName)
Definition: Attributes.cpp:239
bool isEnumAttribute() const
Return true if the attribute is an Attribute::AttrKind type.
Definition: Attributes.cpp:274
static Attribute getWithStackAlignment(LLVMContext &Context, Align Alignment)
Definition: Attributes.cpp:173
bool isIntAttribute() const
Return true if the attribute is an integer attribute.
Definition: Attributes.cpp:278
static Attribute getWithByRefType(LLVMContext &Context, Type *Ty)
Definition: Attributes.cpp:198
std::optional< unsigned > getVScaleRangeMax() const
Returns the maximum value for the vscale_range attribute or std::nullopt when unknown.
Definition: Attributes.cpp:381
uint64_t getValueAsInt() const
Return the attribute's value as an integer.
Definition: Attributes.cpp:297
unsigned getVScaleRangeMin() const
Returns the minimum value for the vscale_range attribute.
Definition: Attributes.cpp:375
AllocFnKind getAllocKind() const
Definition: Attributes.cpp:393
StringRef getKindAsString() const
Return the attribute's kind as a string.
Definition: Attributes.cpp:311
static Attribute getWithPreallocatedType(LLVMContext &Context, Type *Ty)
Definition: Attributes.cpp:202
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:92
static bool canUseAsRetAttr(AttrKind Kind)
Definition: Attributes.cpp:635
static bool isTypeAttrKind(AttrKind Kind)
Definition: Attributes.h:103
std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
Definition: Attributes.cpp:425
uint64_t getDereferenceableOrNullBytes() const
Returns the number of dereferenceable_or_null bytes from the dereferenceable_or_null attribute.
Definition: Attributes.cpp:361
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:178
std::pair< unsigned, std::optional< unsigned > > getAllocSizeArgs() const
Returns the argument numbers for the allocsize attribute.
Definition: Attributes.cpp:369
static Attribute getWithUWTableKind(LLVMContext &Context, UWTableKind Kind)
Definition: Attributes.cpp:210
bool operator!=(Attribute A) const
Definition: Attributes.h:263
FPClassTest getNoFPClass() const
Return the FPClassTest for nofpclass.
Definition: Attributes.cpp:405
static Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
Definition: Attributes.cpp:226
Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
Definition: Attributes.cpp:290
Attribute()=default
bool getValueAsBool() const
Return the attribute's value as a boolean.
Definition: Attributes.cpp:304
uint64_t getDereferenceableBytes() const
Returns the number of dereferenceable bytes from the dereferenceable attribute.
Definition: Attributes.cpp:354
static Attribute getWithVScaleRangeArgs(LLVMContext &Context, unsigned MinValue, unsigned MaxValue)
Definition: Attributes.cpp:233
MemoryEffects getMemoryEffects() const
Returns memory effects.
Definition: Attributes.cpp:399
UWTableKind getUWTableKind() const
Definition: Attributes.cpp:387
static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes)
Definition: Attributes.cpp:184
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:318
static bool isExistingAttribute(StringRef Name)
Return true if the provided string matches the IR name of an attribute.
Definition: Attributes.cpp:262
static StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind)
Definition: Attributes.cpp:248
static bool canUseAsFnAttr(AttrKind Kind)
Definition: Attributes.cpp:627
static Attribute getWithNoFPClass(LLVMContext &Context, FPClassTest Mask)
Definition: Attributes.cpp:220
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:84
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
Definition: Attributes.h:91
@ None
No attributes have been set.
Definition: Attributes.h:86
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
Definition: Attributes.h:90
@ EndAttrKinds
Sentinal value useful for loops.
Definition: Attributes.h:89
void * getRawPointer() const
Return a raw pointer that uniquely identifies this attribute.
Definition: Attributes.h:271
bool hasParentContext(LLVMContext &C) const
Return true if this attribute belongs to the LLVMContext.
Definition: Attributes.cpp:592
bool isTypeAttribute() const
Return true if the attribute is a type attribute.
Definition: Attributes.cpp:286
static Attribute getWithInAllocaType(LLVMContext &Context, Type *Ty)
Definition: Attributes.cpp:206
static bool isIntAttrKind(AttrKind Kind)
Definition: Attributes.h:100
static Attribute getWithByValType(LLVMContext &Context, Type *Ty)
Definition: Attributes.cpp:190
Attribute getWithNewType(LLVMContext &Context, Type *ReplacementTy)
For a typed attribute, return the equivalent attribute with the type changed to ReplacementTy.
Definition: Attributes.h:153
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
Definition: Attributes.cpp:333
static bool isEnumAttrKind(AttrKind Kind)
Definition: Attributes.h:97
static Attribute getWithMemoryEffects(LLVMContext &Context, MemoryEffects ME)
Definition: Attributes.cpp:215
static bool canUseAsParamAttr(AttrKind Kind)
Definition: Attributes.cpp:631
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition: Attributes.h:184
MaybeAlign getStackAlignment() const
Returns the stack alignment field of an attribute as a byte alignment value.
Definition: Attributes.cpp:348
static Attribute fromRawPointer(void *RawPtr)
Get an attribute from a raw pointer created by getRawPointer.
Definition: Attributes.h:276
static const unsigned NumIntAttrKinds
Definition: Attributes.h:94
MaybeAlign getAlignment() const
Returns the alignment field of an attribute as a byte alignment value.
Definition: Attributes.cpp:342
bool operator<(Attribute A) const
Less-than operator. Useful for sorting the attributes list.
Definition: Attributes.cpp:600
static Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
Definition: Attributes.cpp:168
Type * getValueAsType() const
Return the attribute's value as a Type.
Definition: Attributes.cpp:325
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:319
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
struct LLVMOpaqueAttributeRef * LLVMAttributeRef
Used to represent an attributes.
Definition: Types.h:140
bool areInlineCompatible(const Function &Caller, const Function &Callee)
AttributeMask getUBImplyingAttributes()
Get param/return attributes which imply immediate undefined behavior if an invalid value is passed.
bool isNoFPClassCompatibleType(Type *Ty)
Returns true if this is a type legal for the 'nofpclass' attribute.
bool areOutlineCompatible(const Function &A, const Function &B)
Checks if there are any incompatible function attributes between A and B.
void updateMinLegalVectorWidthAttr(Function &Fn, uint64_t Width)
Update min-legal-vector-width if it is in Attribute and less than Width.
void mergeAttributesForOutlining(Function &Base, const Function &ToMerge)
Merges the functions attributes from ToMerge into function Base.
void mergeAttributesForInlining(Function &Caller, const Function &Callee)
Merge caller's and callee's attributes.
AttributeMask typeIncompatible(Type *Ty, AttributeSafetyKind ASK=ASK_ALL)
Which attributes cannot be applied to a type.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Uninitialized
Definition: Threading.h:61
AllocFnKind
Definition: Attributes.h:47
UWTableKind
Definition: CodeGen.h:120
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
@ Other
Any other memory.
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:287
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:282
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
bool operator!=(const int_wrapper &Other)
Definition: Attributes.h:924
static unsigned getHashValue(AttributeList AS)
Definition: Attributes.h:974
static AttributeList getTombstoneKey()
Definition: Attributes.h:968
static bool isEqual(AttributeList LHS, AttributeList RHS)
Definition: Attributes.h:979
static AttributeSet getTombstoneKey()
Definition: Attributes.h:413
static bool isEqual(AttributeSet LHS, AttributeSet RHS)
Definition: Attributes.h:424
static unsigned getHashValue(AttributeSet AS)
Definition: Attributes.h:419
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:50
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117