cleanup: Remove code duplication for implementing get_irg_graph_nr().
[libfirm] / ir / ir / irgraph.c
index 6e78c50..8ecf734 100644 (file)
@@ -1,20 +1,6 @@
 /*
- * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
- *
  * This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
@@ -85,8 +71,12 @@ static ir_graph *alloc_graph(void)
        res->kind = k_ir_graph;
 
        /* initialize the idx->node map. */
-       res->idx_irn_map = NEW_ARR_F(ir_node *, INITIAL_IDX_IRN_MAP_SIZE);
-       memset(res->idx_irn_map, 0, INITIAL_IDX_IRN_MAP_SIZE * sizeof(res->idx_irn_map[0]));
+       res->idx_irn_map = NEW_ARR_FZ(ir_node*, INITIAL_IDX_IRN_MAP_SIZE);
+
+       obstack_init(&res->obst);
+
+       /* value table for global value numbering for optimizing use in iropt.c */
+       new_identities(res);
 
        return res;
 }
@@ -128,29 +118,14 @@ ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc)
        /* inform statistics here, as blocks will be already build on this graph */
        hook_new_graph(res, ent);
 
-       /*-- initialized for each graph. --*/
-       res->kind = k_ir_graph;
-       obstack_init(&res->obst);
-
        /* graphs are in construction mode by default */
        add_irg_constraints(res, IR_GRAPH_CONSTRAINT_CONSTRUCTION);
        irg_set_nloc(res, n_loc);
 
-       /* descriptions will be allocated on demand */
-       res->loc_descriptions = NULL;
-
-       res->visited       = 0; /* visited flag, for the ir walker */
-       res->block_visited = 0; /* visited flag, for the 'block'-walker */
-
-       res->last_node_idx = 0;
-
-       new_identities(res);
-
        res->irg_pinned_state    = op_pin_state_pinned;
        res->typeinfo_state      = ir_typeinfo_none;
        set_irp_typeinfo_inconsistent();           /* there is a new graph with typeinfo_none. */
        res->callee_info_state   = irg_callee_info_none;
-       res->class_cast_state    = ir_class_casts_transitive;
        res->fp_model            = fp_model_precise;
        res->mem_disambig_opt    = aa_opt_inherited;
 
@@ -220,21 +195,10 @@ ir_graph *new_const_code_irg(void)
        /* inform statistics here, as blocks will be already build on this graph */
        hook_new_graph(res, NULL);
 
-       res->n_loc         = 1; /* Only the memory. */
-       res->visited       = 0; /* visited flag, for the ir walker */
-       res->block_visited = 0; /* visited flag, for the 'block'-walker */
-       obstack_init(&res->obst);
-
-       res->last_node_idx = 0;
-
+       res->n_loc            = 1; /* Only the memory. */
        res->irg_pinned_state = op_pin_state_pinned;
        res->fp_model         = fp_model_precise;
 
-       /* value table for global value numbering for optimizing use in iropt.c */
-       new_identities(res);
-       res->ent         = NULL;
-       res->frame_type  = NULL;
-
        add_irg_constraints(res, IR_GRAPH_CONSTRAINT_CONSTRUCTION);
 
        /* the Anchor node must be created first */
@@ -323,18 +287,9 @@ ir_graph *create_irg_copy(ir_graph *irg)
 
        res = alloc_graph();
 
-       res->n_loc = 0;
-       res->visited = 0;       /* visited flag, for the ir walker */
-       res->block_visited = 0; /* visited flag, for the 'block'-walker */
-       obstack_init(&res->obst);
-
-       res->last_node_idx = 0;
-
        res->irg_pinned_state = irg->irg_pinned_state;
        res->fp_model         = irg->fp_model;
 
-       new_identities(res);
-
        /* clone the frame type here for safety */
        irp_reserve_resources(irp, IRP_RESOURCE_ENTITY_LINK);
        res->frame_type  = clone_frame_type(irg->frame_type);
@@ -392,17 +347,14 @@ int (is_ir_graph)(const void *thing)
        return is_ir_graph_(thing);
 }
 
-#ifdef DEBUG_libfirm
 long get_irg_graph_nr(const ir_graph *irg)
 {
+#ifdef DEBUG_libfirm
        return irg->graph_nr;
-}
 #else
-long get_irg_graph_nr(const ir_graph *irg)
-{
        return PTR_TO_INT(irg);
-}
 #endif
+}
 
 size_t get_irg_idx(const ir_graph *irg)
 {