OSDN Git Service

Use ssizetype when long_long_integer_type_node is NULL.
[pf3gnuchains/gcc-fork.git] / gcc / graphite-clast-to-gimple.c
index bbc77d2..f99a158 100644 (file)
@@ -52,6 +52,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "graphite-clast-to-gimple.h"
 #include "graphite-dependences.h"
 
+/* This flag is set when an error occurred during the translation of
+   CLAST to Gimple.  */
+static bool gloog_error;
+
 /* Verifies properties that GRAPHITE should maintain during translation.  */
 
 static inline void
@@ -278,14 +282,24 @@ clast_to_gcc_expression (tree type, struct clast_expr *e,
              {
                tree name = clast_name_to_gcc (t->var, region, newivs,
                                               newivs_index, params_index);
-               return fold_convert (type, name);
+
+               if (POINTER_TYPE_P (TREE_TYPE (name)) != POINTER_TYPE_P (type))
+                 name = fold_convert (sizetype, name);
+
+               name = fold_convert (type, name);
+               return name;
              }
 
            else if (value_mone_p (t->val))
              {
                tree name = clast_name_to_gcc (t->var, region, newivs,
                                               newivs_index, params_index);
+
+               if (POINTER_TYPE_P (TREE_TYPE (name)) != POINTER_TYPE_P (type))
+                 name = fold_convert (sizetype, name);
+
                name = fold_convert (type, name);
+
                return fold_build1 (NEGATE_EXPR, type, name);
              }
            else
@@ -293,8 +307,17 @@ clast_to_gcc_expression (tree type, struct clast_expr *e,
                tree name = clast_name_to_gcc (t->var, region, newivs,
                                               newivs_index, params_index);
                tree cst = gmp_cst_to_tree (type, t->val);
+
+               if (POINTER_TYPE_P (TREE_TYPE (name)) != POINTER_TYPE_P (type))
+                 name = fold_convert (sizetype, name);
+
                name = fold_convert (type, name);
-               return fold_build2 (MULT_EXPR, type, cst, name);
+
+               if (!POINTER_TYPE_P (type))
+                 return fold_build2 (MULT_EXPR, type, cst, name);
+
+               gloog_error = true;
+               return cst;
              }
          }
        else
@@ -524,9 +547,19 @@ clast_get_body_of_loop (struct clast_stmt *stmt)
   gcc_unreachable ();
 }
 
-/* Given a CLOOG_IV, returns the type that it should have in GCC land.
-   If the information is not available, i.e. in the case one of the
-   transforms created the loop, just return integer_type_node.  */
+/* Java does not initialize long_long_integer_type_node.  */
+#define my_long_long (long_long_integer_type_node ? long_long_integer_type_node : ssizetype)
+
+/* Given a CLOOG_IV, return the type that CLOOG_IV should have in GCC
+   land.  The selected type is big enough to include the original loop
+   iteration variable, but signed to work with the subtractions CLooG
+   may have introduced.  If such a type is not available, we fail.
+
+   TODO: Do not always return long_long, but the smallest possible
+   type, that still holds the original type.
+
+   TODO: Get the types using CLooG instead.  This enables further
+   optimizations, but needs CLooG support.  */
 
 static tree
 gcc_type_for_cloog_iv (const char *cloog_iv, gimple_bb_p gbb)
@@ -538,11 +571,44 @@ gcc_type_for_cloog_iv (const char *cloog_iv, gimple_bb_p gbb)
   slot = htab_find_slot (GBB_CLOOG_IV_TYPES (gbb), &tmp, NO_INSERT);
 
   if (slot && *slot)
-    return ((ivtype_map_elt) *slot)->type;
+    {
+      tree type = ((ivtype_map_elt) *slot)->type;
+      int type_precision = TYPE_PRECISION (type);
+
+      /* Find the smallest signed type possible.  */
+      if (!TYPE_UNSIGNED (type))
+       {
+         if (type_precision <= TYPE_PRECISION (integer_type_node))
+           return integer_type_node;
+
+         if (type_precision <= TYPE_PRECISION (long_integer_type_node))
+           return long_integer_type_node;
+
+         if (type_precision <= TYPE_PRECISION (my_long_long))
+           return my_long_long;
+
+         gcc_unreachable ();
+       }
+
+      if (type_precision < TYPE_PRECISION (integer_type_node))
+       return integer_type_node;
 
-  return integer_type_node;
+      if (type_precision < TYPE_PRECISION (long_integer_type_node))
+       return long_integer_type_node;
+
+      if (type_precision < TYPE_PRECISION (my_long_long))
+       return my_long_long;
+
+      /* There is no signed type available, that is large enough to hold the
+        original value.  */
+      gcc_unreachable ();
+    }
+
+  return my_long_long;
 }
 
+#undef my_long_long
+
 /* Returns the induction variable for the loop that gets translated to
    STMT.  */
 
@@ -762,9 +828,6 @@ translate_clast_user (sese region, struct clast_user_stmt *stmt, edge next_e,
   return next_e;
 }
 
