LLVM 20.0.0git
Public Member Functions | List of all members
llvm::AttrBuilder Class Reference

#include "llvm/IR/Attributes.h"

Public Member Functions

 AttrBuilder (LLVMContext &Ctx)
 
 AttrBuilder (const AttrBuilder &)=delete
 
 AttrBuilder (AttrBuilder &&)=default
 
 AttrBuilder (LLVMContext &Ctx, const Attribute &A)
 
 AttrBuilder (LLVMContext &Ctx, AttributeSet AS)
 
void clear ()
 
AttrBuilderaddAttribute (Attribute::AttrKind Val)
 Add an attribute to the builder.
 
AttrBuilderaddAttribute (Attribute A)
 Add the Attribute object to the builder.
 
AttrBuilderaddAttribute (StringRef A, StringRef V=StringRef())
 Add the target-dependent attribute to the builder.
 
AttrBuilderremoveAttribute (Attribute::AttrKind Val)
 Remove an attribute from the builder.
 
AttrBuilderremoveAttribute (StringRef A)
 Remove the target-dependent attribute from the builder.
 
AttrBuilderremoveAttribute (Attribute A)
 Remove the target-dependent attribute from the builder.
 
AttrBuildermerge (const AttrBuilder &B)
 Add the attributes from the builder.
 
AttrBuilderremove (const AttributeMask &AM)
 Remove the attributes from the builder.
 
bool overlaps (const AttributeMask &AM) const
 Return true if the builder has any attribute that's in the specified builder.
 
bool contains (Attribute::AttrKind A) const
 Return true if the builder has the specified attribute.
 
bool contains (StringRef A) const
 Return true if the builder has the specified target-dependent attribute.
 
bool hasAttributes () const
 Return true if the builder has IR-level attributes.
 
Attribute getAttribute (Attribute::AttrKind Kind) const
 Return Attribute with the given Kind.
 
Attribute getAttribute (StringRef Kind) const
 Return Attribute with the given Kind.
 
std::optional< uint64_tgetRawIntAttr (Attribute::AttrKind Kind) const
 Return raw (possibly packed/encoded) value of integer attribute or std::nullopt if not set.
 
MaybeAlign getAlignment () const
 Retrieve the alignment attribute, if it exists.
 
MaybeAlign getStackAlignment () const
 Retrieve the stack alignment attribute, if it exists.
 
uint64_t getDereferenceableBytes () const
 Retrieve the number of dereferenceable bytes, if the dereferenceable attribute exists (zero is returned otherwise).
 
uint64_t getDereferenceableOrNullBytes () const
 Retrieve the number of dereferenceable_or_null bytes, if the dereferenceable_or_null attribute exists (zero is returned otherwise).
 
TypegetTypeAttr (Attribute::AttrKind Kind) const
 Retrieve type for the given type attribute.
 
TypegetByValType () const
 Retrieve the byval type.
 
TypegetStructRetType () const
 Retrieve the sret type.
 
TypegetByRefType () const
 Retrieve the byref type.
 
TypegetPreallocatedType () const
 Retrieve the preallocated type.
 
TypegetInAllocaType () const
 Retrieve the inalloca type.
 
std::optional< std::pair< unsigned, std::optional< unsigned > > > getAllocSizeArgs () const
 Retrieve the allocsize args, or std::nullopt if the attribute does not exist.
 
AttrBuilderaddRawIntAttr (Attribute::AttrKind Kind, uint64_t Value)
 Add integer attribute with raw value (packed/encoded if necessary).
 
AttrBuilderaddAlignmentAttr (MaybeAlign Align)
 This turns an alignment into the form used internally in Attribute.
 
AttrBuilderaddAlignmentAttr (unsigned Align)
 This turns an int alignment (which must be a power of 2) into the form used internally in Attribute.
 
AttrBuilderaddStackAlignmentAttr (MaybeAlign Align)
 This turns a stack alignment into the form used internally in Attribute.
 
AttrBuilderaddStackAlignmentAttr (unsigned Align)
 This turns an int stack alignment (which must be a power of 2) into the form used internally in Attribute.
 
