Small simplification in ia32 ASM emitter.
[libfirm] / ir / be / ia32 / ia32_emitter.c
index 9bcca87..50be459 100644 (file)
@@ -81,33 +81,33 @@ static ir_node *get_prev_block_sched(const ir_node *block)
        return get_irn_link(block);
 }
 
-static bool is_fallthrough(const ir_node *cfgpred)
+static int is_fallthrough(const ir_node *cfgpred)
 {
        ir_node *pred;
 
        if(!is_Proj(cfgpred))
-               return true;
+               return 1;
        pred = get_Proj_pred(cfgpred);
        if(is_ia32_SwitchJmp(pred))
-               return false;
+               return 0;
 
-       return true;
+       return 1;
 }
 
-static bool block_needs_label(const ir_node *block)
+static int block_needs_label(const ir_node *block)
 {
-       bool need_label = true;
+       int need_label = 1;
        int  n_cfgpreds = get_Block_n_cfgpreds(block);
 
        if (n_cfgpreds == 0) {
-               need_label = false;
+               need_label = 0;
        } else if (n_cfgpreds == 1) {
                ir_node *cfgpred            = get_Block_cfgpred(block, 0);
                ir_node *cfgpred_block      = get_nodes_block(cfgpred);
 
                if (get_prev_block_sched(block) == cfgpred_block
                                && is_fallthrough(cfgpred)) {
-                       need_label = false;
+                       need_label = 0;
                }
        }
 
@@ -825,7 +825,7 @@ static ir_node *get_proj(const ir_node *node, long proj) {
        return NULL;
 }
 
-static bool can_be_fallthrough(const ir_node *node)
+static int can_be_fallthrough(const ir_node *node)
 {
        ir_node *target_block = get_cfop_target_block(node);
        ir_node *block        = get_nodes_block(node);
@@ -841,7 +841,6 @@ static void emit_ia32_Jcc(const ir_node *node)
        const ir_node *proj_true;
        const ir_node *proj_false;
        const ir_node *block;
-       const ir_node *next_block;
        pn_Cmp         pnc = get_ia32_condcode(node);
 
        pnc = determine_final_pnc(node, 0, pnc);
@@ -890,7 +889,7 @@ static void emit_ia32_Jcc(const ir_node *node)
                        case pn_Cmp_Le:
                                /* we need a local label if the false proj is a fallthrough
                                 * as the falseblock might have no label emitted then */
-                               if (get_cfop_target_block(proj_false) == next_block) {
+                               if (can_be_fallthrough(proj_false)) {
                                        need_parity_label = 1;
                                        be_emit_cstring("\tjp 1f");
                                } else {
@@ -926,14 +925,14 @@ emit_jcc:
        }
 
        /* the second Proj might be a fallthrough */
-       if (get_cfop_target_block(proj_false) != next_block) {
-               be_emit_cstring("\tjmp ");
+       if (can_be_fallthrough(proj_false)) {
+               be_emit_cstring("\t/* fallthrough to ");
                ia32_emit_cfop_target(proj_false);
+               be_emit_cstring(" */");
                be_emit_finish_line_gas(proj_false);
        } else {
-               be_emit_cstring("\t/* fallthrough to ");
+               be_emit_cstring("\tjmp ");
                ia32_emit_cfop_target(proj_false);
-               be_emit_cstring(" */");
                be_emit_finish_line_gas(proj_false);
        }
 }
@@ -1330,7 +1329,7 @@ static void emit_ia32_Asm(const ir_node *node)
        ident                 *asm_text = attr->asm_text;
        const char            *s        = get_id_str(asm_text);
 
-       be_emit_cstring("# Begin ASM \t");
+       be_emit_cstring("#APP\t");
        be_emit_finish_line_gas(node);
 
        if (s[0] != '\t')
@@ -1339,17 +1338,15 @@ static void emit_ia32_Asm(const ir_node *node)
        while(*s != 0) {
                if(*s == '%') {
                        s = emit_asm_operand(node, s);
-                       continue;
                } else {
-                       be_emit_char(*s);
+                       be_emit_char(*s++);
                }
-               ++s;
        }
 
        be_emit_char('\n');
        be_emit_write_line();
 
-       be_emit_cstring("# End ASM\n");
+       be_emit_cstring("#NO_APP\n");
        be_emit_write_line();
 }
 
@@ -2012,8 +2009,8 @@ static int should_align_block(const ir_node *block)
 
        n_cfgpreds = get_Block_n_cfgpreds(block);
        for(i = 0; i < n_cfgpreds; ++i) {
-               ir_node *pred      = get_Block_cfgpred_block(block, i);
-               double   pred_freq = get_block_execfreq(exec_freq, pred);
+               const ir_node *pred      = get_Block_cfgpred_block(block, i);
+               double         pred_freq = get_block_execfreq(exec_freq, pred);
 
                if(pred == prev) {
                        prev_freq += pred_freq;
@@ -2039,8 +2036,7 @@ static int should_align_block(const ir_node *block)
 static void ia32_emit_block_header(ir_node *block)
 {
        ir_graph     *irg = current_ir_graph;
-       int           n_cfgpreds;
-       bool          need_label = block_needs_label(block);
+       int           need_label = block_needs_label(block);
        int           i, arity;
        ir_exec_freq *exec_freq = cg->birg->exec_freq;
 
@@ -2057,13 +2053,13 @@ static void ia32_emit_block_header(ir_node *block)
                } else {
                        /* if the predecessor block has no fall-through,
                           we can always align the label. */
-                       int      i;
-                       bool     has_fallthrough = false;;
+                       int i;
+                       int has_fallthrough = 0;
 
-                       for (i = n_cfgpreds - 1; i >= 0; --i) {
+                       for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) {
                                ir_node *cfg_pred = get_Block_cfgpred(block, i);
                                if (can_be_fallthrough(cfg_pred)) {
-                                       has_fallthrough = true;
+                                       has_fallthrough = 1;
                                        break;
                                }
                        }
@@ -2203,7 +2199,7 @@ void ia32_gen_routine(ia32_code_gen_t *ia32_cg, ir_graph *irg)
        be_gas_emit_function_prolog(entity, ia32_cg_config.function_alignment);
 
        /* we use links to point to target blocks */
-       set_using_irn_link(irg);
+       ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
        irg_block_walk_graph(irg, ia32_gen_labels, NULL, &exc_list);
 
        /* initialize next block links */
@@ -2226,7 +2222,7 @@ void ia32_gen_routine(ia32_code_gen_t *ia32_cg, ir_graph *irg)
        be_emit_char('\n');
        be_emit_write_line();
 
-       clear_using_irn_link(irg);
+       ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
 
        /* Sort the exception table using the exception label id's.
           Those are ascending with ascending addresses. */