forbid calls of new_XXX and new_d_XXX when not in phase_building (only new_r_XXX...
[libfirm] / ir / opt / tailrec.c
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Tail-recursion call optimization.
23  * @date    08.06.2004
24  * @author  Michael Beck
25  * @version $Id$
26  */
27 #include "config.h"
28
29 #include <string.h>
30 #include <assert.h>
31
32 #include "debug.h"
33 #include "iroptimize.h"
34 #include "scalar_replace.h"
35 #include "array_t.h"
36 #include "irprog_t.h"
37 #include "irgwalk.h"
38 #include "irgmod.h"
39 #include "irop.h"
40 #include "irnode_t.h"
41 #include "irgraph_t.h"
42 #include "ircons.h"
43 #include "irflag.h"
44 #include "trouts.h"
45 #include "irouts.h"
46 #include "irhooks.h"
47 #include "ircons_t.h"
48 #include "irpass.h"
49
50 DEBUG_ONLY(static firm_dbg_module_t *dbg);
51
52 /**
53  * the environment for collecting data
54  */
55 typedef struct collect_t {
56         ir_node *proj_X;      /**< initial exec proj */
57         ir_node *block;       /**< old first block */
58         int     blk_idx;      /**< cfgpred index of the initial exec in block */
59         ir_node *proj_m;      /**< memory from start proj's */
60         ir_node *proj_data;   /**< linked list of all parameter access proj's */
61 } collect_t;
62
63 /**
64  * walker for collecting data, fills a collect_t environment
65  */
66 static void collect_data(ir_node *node, void *env)
67 {
68         collect_t *data = env;
69         ir_node *pred;
70         ir_op *op;
71
72         switch (get_irn_opcode(node)) {
73         case iro_Proj:
74                 pred = get_Proj_pred(node);
75
76                 op = get_irn_op(pred);
77                 if (op == op_Proj) {
78                         ir_node *start = get_Proj_pred(pred);
79
80                         if (is_Start(start)) {
81                                 if (get_Proj_proj(pred) == pn_Start_T_args) {
82                                         /* found Proj(ProjT(Start)) */
83                                         set_irn_link(node, data->proj_data);
84                                         data->proj_data = node;
85                                 }
86                         }
87                 } else if (op == op_Start) {
88                         if (get_Proj_proj(node) == pn_Start_X_initial_exec) {
89                                 /* found ProjX(Start) */
90                                 data->proj_X = node;
91                         }
92                 }
93                 break;
94         case iro_Block: {
95                 int i, n_pred = get_Block_n_cfgpreds(node);
96
97                 /*
98                  * the first block has the initial exec as cfg predecessor
99                  */
100                 if (node != get_irg_start_block(current_ir_graph)) {
101                         for (i = 0; i < n_pred; ++i) {
102                                 if (get_Block_cfgpred(node, i) == data->proj_X) {
103                                         data->block   = node;
104                                         data->blk_idx = i;
105                                         break;
106                                 }
107                         }
108                 }
109                 break;
110         }
111         default:
112                 break;
113         }
114 }
115
116 typedef enum tail_rec_variants {
117         TR_DIRECT,  /**< direct return value, i.e. return func(). */
118         TR_ADD,     /**< additive return value, i.e. return x +/- func() */
119         TR_MUL,     /**< multiplicative return value, i.e. return x * func() or return -func() */
120         TR_BAD,     /**< any other transformation */
121         TR_UNKNOWN  /**< during construction */
122 } tail_rec_variants;
123
124 typedef struct tr_env {
125         int               n_tail_calls;  /**< number of tail calls found */
126         int               n_ress;        /**< number of return values */
127         tail_rec_variants *variants;     /**< return value variants */
128         ir_node           *rets;         /**< list of returns that can be transformed */
129 } tr_env;
130
131
132 /**
133  * do the graph reconstruction for tail-recursion elimination
134  *
135  * @param irg           the graph that will reconstructed
136  * @param rets          linked list of all rets
137  * @param n_tail_calls  number of tail-recursion calls
138  */
139 static void do_opt_tail_rec(ir_graph *irg, tr_env *env)
140 {
141         ir_node *end_block = get_irg_end_block(irg);
142         ir_node *block, *jmp, *call, *calls;
143         ir_node **in;
144         ir_node **phis;
145         ir_node ***call_params;
146         ir_node *p, *n;
147         int i, j, n_params, n_locs;
148         collect_t data;
149         int rem            = get_optimize();
150         ir_entity *ent     = get_irg_entity(irg);
151         ir_type *method_tp = get_entity_type(ent);
152         ir_graph *old      = current_ir_graph;
153
154         current_ir_graph = irg;
155
156         assert(env->n_tail_calls > 0);
157
158         /* we add new nodes, so the outs are inconsistent */
159         set_irg_outs_inconsistent(irg);
160
161         /* we add new blocks and change the control flow */
162         set_irg_doms_inconsistent(irg);
163         set_irg_extblk_inconsistent(irg);
164
165         /* we add a new loop */
166         set_irg_loopinfo_inconsistent(irg);
167
168         /* calls are removed */
169         set_trouts_inconsistent();
170
171         /* we must build some new nodes WITHOUT CSE */
172         set_optimize(0);
173
174         /* collect needed data */
175         data.proj_X    = NULL;
176         data.block     = NULL;
177         data.blk_idx   = -1;
178         data.proj_m    = get_irg_initial_mem(irg);
179         data.proj_data = NULL;
180         irg_walk_graph(irg, NULL, collect_data, &data);
181
182         /* check number of arguments */
183         call = get_irn_link(end_block);
184         n_params = get_Call_n_params(call);
185
186         assert(data.proj_X && "Could not find initial exec from Start");
187         assert(data.block  && "Could not find first block");
188         assert(data.proj_m && "Could not find initial memory");
189         assert((data.proj_data || n_params == 0) && "Could not find Proj(ProjT(Start)) of non-void function");
190
191         /* allocate in's for phi and block construction */
192         NEW_ARR_A(ir_node *, in, env->n_tail_calls + 1);
193
194         in[0] = data.proj_X;
195
196         /* turn Return's into Jmp's */
197         for (i = 1, p = env->rets; p; p = n) {
198                 ir_node *block = get_nodes_block(p);
199
200                 n = get_irn_link(p);
201                 in[i++] = new_r_Jmp(block);
202
203                 // exchange(p, new_r_Bad(irg));
204
205                 /* we might generate an endless loop, so add
206                  * the block to the keep-alive list */
207                 add_End_keepalive(get_irg_end(irg), block);
208         }
209
210         /* create a new block at start */
211         block = new_r_Block(irg, env->n_tail_calls + 1, in);
212         jmp   = new_r_Jmp(block);
213
214         /* the old first block is now the second one */
215         set_Block_cfgpred(data.block, data.blk_idx, jmp);
216
217         /* allocate phi's, position 0 contains the memory phi */
218         NEW_ARR_A(ir_node *, phis, n_params + 1);
219
220         /* build the memory phi */
221         i = 0;
222         in[i] = new_r_Proj(get_irg_start(irg), mode_M, pn_Start_M);
223         set_irg_initial_mem(irg, in[i]);
224         ++i;
225
226         for (calls = call; calls; calls = get_irn_link(calls)) {
227                 in[i] = get_Call_mem(calls);
228                 ++i;
229         }
230         assert(i == env->n_tail_calls + 1);
231
232         phis[0] = new_r_Phi(block, env->n_tail_calls + 1, in, mode_M);
233
234         /* build the data Phi's */
235         if (n_params > 0) {
236                 ir_node *calls;
237                 ir_node *args;
238                 ir_node *args_bl;
239
240                 NEW_ARR_A(ir_node **, call_params, env->n_tail_calls);
241
242                 /* collect all parameters */
243                 for (i = 0, calls = call; calls; calls = get_irn_link(calls)) {
244                         call_params[i] = get_Call_param_arr(calls);
245                         ++i;
246                 }
247
248                 /* build new Proj's and Phi's */
249                 args    = get_irg_args(irg);
250                 args_bl = get_nodes_block(args);
251                 for (i = 0; i < n_params; ++i) {
252                         ir_mode *mode = get_type_mode(get_method_param_type(method_tp, i));
253
254                         in[0] = new_r_Proj(args, mode, i);
255                         for (j = 0; j < env->n_tail_calls; ++j)
256                                 in[j + 1] = call_params[j][i];
257
258                         phis[i + 1] = new_r_Phi(block, env->n_tail_calls + 1, in, mode);
259                 }
260         }
261
262         /*
263          * ok, we are here, so we have build and collected all needed Phi's
264          * now exchange all Projs into links to Phi
265          */
266         exchange(data.proj_m, phis[0]);
267         for (p = data.proj_data; p; p = n) {
268                 long proj = get_Proj_proj(p);
269
270                 assert(0 <= proj && proj < n_params);
271                 n = get_irn_link(p);
272                 exchange(p, phis[proj + 1]);
273         }
274
275         /* tail recursion was done, all info is invalid */
276         set_irg_doms_inconsistent(irg);
277         set_irg_outs_inconsistent(irg);
278         set_irg_extblk_inconsistent(irg);
279         set_irg_loopinfo_state(current_ir_graph, loopinfo_cf_inconsistent);
280         set_trouts_inconsistent();
281         set_irg_callee_info_state(irg, irg_callee_info_inconsistent);
282
283         set_optimize(rem);
284
285         /* check if we need new values */
286         n_locs = 0;
287         for (i = 0; i < env->n_ress; ++i) {
288                 if (env->variants[i] != TR_DIRECT)
289                         ++n_locs;
290         }
291
292         if (n_locs > 0) {
293                 ir_node *bad, *start_block;
294                 ir_node **in;
295                 ir_mode **modes;
296
297                 NEW_ARR_A(ir_node *, in, n_locs);
298                 NEW_ARR_A(ir_mode *, modes, n_locs);
299                 ssa_cons_start(irg, n_locs);
300
301                 start_block = get_irg_start_block(irg);
302                 set_cur_block(start_block);
303
304                 for (i = 0; i < env->n_ress; ++i) {
305                         ir_type *tp = get_method_res_type(method_tp, i);
306                         ir_mode *mode = get_type_mode(tp);
307
308                         modes[i] = mode;
309                         if (env->variants[i] == TR_ADD) {
310                                 set_value(i, new_r_Const(irg, get_mode_null(mode)));
311                         } else if (env->variants[i] == TR_MUL) {
312                                 set_value(i, new_r_Const(irg, get_mode_one(mode)));
313                         }
314                 }
315                 mature_immBlock(start_block);
316
317                 /* no: we can kill all returns */
318                 bad = get_irg_bad(irg);
319
320                 for (p = env->rets; p; p = n) {
321                         ir_node *block = get_nodes_block(p);
322                         ir_node *call, *mem, *jmp, *tuple;
323
324                         set_cur_block(block);
325                         n = get_irn_link(p);
326
327                         call = skip_Proj(get_Return_mem(p));
328                         assert(is_Call(call));
329
330                         mem = get_Call_mem(call);
331
332                         /* create a new jump, free of CSE */
333                         set_optimize(0);
334                         jmp = new_r_Jmp(block);
335                         set_optimize(rem);
336
337                         for (i = 0; i < env->n_ress; ++i) {
338                                 if (env->variants[i] != TR_DIRECT) {
339                                         in[i] = get_value(i, modes[i]);
340                                 } else {
341                                         in[i] = bad;
342                                 }
343                         }
344                         /* create a new tuple for the return values */
345                         tuple = new_r_Tuple(block, env->n_ress, in);
346
347                         turn_into_tuple(call, pn_Call_max);
348                         set_Tuple_pred(call, pn_Call_M,                mem);
349                         set_Tuple_pred(call, pn_Call_X_regular,        jmp);
350                         set_Tuple_pred(call, pn_Call_X_except,         bad);
351                         set_Tuple_pred(call, pn_Call_T_result,         tuple);
352                         set_Tuple_pred(call, pn_Call_P_value_res_base, bad);
353
354                         for (i = 0; i < env->n_ress; ++i) {
355                                 ir_node *res = get_Return_res(p, i);
356                                 if (env->variants[i] != TR_DIRECT) {
357                                         set_value(i, res);
358                                 }
359                         }
360
361                         exchange(p, bad);
362                 }
363
364                 /* finally fix all other returns */
365                 end_block = get_irg_end_block(irg);
366                 for (i = get_Block_n_cfgpreds(end_block) - 1; i >= 0; --i) {
367                         ir_node *ret = get_Block_cfgpred(end_block, i);
368                         ir_node *block;
369
370                         /* search all Returns of a block */
371                         if (! is_Return(ret))
372                                 continue;
373
374                         block = get_nodes_block(ret);
375                         set_cur_block(block);
376                         for (j = 0; j < env->n_ress; ++j) {
377                                 ir_node *pred = get_Return_res(ret, j);
378                                 ir_node *n;
379
380                                 switch (env->variants[j]) {
381                                 case TR_DIRECT:
382                                         continue;
383
384                                 case TR_ADD:
385                                         n = get_value(j, modes[j]);
386                                         n = new_r_Add(block, n, pred, modes[j]);
387                                         set_Return_res(ret, j, n);
388                                         break;
389
390                                 case TR_MUL:
391                                         n = get_value(j, modes[j]);
392                                         n = new_r_Mul(block, n, pred, modes[j]);
393                                         set_Return_res(ret, j, n);
394                                         break;
395
396                                 default:
397                                         assert(!"unexpected tail recursion variant");
398                                 }
399                         }
400                 }
401                 ssa_cons_finish(irg);
402         } else {
403                 ir_node *bad = get_irg_bad(irg);
404
405                 /* no: we can kill all returns */
406                 for (p = env->rets; p; p = n) {
407                         n = get_irn_link(p);
408                         exchange(p, bad);
409                 }
410         }
411         current_ir_graph = old;
412 }
413
414 /**
415  * Check the lifetime of locals in the given graph.
416  * Tail recursion can only be done, if we can prove that
417  * the lifetime of locals end with the recursive call.
418  * We do this by checking that no address of a local variable is
419  * stored or transmitted as an argument to a call.
420  *
421  * @return non-zero if it's ok to do tail recursion
422  */
423 static int check_lifetime_of_locals(ir_graph *irg)
424 {
425         ir_node *irg_frame;
426         int i;
427         ir_type *frame_tp = get_irg_frame_type(irg);
428
429         irg_frame = get_irg_frame(irg);
430         for (i = get_irn_n_outs(irg_frame) - 1; i >= 0; --i) {
431                 ir_node *succ = get_irn_out(irg_frame, i);
432
433                 if (is_Sel(succ)) {
434                         /* Check if we have compound arguments.
435                            For now, we cannot handle them, */
436                         if (get_entity_owner(get_Sel_entity(succ)) != frame_tp)
437                                 return 0;
438
439                         if (is_address_taken(succ))
440                                 return 0;
441                 }
442         }
443         return 1;
444 }
445
446 /**
447  * Examine irn and detect the recursion variant.
448  */
449 static tail_rec_variants find_variant(ir_node *irn, ir_node *call)
450 {
451         ir_node           *a, *b;
452         tail_rec_variants va, vb, res;
453
454         if (skip_Proj(skip_Proj(irn)) == call) {
455                 /* found it */
456                 return TR_DIRECT;
457         }
458         switch (get_irn_opcode(irn)) {
459         case iro_Add:
460                 /* try additive */
461                 a = get_Add_left(irn);
462                 if (get_nodes_block(a) != get_nodes_block(call)) {
463                         /* we are outside, ignore */
464                         va = TR_UNKNOWN;
465                 } else {
466                         va = find_variant(a, call);
467                         if (va == TR_BAD)
468                                 return TR_BAD;
469                 }
470                 b = get_Add_right(irn);
471                 if (get_nodes_block(b) != get_nodes_block(call)) {
472                         /* we are outside, ignore */
473                         vb = TR_UNKNOWN;
474                 } else {
475                         vb = find_variant(b, call);
476                         if (vb == TR_BAD)
477                                 return TR_BAD;
478                 }
479                 if (va == vb) {
480                         res = va;
481                 }
482                 else if (va == TR_UNKNOWN)
483                         res = vb;
484                 else if (vb == TR_UNKNOWN)
485                         res = va;
486                 else {
487                         /* they are different but none is TR_UNKNOWN -> incompatible */
488                         return TR_BAD;
489                 }
490                 if (res == TR_DIRECT || res == TR_ADD)
491                         return TR_ADD;
492                 /* not compatible */
493                 return TR_BAD;
494
495         case iro_Sub:
496                 /* try additive, but return value must be left */
497                 a = get_Sub_left(irn);
498                 if (get_nodes_block(a) != get_nodes_block(call)) {
499                         /* we are outside, ignore */
500                         va = TR_UNKNOWN;
501                 } else {
502                         va = find_variant(a, call);
503                         if (va == TR_BAD)
504                                 return TR_BAD;
505                 }
506                 b = get_Sub_right(irn);
507                 if (get_nodes_block(b) != get_nodes_block(call)) {
508                         /* we are outside, ignore */
509                         vb = TR_UNKNOWN;
510                 } else {
511                         vb = find_variant(b, call);
512                         if (vb != TR_UNKNOWN)
513                                 return TR_BAD;
514                 }
515                 res = va;
516                 if (res == TR_DIRECT || res == TR_ADD)
517                         return res;
518                 /* not compatible */
519                 return TR_BAD;
520
521         case iro_Mul:
522                 /* try multiplicative */
523                 a = get_Mul_left(irn);
524                 if (get_nodes_block(a) != get_nodes_block(call)) {
525                         /* we are outside, ignore */
526                         va = TR_UNKNOWN;
527                 } else {
528                         va = find_variant(a, call);
529                         if (va == TR_BAD)
530                                 return TR_BAD;
531                 }
532                 b = get_Mul_right(irn);
533                 if (get_nodes_block(b) != get_nodes_block(call)) {
534                         /* we are outside, ignore */
535                         vb = TR_UNKNOWN;
536                 } else {
537                         vb = find_variant(b, call);
538                         if (vb == TR_BAD)
539                                 return TR_BAD;
540                 }
541                 if (va == vb) {
542                         res = va;
543                 }
544                 else if (va == TR_UNKNOWN)
545                         res = vb;
546                 else if (vb == TR_UNKNOWN)
547                         res = va;
548                 else {
549                         /* they are different but none is TR_UNKNOWN -> incompatible */
550                         return TR_BAD;
551                 }
552                 if (res == TR_DIRECT || res == TR_MUL)
553                         return TR_MUL;
554                 /* not compatible */
555                 return TR_BAD;
556
557         case iro_Minus:
558                 /* try multiplicative */
559                 a = get_Minus_op(irn);
560                 res =  find_variant(a, call);
561                 if (res == TR_DIRECT)
562                         return TR_MUL;
563                 if (res == TR_MUL || res == TR_UNKNOWN)
564                         return res;
565                 /* not compatible */
566                 return TR_BAD;
567
568         default:
569                 return TR_UNKNOWN;
570         }
571 }
572
573
574 /*
575  * convert simple tail-calls into loops
576  */
577 int opt_tail_rec_irg(ir_graph *irg)
578 {
579         tr_env            env;
580         ir_node           *end_block;
581         int               i, n_ress, n_tail_calls = 0;
582         ir_node           *rets = NULL;
583         ir_type           *mtd_type, *call_type;
584         ir_entity         *ent;
585
586         FIRM_DBG_REGISTER(dbg, "firm.opt.tailrec");
587
588         assure_irg_outs(irg);
589
590         if (! check_lifetime_of_locals(irg))
591                 return 0;
592
593         ent      = get_irg_entity(irg);
594         mtd_type = get_entity_type(ent);
595     n_ress   = get_method_n_ress(mtd_type);
596
597         env.variants = NULL;
598         env.n_ress   = n_ress;
599
600         if (n_ress > 0) {
601                 NEW_ARR_A(tail_rec_variants, env.variants, n_ress);
602
603                 for (i = 0; i < n_ress; ++i)
604                         env.variants[i] = TR_DIRECT;
605         }
606
607         /*
608          * This tail recursion optimization works best
609          * if the Returns are normalized.
610          */
611         normalize_n_returns(irg);
612
613         end_block = get_irg_end_block(irg);
614         set_irn_link(end_block, NULL);
615
616         for (i = get_Block_n_cfgpreds(end_block) - 1; i >= 0; --i) {
617                 ir_node *ret = get_Block_cfgpred(end_block, i);
618                 ir_node *call, *call_ptr;
619                 int j;
620                 ir_node **ress;
621
622                 /* search all Returns of a block */
623                 if (! is_Return(ret))
624                         continue;
625
626                 /* check, if it's a Return self() */
627                 call = skip_Proj(get_Return_mem(ret));
628                 if (! is_Call(call))
629                         continue;
630
631                 /* the call must be in the same block as the return */
632                 if (get_nodes_block(call) != get_nodes_block(ret))
633                         continue;
634
635                 /* check if it's a recursive call */
636                 call_ptr = get_Call_ptr(call);
637
638                 if (! is_Global(call_ptr))
639                         continue;
640
641                 ent = get_Global_entity(call_ptr);
642                 if (!ent || get_entity_irg(ent) != irg)
643                         continue;
644
645                 /*
646                  * Check, that the types match. At least in C
647                  * this might fail.
648                  */
649                 mtd_type  = get_entity_type(ent);
650                 call_type = get_Call_type(call);
651
652                 if (mtd_type != call_type) {
653                         /*
654                          * Hmm, the types did not match, bad.
655                          * This can happen in C when no prototype is given
656                          * or K&R style is used.
657                          */
658 #if 0
659                         printf("Warning: Tail recursion fails because of different method and call types:\n");
660                         dump_type(mtd_type);
661                         dump_type(call_type);
662 #endif
663                         continue;
664                 }
665
666                 /* ok, mem is routed to a recursive call, check return args */
667                 ress = get_Return_res_arr(ret);
668                 for (j = get_Return_n_ress(ret) - 1; j >= 0; --j) {
669                         tail_rec_variants var = find_variant(ress[j], call);
670
671                         if (var >= TR_BAD) {
672                                 /* cannot be transformed */
673                                 break;
674                         }
675                         if (var == TR_DIRECT)
676                                 var = env.variants[j];
677                         else if (env.variants[j] == TR_DIRECT)
678                                 env.variants[j] = var;
679                         if (env.variants[j] != var) {
680                                 /* not compatible */
681                                 break;
682                         }
683                 }
684                 if (j >= 0)
685                         continue;
686
687                 /* here, we have found a call */
688                 set_irn_link(call, get_irn_link(end_block));
689                 set_irn_link(end_block, call);
690                 ++n_tail_calls;
691
692                 /* link all returns, we will need this */
693                 set_irn_link(ret, rets);
694                 rets = ret;
695         }
696
697         /* now, end_block->link contains the list of all tail calls */
698         if (n_tail_calls <= 0)
699                 return 0;
700
701         DB((dbg, LEVEL_2, "  Performing tail recursion for graph %s and %d Calls\n",
702             get_entity_ld_name(get_irg_entity(irg)), n_tail_calls));
703
704         hook_tail_rec(irg, n_tail_calls);
705
706         env.n_tail_calls = n_tail_calls;
707         env.rets         = rets;
708         do_opt_tail_rec(irg, &env);
709
710         return n_tail_calls;
711 }
712
713 ir_graph_pass_t *opt_tail_rec_irg_pass(const char *name)
714 {
715         return def_graph_pass_ret(name ? name : "tailrec", opt_tail_rec_irg);
716 }
717
718 /*
719  * optimize tail recursion away
720  */
721 void opt_tail_recursion(void)
722 {
723         int i;
724         int n_opt_applications = 0;
725         ir_graph *irg;
726
727         FIRM_DBG_REGISTER(dbg, "firm.opt.tailrec");
728
729         for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
730                 irg = get_irp_irg(i);
731
732                 current_ir_graph = irg;
733
734                 ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
735                 if (opt_tail_rec_irg(irg))
736                         ++n_opt_applications;
737
738                 ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
739         }
740
741         DB((dbg, LEVEL_1, "Performed tail recursion for %d of %d graphs\n",
742             n_opt_applications, get_irp_n_irgs()));
743 }
744
745 ir_prog_pass_t *opt_tail_recursion_pass(const char *name)
746 {
747         return def_prog_pass(name ? name : "tailrec", opt_tail_recursion);
748 }