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