time_profiler: Set proper type to time_profiler_counter_ptr.
[platform/upstream/gcc.git] / gcc / graphite-isl-ast-to-gimple.c
index 161b434..0eb564a 100644 (file)
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #ifdef HAVE_isl
 
+#define INCLUDE_MAP
 #include "system.h"
 #include "coretypes.h"
 #include "backend.h"
@@ -54,7 +55,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfganal.h"
 #include "value-prof.h"
 #include "graphite.h"
-#include <map>
 
 /* We always try to use signed 128 bit types, but fall back to smaller types
    in case a platform does not provide types of these sizes. In the future we
@@ -821,7 +821,8 @@ graphite_create_new_loop_guard (edge entry_edge,
   if (integer_onep (cond_expr))
     exit_edge = entry_edge;
   else
-    exit_edge = create_empty_if_region_on_edge (entry_edge, cond_expr);
+    exit_edge = create_empty_if_region_on_edge (entry_edge,
+                                               unshare_expr (cond_expr));
 
   return exit_edge;
 }
@@ -1074,9 +1075,7 @@ bb_contains_loop_close_phi_nodes (basic_block bb)
 static bool
 bb_contains_loop_phi_nodes (basic_block bb)
 {
-  gcc_assert (EDGE_COUNT (bb->preds) <= 2);
-
-  if (bb->preds->length () == 1)
+  if (EDGE_COUNT (bb->preds) != 2)
     return false;
 
   unsigned depth = loop_depth (bb->loop_father);
@@ -1306,6 +1305,18 @@ later_of_the_two (gimple_stmt_iterator gsi1, gimple_stmt_iterator gsi2)
   /* Find the iterator which is the latest.  */
   if (bb1 == bb2)
     {
+      gimple *stmt1 = gsi_stmt (gsi1);
+      gimple *stmt2 = gsi_stmt (gsi2);
+
+      if (stmt1 != NULL && stmt2 != NULL)
+       {
+         bool is_phi1 = gimple_code (stmt1) == GIMPLE_PHI;
+         bool is_phi2 = gimple_code (stmt2) == GIMPLE_PHI;
+
+         if (is_phi1 != is_phi2)
+           return is_phi1 ? gsi2 : gsi1;
+       }
+
       /* For empty basic blocks gsis point to the end of the sequence.  Since
         there is no operator== defined for gimple_stmt_iterator and for gsis
         not pointing to a valid statement gsi_next would assert.  */
@@ -1403,6 +1414,8 @@ gsi_insert_earliest (gimple_seq seq)
 void translate_isl_ast_to_gimple::
 collect_all_ssa_names (tree new_expr, vec<tree> *vec_ssa)
 {
+  if (new_expr == NULL_TREE)
+    return;
 
   /* Rename all uses in new_expr.  */
   if (TREE_CODE (new_expr) == SSA_NAME)
@@ -1483,7 +1496,7 @@ substitute_ssa_name (tree exp, tree f, tree r)
        if (exp == f)
          return r;
 
-       /* Fall through...  */
+       /* Fall through.  */
 
       case tcc_exceptional:
       case tcc_unary:
@@ -1587,17 +1600,28 @@ get_rename_from_scev (tree old_name, gimple_seq *stmts, loop_p loop,
   tree scev = scalar_evolution_in_region (region->region, loop, old_name);
 
   /* At this point we should know the exact scev for each
-     scalar SSA_NAME used in the scop.  */
-  gcc_assert (!chrec_contains_undetermined (scev));
+     scalar SSA_NAME used in the scop: all the other scalar
+     SSA_NAMEs should have been translated out of SSA using
+     arrays with one element.  */
+  tree new_expr;
+  if (chrec_contains_undetermined (scev))
+    {
+      codegen_error = true;
+      return build_zero_cst (TREE_TYPE (old_name));
+    }
 
-  tree new_expr = chrec_apply_map (scev, iv_map);
+  new_expr = chrec_apply_map (scev, iv_map);
 
   /* The apply should produce an expression tree containing
      the uses of the new induction variables.  We should be
      able to use new_expr instead of the old_name in the newly
      generated loop nest.  */
-  gcc_assert (!chrec_contains_undetermined (new_expr)
-             && !tree_contains_chrecs (new_expr, NULL));
+  if (chrec_contains_undetermined (new_expr)
+      || tree_contains_chrecs (new_expr, NULL))
+    {
+      codegen_error = true;
+      return build_zero_cst (TREE_TYPE (old_name));
+    }
 
   if (TREE_CODE (new_expr) == SSA_NAME)
     {
@@ -1778,7 +1802,6 @@ get_def_bb_for_const (basic_block bb, basic_block old_bb) const
        b1 = b2;
     }
 
-  gcc_assert (b1);
   return b1;
 }
 
@@ -1790,7 +1813,7 @@ get_new_name (basic_block new_bb, tree op,
              basic_block old_bb, phi_node_kind phi_kind) const
 {
   /* For constants the names are the same.  */
-  if (is_constant (op))
+  if (TREE_CODE (op) != SSA_NAME)
     return op;
 
   return get_rename (new_bb, op, old_bb, phi_kind);
@@ -2425,7 +2448,7 @@ copy_cond_phi_args (gphi *phi, gphi *new_phi, vec<tree> iv_map, bool postpone)
                  fprintf (dump_file, "\n");
                }
              gsi_insert_earliest (stmts);
-             new_phi_args [i] = new_name;
+             new_phi_args[i] = new_expr;
              continue;
            }
 
@@ -2467,13 +2490,14 @@ copy_cond_phi_nodes (basic_block bb, basic_block new_bb, vec<tree> iv_map)
 
   gcc_assert (!bb_contains_loop_close_phi_nodes (bb));
 
+  /* TODO: Handle cond phi nodes with more than 2 predecessors.  */
+  if (EDGE_COUNT (bb->preds) != 2)
+    return false;
+
   if (dump_file)
     fprintf (dump_file, "[codegen] copying cond phi nodes in bb_%d.\n",
             new_bb->index);
 
-  /* Cond phi nodes should have exactly two arguments.  */
-  gcc_assert (2 == EDGE_COUNT (bb->preds));
-
   for (gphi_iterator psi = gsi_start_phis (bb); !gsi_end_p (psi);
        gsi_next (&psi))
     {