OSDN Git Service

Revert my previous commit.
[pf3gnuchains/gcc-fork.git] / gcc / tree-complex.c
index d37a82e..10fa0ae 100644 (file)
@@ -1,11 +1,11 @@
 /* Lower complex number operations to scalar operations.
-   Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
 This file is part of GCC.
    
 GCC is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the
-Free Software Foundation; either version 2, or (at your option) any
+Free Software Foundation; either version 3, or (at your option) any
 later version.
    
 GCC is distributed in the hope that it will be useful, but WITHOUT
@@ -14,9 +14,8 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
    
 You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA.  */
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
 #include "system.h"
@@ -97,6 +96,8 @@ some_nonzerop (tree t)
 
   if (TREE_CODE (t) == REAL_CST)
     zerop = REAL_VALUES_IDENTICAL (TREE_REAL_CST (t), dconst0);
+  else if (TREE_CODE (t) == FIXED_CST)
+    zerop = fixed_zerop (t);
   else if (TREE_CODE (t) == INTEGER_CST)
     zerop = integer_zerop (t);
 
@@ -160,15 +161,14 @@ is_complex_reg (tree lhs)
 static void
 init_parameter_lattice_values (void)
 {
-  tree parm;
+  tree parm, ssa_name;
 
   for (parm = DECL_ARGUMENTS (cfun->decl); parm ; parm = TREE_CHAIN (parm))
-    if (is_complex_reg (parm) && var_ann (parm) != NULL)
-      {
-       tree ssa_name = default_def (parm);
-       VEC_replace (complex_lattice_t, complex_lattice_values,
-                    SSA_NAME_VERSION (ssa_name), VARYING);
-      }
+    if (is_complex_reg (parm)
+       && var_ann (parm) != NULL
+       && (ssa_name = gimple_default_def (cfun, parm)) != NULL_TREE)
+      VEC_replace (complex_lattice_t, complex_lattice_values,
+                  SSA_NAME_VERSION (ssa_name), VARYING);
 }
 
 /* Initialize DONT_SIMULATE_AGAIN for each stmt and phi.  Return false if
@@ -206,13 +206,13 @@ init_dont_simulate_again (void)
                 since it's never used as an input to another computation.  */
              dsa = true;
              stmt = TREE_OPERAND (stmt, 0);
-             if (!stmt || TREE_CODE (stmt) != MODIFY_EXPR)
+             if (!stmt || TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
                break;
              /* FALLTHRU */
 
-           case MODIFY_EXPR:
-             dsa = !is_complex_reg (TREE_OPERAND (stmt, 0));
-             rhs = TREE_OPERAND (stmt, 1);
+           case GIMPLE_MODIFY_STMT:
+             dsa = !is_complex_reg (GIMPLE_STMT_OPERAND (stmt, 0));
+             rhs = GIMPLE_STMT_OPERAND (stmt, 1);
              break;
 
            case COND_EXPR:
@@ -245,6 +245,17 @@ init_dont_simulate_again (void)
                  saw_a_complex_op = true;
                break;
 
+             case REALPART_EXPR:
+             case IMAGPART_EXPR:
+               /* The total store transformation performed during
+                  gimplification creates such uninitialized loads
+                  and we need to lower the statement to be able
+                  to fix things up.  */
+               if (TREE_CODE (TREE_OPERAND (rhs, 0)) == SSA_NAME
+                   && ssa_undefined_value_p (TREE_OPERAND (rhs, 0)))
+                 saw_a_complex_op = true;
+               break;
+
              default:
                break;
              }
