Patchwork [GSoC] generation of Gimple code from isl_ast_node_user

login
register
mail settings
Submitter Roman Gareev
Date July 18, 2014, 10:28 a.m.
Message ID <CABGF_gd-5+o7q4yCsYFXNdLovtpew9aFEy8T9H1T49pqomo4fw@mail.gmail.com>
Download mbox | patch
Permalink /patch/371441/
State New
Headers show

Comments

Roman Gareev - July 18, 2014, 10:28 a.m.
> Can you explain why all functions would need to be rewritten? I proposed
> this function as an easier way to NULL initialize the vector and did not
> expect any rewrite to be necessary.
>
> If there is no such thing, please just add a comment that your loop NULL
> initializes the vector. We can later improve this.

Sorry, I, probably, mixed something up. This function was used in the
attached patch without rewriting of other functions.

--
                                   Cheers, Roman Gareev.
2014-07-12  Roman Gareev  <gareevroman@gmail.com>

	gcc/
	* graphite-isl-ast-to-gimple.c:
	Add inclusion of gimple-ssa.h, tree-into-ssa.h.
	(ivs_params_clear):
	(build_iv_mapping): New function.
	(translate_isl_ast_node_user): Likewise.
	(translate_isl_ast): Add calling of translate_isl_ast_node_user.

	gcc/testsuite/gcc.dg/graphite/
	* isl-ast-gen-single-loop-1.c: New testcase.
	* isl-ast-gen-single-loop-2.c: New testcase.
	* isl-ast-gen-single-loop-3.c: New testcase.
Tobias Grosser - July 18, 2014, 10:31 a.m.
One last question:

On 18/07/2014 12:28, Roman Gareev wrote:
> +  iv_map.create (loop->num + 1);
> +  iv_map.safe_grow_cleared (loop->num + 1);

One of these two seems redundant.

Cheers,
Tobias
Roman Gareev - July 18, 2014, 1:35 p.m.
> One of these two seems redundant.

I get the following error without “iv_map.create (loop->num + 1);”:

"/home/roman/sec_trunk/gcc/gcc/vec.h:1184:39: error: ‘iv_map’ may be
used uninitialized in this function [-Werror=maybe-uninitialized] {
return m_vec ? m_vec->length () : 0; }"

>Can you explain why all functions would need to be rewritten? I proposed this function as an easier way to NULL initialize the vector and did not expect any rewrite to be necessary.

When I'm trying to pass iv_map to vec_safe_grow_cleared I get the
following error:

"/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:596:47:
note:   mismatched types ‘vec<T, A, vl_embed>*’ and ‘vec<tree_node*>’
vec_safe_grow_cleared (iv_map, loop->num + 1);"

In case of passing of iv_map*, I get the following error:

"/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:596:47:
error: no matching function for call to
‘vec_safe_grow_cleared(vec<tree_node*>*&, int)’
   vec_safe_grow_cleared (iv_map, loop->num + 1);
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:596:47:
note: candidate is:
In file included from /home/roman/sec_trunk/gcc/gcc/tree-core.h:27:0,
                 from /home/roman/sec_trunk/gcc/gcc/tree.h:23,
                 from
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:39:
/home/roman/sec_trunk/gcc/gcc/vec.h:627:1: note: template<class T,
class A> void vec_safe_grow_cleared(vec<T, A, vl_embed>*&, unsigned
int)
 vec_safe_grow_cleared (vec<T, A, vl_embed> *&v, unsigned len CXX_MEM_STAT_INFO)
/home/roman/sec_trunk/gcc/gcc/vec.h:627:1: note:   template argument
deduction/substitution failed:
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:596:47:
note:   mismatched types ‘vl_embed’ and ‘vl_ptr’
   vec_safe_grow_cleared (iv_map, loop->num + 1);
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:596:47:
note:   ‘vec<tree_node*>’ is not derived from ‘vec<T, A, vl_embed>’"

If we use vec<T, A, vl_embed> as a type for iv_map, we'll have to
rewrite declarations of the following functions, which are working
with vec<tree_node*>:copy_bb_and_scalar_dependences,
graphite_copy_stmts_from_block, rename_uses, chrec_apply_map. We'll
also have to rewrite declarations of iv_map in
graphite-clast-to-gimple.c in this case.

Please correct me, if I am wrong.

--
                                   Cheers, Roman Gareev.
Roman Gareev - July 21, 2014, 8:25 a.m.
Maybe we should  temporary postpone this and add a FIXME that says:

“We should remove iv_map.create (loop->num + 1), if it is possible.”

What do you think about this?

--
                                   Cheers, Roman Gareev.
Tobias Grosser - July 21, 2014, 8:57 a.m.
On 21/07/2014 10:25, Roman Gareev wrote:
> Maybe we should  temporary postpone this and add a FIXME that says:
>
> “We should remove iv_map.create (loop->num + 1), if it is possible.”
>
> What do you think about this?

Fine with me. Please post a question on gcc devel to see if someone can 
explain us the vec.h implementation.

Cheers,
Tobias

Patch

Index: gcc/graphite-isl-ast-to-gimple.c
===================================================================
--- gcc/graphite-isl-ast-to-gimple.c	(revision 212807)
+++ gcc/graphite-isl-ast-to-gimple.c	(working copy)
@@ -51,6 +51,8 @@ 
 #include "sese.h"
 #include "tree-ssa-loop-manip.h"
 #include "tree-scalar-evolution.h"
+#include "gimple-ssa.h"
+#include "tree-into-ssa.h"
 #include <map>
 
 #ifdef HAVE_cloog
