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