4.3. Target information

Target information allows you to inspect and modify aspects of the code generation, such as which CPU is targetted or what optimization level is desired.

Minimal use of this module would be to create a TargetMachine for later use in code generation:

from llvmlite import binding
target = binding.Target.from_default_triple()
target_machine = target.create_target_machine()

4.3.1. Functions


Return the default target triple LLVM is configured to produce code for, as a string. This represents the host’s architecture and platform.


Get the name of the host’s CPU as a string. You can use the return value with Target.create_target_machine().


Create a TargetData representing the given data_layout (a string).


Create a TargetLibraryInfo for the given triple string.

4.3.2. Classes

class llvmlite.binding.TargetData

A class providing functionality around a given data layout. It specifies how the different types are to be represented in memory. Use create_target_data() to instantiate.


Add an optimization pass based on this data layout to the PassManager instance pm.


Get the ABI-mandated size of the LLVM type (as returned by ValueRef.type). An integer is returned.


Similar to get_abi_size(), but assumes type is a LLVM pointer type, and returns the ABI-mandated size of the type pointed to by. This is useful for global variables (whose type is really a pointer to the declared type).


Similar to get_pointee_abi_size(), but return the ABI-mandated alignment rather than the ABI size.

class llvmlite.binding.Target

A class representing a compilation target. The following factories are provided:

classmethod from_triple(triple)

Create a new Target instance for the given triple string denoting the target platform.

classmethod from_default_triple()

Create a new Target instance for the default platform LLVM is configured to produce code for. This is equivalent to calling Target.from_triple(get_default_triple())

The following methods and attributes are available:


A description of the target.


The name of the target.


The triple (a string) uniquely identifying the target, for example "x86_64-pc-linux-gnu".

create_target_machine(cpu='', features='', opt=2, reloc='default', codemodel='jitdefault')

Create a new TargetMachine instance for this target and with the given options. cpu is an optional CPU name to specialize for. features is a comma-separated list of target-specific features to enable or disable. opt is the optimization level, from 0 to 3. reloc is the relocation model. codemodel is the code model. The defaults for reloc and codemodel are appropriate for JIT compilation.


To list the available CPUs and features for a target, execute llc -mcpu=help on the command line.

class llvmlite.binding.TargetMachine

A class holding all the settings necessary for proper code generation (including target information and compiler options). Instantiate using Target.create_target_machine().


Register analysis passes for this target machine with the PassManager instance pm.


Represent the compiled module (a ModuleRef instance) as a code object, suitable for use with the platform’s linker. A bytestring is returned.


Return the compiled module‘s native assembler, as a string.

initialize_native_asmprinter() must have been called first.


The TargetData associated with this target machine.

class llvmlite.binding.TargetLibraryInfo

This class provides information about what library functions are available for the current target. Instantiate using create_target_library_info().


Add an optimization pass based on this library info to the PassManager instance pm.


Disable all “builtin” functions.


Get the library function name. NameError is raised if not found.


Mark the library function libfunc (as returned by get_libfunc()) unavailable.