Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def unary_op(self, node):
op = node.op
expr = self.visit(node.expr)
if hasFunction(self, userdef_unary_str(op, expr)) and \
self.current_function.name != userdef_unary_str(op, expr):
return self.builder.call(self.module.get_global(userdef_unary_str(op, expr)),
[expr], "unop")
elif op == MINUS:
if isinstance(expr.type, ir.IntType):
return self.builder.neg(expr)
elif isinstance(expr.type, (ir.FloatType, ir.DoubleType)):
return self.builder.fsub(ir.Constant(ir.DoubleType(), 0), expr)
elif op == NOT:
if isinstance(expr.type, ir.IntType) and str(expr.type).split("i")[1] == '1':
return self.builder.not_(expr)
elif op == BINARY_ONES_COMPLIMENT:
if isinstance(expr.type, ir.IntType):
return self.builder.not_(expr)
else:
error('file={} line={}: Unknown operator {} for {}'.format(
self.file_name,
node.line_num,
op,
expr
))
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()
function_names = []
registers, functions, uniques, extracts = {}, {}, {}, {}
internal_functions = {}
memory = {}
flags = ["ZF", "CF", "OF", "SF"]
pointers = ["RSP", "RIP", "RBP", "EBP", "ESP"]
def lift(filename):
root = et.parse(filename).getroot()
module = ir.Module(name="lifted")
for register in root.find('globals').findall('register'):
if register.get('name') in flags:
var = ir.GlobalVariable(module, ir.IntType(1), register.get('name'))
sig = typing.signature(types.boolean, fe_type, fe_type)
op = operator.eq
fnop = context.typing_context.resolve_value_type(op)
fnop.get_call_type(context.typing_context, sig.args, {})
eqfn = context.get_function(fnop, sig)
res = eqfn(builder, args)
intres = context.cast(builder, res, types.boolean, types.int32)
context.call_conv.return_value(builder, intres)
wrapfn = module.get_or_insert_function(
wrapfnty,
name='.numba_{}_item_equal.wrap${}'.format(container_type, fe_type)
)
build_wrapper(wrapfn)
equal_fnty = ir.FunctionType(ir.IntType(32), [data_ptr_ty, data_ptr_ty])
equal_fn = module.get_or_insert_function(
equal_fnty,
name='.numba_{}_item_equal${}'.format(container_type, fe_type),
)
builder = Builder(equal_fn.append_basic_block())
lhs = datamodel.load_from_data_pointer(builder, equal_fn.args[0])
rhs = datamodel.load_from_data_pointer(builder, equal_fn.args[1])
status, retval = context.call_conv.call_function(
builder, wrapfn, types.boolean, argtypes, [lhs, rhs],
)
with builder.if_then(status.is_ok, likely=True):
with builder.if_then(status.is_none):
builder.ret(context.get_constant(types.int32, 0))
retval = context.cast(builder, retval, types.boolean, types.int32)
builder.ret(retval)
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()
builder = ll.IRBuilder()
builder.position_at_end(bb_entry)
builder.branch(bb_loop)
builder.position_at_end(bb_loop)
index = builder.phi(ll.IntType(32))
def codegen(context, builder, sig, args):
in_str_arr, ind = args
string_array = context.make_helper(builder, string_array_type, in_str_arr)
# (null_bitmap[i / 8] & kBitmask[i % 8]) == 0;
byte_ind = builder.lshr(ind, lir.Constant(lir.IntType(64), 3))
bit_ind = builder.urem(ind, lir.Constant(lir.IntType(64), 8))
byte = builder.load(builder.gep(string_array.null_bitmap, [byte_ind], inbounds=True))
ll_typ_mask = lir.ArrayType(lir.IntType(8), 8)
mask_tup = cgutils.alloca_once_value(builder, lir.Constant(ll_typ_mask, (1, 2, 4, 8, 16, 32, 64, 128)))
mask = builder.load(builder.gep(mask_tup, [lir.Constant(lir.IntType(64), 0), bit_ind], inbounds=True))
return builder.icmp_unsigned('==', builder.and_(byte, mask), lir.Constant(lir.IntType(8), 0))
def codegen(context, builder, signature, args):
data, idx, ch = args
if bitsize < 32:
ch = builder.trunc(ch, IntType(bitsize))
ptr = builder.bitcast(data, IntType(bitsize).as_pointer())
builder.store(ch, builder.gep(ptr, [idx]))
return context.get_dummy_value()
def __init__(self, dmm, fe_type):
be_type = ir.IntType(64)
super(NPDatetimeModel, self).__init__(dmm, fe_type, be_type)
def pq_read_parallel_lower(context, builder, sig, args):
fnty = lir.FunctionType(lir.IntType(32),
[lir.IntType(8).as_pointer(), lir.IntType(64),
lir.IntType(8).as_pointer(),
lir.IntType(32), lir.IntType(64), lir.IntType(64)])
out_array = make_array(sig.args[2])(context, builder, args[2])
fn = builder.module.get_or_insert_function(fnty, name="pq_read_parallel")
return builder.call(fn, [args[0], args[1],
builder.bitcast(
out_array.data, lir.IntType(8).as_pointer()),
args[3], args[4], args[5]])
def access_member(member_offset):
# Access member by byte offset
offset = c.context.get_constant(types.uintp, member_offset)
llvoidptr = ir.IntType(8).as_pointer()
ptr = cgutils.pointer_add(c.builder, val, offset)
casted = c.builder.bitcast(ptr, llvoidptr.as_pointer())
return c.builder.load(casted)