codegen Package

codegen Package

codeutils Module

numba.codegen.codeutils.if_badval(translator, llvm_result, badval, callback, cmp=ICMP_EQ(32), name='cleanup')
numba.codegen.codeutils.llvm_alloca(lfunc, builder, ltype, name='', change_bb=True)

Use alloca only at the entry bock of the function

coerce Module

class numba.codegen.coerce.ObjectCoercer(translator)

Bases: object

Object that knows how to convert to/from objects using Py_BuildValue and PyArg_ParseTuple.

build_dict(key_types, value_types, llvm_keys, llvm_values)

Build a dict from a bunch of LLVM values

build_list(types, llvm_values)

Build a tuple from a bunch of LLVM values

build_tuple(types, llvm_values)

Build a tuple from a bunch of LLVM values

buildvalue(types, *largs, **kwds)
check_err(llvm_result, callback=None, cmp=ICMP_EQ(32), pos_node=None)

Check for errors. If the result is NULL, and error should have been set Jumps to translator.error_label if an exception occurred.

check_err_int(llvm_result, badval)
convert_single(type, llvm_result, name='')

Generate code to convert an LLVM value to a Python object

convert_single_struct(llvm_result, type)
lstr(types, fmt=None)

Get an llvm format string for the given types

npy_intp_to_py_ssize_t(llvm_result, type)
parse_tuple(lstr, llvm_tuple, types, name='')

Unpack a Python tuple into typed llvm variables

py_ssize_t_to_npy_intp(llvm_result, type)
to_native(type, llvm_tuple, name='')

Generate code to convert a Python object to an LLVM value

type_to_buildvalue_str = {float64: 'd', ulong: 'k', object: 'O', string: 's', longlong: 'L', ushort: 'H', uchar: 'B', char *: 's', float32: 'f', short: 'h', ulonglong: 'K', size_t: 'n', bool: 'b', npy_intp: 'n', int: 'i', uint: 'I', char: 'c', complex128: 'D', long: 'l', Py_ssize_t: 'n'}

complexsupport Module

class numba.codegen.complexsupport.ComplexSupportMixin

Bases: object

Support for complex numbers

datetimesupport Module

class numba.codegen.datetimesupport.DateTimeSupportMixin

Bases: object

Support for datetimes

debug Module

globalconstants Module

class numba.codegen.globalconstants.LLVMConstantsManager

Bases: object

Manage global constants. The result should be linked into the consumer LLVM module.

get_string_constant(const_str)

llvmcontext Module

class numba.codegen.llvmcontext.LLVMContextManager

Bases: object

TODO: Make this class not a singleton. A possible design is to let each Numba Context owns a LLVMContextManager.

execution_engine
get_pointer_to_function(lfunc)
module
pass_manager
target_machine
verify(lfunc)
numba.codegen.llvmcontext.handle(llvm_value)

Link a source module into a destination module while preserving the execution engine’s global mapping of pointers.

llvmwrapper Module

Module that creates wrapper around llvm functions. The wrapper is callable from Python.

numba.codegen.llvmwrapper.build_wrapper_function(env)

Build a wrapper function for the currently translated function.

Return the interpreter-level wrapper function, the LLVM wrapper function, and the method definition record.

numba.codegen.llvmwrapper.build_wrapper_function_ast(env, wrapper_lfunc, llvm_module)

Build AST for LLVM function wrapper.

lfunc: LLVM function to wrap llvm_module: module the wrapper is being defined in

The resulting AST has a NativeCallNode to the wrapped function. The arguments are LLVMValueRefNode nodes which still need their llvm_value set to the object from the tuple. This happens in visit_FunctionWrapperNode during codegen.

numba.codegen.llvmwrapper.build_wrapper_module(env)

Build a wrapper function for the currently translated function, and return a tuple containing the separate LLVM module, and the LLVM wrapper function.

numba.codegen.llvmwrapper.build_wrapper_translation(env, llvm_module=None)

Generate a wrapper function in the given llvm module.

numba.codegen.llvmwrapper.fake_pyfunc(self, args)

PyObject ()(PyObject *self, PyObject *args)

numba.codegen.llvmwrapper.get_closure_scope(func_signature, func_obj)

Retrieve the closure from the NumbaFunction from the func_closure attribute.

func_signature:
signature of closure function
func_obj:
LLVM Value referencing the closure function as a Python object
numba.codegen.llvmwrapper.get_ctypes_func(self, llvm=True)
numba.codegen.llvmwrapper.numbafunction_new(py_func, func_name, func_doc, module_name, func_pointer, wrapped_lfunc_pointer, wrapped_signature)

Create a NumbaFunction (numbafunction.c)

refcounting Module

class numba.codegen.refcounting.RefcountingMixin

Bases: object

decref(value)

Py_DECREF a value

incref(value)

Py_INCREF a value

refcount(func, value)

Refcount a value with a refcounting function

xdecref(value)

Py_XDECREF a value

xdecref_temp(temp)

Py_XDECREF a temporary

xdecref_temp_cleanup(temp)

Cleanup a temp at the end of the function:

  • Save current basic block
  • Generate code at cleanup path
  • Restore basic block
xincref(value)

Py_XINCREF a value

xincref_temp(temp)

Py_XINCREF a temporary

translate Module

class numba.codegen.translate.LLVMCodeGenerator(context, func, ast, func_signature, symtab, optimize=True, nopython=False, llvm_module=None, **kwds)

