ir_graph *create_irg_copy(ir_graph *irg) { ir_graph *res = alloc_graph(); res->irg_pinned_state = irg->irg_pinned_state; /* clone the frame type here for safety */ irp_reserve_resources(irp, IRP_RESOURCE_ENTITY_LINK); res->frame_type = clone_frame_type(irg->frame_type); 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))); ir_free_resources(irg, IR_RESOURCE_IRN_LINK); irp_free_resources(irp, IRP_RESOURCE_ENTITY_LINK); return res; }
static ir_node *transform_end(ir_node *node) { /* Do not transform predecessors yet to keep the pre-transform * phase from visiting all the graph. */ ir_node *const block = be_transform_nodes_block(node); ir_node *const new_end = exact_copy(node); set_nodes_block(new_end, block); ir_graph *const irg = get_irn_irg(new_end); set_irg_end(irg, new_end); be_enqueue_preds(node); return new_end; }
static ir_graph *new_r_ir_graph(ir_entity *ent, int n_loc) { ir_graph *const res = alloc_graph(); /* Inform statistics here, as blocks will be already built on this graph. */ hook_new_graph(res, ent); /* graphs are in construction mode by default */ add_irg_constraints(res, IR_GRAPH_CONSTRAINT_CONSTRUCTION); irg_set_nloc(res, n_loc); res->irg_pinned_state = op_pin_state_pinned; res->callee_info_state = irg_callee_info_none; res->mem_disambig_opt = aa_opt_inherited; /*-- Type information for the procedure of the graph --*/ res->ent = ent; if (ent) set_entity_irg(ent, res); /*-- a class type so that it can contain "inner" methods as in Pascal. --*/ res->frame_type = new_type_frame(); /* the Anchor node must be created first */ res->anchor = new_r_Anchor(res); /*-- Nodes needed in every graph --*/ set_irg_end_block(res, new_r_immBlock(res)); set_irg_end(res, new_r_End(res, 0, NULL)); ir_node *const start_block = new_r_Block_noopt(res, 0, NULL); set_irg_start_block(res, start_block); set_irg_no_mem(res, new_r_NoMem(res)); res->index = get_irp_new_irg_idx(); #ifdef DEBUG_libfirm res->graph_nr = get_irp_new_node_nr(); #endif set_r_cur_block(res, start_block); return res; }
static ir_node *transform_end(ir_node *node) { /* end has to be duplicated manually because we need a dynamic in array */ ir_graph *irg = get_irn_irg(node); dbg_info *dbgi = get_irn_dbg_info(node); ir_node *block = be_transform_node(get_nodes_block(node)); ir_node *new_end = new_ir_node(dbgi, irg, block, op_End, mode_X, -1, NULL); copy_node_attr(irg, node, new_end); be_duplicate_deps(node, new_end); set_irg_end(irg, new_end); /* do not transform predecessors yet to keep the pre-transform * phase from visiting all the graph */ int arity = get_irn_arity(node); for (int i = 0; i < arity; ++i) { ir_node *in = get_irn_n(node, i); add_End_keepalive(new_end, in); } be_enqueue_preds(node); return new_end; }