@@ -267,11 +278,11 @@ complex_visit_stmt (tree stmt, edge *taken_edge_p ATTRIBUTE_UNUSED,
   unsigned int ver;
   tree lhs, rhs;
 
-  if (TREE_CODE (stmt) != MODIFY_EXPR)
+  if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
     return SSA_PROP_VARYING;
 
-  lhs = TREE_OPERAND (stmt, 0);
-  rhs = TREE_OPERAND (stmt, 1);
+  lhs = GIMPLE_STMT_OPERAND (stmt, 0);
+  rhs = GIMPLE_STMT_OPERAND (stmt, 1);
 
   /* These conditions should be satisfied due to the initial filter
      set up in init_dont_simulate_again.  */
@@ -387,7 +398,7 @@ create_one_component_var (tree type, tree orig, const char *prefix,
                          const char *suffix, enum tree_code code)
 {
   tree r = create_tmp_var (type, prefix);
-  add_referenced_tmp_var (r);
+  add_referenced_var (r);
 
   DECL_SOURCE_LOCATION (r) = DECL_SOURCE_LOCATION (orig);
   DECL_ARTIFICIAL (r) = 1;
@@ -532,7 +543,7 @@ set_component_ssa_name (tree ssa_name, bool imag_p, tree value)
   
   /* Do all the work to assign VALUE to COMP.  */
   value = force_gimple_operand (value, &list, false, NULL);
-  last = build2 (MODIFY_EXPR, TREE_TYPE (comp), comp, value);
+  last = build_gimple_modify_stmt (comp, value);
   append_to_statement_list (last, &list);
 
   gcc_assert (SSA_NAME_DEF_STMT (comp) == NULL);
@@ -588,7 +599,7 @@ extract_component (block_stmt_iterator *bsi, tree t, bool imagpart_p,
 static void
 update_complex_components (block_stmt_iterator *bsi, tree stmt, tree r, tree i)
 {
-  tree lhs = TREE_OPERAND (stmt, 0);
+  tree lhs = GIMPLE_STMT_OPERAND (stmt, 0);
   tree list;
 
   list = set_component_ssa_name (lhs, false, r);
@@ -625,11 +636,11 @@ update_complex_assignment (block_stmt_iterator *bsi, tree r, tree i)
   mod = stmt = bsi_stmt (*bsi);
   if (TREE_CODE (stmt) == RETURN_EXPR)
     mod = TREE_OPERAND (mod, 0);
-  else if (in_ssa_p)
+  else if (gimple_in_ssa_p (cfun))
     update_complex_components (bsi, stmt, r, i);
   
-  type = TREE_TYPE (TREE_OPERAND (mod, 1));
-  TREE_OPERAND (mod, 1) = build2 (COMPLEX_EXPR, type, r, i);
+  type = TREE_TYPE (GIMPLE_STMT_OPERAND (mod, 1));
+  GIMPLE_STMT_OPERAND (mod, 1) = build2 (COMPLEX_EXPR, type, r, i);
   update_stmt (stmt);
 }
 
@@ -651,7 +662,9 @@ update_parameter_components (void)
        continue;
 
       type = TREE_TYPE (type);
-      ssa_name = default_def (parm);
+      ssa_name = gimple_default_def (cfun, parm);
+      if (!ssa_name)
+       continue;
 
       r = build1 (REALPART_EXPR, type, ssa_name);
       i = build1 (IMAGPART_EXPR, type, ssa_name);
@@ -749,7 +762,8 @@ expand_complex_move (block_stmt_iterator *bsi, tree stmt, tree type,
          i = build1 (IMAGPART_EXPR, inner_type, lhs);
          update_complex_components_on_edge (e, lhs, r, i);
        }
-      else if (TREE_CODE (rhs) == CALL_EXPR || TREE_SIDE_EFFECTS (rhs))
+      else if (TREE_CODE (rhs) == CALL_EXPR || TREE_SIDE_EFFECTS (rhs)
+              || TREE_CODE (rhs) == PAREN_EXPR)
        {
          r = build1 (REALPART_EXPR, inner_type, lhs);
          i = build1 (IMAGPART_EXPR, inner_type, lhs);
@@ -771,25 +785,24 @@ expand_complex_move (block_stmt_iterator *bsi, tree stmt, tree type,
       i = extract_component (bsi, rhs, 1, false);
 
       x = build1 (REALPART_EXPR, inner_type, unshare_expr (lhs));
-      x = build2 (MODIFY_EXPR, inner_type, x, r);
+      x = build_gimple_modify_stmt (x, r);
       bsi_insert_before (bsi, x, BSI_SAME_STMT);
 
       if (stmt == bsi_stmt (*bsi))
        {
          x = build1 (IMAGPART_EXPR, inner_type, unshare_expr (lhs));
-         TREE_OPERAND (stmt, 0) = x;
-         TREE_OPERAND (stmt, 1) = i;
-         TREE_TYPE (stmt) = inner_type;
+         GIMPLE_STMT_OPERAND (stmt, 0) = x;
+         GIMPLE_STMT_OPERAND (stmt, 1) = i;
        }
       else
        {
          x = build1 (IMAGPART_EXPR, inner_type, unshare_expr (lhs));
-         x = build2 (MODIFY_EXPR, inner_type, x, i);
+         x = build_gimple_modify_stmt (x, i);
          bsi_insert_before (bsi, x, BSI_SAME_STMT);
 
          stmt = bsi_stmt (*bsi);
          gcc_assert (TREE_CODE (stmt) == RETURN_EXPR);
-         TREE_OPERAND (stmt, 0) = lhs;
+         GIMPLE_STMT_OPERAND (stmt, 0) = lhs;
        }
 
       update_all_vops (stmt);
@@ -884,15 +897,10 @@ expand_complex_libcall (block_stmt_iterator *bsi, tree ar, tree ai,
 {
   enum machine_mode mode;
   enum built_in_function bcode;
-  tree args, fn, stmt, type;
-
-  args = tree_cons (NULL, bi, NULL);
-  args = tree_cons (NULL, br, args);
-  args = tree_cons (NULL, ai, args);
-  args = tree_cons (NULL, ar, args);
+  tree fn, stmt, type;
 
   stmt = bsi_stmt (*bsi);
-  type = TREE_TYPE (TREE_OPERAND (stmt, 1));
+  type = TREE_TYPE (GIMPLE_STMT_OPERAND (stmt, 1));
 
   mode = TYPE_MODE (type);
   gcc_assert (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT);
@@ -904,13 +912,12 @@ expand_complex_libcall (block_stmt_iterator *bsi, tree ar, tree ai,
     gcc_unreachable ();
   fn = built_in_decls[bcode];
 
-  TREE_OPERAND (stmt, 1)
-    = build3 (CALL_EXPR, type, build_fold_addr_expr (fn), args, NULL);
+  GIMPLE_STMT_OPERAND (stmt, 1) = build_call_expr (fn, 4, ar, ai, br, bi);
   update_stmt (stmt);
 
-  if (in_ssa_p)
+  if (gimple_in_ssa_p (cfun))
     {
-      tree lhs = TREE_OPERAND (stmt, 0);
+      tree lhs = GIMPLE_STMT_OPERAND (stmt, 0);
       type = TREE_TYPE (type);
       update_complex_components (bsi, stmt,
                                 build1 (REALPART_EXPR, type, lhs),
@@ -1065,11 +1072,6 @@ expand_complex_div_wide (block_stmt_iterator *bsi, tree inner_type,
       bb_true = create_empty_bb (bb_cond);
       bb_false = create_empty_bb (bb_true);
 
-      t1 = build1 (GOTO_EXPR, void_type_node, tree_block_label (bb_true));
-      t2 = build1 (GOTO_EXPR, void_type_node, tree_block_label (bb_false));
-      COND_EXPR_THEN (cond) = t1;
-      COND_EXPR_ELSE (cond) = t2;
-
       /* Wire the blocks together.  */
       e->flags = EDGE_TRUE_VALUE;
       redirect_edge_succ (e, bb_true);
@@ -1120,9 +1122,9 @@ expand_complex_div_wide (block_stmt_iterator *bsi, tree inner_type,
 
      if (bb_true)
        {
-        t1 = build2 (MODIFY_EXPR, inner_type, rr, tr);
+        t1 = build_gimple_modify_stmt (rr, tr);
         bsi_insert_before (bsi, t1, BSI_SAME_STMT);
-        t1 = build2 (MODIFY_EXPR, inner_type, ri, ti);
+        t1 = build_gimple_modify_stmt (ri, ti);
         bsi_insert_before (bsi, t1, BSI_SAME_STMT);
         bsi_remove (bsi, true);
        }
@@ -1159,9 +1161,9 @@ expand_complex_div_wide (block_stmt_iterator *bsi, tree inner_type,
 
      if (bb_false)
        {
-        t1 = build2 (MODIFY_EXPR, inner_type, rr, tr);
+        t1 = build_gimple_modify_stmt (rr, tr);
         bsi_insert_before (bsi, t1, BSI_SAME_STMT);
-        t1 = build2 (MODIFY_EXPR, inner_type, ri, ti);
+        t1 = build_gimple_modify_stmt (ri, ti);
         bsi_insert_before (bsi, t1, BSI_SAME_STMT);
         bsi_remove (bsi, true);
        }
@@ -1305,9 +1307,9 @@ expand_complex_comparison (block_stmt_iterator *bsi, tree ar, tree ai,
     case RETURN_EXPR:
       expr = TREE_OPERAND (stmt, 0);
       /* FALLTHRU */
-    case MODIFY_EXPR:
-      type = TREE_TYPE (TREE_OPERAND (expr, 1));
-      TREE_OPERAND (expr, 1) = fold_convert (type, cc);
+    case GIMPLE_MODIFY_STMT:
+      type = TREE_TYPE (GIMPLE_STMT_OPERAND (expr, 1));
+      GIMPLE_STMT_OPERAND (expr, 1) = fold_convert (type, cc);
       break;
     case COND_EXPR:
       TREE_OPERAND (stmt, 0) = cc;
@@ -1336,12 +1338,12 @@ expand_complex_operations_1 (block_stmt_iterator *bsi)
       stmt = TREE_OPERAND (stmt, 0);
       if (!stmt)
        return;
-      if (TREE_CODE (stmt) != MODIFY_EXPR)
+      if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
        return;
       /* FALLTHRU */
 
-    case MODIFY_EXPR:
-      rhs = TREE_OPERAND (stmt, 1);
+    case GIMPLE_MODIFY_STMT:
+      rhs = GIMPLE_STMT_OPERAND (stmt, 1);
       break;
 
     case COND_EXPR:
@@ -1382,8 +1384,15 @@ expand_complex_operations_1 (block_stmt_iterator *bsi)
 
     default:
       {
-       tree lhs = TREE_OPERAND (stmt, 0);
-       tree rhs = TREE_OPERAND (stmt, 1);
+       tree lhs, rhs;
+
+       /* COND_EXPR may also fallthru here, but we do not need to do anything
+          with it.  */
+       if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
+         return;
+
+       lhs = GIMPLE_STMT_OPERAND (stmt, 0);
+       rhs = GIMPLE_STMT_OPERAND (stmt, 1);
 
        if (TREE_CODE (type) == COMPLEX_TYPE)
          expand_complex_move (bsi, stmt, type, lhs, rhs);
@@ -1391,7 +1400,7 @@ expand_complex_operations_1 (block_stmt_iterator *bsi)
                  || TREE_CODE (rhs) == IMAGPART_EXPR)
                 && TREE_CODE (TREE_OPERAND (rhs, 0)) == SSA_NAME)
          {
-           TREE_OPERAND (stmt, 1)
+           GENERIC_TREE_OPERAND (stmt, 1)
              = extract_component (bsi, TREE_OPERAND (rhs, 0),
                                   TREE_CODE (rhs) == IMAGPART_EXPR, false);
            update_stmt (stmt);
@@ -1420,7 +1429,7 @@ expand_complex_operations_1 (block_stmt_iterator *bsi)
        }
     }
 
-  if (in_ssa_p)
+  if (gimple_in_ssa_p (cfun))
     {
       al = find_lattice_value (ac);
       if (al == UNINITIALIZED)
@@ -1480,7 +1489,7 @@ expand_complex_operations_1 (block_stmt_iterator *bsi)
 \f
 /* Entry point for complex operation lowering during optimization.  */
 
-static void
+static unsigned int
 tree_lower_complex (void)
 {
   int old_last_basic_block;
@@ -1488,13 +1497,11 @@ tree_lower_complex (void)
   basic_block bb;
 
   if (!init_dont_simulate_again ())
-    return;
+    return 0;
 
   complex_lattice_values = VEC_alloc (complex_lattice_t, heap, num_ssa_names);
-  VEC_safe_grow (complex_lattice_t, heap,
-                complex_lattice_values, num_ssa_names);
-  memset (VEC_address (complex_lattice_t, complex_lattice_values), 0,
-         num_ssa_names * sizeof(complex_lattice_t));
+  VEC_safe_grow_cleared (complex_lattice_t, heap,
+                        complex_lattice_values, num_ssa_names);
 
   init_parameter_lattice_values ();
   ssa_propagate (complex_visit_stmt, complex_visit_phi);
@@ -1503,9 +1510,8 @@ tree_lower_complex (void)
                                             int_tree_map_eq, free);
 
   complex_ssa_name_components = VEC_alloc (tree, heap, 2*num_ssa_names);
-  VEC_safe_grow (tree, heap, complex_ssa_name_components, 2*num_ssa_names);
-  memset (VEC_address (tree, complex_ssa_name_components), 0,
-         2 * num_ssa_names * sizeof(tree));
+  VEC_safe_grow_cleared (tree, heap, complex_ssa_name_components,
+                        2 * num_ssa_names);
 
   update_parameter_components ();
 
@@ -1525,6 +1531,7 @@ tree_lower_complex (void)
   htab_delete (complex_variable_components);
   VEC_free (tree, heap, complex_ssa_name_components);
   VEC_free (complex_lattice_t, heap, complex_lattice_values);
+  return 0;
 }
 
 struct tree_opt_pass pass_lower_complex = 
@@ -1538,9 +1545,10 @@ struct tree_opt_pass pass_lower_complex =
   0,                                   /* tv_id */
   PROP_ssa,                            /* properties_required */
   0,                                   /* properties_provided */
-  0,                                   /* properties_destroyed */
+  0,                                   /* properties_destroyed */
   0,                                   /* todo_flags_start */
-  TODO_dump_func | TODO_ggc_collect
+  TODO_dump_func
+    | TODO_ggc_collect
     | TODO_update_ssa
     | TODO_verify_stmts,               /* todo_flags_finish */
   0                                    /* letter */
@@ -1549,7 +1557,7 @@ struct tree_opt_pass pass_lower_complex =
 \f
 /* Entry point for complex operation lowering without optimization.  */
 
-static void
+static unsigned int
 tree_lower_complex_O0 (void)
 {
   int old_last_basic_block = last_basic_block;
@@ -1563,6 +1571,7 @@ tree_lower_complex_O0 (void)
       for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
        expand_complex_operations_1 (&bsi);
     }
+  return 0;
 }
 
 static bool