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