Go to the documentation of this file.
15 #ifndef LLVM_IR_ATTRIBUTES_H
16 #define LLVM_IR_ATTRIBUTES_H
24 #include "llvm/Config/llvm-config.h"
38 class AttributeListImpl;
39 class AttributeSetNode;
40 template<
typename T>
struct DenseMapInfo;
41 class FoldingSetNodeID;
74 #define GET_ATTR_NAMES
75 #define ATTRIBUTE_ENUM(ENUM_NAME, OTHER) ENUM_NAME,
76 #include "llvm/IR/Attributes.inc"
97 StringRef Val = StringRef());
109 unsigned ElemSizeArg,
110 const Optional<unsigned> &NumElemsArg);
112 unsigned MinValue,
unsigned MaxValue);
213 std::string
getAsString(
bool InAttrGrp =
false)
const;
339 std::string
getAsString(
bool InAttrGrp =
false)
const;
348 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
358 auto Val =
static_cast<uintptr_t
>(-1);
359 Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable;
364 auto Val =
static_cast<uintptr_t
>(-2);
365 Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable;
370 return (
unsigned((uintptr_t)AS.SetNode) >> 4) ^
371 (unsigned((uintptr_t)AS.SetNode) >> 9);
512 unsigned Index)
const;
545 unsigned ArgNo)
const {
554 Type *ReplacementTy)
const {
564 uint64_t Bytes)
const;
663 unsigned *
Index =
nullptr)
const;
728 std::pair<unsigned, Optional<unsigned>>
765 bool isEmpty()
const {
return pImpl ==
nullptr; }
777 auto Val =
static_cast<uintptr_t
>(-1);
778 Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
783 auto Val =
static_cast<uintptr_t
>(-2);
784 Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
789 return (
unsigned((uintptr_t)AS.pImpl) >> 4) ^
790 (unsigned((uintptr_t)AS.pImpl) >> 9);
805 std::bitset<Attribute::EndAttrKinds> Attrs;
806 std::map<SmallString<32>,
SmallString<32>, std::less<>> TargetDepAttrs;
809 uint64_t DerefBytes = 0;
810 uint64_t DerefOrNullBytes = 0;
811 uint64_t AllocSizeArgs = 0;
812 uint64_t VScaleRangeArgs = 0;
813 Type *ByValType =
nullptr;
814 Type *StructRetType =
nullptr;
815 Type *ByRefType =
nullptr;
816 Type *PreallocatedType =
nullptr;
817 Type *InAllocaType =
nullptr;
834 "Attribute out of range!");
836 "Adding integer attribute without adding a value!");
987 bool empty()
const {
return Attrs.none(); }
990 using td_type = decltype(TargetDepAttrs)::value_type;
1008 bool td_empty()
const {
return TargetDepAttrs.empty(); }
1014 namespace AttributeFuncs {
1045 #endif // LLVM_IR_ATTRIBUTES_H
LLVM_NODISCARD AttributeList removeParamAttributes(LLVMContext &C, unsigned ArgNo) const
Remove all attributes at the specified arg index from this attribute list.
AttrBuilder & addDereferenceableOrNullAttr(uint64_t Bytes)
This turns the number of dereferenceable_or_null bytes into the form used internally in Attribute.
Type * getParamInAllocaType(unsigned ArgNo) const
Return the inalloca type for the specified function parameter.
void print(raw_ostream &O) const
static Attribute getWithPreallocatedType(LLVMContext &Context, Type *Ty)
@ EndAttrKinds
Sentinal value useful for loops.
LLVM_NODISCARD AttributeList replaceAttributeType(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind, Type *ReplacementTy) const
Replace the type contained by attribute AttrKind at index ArgNo wih ReplacementTy,...
AttributeSet()=default
AttributeSet is a trivially copyable value type.
void mergeAttributesForOutlining(Function &Base, const Function &ToMerge)
Merges the functions attributes from ToMerge into function Base.
MaybeAlign getStackAlignment() const
Retrieve the stack alignment attribute, if it exists.
Type * getByValType() const
Retrieve the byval type.
bool isEnumAttribute() const
Return true if the attribute is an Attribute::AttrKind type.
bool isValid() const
Return true if the attribute is any kind of attribute.
bool hasAttributes() const
Return true if attributes exists in this set.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but may be faster.
bool hasAlignmentAttr() const
Return true if the builder has an alignment attribute.
MaybeAlign getStackAlignment() const
Returns the stack alignment field of an attribute as a byte alignment value.
bool overlaps(const AttrBuilder &B) const
Return true if the builder has any attribute that's in the specified builder.
static Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value.
uint64_t getDereferenceableOrNullBytes() const
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
LLVM_NODISCARD AttributeList addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable_or_null attribute to the attribute set at the given index.
uint64_t getDereferenceableBytes() const
Retrieve the number of dereferenceable bytes, if the dereferenceable attribute exists (zero is return...
AttrBuilder & removeAttributes(AttributeList A, uint64_t WithoutIndex)
Remove the attributes from the builder.
bool hasAttributes() const
Return true if the builder has IR-level attributes.
LLVM_NODISCARD AttributeSet removeAttributes(LLVMContext &C, const AttrBuilder &AttrsToRemove) const
Remove the specified attributes from this set.
Type * getParamPreallocatedType(unsigned ArgNo) const
Return the preallocated type for the specified function parameter.
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
static Attribute::AttrKind getAttrKindFromName(StringRef AttrName)
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
bool isTypeAttribute() const
Return true if the attribute is a type attribute.
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const Module *M)
This lazily constructs the LazyValueInfoImpl.
LLVM_NODISCARD AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
LLVM_NODISCARD AttributeSet addAttributes(LLVMContext &C, AttributeSet AS) const
Add attributes to the attribute set.
LLVM_NODISCARD AttributeList addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
decltype(TargetDepAttrs)::iterator td_iterator
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
static Attribute getWithStackAlignment(LLVMContext &Context, Align Alignment)
MaybeAlign getAlignment() const
Retrieve the alignment attribute, if it exists.
AttrBuilder typeIncompatible(Type *Ty)
Which attributes cannot be applied to a type.
Type * getParamByValType(unsigned ArgNo) const
Return the byval type for the specified function parameter.
LLVM_NODISCARD AttributeList addDereferenceableAttr(LLVMContext &C, unsigned Index, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given index.
static unsigned getHashValue(AttributeSet AS)
AttrBuilder & addAllocSizeAttr(unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
This turns one (or two) ints into the form used internally in Attribute.
The instances of the Type class are immutable: once they are created, they are never changed.
static Attribute getWithVScaleRangeArgs(LLVMContext &Context, unsigned MinValue, unsigned MaxValue)
static bool isEqual(AttributeList LHS, AttributeList RHS)
bool operator==(Attribute A) const
Equality and non-equality operators.
AttrBuilder & addPreallocatedAttr(Type *Ty)
This turns a preallocated type into the form used internally in Attribute.
bool operator==(const AttributeSet &O) const
void * getRawPointer() const
Return a raw pointer that uniquely identifies this attribute list.
static AttributeList getEmptyKey()
MaybeAlign getAlignment() const
Returns the alignment field of an attribute as a byte alignment value.
AttrBuilder & addAlignmentAttr(unsigned Align)
This turns an int alignment (which must be a power of 2) into the form used internally in Attribute.
AttrBuilder & merge(const AttrBuilder &B)
Add the attributes from the builder.
LLVM_NODISCARD AttributeList addAllocSizeAttr(LLVMContext &C, unsigned Index, unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Add the allocsize attribute to the attribute set at the given index.
LLVM_NODISCARD AttributeList removeParamAttribute(LLVMContext &C, unsigned ArgNo, StringRef Kind) const
Remove the specified attribute at the specified arg index from this attribute list.
bool getValueAsBool() const
Return the attribute's value as a boolean.
unsigned index_end() const
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
std::pair< unsigned, unsigned > getVScaleRangeArgs() const
Retrieve the vscale_range args, if the vscale_range attribute exists.
MaybeAlign getParamStackAlignment(unsigned ArgNo) const
Return the stack alignment for the specified function parameter.
uint64_t getValueAsInt() const
Return the attribute's value as an integer.
LLVM_NODISCARD AttributeSet addAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add an argument attribute.
static Attribute getWithInAllocaType(LLVMContext &Context, Type *Ty)
bool operator!=(const AttributeSet &O) const
bool hasParentContext(LLVMContext &C) const
Return true if this attribute list belongs to the LLVMContext.
AttrBuilder & addByValAttr(Type *Ty)
This turns a byval type into the form used internally in Attribute.
std::string getAsString(bool InAttrGrp=false) const
LLVM_NODISCARD AttributeList removeAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &AttrsToRemove) const
Remove the specified attributes at the specified index from this attribute list.
LLVM_NODISCARD AttributeList removeParamAttributes(LLVMContext &C, unsigned ArgNo, const AttrBuilder &AttrsToRemove) const
Remove the specified attribute at the specified arg index from this attribute list.
(vector float) vec_cmpeq(*A, *B) C
unsigned index_begin() const
Use these to iterate over the valid attribute indices.
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
bool operator==(const AttrBuilder &B) const
AttributeSet getFnAttributes() const
The function attributes are returned.
decltype(TargetDepAttrs)::const_iterator td_const_iterator
uint64_t getDereferenceableBytes() const
bool areOutlineCompatible(const Function &A, const Function &B)
Checks if there are any incompatible function attributes between A and B.
AttributeSet getParamAttributes(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
bool empty() const
Return true if the builder contains no target-independent attributes.
std::pair< unsigned, unsigned > getVScaleRangeArgs() const
Returns the argument numbers for the vscale_range attribute (or pair(0, 0) if not known).
std::pair< unsigned, unsigned > getVScaleRangeArgs() const
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
Attribute unwrap(LLVMAttributeRef Attr)
MaybeAlign getRetAlignment() const
Return the alignment of the return value.
td_const_iterator td_end() const
This class implements an extremely fast bulk output stream that can only output to a stream.
Type * getInAllocaType() const
MaybeAlign getStackAlignment(unsigned Index) const
Get the stack alignment.
StringRef getKindAsString() const
Return the attribute's kind as a string.
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
LLVM_NODISCARD AttributeList removeParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified arg index from this attribute list.
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
This struct is a compact representation of a valid (non-zero power of two) alignment.
static Attribute getWithStructRetType(LLVMContext &Context, Type *Ty)
Type * getByRefType() const
Retrieve the byref type.
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
StringRef getValueAsString() const
Return the attribute's value as a string.
AttrBuilder & addAlignmentAttr(MaybeAlign Align)
This turns an alignment into the form used internally in Attribute.
Type * getStructRetType() const
Retrieve the sret type.
decltype(TargetDepAttrs)::value_type td_type
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs(unsigned Index) const
Get the allocsize argument numbers (or pair(0, 0) if unknown).
LLVM_NODISCARD AttributeList addAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &B) const
Add attributes to the attribute set at the given index.
AttrBuilder & addStackAlignmentAttr(MaybeAlign Align)
This turns a stack alignment into the form used internally in Attribute.
bool operator!=(Attribute A) const
void * getRawPointer() const
Return a raw pointer that uniquely identifies this attribute.
@ None
No attributes have been set.
uint64_t getDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown).
AttrBuilder & addVScaleRangeAttrFromRawRepr(uint64_t RawVScaleRangeRepr)
Add a vscale_range attribute, using the representation returned by Attribute.getIntValue().
Attribute getWithNewType(LLVMContext &Context, Type *ReplacementTy)
For a typed attribute, return the equivalent attribute with the type changed to ReplacementTy.
iterator_range< td_const_iterator > td_const_range
LLVM_NODISCARD AttributeList addParamAttributes(LLVMContext &C, unsigned ArgNo, const AttrBuilder &B) const
Add an argument attribute to the list.
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
AttrBuilder & addInAllocaAttr(Type *Ty)
This turns an inalloca type into the form used internally in Attribute.
LLVM_NODISCARD AttributeList addAllocSizeParamAttr(LLVMContext &C, unsigned ArgNo, unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
Add the allocsize attribute to the attribute set at the given arg index.
uint64_t getDereferenceableOrNullBytes() const
Retrieve the number of dereferenceable_or_null bytes, if the dereferenceable_or_null attribute exists...
iterator_range< td_iterator > td_range
static bool isEqual(AttributeSet LHS, AttributeSet RHS)
bool operator!=(const AttrBuilder &B) const
This is an important class for using LLVM in a threaded context.
std::string getAsString(unsigned Index, bool InAttrGrp=false) const
Return the attributes at the index as a string.
Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
MaybeAlign getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
static bool doesAttrKindHaveArgument(Attribute::AttrKind AttrKind)
Return true if and only if the attribute has an Argument.
bool hasParentContext(LLVMContext &C) const
Return true if this attribute set belongs to the LLVMContext.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
AttrBuilder & addByRefAttr(Type *Ty)
This turns a byref type into the form used internally in Attribute.
LLVM_NODISCARD AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, StringRef Kind, StringRef Value=StringRef()) const
Add an argument attribute to the list.
std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
AttrBuilder(const Attribute &A)
LLVM_NODISCARD AttributeSet removeAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute from this set.
Type * getPreallocatedType() const
Retrieve the preallocated type.
static AttributeSet getEmptyKey()
unsigned getNumAttributes() const
Return the number of attributes in this set.
std::pair< unsigned, unsigned > getVScaleRangeArgs(unsigned Index) const
Get the vscale_range argument numbers (or pair(0, 0) if unknown).
bool operator==(const AttributeList &RHS) const
operator==/!= - Provide equality predicates.
LLVMAttributeRef wrap(Attribute Attr)
AttrBuilder & addStackAlignmentAttr(unsigned Align)
This turns an int stack alignment (which must be a power of 2) into the form used internally in Attri...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
StringRef - Represent a constant reference to a string, i.e.
uint64_t getDereferenceableOrNullBytes() const
Returns the number of dereferenceable_or_null bytes from the dereferenceable_or_null attribute.
Type * getParamByRefType(unsigned ArgNo) const
Return the byref type for the specified function parameter.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
LLVM_NODISCARD AttributeList addVScaleRangeAttr(LLVMContext &C, unsigned Index, unsigned MinValue, unsigned MaxValue)
Add the vscale_range attribute to the attribute set at the given index.
AttrBuilder & addAllocSizeAttrFromRawRepr(uint64_t RawAllocSizeRepr)
Add an allocsize attribute, using the representation returned by Attribute.getIntValue().
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes)
struct LLVMOpaqueAttributeRef * LLVMAttributeRef
Used to represent an attributes.
AttrBuilder & addStructRetAttr(Type *Ty)
This turns a sret type into the form used internally in Attribute.
amdgpu Simplify well known AMD library false FunctionCallee Callee
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Get the number of dereferenceable_or_null bytes (or zero if unknown) of an arg.
static Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
uint64_t getDereferenceableBytes() const
Returns the number of dereferenceable bytes from the dereferenceable attribute.
bool hasParentContext(LLVMContext &C) const
Return true if this attribute belongs to the LLVMContext.
Type * getPreallocatedType() const
AttrBuilder & remove(const AttrBuilder &B)
Remove the attributes from the builder.
Type * getByRefType() const
static bool isExistingAttribute(StringRef Name)
Return true if the provided string matches the IR name of an attribute.
Type * getByValType() const
bool hasParamAttr(unsigned ArgNo, StringRef Kind) const
Return true if the attribute exists for the given argument.
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
LLVM_NODISCARD AttributeList removeParamUndefImplyingAttributes(LLVMContext &C, unsigned ArgNo) const
Remove noundef attribute and other attributes that imply undefined behavior if a undef or poison valu...
Type * getParamStructRetType(unsigned ArgNo) const
Return the sret type for the specified function parameter.
td_const_range td_attrs() const
Type * getValueAsType() const
Return the attribute's value as a Type.
LLVM_NODISCARD AttributeList removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
unsigned getNumAttrSets() const
td_const_iterator td_begin() const
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
uint64_t getDereferenceableOrNullBytes(unsigned Index) const
Get the number of dereferenceable_or_null bytes (or zero if unknown).
static Attribute getWithByRefType(LLVMContext &Context, Type *Ty)
static StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind)
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
AttributeSet getRetAttributes() const
The attributes for the ret value are returned.
bool areInlineCompatible(const Function &Caller, const Function &Callee)
Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
bool operator!=(const AttributeList &RHS) const
LLVM_NODISCARD AttributeList addDereferenceableOrNullParamAttr(LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const
Add the dereferenceable_or_null attribute to the attribute set at the given arg index.
A range adaptor for a pair of iterators.
bool hasParamAttrs(unsigned ArgNo) const
Return true if attributes exists for the given argument.
void Profile(FoldingSetNodeID &ID) const
MaybeAlign getStackAlignment() const
bool isIntAttribute() const
Return true if the attribute is an integer attribute.
Type * getStructRetType() const
AttrBuilder & addVScaleRangeAttr(unsigned MinValue, unsigned MaxValue)
This turns two ints into the form used internally in Attribute.
void mergeAttributesForInlining(Function &Caller, const Function &Callee)
Merge caller's and callee's attributes.
MaybeAlign getAlignment() const
bool hasParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the attribute exists for the given argument.
static Attribute getWithByValType(LLVMContext &Context, Type *Ty)
Type * getInAllocaType() const
Retrieve the inalloca type.
LLVM_NODISCARD AttributeList addDereferenceableParamAttr(LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given arg index.
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Retrieve the allocsize args, if the allocsize attribute exists.
bool hasAttributes(unsigned Index) const
Return true if attribute exists at the given index.
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const
Get the number of dereferenceable bytes (or zero if unknown) of an arg.
static AttributeSet getTombstoneKey()
LLVM Value Representation.
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return the attribute object that exists at the arg index.
bool operator<(Attribute A) const
Less-than operator. Useful for sorting the attributes list.
bool isEmpty() const
Return true if there are no attributes.
Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const
Return the attribute object that exists at the given index.
static Attribute fromRawPointer(void *RawPtr)
Get an attribute from a raw pointer created by getRawPointer.
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Returns the argument numbers for the allocsize attribute (or pair(0, 0) if not known).
static unsigned getHashValue(AttributeList AS)
static AttributeList getTombstoneKey()