Commit 4d7ce782 authored by Matthias Braun's avatar Matthias Braun
Browse files

fix handling of default pns in the backend (they don't need table entries)

[r16526]
parent 0deebf40
......@@ -1022,11 +1022,12 @@ int ia32_cmp_branch_t(const void *a, const void *b) {
* possible otherwise a cmp-jmp cascade). Port from
* cggg ia32 backend
*/
static
void emit_ia32_SwitchJmp(const ir_node *node) {
static void emit_ia32_SwitchJmp(const ir_node *node)
{
unsigned long interval;
int last_value, i;
long pnc;
long default_pn;
jmp_tbl_t tbl;
ir_node *proj;
const ir_edge_t *edge;
......@@ -1035,11 +1036,12 @@ void emit_ia32_SwitchJmp(const ir_node *node) {
tbl.label = xmalloc(SNPRINTF_BUF_LEN);
tbl.label = get_unique_label(tbl.label, SNPRINTF_BUF_LEN, ".TBL_");
tbl.defProj = NULL;
tbl.num_branches = get_irn_n_edges(node);
tbl.num_branches = get_irn_n_edges(node) - 1;
tbl.branches = xcalloc(tbl.num_branches, sizeof(tbl.branches[0]));
tbl.min_value = INT_MAX;
tbl.max_value = INT_MIN;
default_pn = get_ia32_condcode(node);
i = 0;
/* go over all proj's and collect them */
foreach_out_edge(node, edge) {
......@@ -1048,21 +1050,22 @@ void emit_ia32_SwitchJmp(const ir_node *node) {
pnc = get_Proj_proj(proj);
/* create branch entry */
tbl.branches[i].target = proj;
tbl.branches[i].value = pnc;
tbl.min_value = pnc < tbl.min_value ? pnc : tbl.min_value;
tbl.max_value = pnc > tbl.max_value ? pnc : tbl.max_value;
/* check for default proj */
if (pnc == get_ia32_condcode(node)) {
assert(tbl.defProj == NULL && "found two defProjs at SwitchJmp");
if (pnc == default_pn) {
assert(tbl.defProj == NULL && "found two default Projs at SwitchJmp");
tbl.defProj = proj;
} else {
tbl.min_value = pnc < tbl.min_value ? pnc : tbl.min_value;
tbl.max_value = pnc > tbl.max_value ? pnc : tbl.max_value;
/* create branch entry */
tbl.branches[i].target = proj;
tbl.branches[i].value = pnc;
++i;
}
i++;
}
assert(i == tbl.num_branches);
/* sort the branches by their number */
qsort(tbl.branches, tbl.num_branches, sizeof(tbl.branches[0]), ia32_cmp_branch_t);
......
......@@ -2280,12 +2280,13 @@ static ir_node *gen_Store(ir_node *node)
static ir_node *create_Switch(ir_node *node)
{
ir_graph *irg = current_ir_graph;
dbg_info *dbgi = get_irn_dbg_info(node);
ir_node *block = be_transform_node(get_nodes_block(node));
ir_node *sel = get_Cond_selector(node);
ir_node *new_sel = be_transform_node(sel);
ir_graph *irg = current_ir_graph;
dbg_info *dbgi = get_irn_dbg_info(node);
ir_node *block = be_transform_node(get_nodes_block(node));
ir_node *sel = get_Cond_selector(node);
ir_node *new_sel = be_transform_node(sel);
int switch_min = INT_MAX;
long default_pn = get_Cond_defaultProj(node);
ir_node *new_node;
const ir_edge_t *edge;
......@@ -2294,7 +2295,10 @@ static ir_node *create_Switch(ir_node *node)
/* determine the smallest switch case value */
foreach_out_edge(node, edge) {
ir_node *proj = get_edge_src_irn(edge);
int pn = get_Proj_proj(proj);
long pn = get_Proj_proj(proj);
if(pn == default_pn)
continue;
if(pn < switch_min)
switch_min = pn;
}
......@@ -2310,8 +2314,7 @@ static ir_node *create_Switch(ir_node *node)
SET_IA32_ORIG_NODE(new_sel, ia32_get_old_node_name(env_cg, node));
}
new_node = new_rd_ia32_SwitchJmp(dbgi, irg, block, new_sel,
get_Cond_defaultProj(node));
new_node = new_rd_ia32_SwitchJmp(dbgi, irg, block, new_sel, default_pn);
SET_IA32_ORIG_NODE(new_node, ia32_get_old_node_name(env_cg, node));
return new_node;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment