Remove pointless local variables.
[libfirm] / ir / ir / ircons.c
index 19d8833..f38994b 100644 (file)
@@ -245,6 +245,8 @@ static ir_node *set_phi_arguments(ir_node *phi, int pos)
                if (is_Bad(cfgpred)) {
                        value = new_r_Bad(irg);
                } else {
+                       inc_irg_visited(irg);
+
                        value = get_r_value_internal(cfgpred, pos, mode);
                }
                in[i] = value;
@@ -277,12 +279,19 @@ static ir_node *set_phi_arguments(ir_node *phi, int pos)
  */
 static ir_node *get_r_value_internal(ir_node *block, int pos, ir_mode *mode)
 {
-       ir_node *res = block->attr.block.graph_arr[pos];
+       ir_node  *res = block->attr.block.graph_arr[pos];
+       ir_graph *irg = get_irn_irg(block);
        if (res != NULL)
                return res;
 
+       /* We ran into a cycle. This may happen in unreachable loops. */
+       if (irn_visited_else_mark(block)) {
+               /* Since the loop is unreachable, return a Bad. */
+               return new_r_Bad(irg);
+       }
+
        /* in a matured block we can immediately determine the phi arguments */
-       if (block->attr.block.is_matured) {
+       if (get_Block_matured(block)) {
                int arity = get_irn_arity(block);
                /* no predecessors: use unknown value */
                if (arity == 0 && block == get_irg_start_block(get_irn_irg(block))) {
@@ -357,7 +366,7 @@ void mature_immBlock(ir_node *block)
                }
        }
 
-       block->attr.block.is_matured = 1;
+       set_Block_matured(block, 1);
 
        /* Now, as the block is a finished Firm node, we can optimize it.
           Since other nodes have been allocated since the block was created
@@ -491,8 +500,7 @@ ir_node *new_rd_immBlock(dbg_info *dbgi, ir_graph *irg)
        /* creates a new dynamic in-array as length of in is -1 */
        res = new_ir_node(dbgi, irg, NULL, op_Block, mode_BB, -1, NULL);
 
-       res->attr.block.is_matured  = 0;
-       res->attr.block.is_dead     = 0;
+       set_Block_matured(res, 0);
        res->attr.block.irg.irg     = irg;
        res->attr.block.backedge    = NULL;
        res->attr.block.in_cg       = NULL;
@@ -533,7 +541,7 @@ void add_immBlock_pred(ir_node *block, ir_node *jmp)
        int n = ARR_LEN(block->in) - 1;
 
        assert(is_Block(block) && "Error: Must be a Block");
-       assert(!block->attr.block.is_matured && "Error: Block already matured!\n");
+       assert(!get_Block_matured(block) && "Error: Block already matured!\n");
        assert(is_ir_node(jmp));
 
        ARR_APP1(ir_node *, block->in, jmp);
@@ -567,6 +575,7 @@ ir_node *get_r_value(ir_graph *irg, int pos, ir_mode *mode)
 {
        assert(get_irg_phase_state(irg) == phase_building);
        assert(pos >= 0);
+       inc_irg_visited(irg);
 
        return get_r_value_internal(irg->current_block, pos + 1, mode);
 }
@@ -586,9 +595,8 @@ static ir_mode *guess_recursively(ir_node *block, int pos)
        int      n_preds;
        int      i;
 
-       if (irn_visited(block))
+       if (irn_visited_else_mark(block))
                return NULL;
-       mark_irn_visited(block);
 
        /* already have a defintion -> we can simply look at its mode */
        value = block->attr.block.graph_arr[pos];
@@ -665,6 +673,7 @@ int find_value(ir_node *value)
 ir_node *get_r_store(ir_graph *irg)
 {
        assert(get_irg_phase_state(irg) == phase_building);
+       inc_irg_visited(irg);
        return get_r_value_internal(irg->current_block, 0, mode_M);
 }