How to use the llvmlite.ir.ArrayType 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 IntelPython / sdc / experimental / daal4py_ext.py View on Github external
def nt2nd(context, builder, ptr, ary_type):
    """
    Generate ir code to convert a pointer-to-daal-numeric-table to a ndarray
    FIXME: handle NULL pointer/table
    """

    # we need to prepare the shape array and a pointer
    shape_type = lir.ArrayType(lir.IntType(64), 2)
    shape = cgutils.alloca_once(builder, shape_type)
    data = cgutils.alloca_once(builder, lir.DoubleType().as_pointer())
    assert(ary_type in [dtable_type, ftable_type, itable_type,])
    # we also need indicate the type of the array (e.g. what we expect)
    d4ptype = context.get_constant(types.byte, d4ptypes[ary_type])
    # we can now declare and call our conversion function
    fnty = lir.FunctionType(lir.VoidType(),
                            [lir.IntType(8).as_pointer(), # actually pointer to numeric table
                             lir.DoubleType().as_pointer().as_pointer(),
                             shape_type.as_pointer(),
                             lir.IntType(8)])
    fn = builder.module.get_or_insert_function(fnty, name="to_c_array")
    builder.call(fn, [ptr, data, shape, d4ptype])
    # convert to ndarray
    shape = cgutils.unpack_tuple(builder, builder.load(shape))
    ary = _empty_nd_impl(context, builder, ary_type, shape)
github numba / numba / numba / cgutils.py View on Github external
def make_bytearray(buf):
    """
    Make a byte array constant from *buf*.
    """
    b = bytearray(buf)
    n = len(b)
    return ir.Constant(ir.ArrayType(ir.IntType(8), n), b)
github APrioriInvestments / typed_python / typed_python / compiler / native_ast_to_llvm.py View on Github external
if c.matches.Struct:
        vals = [constant_to_typed_llvm_value(module, builder, t) for _, t in c.elements]

        t = llvmlite.ir.LiteralStructType(type_to_llvm_type(t.llvm_value.type) for t in vals)
        llvm_c = llvmlite.ir.Constant(t, [t.llvm_value for t in vals])

        nt = native_ast.Type.Struct(
            [(c.elements[i][0], vals[i].native_type) for i in range(len(vals))]
        )

        return TypedLLVMValue(llvm_c, nt)

    if c.matches.ByteArray:
        byte_array = c.val

        t = llvmlite.ir.ArrayType(llvm_i8, len(byte_array) + 1)

        llvm_c = llvmlite.ir.Constant(t, bytearray(byte_array + b"\x00"))

        value = llvmlite.ir.GlobalVariable(module, t, "string_constant_%s" % strings_ever[0])

        strings_ever[0] += 1

        value.linkage = "private"
        value.initializer = llvm_c

        nt = native_ast.Type.Int(bits=8, signed=False).pointer()

        return TypedLLVMValue(
            builder.bitcast(value, llvm_i8ptr),
            nt
        )
github IntelPython / daal4py / daal4py / hpat / d4hpat.py View on Github external
def codegen(context, builder, sig, args):  # def nt2nd(context, builder, ptr, ary_type):
        '''Generate ir code to convert a pointer-to-daal-numeric-table to a ndarray'''
        # we need to prepare the shape array and a pointer
        shape_type = lir.ArrayType(lir.IntType(64), 2)
        shape = cgutils.alloca_once(builder, shape_type)
        data = cgutils.alloca_once(builder, lir.DoubleType().as_pointer())
        # we can now declare and call our conversion function
        fnty = lir.FunctionType(lir.VoidType(),
                                [lir.IntType(8).as_pointer(), # actually pointer to numeric table
                                 lir.DoubleType().as_pointer().as_pointer(),
                                 shape_type.as_pointer(),
                                 lir.IntType(8)])
        fn = builder.module.get_or_insert_function(fnty, name='to_c_array')
        builder.call(fn, [args[0], data, shape, context.get_constant(types.byte, dtype.literal_value)])
        # convert to ndarray
        shape = cgutils.unpack_tuple(builder, builder.load(shape))
        ary = _empty_nd_impl(context, builder, np_ary_type, shape)
        cgutils.raw_memcpy(builder, ary.data, builder.load(data), ary.nitems, ary.itemsize, align=1)
        # we are done!
        return impl_ret_new_ref(context, builder, np_ary_type, ary._getvalue())
github PrincetonUniversity / PsyNeuLink / psyneulink / core / llvm / helpers.py View on Github external
def get_private_condition_struct_type(self, composition):
        time_stamp_struct = ir.LiteralStructType([self.ctx.int32_ty,
                                                  self.ctx.int32_ty,
                                                  self.ctx.int32_ty])

        structure = ir.LiteralStructType([
            time_stamp_struct,  # current time stamp
            ir.ArrayType(       # for each node
                ir.LiteralStructType([
                    self.ctx.int32_ty,  # number of executions
                    time_stamp_struct   # time stamp of last execution
                ]), len(composition.nodes)
            )
        ])
        return structure
github squisher / stella / stella / tp.py View on Github external
def _llvmType(self, module):
        type_ = ll.ArrayType(self.type_.llvmType(module), self.shape)
        return type_
github PrincetonUniversity / PsyNeuLink / psyneulink / core / llvm / helpers.py View on Github external
def load_extract_scalar_array_one(builder, ptr):
    val = builder.load(ptr)
    if isinstance(val.type, ir.ArrayType) and val.type.count == 1:
        val = builder.extract_value(val, [0])
    return val