How to use the llvmlite.ir.FunctionType function in llvmlite

To help you get started, we’ve selected a few llvmlite examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hassanalinali / Lesma / src / lesma / compiler / builtins.py View on Github external
def dynamic_array_init(self, dyn_array_ptr, array_type):
    # START
    dyn_array_init_type = ir.FunctionType(type_map[VOID], [dyn_array_ptr])
    dyn_array_init = ir.Function(self.module, dyn_array_init_type, '{}.array.init'.format(str(array_type)))
    dyn_array_init.args[0].name = 'self'
    dyn_array_init_entry = dyn_array_init.append_basic_block('entry')
    builder = ir.IRBuilder(dyn_array_init_entry)
    self.builder = builder
    dyn_array_init_exit = dyn_array_init.append_basic_block('exit')
    builder.position_at_end(dyn_array_init_entry)
    array_ptr = builder.alloca(dyn_array_ptr)
    builder.store(dyn_array_init.args[0], array_ptr)

    # BODY
    size_ptr = builder.gep(builder.load(array_ptr), [zero_32, zero_32], inbounds=True)
    builder.store(zero, size_ptr)

    capacity_ptr = builder.gep(builder.load(array_ptr), [zero_32, one_32], inbounds=True)
    builder.store(ARRAY_INITIAL_CAPACITY, capacity_ptr)
github squisher / stella / stella / ir.py View on Github external
def translate(self, clib, module):
        logging.debug("Adding external function {0}".format(self.name))
        f = getattr(clib, self.name)
        llvm.add_symbol(self.name, ctypes.cast(f, ctypes.c_void_p).value)

        llvm_arg_types = [arg.llvmType(module) for arg in self.type_.arg_types]

        func_tp = ll.FunctionType(self.type_.return_type.llvmType(module), llvm_arg_types)
        self.llvm = ll.Function(module, func_tp, self.name)
github IntelPython / sdc / sdc / str_ext.py View on Github external
def gen_unicode_to_std_str(context, builder, unicode_val):
    #
    uni_str = cgutils.create_struct_proxy(string_type)(
        context, builder, value=unicode_val)
    fnty = lir.FunctionType(lir.IntType(8).as_pointer(),
                            [lir.IntType(8).as_pointer(), lir.IntType(64)])
    fn = builder.module.get_or_insert_function(fnty, name="init_string_const")
    return builder.call(fn, [uni_str.data, uni_str.length])
github numba / numba / numba / targets / linalg.py View on Github external
def call_xxgemv(context, builder, do_trans,
                m_type, m_shapes, m_data, v_data, out_data):
    """
    Call the BLAS matrix * vector product function for the given arguments.
    """
    fnty = ir.FunctionType(ir.IntType(32),
                           [ll_char, ll_char,                 # kind, trans
                            intp_t, intp_t,                   # m, n
                            ll_void_p, ll_void_p, intp_t,     # alpha, a, lda
                            ll_void_p, ll_void_p, ll_void_p,  # x, beta, y
                            ])
    fn = builder.module.get_or_insert_function(fnty, name="numba_xxgemv")

    dtype = m_type.dtype
    alpha = make_constant_slot(context, builder, dtype, 1.0)
    beta = make_constant_slot(context, builder, dtype, 0.0)

    if m_type.layout == 'F':
        m, n = m_shapes
        lda = m_shapes[0]
    else:
        n, m = m_shapes
github IntelPython / sdc / sdc / str_ext.py View on Github external
def const_string(context, builder, ty, pyval):
    cstr = context.insert_const_string(builder.module, pyval)
    length = context.get_constant(types.intp, len(pyval))

    fnty = lir.FunctionType(lir.IntType(8).as_pointer(),
                            [lir.IntType(8).as_pointer(), lir.IntType(64)])
    fn = builder.module.get_or_insert_function(fnty, name="init_string_const")
    ret = builder.call(fn, [cstr, length])
    return ret
github syegulalp / Akilang / aki / core / akitypes.py View on Github external
def __init__(self, arguments: list, return_type: AkiType):
        # list of decorated AkiType nodes
        self.arguments = arguments
        # single decorated AkiType node
        self.return_type = return_type

        self.llvm_type = ir.PointerType(
            ir.FunctionType(
                self.return_type.llvm_type, [_.llvm_type for _ in self.arguments]
            )
        )
        self.type_id = f'func({",".join([str(_.akitype)[1:] for _ in self.arguments])}){self.return_type}'
        self.name = self.type_id
github IntelPython / sdc / hpat / io / pio_lower.py View on Github external
def h5_size(context, builder, sig, args):
    fnty = lir.FunctionType(lir.IntType(
        64), [h5file_lir_type, lir.IntType(32)])
    fn = builder.module.get_or_insert_function(fnty, name="hpat_h5_size")
    return builder.call(fn, [args[0], args[1]])
github toor-de-force / Ghidra-to-LLVM / src / xmltollvm.py View on Github external
var.initializer = ir.Constant(ir.IntType(8 * int(memory_location.get('size'))), None)
        var.linkage = 'internal'
        memory[memory_location.get('name')] = var

    func_return = ir.VoidType()
    fnty = ir.FunctionType(func_return, [])
    ir_func = ir.Function(module, fnty, "intra_function_branch")
    internal_functions["intra_function_branch"] = ir_func

    func_return = ir.VoidType()
    fnty = ir.FunctionType(func_return, [])
    ir_func = ir.Function(module, fnty, "call_indirect")
    internal_functions["call_indirect"] = ir_func

    func_return = ir.VoidType()
    fnty = ir.FunctionType(func_return, [])
    ir_func = ir.Function(module, fnty, "bit_extraction")
    internal_functions["bit_extraction"] = ir_func

    for function in root.findall('function'):
        name = function.get('name')
        x = 1
        while name in function_names:
            name = name + "_" + str(x)
            x += 1
        function_names.append(name)
        address = function.get('address')
        functions[address] = [build_function(name, module), function]

    for address in functions:
        ir_func, function = functions[address]
        populate_func(ir_func, function)
github numba / numba / numba / listobject.py View on Github external
def codegen(context, builder, sig, args):
        fnty = ir.FunctionType(
            ll_status,
            [ll_list_type, ll_ssize_t, ll_ssize_t, ll_ssize_t],
        )
        [l, start, stop, step] = args
        [tl, tstart, tstop, tstep] = sig.args
        fn = builder.module.get_or_insert_function(
            fnty, name='numba_list_delete_slice')

        lp = _container_get_data(context, builder, tl, l)
        status = builder.call(
            fn,
            [
                lp,
                start,
                stop,
                step,
github numba / numba / numba / cgutils.py View on Github external
def snprintf(builder, buffer, bufsz, format, *args):
    """Calls libc snprintf(buffer, bufsz, format, ...args)
    """
    assert isinstance(format, str)
    mod = builder.module
    # Make global constant for format string
    cstring = voidptr_t
    fmt_bytes = make_bytearray((format + '\00').encode('ascii'))
    global_fmt = global_constant(mod, "snprintf_format", fmt_bytes)
    fnty = ir.FunctionType(
        int32_t, [cstring, intp_t, cstring], var_arg=True,
    )
    # Actual symbol name of snprintf is different on win32.
    symbol = 'snprintf'
    if config.IS_WIN32:
        symbol = '_' + symbol
    # Insert snprintf()
    try:
        fn = mod.get_global(symbol)
    except KeyError:
        fn = ir.Function(mod, fnty, name=symbol)
    # Call
    ptr_fmt = builder.bitcast(global_fmt, cstring)
    return builder.call(fn, [buffer, bufsz, ptr_fmt] + list(args))