- * Optimize table-switch Conds.
- *
- * @param cond the switch-Cond
- * @return true if the switch-Cond was optimized
- */
-static bool handle_switch_cond(ir_node *cond)
-{
- ir_node *sel = get_Cond_selector(cond);
- ir_node *proj1 = (ir_node*)get_irn_link(cond);
- ir_node *proj2 = (ir_node*)get_irn_link(proj1);
- ir_node *blk = get_nodes_block(cond);
-
- /* exactly 1 Proj on the Cond node: must be the defaultProj */
- if (proj2 == NULL) {
- ir_node *jmp = new_r_Jmp(blk);
- assert(get_Cond_default_proj(cond) == get_Proj_proj(proj1));
- /* convert it into a Jmp */
- exchange(proj1, jmp);
- return true;
- }
-
- /* handle Cond nodes with constant argument. In this case the localopt rules
- * should have killed all obviously impossible cases.
- * So the only case left to handle here is 1 defaultProj + 1case
- * (this one case should be the one taken) */
- if (get_irn_link(proj2) == NULL) {
- ir_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_default_proj(cond);
- ir_graph *irg = get_irn_irg(cond);
- ir_node *bad = new_r_Bad(irg, mode_X);
-
- if (def_num == get_Proj_proj(proj1)) {
- /* first one is the defProj */
- if (num == get_Proj_proj(proj2)) {
- ir_node *jmp = new_r_Jmp(blk);
- exchange(proj2, jmp);
- exchange(proj1, bad);
- return true;
- }
- } else if (def_num == get_Proj_proj(proj2)) {
- /* second one is the defProj */
- if (num == get_Proj_proj(proj1)) {
- ir_node *jmp = new_r_Jmp(blk);
- exchange(proj1, jmp);
- exchange(proj2, bad);
- return true;
- }
- } else {
- /* neither: strange, Cond was not optimized so far */
- if (num == get_Proj_proj(proj1)) {
- ir_node *jmp = new_r_Jmp(blk);
- exchange(proj1, jmp);
- exchange(proj2, bad);
- return true;
- } else if (num == get_Proj_proj(proj2)) {
- ir_node *jmp = new_r_Jmp(blk);
- exchange(proj2, jmp);
- exchange(proj1, bad);
- return true;
- }
- }
- }
- }
- return false;
-}
-
-static bool get_phase_flag(ir_phase *block_info, ir_node *block, int offset) {
- return ((int)phase_get_irn_data(block_info, block)) & (1<<offset);
-}
-static void set_phase_flag(ir_phase *block_info, ir_node *block, int offset) {
- int data = (int)phase_get_irn_data(block_info, block);
- data |= (1<<offset);
- phase_set_irn_data(block_info, block, (void*)data);
-}
-
-static bool has_operations(ir_phase *block_info, ir_node *block) {
- return get_phase_flag(block_info, block, 1);
-}
-static void set_has_operations(ir_phase *block_info, ir_node *block) {
- set_phase_flag(block_info, block, 1);
-}
-
-static bool has_phis(ir_phase *block_info, ir_node *block) {
- return get_phase_flag(block_info, block, 2);
-}
-static void set_has_phis(ir_phase *block_info, ir_node *block) {
- set_phase_flag(block_info, block, 2);
-}
-
-static bool is_unknown_jump_target(ir_phase *block_info, ir_node *block) {
- return get_phase_flag(block_info, block, 3);
-}
-static void set_is_unknown_jump_target(ir_phase *block_info, ir_node *block) {
- set_phase_flag(block_info, block, 3);
-}
-
-/**
- * Optimize Conds, where true and false jump to the same block into a Jmp