OSDN Git Service

2012-02-02 Vladimir Makarov <vmakarov@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / sese.c
index f5e41f5..492667e 100644 (file)
@@ -1,5 +1,5 @@
 /* Single entry single exit control flow regions.
-   Copyright (C) 2008, 2009, 2010
+   Copyright (C) 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
    Contributed by Jan Sjodin <jan.sjodin@amd.com> and
    Sebastian Pop <sebastian.pop@amd.com>.
@@ -23,25 +23,14 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
-#include "ggc.h"
-#include "tree.h"
-#include "rtl.h"
-#include "basic-block.h"
-#include "diagnostic.h"
 #include "tree-pretty-print.h"
 #include "tree-flow.h"
-#include "tree-dump.h"
-#include "timevar.h"
 #include "cfgloop.h"
 #include "tree-chrec.h"
 #include "tree-data-ref.h"
 #include "tree-scalar-evolution.h"
 #include "tree-pass.h"
-#include "domwalk.h"
 #include "value-prof.h"
-#include "pointer-set.h"
-#include "gimple.h"
 #include "sese.h"
 
 /* Print to stderr the element ELT.  */
@@ -460,8 +449,7 @@ set_rename (htab_t rename_map, tree old_name, tree expr)
   if (!slot)
     return;
 
-  if (*slot)
-    free (*slot);
+  free (*slot);
 
   *slot = new_rename_map_elt (old_name, expr);
 }
@@ -470,23 +458,28 @@ set_rename (htab_t rename_map, tree old_name, tree expr)
    substitution map RENAME_MAP, inserting the gimplification code at
    GSI_TGT, for the translation REGION, with the original copied
    statement in LOOP, and using the induction variable renaming map
-   IV_MAP.  */
+   IV_MAP.  Returns true when something has been renamed.  GLOOG_ERROR
+   is set when the code generation cannot continue.  */
 
-static void
+static bool
 rename_uses (gimple copy, htab_t rename_map, gimple_stmt_iterator *gsi_tgt,
-            sese region, loop_p loop, VEC (tree, heap) *iv_map)
+            sese region, loop_p loop, VEC (tree, heap) *iv_map,
+            bool *gloog_error)
 {
   use_operand_p use_p;
   ssa_op_iter op_iter;
+  bool changed = false;
 
   if (is_gimple_debug (copy))
     {
       if (gimple_debug_bind_p (copy))
        gimple_debug_bind_reset_value (copy);
+      else if (gimple_debug_source_bind_p (copy))
+       return false;
       else
        gcc_unreachable ();
 
-      return;
+      return false;
     }
 
   FOR_EACH_SSA_USE_OPERAND (use_p, copy, op_iter, SSA_OP_ALL_USES)
@@ -500,6 +493,7 @@ rename_uses (gimple copy, htab_t rename_map, gimple_stmt_iterator *gsi_tgt,
          || SSA_NAME_IS_DEFAULT_DEF (old_name))
        continue;
 
+      changed = true;
       new_expr = get_rename (rename_map, old_name);
       if (new_expr)
        {
@@ -530,46 +524,56 @@ rename_uses (gimple copy, htab_t rename_map, gimple_stmt_iterator *gsi_tgt,
         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.  */
-      gcc_assert (!chrec_contains_undetermined (scev));
-
-      new_expr = chrec_apply_map (scev, iv_map);
+      if (chrec_contains_undetermined (scev))
+       {
+         *gloog_error = true;
+         new_expr = build_zero_cst (TREE_TYPE (old_name));
+       }
+      else
+       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))
+       {
+         *gloog_error = true;
+         new_expr = build_zero_cst (TREE_TYPE (old_name));
+       }
+      else
+       /* Replace the old_name with the new_expr.  */
+       new_expr = force_gimple_operand (unshare_expr (new_expr), &stmts,
+                                        true, NULL_TREE);
 
-      /* Replace the old_name with the new_expr.  */
-      new_expr = force_gimple_operand (unshare_expr (new_expr), &stmts,
-                                      true, NULL_TREE);
       gsi_insert_seq_before (gsi_tgt, stmts, GSI_SAME_STMT);
       replace_exp (use_p, new_expr);
 
-
-      if (TREE_CODE (new_expr) == INTEGER_CST)
+      if (TREE_CODE (new_expr) == INTEGER_CST
+         && is_gimple_assign (copy))
        {
-         tree lhs = gimple_assign_lhs (copy);
          tree rhs = gimple_assign_rhs1 (copy);
 
-         if (TREE_CODE (lhs) == ADDR_EXPR)
-           recompute_tree_invariant_for_addr_expr (lhs);
          if (TREE_CODE (rhs) == ADDR_EXPR)
            recompute_tree_invariant_for_addr_expr (rhs);
        }
 
       set_rename (rename_map, old_name, new_expr);
     }
