How to use the llvmlite.binding 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 numba / numba / numba / targets / codegen.py View on Github external
def _init(self, llvm_module):
        assert list(llvm_module.global_variables) == [], "Module isn't empty"

        target = ll.Target.from_triple(ll.get_process_triple())
        tm_options = dict(opt=config.OPT)
        self._tm_features = self._customize_tm_features()
        self._customize_tm_options(tm_options)
        tm = target.create_target_machine(**tm_options)
        engine = ll.create_mcjit_compiler(llvm_module, tm)

        if config.ENABLE_PROFILING:
            engine.enable_jit_events()

        self._tm = tm
        self._engine = JitEngine(engine)
        self._target_data = engine.target_data
        self._data_layout = str(self._target_data)
        self._mpm = self._module_pass_manager()

        self._engine.set_object_cache(self._library_class._object_compiled_hook,
github numba / llvmlite / examples / ll_fpadd.py View on Github external
def create_execution_engine():
    """
    Create an ExecutionEngine suitable for JIT code generation on
    the host CPU.  The engine is reusable for an arbitrary number of
    modules.
    """
    # Create a target machine representing the host
    target = llvm.Target.from_default_triple()
    target_machine = target.create_target_machine()
    # And an execution engine with an empty backing module
    backing_mod = llvm.parse_assembly("")
    engine = llvm.create_mcjit_compiler(backing_mod, target_machine)
    return engine
github h2oai / datatable / datatable / graph / llvm.py View on Github external
Create an ExecutionEngine suitable for JIT code generation on the host
        CPU. The engine is reusable for any number of modules.
        """
        from llvmlite import binding
        if not self._clang:
            return None
        # Initialization...
        binding.initialize()
        binding.initialize_native_target()
        binding.initialize_native_asmprinter()
        # Create a target machine representing the host
        target = binding.Target.from_default_triple()
        target_machine = target.create_target_machine()
        # And an execution engine with an empty backing module
        backing_mod = binding.parse_assembly("")
        engine = binding.create_mcjit_compiler(backing_mod, target_machine)
        self._binding = binding
        return engine
github numba / llvmlite / llvmlite / llvmpy / passes.py View on Github external
pm = llvm.create_module_pass_manager()

    if kws.get('fpm', True):
        assert isinstance(mod, llvm.ModuleRef)
        fpm = llvm.create_function_pass_manager(mod)
    else:
        fpm = None

    with llvm.create_pass_manager_builder() as pmb:
        pmb.opt_level = opt = kws.get('opt', 2)
        pmb.loop_vectorize = kws.get('loop_vectorize', False)
        pmb.slp_vectorize = kws.get('slp_vectorize', False)
        pmb.inlining_threshold = _inlining_threshold(optlevel=opt)

        if mod:
            tli = llvm.create_target_library_info(mod.triple)
            if kws.get('nobuiltins', False):
                # Disable all builtins (-fno-builtins)
                tli.disable_all()
            else:
                # Disable a list of builtins given
                for k in kws.get('disable_builtins', ()):
                    libf = tli.get_libfunc(k)
                    tli.set_unavailable(libf)

            tli.add_pass(pm)
            if fpm is not None:
                tli.add_pass(fpm)

        tm = kws.get('tm')
        if tm:
            tm.add_analysis_passes(pm)
github syegulalp / Akilang / aki / core / repl / __init__.py View on Github external
def make_module(self, name, typemgr=None):
        if typemgr is None:
            typemgr = self.typemgr
        mod = ir.Module(name)
        mod.triple = binding.Target.from_default_triple().triple
        other_modules = []
        if name != "stdlib":
            other_modules.append(self.stdlib_module)
        mod.codegen = AkiCodeGen(mod, typemgr, name, other_modules)
        return mod
github IntelPython / sdc / sdc / hiframes / join.py View on Github external
func_text += "  val_{}._data, n_chars_{})\n".format(i, i)
            func_text += "  meta_tup[{}].tmp_offset_char[node_id] += n_chars_{}\n".format(i, i)

    func_text += "  return\n"
    loc_vars = {}
    exec(func_text, {'str_copy_ptr': str_copy_ptr, 'get_utf8_size': get_utf8_size}, loc_vars)
    write_impl = loc_vars['f']
    return write_impl


if hpat_config.config_transport_mpi:
    from .. import transport_mpi as transport
else:
    from .. import transport_seq as transport

ll.add_symbol('get_join_sendrecv_counts', transport.get_join_sendrecv_counts)
ll.add_symbol('c_alltoallv', transport.c_alltoallv)

ll.add_symbol('timsort', chiframes.timsort)


@numba.njit
def calc_disp(arr):
    disp = np.empty_like(arr)
    disp[0] = 0
    for i in range(1, len(arr)):
        disp[i] = disp[i - 1] + arr[i - 1]
    return disp


def ensure_capacity(arr, new_size):
    new_arr = arr
github numba / numba / numba / targets / codegen.py View on Github external
def display(self, filename=None, view=False):
        """
        Plot the CFG.  In IPython notebook, the return image object can be
        inlined.

        The *filename* option can be set to a specific path for the rendered
        output to write to.  If *view* option is True, the plot is opened by
        the system default application for the image format (PDF).
        """
        return ll.view_dot_graph(self.dot, filename=filename, view=view)
github numba / llvmlite / examples / sum.py View on Github external
from time import perf_counter as time
except ImportError:
    from time import time

import numpy as np

try:
    import faulthandler; faulthandler.enable()
except ImportError:
    pass

import llvmlite.ir as ll
import llvmlite.binding as llvm


llvm.initialize()
llvm.initialize_native_target()
llvm.initialize_native_asmprinter()


t1 = time()

fnty = ll.FunctionType(ll.IntType(32), [ll.IntType(32).as_pointer(),
                                        ll.IntType(32)])
module = ll.Module()

func = ll.Function(module, fnty, name="sum")

bb_entry = func.append_basic_block()
bb_loop = func.append_basic_block()
bb_exit = func.append_basic_block()
github cea-sec / miasm / miasm / jitter / llvmconvert.py View on Github external
def init_fc(self):
        "Init the function"

        # Build type for fc signature
        fc_type = llvm_ir.FunctionType(
            self.ret_type,
            [k[1] for k in self.my_args]
        )

        # Add fc in module
        try:
            fc = llvm_ir.Function(self.mod, fc_type, name=self.name)
        except llvm.LLVMException:
            # Overwrite the previous function
            previous_fc = self.mod.get_global(self.name)
            previous_fc.delete()
            fc = self.mod.add_function(fc_type, self.name)

        # Name args
        for i, a in enumerate(self.my_args):
            fc.args[i].name = a[2]

        # Initialize local variable pool
        self.local_vars = {}
        self.local_vars_pointers = {}
        for i, a in enumerate(self.my_args):
            self.local_vars[a[2]] = fc.args[i]

        # Init cache
github IntelPython / sdc / sdc / dict_ext.py View on Github external
'multimap_int64_equal_range_dealloc',
    types.void(multimap_int64_range_iterator_type))

multimap_int64_equal_range_inplace = types.ExternalFunction(
    'multimap_int64_equal_range_inplace',
    multimap_int64_range_iterator_type(multimap_int64_type, types.int64,
                                       multimap_int64_range_iterator_type))

ll.add_symbol('multimap_int64_init', hdict_ext.multimap_int64_init)
ll.add_symbol('multimap_int64_insert', hdict_ext.multimap_int64_insert)
ll.add_symbol('multimap_int64_equal_range', hdict_ext.multimap_int64_equal_range)
ll.add_symbol('multimap_int64_equal_range_alloc', hdict_ext.multimap_int64_equal_range_alloc)
ll.add_symbol('multimap_int64_equal_range_dealloc', hdict_ext.multimap_int64_equal_range_dealloc)
ll.add_symbol('multimap_int64_equal_range_inplace', hdict_ext.multimap_int64_equal_range_inplace)
ll.add_symbol('multimap_int64_it_is_valid', hdict_ext.multimap_int64_it_is_valid)
ll.add_symbol('multimap_int64_it_get_value', hdict_ext.multimap_int64_it_get_value)
ll.add_symbol('multimap_int64_it_inc', hdict_ext.multimap_int64_it_inc)


@lower_builtin('getiter', MultiMapRangeIteratorType)
def iterator_getiter(context, builder, sig, args):
    it, = args
    # return impl_ret_borrowed(context, builder, sig.return_type, it)
    return it


@lower_builtin('iternext', MultiMapRangeIteratorType)
@iternext_impl(RefType.UNTRACKED)
def iternext_listiter(context, builder, sig, args, result):
    ll_bool = context.get_value_type(types.bool_)  # lir.IntType(1)?

    # is valid