Types¶
All values used in an LLVM module are
explicitly typed. All types derive from a common base class
Type. You can instantiate most of them directly. Once
instantiated, a type should be considered immutable.
-
class
llvmlite.ir.Type¶ The base class for all types. Never instantiate it directly. Types have the following methods in common:
-
as_pointer(addrspace=0)¶ Return a
PointerTypepointing to this type. The optional addrspace integer allows you to choose a non-default address space—the meaning is platform dependent.
-
-
get_abi_size(target_data)¶ Get the ABI size of this type, in bytes, according to the target_data—an
llvmlite.binding.TargetDatainstance.
-
-
get_abi_alignment(target_data)¶ Get the ABI alignment of this type, in bytes, according to the target_data—an
llvmlite.binding.TargetDatainstance.NOTE:
get_abi_size()andget_abi_alignment()call into the LLVM C++ API to get the requested information.
-
Atomic types¶
-
class
llvmlite.ir.PointerType(pointee, addrspace=0)¶ The type of pointers to another type.
Pointer types expose the following attributes:
-
class
llvmlite.ir.IntType(bits)¶ The type of integers. The Python integer bits specifies the bitwidth of the integers having this type.
-
width¶ The width in bits.
-
-
class
llvmlite.ir.HalfType¶ The type of half-precision, floating-point, real numbers.
NOTE: On Python 3.5 and earlier, constants won’t be rounded to valid fp16 numbers, and so may generate invalid IR. In this case, use rounding code like
float(np.float16(1.12312321e-2))before callingIRBuildermethods.
-
class
llvmlite.ir.FloatType¶ The type of single-precision, floating-point, real numbers.
-
class
llvmlite.ir.DoubleType¶ The type of double-precision, floating-point, real numbers.
-
class
llvmlite.ir.VoidType¶ The class for void types. Used only as the return type of a function without a return value.
Aggregate types¶
-
class
llvmlite.ir.Aggregate¶ The base class for aggregate types. Never instantiate it directly. Aggregate types have the elements attribute in common.
-
elements¶ A tuple-like immutable sequence of element types for this aggregate type.
-
-
class
llvmlite.ir.ArrayType(element, count)¶ The class for array types.
- element is the type of every element.
- count is a Python integer representing the number of elements.
-
class
llvmlite.ir.VectorType(element, count)¶ The class for vector types.
- element is the type of every element.
- count is a Python integer representing the number of elements.
-
class
llvmlite.ir.LiteralStructType(elements[, packed=False])¶ The class for literal struct types.
- elements is a sequence of element types for each member of the structure.
- packed controls whether to use packed layout.
-
class
llvmlite.ir.IdentifiedStructType¶ The class for identified struct types. Identified structs are compared by name. It can be used to make opaque types.
Users should not create new instance directly. Use the
Context.get_identified_typemethod instead.An identified struct is created without a body (thus opaque). To define the struct body, use the
.set_bodymethod.-
set_body(*elems)¶ Define the structure body with a sequence of element types.
-
Other types¶
-
class
llvmlite.ir.FunctionType(return_type, args, var_arg=False)¶ The type of a function.
return_type is the return type of the function.
args is a sequence describing the types of argument to the function.
If var_arg is
True, the function takes a variable number of additional arguments of unknown types after the explicit args.EXAMPLE:
int32 = ir.IntType(32) fnty = ir.FunctionType(int32, (ir.DoubleType(), ir.PointerType(int32)))
An equivalent C declaration would be:
typedef int32_t (*fnty)(double, int32_t *);