llvm::StructType

Class to represent struct types. There are two different kinds of struct types: Literal structs and Identified structs.

Synopsis

Declared in <llvm/IR/DerivedTypes.h>

class StructType
    : public Type

Description

Literal struct types (e.g. { i32, i32 }) are uniqued structurally, and must always have a body when created. You can get one of these by using one of the StructType::get() forms.

Identified structs (e.g. %foo or %42) may optionally have a name and are not uniqued. The names for identified structs are managed at the LLVMContext level, so there can only be a single identified struct with a given name in a particular LLVMContext. Identified structs may also optionally be opaque (have no body specified). You get one of these by using one of the StructType::create() forms.

Independent of what kind of struct you have, the body of a struct type are laid out in memory consecutively with the elements directly one after the other (if the struct is packed) or (if not packed) with padding between the elements as defined by DataLayout (which is required to match what the code generator for a target expects).

Base Classes

NameDescription
TypeThe root of the LLVM type system hierarchy.

Type Aliases

NameDescription
element_iterator Iterator over this structure's element types.
subtype_iterator Iterator over this type's contained (subtype) types.
subtype_reverse_iterator Reverse iterator over contained (subtype) types.

Enums

NameDescription
TypeID Identifiers for all base types in the LLVM type system.

Member Functions

NameDescription
StructType [constructor] [deleted]Copy construction is deleted; identified structs are not copyable this way.
operator= [deleted]Copy assignment is deleted; identified structs are not assignable this way.
canLosslesslyBitCastTo Return true if this type could be converted with a lossless BitCast to Ty.
checkBody Return an error if the body for an opaque identified type would make it recursive.
containsHomogeneousScalableVectorTypes Return true if this struct contains homogeneous scalable vector types.
containsHomogeneousTypes Return true if this struct is non-empty and all element types are the same.
containsNonGlobalTargetExtType Return true if this type is or contains a target extension type that disallows being used as a global.
containsNonLocalTargetExtType Return true if this type is or contains a target extension type that disallows being used as a local.
dump Dump this type to stderr for debugging.
element_begin Return an iterator to the first element type.
element_end End iterator over the structure's element types.
elements Return an array view of this struct's element types.
getArrayElementType Return the element type of this array type.
getArrayNumElements Return the number of elements in this array type.
getByteBitWidth Return the bit width of this byte type (or of its scalar element).
getContainedType Return the type contained at index i in this derived type.
getContext Return the LLVMContext in which this type was uniqued.
getElementType Return the type of element N.
getExtendedType Given scalar/vector integer type, returns a type with elements twice as wide as in the original type. For vectors, preserves element count.
getFPMantissaWidth Return the width of the mantissa of this floating-point type.
getFltSemantics Return the floating-point semantics for this floating-point type.
getFunctionNumParams Return the number of fixed parameters of this function type.
getFunctionParamType Return the type of formal parameter i of this function type.
getIntegerBitWidth Return the bit width of this integer type.
getName Return the name for this struct type if it has an identity. This may return an empty string for an unnamed struct type. Do not call this on an literal type.
getNumContainedTypes Return the number of types in the derived type.
getNumElements Return the number of elements in this struct.
getPointerAddressSpace Get the address space of this pointer or pointer vector type.
getPrimitiveSizeInBits Return the basic size of this type if it is a primitive type.
getScalarSizeInBits If this is a vector type, return the getPrimitiveSizeInBits value for the element type. Otherwise return the getPrimitiveSizeInBits value for this type.
getScalarType If this is a vector type, return the element type, otherwise return 'this'.
getStructElementType Return the type of element N in this struct type.
getStructName Return the name of this identified struct type.
getStructNumElements Return the number of elements in this struct type.
getTargetExtName Return the name of this target extension type.
getTruncatedType Given scalar/vector integer type, returns a type with elements half as wide as in the original type. For vectors, preserves element count.
getTypeAtIndex getTypeAtIndex overloads
getTypeID Return the type id for the type. This will return one of the TypeID enum elements defined above.
getWithNewBitWidth Given an integer or vector type, change the lane bitwidth to NewBitwidth, whilst keeping the old number of lanes.
getWithNewType Given vector type, change the element type, whilst keeping the old number of elements. For non-vectors simply returns EltTy.
hasName Return true if this is a named struct that has a non-empty name.
indexValid indexValid overloads
is16bitFPTy Return true if this is a 16-bit float type.
isAggregateType Return true if the type is an aggregate type.
isArrayTy True if this is an instance of ArrayType.
isBFloatTy Return true if this is 'bfloat', a 16-bit bfloat type.
isByteOrByteVectorTy isByteOrByteVectorTy overloads
isByteTy isByteTy overloads
isDoubleTy Return true if this is 'double', a 64-bit IEEE fp type.
isEmptyTy Return true if this type is empty, that is, it has no elements or all of its elements are empty.
isFP128Ty Return true if this is 'fp128'.
isFPOrFPVectorTy Return true if this is a FP type or a vector of FP.
isFirstClassType Return true if the type is "first class", meaning it is a valid type for a Value.
isFloatTy Return true if this is 'float', a 32-bit IEEE fp type.
isFloatingPointTy Return true if this is one of the floating-point types.
isFunctionTy True if this is an instance of FunctionType.
isFunctionVarArg Return true if this function type is variadic.
isHalfTy Return true if this is 'half', a 16-bit IEEE fp type.
isIEEELikeFPTy Return true if this is a well-behaved IEEE-like type, which has a IEEE compatible layout, and does not have non-IEEE values, such as x86_fp80's unnormal values.
isIntOrIntVectorTy isIntOrIntVectorTy overloads
isIntOrPtrTy Return true if this is an integer type or a pointer type.
isIntegerTy isIntegerTy overloads
isLabelTy Return true if this is 'label'.
isLayoutIdentical Return true if this is layout identical to the specified struct.
isLiteral Return true if this type is uniqued by structural equivalence, false if it is a struct definition.
isMetadataTy Return true if this is 'metadata'.
isMultiUnitFPType Return true if this is a multi-unit floating-point type.
isOpaque Return true if this is a type with an identity that has no body specified yet. These prints as 'opaque' in .ll files.
isPPC_FP128Ty Return true if this is powerpc long double.
isPacked Return true if this struct is packed (no padding between elements).
isPointerTy True if this is an instance of PointerType.
isPtrOrPtrVectorTy Return true if this is a pointer type or a vector of pointer types.
isRISCVVectorTupleTy True if this is an instance of TargetExtType of RISC-V vector tuple.
isScalableTargetExtTy Return true if this is a target extension type with a scalable layout.
isScalableTy isScalableTy overloads
isSingleValueType Return true if the type is a valid type for a register in codegen. This includes all first-class types except struct and array types.
isSized Return true if this is a sized type.
isStructTy True if this is an instance of StructType.
isTargetExtTy Return true if this is a target extension type.
isTokenLikeTy Returns true if this is 'token' or a token-like target type.s
isTokenTy Return true if this is 'token'.
isVectorTy True if this is an instance of VectorType.
isVoidTy Return true if this is 'void'.
isX86_AMXTy Return true if this is X86 AMX.
isX86_FP80Ty Return true if this is x86 long double.
print Print the current type.
setBody Specify a body for an opaque identified type, which must not make the type recursive.
setBodyOrError Specify a body for an opaque identified type or return an error if it would make the type recursive.
setName Change the name of this type to the specified name, or to a name with a suffix if there is a collision. Do not call this on an literal type.
subtype_begin Iterator to the first contained (subtype) type.
subtype_end Iterator past the last contained (subtype) type.
subtype_rbegin Reverse iterator to the last contained (subtype) type.
subtype_rend Reverse iterator past the first contained (subtype) type.
subtypes Return an array view of this type's contained subtypes.

