- /* we add nwe nodes, so the outs are inconsistant */
- set_irg_outs_inconsistent(irg);
-
- /* we add new blocks and change the control flow */
- set_irg_dom_inconsistent(irg);
-
- /* we add a new loop */
- set_irg_loopinfo_inconsistent(irg);
-
- set_optimize(0);
-
- /* collect needed data */
- data.proj_X = NULL;
- data.block = NULL;
- data.blk_idx = -1;
- data.proj_m = NULL;
- data.proj_data = NULL;
- irg_walk_graph(irg, NULL, collect_data, &data);
-
- /* check number of arguments */
- call = get_irn_link(end_block);
- n_params = get_Call_n_params(call);
-
- assert(data.proj_X && "Could not find initial exec from Start");
- assert(data.block && "Could not find first block");
- assert(data.proj_m && "Could not find ProjM(Start)");
- assert((data.proj_data || n_params == 0) && "Could not find Proj(ProjT(Start)) of non-void function");
-
- current_ir_graph = irg;
-
- /* allocate in's for phi and block construction */
- NEW_ARR_A(ir_node *, in, n_tail_calls + 1);
-
- in[0] = data.proj_X;
-
- /* turn Return's into Jmp's */
- for (i = 1, p = rets; p; p = get_irn_link(p)) {
- ir_node *jmp;
-
- set_cur_block(get_nodes_block(p));
- jmp = new_Jmp();
-
- exchange(p, new_Bad());
- in[i++] = jmp;
-
- add_End_keepalive(get_irg_end(irg), jmp);
- }
-
- /* create a new block at start */
- block = new_Block(n_tail_calls + 1, in);
- jmp = new_Jmp();
-
- /* the old first block is now the second one */
- set_Block_cfgpred(data.block, data.blk_idx, jmp);
-
- /* allocate phi's, position 0 contains the memory phi */
- NEW_ARR_A(ir_node *, phis, n_params + 1);
-
- /* build the memory phi */
- i = 0;
- in[i] = new_rd_Proj(NULL, irg, irg->start_block, irg->start, mode_M, pn_Start_M);
- ++i;
-
- for (calls = call; calls; calls = get_irn_link(calls)) {
- in[i] = get_Call_mem(calls);
- ++i;
- }
- assert(i == n_tail_calls + 1);
-
- phis[0] = new_rd_Phi(NULL, irg, block, n_tail_calls + 1, in, mode_M);
-
- /* build the data phi's */
- if (n_params > 0) {
- ir_node *calls;
-
- NEW_ARR_A(ir_node **, call_params, n_params);
-
- /* collect all parameters */
- for (i = 0, calls = call; calls; calls = get_irn_link(calls)) {
- call_params[i] = get_Call_param_arr(calls);
- ++i;
- }
-
- /* build new projs and Phi's */
- for (i = 0; i < n_params; ++i) {
- ir_mode *mode = get_irn_mode(call_params[0][i]);
-
- in[0] = new_rd_Proj(NULL, irg, block, irg->args, mode, i);
- for (j = 0; j < n_tail_calls; ++j)
- in[j + 1] = call_params[j][i];