Exemplo n.º 1
0
/* Insert an if node around graft->node testing the condition encoded
 * in guard "guard", assuming guard involves any conditions.
 */
static __isl_give isl_ast_graft *insert_if_node(
	__isl_take isl_ast_graft *graft, __isl_take isl_set *guard,
	__isl_keep isl_ast_build *build)
{
	int univ;

	if (!graft)
		goto error;

	univ = isl_set_plain_is_universe(guard);
	if (univ < 0)
		goto error;
	if (univ) {
		isl_set_free(guard);
		return graft;
	}

	build = isl_ast_build_copy(build);
	graft->node = ast_node_insert_if(graft->node, guard, build);
	isl_ast_build_free(build);

	if (!graft->node)
		return isl_ast_graft_free(graft);

	return graft;
error:
	isl_set_free(guard);
	return isl_ast_graft_free(graft);
}
Exemplo n.º 2
0
ast_isl ast_gen::generate()
{
    auto ctx = m_model.context;

    if (verbose<ast_gen>::enabled())
        print_isl_ast_options(ctx);

    if (true)
    {
        //isl_options_set_ast_build_separation_bounds
                //(ctx.get(), ISL_AST_BUILD_SEPARATION_BOUNDS_IMPLICIT);
        //isl_options_set_ast_build_scale_strides(ctx, 0);
    }

    ast_isl output;

    auto build = isl_ast_build_from_context(m_schedule.params.copy());

    if (m_options.separate_loops)
    {
        if (m_schedule.tree.get())
        {
            auto root = isl_schedule_get_root(m_schedule.prelude_tree.get());
            root = mark_loop_type_separate(ctx, root);
            m_schedule.tree = isl_schedule_node_get_schedule(root);
            isl_schedule_node_free(root);
        }

        if (m_schedule.prelude_tree.get())
        {
            auto root = isl_schedule_get_root(m_schedule.prelude_tree.get());
            root = mark_loop_type_separate(ctx, root);

            m_schedule.prelude_tree = isl_schedule_node_get_schedule(root);

            isl_schedule_node_free(root);
        }

        if (m_schedule.period_tree.get())
        {
            auto root = isl_schedule_get_root(m_schedule.period_tree.get());
            root = mark_loop_type_separate(ctx, root);

            m_schedule.period_tree = isl_schedule_node_get_schedule(root);

            isl_schedule_node_free(root);
        }
    }

    build = isl_ast_build_set_before_each_for(build, &ast_gen::invoke_before_for, this);
    build = isl_ast_build_set_after_each_for(build, &ast_gen::invoke_after_for, this);

    // Initialize parallel accesses to empty map
    m_model.parallel_accesses = isl::union_map(m_model.context);

    if (m_schedule.tree.get())
    {
        if (verbose<ast_gen>::enabled())
            cout << endl << "** Building AST for entire program." << endl;
        m_allow_parallel_for = false;
        output.full =
                isl_ast_build_node_from_schedule(build, m_schedule.tree.copy());
    }
    if (m_schedule.prelude_tree.get())
    {
        if (verbose<ast_gen>::enabled())
            cout << endl << "** Building AST for prelude." << endl;
        m_allow_parallel_for = false;
        output.prelude =
                isl_ast_build_node_from_schedule(build, m_schedule.prelude_tree.copy());
    }
    if (m_schedule.period_tree.get())
    {
        if (verbose<ast_gen>::enabled())
            cout << endl << "** Building AST for period." << endl;

        m_allow_parallel_for = m_options.parallel | m_options.vectorize;

        int num_sched_dim = 0;

        m_schedule.period.for_each([&](const isl::map & m){
            num_sched_dim = m.get_space().dimension(isl::space::output);
            return false;
        });

        build = set_loop_iterators(build, num_sched_dim, m_options.parallel_dim);

        output.period =
                isl_ast_build_node_from_schedule(build, m_schedule.period_tree.copy());
    }

    isl_ast_build_free(build);

    return output;
}