Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_helper_all_close(mode):
with pnlvm.LLVMBuilderContext() as ctx:
arr_ptr_ty = ir.ArrayType(ctx.float_ty, DIM_X).as_pointer()
func_ty = ir.FunctionType(ir.VoidType(), [arr_ptr_ty, arr_ptr_ty,
ir.IntType(32).as_pointer()])
custom_name = ctx.get_unique_name("all_close")
function = ir.Function(ctx.module, func_ty, name=custom_name)
in1, in2, out = function.args
block = function.append_basic_block(name="entry")
builder = ir.IRBuilder(block)
all_close = pnlvm.helpers.all_close(builder, in1, in2)
res = builder.select(all_close, out.type.pointee(1), out.type.pointee(0))
builder.store(res, out)
builder.ret_void()
vec1 = copy.deepcopy(VECTOR)
vec2 = copy.deepcopy(VECTOR)
def test_matmul_transposed_llvm_constant_dim(benchmark, mode):
custom_name = None
with pnlvm.LLVMBuilderContext() as ctx:
custom_name = ctx.get_unique_name("vxsqm")
double_ptr_ty = ctx.float_ty.as_pointer()
func_ty = ir.FunctionType(ir.VoidType(), (double_ptr_ty, double_ptr_ty, double_ptr_ty))
# get builtin IR
builtin = ctx.get_llvm_function("__pnl_builtin_vxm_transposed")
# Create square vector matrix multiply
function = ir.Function(ctx.module, func_ty, name=custom_name)
_x = ctx.int32_ty(x)
_y = ctx.int32_ty(y)
_v, _m, _o = function.args
block = function.append_basic_block(name="entry")
builder = ir.IRBuilder(block)
builder.call(builtin, [_v, _m, _x, _y, _o])
builder.ret_void()
binf2 = pnlvm.LLVMBinaryFunction.get(custom_name)
if mode == 'CPU':
def lower_dist_comm_req_dealloc(context, builder, sig, args):
fnty = lir.FunctionType(lir.VoidType(), [lir.IntType(8).as_pointer()])
fn = builder.module.get_or_insert_function(fnty, name="comm_req_dealloc")
builder.call(fn, args)
return context.get_dummy_value()
def add_log_functions(self):
"Add functions for state logging"
p8 = llvm_ir.PointerType(LLVMType.IntType(8))
self.add_fc({self.logging_func: {"ret": llvm_ir.VoidType(),
"args": [p8]}},
readonly=True)
def constant(self, value, cge=None):
return ll.Constant(self._llvm, value)
def __str__(self):
return self.name
def __repr__(self):
return "<{0}:{1}>".format(str(type(self))[8:-2], self.name)
tp_int = ll.IntType(64)
tp_int32 = ll.IntType(32) # needed for llvm operators
tp_double = ll.DoubleType()
tp_bool = ll.IntType(1)
tp_void = ll.VoidType()
Int = ScalarType(
"Int",
int, tp_int, ctypes.c_int64,
{float: 'fptosi'},
)
uInt = ScalarType( # TODO: unclear whether this is correct or not
"uInt",
int, tp_int32, ctypes.c_int32,
{},
)
Float = ScalarType(
"Float",
float, tp_double, ctypes.c_double,
{int: 'sitofp'},
)
def codegen(context, builder, sig, args):
in_set, in_str_arr = args
string_array = context.make_helper(builder, string_array_type, in_str_arr)
fnty = lir.FunctionType(lir.VoidType(),
[lir.IntType(8).as_pointer(),
lir.IntType(32).as_pointer(),
lir.IntType(8).as_pointer(),
])
fn_getitem = builder.module.get_or_insert_function(fnty,
name="populate_str_arr_from_set")
builder.call(fn_getitem, [in_set, string_array.offsets,
string_array.data])
return context.get_dummy_value()
from llvmlite import ir
import xml.etree.ElementTree as ET
int32 = ir.IntType(32)
int64 = ir.IntType(64)
int1 = ir.IntType(1)
void_type = ir.VoidType()
registers, varnodes, functions = {}, {}, {}
def main():
root = ET.parse('/tmp/output.xml').getroot()
module = ir.Module(name="lifted")
for register in root.find('globals').findall('register'):
var = ir.GlobalVariable(module, ir.IntType(8*int(register.get('size'))), register.get('name'))
var.initializer = ir.Constant(ir.IntType(8*int(register.get('size'))), None)
var.linkage = 'internal'
registers[register.get('name')] = var
for function in root.findall('function'):
name = function.get('name')
functions[name] = get_function(function, name, module)
print(module)
return 0
def get_rnd_shuffle(builder):
"""
Get the internal function to shuffle the MT taste.
"""
fnty = ir.FunctionType(ir.VoidType(), (rnd_state_ptr_t,))
fn = builder.function.module.get_or_insert_function(fnty, "numba_rnd_shuffle")
fn.args[0].add_attribute("nocapture")
return fn
def setitem_dict(context, builder, sig, args):
_, key_typ, val_typ = sig.args
dct, key, val = args
fname = "dict_{}_{}_setitem".format(key_typ, val_typ)
if key_typ == string_type:
key_typ = types.voidptr
key = gen_unicode_to_std_str(context, builder, key)
if val_typ == string_type:
val_typ = types.voidptr
val = gen_unicode_to_std_str(context, builder, val)
fnty = lir.FunctionType(lir.VoidType(),
[lir.IntType(8).as_pointer(),
context.get_value_type(key_typ),
context.get_value_type(val_typ)])
fn = builder.module.get_or_insert_function(fnty, name=fname)
return builder.call(fn, [dct, key, val])
def build_function(name, module):
func_return = ir.VoidType()
fnty = ir.FunctionType(func_return, [])
ir_func = ir.Function(module, fnty, name)
return ir_func