AttrBuilderaddDereferenceableAttr (uint64_t Bytes)
 This turns the number of dereferenceable bytes into the form used internally in Attribute.
 
AttrBuilderaddDereferenceableOrNullAttr (uint64_t Bytes)
 This turns the number of dereferenceable_or_null bytes into the form used internally in Attribute.
 
AttrBuilderaddAllocSizeAttr (unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
 This turns one (or two) ints into the form used internally in Attribute.
 
AttrBuilderaddVScaleRangeAttr (unsigned MinValue, std::optional< unsigned > MaxValue)
 This turns two ints into the form used internally in Attribute.
 
AttrBuilderaddTypeAttr (Attribute::AttrKind Kind, Type *Ty)
 Add a type attribute with the given type.
 
AttrBuilderaddByValAttr (Type *Ty)
 This turns a byval type into the form used internally in Attribute.
 
AttrBuilderaddStructRetAttr (Type *Ty)
 This turns a sret type into the form used internally in Attribute.
 
AttrBuilderaddByRefAttr (Type *Ty)
 This turns a byref type into the form used internally in Attribute.
 
AttrBuilderaddPreallocatedAttr (Type *Ty)
 This turns a preallocated type into the form used internally in Attribute.
 
AttrBuilderaddInAllocaAttr (Type *Ty)
 This turns an inalloca type into the form used internally in Attribute.
 
AttrBuilderaddAllocSizeAttrFromRawRepr (uint64_t RawAllocSizeRepr)
 Add an allocsize attribute, using the representation returned by Attribute.getIntValue().
 
AttrBuilderaddVScaleRangeAttrFromRawRepr (uint64_t RawVScaleRangeRepr)
 Add a vscale_range attribute, using the representation returned by Attribute.getIntValue().
 
AttrBuilderaddUWTableAttr (UWTableKind Kind)
 This turns the unwind table kind into the form used internally in Attribute.
 
AttrBuilderaddAllocKindAttr (AllocFnKind Kind)
 
AttrBuilderaddMemoryAttr (MemoryEffects ME)
 Add memory effect attribute.
 
AttrBuilderaddNoFPClassAttr (FPClassTest NoFPClassMask)
 
AttrBuilderaddConstantRangeAttr (Attribute::AttrKind Kind, const ConstantRange &CR)
 Add a ConstantRange attribute with the given range.
 
AttrBuilderaddRangeAttr (const ConstantRange &CR)
 Add range attribute.
 
AttrBuilderaddConstantRangeListAttr (Attribute::AttrKind Kind, ArrayRef< ConstantRange > Val)
 Add a ConstantRangeList attribute with the given ranges.
 
AttrBuilderaddInitializesAttr (const ConstantRangeList &CRL)
 Add initializes attribute.
 
ArrayRef< Attributeattrs () const
 
bool operator== (const AttrBuilder &B) const
 
bool operator!= (const AttrBuilder &B) const
 

Detailed Description

Definition at line 1033 of file Attributes.h.

Constructor & Destructor Documentation

◆ AttrBuilder() [1/5]

llvm::AttrBuilder::AttrBuilder ( LLVMContext Ctx)
inline

Definition at line 1038 of file Attributes.h.

◆ AttrBuilder() [2/5]

llvm::AttrBuilder::AttrBuilder ( const AttrBuilder )
delete

◆ AttrBuilder() [3/5]

llvm::AttrBuilder::AttrBuilder ( AttrBuilder &&  )
default

◆ AttrBuilder() [4/5]

llvm::AttrBuilder::AttrBuilder ( LLVMContext Ctx,
const Attribute A 
)
inline

Definition at line 1042 of file Attributes.h.

References A, and addAttribute().

◆ AttrBuilder() [5/5]

AttrBuilder::AttrBuilder ( LLVMContext Ctx,
AttributeSet  AS 
)

Definition at line 1816 of file Attributes.cpp.

References llvm::append_range(), assert(), and llvm::is_sorted().

Member Function Documentation

◆ addAlignmentAttr() [1/2]

AttrBuilder & AttrBuilder::addAlignmentAttr ( MaybeAlign  Align)

This turns an alignment into the form used internally in Attribute.

This call has no effect if Align is not set.

Definition at line 1916 of file Attributes.cpp.

References addRawIntAttr(), assert(), llvm::Value::MaximumAlignment, and llvm::Align::value().

Referenced by addAlignmentAttr(), addFramePointerAttrs(), and IdentifyValidPoisonGeneratingAttributes().

◆ addAlignmentAttr() [2/2]

AttrBuilder & llvm::AttrBuilder::addAlignmentAttr ( unsigned  Align)
inline

This turns an int alignment (which must be a power of 2) into the form used internally in Attribute.

This call has no effect if Align is 0. Deprecated, use the version using a MaybeAlign.

Definition at line 1164 of file Attributes.h.

References addAlignmentAttr().

◆ addAllocKindAttr()

AttrBuilder & AttrBuilder::addAllocKindAttr ( AllocFnKind  Kind)

Definition at line 1988 of file Attributes.cpp.

References addRawIntAttr().

◆ addAllocSizeAttr()

AttrBuilder & AttrBuilder::addAllocSizeAttr ( unsigned  ElemSizeArg,
const std::optional< unsigned > &  NumElemsArg 
)

This turns one (or two) ints into the form used internally in Attribute.

Definition at line 1947 of file Attributes.cpp.

References addAllocSizeAttrFromRawRepr(), and packAllocSizeArgs().

◆ addAllocSizeAttrFromRawRepr()

AttrBuilder & AttrBuilder::addAllocSizeAttrFromRawRepr ( uint64_t  RawAllocSizeRepr)

Add an allocsize attribute, using the representation returned by Attribute.getIntValue().

Definition at line 1952 of file Attributes.cpp.

References addRawIntAttr(), and assert().

Referenced by addAllocSizeAttr().

◆ addAttribute() [1/3]

AttrBuilder & AttrBuilder::addAttribute ( Attribute  A)

◆ addAttribute() [2/3]

AttrBuilder & AttrBuilder::addAttribute ( Attribute::AttrKind  Val)

◆ addAttribute() [3/3]

AttrBuilder & AttrBuilder::addAttribute ( StringRef  A,
StringRef  V = StringRef() 
)

Add the target-dependent attribute to the builder.

Definition at line 1874 of file Attributes.cpp.

References A, addAttributeImpl(), and llvm::Attribute::get().

◆ addByRefAttr()

AttrBuilder & AttrBuilder::addByRefAttr ( Type Ty)

This turns a byref type into the form used internally in Attribute.

Definition at line 2010 of file Attributes.cpp.

References addTypeAttr().

◆ addByValAttr()

AttrBuilder & AttrBuilder::addByValAttr ( Type Ty)

This turns a byval type into the form used internally in Attribute.

Definition at line 2002 of file Attributes.cpp.

References addTypeAttr().

Referenced by llvm::promoteCall().

◆ addConstantRangeAttr()

AttrBuilder & AttrBuilder::addConstantRangeAttr ( Attribute::AttrKind  Kind,
const ConstantRange CR 
)

Add a ConstantRange attribute with the given range.

Definition at line 2022 of file Attributes.cpp.

References addAttribute(), llvm::Attribute::get(), and llvm::ConstantRange::isFullSet().

Referenced by addRangeAttr().

◆ addConstantRangeListAttr()

AttrBuilder & AttrBuilder::addConstantRangeListAttr ( Attribute::AttrKind  Kind,
ArrayRef< ConstantRange Val 
)

Add a ConstantRangeList attribute with the given ranges.

Definition at line 2035 of file Attributes.cpp.

References addAttribute(), and llvm::Attribute::get().

Referenced by addInitializesAttr().

◆ addDereferenceableAttr()

AttrBuilder & AttrBuilder::addDereferenceableAttr ( uint64_t  Bytes)

This turns the number of dereferenceable bytes into the form used internally in Attribute.

Definition at line 1933 of file Attributes.cpp.

References addRawIntAttr().

Referenced by addFramePointerAttrs(), and IdentifyValidUBGeneratingAttributes().

◆ addDereferenceableOrNullAttr()

AttrBuilder & AttrBuilder::addDereferenceableOrNullAttr ( uint64_t  Bytes)

This turns the number of dereferenceable_or_null bytes into the form used internally in Attribute.

Definition at line 1939 of file Attributes.cpp.

References addRawIntAttr().

Referenced by IdentifyValidUBGeneratingAttributes().

◆ addInAllocaAttr()

AttrBuilder & AttrBuilder::addInAllocaAttr ( Type Ty)

This turns an inalloca type into the form used internally in Attribute.

Definition at line 2018 of file Attributes.cpp.

References addTypeAttr().

Referenced by llvm::promoteCall().

◆ addInitializesAttr()

AttrBuilder & AttrBuilder::addInitializesAttr ( const ConstantRangeList CRL)

Add initializes attribute.

Definition at line 2040 of file Attributes.cpp.

References addConstantRangeListAttr(), and llvm::ConstantRangeList::rangesRef().

◆ addMemoryAttr()

AttrBuilder & AttrBuilder::addMemoryAttr ( MemoryEffects  ME)

Add memory effect attribute.

Definition at line 1977 of file Attributes.cpp.

References addRawIntAttr(), and llvm::MemoryEffectsBase< LocationEnum >::toIntValue().

◆ addNoFPClassAttr()

AttrBuilder & AttrBuilder::addNoFPClassAttr ( FPClassTest  NoFPClassMask)

Definition at line 1981 of file Attributes.cpp.

References addRawIntAttr(), and llvm::fcNone.

◆ addPreallocatedAttr()

AttrBuilder & AttrBuilder::addPreallocatedAttr ( Type Ty)

This turns a preallocated type into the form used internally in Attribute.

Definition at line 2014 of file Attributes.cpp.

References addTypeAttr().

◆ addRangeAttr()

AttrBuilder & AttrBuilder::addRangeAttr ( const ConstantRange CR)

Add range attribute.

Definition at line 2030 of file Attributes.cpp.

References addConstantRangeAttr().

Referenced by AddReturnAttributes(), and IdentifyValidPoisonGeneratingAttributes().

◆ addRawIntAttr()

AttrBuilder & AttrBuilder::addRawIntAttr ( Attribute::AttrKind  Kind,
uint64_t  Value 
)

◆ addStackAlignmentAttr() [1/2]

AttrBuilder & AttrBuilder::addStackAlignmentAttr ( MaybeAlign  Align)

This turns a stack alignment into the form used internally in Attribute.

This call has no effect if Align is not set.

Definition at line 1924 of file Attributes.cpp.

References addRawIntAttr(), assert(), and llvm::Align::value().

Referenced by addStackAlignmentAttr().

◆ addStackAlignmentAttr() [2/2]

AttrBuilder & llvm::AttrBuilder::addStackAlignmentAttr ( unsigned  Align)
inline

This turns an int stack alignment (which must be a power of 2) into the form used internally in Attribute.

This call has no effect if Align is 0. Deprecated, use the version using a MaybeAlign.

Definition at line 1176 of file Attributes.h.

References addStackAlignmentAttr().

◆ addStructRetAttr()

AttrBuilder & AttrBuilder::addStructRetAttr ( Type Ty)

This turns a sret type into the form used internally in Attribute.

Definition at line 2006 of file Attributes.cpp.

References addTypeAttr().

◆ addTypeAttr()

AttrBuilder & AttrBuilder::addTypeAttr ( Attribute::AttrKind  Kind,
Type Ty 
)

Add a type attribute with the given type.

Definition at line 1998 of file Attributes.cpp.

References addAttribute(), and llvm::Attribute::get().

Referenced by addByRefAttr(), addByValAttr(), addInAllocaAttr(), addPreallocatedAttr(), and addStructRetAttr().

◆ addUWTableAttr()

AttrBuilder & AttrBuilder::addUWTableAttr ( UWTableKind  Kind)

This turns the unwind table kind into the form used internally in Attribute.

Definition at line 1971 of file Attributes.cpp.

References addRawIntAttr(), and llvm::None.

◆ addVScaleRangeAttr()

AttrBuilder & AttrBuilder::addVScaleRangeAttr ( unsigned  MinValue,
std::optional< unsigned MaxValue 
)

This turns two ints into the form used internally in Attribute.

Definition at line 1958 of file Attributes.cpp.

References addVScaleRangeAttrFromRawRepr(), and packVScaleRangeArgs().

◆ addVScaleRangeAttrFromRawRepr()

AttrBuilder & AttrBuilder::addVScaleRangeAttrFromRawRepr ( uint64_t  RawVScaleRangeRepr)

Add a vscale_range attribute, using the representation returned by Attribute.getIntValue().

Definition at line 1963 of file Attributes.cpp.

References addRawIntAttr().

Referenced by addVScaleRangeAttr().

◆ attrs()

ArrayRef< Attribute > llvm::AttrBuilder::attrs ( ) const
inline

Definition at line 1249 of file Attributes.h.

◆ clear()

void AttrBuilder::clear ( )

Definition at line 1821 of file Attributes.cpp.

◆ contains() [1/2]

bool AttrBuilder::contains ( Attribute::AttrKind  A) const

Return true if the builder has the specified attribute.

Definition at line 2076 of file Attributes.cpp.

References A, getAttribute(), and llvm::Attribute::isValid().

Referenced by llvm::attributesPermitTailCall(), and llvm::TargetLowering::isInTailCallPosition().

◆ contains() [2/2]

bool AttrBuilder::contains ( StringRef  A) const

Return true if the builder has the specified target-dependent attribute.

Definition at line 2080 of file Attributes.cpp.

References A, getAttribute(), and llvm::Attribute::isValid().

◆ getAlignment()

MaybeAlign llvm::AttrBuilder::getAlignment ( ) const
inline

Retrieve the alignment attribute, if it exists.

Definition at line 1107 of file Attributes.h.

References getRawIntAttr().

Referenced by AddReturnAttributes().

◆ getAllocSizeArgs()

std::optional< std::pair< unsigned, std::optional< unsigned > > > AttrBuilder::getAllocSizeArgs ( ) const

Retrieve the allocsize args, or std::nullopt if the attribute does not exist.

Definition at line 1909 of file Attributes.cpp.

References A, and getAttribute().

◆ getAttribute() [1/2]

Attribute AttrBuilder::getAttribute ( Attribute::AttrKind  Kind) const

Return Attribute with the given Kind.

The returned attribute will be invalid if the Kind is not present in the builder.

Definition at line 2061 of file Attributes.cpp.

References A, assert(), llvm::Attribute::EndAttrKinds, and llvm::lower_bound().

Referenced by AddReturnAttributes(), contains(), getAllocSizeArgs(), getRawIntAttr(), and getTypeAttr().

◆ getAttribute() [2/2]

Attribute AttrBuilder::getAttribute ( StringRef  Kind) const

Return Attribute with the given Kind.

The returned attribute will be invalid if the Kind is not present in the builder.

Definition at line 2069 of file Attributes.cpp.

References A, and llvm::lower_bound().

◆ getByRefType()

Type * llvm::AttrBuilder::getByRefType ( ) const
inline

Retrieve the byref type.

Definition at line 1138 of file Attributes.h.

References getTypeAttr().

◆ getByValType()

Type * llvm::AttrBuilder::getByValType ( ) const
inline

Retrieve the byval type.

Definition at line 1132 of file Attributes.h.

References getTypeAttr().

Referenced by llvm::promoteCall().

◆ getDereferenceableBytes()

uint64_t llvm::AttrBuilder::getDereferenceableBytes ( ) const
inline

Retrieve the number of dereferenceable bytes, if the dereferenceable attribute exists (zero is returned otherwise).

Definition at line 1118 of file Attributes.h.

References getRawIntAttr().

Referenced by AddReturnAttributes().

◆ getDereferenceableOrNullBytes()

uint64_t llvm::AttrBuilder::getDereferenceableOrNullBytes ( ) const
inline

Retrieve the number of dereferenceable_or_null bytes, if the dereferenceable_or_null attribute exists (zero is returned otherwise).

Definition at line 1124 of file Attributes.h.

References getRawIntAttr().

Referenced by AddReturnAttributes().

◆ getInAllocaType()

Type * llvm::AttrBuilder::getInAllocaType ( ) const
inline

Retrieve the inalloca type.

Definition at line 1146 of file Attributes.h.

References getTypeAttr().

Referenced by llvm::promoteCall().

◆ getPreallocatedType()

Type * llvm::AttrBuilder::getPreallocatedType ( ) const
inline

Retrieve the preallocated type.

Definition at line 1141 of file Attributes.h.

References getTypeAttr().

◆ getRawIntAttr()

std::optional< uint64_t > AttrBuilder::getRawIntAttr ( Attribute::AttrKind  Kind) const

Return raw (possibly packed/encoded) value of integer attribute or std::nullopt if not set.

Definition at line 1895 of file Attributes.cpp.

References A, assert(), getAttribute(), and llvm::Attribute::isIntAttrKind().

Referenced by getAlignment(), getDereferenceableBytes(), getDereferenceableOrNullBytes(), and getStackAlignment().

◆ getStackAlignment()

MaybeAlign llvm::AttrBuilder::getStackAlignment ( ) const
inline

Retrieve the stack alignment attribute, if it exists.

Definition at line 1112 of file Attributes.h.

References getRawIntAttr().

◆ getStructRetType()

Type * llvm::AttrBuilder::getStructRetType ( ) const
inline

Retrieve the sret type.

Definition at line 1135 of file Attributes.h.

References getTypeAttr().

◆ getTypeAttr()

Type * AttrBuilder::getTypeAttr ( Attribute::AttrKind  Kind) const

Retrieve type for the given type attribute.

Definition at line 1992 of file Attributes.cpp.

References A, assert(), getAttribute(), and llvm::Attribute::isTypeAttrKind().

Referenced by getByRefType(), getByValType(), getInAllocaType(), getPreallocatedType(), and getStructRetType().

◆ hasAttributes()

bool llvm::AttrBuilder::hasAttributes ( ) const
inline

Return true if the builder has IR-level attributes.

Definition at line 1092 of file Attributes.h.

Referenced by AddReturnAttributes(), llvm::TargetLowering::isInTailCallPosition(), and isLibCallInTailPosition().

◆ merge()

AttrBuilder & AttrBuilder::merge ( const AttrBuilder B)

Add the attributes from the builder.

Attributes in the passed builder overwrite attributes in this builder if they have the same key.

Definition at line 2044 of file Attributes.cpp.

References addAttribute(), B, and I.

Referenced by llvm::AttributeList::get().

◆ operator!=()

bool llvm::AttrBuilder::operator!= ( const AttrBuilder B) const
inline

Definition at line 1252 of file Attributes.h.

References B.

◆ operator==()

bool AttrBuilder::operator== ( const AttrBuilder B) const

Definition at line 2084 of file Attributes.cpp.

References B.

◆ overlaps()

bool AttrBuilder::overlaps ( const AttributeMask AM) const

Return true if the builder has any attribute that's in the specified builder.

Definition at line 2057 of file Attributes.cpp.

References A, llvm::any_of(), and llvm::AttributeMask::contains().

◆ remove()

AttrBuilder & AttrBuilder::remove ( const AttributeMask AM)

Remove the attributes from the builder.

Definition at line 2052 of file Attributes.cpp.

References A, llvm::AttributeMask::contains(), and llvm::erase_if().

Referenced by llvm::promoteCall().

◆ removeAttribute() [1/3]

AttrBuilder & llvm::AttrBuilder::removeAttribute ( Attribute  A)
inline

Remove the target-dependent attribute from the builder.

Definition at line 1066 of file Attributes.h.

References A, and removeAttribute().

◆ removeAttribute() [2/3]

AttrBuilder & AttrBuilder::removeAttribute ( Attribute::AttrKind  Val)

◆ removeAttribute() [3/3]

AttrBuilder & AttrBuilder::removeAttribute ( StringRef  A)

Remove the target-dependent attribute from the builder.

Definition at line 1887 of file Attributes.cpp.

References A, and llvm::lower_bound().


The documentation for this class was generated from the following files: