+/**
+ * handle pre-optimized table switch Cond's
+ */
+static void handle_switch_cond(ir_node *proj) {
+ ir_node *cond = skip_Proj(proj);
+ ir_node *sel;
+
+ if (! is_Cond(cond))
+ return;
+
+ sel = get_Cond_selector(cond);
+ if (mode_is_int(get_irn_mode(sel))) {
+ /* check for table switch that could be optimized */
+ ir_node *proj1 = get_irn_link(cond);
+ ir_node *proj2 = get_irn_link(proj1);
+ ir_node *jmp, *blk;
+
+ blk = is_Bad(cond) ? cond : get_nodes_block(cond);
+
+ if (! proj2) {
+ /* this Cond has only one Proj: must be the defProj */
+ assert(get_Cond_defaultProj(cond) == get_Proj_proj(proj1));
+ /* convert it into a Jmp */
+ jmp = new_r_Jmp(current_ir_graph, blk);
+ exchange(proj1, jmp);
+ }
+ else if (get_irn_link(proj2) == NULL) {
+ /* We have two Proj's here. Check if the Cond has
+ a constant argument */
+ tarval *tv = value_of(sel);
+
+ if (tv != tarval_bad) {
+ /* we have a constant switch */
+ long num = get_tarval_long(tv);
+ long def_num = get_Cond_defaultProj(cond);
+
+ if (def_num == get_Proj_proj(proj1)) {
+ /* first one is the defProj */
+ if (num == get_Proj_proj(proj2)) {
+ jmp = new_r_Jmp(current_ir_graph, blk);
+ exchange(proj2, jmp);
+ exchange(proj1, new_Bad());
+ }
+ }
+ else if (def_num == get_Proj_proj(proj2)) {
+ /* second one is the defProj */
+ if (num == get_Proj_proj(proj1)) {
+ jmp = new_r_Jmp(current_ir_graph, blk);
+ exchange(proj1, jmp);
+ exchange(proj2, new_Bad());
+ }
+ }
+ else {
+ /* neither: strange, Cond was not optimized so far */
+ if (num == get_Proj_proj(proj1)) {
+ jmp = new_r_Jmp(current_ir_graph, blk);
+ exchange(proj1, jmp);
+ exchange(proj2, new_Bad());
+ }
+ else if (num == get_Proj_proj(proj2)) {
+ jmp = new_r_Jmp(current_ir_graph, blk);
+ exchange(proj2, jmp);
+ exchange(proj1, new_Bad());
+ }
+ }
+ }
+ }
+ }
+}
+