From 333cc5184301dc7efafa0f71d2493f4fd88bc106 Mon Sep 17 00:00:00 2001 From: Roman Gareev Date: Mon, 28 Jul 2014 05:49:05 +0000 Subject: [PATCH] [gcc/] * graphite-isl-ast-to-gimple.c: (graphite_create_new_guard): New function. (translate_isl_ast_node_if): New function. (translate_isl_ast): Add calling of translate_isl_ast_node_if. [gcc/testsuite] * gcc.dg/graphite/isl-ast-gen-if-1.c: New testcase. From-SVN: r213109 --- gcc/ChangeLog | 9 +++++ gcc/graphite-isl-ast-to-gimple.c | 40 ++++++++++++++++++- .../gcc.dg/graphite/isl-ast-gen-if-1.c | 37 +++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/graphite/isl-ast-gen-if-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 62a4e6408bd..187f98858fe 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2014-07-28 Roman Gareev + + * graphite-isl-ast-to-gimple.c: + (graphite_create_new_guard): New function. + (translate_isl_ast_node_if): New function. + (translate_isl_ast): Add calling of translate_isl_ast_node_if. + + * gcc.dg/graphite/isl-ast-gen-if-1.c: New testcase. + 2014-07-27 Anthony Green * config.gcc: Add moxie-*-moxiebox* configuration. diff --git a/gcc/graphite-isl-ast-to-gimple.c b/gcc/graphite-isl-ast-to-gimple.c index 77b5ed4afe1..b5631ca6fba 100644 --- a/gcc/graphite-isl-ast-to-gimple.c +++ b/gcc/graphite-isl-ast-to-gimple.c @@ -645,6 +645,43 @@ translate_isl_ast_node_block (loop_p context_loop, isl_ast_node_list_free (node_list); return next_e; } + +/* Creates a new if region corresponding to ISL's cond. */ + +static edge +graphite_create_new_guard (edge entry_edge, __isl_take isl_ast_expr *if_cond, + ivs_params &ip) +{ + tree type = + build_nonstandard_integer_type (graphite_expression_type_precision, 0); + tree cond_expr = gcc_expression_from_isl_expression (type, if_cond, ip); + edge exit_edge = create_empty_if_region_on_edge (entry_edge, cond_expr); + return exit_edge; +} + +/* Translates an isl_ast_node_if to Gimple. */ + +static edge +translate_isl_ast_node_if (loop_p context_loop, + __isl_keep isl_ast_node *node, + edge next_e, ivs_params &ip) +{ + gcc_assert (isl_ast_node_get_type (node) == isl_ast_node_if); + isl_ast_expr *if_cond = isl_ast_node_if_get_cond (node); + edge last_e = graphite_create_new_guard (next_e, if_cond, ip); + + edge true_e = get_true_edge_from_guard_bb (next_e->dest); + isl_ast_node *then_node = isl_ast_node_if_get_then (node); + translate_isl_ast (context_loop, then_node, true_e, ip); + isl_ast_node_free (then_node); + + edge false_e = get_false_edge_from_guard_bb (next_e->dest); + isl_ast_node *else_node = isl_ast_node_if_get_else (node); + if (isl_ast_node_get_type (else_node) != isl_ast_node_error) + translate_isl_ast (context_loop, else_node, false_e, ip); + isl_ast_node_free (else_node); + return last_e; +} /* Translates an ISL AST node NODE to GCC representation in the context of a SESE. */ @@ -663,7 +700,8 @@ translate_isl_ast (loop_p context_loop, __isl_keep isl_ast_node *node, next_e, ip); case isl_ast_node_if: - return next_e; + return translate_isl_ast_node_if (context_loop, node, + next_e, ip); case isl_ast_node_user: return translate_isl_ast_node_user (node, next_e, ip); diff --git a/gcc/testsuite/gcc.dg/graphite/isl-ast-gen-if-1.c b/gcc/testsuite/gcc.dg/graphite/isl-ast-gen-if-1.c new file mode 100644 index 00000000000..867b84e8359 --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/isl-ast-gen-if-1.c @@ -0,0 +1,37 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fgraphite-identity -fgraphite-code-generator=isl" } */ + +int st = 1; +static void __attribute__((noinline)) +foo (int a[], int n) +{ + int i; + for (i = 0; i < n; i++) + { + if (i < 25) + a[i] = i; + a[n - i] = 1; + } +} + +static int __attribute__((noinline)) +array_sum (int a[]) +{ + int i, res = 0; + for(i = 0; i < 50; i += st) + res += a[i]; + return res; +} + +extern void abort (); + +int +main (void) +{ + int a[50]; + foo (a, 50); + int res = array_sum (a); + if (res != 49) + abort (); + return 0; +} -- 2.30.2