-static tree gcc_type_for_iv_of_clast_loop (struct clast_for *);
-
-
 /* Creates a new if region protecting the loop to be executed, if the execution
    count is zero (lb > ub).  */
 static edge
@@ -989,34 +1052,30 @@ static const char *
 find_cloog_iv_in_expr (struct clast_expr *expr)
 {
   struct clast_term *term = (struct clast_term *) expr;
-
-  if (expr->type == expr_term
-      && !term->var)
-    return NULL;
+  struct clast_reduction *red;
+  int i;
 
   if (expr->type == expr_term)
     return term->var;
 
-  if (expr->type == expr_red)
-    {
-      int i;
-      struct clast_reduction *red = (struct clast_reduction *) expr;
+  if (expr->type != expr_red)
+    return NULL;
 
-      for (i = 0; i < red->n; i++)
-       {
-         const char *res = find_cloog_iv_in_expr ((red)->elts[i]);
+  red = (struct clast_reduction *) expr;
+  for (i = 0; i < red->n; i++)
+    {
+      const char *res = find_cloog_iv_in_expr (red->elts[i]);
 
-         if (res)
-           return res;
-       }
+      if (res)
+       return res;
     }
 
   return NULL;
 }
 
-/* Build for a clast_user_stmt USER_STMT a map between the CLAST
-   induction variables and the corresponding GCC old induction
-   variables.  This information is stored on each GRAPHITE_BB.  */
+/* Build for USER_STMT a map between the CLAST induction variables and
+   the corresponding GCC old induction variables.  This information is
+   stored on each GRAPHITE_BB.  */
 
 static void
 compute_cloog_iv_types_1 (poly_bb_p pbb, struct clast_user_stmt *user_stmt)
@@ -1042,7 +1101,7 @@ compute_cloog_iv_types_1 (poly_bb_p pbb, struct clast_user_stmt *user_stmt)
       if (slot && !*slot)
        {
          tree oldiv = pbb_to_depth_to_oldiv (pbb, index);
-         tree type = oldiv ? TREE_TYPE (oldiv) : integer_type_node;
+         tree type = TREE_TYPE (oldiv);
          *slot = new_ivtype_map_elt (tmp.cloog_iv, type);
        }
     }
@@ -1400,8 +1459,8 @@ debug_generated_program (scop_p scop)
   print_generated_program (stderr, scop);
 }
 
-/* Add CLooG names to parameter index.  The index is used to translate back from
* CLooG names to GCC trees.  */
+/* Add CLooG names to parameter index.  The index is used to translate
  back from CLooG names to GCC trees.  */
 
 static void
 create_params_index (htab_t index_table, CloogProgram *prog) {
@@ -1420,17 +1479,18 @@ create_params_index (htab_t index_table, CloogProgram *prog) {
 */
 
 bool
-gloog (scop_p scop, htab_t bb_pbb_mapping)
+gloog (scop_p scop, VEC (scop_p, heap) *scops, htab_t bb_pbb_mapping)
 {
-  edge new_scop_exit_edge = NULL;
   VEC (tree, heap) *newivs = VEC_alloc (tree, heap, 10);
   loop_p context_loop;
   sese region = SCOP_REGION (scop);
   ifsese if_region = NULL;
   htab_t rename_map, newivs_index, params_index;
   cloog_prog_clast pc;
+  int i;
 
   timevar_push (TV_GRAPHITE_CODE_GEN);
+  gloog_error = false;
 
   pc = scop_to_clast (scop);
 
@@ -1462,18 +1522,27 @@ gloog (scop_p scop, htab_t bb_pbb_mapping)
 
   create_params_index (params_index, pc.prog);
 
-  new_scop_exit_edge = translate_clast (region, context_loop, pc.stmt,
-                                       if_region->true_region->entry,
-                                       rename_map, &newivs, newivs_index,
-                                       bb_pbb_mapping, 1, params_index);
+  translate_clast (region, context_loop, pc.stmt,
+                  if_region->true_region->entry,
+                  rename_map, &newivs, newivs_index,
+                  bb_pbb_mapping, 1, params_index);
   graphite_verify ();
   sese_adjust_liveout_phis (region, rename_map,
                            if_region->region->exit->src,
                            if_region->false_region->exit,
                            if_region->true_region->exit);
+  scev_reset_htab ();
+  rename_nb_iterations (rename_map);
+
+  for (i = 0; VEC_iterate (scop_p, scops, i, scop); i++)
+    rename_sese_parameters (rename_map, SCOP_REGION (scop));
+
   recompute_all_dominators ();
   graphite_verify ();
 
+  if (gloog_error)
+    set_ifsese_condition (if_region, integer_zero_node);
+
   free (if_region->true_region);
   free (if_region->region);
   free (if_region);
@@ -1500,7 +1569,7 @@ gloog (scop_p scop, htab_t bb_pbb_mapping)
               num_no_dependency);
     }
 
-  return true;
+  return !gloog_error;
 }
 
 #endif