Implemented scc algorithm. Added datastructure to mark
[libfirm] / ir / ana / irloop.h
1 /* Copyright (C) 2002 by Universitaet Karlsruhe
2 ** All rights reserved.
3 **
4 ** Authors: Goetz Lindenmaier
5 **
6 **  irloops.h:  Computes backedges in the control and data flow.
7 **  Only Block and Phi/Filter nodes can have incoming backedges.
8 **  Constructs loops data structure: indicates loop nesting.
9 */
10
11 /* $Id$ */
12
13 # ifndef _IRLOOP_H_
14 # define _IRLOOP_H_
15
16 # include "irgraph.h"
17 # include "irnode.h"
18
19
20 /** @@@ Interprocedural backedges ... ???? **/
21
22 /**********************************************************************/
23 /** Backedge information.                                            **/
24 /**                                                                  **/
25 /** Predecessors of Block, Phi and interprocedural Filter nodes can  **/
26 /** have  backedges.  If loop information is computed, this          **/
27 /** information is computed, too.                                    **/
28 /** The backedge information can only be used if the graph is not in **/
29 /** phase phase_building.                                            **/
30 /**********************************************************************/
31
32 /* Returns true if the predesessor pos is a backedge. */
33 bool is_backedge (ir_node *n, int pos);
34 /* Remarks that edge pos is a backedge. */
35 void set_backedge (ir_node *n, int pos);
36 /* Remarks that edge pos is not a backedge. */
37 void set_not_backedge (ir_node *n, int pos);
38 /* Returns true if n has backedges. */
39 bool has_backedges (ir_node *n);
40 /* Sets backedge information to zero. */
41 void clear_backedges (ir_node *n);
42
43 /**********************************************************************/
44 /** The loops datastructure                                          **/
45 /**                                                                  **/
46 /** The loops datastructure represents circles in the intermediate   **/
47 /** representation.  It does not represent loops in the terms of a   **/
48 /** source program.                                                  **/
49 /** Each ir_graph can contain one outermost loop datastructure.      **/
50 /** loop is the entry point to the nested loops.                     **/
51 /** The loop datastructure contains a field indicating the depth of  **/
52 /** the loop within the nesting.  Further it contains a list of the  **/
53 /** loops with nesting depth -1.  Finally it contains a list of all  **/
54 /** nodes in the loop.                                               **/
55 /* @@@ We could add a field pointing from a node to the containing loop,
56    this would cost a lot of memory, though. */
57 /**********************************************************************/
58
59 typedef struct ir_loop ir_loop;
60
61 void     set_irg_loop(ir_graph *irg, ir_loop *l);
62 ir_loop *get_irg_loop(ir_graph *irg);
63
64 /* Returns the loop n is contained in.
65    assumes current_ir_graph set properly. */
66 ir_loop *get_irn_loop(ir_node *n);
67
68 /* Returns outer loop, itself if outermost. */
69 ir_loop *get_loop_outer_loop (ir_loop *loop);
70 /* Returns nesting depth of this loop */
71 int      get_loop_depth (ir_loop *loop);
72
73 /* Sons are the inner loops contained in this loop. */
74 /* Returns the number of inner loops */
75 int      get_loop_n_sons (ir_loop *loop);
76 ir_loop *get_loop_son (ir_loop *loop, int pos);
77 /* Returns the number of nodes contained in loop.  */
78 int      get_loop_n_nodes (ir_loop *loop);
79 ir_node *get_loop_node (ir_loop *loop, int pos);
80
81
82 /**********************************************************************/
83 /* Constructing and destructing the loop/backedge information.       **/
84 /**********************************************************************/
85
86 /* Constructs backedge information for irg. In interprocedural view constructs
87    backedges for all methods called by irg, too.
88    @@@ I'm not sure what happens if irg is within a recursion in iterproc_view.
89    @@@ Interprocedural backedge construction is not yet functioning!!!
90 */
91 void construct_backedges(ir_graph *irg);
92
93 #endif /* _IRLOOP_H_ */