/* Translation of ISL AST to Gimple.
- Copyright (C) 2014 Free Software Foundation, Inc.
+ Copyright (C) 2014-2015 Free Software Foundation, Inc.
Contributed by Roman Gareev <gareevroman@gmail.com>.
This file is part of GCC.
#include "config.h"
-#ifdef HAVE_cloog
+#ifdef HAVE_isl
#include <isl/set.h>
#include <isl/map.h>
#include <isl/union_map.h>
#include <isl/ast_build.h>
-#if defined(__cplusplus)
+
+/* Since ISL-0.13, the extern is in val_gmp.h. */
+#if !defined(HAVE_ISL_SCHED_CONSTRAINTS_COMPUTE_SCHEDULE) && defined(__cplusplus)
extern "C" {
#endif
#include <isl/val_gmp.h>
-#if defined(__cplusplus)
+#if !defined(HAVE_ISL_SCHED_CONSTRAINTS_COMPUTE_SCHEDULE) && defined(__cplusplus)
}
#endif
#endif
#include "system.h"
#include "coretypes.h"
+#include "alias.h"
+#include "symtab.h"
+#include "options.h"
#include "tree.h"
+#include "fold-const.h"
+#include "predict.h"
+#include "tm.h"
+#include "hard-reg-set.h"
+#include "function.h"
+#include "dominance.h"
+#include "cfg.h"
#include "basic-block.h"
#include "tree-ssa-alias.h"
#include "internal-fn.h"
#include "gimple-expr.h"
-#include "is-a.h"
#include "gimple.h"
#include "gimple-iterator.h"
#include "tree-ssa-loop.h"
#include "tree-into-ssa.h"
#include <map>
-#ifdef HAVE_cloog
+#ifdef HAVE_isl
#include "graphite-poly.h"
#include "graphite-isl-ast-to-gimple.h"
static int graphite_expression_type_precision = 128 <= max_mode_int_precision ?
128 : max_mode_int_precision;
+struct ast_build_info
+{
+ ast_build_info()
+ : is_parallelizable(false)
+ { };
+ bool is_parallelizable;
+};
+
/* Converts a GMP constant VAL to a tree and returns it. */
static tree
redirect_edge_succ_nodup (next_e, after);
set_immediate_dominator (CDI_DOMINATORS, next_e->dest, next_e->src);
- /* TODO: Add checking for the loop parallelism. */
+ if (flag_loop_parallelize_all)
+ {
+ isl_id *id = isl_ast_node_get_annotation (node_for);
+ gcc_assert (id);
+ ast_build_info *for_info = (ast_build_info *) isl_id_get_user (id);
+ loop->can_be_parallel = for_info->is_parallelizable;
+ free (for_info);
+ isl_id_free (id);
+ }
return last_e;
}
gcc_assert (GBB_BB (gbb) != ENTRY_BLOCK_PTR_FOR_FN (cfun) &&
"The entry block should not even appear within a scop");
- loop_p loop = gbb_loop (gbb);
- iv_map.create (loop->num + 1);
- iv_map.safe_grow_cleared (loop->num + 1);
+ int nb_loops = number_of_loops (cfun);
+ iv_map.create (nb_loops);
+ iv_map.safe_grow_cleared (nb_loops);
build_iv_mapping (iv_map, gbb, user_expr, ip, SCOP_REGION (pbb->scop));
isl_ast_expr_free (user_expr);
return schedule;
}
+/* Set the separation_class option for unroll and jam. */
+
+static __isl_give isl_union_map *
+generate_luj_sepclass_opt (scop_p scop, __isl_take isl_union_set *domain,
+ int dim, int cl)
+{
+ isl_map *map;
+ isl_space *space, *space_sep;
+ isl_ctx *ctx;
+ isl_union_map *mapu;
+ int nsched = get_max_schedule_dimensions (scop);
+
+ ctx = scop->ctx;
+ space_sep = isl_space_alloc (ctx, 0, 1, 1);
+ space_sep = isl_space_wrap (space_sep);
+ space_sep = isl_space_set_tuple_name (space_sep, isl_dim_set,
+ "separation_class");
+ space = isl_set_get_space (scop->context);
+ space_sep = isl_space_align_params (space_sep, isl_space_copy(space));
+ space = isl_space_map_from_domain_and_range (space, space_sep);
+ space = isl_space_add_dims (space,isl_dim_in, nsched);
+ map = isl_map_universe (space);
+ isl_map_fix_si (map,isl_dim_out,0,dim);
+ isl_map_fix_si (map,isl_dim_out,1,cl);
+
+ mapu = isl_union_map_intersect_domain (isl_union_map_from_map (map),
+ domain);
+ return (mapu);
+}
+
+/* Compute the separation class for loop unroll and jam. */
+
+static __isl_give isl_union_set *
+generate_luj_sepclass (scop_p scop)
+{
+ int i;
+ poly_bb_p pbb;
+ isl_union_set *domain_isl;
+
+ domain_isl = isl_union_set_empty (isl_set_get_space (scop->context));
+
+ FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb)
+ {
+ isl_set *bb_domain;
+ isl_set *bb_domain_s;
+
+ if (pbb->map_sepclass == NULL)
+ continue;
+
+ if (isl_set_is_empty (pbb->domain))
+ continue;
+
+ bb_domain = isl_set_copy (pbb->domain);
+ bb_domain_s = isl_set_apply (bb_domain, pbb->map_sepclass);
+ pbb->map_sepclass = NULL;
+
+ domain_isl =
+ isl_union_set_union (domain_isl, isl_union_set_from_set (bb_domain_s));
+ }
+
+ return domain_isl;
+}
+
+/* Set the AST built options for loop unroll and jam. */
+
+static __isl_give isl_union_map *
+generate_luj_options (scop_p scop)
+{
+ isl_union_set *domain_isl;
+ isl_union_map *options_isl_ss;
+ isl_union_map *options_isl =
+ isl_union_map_empty (isl_set_get_space (scop->context));
+ int dim = get_max_schedule_dimensions (scop) - 1;
+ int dim1 = dim - PARAM_VALUE (PARAM_LOOP_UNROLL_JAM_DEPTH);
+
+ if (!flag_loop_unroll_jam)
+ return options_isl;
+
+ domain_isl = generate_luj_sepclass (scop);
+
+ options_isl_ss = generate_luj_sepclass_opt (scop, domain_isl, dim1, 0);
+ options_isl = isl_union_map_union (options_isl, options_isl_ss);
+
+ return options_isl;
+}
+
/* Generates a schedule, which specifies an order used to
visit elements in a domain. */
return schedule_isl;
}
+/* This method is executed before the construction of a for node. */
+static __isl_give isl_id *
+ast_build_before_for (__isl_keep isl_ast_build *build, void *user)
+{
+ isl_union_map *dependences = (isl_union_map *) user;
+ ast_build_info *for_info = XNEW (struct ast_build_info);
+ isl_union_map *schedule = isl_ast_build_get_schedule (build);
+ isl_space *schedule_space = isl_ast_build_get_schedule_space (build);
+ int dimension = isl_space_dim (schedule_space, isl_dim_out);
+ for_info->is_parallelizable =
+ !carries_deps (schedule, dependences, dimension);
+ isl_union_map_free (schedule);
+ isl_space_free (schedule_space);
+ isl_id *id = isl_id_alloc (isl_ast_build_get_ctx (build), "", for_info);
+ return id;
+}
+
+/* Set the separate option for all dimensions.
+ This helps to reduce control overhead.
+ Set the options for unroll and jam. */
+
+static __isl_give isl_ast_build *
+set_options (__isl_take isl_ast_build *control,
+ __isl_keep isl_union_map *schedule,
+ __isl_take isl_union_map *opt_luj)
+{
+ isl_ctx *ctx = isl_union_map_get_ctx (schedule);
+ isl_space *range_space = isl_space_set_alloc (ctx, 0, 1);
+ range_space =
+ isl_space_set_tuple_name (range_space, isl_dim_set, "separate");
+ isl_union_set *range =
+ isl_union_set_from_set (isl_set_universe (range_space));
+ isl_union_set *domain = isl_union_map_range (isl_union_map_copy (schedule));
+ domain = isl_union_set_universe (domain);
+ isl_union_map *options = isl_union_map_from_domain_and_range (domain, range);
+
+ options = isl_union_map_union (options, opt_luj);
+
+ return isl_ast_build_set_options (control, options);
+}
+
static __isl_give isl_ast_node *
scop_to_isl_ast (scop_p scop, ivs_params &ip)
{
isl_options_set_ast_build_atomic_upper_bound (scop->ctx, true);
add_parameters_to_ivs_params (scop, ip);
+
+ isl_union_map *options_luj = generate_luj_options (scop);
+
isl_union_map *schedule_isl = generate_isl_schedule (scop);
isl_ast_build *context_isl = generate_isl_context (scop);
+
+ context_isl = set_options (context_isl, schedule_isl, options_luj);
+
+ isl_union_map *dependences = NULL;
+ if (flag_loop_parallelize_all)
+ {
+ dependences = scop_get_dependences (scop);
+ context_isl =
+ isl_ast_build_set_before_each_for (context_isl, ast_build_before_for,
+ dependences);
+ }
isl_ast_node *ast_isl = isl_ast_build_ast_from_schedule (context_isl,
schedule_isl);
+ if(dependences)
+ isl_union_map_free (dependences);
isl_ast_build_free (context_isl);
return ast_isl;
}
translate_isl_ast (context_loop, root_node, if_region->true_region->entry,
ip);
+
+ mark_virtual_operands_for_renaming (cfun);
+ update_ssa (TODO_update_ssa);
+
graphite_verify ();
scev_reset ();
recompute_all_dominators ();
ivs_params_clear (ip);
isl_ast_node_free (root_node);
timevar_pop (TV_GRAPHITE_CODE_GEN);
- /* TODO: Add dump */
+
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ loop_p loop;
+ int num_no_dependency = 0;
+
+ FOR_EACH_LOOP (loop, 0)
+ if (loop->can_be_parallel)
+ num_no_dependency++;
+
+ fprintf (dump_file, "\n%d loops carried no dependency.\n",
+ num_no_dependency);
+ }
+
return !graphite_regenerate_error;
}
#endif