Static Member Functions

NameDescription
classof Methods for support type inquiry through isa, cast, and dyn_cast.
create create overloads
get get overloads
getBFloatTy Return the bfloat (16-bit) floating-point type.
getByte128Ty Return the 128-bit byte type.
getByte16Ty Return the 16-bit byte type for the given context.
getByte1Ty Return the 1-bit byte type.
getByte32Ty Return the 32-bit byte type for the given context.
getByte64Ty Return the 64-bit byte type.
getByte8Ty Return the 8-bit byte type.
getByteFromIntType Returns a byte (vector of byte) type with the same size of an integer of the given integer (vector of integer) type.
getByteNTy Return a byte type with bit width N.
getDoubleTy Return the IEEE double-precision (64-bit) floating-point type.
getFP128Ty Return the 128-bit IEEE floating-point type (fp128).
getFloatTy Return the IEEE single-precision (32-bit) floating-point type.
getFloatingPointTy Return the floating-point type matching semantics S.
getHalfTy Return the IEEE half-precision (16-bit) floating-point type.
getInt128Ty Return the 128-bit integer type.
getInt16Ty Return the 16-bit integer type.
getInt1Ty Return the 1-bit integer type.
getInt32Ty Return the 32-bit integer type.
getInt64Ty Return the 64-bit integer type.
getInt8Ty Return the 8-bit integer type.
getIntFromByteType Returns an integer (vector of integer) type with the same size of a byte of the given byte (vector of byte) type.
getIntNTy Return an integer type with bit width N.
getLabelTy Return the label type.
getMetadataTy Return the metadata type used for metadata operands in the IR.
getPPC_FP128Ty Return the PowerPC double-double (ppc_fp128) floating-point type.
getPrimitiveType Return a type based on an identifier.
getScalarTy Return the LLVM scalar type corresponding to a C++ scalar type ScalarTy.
getTokenTy Return the token type.
getTypeByName Return the type with the specified name, or null if there is none by that name.
getVoidTy Return the void type.
getWasm_ExternrefTy Return the WebAssembly externref target-extension type.
getWasm_FuncrefTy Return the WebAssembly funcref target-extension type.
getX86_AMXTy Return the X86 AMX type for the given context.
getX86_FP80Ty Return the x86 80-bit extended-precision floating-point type.
isValidElementType Return true if the specified type is valid as a element type.

