get_Call_n_params: use int for consistency
[libfirm] / ir / ir / ircons.c
index 9e28bd1..28d838f 100644 (file)
@@ -232,13 +232,12 @@ static ir_node *set_phi_arguments(ir_node *phi, int pos)
 
        phi->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);
        set_irn_in(phi, arity, in);
-       set_irn_op(phi, op_Phi);
 
        irn_verify_irg(phi, irg);
 
        /* Memory Phis in endless loops must be kept alive.
           As we can't distinguish these easily we keep all of them alive. */
-       if (is_Phi(phi) && mode == mode_M)
+       if (mode == mode_M)
                add_End_keepalive(get_irg_end(irg), phi);
 
        try_remove_unnecessary_phi(phi);
@@ -272,14 +271,19 @@ static ir_node *get_r_value_internal(ir_node *block, int pos, ir_mode *mode)
        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))) {
-                       if (default_initialize_local_variable != NULL) {
-                               ir_node *rem = get_r_cur_block(irg);
-                               set_r_cur_block(irg, block);
-                               res = default_initialize_local_variable(irg, mode, pos - 1);
-                               set_r_cur_block(irg, rem);
+               if (arity == 0) {
+                       if (block == get_irg_start_block(irg)) {
+                               if (default_initialize_local_variable != NULL) {
+                                       ir_node *rem = get_r_cur_block(irg);
+                                       set_r_cur_block(irg, block);
+                                       res = default_initialize_local_variable(irg, mode, pos - 1);
+                                       set_r_cur_block(irg, rem);
+                               } else {
+                                       res = new_r_Unknown(irg, mode);
+                               }
                        } else {
-                               res = new_r_Unknown(irg, mode);
+                               /* unreachable block, use Bad */
+                               res = new_r_Bad(irg, mode);
                        }
                /* one predecessor just use its value */
                } else if (arity == 1) {
@@ -314,6 +318,7 @@ void mature_immBlock(ir_node *block)
        size_t   n_preds;
        ir_node  *next;
        ir_node  *phi;
+       ir_node **new_in;
        ir_graph *irg;
 
        assert(is_Block(block));
@@ -340,6 +345,15 @@ void mature_immBlock(ir_node *block)
 
        set_Block_matured(block, 1);
 
+       /* create final in-array for the block */
+       if (block->attr.block.dynamic_ins) {
+               new_in = NEW_ARR_D(ir_node*, irg->obst, n_preds+1);
+               memcpy(new_in, block->in, (n_preds+1) * sizeof(new_in[0]));
+               DEL_ARR_F(block->in);
+               block->in = new_in;
+               block->attr.block.dynamic_ins = false;
+       }
+
        /* Now, as the block is a finished Firm node, we can optimize it.
           Since other nodes have been allocated since the block was created
           we can not free the node on the obstack.  Therefore we have to call
@@ -462,11 +476,9 @@ ir_node *new_rd_immBlock(dbg_info *dbgi, ir_graph *irg)
        res = new_ir_node(dbgi, irg, NULL, op_Block, mode_BB, -1, NULL);
 
        set_Block_matured(res, 0);
+       res->attr.block.dynamic_ins = true;
        res->attr.block.irg.irg     = irg;
        res->attr.block.backedge    = NULL;
-       res->attr.block.in_cg       = NULL;
-       res->attr.block.cg_backedge = NULL;
-       res->attr.block.extblk      = NULL;
        res->attr.block.entity      = NULL;
 
        set_Block_block_visited(res, 0);
@@ -516,13 +528,15 @@ void set_cur_block(ir_node *target)
 
 void set_r_cur_block(ir_graph *irg, ir_node *target)
 {
-       assert(target == NULL || get_irn_mode(target) == mode_BB);
-       assert(target == NULL || get_irn_irg(target)  == irg);
+       assert(get_irg_phase_state(irg) == phase_building);
+       assert(target == NULL || is_Block(target));
+       assert(target == NULL || get_irn_irg(target) == irg);
        irg->current_block = target;
 }
 
 ir_node *get_r_cur_block(ir_graph *irg)
 {
+       assert(get_irg_phase_state(irg) == phase_building);
        return irg->current_block;
 }
 
@@ -613,23 +627,6 @@ void set_value(int pos, ir_node *value)
        set_r_value(current_ir_graph, pos, value);
 }
 
-int r_find_value(ir_graph *irg, ir_node *value)
-{
-       size_t i;
-       ir_node *bl = irg->current_block;
-
-       for (i = ARR_LEN(bl->attr.block.graph_arr); i > 1;) {
-               if (bl->attr.block.graph_arr[--i] == value)
-                       return i - 1;
-       }
-       return -1;
-}
-
-int find_value(ir_node *value)
-{
-       return r_find_value(current_ir_graph, value);
-}
-
 ir_node *get_r_store(ir_graph *irg)
 {
        assert(get_irg_phase_state(irg) == phase_building);
@@ -699,6 +696,9 @@ void ir_set_uninitialized_local_variable_func(
 
 void irg_finalize_cons(ir_graph *irg)
 {
+       ir_node *end_block = get_irg_end_block(irg);
+       mature_immBlock(end_block);
+
        set_irg_phase_state(irg, phase_high);
 }