def to_codegen_result(codegen_state, insn_id, domain, check_inames, required_preds, ast): from loopy.codegen.bounds import get_bounds_checks from loopy.symbolic import constraint_to_expr bounds_checks = get_bounds_checks(domain, check_inames, codegen_state.implemented_domain, overapproximate=False) bounds_check_set = isl.Set.universe(domain.get_space()) \ .add_constraints(bounds_checks) bounds_check_set, new_implemented_domain = isl.align_two( bounds_check_set, codegen_state.implemented_domain) new_implemented_domain = new_implemented_domain & bounds_check_set if bounds_check_set.is_empty(): return None condition_exprs = [constraint_to_expr(cns) for cns in bounds_checks] condition_exprs.extend(required_preds - codegen_state.implemented_predicates) if condition_exprs: from pymbolic.primitives import LogicalAnd from pymbolic.mapper.stringifier import PREC_NONE ast = codegen_state.ast_builder.emit_if( codegen_state.expression_to_code_mapper( LogicalAnd(tuple(condition_exprs)), PREC_NONE), ast) return CodeGenerationResult.new(codegen_state, insn_id, ast, new_implemented_domain)
def to_codegen_result( codegen_state, insn_id, domain, check_inames, required_preds, ast): from loopy.codegen.bounds import get_bounds_checks from loopy.symbolic import constraint_to_expr bounds_checks = get_bounds_checks( domain, check_inames, codegen_state.implemented_domain, overapproximate=False) bounds_check_set = isl.Set.universe(domain.get_space()) \ .add_constraints(bounds_checks) bounds_check_set, new_implemented_domain = isl.align_two( bounds_check_set, codegen_state.implemented_domain) new_implemented_domain = new_implemented_domain & bounds_check_set if bounds_check_set.is_empty(): return None condition_exprs = [ constraint_to_expr(cns) for cns in bounds_checks] condition_exprs.extend( required_preds - codegen_state.implemented_predicates) if condition_exprs: from pymbolic.primitives import LogicalAnd from pymbolic.mapper.stringifier import PREC_NONE ast = codegen_state.ast_builder.emit_if( codegen_state.expression_to_code_mapper( LogicalAnd(tuple(condition_exprs)), PREC_NONE), ast) return CodeGenerationResult.new( codegen_state, insn_id, ast, new_implemented_domain)
def constraint_to_code(ecm, cns): if cns.is_equality(): comp_op = "==" else: comp_op = ">=" from loopy.symbolic import constraint_to_expr return "%s %s 0" % (ecm(constraint_to_expr(cns), PREC_NONE, "i"), comp_op)
def gen_code(inner_codegen_state): condition_exprs = [ constraint_to_expr(cns) for cns in bounds_checks ] + [pred_chk for pred_chk in pred_checks] prev_result = prev_gen_code(inner_codegen_state) return [ wrap_in_if( inner_codegen_state, condition_exprs, merge_codegen_results(codegen_state, prev_result)) ]
def gen_code(inner_codegen_state): from pymbolic.primitives import Variable condition_exprs = [ constraint_to_expr(cns) for cns in bounds_checks ] + [Variable(pred_chk) for pred_chk in pred_checks] prev_result = prev_gen_code(inner_codegen_state) return [ wrap_in_if( inner_codegen_state, condition_exprs, merge_codegen_results(codegen_state, prev_result)) ]
def gen_code(inner_codegen_state): from pymbolic.primitives import Variable condition_exprs = [ constraint_to_expr(cns) for cns in bounds_checks] + [ Variable(pred_chk) for pred_chk in pred_checks] prev_result = prev_gen_code(inner_codegen_state) return [wrap_in_if( inner_codegen_state, condition_exprs, merge_codegen_results(codegen_state, prev_result))]