+
+  return changed;
 }
 
 /* Duplicates the statements of basic block BB into basic block NEW_BB
-   and compute the new induction variables according to the IV_MAP.  */
+   and compute the new induction variables according to the IV_MAP.
+   GLOOG_ERROR is set when the code generation cannot continue.  */
 
 static void
 graphite_copy_stmts_from_block (basic_block bb, basic_block new_bb,
                                htab_t rename_map,
-                               VEC (tree, heap) *iv_map, sese region)
+                               VEC (tree, heap) *iv_map, sese region,
+                               bool *gloog_error)
 {
   gimple_stmt_iterator gsi, gsi_tgt;
   loop_p loop = bb->loop_father;
@@ -614,7 +618,12 @@ graphite_copy_stmts_from_block (basic_block bb, basic_block new_bb,
          set_rename (rename_map, old_name, new_name);
        }
 
-      rename_uses (copy, rename_map, &gsi_tgt, region, loop, iv_map);
+      if (rename_uses (copy, rename_map, &gsi_tgt, region, loop, iv_map,
+                      gloog_error))
+       {
+         gcc_assert (gsi_stmt (gsi_tgt) == copy);
+         fold_stmt_inplace (&gsi_tgt);
+       }
 
       update_stmt (copy);
     }
@@ -622,18 +631,21 @@ graphite_copy_stmts_from_block (basic_block bb, basic_block new_bb,
 
 /* Copies BB and includes in the copied BB all the statements that can
    be reached following the use-def chains from the memory accesses,
-   and returns the next edge following this new block.  */
+   and returns the next edge following this new block.  GLOOG_ERROR is
+   set when the code generation cannot continue.  */
 
 edge
 copy_bb_and_scalar_dependences (basic_block bb, sese region,
-                               edge next_e, VEC (tree, heap) *iv_map)
+                               edge next_e, VEC (tree, heap) *iv_map,
+                               bool *gloog_error)
 {
   basic_block new_bb = split_edge (next_e);
   htab_t rename_map = htab_create (10, rename_map_elt_info,
                                   eq_rename_map_elts, free);
 
   next_e = single_succ_edge (new_bb);
-  graphite_copy_stmts_from_block (bb, new_bb, rename_map, iv_map, region);
+  graphite_copy_stmts_from_block (bb, new_bb, rename_map, iv_map, region,
+                                 gloog_error);
   remove_phi_nodes (new_bb);
   htab_delete (rename_map);
 
@@ -685,8 +697,7 @@ if_region_set_false_region (ifsese if_region, sese region)
 
   SESE_EXIT (region) = false_edge;
 
-  if (if_region->false_region)
-    free (if_region->false_region);
+  free (if_region->false_region);
   if_region->false_region = region;
 
   if (slot)
@@ -799,14 +810,16 @@ scalar_evolution_in_region (sese region, loop_p loop, tree t)
   struct loop *def_loop;
   basic_block before = block_before_sese (region);
 
+  /* SCOP parameters.  */
+  if (TREE_CODE (t) == SSA_NAME
+      && !defined_in_sese_p (t, region))
+    return t;
+
   if (TREE_CODE (t) != SSA_NAME
       || loop_in_sese_p (loop, region))
     return instantiate_scev (before, loop,
                             analyze_scalar_evolution (loop, t));
 
-  if (!defined_in_sese_p (t, region))
-    return t;
-
   def = SSA_NAME_DEF_STMT (t);
   def_loop = loop_containing_stmt (def);