OSDN Git Service

* config/m32r/m32r.h (LEGITIMATE_CONSTANT_P): Treat LABEL_REFs in
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-phiprop.c
index f408939..ff3ee4a 100644 (file)
@@ -95,7 +95,7 @@ along with GCC; see the file COPYING3.  If not see
 struct phiprop_d
 {
   tree value;
-  tree vop_stmt;
+  gimple vop_stmt;
 };
 
 /* Verify if the value recorded for NAME in PHIVN is still valid at
@@ -104,7 +104,7 @@ struct phiprop_d
 static bool
 phivn_valid_p (struct phiprop_d *phivn, tree name, basic_block bb)
 {
-  tree vop_stmt = phivn[SSA_NAME_VERSION (name)].vop_stmt;
+  gimple vop_stmt = phivn[SSA_NAME_VERSION (name)].vop_stmt;
   ssa_op_iter ui;
   tree vuse;
 
@@ -112,17 +112,17 @@ phivn_valid_p (struct phiprop_d *phivn, tree name, basic_block bb)
      by bb.  */
   FOR_EACH_SSA_TREE_OPERAND (vuse, vop_stmt, ui, SSA_OP_VUSE)
     {
-      tree use_stmt;
+      gimple use_stmt;
       imm_use_iterator ui2;
       bool ok = true;
 
       FOR_EACH_IMM_USE_STMT (use_stmt, ui2, vuse)
        {
          /* If BB does not dominate a VDEF, the value is invalid.  */
-         if (((TREE_CODE (use_stmt) == GIMPLE_MODIFY_STMT
+         if (((is_gimple_assign (use_stmt)
                && !ZERO_SSA_OPERANDS (use_stmt, SSA_OP_VDEF))
-              || TREE_CODE (use_stmt) == PHI_NODE)
-             && !dominated_by_p (CDI_DOMINATORS, bb_for_stmt (use_stmt), bb))
+              || gimple_code (use_stmt) == GIMPLE_PHI)
+             && !dominated_by_p (CDI_DOMINATORS, gimple_bb (use_stmt), bb))
            {
              ok = false;
              BREAK_FROM_IMM_USE_STMT (ui2);
@@ -139,31 +139,36 @@ phivn_valid_p (struct phiprop_d *phivn, tree name, basic_block bb)
    BB with the virtual operands from USE_STMT.  */
 
 static tree
-phiprop_insert_phi (basic_block bb, tree phi, tree use_stmt,
+phiprop_insert_phi (basic_block bb, gimple phi, gimple use_stmt,
                    struct phiprop_d *phivn, size_t n)
 {
-  tree res, new_phi;
+  tree res;
+  gimple new_phi;
   edge_iterator ei;
   edge e;
 
+  gcc_assert (is_gimple_assign (use_stmt)
+             && gimple_assign_rhs_code (use_stmt) == INDIRECT_REF);
+
   /* Build a new PHI node to replace the definition of
      the indirect reference lhs.  */
-  res = GIMPLE_STMT_OPERAND (use_stmt, 0);
+  res = gimple_assign_lhs (use_stmt);
   SSA_NAME_DEF_STMT (res) = new_phi = create_phi_node (res, bb);
 
   /* Add PHI arguments for each edge inserting loads of the
      addressable operands.  */
   FOR_EACH_EDGE (e, ei, bb->preds)
     {
-      tree old_arg, new_var, tmp;
+      tree old_arg, new_var;
+      gimple tmp;
 
       old_arg = PHI_ARG_DEF_FROM_EDGE (phi, e);
       while (TREE_CODE (old_arg) == SSA_NAME
             && (SSA_NAME_VERSION (old_arg) >= n
                 || phivn[SSA_NAME_VERSION (old_arg)].value == NULL_TREE))
        {
-         tree def_stmt = SSA_NAME_DEF_STMT (old_arg);
-         old_arg = GIMPLE_STMT_OPERAND (def_stmt, 1);
+         gimple def_stmt = SSA_NAME_DEF_STMT (old_arg);
+         old_arg = gimple_assign_rhs1 (def_stmt);
        }
 
       if (TREE_CODE (old_arg) == SSA_NAME)
@@ -171,18 +176,19 @@ phiprop_insert_phi (basic_block bb, tree phi, tree use_stmt,
        new_var = phivn[SSA_NAME_VERSION (old_arg)].value;
       else
        {
+         gcc_assert (TREE_CODE (old_arg) == ADDR_EXPR);
          old_arg = TREE_OPERAND (old_arg, 0);
          new_var = create_tmp_var (TREE_TYPE (old_arg), NULL);
-         tmp = build2 (GIMPLE_MODIFY_STMT, void_type_node,
-                       NULL_TREE, unshare_expr (old_arg));
+         tmp = gimple_build_assign (new_var, unshare_expr (old_arg));
          if (TREE_CODE (TREE_TYPE (old_arg)) == COMPLEX_TYPE
              || TREE_CODE (TREE_TYPE (old_arg)) == VECTOR_TYPE)
            DECL_GIMPLE_REG_P (new_var) = 1;
+         gcc_assert (is_gimple_reg (new_var));
          add_referenced_var (new_var);
          new_var = make_ssa_name (new_var, tmp);
-         GIMPLE_STMT_OPERAND (tmp, 0) = new_var;
+         gimple_assign_set_lhs (tmp, new_var);
 
-         bsi_insert_on_edge (e, tmp);
+         gsi_insert_on_edge (e, tmp);
 
          update_stmt (tmp);
          mark_symbols_for_renaming (tmp);
@@ -211,11 +217,13 @@ phiprop_insert_phi (basic_block bb, tree phi, tree use_stmt,
    with aliasing issues as we are moving memory reads.  */
 
 static bool
-propagate_with_phi (basic_block bb, tree phi, struct phiprop_d *phivn, size_t n)
+propagate_with_phi (basic_block bb, gimple phi, struct phiprop_d *phivn,
+                   size_t n)
 {
   tree ptr = PHI_RESULT (phi);
-  tree use_stmt, res = NULL_TREE;
-  block_stmt_iterator bsi;
+  gimple use_stmt;
+  tree res = NULL_TREE;
+  gimple_stmt_iterator gsi;
   imm_use_iterator ui;
   use_operand_p arg_p, use;
   ssa_op_iter i;
@@ -238,10 +246,10 @@ propagate_with_phi (basic_block bb, tree phi, struct phiprop_d *phivn, size_t n)
             && (SSA_NAME_VERSION (arg) >= n
                 || phivn[SSA_NAME_VERSION (arg)].value == NULL_TREE))
        {
-         tree def_stmt = SSA_NAME_DEF_STMT (arg);
-         if (TREE_CODE (def_stmt) != GIMPLE_MODIFY_STMT)
+         gimple def_stmt = SSA_NAME_DEF_STMT (arg);
+         if (gimple_code (def_stmt) != GIMPLE_ASSIGN)
            return false;
-         arg = GIMPLE_STMT_OPERAND (def_stmt, 1);
+         arg = gimple_assign_rhs1 (def_stmt);
        }
       if ((TREE_CODE (arg) != ADDR_EXPR
           /* Avoid to have to decay *&a to a[0] later.  */
@@ -255,10 +263,8 @@ propagate_with_phi (basic_block bb, tree phi, struct phiprop_d *phivn, size_t n)
   /* Find a dereferencing use.  First follow (single use) ssa
      copy chains for ptr.  */
   while (single_imm_use (ptr, &use, &use_stmt)
-        && TREE_CODE (use_stmt) == GIMPLE_MODIFY_STMT
-        && GIMPLE_STMT_OPERAND (use_stmt, 1) == ptr
-        && TREE_CODE (GIMPLE_STMT_OPERAND (use_stmt, 0)) == SSA_NAME)
-    ptr = GIMPLE_STMT_OPERAND (use_stmt, 0);
+        && gimple_assign_ssa_name_copy_p (use_stmt))
+    ptr = gimple_assign_lhs (use_stmt);
 
   /* Replace the first dereference of *ptr if there is one and if we
      can move the loads to the place of the ptr phi node.  */
@@ -269,23 +275,23 @@ propagate_with_phi (basic_block bb, tree phi, struct phiprop_d *phivn, size_t n)
       tree vuse;
 
       /* Check whether this is a load of *ptr.  */
-      if (!(TREE_CODE (use_stmt) == GIMPLE_MODIFY_STMT
-           && TREE_CODE (GIMPLE_STMT_OPERAND (use_stmt, 0)) == SSA_NAME 
-           && TREE_CODE (GIMPLE_STMT_OPERAND (use_stmt, 1)) == INDIRECT_REF
-           && TREE_OPERAND (GIMPLE_STMT_OPERAND (use_stmt, 1), 0) == ptr
+      if (!(is_gimple_assign (use_stmt)
+           && TREE_CODE (gimple_assign_lhs (use_stmt)) == SSA_NAME 
+           && gimple_assign_rhs_code (use_stmt) == INDIRECT_REF
+           && TREE_OPERAND (gimple_assign_rhs1 (use_stmt), 0) == ptr
            /* We cannot replace a load that may throw or is volatile.  */
-           && !tree_can_throw_internal (use_stmt)))
+           && !stmt_can_throw_internal (use_stmt)))
        continue;
 
       /* Check if we can move the loads.  The def stmts of all virtual uses
         need to be post-dominated by bb.  */
       FOR_EACH_SSA_TREE_OPERAND (vuse, use_stmt, ui2, SSA_OP_VUSE)
        {
-         tree def_stmt = SSA_NAME_DEF_STMT (vuse);
+         gimple def_stmt = SSA_NAME_DEF_STMT (vuse);
          if (!SSA_NAME_IS_DEFAULT_DEF (vuse)
-             && (bb_for_stmt (def_stmt) == bb
+             && (gimple_bb (def_stmt) == bb
                  || !dominated_by_p (CDI_DOMINATORS,
-                                     bb, bb_for_stmt (def_stmt))))
+                                     bb, gimple_bb (def_stmt))))
            goto next;
        }
 
@@ -302,8 +308,8 @@ propagate_with_phi (basic_block bb, tree phi, struct phiprop_d *phivn, size_t n)
          /* Remove old stmt.  The phi is taken care of by DCE, if we
             want to delete it here we also have to delete all intermediate
             copies.  */
-         bsi = bsi_for_stmt (use_stmt);
-         bsi_remove (&bsi, 0);
+         gsi = gsi_for_stmt (use_stmt);
+         gsi_remove (&gsi, false);
 
          phi_inserted = true;
        }
@@ -311,7 +317,7 @@ propagate_with_phi (basic_block bb, tree phi, struct phiprop_d *phivn, size_t n)
        {
          /* Further replacements are easy, just make a copy out of the
             load.  */
-         GIMPLE_STMT_OPERAND (use_stmt, 1) = res;
+         gimple_assign_set_rhs1 (use_stmt, res);
          update_stmt (use_stmt);
        }
 
@@ -330,10 +336,10 @@ tree_ssa_phiprop_1 (basic_block bb, struct phiprop_d *phivn, size_t n)
 {
   bool did_something = false; 
   basic_block son;
-  tree phi;
+  gimple_stmt_iterator gsi;
 
-  for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
-    did_something |= propagate_with_phi (bb, phi, phivn, n);
+  for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+    did_something |= propagate_with_phi (bb, gsi_stmt (gsi), phivn, n);
 
   for (son = first_dom_son (CDI_DOMINATORS, bb);
        son;
@@ -355,7 +361,7 @@ tree_ssa_phiprop (void)
   phivn = XCNEWVEC (struct phiprop_d, num_ssa_names);
 
   if (tree_ssa_phiprop_1 (ENTRY_BLOCK_PTR, phivn, num_ssa_names))
-    bsi_commit_edge_inserts ();
+    gsi_commit_edge_inserts ();
 
   free (phivn);