Using Declarations

NameDescription
containsNonGlobalTargetExtType Inherit Type::containsNonGlobalTargetExtType overloads that do not take a visited set.
containsNonLocalTargetExtType Bring Type::containsNonLocalTargetExtType overloads into this scope.
isScalableTy Inherit Type::isScalableTy() overloads that do not take a visited set.

Protected Member Functions

NameDescription
getSubclassData Return the subclass-specific data packed into this type.
setSubclassData Store subclass-specific data into this type's SubclassData field.

Protected Data Members

NameDescription
ContainedTys Pointer to the array of Types contained by this Type.
NumContainedTys Keeps track of how many Type*'s there are in the ContainedTys list.

Non-Member Functions

NameDescription
ComputeLinearIndexCompute the linearized index of a member in a nested aggregate.
ComputeLinearIndexCompute the linearized index of a member in a nested aggregate/struct/array.
ConstantFoldGetElementPtrAttempt to constant fold a getelementptr instruction with the specified operands.
canVectorizeStructTyReturns true if StructTy is an unpacked literal struct where all elements are scalars that can be used as vector element types.
canVectorizeTyReturns true if Ty can be used as a vector element or vectorized struct.
checkGEPTypeReturn Ty after asserting it is a valid GEP index result type.
gep_type_beginReturn a begin iterator over GEP indices from type Op0 and operands A.
gep_type_endReturn an end iterator for GEP indices from operands A.
getContainedTypesReturns the types contained in Ty. For struct types, it returns the elements, all other types are returned directly.
getLLTForTypeConstruct a low-level type based on an LLVM type.
getPointersDiffReturns the distance between compatible pointers PtrA and PtrB.
getVectorizedTypeVFReturns the number of vector elements for a vectorized type.
isUnpackedStructLiteralReturns true if StructTy is an unpacked (non-packed) literal struct.
isVectorizedStructTyReturns true if StructTy is an unpacked literal struct where all elements are vectors of matching element count. This does not include empty structs.
isVectorizedTyReturns true if Ty is a vector type or a struct of vector types where all vector types share the same VF.
simplifyGEPInstGiven operands for a GetElementPtrInst, fold the result or return null.
toScalarizedStructTyConvert a struct of vector types to a struct of scalar types.
toScalarizedTyConvert a vectorized type to its scalarized (non-vector) form.
toVectorTyConvert a scalar type to a vector type.
toVectorTyConvert a scalar type to a fixed-length vector type.
toVectorizedStructTyConvert a struct of scalar types to a struct of vector types.
toVectorizedTyConvert a scalar or struct type to its vectorized form.
wrapC API conversion helpers for Type / LLVMTypeRef, including typed unwrap.
wrapWrap an array of Type pointers for the C API.
AttributeFuncs::isNoFPClassCompatibleTypeReturns true if this is a type legal for the 'nofpclass' attribute. This follows the same type rules as FPMathOperator.
AttributeFuncs::typeIncompatibleReturn the mask of attributes incompatible with type Ty.
PatternMatch::m_SpecificTypeMatch a value of a specific type, capturing it if we match.
PatternMatch::m_SpecificTypeMatch any value of a specific type.
PatternMatch::m_SpecificTypeMatch a const value of a specific type, capturing it if we match.
PatternMatch::m_SpecificTypeMatch a value of a specific type.
VNCoercion::analyzeLoadFromClobberingLoadThis function determines whether a value for the pointer LoadPtr can be extracted from the load at DepLI.
VNCoercion::analyzeLoadFromClobberingMemInstThis function determines whether a value for the pointer LoadPtr can be extracted from the memory intrinsic at DepMI.
VNCoercion::analyzeLoadFromClobberingStoreThis function determines whether a value for the pointer LoadPtr can be extracted from the store at DepSI.
fuzzerop::makeConstantsWithTypePopulate a small list of potentially interesting constants of a given type.
fuzzerop::makeConstantsWithTypeReturn a small list of potentially interesting constants of a given type.
hlsl::getDXILElementTypeConverts a scalar or vector LLVM type to its DXIL element type.
offloading::getEntryTyReturns the type of the offloading entry we use to store kernels and globals that will be registered with the offloading runtime.