Bases: numba.visitors.NumbaVisitor, numba.codegen.complexsupport.ComplexSupportMixin, numba.codegen.refcounting.RefcountingMixin, numba.visitors.NoPythonContextMixin, numba.codegen.datetimesupport.DateTimeSupportMixin

Translate a Python AST to LLVM. Each visit_* method should directly return an LLVM value.

alloca(type, name='', change_bb=True)
annotations
append_basic_block(name='unamed')
bool_ltype = <llvm.core.IntegerType object at 0x10576fbd0>
c_array_to_pointer(name, stackspace, var)

Decay a C array to a pointer to allow pointer access

check_unbound_local(node, var)
cur_bb
current_node
declare(cbuilder_func)
generate_assign_stack(lvalue, ltarget, tbaa_node=None, tbaa_type=None, decref=False, incref=False)

Generate assignment operation and automatically cast value to match the target type.

generate_constant_int(val, ty=int)
handle_phis()

Update all our phi nodes after translation is done and all Variables have their llvm values set.

incref_arg(argname, argtype, larg, variable)
is_block_terminated(basic_block=None)

Check if the current basicblock is properly terminated. That means the basicblock is ended with a branch or return

is_obj(type)
lfunc_pointer
llvm_alloca(ltype, name='', change_bb=True)
load_tbaa(ptr, tbaa_type, name='')

Load a pointer and annotate with Type Based Alias Analysis metadata.

multiarray_api = <numba.multiarray_api.MultiarrayAPI object at 0x105723f50>
ndarray(llvm_array_ptr, type)
opname(op)
preload_attributes(var, value)

Pre-load ndarray attributes data/shape/strides.

puts(msg)
puts_llvm(llvm_string)
pyarray_accessor(llvm_array_ptr, dtype)
renameable(variable)
reset_pos(pos)

Reset position for annotation

setblock(cfg_basic_block)
setup_func()
setup_loop(continue_block, bb_cond, bb_exit)
setup_return()
store_tbaa(value, ptr, tbaa_type)

Load a pointer and annotate with Type Based Alias Analysis metadata.

struct_field(node, value)
teardown_loop()
term_block(end_block)
terminate_block(block, end_block)
terminate_cleanup_blocks()
to_llvm(type)
translate()
update_pos(node)

Update position for annotation

using_numpy_array
visit(node)
visit_ArrayAttributeNode(node)
visit_Assign(node)
visit_Attribute(node)
visit_BadValue(node)
visit_BinOp(node)
visit_BoolOp(node)
visit_Break(node)
visit_BroadcastNode(node)
visit_Call(node)
visit_CloneNode(node)
visit_CloneableNode(node)
visit_ClosureCallNode(node)
visit_CoerceToNative(node)
visit_CoerceToObject(node)
visit_CoercionNode(node, val=None)
visit_Compare(node)
visit_ComplexAttributeNode(node)
visit_ComplexConjugateNode(node)
visit_ComplexNode(node)
visit_ConstNode(node)
visit_Continue(node)
visit_ControlBlock(node, visit_body=True)

Return a new basic block and handle phis and promotions. Promotions are needed at merge (phi) points to have a consistent type.

visit_DataPointerNode(node)
visit_DateTimeAttributeNode(node)
visit_DateTimeNode(node)
visit_DecrefNode(node)
visit_DereferenceNode(node)
visit_Dict(node)
visit_Expr(node)
visit_ExpressionNode(node)
visit_ExtSlice(node)
visit_For(node)
visit_FunctionWrapperNode(node)
visit_If(node, is_while=False)
visit_IfExp(node)
visit_IncrefNode(node)
visit_IntrinsicNode(node)
visit_LLMacroNode(node)
visit_LLVMExternalFunctionNode(node)
visit_LLVMIntrinsicNode(node)
visit_LLVMValueRefNode(node)
visit_List(node)
visit_LowLevelBasicBlockNode(node)
visit_MathCallNode(node)
visit_MultiArrayAPINode(node)
visit_Name(node)
visit_NativeCallNode(node, largs=None)
visit_NativeFunctionCallNode(node)
visit_NativeSliceNode(node)

Slice an array. Allocate fake PyArray and allocate shape/strides

visit_NoneNode(node)
visit_NumpyDateTimeNode(node)
visit_NumpyTimeDeltaNode(node)
visit_ObjectCallNode(node)
visit_ObjectInjectNode(node)
visit_ObjectTempNode(node)
visit_ObjectTempRefNode(node)
visit_Pass(node)
visit_PointerCallNode(node)
visit_PointerFromObject(node)
visit_PromotionNode(node)
visit_PropagateNode(node)
visit_Return(node)
visit_ShapeAttributeNode(node)
visit_SliceDimNode(node)

Handle indexing and newaxes in a slice operation

visit_SliceSliceNode(node)

Handle slicing

visit_StructAttribute(node)
visit_StructVariable(node)
visit_Subscript(node)
visit_Suite(node)
visit_TempLoadNode(node)
visit_TempNode(node)
visit_TempStoreNode(node)
visit_TimeDeltaAttributeNode(node)
visit_TimeDeltaNode(node)
visit_Tuple(node)
visit_UnaryOp(node)
visit_UserNode(node)
visit_While(node)
numba.codegen.translate.add_cast_flag_unsigned(flags, lty, rty)