/* Switch Conversion converts variable initializations based on switch
statements to initializations from a static array.
- Copyright (C) 2006, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
Contributed by Martin Jambor <jamborm@suse.cz>
This file is part of GCC.
#include "input.h"
#include "tree-pass.h"
#include "diagnostic.h"
+#include "gimple-pretty-print.h"
#include "tree-dump.h"
#include "timevar.h"
tree low = CASE_LOW (cs);
pos = CASE_LOW (cs);
- do
+ do
{
constructor_elt *elt;
for (i = 0; i < len; i++)
{
constructor_elt *elt = VEC_index (constructor_elt, vec, i);
-
+
if (!prev)
prev = elt->value;
else if (!operand_equal_p (elt->value, prev, OEP_ONLY_CONST))
tree name, cst;
gimple load;
gimple_stmt_iterator gsi = gsi_for_stmt (swtch);
+ location_t loc = gimple_location (swtch);
gcc_assert (info.default_values[num]);
ctor = build_constructor (array_type, info.constructors[num]);
TREE_CONSTANT (ctor) = true;
- decl = build_decl (VAR_DECL, NULL_TREE, array_type);
+ decl = build_decl (loc, VAR_DECL, NULL_TREE, array_type);
TREE_STATIC (decl) = 1;
DECL_INITIAL (decl) = ctor;
gimple stmt;
gimple_stmt_iterator gsi;
int i;
+ location_t loc = gimple_location (swtch);
gsi = gsi_for_stmt (swtch);
arr_index_type = build_index_type (info.range_size);
- tmp = create_tmp_var (arr_index_type, "csti");
+ tmp = create_tmp_var (TREE_TYPE (info.index_expr), "csti");
add_referenced_var (tmp);
tidx = make_ssa_name (tmp, NULL);
- sub = fold_build2 (MINUS_EXPR, TREE_TYPE (info.index_expr), info.index_expr,
- fold_convert (TREE_TYPE (info.index_expr),
- info.range_min));
- sub = force_gimple_operand_gsi (&gsi, fold_convert (arr_index_type, sub),
+ sub = fold_build2_loc (loc, MINUS_EXPR,
+ TREE_TYPE (info.index_expr), info.index_expr,
+ fold_convert_loc (loc, TREE_TYPE (info.index_expr),
+ info.range_min));
+ sub = force_gimple_operand_gsi (&gsi, sub,
false, NULL, true, GSI_SAME_STMT);
stmt = gimple_build_assign (tidx, sub);
SSA_NAME_DEF_STMT (tidx) = stmt;
!gsi_end_p (gsi); gsi_next (&gsi), i++)
{
gimple phi = gsi_stmt (gsi);
- add_phi_arg (phi, info.target_inbound_names[i], e1f);
- add_phi_arg (phi, info.target_outbound_names[i], e2f);
+ add_phi_arg (phi, info.target_inbound_names[i], e1f, UNKNOWN_LOCATION);
+ add_phi_arg (phi, info.target_outbound_names[i], e2f, UNKNOWN_LOCATION);
}
}
static void
gen_inbound_check (gimple swtch)
{
- tree label_decl1 = create_artificial_label ();
- tree label_decl2 = create_artificial_label ();
- tree label_decl3 = create_artificial_label ();
+ tree label_decl1 = create_artificial_label (UNKNOWN_LOCATION);
+ tree label_decl2 = create_artificial_label (UNKNOWN_LOCATION);
+ tree label_decl3 = create_artificial_label (UNKNOWN_LOCATION);
gimple label1, label2, label3;
tree utype;
gimple_stmt_iterator gsi;
basic_block bb0, bb1, bb2, bbf, bbd;
edge e01, e02, e21, e1d, e1f, e2f;
+ location_t loc = gimple_location (swtch);
gcc_assert (info.default_values);
bb0 = gimple_bb (swtch);
add_referenced_var (tmp_u_var);
tmp_u_1 = make_ssa_name (tmp_u_var, NULL);
- cast = fold_convert (utype, info.index_expr);
+ cast = fold_convert_loc (loc, utype, info.index_expr);
cast_assign = gimple_build_assign (tmp_u_1, cast);
SSA_NAME_DEF_STMT (tmp_u_1) = cast_assign;
gsi_insert_before (&gsi, cast_assign, GSI_SAME_STMT);
update_stmt (cast_assign);
- ulb = fold_convert (utype, info.range_min);
- minus = fold_build2 (MINUS_EXPR, utype, tmp_u_1, ulb);
+ ulb = fold_convert_loc (loc, utype, info.range_min);
+ minus = fold_build2_loc (loc, MINUS_EXPR, utype, tmp_u_1, ulb);
minus = force_gimple_operand_gsi (&gsi, minus, false, NULL, true,
GSI_SAME_STMT);
tmp_u_2 = make_ssa_name (tmp_u_var, NULL);
gsi_insert_before (&gsi, minus_assign, GSI_SAME_STMT);
update_stmt (minus_assign);
- bound = fold_convert (utype, info.range_size);
+ bound = fold_convert_loc (loc, utype, info.range_size);
cond_stmt = gimple_build_cond (LE_EXPR, tmp_u_2, bound, NULL_TREE, NULL_TREE);
gsi_insert_before (&gsi, cond_stmt, GSI_SAME_STMT);
update_stmt (cond_stmt);
"SWITCH statement (%s:%d) : ------- \n",
loc.file, loc.line);
print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
- fprintf (dump_file, "\n");
+ putc ('\n', dump_file);
}
info.reason = NULL;
{
if (dump_file)
{
- fprintf (dump_file, "Switch converted\n");
- fprintf (dump_file, "--------------------------------\n");
+ fputs ("Switch converted\n", dump_file);
+ fputs ("--------------------------------\n", dump_file);
}
}
else
if (dump_file)
{
gcc_assert (info.reason);
- fprintf (dump_file, "Bailing out - ");
- fprintf (dump_file, info.reason);
- fprintf (dump_file, "--------------------------------\n");
+ fputs ("Bailing out - ", dump_file);
+ fputs (info.reason, dump_file);
+ fputs ("--------------------------------\n", dump_file);
}
}
}