/* 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
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"
{
struct int_tree_map *h, in;
in.uid = uid;
- h = htab_find_with_hash (complex_variable_components, &in, uid);
+ h = (struct int_tree_map *) htab_find_with_hash (complex_variable_components, &in, uid);
return h ? h->to : NULL;
}
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);
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
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:
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;
}
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. */
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;
/* 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);
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);
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);
}
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);
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);
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);
{
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);
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),
tree ar, tree ai, tree br, tree bi,
enum tree_code code)
{
- tree rr, ri, ratio, div, t1, t2, tr, ti, cond;
+ tree rr, ri, ratio, div, t1, t2, tr, ti, compare;
basic_block bb_cond, bb_true, bb_false, bb_join;
/* Examine |br| < |bi|, and branch. */
t1 = gimplify_build1 (bsi, ABS_EXPR, inner_type, br);
t2 = gimplify_build1 (bsi, ABS_EXPR, inner_type, bi);
- cond = fold_build2 (LT_EXPR, boolean_type_node, t1, t2);
- STRIP_NOPS (cond);
+ compare = fold_build2 (LT_EXPR, boolean_type_node, t1, t2);
+ STRIP_NOPS (compare);
bb_cond = bb_true = bb_false = bb_join = NULL;
rr = ri = tr = ti = NULL;
- if (!TREE_CONSTANT (cond))
+ if (!TREE_CONSTANT (compare))
{
edge e;
+ tree cond, tmp;
+
+ tmp = create_tmp_var (boolean_type_node, NULL);
+ cond = build_gimple_modify_stmt (tmp, compare);
+ if (gimple_in_ssa_p (cfun))
+ tmp = make_ssa_name (tmp, cond);
+ GIMPLE_STMT_OPERAND (cond, 0) = tmp;
+ bsi_insert_before (bsi, cond, BSI_SAME_STMT);
- cond = build3 (COND_EXPR, void_type_node, cond, NULL_TREE, NULL_TREE);
+ cond = build3 (COND_EXPR, void_type_node, tmp, NULL_TREE, NULL_TREE);
bsi_insert_before (bsi, cond, BSI_SAME_STMT);
/* Split the original block, and create the TRUE and FALSE blocks. */
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);
ti = (ai * ratio) - ar;
tr = tr / div;
ti = ti / div; */
- if (bb_true || integer_nonzerop (cond))
+ if (bb_true || integer_nonzerop (compare))
{
if (bb_true)
{
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);
}
ti = b - (a * ratio);
tr = tr / div;
ti = ti / div; */
- if (bb_false || integer_zerop (cond))
+ if (bb_false || integer_zerop (compare))
{
if (bb_false)
{
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);
}
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;
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:
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);
|| 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);
}
}
- if (in_ssa_p)
+ if (gimple_in_ssa_p (cfun))
{
al = find_lattice_value (ac);
if (al == UNINITIALIZED)
\f
/* Entry point for complex operation lowering during optimization. */
-static void
+static unsigned int
tree_lower_complex (void)
{
int old_last_basic_block;
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);
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 ();
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 =
+struct gimple_opt_pass pass_lower_complex =
{
+ {
+ GIMPLE_PASS,
"cplxlower", /* name */
0, /* gate */
tree_lower_complex, /* execute */
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 */
+ | TODO_verify_stmts /* todo_flags_finish */
+ }
};
\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;
for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
expand_complex_operations_1 (&bsi);
}
+ return 0;
}
static bool
return optimize == 0 || sorrycount || errorcount;
}
-struct tree_opt_pass pass_lower_complex_O0 =
+struct gimple_opt_pass pass_lower_complex_O0 =
{
+ {
+ GIMPLE_PASS,
"cplxlower0", /* name */
gate_no_optimization, /* gate */
tree_lower_complex_O0, /* execute */
0, /* todo_flags_start */
TODO_dump_func | TODO_ggc_collect
| TODO_verify_stmts, /* todo_flags_finish */
- 0 /* letter */
+ }
};