- contain "inner" methods as in Pascal. **/
- res->frame_type = new_type_class(mangle(get_entity_ident(ent),
- id_from_str(FRAME_TP_SUFFIX, strlen(FRAME_TP_SUFFIX))));
- /* Remove type from type list. Must be treated differently than other types. */
- remove_irp_type_from_list(res->frame_type);
-
- /** Nodes needed in every graph **/
- res->end_block = new_immBlock ();
- res->end = new_End ();
-
- res->start_block = new_immBlock ();
- res->start = new_Start ();
- res->bad = new_ir_node (NULL, res, res->start_block, op_Bad, mode_T, 0, NULL);
- res->unknown = new_ir_node (NULL, res, res->start_block, op_Unknown, mode_T, 0, NULL);
-
- /* Proj results of start node */
- projX = new_Proj (res->start, mode_X, pns_initial_exec);
- set_store (new_Proj (res->start, mode_M, pns_global_store));
- res->frame = new_Proj (res->start, mode_P, pns_frame_base);
- res->globals = new_Proj (res->start, mode_P, pns_globals);
- res->args = new_Proj (res->start, mode_T, pns_args);
-
- add_in_edge(res->start_block, projX);
- /*
- * The code generation needs it. leave it in now.
- * Use of this edge is matter of discussion, unresolved. Also possible:
- * add_in_edge(res->start_block, res->start_block), but invalid typed.
- */
- mature_block (res->current_block);
-
- /** Make a block to start with **/
- first_block = new_immBlock ();
- add_in_edge (first_block, projX);
-
- return res;
-}
-
-
-/* Make a rudimentary ir graph for the constant code.
- Must look like a correct irg, spare everything else. */
-ir_graph *new_const_code_irg() {
- ir_graph *res;
- ir_node *projX;
-
- res = (ir_graph *) malloc (sizeof (ir_graph));
- current_ir_graph = res;
- 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 */
-#if USE_EXPLICIT_PHI_IN_STACK
- res->Phi_in_stack = NULL;
-#endif
- res->obst = (struct obstack *) xmalloc (sizeof (struct obstack));
- obstack_init (res->obst);
- res->phase_state = phase_building;
- res->pinned = pinned;
- res->value_table = new_identities (); /* value table for global value
- numbering for optimizing use in
- iropt.c */
- res->ent = NULL;
- res->frame_type = NULL;
- res->start_block = new_immBlock ();
- res->end_block = new_immBlock ();
- res->end = new_End ();
- mature_block(get_cur_block());
- res->bad = new_ir_node (NULL, res, res->start_block, op_Bad, mode_T, 0, NULL);
- res->unknown = new_ir_node (NULL, res, res->start_block, op_Unknown, mode_T, 0, NULL);
- res->start = new_Start ();
- /* Proj results of start node */
- projX = new_Proj (res->start, mode_X, pns_initial_exec);
- set_store (new_Proj (res->start, mode_M, pns_global_store));
- add_in_edge(res->start_block, projX);
- mature_block (res->current_block);
- add_in_edge (new_immBlock (), projX);
- mature_block(get_cur_block());
- /* Set the visited flag high enough that the block will never be visited. */
- set_irn_visited(get_cur_block(), -1);
- set_Block_block_visited(get_cur_block(), -1);
- set_Block_block_visited(res->start_block, -1);
- return res;
-}
-
-/* Frees the passed irgraph.
- Deallocates all nodes in this graph and the ir_graph structure.
- Sets the field irgraph in the corresponding entity to NULL.
- Does not remove the irgraph from the list in irprog (requires
- inefficient search, call remove_irp_irg by hand).
- Does not free types, entities or modes that are used only by this
- graph, nor the entity standing for this graph. */
-void free_ir_graph (ir_graph *irg) {
- set_entity_irg(irg->ent, NULL);
- free(irg->obst);
-#if USE_EXPLICIT_PHI_IN_STACK
- free_Phi_in_stack(irg->Phi_in_stack);
+ * Post-walker: Set the predecessors of the copied nodes.
+ * The copied nodes are set as link of their original nodes. The links of
+ * "irn" predecessors are the predecessors of copied node.
+ */
+static void rewire(ir_node *irn, void *env)
+{
+ (void) env;
+ irn_rewire_inputs(irn);
+}
+
+static ir_node *get_new_node(const ir_node *old_node)
+{
+ return (ir_node*) get_irn_link(old_node);
+}
+
+ir_graph *create_irg_copy(ir_graph *irg)
+{
+ ir_graph *res;
+
+ 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 */
+ res->obst = XMALLOC(struct obstack);
+ obstack_init(res->obst);
+
+ res->last_node_idx = 0;
+
+ res->phase_state = irg->phase_state;
+ 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);
+
+ res->phase_state = irg->phase_state;
+
+ ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
+
+ /* copy all nodes from the graph irg to the new graph res */
+ irg_walk_anchors(irg, copy_all_nodes, rewire, res);
+
+ /* copy the Anchor node */
+ res->anchor = get_new_node(irg->anchor);
+
+ /* -- The end block -- */
+ set_irg_end_block (res, get_new_node(get_irg_end_block(irg)));
+ set_irg_end (res, get_new_node(get_irg_end(irg)));
+
+ /* -- The start block -- */
+ set_irg_start_block(res, get_new_node(get_irg_start_block(irg)));
+ set_irg_no_mem (res, get_new_node(get_irg_no_mem(irg)));
+ set_irg_start (res, get_new_node(get_irg_start(irg)));
+
+ /* Proj results of start node */
+ set_irg_initial_mem(res, get_new_node(get_irg_initial_mem(irg)));
+
+ /* Copy the node count estimation. Would be strange if this
+ is different from the original one. */
+ res->estimated_node_count = irg->estimated_node_count;
+
+ ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
+ irp_free_resources(irp, IRP_RESOURCE_ENTITY_LINK);
+
+ return res;
+}
+
+void free_ir_graph(ir_graph *irg)
+{
+ assert(is_ir_graph(irg));
+
+ edges_deactivate(irg);
+
+ hook_free_graph(irg);
+ free_irg_outs(irg);
+ del_identities(irg);
+ if (irg->ent) {
+ set_entity_irg(irg->ent, NULL); /* not set in const code irg */
+ }
+
+ free_End(get_irg_end(irg));
+ obstack_free(irg->obst, NULL);
+ free(irg->obst);
+ if (irg->loc_descriptions)
+ free(irg->loc_descriptions);
+ irg->kind = k_BAD;
+ free_graph(irg);
+}
+
+int (is_ir_graph)(const void *thing)
+{
+ return is_ir_graph_(thing);
+}
+
+#ifdef DEBUG_libfirm
+long get_irg_graph_nr(const ir_graph *irg)
+{
+ return irg->graph_nr;
+}
+#else
+long get_irg_graph_nr(const ir_graph *irg)
+{
+ return PTR_TO_INT(irg);
+}