@@ -541,6 +543,70 @@ 
   return last_e;
 }
 
+/* Inserts in iv_map a tuple (OLD_LOOP->num, NEW_NAME) for the induction
+   variables of the loops around GBB in SESE.
+ 
+   FIXME: Instead of using a vec<tree> that maps each loop id to a possible
+   chrec, we could consider using a map<int, tree> that maps loop ids to the
+   corresponding tree expressions.  */
+
+static void
+build_iv_mapping (vec<tree> iv_map, gimple_bb_p gbb,
+		  __isl_keep isl_ast_expr *user_expr, ivs_params &ip,
+		  sese region)
+{
+  gcc_assert (isl_ast_expr_get_type (user_expr) == isl_ast_expr_op &&
+              isl_ast_expr_get_op_type (user_expr) == isl_ast_op_call);
+  int i;
+  isl_ast_expr *arg_expr;
+  for (i = 1; i < isl_ast_expr_get_op_n_arg (user_expr); i++)
+    {
+      arg_expr = isl_ast_expr_get_op_arg (user_expr, i);
+      tree type = *graphite_expression_size_type;
+      tree t = gcc_expression_from_isl_expression (type, arg_expr, ip);
+      loop_p old_loop = gbb_loop_at_index (gbb, region, i - 1);
+      iv_map[old_loop->num] = t;
+    }
+
+}
+
+/* Translates an isl_ast_node_user to Gimple. */
+
+static edge
+translate_isl_ast_node_user (__isl_keep isl_ast_node *node,
+			     edge next_e, ivs_params &ip)
+{
+  gcc_assert (isl_ast_node_get_type (node) == isl_ast_node_user);
+  isl_ast_expr *user_expr = isl_ast_node_user_get_expr (node);
+  isl_ast_expr *name_expr = isl_ast_expr_get_op_arg (user_expr, 0);
+  gcc_assert (isl_ast_expr_get_type (name_expr) == isl_ast_expr_id);
+  isl_id *name_id = isl_ast_expr_get_id (name_expr);
+  poly_bb_p pbb = (poly_bb_p) isl_id_get_user (name_id);
+  gcc_assert (pbb);
+  gimple_bb_p gbb = PBB_BLACK_BOX (pbb);
+  vec<tree> iv_map;
+  isl_ast_expr_free (name_expr);
+  isl_id_free (name_id);
+
+  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);
+
+  build_iv_mapping (iv_map, gbb, user_expr, ip, SCOP_REGION (pbb->scop));
+  isl_ast_expr_free (user_expr);
+  next_e = copy_bb_and_scalar_dependences (GBB_BB (gbb),
+					   SCOP_REGION (pbb->scop), next_e,
+					   iv_map,
+					   &graphite_regenerate_error);
+  iv_map.release ();
+  mark_virtual_operands_for_renaming (cfun);
+  update_ssa (TODO_update_ssa);
+  return next_e;
+}
+
 /* Translates an ISL AST node NODE to GCC representation in the
    context of a SESE.  */
 
@@ -561,7 +627,7 @@ 
       return next_e;
 
     case isl_ast_node_user:
-      return next_e;
+      return translate_isl_ast_node_user (node, next_e, ip);
 
     case isl_ast_node_block:
       return next_e;
Index: gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-1.c
===================================================================
--- gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-1.c	(revision 0)
+++ gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-1.c	(working copy)
@@ -0,0 +1,28 @@ 
+/* { dg-do run } */
+/* { dg-options "-O2 -fgraphite-identity -fgraphite-code-generator=isl" } */
+
+int n = 25;
+
+int
+foo ()
+{
+  int i, res;
+
+  for (i = n, res = 0; i < 50; i++)
+      res += i;
+
+  return res;
+}
+
+extern void abort ();
+
+int
+main (void)
+{ 
+  int res = foo ();
+
+  if (res != 1225)
+    abort ();
+
+  return 0;
+}
Index: gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-2.c
===================================================================
--- gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-2.c	(revision 0)
+++ gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-2.c	(working copy)
@@ -0,0 +1,34 @@ 
+/* { dg-do run } */
+/* { dg-options "-O2 -fgraphite-identity -fgraphite-code-generator=isl" } */
+int n = 50;
+
+void
+foo (int a[])
+{
+  int i;
+  for (i = n - 20; i < 50; i++)
+    a[i] = i;
+}
+
+int
+array_sum (int a[])
+{
+  int i;
+  int res = 0;
+  for(i = n - 20; i < n; i *= 2)
+    res += a[i];
+  return res;
+}
+
+extern void abort ();
+
+int
+main (void)
+{
+  int a[50];
+  foo (a);
+  int res = array_sum (a);
+  if (res != 30)
+    abort ();
+  return 0;
+}
Index: gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-3.c
===================================================================
--- gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-3.c	(revision 0)
+++ gcc/testsuite/gcc.dg/graphite/isl-ast-gen-single-loop-3.c	(working copy)
@@ -0,0 +1,34 @@ 
+/* { dg-do run } */
+/* { dg-options "-O2 -fgraphite-identity -fgraphite-code-generator=isl" } */
+int n = 50;
+
+void
+foo (int a[])
+{
+  int i;
+  for (i = 0; i < n; i++)
+    a[i] = i;
+}
+
+int
+array_sum (int a[])
+{
+  int i;
+  int res = 0;
+  for(i = 1; i < n; i *= 2)
+    res += a[i];
+  return res;
+}
+
+extern void abort ();
+
+int
+main (void)
+{
+  int a[50];
+  foo (a);
+  int res = array_sum (a);
+  if (res != 63)
+    abort ();
+  return 0;
+}